khi_robot_krnx_driver.cpp
Go to the documentation of this file.
1 /*********************************************************************
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2019, Kawasaki Heavy Industries, LTD.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * * Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  * * Redistributions in binary form must reproduce the above
14  * copyright notice, this list of conditions and the following
15  * disclaimer in the documentation and/or other materials provided
16  * with the distribution.
17  * * Neither the name of the Willow Garage nor the names of its
18  * contributors may be used to endorse or promote products derived
19  * from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32  * POSSIBILITY OF SUCH DAMAGE.
33  *********************************************************************/
34 
35 #include <urdf/model.h>
36 #include <khi_robot_krnx_driver.h>
37 
38 namespace khi_robot_control
39 {
40 #define KHI_ROBOT_WD002N "WD002N"
41 #define KHI_ROBOT_RS007L "RS007L"
42 #define KHI_ROBOT_RS007N "RS007N"
43 #define KHI_ROBOT_RS013N "RS013N"
44 #define KHI_ROBOT_RS080N "RS080N"
45 #define KHI_KRNX_BUFFER_SIZE 4
46 #define KHI_KRNX_ACTIVATE_TH 0.02
47 #define KHI_KRNX_M2MM 1000
48 
49 KhiRobotKrnxDriver::KhiRobotKrnxDriver() : KhiRobotDriver()
50 {
51  driver_name = __func__;
52  for ( int cno = 0; cno < KRNX_MAX_CONTROLLER; cno++ )
53  {
54  rtc_data[cno].seq_no = 0;
55  sw_dblrefflt[cno] = 0;
56  }
57 }
58 
60 {
61  int state;
62 
63  for ( int cno = 0; cno < KRNX_MAX_CONTROLLER; cno++ )
64  {
65  state = getState( cno );
66  if ( ( state != INIT ) && ( state != DISCONNECTED ) )
67  {
68  infoPrint("destructor");
69  close( cno );
70  }
71  }
72 }
73 
74 bool KhiRobotKrnxDriver::setState( const int& cont_no, const int& state )
75 {
76  bool is_state_set;
77  std::lock_guard<std::mutex> lock( mutex_state[cont_no] );
78 
79  is_state_set = KhiRobotDriver::setState( cont_no, state );
80  return is_state_set;
81 }
82 
83 int KhiRobotKrnxDriver::execAsMonCmd( const int& cont_no, const char* cmd, char* buffer, int buffer_sz, int* as_err_code )
84 {
85  std::lock_guard<std::mutex> lock( mutex_state[cont_no] );
86 
87  return_code = krnx_ExecMon( cont_no, cmd, buffer, buffer_sz, as_err_code );
88  if ( *as_err_code != 0 )
89  {
90  warnPrint( "AS returned %d by %s", *as_err_code, cmd );
91  }
92  else
93  {
94  retKrnxRes( cont_no, "krnx_ExecMon()", return_code );
95  }
96 
97  return return_code;
98 }
99 
100 bool KhiRobotKrnxDriver::retKrnxRes( const int& cont_no, const std::string& name, const int& ret, const bool error )
101 {
102  if ( ret != KRNX_NOERROR )
103  {
104  errorPrint( "%s returned -0x%X", name.c_str(), -ret );
105  if ( error ) { setState( cont_no, ERROR ); }
106  return false;
107  }
108  else
109  {
110  return true;
111  }
112 }
113 
114 /* This function needs some communication time. Don't use this in control loop */
115 bool KhiRobotKrnxDriver::conditionCheck( const int& cont_no, const KhiRobotData& data )
116 {
117  TKrnxPanelInfo panel_info;
118  bool ret = true;
119 
120  if ( getState( cont_no ) == ERROR )
121  {
122  return false;
123  }
124 
125  if ( in_simulation ) { return true; }
126 
127  for ( int ano = 0; ano < data.arm_num; ano++ )
128  {
129  /* Condition Check */
130  return_code = krnx_GetPanelInfo( cont_no, ano, &panel_info );
131  if ( !retKrnxRes( cont_no, "krnx_GetPanelInfo", return_code ) )
132  {
133  ret = false;
134  }
135 
136  if ( panel_info.repeat_lamp != -1 )
137  {
138  errorPrint( "Please change Robot Controller's TEACH/REPEAT to REPEAT" );
139  ret = false;
140  }
141  if ( panel_info.teach_lock_lamp != 0 )
142  {
143  errorPrint( "Please change Robot Controller's TEACH LOCK to OFF" );
144  ret = false;
145  }
146  else if ( panel_info.run_lamp != -1 )
147  {
148  errorPrint( "Please change Robot Controller's RUN/HOLD to RUN" );
149  ret = false;
150  }
151  else if ( panel_info.emergency != 0 )
152  {
153  errorPrint( "Please change Robot Controller's EMERGENCY to OFF" );
154  ret = false;
155  }
156  }
157 
158  if ( !ret )
159  {
160  setState( cont_no, ERROR );
161  }
162 
163  return ret;
164 }
165 
166 bool KhiRobotKrnxDriver::initialize( const int& cont_no, const double& period, KhiRobotData& data, const bool in_simulation )
167 {
168  char msg[256] = { 0 };
169 
170  // robot info
171  cont_info[cont_no].period = period;
172 
173  return_code = krnx_GetKrnxVersion( msg, sizeof(msg) );
174  infoPrint( msg );
175 
176  this->in_simulation = in_simulation;
177 
178  return true;
179 }
180 
181 bool KhiRobotKrnxDriver::open( const int& cont_no, const std::string& ip_address, KhiRobotData& data )
182 {
183  char c_ip_address[64] = { 0 };
184 
185  if ( !contLimitCheck( cont_no, KRNX_MAX_CONTROLLER ) ) { return false; }
186 
187  if ( getState( cont_no ) != INIT )
188  {
189  warnPrint( "Cannot open cont_no:%d because it is already opend...", cont_no );
190  return false;
191  }
192 
193  if ( in_simulation )
194  {
195  setState( cont_no, CONNECTING );
196  setState( cont_no, INACTIVE );
197  return true;
198  }
199 
200 
201  setState( cont_no, CONNECTING );
202  strncpy( c_ip_address, ip_address.c_str(), sizeof(c_ip_address) );
203  infoPrint( "Connecting to real controller: %s", c_ip_address );
204  return_code = krnx_Open( cont_no, c_ip_address );
205  if ( return_code == cont_no )
206  {
207  cont_info[cont_no].ip_address = ip_address;
208  if ( !loadDriverParam( cont_no, data ) ) { return false; };
209 
210  setState( cont_no, INACTIVE );
211  return true;
212  }
213  else
214  {
215  retKrnxRes( cont_no, "krnx_Open", return_code, false );
216  setState( cont_no, INIT );
217  return false;
218  }
219 }
220 
221 bool KhiRobotKrnxDriver::close( const int& cont_no )
222 {
223  char msg[1024] = { 0 };
224 
225  if ( !contLimitCheck( cont_no, KRNX_MAX_CONTROLLER ) ) { return false; }
226 
227  if ( in_simulation )
228  {
229  setState( cont_no, DISCONNECTING );
230  setState( cont_no, DISCONNECTED );
231  return true;
232  }
233 
234  /* Switch Reversion */
235  if ( sw_dblrefflt[cont_no] == -1 )
236  {
237  snprintf( msg, sizeof(msg), "SW ZDBLREFFLT_MODSTABLE=ON" );
238  return_code = execAsMonCmd( cont_no, msg, msg_buf, sizeof(msg_buf), &error_code );
239  }
240 
241  setState( cont_no, DISCONNECTING );
242  return_code = krnx_Close( cont_no );
243  if ( return_code == KRNX_NOERROR )
244  {
245  setState( cont_no, DISCONNECTED );
246  }
247 
248  return retKrnxRes( cont_no, "krnx_Close", return_code, false );
249 }
250 
251 bool KhiRobotKrnxDriver::activate( const int& cont_no, KhiRobotData& data )
252 {
253  const int to_home_vel = 20; /* speed 20 */
254  const double timeout_sec_th = 5.0; /* 5 sec */
255  bool is_ready;
256  TKrnxCurMotionData motion_data = { 0 };
257  double timeout_sec_cnt = 0.0;
258  int conv = 1;
259  float diff = 0;
260  int error_lamp = 0;
261  TKrnxPanelInfo panel_info;
262  TKrnxProgramInfo program_info;
263  int arm_num = data.arm_num;
264 
265  if ( !contLimitCheck( cont_no, KRNX_MAX_CONTROLLER ) ) { return false; }
266 
267  setState( cont_no, ACTIVATING );
268  if ( !conditionCheck( cont_no, data ) ) { return false; }
269 
270  if ( in_simulation )
271  {
272  setRobotDataHome( cont_no, data );
273  setState( cont_no, ACTIVE );
274  return true;
275  }
276 
277  /* Preparation */
278  bool is_cycle = true;
279  for ( int ano = 0; ano < arm_num; ano++ )
280  {
281  return_code = krnx_GetCurErrorLamp( cont_no, ano, &error_lamp );
282  if ( retKrnxRes( cont_no, "krnx_GetCurErrorLamp", return_code ) && ( error_lamp != 0 ) )
283  {
284  /* Error Reset */
285  return_code = krnx_Ereset( cont_no, ano, &error_code );
286  }
287  return_code = krnx_GetPanelInfo( cont_no, ano, &panel_info );
288  if ( retKrnxRes( cont_no, "krnx_GetPanelInfo", return_code ) )
289  {
290  if ( panel_info.cycle_lamp != -1 )
291  {
292  is_cycle = false;
293  }
294  if ( panel_info.motor_lamp != -1 )
295  {
296  /* Motor Power ON */
297  return_code = execAsMonCmd( cont_no, "ZPOW ON", msg_buf, sizeof(msg_buf), &error_code );
298  /* Error Reset */
299  return_code = krnx_Ereset( cont_no, ano, &error_code );
300  }
301  }
302  /* Clear RTC Comp Data */
303  return_code = krnx_OldCompClear( cont_no, ano );
304  }
305  if ( is_cycle )
306  {
307  for ( int ano = 0; ano < arm_num; ano++ )
308  {
309  return_code = krnx_GetProgramInfo( cont_no, ano, &program_info );
310  if ( retKrnxRes( cont_no, "krnx_GetProgramInfo", return_code ) )
311  {
312  std::stringstream program;
313  program << "rb_rtc" << ano + 1;
314  if ( strcmp( program_info.robot[ano].program_name, program.str().c_str() ) == 0 )
315  {
316  /* Already ROS Control */
317  setState( cont_no, ACTIVE );
318  return true;
319  }
320  else
321  {
322  /* Not ROS Control */
323  return_code = krnx_Hold( cont_no, ano, &error_code );
324  ros::Duration(0.2).sleep();
325  }
326  }
327  }
328  }
329 
330  /* Sync RTC Position */
331  if ( !syncRtcPos( cont_no, data ) )
332  {
333  errorPrint( "Failed to sync position" );
334  setState( cont_no, ERROR );
335  return false;
336  }
337 
338  /* Set HOME position */
339  for ( int ano = 0; ano < arm_num; ano++ )
340  {
341  /* Speed SLOW */
342  return_code = krnx_SetMonSpeed( cont_no, ano, to_home_vel, &error_code );
343  /* Executing base program */
344  std::stringstream program;
345  program << "rb_rtc" << ano + 1;
346  return_code = krnx_Execute( cont_no, ano, program.str().c_str(), 1, 0, &error_code );
347 
348  while ( 1 )
349  {
350  ros::Duration(cont_info[cont_no].period/1e+9).sleep();
351  timeout_sec_cnt += cont_info[cont_no].period/1e+9;
352  if ( timeout_sec_cnt > timeout_sec_th )
353  {
354  errorPrint( "Failed to activate: timeout" );
355  setState( cont_no, ERROR );
356  return false;
357  }
358 
359  return_code = krnx_GetRtcSwitch( cont_no, ano, &rtc_data[cont_no].sw );
360  if ( ( return_code != KRNX_NOERROR ) || ( rtc_data[cont_no].sw == 0 ) ) { continue; }
361 
362  return_code = krnx_GetCurMotionData( cont_no, ano, &motion_data );
363  if ( return_code != KRNX_NOERROR ) { continue; }
364 
365  is_ready = true;
366  for ( int jt = 0; jt < data.arm[ano].jt_num; jt++ )
367  {
368  if ( data.arm[ano].type[jt] == urdf::Joint::PRISMATIC ) { conv = KHI_KRNX_M2MM; }
369  else { conv = 1; }
370 
371  diff = data.arm[ano].home[jt]*conv - motion_data.ang[jt];
372  if ( fabs(diff) > KHI_KRNX_ACTIVATE_TH )
373  {
374  is_ready = false;
375  break;
376  }
377  }
378 
379  if ( is_ready )
380  {
381  /* Speed 100 */
382  return_code = krnx_SetMonSpeed( cont_no, ano, 100, &error_code );
383  break;
384  }
385  }
386  }
387 
388  if ( !conditionCheck( cont_no, data ) ) { return false; }
389 
390  setState( cont_no, ACTIVE );
391 
392  return true;
393 }
394 
395 bool KhiRobotKrnxDriver::hold( const int& cont_no, const KhiRobotData& data )
396 {
397  int state;
398  bool ret = true;
399 
400  if ( !contLimitCheck( cont_no, KRNX_MAX_CONTROLLER ) ) { return false; }
401 
402  state = getState( cont_no );
403  if ( state == ACTIVE )
404  {
405  ret = setState( cont_no, HOLDED );
406  }
407 
408  return ret;
409 }
410 
411 bool KhiRobotKrnxDriver::deactivate( const int& cont_no, const KhiRobotData& data )
412 {
413  char msg[1024] = { 0 };
414  int error_lamp = 0;
415 
416  if ( !contLimitCheck( cont_no, KRNX_MAX_CONTROLLER ) ) { return false; }
417 
418  if ( in_simulation )
419  {
420  setState( cont_no, DEACTIVATING );
421  setState( cont_no, INACTIVE );
422  return true;
423  }
424 
425  setState( cont_no, DEACTIVATING );
426 
427  for ( int ano = 0; ano < data.arm_num; ano++ )
428  {
429  /* Hold Program */
430  return_code = krnx_Hold( cont_no, ano, &error_code );
431  ros::Duration(0.2).sleep();
432  /* Kill Program */
433  return_code = krnx_Kill( cont_no, ano, &error_code );
434  /* Motor Power OFF */
435  return_code = execAsMonCmd( cont_no, "ZPOW OFF", msg_buf, sizeof(msg_buf), &error_code );
436  return_code = krnx_GetCurErrorLamp( cont_no, ano, &error_lamp );
437  if ( retKrnxRes( cont_no, "krnx_GetCurErrorLamp", return_code ) && ( error_lamp != 0 ) )
438  {
439  /* Error Reset */
440  return_code = krnx_Ereset( cont_no, ano, &error_code );
441  }
442  }
443 
444  setState( cont_no, INACTIVE );
445 
446  return true;
447 }
448 
449 bool KhiRobotKrnxDriver::loadDriverParam( const int& cont_no, KhiRobotData& data )
450 {
451  char robot_name[64] = { 0 };
452  char msg[256] = { 0 };
453  TKrnxPanelInfo panel_info;
454  int jt_num = 0;
455 
456  int arm_num = data.arm_num;
457 
458  if ( arm_num <= 0 )
459  {
460  errorPrint( "Invalid robot size" );
461  return false;
462  }
463 
464  for ( int ano = 0; ano < arm_num; ano++ )
465  {
466  /* Robot Name */
467  return_code = krnx_GetRobotName( cont_no, ano, robot_name );
468  if ( strncmp( robot_name, data.robot_name.c_str(), 6 ) != 0 )
469  {
470  errorPrint( "ROS Robot:%s does not match AS:%s", data.robot_name.c_str(), robot_name );
471  return false;
472  }
473 
474  /* AS Switch */
475  return_code = execAsMonCmd( cont_no, "TYPE SWITCH(ZDBLREFFLT_MODSTABLE)", msg_buf, sizeof(msg_buf), &error_code );
476  if ( retKrnxRes( cont_no, msg, return_code ) )
477  {
478  sw_dblrefflt[cont_no] = atoi(msg_buf);
479  if ( sw_dblrefflt[cont_no] == -1 )
480  {
481  return_code = execAsMonCmd( cont_no, "SW ZDBLREFFLT_MODSTABLE=OFF", msg_buf, sizeof(msg_buf), &error_code );
482  }
483  }
484 
485  /* Joint num */
486  snprintf( msg, sizeof(msg), "TYPE SYSDATA(ZROB.NOWAXIS,%d)", ano+1 );
487  return_code = execAsMonCmd( cont_no, msg, msg_buf, sizeof(msg_buf), &error_code );
488  if ( retKrnxRes( cont_no, msg, return_code ) )
489  {
490  jt_num = atoi(msg_buf);
491  if ( data.arm[ano].jt_num != jt_num )
492  {
493  warnPrint( "ROS JT:%d does not match AS:%d", data.arm[ano].jt_num, jt_num );
494  }
495  }
496 
497  return_code = krnx_GetPanelInfo( cont_no, ano, &panel_info );
498  if ( retKrnxRes( cont_no, "krnx_GetPanelInfo", return_code ) && ( panel_info.cycle_lamp != 0 ) )
499  {
500  /* Hold Program */
501  return_code = krnx_Hold( cont_no, ano, &error_code );
502  if ( !retKrnxRes( cont_no, "krnx_Hold", return_code ) ) { return false; }
503  }
504 
505  /* KRNX */
506  TKrnxRtcInfo rtcont_info;
507  rtcont_info.cyc = (int)(cont_info[cont_no].period/1e+6);
508  rtcont_info.buf = KHI_KRNX_BUFFER_SIZE;
509  rtcont_info.interpolation = 1;
510  return_code = krnx_SetRtcInfo( cont_no, &rtcont_info );
511  retKrnxRes( cont_no, "krnx_SetRtcInfo", return_code );
512  krnx_SetRtcCompMask( cont_no, ano, pow( 2, data.arm[ano].jt_num ) - 1 );
513 
514  /* Kill Program */
515  return_code = krnx_Kill( cont_no, ano, &error_code );
516  if ( !retKrnxRes( cont_no, "krnx_Kill", return_code ) ) { return false; }
517 
518  /* Load Program */
519  if ( !loadRtcProg( cont_no, data.robot_name.c_str() ) )
520  {
521  errorPrint( "Failed to load RTC program");
522  return false;
523  }
524  }
525 
526  return true;
527 }
528 
532 bool KhiRobotKrnxDriver::readData( const int& cont_no, KhiRobotData& data )
533 {
534  static int sim_cnt[KHI_MAX_CONTROLLER] = { 0 };
535  static KhiRobotData prev_data = data;
536  int arm_num = data.arm_num;
537 
538  if ( !contLimitCheck( cont_no, KRNX_MAX_CONTROLLER ) ) { return false; }
539 
540  if ( in_simulation )
541  {
542  for ( int ano = 0; ano < arm_num; ano++ )
543  {
544  memcpy( data.arm[ano].pos, data.arm[ano].cmd, sizeof(data.arm[ano].pos) );
545  for ( int jt = 0; jt < data.arm[ano].jt_num; jt++ )
546  {
547  data.arm[ano].vel[jt] = data.arm[ano].pos[jt] - prev_data.arm[ano].pos[jt];
548  }
549  }
550  prev_data = data;
551  if ( ( sim_cnt[cont_no] - 1 ) % KRNX_PRINT_TH == 0 )
552  {
553  jointPrint( std::string("read"), data );
554  }
555  sim_cnt[cont_no]++;
556  return true;
557  }
558 
559  static std::vector<TKrnxCurMotionData> motion_data[KRNX_MAX_CONTROLLER][KRNX_MAX_ROBOT];
561  float ang[KRNX_MAX_ROBOT][KRNX_MAXAXES] = {{ 0 }};
562  float vel[KRNX_MAX_ROBOT][KRNX_MAXAXES] = {{ 0 }};
563 
564  for ( int ano = 0; ano < arm_num; ano++ )
565  {
566  if ( !getCurMotionData( cont_no, ano, &motion_cur[ano] ) ) { return false; }
567 
568  if ( motion_data[cont_no][ano].size() >= KRNX_MOTION_BUF )
569  {
570  motion_data[cont_no][ano].erase( motion_data[cont_no][ano].begin() );
571  }
572  motion_data[cont_no][ano].push_back( motion_cur[ano] );
573 
574  // ang
575  memcpy( ang[ano], &motion_cur[ano].ang, sizeof(motion_cur[ano].ang) );
576  // vel
577  if ( motion_data[cont_no][ano].size() > 1 )
578  {
579  std::vector<TKrnxCurMotionData>::iterator it = motion_data[cont_no][ano].end();
580  it--;
581  for ( int jt=0; jt < KHI_MAX_JOINT; jt++ )
582  {
583  vel[ano][jt] = motion_data[cont_no][ano].back().ang[jt] - it->ang[jt];
584  }
585  }
586 
587  for ( int jt = 0; jt < data.arm[ano].jt_num; jt++ )
588  {
589  data.arm[ano].pos[jt] = (double)ang[ano][jt];
590  data.arm[ano].vel[jt] = (double)vel[ano][jt];
591  data.arm[ano].eff[jt] = (double)0; // tmp
592 
593  /* [ mm ] to [ m ] */
594  if ( data.arm[ano].type[jt] == urdf::Joint::PRISMATIC )
595  {
596  data.arm[ano].pos[jt] /= KHI_KRNX_M2MM;
597  data.arm[ano].vel[jt] /= KHI_KRNX_M2MM;
598  }
599  }
600  }
601 
602  return true;
603 }
604 
605 bool KhiRobotKrnxDriver::getCurMotionData( const int& cont_no, const int& robot_no, TKrnxCurMotionData* p_motion_data )
606 {
607  if ( !contLimitCheck( cont_no, KRNX_MAX_CONTROLLER ) ) { return false; }
608 
609  return_code = krnx_GetCurMotionData( cont_no, robot_no, p_motion_data );
610 
611  return retKrnxRes( cont_no, "krnx_GetCurMotionData", return_code );
612 }
613 
614 bool KhiRobotKrnxDriver::setRobotDataHome( const int& cont_no, KhiRobotData& data )
615 {
616  KhiRobotData base;
617  int arm_num = data.arm_num;
618 
619  if ( data.robot_name == KHI_ROBOT_WD002N )
620  {
621  data.arm[0].home[0] = -45.0f*M_PI/180;
622  data.arm[0].home[1] = 45.0f*M_PI/180;
623  data.arm[1].home[0] = 45.0f*M_PI/180;
624  data.arm[1].home[1] = -45.0f*M_PI/180;
625  data.arm[0].home[2] = data.arm[1].home[2] = 90.0f/KHI_KRNX_M2MM;
626  data.arm[0].home[3] = data.arm[1].home[3] = 0.0f;
627  }
628  else
629  {
630  for ( int ano = 0; ano < arm_num; ano++ )
631  {
632  for ( int jt = 0; jt < data.arm[ano].jt_num; jt++ )
633  {
634  data.arm[ano].home[jt] = 0.0f;
635  }
636  }
637  }
638 
639  for ( int ano = 0; ano < arm_num; ano++ )
640  {
641  for ( int jt = 0; jt < data.arm[ano].jt_num; jt++ )
642  {
643  data.arm[ano].cmd[jt] = data.arm[ano].pos[jt] = data.arm[ano].home[jt];
644  }
645  }
646 
647  return true;
648 }
649 
653 bool KhiRobotKrnxDriver::writeData( const int& cont_no, const KhiRobotData& data )
654 {
655  static int sim_cnt[KHI_MAX_CONTROLLER] = { 0 };
656  int idx, ano, jt;
657  char msg[1024] = { 0 };
658  char status[128] = { 0 };
659  TKrnxCurMotionData motion_data;
660  float jt_pos = 0.0F;
661  float jt_vel = 0.0F;
662  bool is_primed = true;
663  int arm_num = data.arm_num;
664  KhiRobotKrnxRtcData* p_rtc_data = &rtc_data[cont_no];
665 
666  if ( !contLimitCheck( cont_no, KRNX_MAX_CONTROLLER ) ) { return false; }
667 
668  if ( getState( cont_no ) != ACTIVE ) { return true; }
669 
670  if ( in_simulation )
671  {
672  if ( ( sim_cnt[cont_no] - 1 ) % KRNX_PRINT_TH == 0 )
673  {
674  jointPrint( std::string("write"), data );
675  }
676  sim_cnt[cont_no]++;
677  return true;
678  }
679 
680  /* convert */
681  for ( int ano = 0; ano < arm_num; ano++ )
682  {
683  for ( int jt = 0; jt < data.arm[ano].jt_num; jt++ )
684  {
685  p_rtc_data->comp[ano][jt] = (float)(data.arm[ano].cmd[jt] - data.arm[ano].home[jt]);
686  if ( data.arm[ano].type[jt] == urdf::Joint::PRISMATIC )
687  {
688  p_rtc_data->comp[ano][jt] *= KHI_KRNX_M2MM;
689  }
690  }
691  }
692 
693  for ( int ano = 0; ano < arm_num; ano++ )
694  {
695  return_code = krnx_PrimeRtcCompData( cont_no, ano, &p_rtc_data->comp[ano][0], &p_rtc_data->status[ano][0] );
696  if ( !retKrnxRes( cont_no, "krnx_PrimeRtcCompData", return_code ) ) { is_primed = false; }
697  }
698  if ( !is_primed )
699  {
700  /* ERROR log */
701  for ( int ano = 0; ano < arm_num; ano++ )
702  {
703  snprintf( msg, sizeof(msg), "[krnx_PrimeRtcCompData] ano:%d [jt]pos:vel:status ", ano+1 );
704  krnx_GetRtcCompData( cont_no, ano, &p_rtc_data->old_comp[ano][0] );
705  getCurMotionData( cont_no, ano, &motion_data );
706  for ( int jt = 0; jt < data.arm[ano].jt_num; jt++ )
707  {
708  jt_pos = motion_data.ang_ref[jt];
709  jt_vel = ( p_rtc_data->comp[ano][jt] - p_rtc_data->old_comp[ano][jt] )*(1e+9/cont_info[cont_no].period);
710  if ( data.arm[ano].type[jt] == urdf::Joint::PRISMATIC )
711  {
712  jt_pos /= KHI_KRNX_M2MM;
713  jt_vel /= KHI_KRNX_M2MM;
714  }
715  snprintf( status, sizeof(status), "[%d]%.4f:%.4f:%d ", jt+1, jt_pos, jt_vel, p_rtc_data->status[ano][jt] );
716  strcat( msg, status );
717  ROS_WARN("JT%d:%f,%f,%f,%f,%f,%f", jt+1, data.arm[ano].cmd[jt], data.arm[ano].home[jt]+p_rtc_data->comp[ano][jt],p_rtc_data->old_comp[ano][jt], p_rtc_data->comp[ano][jt], data.arm[ano].home[jt], motion_data.ang_ref[jt]);
718  ROS_WARN("JT%d:%f,%f,%f,%f,%f,%f", jt+1, data.arm[ano].cmd[jt]*180/M_PI, (data.arm[ano].home[jt]+p_rtc_data->comp[ano][jt])*180/M_PI, p_rtc_data->old_comp[ano][jt]*180/M_PI, p_rtc_data->comp[ano][jt]*180/M_PI, data.arm[ano].home[jt]*180/M_PI, motion_data.ang_ref[jt]*180/M_PI);
719  }
720  errorPrint( msg );
721  }
722  return false;
723  }
724 
725  return_code = krnx_SendRtcCompData( cont_no, p_rtc_data->seq_no );
726  p_rtc_data->seq_no++;
727 
728  return retKrnxRes( cont_no, "krnx_SendRtcCompData", return_code );
729 }
730 
731 bool KhiRobotKrnxDriver::updateState( const int& cont_no, const KhiRobotData& data )
732 {
733  int error_lamp = 0;
734  int error_code = 0;
735  int state;
736  TKrnxPanelInfo panel_info;
737  int arm_num = data.arm_num;
738 
739  if ( !contLimitCheck( cont_no, KRNX_MAX_CONTROLLER ) ) { return false; }
740 
741  state = getState( cont_no );
742  if ( state == ERROR )
743  {
744  for ( int ano = 0; ano < arm_num; ano++ )
745  {
746  return_code = krnx_GetPanelInfo( cont_no, ano, &panel_info );
747  if ( retKrnxRes( cont_no, "krnx_GetPanelInfo", return_code ) && ( panel_info.cycle_lamp != 0 ) )
748  {
749  /* Hold Program */
750  return_code = krnx_Hold( cont_no, ano, &error_code );
751  if ( !retKrnxRes( cont_no, "krnx_Hold", return_code ) ) { return false; }
752  }
753  }
754  }
755 
756  if ( in_simulation ) { return true; }
757 
758  for ( int ano = 0; ano < arm_num; ano++ )
759  {
760  return_code = krnx_GetCurErrorLamp( cont_no, ano, &error_lamp );
761  if ( ( state != ERROR ) && ( error_lamp != 0 ) )
762  {
764  errorPrint( "AS ERROR %d: ano:%d code:%d", cont_no, ano+1, error_code );
765  setState( cont_no, ERROR );
766  return true;
767  }
768  return_code = krnx_GetRtcSwitch( cont_no, ano, &rtc_data[cont_no].sw );
769  if ( ( state != INACTIVE ) && ( rtc_data[cont_no].sw == 0 ) )
770  {
771  errorPrint( "RTC SWITCH turned OFF %d: ano:%d", cont_no, ano+1 );
772  deactivate( cont_no, data );
773  return true;
774  }
775  }
776 
777  return true;
778 }
779 
780 bool KhiRobotKrnxDriver::getPeriodDiff( const int& cont_no, double& diff )
781 {
782  if ( !contLimitCheck( cont_no, KRNX_MAX_CONTROLLER ) ) { return false; }
783  static bool buffer_enabled = false;
784  int ano = 0;
785  int buffer_length = 0;
786 
787  if ( getState( cont_no ) != ACTIVE )
788  {
789  diff = 0;
790  return true;
791  }
792 
793  if ( in_simulation )
794  {
795  diff = 0;
796  return true;
797  }
798 
799  buffer_length = krnx_GetRtcBufferLength( cont_no, ano );
800  // check if KRNX can get buffer length from KHI controller
801  if ( buffer_length > 0 )
802  {
803  buffer_enabled = true;
804  }
805 
806  if ( buffer_enabled )
807  {
808  diff = ( buffer_length - KHI_KRNX_BUFFER_SIZE ) * cont_info[cont_no].period;
809  }
810  else
811  {
812  diff = 0;
813  }
814 
815  return true;
816 }
817 
818 std::vector<std::string> KhiRobotKrnxDriver::splitString( const std::string& str, const char& del )
819 {
820  int first = 0;
821  int last = str.find_first_of( del );
822  std::vector<std::string> list;
823 
824  if ( first < str.size() )
825  {
826  std::string sub_str1( str, first, last - first );
827  list.push_back( sub_str1 );
828  first = last + 1;
829  std::string sub_str2( str, first, std::string::npos );
830  list.push_back( sub_str2 );
831  }
832 
833  return list;
834 }
835 
836 bool KhiRobotKrnxDriver::loadRtcProg( const int& cont_no, const std::string& name )
837 {
838  FILE* fp;
839  int fd;
840  char tmplt[] = "/tmp/khi_robot-rtc_param-XXXXXX";
841  char fd_path[128] = { 0 };
842  char file_path[128] = { 0 };
843  ssize_t rsize;
844 
845  fd = mkstemp(tmplt);
846 
847  if ( ( fp = fdopen( fd, "w" ) ) != NULL)
848  {
849  /* retrieve path */
850  snprintf( fd_path, sizeof(fd_path), "/proc/%d/fd/%d", getpid(), fd );
851  rsize = readlink( fd_path, file_path, sizeof(file_path) );
852  if ( rsize < 0 ) { return false; }
853 
854  /* RTC program */
855  if ( name == KHI_ROBOT_WD002N )
856  {
857  fprintf( fp, ".PROGRAM rb_rtc1()\n" );
858  fprintf( fp, " HERE #rtchome1\n" );
859  fprintf( fp, " FOR .i = 1 TO 8\n" );
860  fprintf( fp, " .acc[.i] = 0\n" );
861  fprintf( fp, " END\n" );
862  fprintf( fp, " L3ACCURACY .acc[1] ALWAYS\n" );
863  fprintf( fp, " RTC_SW 1: ON\n" );
864  fprintf( fp, "1 JMOVE #rtchome1\n" );
865  fprintf( fp, " GOTO 1\n" );
866  fprintf( fp, " RTC_SW 1: OFF\n" );
867  fprintf( fp, ".END\n" );
868  fprintf( fp, ".PROGRAM rb_rtc2()\n" );
869  fprintf( fp, " HERE #rtchome2\n" );
870  fprintf( fp, " FOR .i = 1 TO 8\n" );
871  fprintf( fp, " .acc[.i] = 0\n" );
872  fprintf( fp, " END\n" );
873  fprintf( fp, " L3ACCURACY .acc[1] ALWAYS\n" );
874  fprintf( fp, " RTC_SW 2: ON\n" );
875  fprintf( fp, "1 JMOVE #rtchome2\n" );
876  fprintf( fp, " GOTO 1\n" );
877  fprintf( fp, " RTC_SW 2: OFF\n" );
878  fprintf( fp, ".END\n" );
879  }
880  else
881  {
882  fprintf( fp, ".PROGRAM rb_rtc1()\n" );
883  fprintf( fp, " HERE #rtchome1\n" );;
884  fprintf( fp, " ACCURACY 0 ALWAYS\n" );
885  fprintf( fp, " RTC_SW 1: ON\n" );
886  fprintf( fp, "1 JMOVE #rtchome1\n" );
887  fprintf( fp, " GOTO 1\n" );
888  fprintf( fp, " RTC_SW 1: OFF\n" );
889  fprintf( fp, ".END\n" );
890  }
891  fclose( fp );
892  }
893  else
894  {
895  return false;
896  }
897 
898  return_code = krnx_Load( cont_no, file_path );
899  unlink( file_path );
900  if ( !retKrnxRes( cont_no, "krnx_Load", return_code ) ) { return false; }
901 
902  return true;
903 }
904 
905 bool KhiRobotKrnxDriver::syncRtcPos( const int& cont_no, KhiRobotData& data )
906 {
907  TKrnxCurMotionData motion_data = { 0 };
908 
909  for ( int ano = 0; ano < data.arm_num; ano++ )
910  {
911  /* Driver */
912  if ( !getCurMotionData( cont_no, ano, &motion_data ) ) { return false; }
913  for ( int jt = 0; jt < data.arm[ano].jt_num; jt++ )
914  {
915  data.arm[ano].home[jt] = (double)motion_data.ang[jt];
916  if ( data.arm[ano].type[jt] == urdf::Joint::PRISMATIC )
917  {
918  data.arm[ano].home[jt] /= KHI_KRNX_M2MM;
919  }
920  }
921  }
922 
923  return true;
924 }
925 
926 bool KhiRobotKrnxDriver::commandHandler( khi_robot_msgs::KhiRobotCmd::Request& req, khi_robot_msgs::KhiRobotCmd::Response& res)
927 {
928  int cont_no = 0;
929  char resp[KRNX_MSGSIZE] = { 0 };
930  int acode;
931  int dcode;
932  std::vector<std::string> vlist;
933  std::string api_cmd;
934  const char del = ' ';
935  int arg;
936  int onoff;
937  int state;
938  TKrnxIoInfo io;
939 
940  /* default */
941  res.driver_ret = KRNX_NOERROR;
942  res.as_ret = 0;
943  res.cmd_ret = "";
944  api_cmd = "";
945  arg = 0;
946  onoff = 0;
947 
948  if ( req.type == "as" )
949  {
950  if ( !isTransitionState( cont_no ) )
951  {
952  dcode = execAsMonCmd( cont_no, req.cmd.c_str(), resp, sizeof(resp), &acode );
953  res.driver_ret = dcode;
954  res.as_ret = acode;
955  res.cmd_ret = std::string(resp);
956  }
957  else
958  {
959  res.driver_ret = KRNX_E_BADARGS;
960  res.cmd_ret = "IS TRANSITION STATE";
961  }
962  }
963  else if ( req.type == "driver" )
964  {
965  state = getState( cont_no );
966  if ( req.cmd == "get_status" )
967  {
968  res.cmd_ret = getStateName( cont_no );
969  }
970  else if ( req.cmd == "hold" )
971  {
972  if ( state == ACTIVE )
973  {
974  setStateTrigger( cont_no, HOLD );
975  }
976  else
977  {
978  res.cmd_ret = "NOT ACTIVE STATE";
979  }
980  }
981  else if ( req.cmd == "restart" )
982  {
983  if ( ( state == INACTIVE ) || ( state == HOLDED ) || ( state == ERROR ) )
984  {
985  setStateTrigger( cont_no, RESTART );
986  }
987  else
988  {
989  res.cmd_ret = "NOT INACTIVE/HOLDED/ERROR STATE";
990  }
991  }
992  else if ( req.cmd == "quit" )
993  {
994  setStateTrigger( cont_no, QUIT );
995  }
996  else
997  {
998  vlist = splitString( req.cmd, del );
999  if ( vlist.size() == 2 )
1000  {
1001  api_cmd = vlist[0];
1002  if ( api_cmd == "get_signal" )
1003  {
1004  dcode = krnx_GetCurIoInfo( cont_no, &io );
1005  res.driver_ret = dcode;
1006  arg = std::atoi( vlist[1].c_str() );
1007  if ( arg >= 1 && arg <= KHI_MAX_SIG_SIZE )
1008  {
1009  /* DO */
1010  onoff = io.io_do[(arg-1)/8] & ( 1 << (arg-1)%8 );
1011  }
1012  else if ( arg >= 1000 && arg <= 1000 + KHI_MAX_SIG_SIZE )
1013  {
1014  /* DI */
1015  arg -= 1000;
1016  onoff = io.io_di[(arg-1)/8] & ( 1 << (arg-1)%8 );
1017  }
1018  else if ( arg >= 2001 && arg <= 2000 + KHI_MAX_SIG_SIZE )
1019  {
1020  /* INTERNAL */
1021  arg -= 2000;
1022  onoff = io.internal[(arg-1)/8] & ( 1 << (arg-1)%8 );
1023  }
1024  else
1025  {
1026  res.driver_ret = KRNX_E_BADARGS;
1027  res.cmd_ret = "INVALID ARGS";
1028  }
1029  if ( res.driver_ret == KRNX_NOERROR )
1030  {
1031  if ( onoff ) { res.cmd_ret = "-1"; }
1032  else { res.cmd_ret = "0";}
1033  }
1034  }
1035  else if ( api_cmd == "set_signal" )
1036  {
1037  std::string as_cmd = req.cmd;
1038  as_cmd.replace( 0, strlen("set_signal"), "SIGNAL" );
1039  dcode = execAsMonCmd( cont_no, as_cmd.c_str(), resp, sizeof(resp), &acode );
1040  res.driver_ret = dcode;
1041  res.as_ret = acode;
1042  }
1043  else
1044  {
1045  res.driver_ret = KRNX_E_BADARGS;
1046  res.cmd_ret = "INVALID CMD";
1047  }
1048  }
1049  else
1050  {
1051  res.driver_ret = KRNX_E_BADARGS;
1052  res.cmd_ret = "INVALID ARGS";
1053  }
1054  }
1055  }
1056  else
1057  {
1058  res.driver_ret = KRNX_E_BADARGS;
1059  res.cmd_ret = "INVALID TYPE";
1060  }
1061 
1062  return true;
1063 }
1064 
1065 } // end of khi_robot_control namespace
TKrnxRtcInfo
Definition: krnx.h:288
khi_robot_control::ERROR
@ ERROR
Definition: khi_robot_driver.h:119
khi_robot_control::KhiRobotKrnxDriver::open
bool open(const int &cont_no, const std::string &ip_address, KhiRobotData &data) override
Definition: khi_robot_krnx_driver.cpp:213
KRNX_MAX_CONTROLLER
#define KRNX_MAX_CONTROLLER
Definition: krnx.h:59
khi_robot_control::KhiRobotDriver::return_code
int return_code
Definition: khi_robot_driver.h:340
krnx_Ereset
DECLSPEC_IMPORT int WINAPI krnx_Ereset(int cont_no, int robot_no, int *as_err_code)
khi_robot_control::KhiRobotKrnxDriver::getCurMotionData
bool getCurMotionData(const int &cont_no, const int &robot_no, TKrnxCurMotionData *p_motion_data)
Definition: khi_robot_krnx_driver.cpp:637
KRNX_PRINT_TH
#define KRNX_PRINT_TH
Definition: khi_robot_krnx_driver.h:81
msg
msg
krnx_Hold
DECLSPEC_IMPORT int WINAPI krnx_Hold(int cont_no, int robot_no, int *as_err_code)
khi_robot_control::KhiRobotKrnxDriver::activate
bool activate(const int &cont_no, KhiRobotData &data) override
Definition: khi_robot_krnx_driver.cpp:283
khi_robot_control::CONNECTING
@ CONNECTING
Definition: khi_robot_driver.h:111
khi_robot_control::INACTIVE
@ INACTIVE
Definition: khi_robot_driver.h:112
TKrnxPanelInfo
Definition: krnx.h:200
TKrnxIoInfo::internal
char internal[KRNX_MAXSIGNAL/8]
Definition: krnx.h:217
TKrnxPanelInfo::run_lamp
short run_lamp
Definition: krnx.h:206
khi_robot_control::KhiRobotDriver::contLimitCheck
bool contLimitCheck(const int &cont_no, const int &limit)
Definition: khi_robot_driver.h:257
khi_robot_control::ACTIVATING
@ ACTIVATING
Definition: khi_robot_driver.h:113
krnx_Close
DECLSPEC_IMPORT int WINAPI krnx_Close(int sd)
khi_robot_control::KhiRobotControllerInfo::period
double period
Definition: khi_robot_driver.h:104
TKrnxIoInfo::io_di
char io_di[KRNX_MAXSIGNAL/8]
Definition: krnx.h:216
TKrnxCurMotionData::ang_ref
float ang_ref[KRNX_MAXAXES]
Definition: krnx.h:569
khi_robot_control::KhiRobotKrnxDriver::loadDriverParam
bool loadDriverParam(const int &cont_no, KhiRobotData &data)
Definition: khi_robot_krnx_driver.cpp:481
krnx_OldCompClear
DECLSPEC_IMPORT int WINAPI krnx_OldCompClear(int cont_no, int robot_no)
khi_robot_control::KhiRobotDriver::isTransitionState
bool isTransitionState(const int &cont_no)
Definition: khi_robot_driver.h:209
krnx_GetRtcBufferLength
DECLSPEC_IMPORT int WINAPI krnx_GetRtcBufferLength(int cont_no, int robot_no)
TKrnxRtcInfo::buf
short buf
Definition: krnx.h:291
khi_robot_control::KhiRobotControllerInfo::ip_address
std::string ip_address
Definition: khi_robot_driver.h:103
khi_robot_control::KhiRobotDriver::jointPrint
void jointPrint(std::string name, const KhiRobotData &data)
Definition: khi_robot_driver.h:303
khi_robot_control::KhiRobotKrnxDriver::readData
bool readData(const int &cont_no, KhiRobotData &data) override
Definition: khi_robot_krnx_driver.cpp:564
krnx_GetRtcCompData
DECLSPEC_IMPORT int WINAPI krnx_GetRtcCompData(int cont_no, int robot_no, float *comp)
khi_robot_control::KhiRobotDriver::in_simulation
bool in_simulation
Definition: khi_robot_driver.h:337
khi_robot_control::KhiRobotDriver::setState
bool setState(const int &cont_no, const int &state)
Definition: khi_robot_driver.h:190
khi_robot_control::KhiRobotKrnxDriver::deactivate
bool deactivate(const int &cont_no, const KhiRobotData &data) override
Definition: khi_robot_krnx_driver.cpp:443
krnx_SetMonSpeed
DECLSPEC_IMPORT int WINAPI krnx_SetMonSpeed(int cont_no, int robot_no, float speed, int *as_err_code)
KRNX_MSGSIZE
#define KRNX_MSGSIZE
Definition: khi_robot_krnx_driver.h:78
khi_robot_control::KhiRobotKrnxDriver::conditionCheck
bool conditionCheck(const int &cont_no, const KhiRobotData &data)
Definition: khi_robot_krnx_driver.cpp:147
khi_robot_krnx_driver.h
KHI_MAX_SIG_SIZE
#define KHI_MAX_SIG_SIZE
Definition: khi_robot_driver.h:78
khi_robot_control::INIT
@ INIT
Definition: khi_robot_driver.h:110
krnx_GetKrnxVersion
DECLSPEC_IMPORT int WINAPI krnx_GetKrnxVersion(char *ver_text, int ver_len)
khi_robot_control::HOLD
@ HOLD
Definition: khi_robot_driver.h:142
TKrnxPanelInfo::emergency
short emergency
Definition: krnx.h:209
khi_robot_control::KhiRobotKrnxDriver::sw_dblrefflt
int sw_dblrefflt[KRNX_MAX_CONTROLLER]
Definition: khi_robot_krnx_driver.h:115
del
ROSCPP_DECL bool del(const std::string &key)
khi_robot_control::KhiRobotKrnxDriver::commandHandler
bool commandHandler(khi_robot_msgs::KhiRobotCmd::Request &req, khi_robot_msgs::KhiRobotCmd::Response &res) override
Definition: khi_robot_krnx_driver.cpp:958
data
data
TKrnxCurMotionData::ang
float ang[KRNX_MAXAXES]
Definition: krnx.h:568
khi_robot_control::KhiRobotKrnxDriver::setState
bool setState(const int &cont_no, const int &state)
Definition: khi_robot_krnx_driver.cpp:106
krnx_Open
DECLSPEC_IMPORT int WINAPI krnx_Open(int cont_no, char *hostname)
KRNX_NOERROR
#define KRNX_NOERROR
Definition: krnx.h:103
khi_robot_control::KhiRobotKrnxDriver::setRobotDataHome
bool setRobotDataHome(const int &cont_no, KhiRobotData &data)
Definition: khi_robot_krnx_driver.cpp:646
khi_robot_control::RESTART
@ RESTART
Definition: khi_robot_driver.h:143
TKrnxCurMotionData
Definition: krnx.h:563
khi_robot_control::QUIT
@ QUIT
Definition: khi_robot_driver.h:144
KHI_KRNX_M2MM
#define KHI_KRNX_M2MM
Definition: khi_robot_krnx_driver.cpp:79
khi_robot_control::KhiRobotDriver::warnPrint
void warnPrint(const char *format,...)
Definition: khi_robot_driver.h:281
khi_robot_control::KhiRobotKrnxDriver::rtc_data
KhiRobotKrnxRtcData rtc_data[KRNX_MAX_CONTROLLER]
Definition: khi_robot_krnx_driver.h:119
TKrnxPanelInfo::motor_lamp
short motor_lamp
Definition: krnx.h:203
krnx_GetRobotName
DECLSPEC_IMPORT int WINAPI krnx_GetRobotName(int cont_no, int robot_no, char *robot_name)
khi_robot_control::ACTIVE
@ ACTIVE
Definition: khi_robot_driver.h:114
KHI_KRNX_ACTIVATE_TH
#define KHI_KRNX_ACTIVATE_TH
Definition: khi_robot_krnx_driver.cpp:78
krnx_GetPanelInfo
DECLSPEC_IMPORT int WINAPI krnx_GetPanelInfo(int cont_no, int robot_no, TKrnxPanelInfo *panelinfo)
TKrnxStepperInfo::program_name
char program_name[20]
Definition: krnx.h:244
khi_robot_control::KhiRobotKrnxDriver::syncRtcPos
bool syncRtcPos(const int &cont_no, KhiRobotData &data)
Definition: khi_robot_krnx_driver.cpp:937
khi_robot_control::KhiRobotKrnxDriver::getPeriodDiff
bool getPeriodDiff(const int &cont_no, double &diff) override
Definition: khi_robot_krnx_driver.cpp:812
khi_robot_control::KhiRobotDriver::getStateName
std::string getStateName(const int &cont_no)
Definition: khi_robot_driver.h:176
model.h
khi_robot_control::KhiRobotDriver::infoPrint
void infoPrint(const char *format,...)
Definition: khi_robot_driver.h:270
krnx_GetCurErrorLamp
DECLSPEC_IMPORT int WINAPI krnx_GetCurErrorLamp(int cont_no, int robot_no, int *error_lamp)
khi_robot_control::KhiRobotDriver::cont_info
KhiRobotControllerInfo cont_info[KHI_MAX_CONTROLLER]
Definition: khi_robot_driver.h:339
khi_robot_control::KhiRobotKrnxDriver::~KhiRobotKrnxDriver
~KhiRobotKrnxDriver()
Definition: khi_robot_krnx_driver.cpp:91
krnx_ExecMon
DECLSPEC_IMPORT int WINAPI krnx_ExecMon(int cont_no, const char *cmd, char *buffer, int buffer_sz, int *as_err_code)
TKrnxIoInfo
Definition: krnx.h:212
krnx_SendRtcCompData
DECLSPEC_IMPORT int WINAPI krnx_SendRtcCompData(int cont_no, unsigned short seq_no)
krnx_Execute
DECLSPEC_IMPORT int WINAPI krnx_Execute(int cont_no, int robot_no, const char *program, int exec_num, int step_num, int *as_err_code)
ROS_WARN
#define ROS_WARN(...)
TKrnxPanelInfo::repeat_lamp
short repeat_lamp
Definition: krnx.h:205
KRNX_MOTION_BUF
#define KRNX_MOTION_BUF
Definition: khi_robot_krnx_driver.h:80
khi_robot_control::KhiRobotDriver::setStateTrigger
bool setStateTrigger(const int &cont_no, const int &state_trigger)
Definition: khi_robot_driver.h:237
khi_robot_control::KhiRobotKrnxDriver::updateState
bool updateState(const int &cont_no, const KhiRobotData &data) override
Definition: khi_robot_krnx_driver.cpp:763
krnx_SetRtcInfo
DECLSPEC_IMPORT int WINAPI krnx_SetRtcInfo(int cont_no, TKrnxRtcInfo *rtc_info)
krnx_GetProgramInfo
DECLSPEC_IMPORT int WINAPI krnx_GetProgramInfo(int cont_no, int robot_no, TKrnxProgramInfo *proginfo)
khi_robot_control::KhiRobotKrnxDriver::initialize
bool initialize(const int &cont_no, const double &period, KhiRobotData &data, const bool in_simulation=false) override
Definition: khi_robot_krnx_driver.cpp:198
KHI_MAX_JOINT
#define KHI_MAX_JOINT
Definition: khi_robot_driver.h:77
krnx_Load
DECLSPEC_IMPORT int WINAPI krnx_Load(int cont_no, const char *filename)
khi_robot_control::KhiRobotKrnxDriver::hold
bool hold(const int &cont_no, const KhiRobotData &data) override
Definition: khi_robot_krnx_driver.cpp:427
khi_robot_control::KhiRobotKrnxDriver::KhiRobotKrnxDriver
KhiRobotKrnxDriver()
Definition: khi_robot_krnx_driver.cpp:81
khi_robot_control::KhiRobotDriver::errorPrint
void errorPrint(const char *format,...)
Definition: khi_robot_driver.h:292
khi_robot_control::KhiRobotData
Definition: khi_robot_driver.h:92
krnx_GetCurMotionData
DECLSPEC_IMPORT int WINAPI krnx_GetCurMotionData(int cont_no, int robot_no, TKrnxCurMotionData *md)
TKrnxProgramInfo
Definition: krnx.h:254
krnx_GetCurErrorInfo
DECLSPEC_IMPORT int WINAPI krnx_GetCurErrorInfo(int cont_no, int robot_no, int *error_code)
KHI_MAX_CONTROLLER
#define KHI_MAX_CONTROLLER
Definition: khi_robot_driver.h:75
TKrnxPanelInfo::teach_lock_lamp
short teach_lock_lamp
Definition: krnx.h:208
TKrnxRtcInfo::interpolation
short interpolation
Definition: krnx.h:292
khi_robot_control
Definition: khi_robot_client.h:42
TKrnxPanelInfo::cycle_lamp
short cycle_lamp
Definition: krnx.h:204
krnx_SetRtcCompMask
DECLSPEC_IMPORT int WINAPI krnx_SetRtcCompMask(int cont_no, int robot_no, int mask)
khi_robot_control::KhiRobotKrnxDriver::writeData
bool writeData(const int &cont_no, const KhiRobotData &data) override
Definition: khi_robot_krnx_driver.cpp:685
krnx_Kill
DECLSPEC_IMPORT int WINAPI krnx_Kill(int cont_no, int robot_no, int *as_err_code)
TKrnxRtcInfo::cyc
short cyc
Definition: krnx.h:290
KRNX_MAX_ROBOT
#define KRNX_MAX_ROBOT
Definition: krnx.h:61
KRNX_E_BADARGS
#define KRNX_E_BADARGS
Definition: krnx.h:104
khi_robot_control::KhiRobotKrnxDriver::mutex_state
std::mutex mutex_state[KRNX_MAX_CONTROLLER]
Definition: khi_robot_krnx_driver.h:116
khi_robot_control::DEACTIVATING
@ DEACTIVATING
Definition: khi_robot_driver.h:116
TKrnxIoInfo::io_do
char io_do[KRNX_MAXSIGNAL/8]
Definition: krnx.h:215
khi_robot_control::KhiRobotKrnxDriver::msg_buf
char msg_buf[KRNX_MSGSIZE]
Definition: khi_robot_krnx_driver.h:114
KRNX_MAXAXES
#define KRNX_MAXAXES
Definition: krnx.h:66
TKrnxProgramInfo::robot
TKrnxStepperInfo robot[KRNX_MAX_ROBOT]
Definition: krnx.h:261
khi_robot_control::DISCONNECTED
@ DISCONNECTED
Definition: khi_robot_driver.h:118
KHI_KRNX_BUFFER_SIZE
#define KHI_KRNX_BUFFER_SIZE
Definition: khi_robot_krnx_driver.cpp:77
khi_robot_control::KhiRobotKrnxDriver::splitString
std::vector< std::string > splitString(const std::string &str, const char &del)
Definition: khi_robot_krnx_driver.cpp:850
ros::Duration::sleep
bool sleep() const
khi_robot_control::HOLDED
@ HOLDED
Definition: khi_robot_driver.h:115
khi_robot_control::KhiRobotDriver::error_code
int error_code
Definition: khi_robot_driver.h:341
cmd
string cmd
krnx_GetCurIoInfo
DECLSPEC_IMPORT int WINAPI krnx_GetCurIoInfo(int cont_no, TKrnxIoInfo *ioinfo)
khi_robot_control::KhiRobotKrnxDriver::close
bool close(const int &cont_no) override
Definition: khi_robot_krnx_driver.cpp:253
khi_robot_control::KhiRobotDriver::getState
int getState(const int &cont_no)
Definition: khi_robot_driver.h:170
khi_robot_control::DISCONNECTING
@ DISCONNECTING
Definition: khi_robot_driver.h:117
ros::Duration
KHI_ROBOT_WD002N
#define KHI_ROBOT_WD002N
Definition: khi_robot_krnx_driver.cpp:72
krnx_PrimeRtcCompData
DECLSPEC_IMPORT int WINAPI krnx_PrimeRtcCompData(int cont_no, int robot_no, const float *comp, int *status)
khi_robot_control::KhiRobotKrnxDriver::loadRtcProg
bool loadRtcProg(const int &cont_no, const std::string &name)
Definition: khi_robot_krnx_driver.cpp:868
krnx_GetRtcSwitch
DECLSPEC_IMPORT int WINAPI krnx_GetRtcSwitch(int cont_no, int robot_no, int *rtc_sw)
khi_robot_control::KhiRobotKrnxDriver::retKrnxRes
bool retKrnxRes(const int &cont_no, const std::string &name, const int &ret, const bool error=true)
Definition: khi_robot_krnx_driver.cpp:132
khi_robot_control::KhiRobotKrnxDriver::execAsMonCmd
int execAsMonCmd(const int &cont_no, const char *cmd, char *buffer, int buffer_sz, int *as_err_code)
Definition: khi_robot_krnx_driver.cpp:115


khi_robot_control
Author(s): nakamichi_d
autogenerated on Sat Oct 21 2023 02:54:50