uxbus_cmd.cc
Go to the documentation of this file.
1 /*
2 # Software License Agreement (MIT License)
3 #
4 # Copyright (c) 2018, UFACTORY, Inc.
5 # All rights reserved.
6 #
7 # Author: Vinman <vinman.wen@ufactory.cc> <vinman.cub@gmail.com>
8 */
9 
14 
15 static int BAUDRATES[13] = { 4800, 9600, 19200, 38400, 57600, 115200, 230400, 460800, 921600, 1000000, 1500000, 2000000, 2500000 };
16 
17 static int get_baud_inx(int baud) {
18  for (int i = 0; i < 13; i++) { if (BAUDRATES[i] == baud) return i; }
19  return -1;
20 }
21 
23  state_is_ready = false;
24 }
25 
27 
28 int UxbusCmd::check_xbus_prot(unsigned char *data, int funcode) { return -11; }
29 
30 int UxbusCmd::send_pend(int funcode, int num, int timeout, unsigned char *rx_data) {
31  return -11;
32 }
33 
34 int UxbusCmd::send_xbus(int funcode, unsigned char *txdata, int num) { return -11; }
35 
36 void UxbusCmd::close(void) {}
37 
38 int UxbusCmd::is_ok(void) {return -1;}
39 
40 int UxbusCmd::set_timeout(float timeout) {
41  GET_TIMEOUT_ = (int)(timeout * 1000);
42  SET_TIMEOUT_ = (int)(timeout * 1000);
43  return 0;
44 }
45 
46 
47 /*******************************************************
48  * Uxbus generic protocol function
49  *******************************************************/
50 // new: input argument as char array instead of int array
51 int UxbusCmd::set_nu8_char(int funcode, char *datas, int num) {
52  unsigned char *send_data = new unsigned char[num];
53  for (int i = 0; i < num; i++) { send_data[i] = (unsigned char)datas[i];}
54 
55  std::lock_guard<std::mutex> locker(mutex_);
56  int ret = send_xbus(funcode, send_data, num);
57  delete[] send_data;
58  if (ret != 0) { return UXBUS_STATE::ERR_NOTTCP; }
59  int timeout = (funcode != UXBUS_RG::MOTION_EN || (funcode == UXBUS_RG::MOTION_EN && SET_TIMEOUT_ >= 2)) ? SET_TIMEOUT_ : 2000;
60  ret = send_pend(funcode, 0, timeout, NULL);
61  return ret;
62 }
63 
64 int UxbusCmd::set_nu8(int funcode, int *datas, int num) {
65  unsigned char *send_data = new unsigned char[num];
66  for (int i = 0; i < num; i++) { send_data[i] = (unsigned char)datas[i]; }
67 
68  std::lock_guard<std::mutex> locker(mutex_);
69  int ret = send_xbus(funcode, send_data, num);
70  delete[] send_data;
71  if (ret != 0) { return UXBUS_STATE::ERR_NOTTCP; }
72  int timeout = (funcode != UXBUS_RG::MOTION_EN || (funcode == UXBUS_RG::MOTION_EN && SET_TIMEOUT_ >= 2)) ? SET_TIMEOUT_ : 2000;
73  ret = send_pend(funcode, 0, timeout, NULL);
74  return ret;
75 }
76 
77 int UxbusCmd::get_nu8(int funcode, int *rx_data, int num) {
78  unsigned char *send_data = new unsigned char[num];
79  int ret = get_nu8(funcode, send_data, num);
80  for (int i = 0; i < num; i++) { rx_data[i] = send_data[i]; }
81  delete[] send_data;
82  return ret;
83 }
84 
85 int UxbusCmd::get_nu8(int funcode, unsigned char *rx_data, int num) {
86  std::lock_guard<std::mutex> locker(mutex_);
87  int ret = send_xbus(funcode, 0, 0);
88  if (ret != 0) { return UXBUS_STATE::ERR_NOTTCP; }
89  return send_pend(funcode, num, GET_TIMEOUT_, rx_data);
90 }
91 
92 int UxbusCmd::set_nu16(int funcode, int *datas, int num) {
93  unsigned char *send_data = new unsigned char[num * 2];
94  for (int i = 0; i < num; i++) { bin16_to_8(datas[i], &send_data[i * 2]); }
95 
96  std::lock_guard<std::mutex> locker(mutex_);
97  int ret = send_xbus(funcode, send_data, num * 2);
98  delete[] send_data;
99  if (ret != 0) { return UXBUS_STATE::ERR_NOTTCP; }
100  return send_pend(funcode, 0, SET_TIMEOUT_, NULL);
101 }
102 
103 int UxbusCmd::get_nu16(int funcode, int *rx_data, int num) {
104  std::lock_guard<std::mutex> locker(mutex_);
105  int ret = send_xbus(funcode, 0, 0);
106  if (ret != 0) { return UXBUS_STATE::ERR_NOTTCP; }
107  unsigned char *datas = new unsigned char[num * 2];
108  ret = send_pend(funcode, num * 2, GET_TIMEOUT_, datas);
109  for (int i = 0; i < num; i++) { rx_data[i] = bin8_to_16(&datas[i * 2]); }
110  delete[] datas;
111  return ret;
112 }
113 
114 int UxbusCmd::set_nfp32(int funcode, float *datas, int num) {
115  unsigned char *send_data = new unsigned char[num * 4];
116  nfp32_to_hex(datas, send_data, num);
117 
118  std::lock_guard<std::mutex> locker(mutex_);
119  int ret = send_xbus(funcode, send_data, num * 4);
120  delete[] send_data;
121  if (0 != ret) { return UXBUS_STATE::ERR_NOTTCP; }
122  ret = send_pend(funcode, 0, SET_TIMEOUT_, NULL);
123  return ret;
124 }
125 
126 int UxbusCmd::set_nint32(int funcode, int *datas, int num) {
127  unsigned char *send_data = new unsigned char[num * 4];
128  nint32_to_hex(datas, send_data, num);
129 
130  std::lock_guard<std::mutex> locker(mutex_);
131  int ret = send_xbus(funcode, send_data, num * 4);
132  delete[] send_data;
133  if (0 != ret) { return UXBUS_STATE::ERR_NOTTCP; }
134  return send_pend(funcode, 0, SET_TIMEOUT_, NULL);
135 }
136 
137 int UxbusCmd::get_nfp32(int funcode, float *rx_data, int num) {
138  std::lock_guard<std::mutex> locker(mutex_);
139  int ret = send_xbus(funcode, 0, 0);
140  if (0 != ret) { return UXBUS_STATE::ERR_NOTTCP; }
141  unsigned char *datas = new unsigned char[num * 4];
142  ret = send_pend(funcode, num * 4, GET_TIMEOUT_, datas);
143  hex_to_nfp32(datas, rx_data, num);
144  delete[] datas;
145  return ret;
146 }
147 
148 int UxbusCmd::swop_nfp32(int funcode, float tx_datas[], int txn, float *rx_data, int rxn) {
149  unsigned char *send_data = new unsigned char[128];
150  nfp32_to_hex(tx_datas, send_data, txn);
151 
152  std::lock_guard<std::mutex> locker(mutex_);
153  int ret = send_xbus(funcode, send_data, txn * 4);
154  delete[] send_data;
155  if (0 != ret) { return UXBUS_STATE::ERR_NOTTCP; }
156  unsigned char *datas = new unsigned char[128];
157  ret = send_pend(funcode, rxn * 4, GET_TIMEOUT_, datas);
158  hex_to_nfp32(datas, rx_data, rxn);
159  delete[] datas;
160  return ret;
161 }
162 
163 int UxbusCmd::is_nfp32(int funcode, float tx_datas[], int txn, int *value) {
164  unsigned char *send_data = new unsigned char[txn * 4];
165  nfp32_to_hex(tx_datas, send_data, txn);
166 
167  std::lock_guard<std::mutex> locker(mutex_);
168  int ret = send_xbus(funcode, send_data, txn * 4);
169  delete[] send_data;
170  if (0 != ret) { return UXBUS_STATE::ERR_NOTTCP; }
171  unsigned char *rx_data = new unsigned char[txn * 4];
172  ret = send_pend(funcode, 1, GET_TIMEOUT_, rx_data);
173  *value = rx_data[0];
174  delete[] rx_data;
175  return ret;
176 }
177 
178 int UxbusCmd::set_nfp32_with_bytes(int funcode, float *tx_datas, int num, char *additional, int len) {
179  unsigned char *send_data = new unsigned char[num * 4 + len];
180  nfp32_to_hex(tx_datas, send_data, num);
181  for (int i = 0; i < len; i++) { send_data[num * 4 + i] = additional[i]; }
182 
183  std::lock_guard<std::mutex> locker(mutex_);
184  int ret = send_xbus(funcode, send_data, num * 4 + len);
185  delete[] send_data;
186  if (0 != ret) { return UXBUS_STATE::ERR_NOTTCP; }
187  ret = send_pend(funcode, 0, SET_TIMEOUT_, NULL);
188  return ret;
189 }
190 
191 /*******************************************************
192  * controler setting
193  *******************************************************/
194 int UxbusCmd::get_version(unsigned char rx_data[40]) {
195  return get_nu8(UXBUS_RG::GET_VERSION, rx_data, 40);
196 }
197 
198 int UxbusCmd::get_robot_sn(unsigned char rx_data[40]) {
199  return get_nu8(UXBUS_RG::GET_ROBOT_SN, rx_data, 40);
200 }
201 
202 int UxbusCmd::check_verification(int *rx_data) {
203  return get_nu8(UXBUS_RG::CHECK_VERIFY, rx_data, 1);
204 }
205 
207  return set_nu8(UXBUS_RG::SHUTDOWN_SYSTEM, &value, 1);
208 }
209 
211  int txdata[1] = { value };
212  return set_nu8(UXBUS_RG::SET_TRAJ_RECORD, txdata, 1);
213 }
214 
215 int UxbusCmd::playback_traj(int times, int spdx) {
216  int txdata[2] = { times, spdx };
217  return set_nint32(UXBUS_RG::PLAY_TRAJ, txdata, 2);
218 }
219 
221  int txdata[1] = { times };
222  return set_nint32(UXBUS_RG::PLAY_TRAJ, txdata, 1);
223 }
224 
225 int UxbusCmd::save_traj(char filename[81]) {
226  return set_nu8_char(UXBUS_RG::SAVE_TRAJ, filename, 81);
227 }
228 
229 int UxbusCmd::load_traj(char filename[81]) {
230  return set_nu8_char(UXBUS_RG::LOAD_TRAJ, filename, 81);
231 }
232 
233 int UxbusCmd::get_traj_rw_status(int *rx_data) {
234  return get_nu8(UXBUS_RG::GET_TRAJ_RW_STATUS, rx_data, 1);
235 }
236 
237 int UxbusCmd::set_reduced_mode(int on_off) {
238  int txdata[1] = { on_off };
239  return set_nu8(UXBUS_RG::SET_REDUCED_MODE, txdata, 1);
240 }
241 
243  float txdata[1] = { lspd_mm };
244  return set_nfp32(UXBUS_RG::SET_REDUCED_TRSV, txdata, 1);
245 }
246 
247 int UxbusCmd::set_reduced_jointspeed(float jspd_rad) {
248  float txdata[1] = { jspd_rad };
249  return set_nfp32(UXBUS_RG::SET_REDUCED_P2PV, txdata, 1);
250 }
251 
252 int UxbusCmd::get_reduced_mode(int *rx_data) {
253  return get_nu8(UXBUS_RG::GET_REDUCED_MODE, rx_data, 1);
254 }
255 
256 int UxbusCmd::get_reduced_states(int *on, int xyz_list[6], float *tcp_speed, float *joint_speed, float jrange_rad[14], int *fense_is_on, int *collision_rebound_is_on, int length) {
257  unsigned char *rx_data = new unsigned char[length];
258  int ret = get_nu8(UXBUS_RG::GET_REDUCED_STATE, rx_data, length);
259  *on = rx_data[0];
260  bin8_to_ns16(&rx_data[1], xyz_list, 6);
261  *tcp_speed = hex_to_fp32(&rx_data[13]);
262  *joint_speed = hex_to_fp32(&rx_data[17]);
263  if (length == 79) {
264  if (jrange_rad != NULL) { hex_to_nfp32(&rx_data[21], jrange_rad, 14); }
265  if (fense_is_on != NULL) { *fense_is_on = rx_data[77]; }
266  if (collision_rebound_is_on != NULL) { *collision_rebound_is_on = rx_data[78]; }
267  }
268  delete[] rx_data;
269  return ret;
270 }
271 
272 int UxbusCmd::set_xyz_limits(int xyz_list[6]) {
273  return set_nint32(UXBUS_RG::SET_LIMIT_XYZ, xyz_list, 6);
274 }
275 
276 int UxbusCmd::set_world_offset(float pose_offset[6]) {
277  return set_nfp32(UXBUS_RG::SET_WORLD_OFFSET, pose_offset, 6);
278 }
279 
281  return set_nu8(UXBUS_RG::CNTER_RESET, 0, 0);
282 }
283 
285  return set_nu8(UXBUS_RG::CNTER_PLUS, 0, 0);
286 }
287 
288 int UxbusCmd::set_reduced_jrange(float jrange_rad[14]) {
289  return set_nfp32(UXBUS_RG::SET_REDUCED_JRANGE, jrange_rad, 14);
290 }
291 
292 int UxbusCmd::set_fense_on(int on_off) {
293  int txdata[1] = { on_off };
294  return set_nu8(UXBUS_RG::SET_FENSE_ON, txdata, 1);
295 }
296 
297 int UxbusCmd::set_collis_reb(int on_off) {
298  int txdata[1] = { on_off };
299  return set_nu8(UXBUS_RG::SET_COLLIS_REB, txdata, 1);
300 }
301 
302 int UxbusCmd::motion_en(int id, int value) {
303  int txdata[2] = { id, value };
304  return set_nu8(UXBUS_RG::MOTION_EN, txdata, 2);
305 }
306 
307 int UxbusCmd::set_state(int value) {
308  return set_nu8(UXBUS_RG::SET_STATE, &value, 1);
309 }
310 
311 int UxbusCmd::get_state(int *rx_data) {
312  return get_nu8(UXBUS_RG::GET_STATE, rx_data, 1);
313 }
314 
315 int UxbusCmd::get_cmdnum(int *rx_data) {
316  return get_nu16(UXBUS_RG::GET_CMDNUM, rx_data, 1);
317 }
318 
319 int UxbusCmd::get_err_code(int * rx_data) {
320  return get_nu8(UXBUS_RG::GET_ERROR, rx_data, 2);
321 }
322 
323 int UxbusCmd::get_hd_types(int *rx_data) {
324  return get_nu8(UXBUS_RG::GET_HD_TYPES, rx_data, 2);
325 }
326 
328  int txdata[1] = { 0 };
329  return set_nu8(UXBUS_RG::RELOAD_DYNAMICS, txdata, 0);
330 }
331 
333  int txdata[1] = { 0 };
334  return set_nu8(UXBUS_RG::CLEAN_ERR, txdata, 0);
335 }
336 
338  int txdata[1] = { 0 };
339  return set_nu8(UXBUS_RG::CLEAN_WAR, txdata, 0);
340 }
341 
342 int UxbusCmd::set_brake(int axis, int en) {
343  int txdata[2] = { axis, en };
344  return set_nu8(UXBUS_RG::SET_BRAKE, txdata, 2);
345 }
346 
347 int UxbusCmd::set_mode(int value) {
348  int txdata[1] = { value };
349  return set_nu8(UXBUS_RG::SET_MODE, txdata, 1);
350 }
351 
352 /*******************************************************
353  * controler motion
354  *******************************************************/
355 int UxbusCmd::move_line(float mvpose[6], float mvvelo, float mvacc, float mvtime) {
356  float txdata[9] = { 0 };
357  for (int i = 0; i < 6; i++) { txdata[i] = mvpose[i]; }
358  txdata[6] = mvvelo;
359  txdata[7] = mvacc;
360  txdata[8] = mvtime;
361  return set_nfp32(UXBUS_RG::MOVE_LINE, txdata, 9);
362 }
363 
364 int UxbusCmd::move_lineb(float mvpose[6], float mvvelo, float mvacc, float mvtime,
365  float mvradii) {
366  float txdata[10] = { 0 };
367  for (int i = 0; i < 6; i++) { txdata[i] = mvpose[i]; }
368  txdata[6] = mvvelo;
369  txdata[7] = mvacc;
370  txdata[8] = mvtime;
371  txdata[9] = mvradii;
372 
373  return set_nfp32(UXBUS_RG::MOVE_LINEB, txdata, 10);
374 }
375 
376 int UxbusCmd::move_joint(float mvjoint[7], float mvvelo, float mvacc,
377  float mvtime) {
378  float txdata[10] = { 0 };
379  for (int i = 0; i < 7; i++) { txdata[i] = mvjoint[i]; }
380  txdata[7] = mvvelo;
381  txdata[8] = mvacc;
382  txdata[9] = mvtime;
383  return set_nfp32(UXBUS_RG::MOVE_JOINT, txdata, 10);
384 }
385 
386 int UxbusCmd::move_jointb(float mvjoint[7], float mvvelo, float mvacc, float mvradii) {
387  float txdata[10] = { 0 };
388  for (int i = 0; i < 7; i++) { txdata[i] = mvjoint[i]; }
389  txdata[7] = mvvelo;
390  txdata[8] = mvacc;
391  txdata[9] = mvradii;
392  return set_nfp32(UXBUS_RG::MOVE_JOINTB, txdata, 10);
393 }
394 
395 int UxbusCmd::move_line_tool(float mvpose[6], float mvvelo, float mvacc, float mvtime) {
396  float txdata[9] = { 0 };
397  for (int i = 0; i < 6; i++) { txdata[i] = mvpose[i]; }
398  txdata[6] = mvvelo;
399  txdata[7] = mvacc;
400  txdata[8] = mvtime;
401  return set_nfp32(UXBUS_RG::MOVE_LINE_TOOL, txdata, 9);
402 }
403 
404 int UxbusCmd::move_gohome(float mvvelo, float mvacc, float mvtime) {
405  float txdata[3] = { 0 };
406  txdata[0] = mvvelo;
407  txdata[1] = mvacc;
408  txdata[2] = mvtime;
409  return set_nfp32(UXBUS_RG::MOVE_HOME, txdata, 3);
410 }
411 
412 int UxbusCmd::move_servoj(float mvjoint[7], float mvvelo, float mvacc, float mvtime) {
413  float txdata[10] = { 0 };
414  for (int i = 0; i < 7; i++) { txdata[i] = mvjoint[i]; }
415  txdata[7] = mvvelo;
416  txdata[8] = mvacc;
417  txdata[9] = mvtime;
418  return set_nfp32(UXBUS_RG::MOVE_SERVOJ, txdata, 10);
419 }
420 
421 int UxbusCmd::move_servo_cartesian(float mvpose[6], float mvvelo, float mvacc, float mvtime) {
422  float txdata[9] = { 0 };
423  for (int i = 0; i < 6; i++) { txdata[i] = mvpose[i]; }
424  txdata[6] = mvvelo;
425  txdata[7] = mvacc;
426  txdata[8] = mvtime;
427  return set_nfp32(UXBUS_RG::MOVE_SERVO_CART, txdata, 9);
428 }
429 
430 int UxbusCmd::set_servot(float jnt_taus[7]) {
431  float txdata[7] = { 0 };
432  for (int i = 0; i < 7; i++) { txdata[i] = jnt_taus[i]; }
433  return set_nfp32(UXBUS_RG::SET_SERVOT, txdata, 7);
434 }
435 
436 int UxbusCmd::get_joint_tau(float jnt_taus[7]) {
437  return get_nfp32(UXBUS_RG::GET_JOINT_TAU, jnt_taus, 7);
438 }
439 
440 int UxbusCmd::set_safe_level(int level) {
441  int txdata[1] = { level };
442  return set_nu8(UXBUS_RG::SET_SAFE_LEVEL, txdata, 1);
443 }
444 
445 int UxbusCmd::get_safe_level(int *level) {
446  return get_nu8(UXBUS_RG::GET_SAFE_LEVEL, level, 1);
447 }
448 
449 int UxbusCmd::sleep_instruction(float sltime) {
450  float txdata[1] = { sltime };
451  return set_nfp32(UXBUS_RG::SLEEP_INSTT, txdata, 1);
452 }
453 
454 int UxbusCmd::move_circle(float pose1[6], float pose2[6], float mvvelo, float mvacc, float mvtime, float percent) {
455 
456  float txdata[16] = { 0 };
457  for (int i = 0; i < 6; i++) {
458  txdata[i] = pose1[i];
459  txdata[6 + i] = pose2[i];
460  }
461  txdata[12] = mvvelo;
462  txdata[13] = mvacc;
463  txdata[14] = mvtime;
464  txdata[15] = percent;
465 
466  return set_nfp32(UXBUS_RG::MOVE_CIRCLE, txdata, 16);
467 }
468 
469 int UxbusCmd::set_tcp_jerk(float jerk) {
470  float txdata[1] = { jerk };
471  return set_nfp32(UXBUS_RG::SET_TCP_JERK, txdata, 1);
472 }
473 
474 int UxbusCmd::set_tcp_maxacc(float maxacc) {
475  float txdata[1] = { maxacc };
476  return set_nfp32(UXBUS_RG::SET_TCP_MAXACC, txdata, 1);
477 }
478 
479 int UxbusCmd::set_joint_jerk(float jerk) {
480  float txdata[1] = { jerk };
481  return set_nfp32(UXBUS_RG::SET_JOINT_JERK, txdata, 1);
482 }
483 
484 int UxbusCmd::set_joint_maxacc(float maxacc) {
485  float txdata[1] = { maxacc };
486  return set_nfp32(UXBUS_RG::SET_JOINT_MAXACC, txdata, 1);
487 }
488 
489 int UxbusCmd::set_tcp_offset(float pose_offset[6]) {
490  return set_nfp32(UXBUS_RG::SET_TCP_OFFSET, pose_offset, 6);
491 }
492 
493 int UxbusCmd::set_tcp_load(float mass, float load_offset[3]) {
494  float txdata[4] = { mass, load_offset[0], load_offset[1], load_offset[2] };
495  return set_nfp32(UXBUS_RG::SET_LOAD_PARAM, txdata, 4);
496 }
497 
499  return set_nu8(UXBUS_RG::SET_TEACH_SENS, &value, 1);
500 }
501 
502 int UxbusCmd::set_teach_sens(int value) {
503  return set_nu8(UXBUS_RG::SET_TEACH_SENS, &value, 1);
504 }
505 
506 int UxbusCmd::set_gravity_dir(float gravity_dir[3]) {
507  return set_nfp32(UXBUS_RG::SET_GRAVITY_DIR, gravity_dir, 3);
508 }
509 
511  return set_nu8(UXBUS_RG::CLEAN_CONF, 0, 0);
512 }
513 
515  return set_nu8(UXBUS_RG::SAVE_CONF, 0, 0);
516 }
517 
518 int UxbusCmd::get_tcp_pose(float pose[6]) {
519  return get_nfp32(UXBUS_RG::GET_TCP_POSE, pose, 6);
520 }
521 
522 int UxbusCmd::get_joint_pose(float angles[7]) {
523  return get_nfp32(UXBUS_RG::GET_JOINT_POS, angles, 7);
524 }
525 
526 int UxbusCmd::get_ik(float pose[6], float angles[7]) {
527  return swop_nfp32(UXBUS_RG::GET_IK, pose, 6, angles, 7);
528 }
529 
530 int UxbusCmd::get_fk(float angles[7], float pose[6]) {
531  return swop_nfp32(UXBUS_RG::GET_FK, angles, 7, pose, 6);
532 }
533 
534 int UxbusCmd::is_joint_limit(float joint[7], int *value) {
535  return is_nfp32(UXBUS_RG::IS_JOINT_LIMIT, joint, 7, value);
536 }
537 
538 int UxbusCmd::is_tcp_limit(float pose[6], int *value) {
539  return is_nfp32(UXBUS_RG::IS_TCP_LIMIT, pose, 6, value);
540 }
541 
542 /*******************************************************
543  * gripper
544  *******************************************************/
545 int UxbusCmd::gripper_addr_w16(int addr, float value) {
546  unsigned char *txdata = new unsigned char[7];
547  txdata[0] = UXBUS_CONF::GRIPPER_ID;
548  bin16_to_8(addr, &txdata[1]);
549  fp32_to_hex(value, &txdata[3]);
550 
551  std::lock_guard<std::mutex> locker(mutex_);
552  int ret = send_xbus(UXBUS_RG::TGPIO_W16B, txdata, 7);
553  delete[] txdata;
554  if (0 != ret) { return UXBUS_STATE::ERR_NOTTCP; }
555  return send_pend(UXBUS_RG::TGPIO_W16B, 0, GET_TIMEOUT_, NULL);
556 }
557 
558 int UxbusCmd::gripper_addr_r16(int addr, float *value) {
559  unsigned char *txdata = new unsigned char[3];
560  txdata[0] = UXBUS_CONF::GRIPPER_ID;
561  bin16_to_8(addr, &txdata[1]);
562 
563  std::lock_guard<std::mutex> locker(mutex_);
564  int ret = send_xbus(UXBUS_RG::TGPIO_R16B, txdata, 3);
565  delete[] txdata;
566  if (0 != ret) { return UXBUS_STATE::ERR_NOTTCP; }
567  unsigned char *rx_data = new unsigned char[4];
568  ret = send_pend(UXBUS_RG::TGPIO_R16B, 4, GET_TIMEOUT_, rx_data);
569  *value = (float)bin8_to_32(rx_data);
570  delete[] rx_data;
571  return ret;
572 }
573 
574 int UxbusCmd::gripper_addr_w32(int addr, float value) {
575  unsigned char *txdata = new unsigned char[7];
576  txdata[0] = UXBUS_CONF::GRIPPER_ID;
577  bin16_to_8(addr, &txdata[1]);
578  fp32_to_hex(value, &txdata[3]);
579 
580  std::lock_guard<std::mutex> locker(mutex_);
581  int ret = send_xbus(UXBUS_RG::TGPIO_W32B, txdata, 7);
582  delete[] txdata;
583  if (0 != ret) { return UXBUS_STATE::ERR_NOTTCP; }
584  return send_pend(UXBUS_RG::TGPIO_W32B, 0, GET_TIMEOUT_, NULL);
585 }
586 
587 int UxbusCmd::gripper_addr_r32(int addr, float *value) {
588  unsigned char *txdata = new unsigned char[3];
589  txdata[0] = UXBUS_CONF::GRIPPER_ID;
590  bin16_to_8(addr, &txdata[1]);
591 
592  std::lock_guard<std::mutex> locker(mutex_);
593  int ret = send_xbus(UXBUS_RG::TGPIO_R32B, txdata, 3);
594  delete[] txdata;
595  if (0 != ret) { return UXBUS_STATE::ERR_NOTTCP; }
596  unsigned char *rx_data = new unsigned char[4];
597  ret = send_pend(UXBUS_RG::TGPIO_R32B, 4, GET_TIMEOUT_, rx_data);
598  *value = (float)bin8_to_32(rx_data);
599  delete[] rx_data;
600  return ret;
601 }
602 
603 int UxbusCmd::gripper_set_en(int value) {
604  return gripper_addr_w16(SERVO3_RG::CON_EN, (float)value);
605 }
606 
608  return gripper_addr_w16(SERVO3_RG::CON_MODE, (float)value);
609 }
610 
613 }
614 
615 int UxbusCmd::gripper_get_pos(float *pulse) {
616  return gripper_addr_r32(SERVO3_RG::CURR_POS, pulse);
617 }
618 
619 int UxbusCmd::gripper_set_pos(float pulse) {
620  return gripper_addr_w32(SERVO3_RG::TAGET_POS, pulse);
621 }
622 
624  return gripper_addr_w16(SERVO3_RG::POS_SPD, speed);
625 }
626 
627 int UxbusCmd::gripper_get_errcode(int rx_data[2]) {
628  return get_nu8(UXBUS_RG::TGPIO_ERR, rx_data, 2);
629 }
630 
633 }
634 
635 /*******************************************************
636  * tool gpio
637  *******************************************************/
638 int UxbusCmd::tgpio_addr_w16(int addr, float value) {
639  unsigned char *txdata = new unsigned char[7];
640  txdata[0] = UXBUS_CONF::TGPIO_ID;
641  bin16_to_8(addr, &txdata[1]);
642  fp32_to_hex(value, &txdata[3]);
643 
644  std::lock_guard<std::mutex> locker(mutex_);
645  int ret = send_xbus(UXBUS_RG::TGPIO_W16B, txdata, 7);
646  delete[] txdata;
647  if (0 != ret) { return UXBUS_STATE::ERR_NOTTCP; }
648  return send_pend(UXBUS_RG::TGPIO_W16B, 0, GET_TIMEOUT_, NULL);
649 }
650 
651 int UxbusCmd::tgpio_addr_r16(int addr, float *value) {
652  unsigned char *txdata = new unsigned char[3];
653  txdata[0] = UXBUS_CONF::TGPIO_ID;
654  bin16_to_8(addr, &txdata[1]);
655 
656  std::lock_guard<std::mutex> locker(mutex_);
657  int ret = send_xbus(UXBUS_RG::TGPIO_R16B, txdata, 3);
658  delete[] txdata;
659  if (0 != ret) { return UXBUS_STATE::ERR_NOTTCP; }
660  unsigned char *rx_data = new unsigned char[4];
661  ret = send_pend(UXBUS_RG::TGPIO_R16B, 4, GET_TIMEOUT_, rx_data);
662  *value = (float)bin8_to_32(rx_data);
663  delete[] rx_data;
664  return ret;
665 }
666 int UxbusCmd::tgpio_addr_w32(int addr, float value) {
667  unsigned char *txdata = new unsigned char[7];
668  txdata[0] = UXBUS_CONF::TGPIO_ID;
669  bin16_to_8(addr, &txdata[1]);
670  fp32_to_hex(value, &txdata[3]);
671 
672  std::lock_guard<std::mutex> locker(mutex_);
673  int ret = send_xbus(UXBUS_RG::TGPIO_W32B, txdata, 7);
674  delete[] txdata;
675  if (0 != ret) { return UXBUS_STATE::ERR_NOTTCP; }
676  return send_pend(UXBUS_RG::TGPIO_W32B, 0, GET_TIMEOUT_, NULL);
677 }
678 
679 int UxbusCmd::tgpio_addr_r32(int addr, float *value) {
680  unsigned char *txdata = new unsigned char[3];
681  txdata[0] = UXBUS_CONF::TGPIO_ID;
682  bin16_to_8(addr, &txdata[1]);
683 
684  std::lock_guard<std::mutex> locker(mutex_);
685  int ret = send_xbus(UXBUS_RG::TGPIO_R32B, txdata, 3);
686  delete[] txdata;
687  if (0 != ret) { return UXBUS_STATE::ERR_NOTTCP; }
688  unsigned char *rx_data = new unsigned char[4];
689  ret = send_pend(UXBUS_RG::TGPIO_R32B, 4, GET_TIMEOUT_, rx_data);
690  *value = (float)bin8_to_32(rx_data);
691  delete[] rx_data;
692  return ret;
693 }
694 
695 int UxbusCmd::tgpio_get_digital(int *io1, int *io2) {
696  float tmp;
697  int ret = tgpio_addr_r16(SERVO3_RG::DIGITAL_IN, &tmp);
698 
699  *io1 = (int)tmp & 0x0001;
700  *io2 = ((int)tmp & 0x0002) >> 1;
701  return ret;
702 }
703 
704 int UxbusCmd::tgpio_set_digital(int ionum, int value) {
705  int tmp = 0;
706  if (ionum == 1) {
707  tmp = tmp | 0x0100;
708  if (value) { tmp = tmp | 0x0001; }
709  }
710  else if (ionum == 2) {
711  tmp = tmp | 0x0200;
712  if (value) { tmp = tmp | 0x0002; }
713  }
714  else {
715  return -1;
716  }
717  return tgpio_addr_w16(SERVO3_RG::DIGITAL_OUT, (float)tmp);
718 }
719 
720 int UxbusCmd::tgpio_get_analog1(float * value) {
721  float tmp;
722  int ret = tgpio_addr_r16(SERVO3_RG::ANALOG_IO1, &tmp);
723  *value = (float)(tmp * 3.3 / 4095.0);
724  return ret;
725 }
726 
727 int UxbusCmd::tgpio_get_analog2(float * value) {
728  float tmp;
729  int ret = tgpio_addr_r16(SERVO3_RG::ANALOG_IO2, &tmp);
730  // printf("tmp = %f\n", tmp);
731  *value = (float)(tmp * 3.3 / 4095.0);
732  return ret;
733 }
734 
735 /*******************************************************
736  * tgpio modbus
737  *******************************************************/
738 
740  return set_nu16(UXBUS_RG::TGPIO_MB_TIOUT, &value, 1);
741 }
742 
744  float val;
745  int baud_inx = get_baud_inx(baud);
746  if (baud_inx == -1) return -1;
747  int ret = tgpio_addr_r16(SERVO3_RG::MODBUS_BAUDRATE & 0x0FFF, &val);
748  if (ret == 0) {
749  int baud_i = (int)val;
750  if (baud_i != baud_inx) {
751  // tgpio_addr_w16(SERVO3_RG::MODBUS_BAUDRATE, (float)baud_inx);
752  tgpio_addr_w16(0x1a0b, (float)baud_inx);
753  sleep_milliseconds(300);
755  }
756  }
757  return ret;
758 }
759 
760 int UxbusCmd::tgpio_set_modbus(unsigned char *modbus_t, int len_t, unsigned char *rx_data) {
761  unsigned char *txdata = new unsigned char[len_t + 1];
762  txdata[0] = UXBUS_CONF::TGPIO_ID;
763  for (int i = 0; i < len_t; i++) { txdata[i + 1] = modbus_t[i]; }
764 
765  std::lock_guard<std::mutex> locker(mutex_);
766  int ret = send_xbus(UXBUS_RG::TGPIO_MODBUS, txdata, len_t + 1);
767  delete[] txdata;
768  if (0 != ret) { return UXBUS_STATE::ERR_NOTTCP; }
769 
770  ret = send_pend(UXBUS_RG::TGPIO_MODBUS, -1, SET_TIMEOUT_, rx_data);
771  return ret;
772 }
773 
774 int UxbusCmd::gripper_modbus_w16s(int addr, float value, int len) {
775  unsigned char *txdata = new unsigned char[9];
776  unsigned char *rx_data = new unsigned char[254];
777  txdata[0] = UXBUS_CONF::GRIPPER_ID;
778  txdata[1] = 0x10;
779  bin16_to_8(addr, &txdata[2]);
780  bin16_to_8(len, &txdata[4]);
781  txdata[6] = len * 2;
782  fp32_to_hex(value, &txdata[7]);
783  int ret = tgpio_set_modbus(txdata, len * 2 + 7, rx_data);
784  delete[] txdata;
785  delete[] rx_data;
786  return ret;
787 }
788 
789 int UxbusCmd::gripper_modbus_r16s(int addr, int len, unsigned char *rx_data) {
790  unsigned char *txdata = new unsigned char[6];
791  txdata[0] = UXBUS_CONF::GRIPPER_ID;
792  txdata[1] = 0x03;
793  bin16_to_8(addr, &txdata[2]);
794  bin16_to_8(len, &txdata[4]);
795  int ret = tgpio_set_modbus(txdata, 6, rx_data);
796  delete[] txdata;
797  return ret;
798 }
799 
801  unsigned char *txdata = new unsigned char[2];
802  bin16_to_8(value, &txdata[0]);
803  float _value = hex_to_fp32(txdata);
804  delete[] txdata;
805  return gripper_modbus_w16s(SERVO3_RG::CON_EN, _value, 1);
806 }
807 
809  unsigned char *txdata = new unsigned char[2];
810  bin16_to_8(value, &txdata[0]);
811  float _value = hex_to_fp32(txdata);
812  delete[] txdata;
813  return gripper_modbus_w16s(SERVO3_RG::CON_MODE, _value, 1);
814 }
815 
818 }
819 
821  unsigned char *rx_data = new unsigned char[254];
822  int ret = gripper_modbus_r16s(SERVO3_RG::CURR_POS, 2, rx_data);
823  *pulse = (float)bin8_to_32(&rx_data[4]);
824  delete[] rx_data;
825  return ret;
826 }
827 
829  unsigned char *txdata = new unsigned char[4];
830  txdata[0] = ((int)pulse >> 24) & 0xFF;
831  txdata[1] = ((int)pulse >> 16) & 0xFF;
832  txdata[2] = ((int)pulse >> 8) & 0xFF;
833  txdata[3] = (int)pulse & 0xFF;
834  float value = hex_to_fp32(txdata);
835  delete[] txdata;
836  return gripper_modbus_w16s(SERVO3_RG::TAGET_POS, value, 2);
837 }
838 
840  unsigned char *txdata = new unsigned char[2];
841  bin16_to_8((int)speed, &txdata[0]);
842  float value = hex_to_fp32(txdata);
843  delete[] txdata;
844  return gripper_modbus_w16s(SERVO3_RG::POS_SPD, value, 1);
845 }
846 
848  unsigned char *rx_data = new unsigned char[254];
849  int ret = gripper_modbus_r16s(SERVO3_RG::ERR_CODE, 1, rx_data);
850  *err = bin8_to_16(&rx_data[4]);
851  delete[] rx_data;
852  return ret;
853 }
854 
857 }
858 
859 /*******************************************************
860  * uservo
861  *******************************************************/
863  return set_nu8(UXBUS_RG::SERVO_ZERO, &id, 1);
864 }
865 
866 int UxbusCmd::servo_get_dbmsg(int rx_data[16]) {
867  return get_nu8(UXBUS_RG::SERVO_DBMSG, rx_data, 16);
868 }
869 
870 int UxbusCmd::servo_addr_w16(int id, int addr, float value) {
871  unsigned char *txdata = new unsigned char[7];
872  txdata[0] = id;
873  bin16_to_8(addr, &txdata[1]);
874  fp32_to_hex(value, &txdata[3]);
875 
876  std::lock_guard<std::mutex> locker(mutex_);
877  int ret = send_xbus(UXBUS_RG::SERVO_W16B, txdata, 7);
878  delete[] txdata;
879  if (0 != ret) { return UXBUS_STATE::ERR_NOTTCP; }
880  return send_pend(UXBUS_RG::SERVO_W16B, 0, SET_TIMEOUT_, NULL);
881 }
882 
883 int UxbusCmd::servo_addr_r16(int id, int addr, float *value) {
884  unsigned char *txdata = new unsigned char[3];
885  txdata[0] = id;
886  bin16_to_8(addr, &txdata[1]);
887 
888  std::lock_guard<std::mutex> locker(mutex_);
889  int ret = send_xbus(UXBUS_RG::SERVO_R16B, txdata, 3);
890  delete[] txdata;
891  if (0 != ret) { return UXBUS_STATE::ERR_NOTTCP; }
892  unsigned char *rx_data = new unsigned char[4];
893  ret = send_pend(UXBUS_RG::SERVO_R16B, 4, GET_TIMEOUT_, rx_data);
894  *value = (float)bin8_to_32(rx_data);
895  delete[] rx_data;
896  return ret;
897 }
898 
899 int UxbusCmd::servo_addr_w32(int id, int addr, float value) {
900  unsigned char *txdata = new unsigned char[7];
901  txdata[0] = id;
902  bin16_to_8(addr, &txdata[1]);
903  fp32_to_hex(value, &txdata[3]);
904 
905  std::lock_guard<std::mutex> locker(mutex_);
906  int ret = send_xbus(UXBUS_RG::SERVO_W32B, txdata, 7);
907  delete[] txdata;
908  if (0 != ret) { return UXBUS_STATE::ERR_NOTTCP; }
909  return send_pend(UXBUS_RG::SERVO_W32B, 0, SET_TIMEOUT_, NULL);
910 }
911 
912 int UxbusCmd::servo_addr_r32(int id, int addr, float *value) {
913  unsigned char *txdata = new unsigned char[3];
914  txdata[0] = id;
915  bin16_to_8(addr, &txdata[1]);
916 
917  std::lock_guard<std::mutex> locker(mutex_);
918  int ret = send_xbus(UXBUS_RG::SERVO_R32B, txdata, 3);
919  delete[] txdata;
920  if (0 != ret) { return UXBUS_STATE::ERR_NOTTCP; }
921  unsigned char *rx_data = new unsigned char[4];
922  ret = send_pend(UXBUS_RG::SERVO_R32B, 4, GET_TIMEOUT_, rx_data);
923  *value = (float)bin8_to_32(rx_data);
924  delete[] rx_data;
925  return ret;
926 }
927 
928 
929 
930 /*******************************************************
931  * controler gpio
932  *******************************************************/
934  return get_nu16(UXBUS_RG::CGPIO_GET_DIGIT, value, 1);
935 }
936 int UxbusCmd::cgpio_get_analog1(float *value) {
937  int tmp;
938  int ret = get_nu16(UXBUS_RG::CGPIO_GET_ANALOG1, &tmp, 1);
939  *value = (float)(tmp * 10.0 / 4095.0);
940  return ret;
941 }
942 int UxbusCmd::cgpio_get_analog2(float *value) {
943  int tmp;
944  int ret = get_nu16(UXBUS_RG::CGPIO_GET_ANALOG2, &tmp, 1);
945  *value = (float)(tmp * 10.0 / 4095.0);
946  return ret;
947 }
948 int UxbusCmd::cgpio_set_auxdigit(int ionum, int value) {
949  if (ionum > 7) {
950  int tmp[2] = {0, 0};
951  tmp[1] = tmp[1] | (0x0100 << (ionum - 8));
952  if (value)
953  {
954  tmp[1] = tmp[1] | (0x0001 << (ionum - 8));
955  }
956  return set_nu16(UXBUS_RG::CGPIO_SET_DIGIT, tmp, 2);
957  }
958  else {
959  int tmp = 0;
960  tmp = tmp | (0x0100 << ionum);
961  if (value)
962  {
963  tmp = tmp | (0x0001 << ionum);
964  }
965  return set_nu16(UXBUS_RG::CGPIO_SET_DIGIT, &tmp, 1);
966  }
967 }
968 
969 int UxbusCmd::cgpio_set_analog1(float value) {
970  int val = (int)(value / 10.0 * 4095.0);
971  return set_nu16(UXBUS_RG::CGPIO_SET_ANALOG1, &val, 1);
972 }
973 
974 int UxbusCmd::cgpio_set_analog2(float value) {
975  int val = (int)(value / 10.0 * 4095.0);
976  return set_nu16(UXBUS_RG::CGPIO_SET_ANALOG2, &val, 1);
977 }
978 
979 int UxbusCmd::cgpio_set_infun(int num, int fun) {
980  int txdata[2] = { num, fun };
981  return set_nu8(UXBUS_RG::CGPIO_SET_IN_FUN, txdata, 2);
982 }
983 int UxbusCmd::cgpio_set_outfun(int num, int fun) {
984  int txdata[2] = { num, fun };
985  return set_nu8(UXBUS_RG::CGPIO_SET_OUT_FUN, txdata, 2);
986 }
987 
1007 int UxbusCmd::cgpio_get_state(int *state, int *digit_io, float *analog, int *input_conf, int *output_conf, int *input_conf2, int *output_conf2) {
1008  unsigned char *rx_data = new unsigned char[50];
1009  int ret = get_nu8(UXBUS_RG::CGPIO_GET_STATE, rx_data, -1);
1010 
1011  state[0] = rx_data[0];
1012  state[1] = rx_data[1];
1013  for (int i = 0; i < 4; i++) {
1014  digit_io[i] = bin8_to_16(&rx_data[2 + i * 2]);
1015  analog[i] = (float)(bin8_to_16(&rx_data[10 + i * 2]) / 4095.0 * 10.0);
1016  }
1017  for (int i = 0; i < 8; i++) {
1018  input_conf[i] = rx_data[18 + i];
1019  output_conf[i] = rx_data[26 + i];
1020  }
1021  if (input_conf2 != NULL) {
1022  for (int i = 0; i < 8; i++) {
1023  input_conf2[i] = rx_data[34 + i];
1024  }
1025  }
1026  if (output_conf2 != NULL) {
1027  for (int i = 0; i < 8; i++) {
1028  output_conf2[i] = rx_data[42 + i];
1029  }
1030  }
1031  delete[] rx_data;
1032  return ret;
1033 }
1034 
1035 int UxbusCmd::get_pose_offset(float pose1[6], float pose2[6], float offset[6], int orient_type_in, int orient_type_out) {
1036  float txdata[14] = { 0 };
1037  for (int i = 0; i < 6; i++) { txdata[i] = pose1[i]; }
1038  for (int i = 0; i < 6; i++) { txdata[6+i] = pose2[i]; }
1039  unsigned char *hexdata = new unsigned char[50];
1040  nfp32_to_hex(txdata, hexdata, 12);
1041  hexdata[48] = orient_type_in;
1042  hexdata[49] = orient_type_out;
1043 
1044  std::lock_guard<std::mutex> locker(mutex_);
1045  int ret = send_xbus(UXBUS_RG::MOVE_LINE_AA, hexdata, 50);
1046  delete[] hexdata;
1047  if (0 != ret) { return UXBUS_STATE::ERR_NOTTCP; }
1048  unsigned char *datas = new unsigned char[24];
1049  ret = send_pend(UXBUS_RG::MOVE_LINE_AA, 24, GET_TIMEOUT_, datas);
1050  hex_to_nfp32(datas, offset, 6);
1051  delete[] datas;
1052  return ret;
1053 }
1054 
1055 int UxbusCmd::get_position_aa(float pose[6]) {
1056  return get_nfp32(UXBUS_RG::GET_TCP_POSE_AA, pose, 6);
1057 }
1058 
1059 int UxbusCmd::move_line_aa(float mvpose[6], float mvvelo, float mvacc, float mvtime, int mvcoord, int relative) {
1060  float txdata[9] = { 0 };
1061  for (int i = 0; i < 6; i++) { txdata[i] = mvpose[i]; }
1062  txdata[6] = mvvelo;
1063  txdata[7] = mvacc;
1064  txdata[8] = mvtime;
1065  char additional[2] = { (char)mvcoord, (char)relative };
1066  return set_nfp32_with_bytes(UXBUS_RG::MOVE_LINE_AA, txdata, 9, additional, 2);
1067 }
1068 
1069 int UxbusCmd::move_servo_cart_aa(float mvpose[6], float mvvelo, float mvacc, int tool_coord, int relative) {
1070  float txdata[9] = { 0 };
1071  for (int i = 0; i < 6; i++) { txdata[i] = mvpose[i]; }
1072  txdata[6] = mvvelo;
1073  txdata[7] = mvacc;
1074  txdata[8] = (char)tool_coord;
1075  char additional[1] = { (char)relative };
1076  return set_nfp32_with_bytes(UXBUS_RG::MOVE_SERVO_CART_AA, txdata, 9, additional, 1);
1077 }
1078 
1079 int UxbusCmd::tgpio_delay_set_digital(int ionum, int value, float delay_sec) {
1080  unsigned char *txdata = new unsigned char[6];
1081  txdata[0] = ionum;
1082  txdata[1] = value;
1083  fp32_to_hex(delay_sec, &txdata[2]);
1084 
1085  std::lock_guard<std::mutex> locker(mutex_);
1086  int ret = send_xbus(UXBUS_RG::DELAYED_TGPIO_SET, txdata, 6);
1087  delete[] txdata;
1088  if (0 != ret) { return UXBUS_STATE::ERR_NOTTCP; }
1090 }
1091 
1092 int UxbusCmd::cgpio_delay_set_digital(int ionum, int value, float delay_sec) {
1093  unsigned char *txdata = new unsigned char[6];
1094  txdata[0] = ionum;
1095  txdata[1] = value;
1096  fp32_to_hex(delay_sec, &txdata[2]);
1097 
1098  std::lock_guard<std::mutex> locker(mutex_);
1099  int ret = send_xbus(UXBUS_RG::DELAYED_CGPIO_SET, txdata, 6);
1100  delete[] txdata;
1101  if (0 != ret) { return UXBUS_STATE::ERR_NOTTCP; }
1103 }
1104 
1105 int UxbusCmd::tgpio_position_set_digital(int ionum, int value, float xyz[3], float tol_r) {
1106  unsigned char *txdata = new unsigned char[18];
1107  txdata[0] = ionum;
1108  txdata[1] = value;
1109  nfp32_to_hex(xyz, &txdata[2], 3);
1110  fp32_to_hex(tol_r, &txdata[14]);
1111 
1112  std::lock_guard<std::mutex> locker(mutex_);
1113  int ret = send_xbus(UXBUS_RG::POSITION_TGPIO_SET, txdata, 18);
1114  delete[] txdata;
1115  if (0 != ret) { return UXBUS_STATE::ERR_NOTTCP; }
1117 }
1118 
1119 int UxbusCmd::cgpio_position_set_digital(int ionum, int value, float xyz[3], float tol_r) {
1120  unsigned char *txdata = new unsigned char[18];
1121  txdata[0] = ionum;
1122  txdata[1] = value;
1123  nfp32_to_hex(xyz, &txdata[2], 3);
1124  fp32_to_hex(tol_r, &txdata[14]);
1125 
1126  std::lock_guard<std::mutex> locker(mutex_);
1127  int ret = send_xbus(UXBUS_RG::POSITION_CGPIO_SET, txdata, 18);
1128  delete[] txdata;
1129  if (0 != ret) { return UXBUS_STATE::ERR_NOTTCP; }
1131 }
1132 
1133 int UxbusCmd::cgpio_position_set_analog(int ionum, float value, float xyz[3], float tol_r) {
1134  unsigned char *txdata = new unsigned char[19];
1135  txdata[0] = ionum;
1136  int val = (int)(value / 10.0 * 4095.0);
1137  bin16_to_8(val, &txdata[1]);
1138  nfp32_to_hex(xyz, &txdata[3], 3);
1139  fp32_to_hex(tol_r, &txdata[15]);
1140 
1141  std::lock_guard<std::mutex> locker(mutex_);
1142  int ret = send_xbus(UXBUS_RG::POSITION_CGPIO_SET, txdata, 19);
1143  delete[] txdata;
1144  if (0 != ret) { return UXBUS_STATE::ERR_NOTTCP; }
1146 }
1147 
1148 int UxbusCmd::config_io_stop_reset(int io_type, int val) {
1149  int txdata[2] = { io_type, val };
1150  return set_nu8(UXBUS_RG::SET_IO_STOP_RESET, txdata, 2);
1151 }
1152 
1154  int txdata[1] = { tau_or_i };
1155  return set_nu8(UXBUS_RG::REPORT_TAU_OR_I, txdata, 1);
1156 }
1157 
1159  return get_nu8(UXBUS_RG::GET_REPORT_TAU_OR_I, rx_data, 1);
1160 }
1161 
1163  int txdata[1] = { on_off };
1164  return set_nu8(UXBUS_RG::SET_SELF_COLLIS_CHECK, txdata, 1);
1165 }
1166 
1167 int UxbusCmd::set_collision_tool_model(int tool_type, int n, float *argv) {
1168  if (n > 0) {
1169  char additional[1] = { (char)tool_type };
1170  return set_nfp32_with_bytes(UXBUS_RG::SET_COLLIS_TOOL, argv, n, additional, 1);
1171  }
1172  else {
1173  int txdata[1] = { tool_type };
1174  return set_nu8(UXBUS_RG::SET_COLLIS_TOOL, txdata, 1);
1175  }
1176 }
1177 
1179  return set_nu8(UXBUS_RG::SET_SIMULATION_ROBOT, &on_off, 1);
1180 }
1181 
1182 int UxbusCmd::vc_set_jointv(float jnt_v[7], int jnt_sync) {
1183  float txdata[7] = { 0 };
1184  for (int i = 0; i < 7; i++) { txdata[i] = jnt_v[i]; }
1185  char additional[1] = { (char)jnt_sync };
1186  return set_nfp32_with_bytes(UXBUS_RG::VC_SET_JOINTV, txdata, 7, additional, 1);
1187 }
1188 
1189 int UxbusCmd::vc_set_linev(float line_v[6], int coord) {
1190  float txdata[6] = { 0 };
1191  for (int i = 0; i < 6; i++) { txdata[i] = line_v[i]; }
1192  char additional[1] = { (char)coord };
1193  return set_nfp32_with_bytes(UXBUS_RG::VC_SET_CARTV, txdata, 6, additional, 1);
1194 }
int set_gravity_dir(float gravity_dir[3])
Definition: uxbus_cmd.cc:506
static const unsigned char DELAYED_CGPIO_SET
static const unsigned char PLAY_TRAJ
int get_reduced_states(int *on, int xyz_list[6], float *tcp_speed, float *joint_speed, float jrange_rad[14]=NULL, int *fense_is_on=NULL, int *collision_rebound_is_on=NULL, int length=21)
Definition: uxbus_cmd.cc:256
int set_collis_sens(int value)
Definition: uxbus_cmd.cc:498
int set_nfp32_with_bytes(int funcode, float *datas, int num, char *additional, int n)
Definition: uxbus_cmd.cc:178
static const unsigned char SET_GRAVITY_DIR
static const unsigned short SOFT_REBOOT
Definition: servo3_config.h:42
int set_nu8(int funcode, int *datas, int num)
Definition: uxbus_cmd.cc:64
int gripper_set_posspd(float speed)
Definition: uxbus_cmd.cc:623
int gripper_addr_r16(int addr, float *value)
Definition: uxbus_cmd.cc:558
static const unsigned char GET_REPORT_TAU_OR_I
static const unsigned char SET_LOAD_PARAM
void sleep_milliseconds(unsigned long milliseconds)
Definition: uxbus_cmd.h:24
int gripper_modbus_set_pos(float pulse)
Definition: uxbus_cmd.cc:828
int set_joint_maxacc(float maxacc)
Definition: uxbus_cmd.cc:484
static const unsigned char SLEEP_INSTT
int get_err_code(int *rx_data)
Definition: uxbus_cmd.cc:319
int get_version(unsigned char rx_data[40])
Definition: uxbus_cmd.cc:194
int gripper_modbus_clean_err(void)
Definition: uxbus_cmd.cc:855
int set_safe_level(int level)
Definition: uxbus_cmd.cc:440
void fp32_to_hex(double dataf, unsigned char datahex[4])
Definition: data_type.h:57
int save_conf(void)
Definition: uxbus_cmd.cc:514
static const unsigned char DELAYED_TGPIO_SET
int tgpio_get_analog1(float *value)
Definition: uxbus_cmd.cc:720
static const unsigned char SERVO_DBMSG
int set_timeout(float timeout)
Definition: uxbus_cmd.cc:40
int playback_traj_old(int times)
Definition: uxbus_cmd.cc:220
static const unsigned char SERVO_W16B
int cgpio_get_analog2(float *value)
Definition: uxbus_cmd.cc:942
static const unsigned char IS_TCP_LIMIT
int gripper_set_mode(int value)
Definition: uxbus_cmd.cc:607
int move_jointb(float mvjoint[7], float mvvelo, float mvacc, float mvradii)
Definition: uxbus_cmd.cc:386
static const unsigned char CGPIO_SET_OUT_FUN
static const unsigned char SET_SIMULATION_ROBOT
static const unsigned short MT_ZERO
Definition: servo3_config.h:51
static const unsigned char MOVE_JOINT
bool state_is_ready
Definition: uxbus_cmd.h:215
static const unsigned char SET_WORLD_OFFSET
static const unsigned char SAVE_CONF
int set_nu8_char(int funcode, char *datas, int num)
Definition: uxbus_cmd.cc:51
int clean_war(void)
Definition: uxbus_cmd.cc:337
static const unsigned char SET_TCP_OFFSET
int SET_TIMEOUT_
Definition: uxbus_cmd.h:220
static const unsigned char TGPIO_MB_TIOUT
static const unsigned char SAVE_TRAJ
static const unsigned char GET_REDUCED_MODE
static const unsigned char GET_TCP_POSE_AA
static const unsigned char MOVE_LINE_TOOL
int move_lineb(float mvpose[6], float mvvelo, float mvacc, float mvtime, float mvradii)
Definition: uxbus_cmd.cc:364
static const unsigned char TGPIO_ERR
int get_hd_types(int *rx_data)
Definition: uxbus_cmd.cc:323
static const unsigned char CGPIO_SET_ANALOG2
static const int TGPIO_ID
int set_tcp_maxacc(float maxacc)
Definition: uxbus_cmd.cc:474
int get_report_tau_or_i(int *rx_data)
Definition: uxbus_cmd.cc:1158
int get_nu16(int funcode, int *rx_data, int num)
Definition: uxbus_cmd.cc:103
int set_mode(int value)
Definition: uxbus_cmd.cc:347
static const unsigned char GET_REDUCED_STATE
static const int GRIPPER_ID
int set_world_offset(float pose_offset[6])
Definition: uxbus_cmd.cc:276
int config_io_stop_reset(int io_type, int val)
Definition: uxbus_cmd.cc:1148
int set_reduced_jrange(float jrange_rad[14])
Definition: uxbus_cmd.cc:288
static const unsigned char CGPIO_SET_DIGIT
int servo_get_dbmsg(int rx_data[16])
Definition: uxbus_cmd.cc:866
static const unsigned char GET_SAFE_LEVEL
virtual int check_xbus_prot(unsigned char *data, int funcode)
Definition: uxbus_cmd.cc:28
void hex_to_nfp32(unsigned char *datahex, float *dataf, int n)
Definition: data_type.h:93
int shutdown_system(int value)
Definition: uxbus_cmd.cc:206
int gripper_get_errcode(int rx_data[2])
Definition: uxbus_cmd.cc:627
static const unsigned char SERVO_W32B
int get_fk(float angles[7], float pose[6])
Definition: uxbus_cmd.cc:530
int gripper_modbus_w16s(int addr, float value, int len)
Definition: uxbus_cmd.cc:774
int load_traj(char filename[81])
Definition: uxbus_cmd.cc:229
static const unsigned char GET_STATE
static const unsigned char SET_IO_STOP_RESET
int vc_set_linev(float line_v[6], int coord)
Definition: uxbus_cmd.cc:1189
int gripper_modbus_set_zero(void)
Definition: uxbus_cmd.cc:816
int get_state(int *rx_data)
Definition: uxbus_cmd.cc:311
int set_xyz_limits(int xyz_list[6])
Definition: uxbus_cmd.cc:272
static const unsigned short POS_SPD
Definition: servo3_config.h:39
int is_tcp_limit(float pose[6], int *value)
Definition: uxbus_cmd.cc:538
static const unsigned char CGPIO_SET_IN_FUN
int bin8_to_32(unsigned char *a)
Definition: data_type.h:38
int tgpio_get_digital(int *io1, int *io2)
Definition: uxbus_cmd.cc:695
static const unsigned char CGPIO_GET_ANALOG1
int reload_dynamics(void)
Definition: uxbus_cmd.cc:327
int set_reduced_jointspeed(float jspd_rad)
Definition: uxbus_cmd.cc:247
int set_servot(float jnt_taus[7])
Definition: uxbus_cmd.cc:430
static const unsigned char POSITION_TGPIO_SET
static const unsigned char MOVE_JOINTB
int save_traj(char filename[81])
Definition: uxbus_cmd.cc:225
int set_collision_tool_model(int tool_type, int n=0, float *argv=NULL)
Definition: uxbus_cmd.cc:1167
int set_nint32(int funcode, int *datas, int num)
Definition: uxbus_cmd.cc:126
int get_joint_pose(float angles[7])
Definition: uxbus_cmd.cc:522
void nint32_to_hex(int *data, unsigned char *datahex, int n)
Definition: data_type.h:107
static const unsigned short CURR_POS
Definition: servo3_config.h:47
int move_circle(float pose1[6], float pose2[6], float mvvelo, float mvacc, float mvtime, float percent)
Definition: uxbus_cmd.cc:454
static const unsigned char SET_JOINT_MAXACC
static const unsigned char VC_SET_JOINTV
static const unsigned char MOVE_SERVO_CART
int gripper_clean_err(void)
Definition: uxbus_cmd.cc:631
int move_servo_cartesian(float mvpose[6], float mvvelo, float mvacc, float mvtime)
Definition: uxbus_cmd.cc:421
static const unsigned char CHECK_VERIFY
static const unsigned char GET_TCP_POSE
int is_joint_limit(float joint[7], int *value)
Definition: uxbus_cmd.cc:534
static const unsigned char MOVE_LINE_AA
static const unsigned char LOAD_TRAJ
int swop_nfp32(int funcode, float tx_datas[], int txn, float *rx_data, int rxn)
Definition: uxbus_cmd.cc:148
static const unsigned char SET_MODE
int set_nu16(int funcode, int *datas, int num)
Definition: uxbus_cmd.cc:92
static const unsigned char MOVE_SERVOJ
static const unsigned char SET_REDUCED_MODE
static int BAUDRATES[13]
Definition: uxbus_cmd.cc:15
static const unsigned char MOVE_CIRCLE
static const unsigned char CNTER_RESET
static const unsigned char SET_TCP_JERK
int cgpio_get_state(int *state, int *digit_io, float *analog, int *input_conf, int *output_conf, int *input_conf2=NULL, int *output_conf2=NULL)
Definition: uxbus_cmd.cc:1007
int playback_traj(int times, int spdx=1)
Definition: uxbus_cmd.cc:215
static const unsigned char SET_LIMIT_XYZ
static const unsigned char SET_STATE
int get_traj_rw_status(int *rx_data)
Definition: uxbus_cmd.cc:233
int cgpio_position_set_analog(int ionum, float value, float xyz[3], float tol_r)
Definition: uxbus_cmd.cc:1133
static const int ERR_NOTTCP
static const unsigned short CON_EN
Definition: servo3_config.h:12
static const unsigned char VC_SET_CARTV
int move_line_aa(float mvpose[6], float mvvelo, float mvacc, float mvtime, int mvcoord=0, int relative=0)
Definition: uxbus_cmd.cc:1059
int get_robot_sn(unsigned char rx_data[40])
Definition: uxbus_cmd.cc:198
int tgpio_addr_w16(int addr, float value)
Definition: uxbus_cmd.cc:638
static const unsigned char SET_REDUCED_TRSV
int servo_addr_r16(int id, int addr, float *value)
Definition: uxbus_cmd.cc:883
static const unsigned char SERVO_ZERO
void nfp32_to_hex(float *dataf, unsigned char *datahex, int n)
Definition: data_type.h:100
int move_gohome(float mvvelo, float mvacc, float mvtime)
Definition: uxbus_cmd.cc:404
int get_ik(float pose[6], float angles[7])
Definition: uxbus_cmd.cc:526
int get_nu8(int funcode, int *rx_data, int num)
Definition: uxbus_cmd.cc:77
int gripper_modbus_set_en(int value)
Definition: uxbus_cmd.cc:800
int tgpio_set_modbus(unsigned char *send_data, int length, unsigned char *recv_data)
Definition: uxbus_cmd.cc:760
static const unsigned char SET_SAFE_LEVEL
int set_modbus_timeout(int value)
Definition: uxbus_cmd.cc:739
int check_verification(int *rx_data)
Definition: uxbus_cmd.cc:202
static const unsigned char CLEAN_CONF
int cnter_plus(void)
Definition: uxbus_cmd.cc:284
static const unsigned char GET_ROBOT_SN
int get_nfp32(int funcode, float *rx_data, int num)
Definition: uxbus_cmd.cc:137
int gripper_modbus_get_errcode(int *err)
Definition: uxbus_cmd.cc:847
int set_simulation_robot(int on_off)
Definition: uxbus_cmd.cc:1178
static const unsigned char SET_TRAJ_RECORD
static const unsigned char SET_REDUCED_P2PV
static const unsigned char SET_FENSE_ON
int servo_addr_w32(int id, int addr, float value)
Definition: uxbus_cmd.cc:899
int cgpio_set_infun(int ionum, int fun)
Definition: uxbus_cmd.cc:979
void bin16_to_8(int a, unsigned char *b)
Definition: data_type.h:32
int get_position_aa(float pose[6])
Definition: uxbus_cmd.cc:1055
int cgpio_set_auxdigit(int ionum, int value)
Definition: uxbus_cmd.cc:948
static const unsigned short ERR_CODE
Definition: servo3_config.h:21
static const unsigned char MOVE_SERVO_CART_AA
static int get_baud_inx(int baud)
Definition: uxbus_cmd.cc:17
int get_pose_offset(float pose1[6], float pose2[6], float offset[6], int orient_type_in=0, int orient_type_out=0)
Definition: uxbus_cmd.cc:1035
int gripper_modbus_set_posspd(float speed)
Definition: uxbus_cmd.cc:839
int gripper_set_pos(float pulse)
Definition: uxbus_cmd.cc:619
static const unsigned char MOVE_HOME
int set_tcp_offset(float pose_offset[6])
Definition: uxbus_cmd.cc:489
static const unsigned char GET_IK
int GET_TIMEOUT_
Definition: uxbus_cmd.h:219
int set_fense_on(int on_off)
Definition: uxbus_cmd.cc:292
virtual int send_pend(int funcode, int num, int timeout, unsigned char *rx_data)
Definition: uxbus_cmd.cc:30
int tgpio_addr_r32(int addr, float *value)
Definition: uxbus_cmd.cc:679
static const unsigned char CNTER_PLUS
int set_modbus_baudrate(int baud)
Definition: uxbus_cmd.cc:743
int gripper_modbus_r16s(int addr, int len, unsigned char *rx_data)
Definition: uxbus_cmd.cc:789
static const unsigned char IS_JOINT_LIMIT
int gripper_modbus_set_mode(int value)
Definition: uxbus_cmd.cc:808
static const unsigned char CGPIO_SET_ANALOG1
int servo_set_zero(int id)
Definition: uxbus_cmd.cc:862
int tgpio_get_analog2(float *value)
Definition: uxbus_cmd.cc:727
static const unsigned char GET_TRAJ_RW_STATUS
virtual void close(void)
Definition: uxbus_cmd.cc:36
int set_collis_reb(int on_off)
Definition: uxbus_cmd.cc:297
static const unsigned char SERVO_R16B
int get_safe_level(int *level)
Definition: uxbus_cmd.cc:445
int get_tcp_pose(float pose[6])
Definition: uxbus_cmd.cc:518
int gripper_addr_r32(int addr, float *value)
Definition: uxbus_cmd.cc:587
static const unsigned char CGPIO_GET_DIGIT
int set_state(int value)
Definition: uxbus_cmd.cc:307
static const unsigned char POSITION_CGPIO_SET
int gripper_set_zero(void)
Definition: uxbus_cmd.cc:611
int cgpio_get_auxdigit(int *value)
Definition: uxbus_cmd.cc:933
int gripper_get_pos(float *pulse)
Definition: uxbus_cmd.cc:615
int move_line_tool(float mvpose[6], float mvvelo, float mvacc, float mvtime)
Definition: uxbus_cmd.cc:395
static const unsigned char TGPIO_W16B
int sleep_instruction(float sltime)
Definition: uxbus_cmd.cc:449
int get_joint_tau(float jnt_taus[7])
Definition: uxbus_cmd.cc:436
void bin8_to_ns16(unsigned char *a, int *data, int n)
Definition: data_type.h:51
int clean_err(void)
Definition: uxbus_cmd.cc:332
int move_line(float mvpose[6], float mvvelo, float mvacc, float mvtime)
Definition: uxbus_cmd.cc:355
int clean_conf(void)
Definition: uxbus_cmd.cc:510
UxbusCmd(void)
Definition: uxbus_cmd.cc:22
static const unsigned char GET_VERSION
static const unsigned char TGPIO_W32B
static const unsigned char GET_JOINT_TAU
static const unsigned short ANALOG_IO2
Definition: servo3_config.h:63
float hex_to_fp32(unsigned char datahex[4])
Definition: data_type.h:69
int get_cmdnum(int *rx_data)
Definition: uxbus_cmd.cc:315
static const unsigned char SET_TCP_MAXACC
static const unsigned char GET_HD_TYPES
static const unsigned char CGPIO_GET_STATE
static const unsigned char CLEAN_ERR
static const unsigned char MOVE_LINEB
int tgpio_addr_r16(int addr, float *value)
Definition: uxbus_cmd.cc:651
static const unsigned short RESET_ERR
Definition: servo3_config.h:55
static const unsigned short TAGET_POS
Definition: servo3_config.h:46
int set_tcp_jerk(float jerk)
Definition: uxbus_cmd.cc:469
static const unsigned char TGPIO_R32B
static const unsigned char MOVE_LINE
~UxbusCmd(void)
Definition: uxbus_cmd.cc:26
int servo_addr_r32(int id, int addr, float *value)
Definition: uxbus_cmd.cc:912
static const unsigned char CGPIO_GET_ANALOG2
int servo_addr_w16(int id, int addr, float value)
Definition: uxbus_cmd.cc:870
static const unsigned char SET_TEACH_SENS
int cgpio_position_set_digital(int ionum, int value, float xyz[3], float tol_r)
Definition: uxbus_cmd.cc:1119
static const unsigned char SET_COLLIS_TOOL
static const unsigned char GET_CMDNUM
int set_record_traj(int value)
Definition: uxbus_cmd.cc:210
static const unsigned char TGPIO_MODBUS
int move_servoj(float mvjoint[7], float mvvelo, float mvacc, float mvtime)
Definition: uxbus_cmd.cc:412
static const unsigned char REPORT_TAU_OR_I
int cnter_reset(void)
Definition: uxbus_cmd.cc:280
int is_nfp32(int funcode, float datas[], int txn, int *value)
Definition: uxbus_cmd.cc:163
int tgpio_position_set_digital(int ionum, int value, float xyz[3], float tol_r)
Definition: uxbus_cmd.cc:1105
static const unsigned char SET_SELF_COLLIS_CHECK
int gripper_modbus_get_pos(float *pulse)
Definition: uxbus_cmd.cc:820
int tgpio_addr_w32(int addr, float value)
Definition: uxbus_cmd.cc:666
static const unsigned short CON_MODE
Definition: servo3_config.h:13
static const unsigned char GET_ERROR
int set_reduced_mode(int on_off)
Definition: uxbus_cmd.cc:237
int set_teach_sens(int value)
Definition: uxbus_cmd.cc:502
static const unsigned char SET_JOINT_JERK
int move_joint(float mvjoint[7], float mvvelo, float mvacc, float mvtime)
Definition: uxbus_cmd.cc:376
int set_reduced_linespeed(float lspd_mm)
Definition: uxbus_cmd.cc:242
int get_reduced_mode(int *rx_data)
Definition: uxbus_cmd.cc:252
int set_nfp32(int funcode, float *datas, int num)
Definition: uxbus_cmd.cc:114
static const unsigned char RELOAD_DYNAMICS
int set_self_collision_detection(int on_off)
Definition: uxbus_cmd.cc:1162
int gripper_addr_w16(int addr, float value)
Definition: uxbus_cmd.cc:545
static const unsigned char CLEAN_WAR
int vc_set_jointv(float jnt_v[7], int jnt_sync)
Definition: uxbus_cmd.cc:1182
static const unsigned short DIGITAL_IN
Definition: servo3_config.h:60
static const unsigned char TGPIO_R16B
static const unsigned short MODBUS_BAUDRATE
Definition: servo3_config.h:58
int set_tcp_load(float mass, float load_offset[3])
Definition: uxbus_cmd.cc:493
int set_joint_jerk(float jerk)
Definition: uxbus_cmd.cc:479
static const unsigned char GET_FK
int gripper_addr_w32(int addr, float value)
Definition: uxbus_cmd.cc:574
int move_servo_cart_aa(float mvpose[6], float mvvelo, float mvacc, int tool_coord=0, int relative=0)
Definition: uxbus_cmd.cc:1069
static const unsigned char SERVO_R32B
int cgpio_set_outfun(int ionum, int fun)
Definition: uxbus_cmd.cc:983
static const unsigned short ANALOG_IO1
Definition: servo3_config.h:62
static const unsigned short DIGITAL_OUT
Definition: servo3_config.h:61
static const unsigned char SET_COLLIS_REB
static const unsigned char GET_JOINT_POS
static const unsigned char SET_BRAKE
static const unsigned char SHUTDOWN_SYSTEM
int motion_en(int id, int value)
Definition: uxbus_cmd.cc:302
int cgpio_set_analog2(float value)
Definition: uxbus_cmd.cc:974
virtual int send_xbus(int funcode, unsigned char *txdata, int num)
Definition: uxbus_cmd.cc:34
static const unsigned char MOTION_EN
int cgpio_get_analog1(float *value)
Definition: uxbus_cmd.cc:936
int cgpio_delay_set_digital(int ionum, int value, float delay_sec)
Definition: uxbus_cmd.cc:1092
virtual int is_ok(void)
Definition: uxbus_cmd.cc:38
static const unsigned char SET_REDUCED_JRANGE
static const unsigned char SET_SERVOT
int set_report_tau_or_i(int tau_or_i)
Definition: uxbus_cmd.cc:1153
int gripper_set_en(int value)
Definition: uxbus_cmd.cc:603
std::mutex mutex_
Definition: uxbus_cmd.h:218
int set_brake(int axis, int en)
Definition: uxbus_cmd.cc:342
int bin8_to_16(unsigned char *a)
Definition: data_type.h:42
int cgpio_set_analog1(float value)
Definition: uxbus_cmd.cc:969
int tgpio_delay_set_digital(int ionum, int value, float delay_sec)
Definition: uxbus_cmd.cc:1079
int tgpio_set_digital(int ionum, int value)
Definition: uxbus_cmd.cc:704


xarm_api
Author(s):
autogenerated on Sat May 8 2021 02:51:23