xarm_api.h
Go to the documentation of this file.
1 /*
2 # Software License Agreement (MIT License)
3 #
4 # Copyright (c) 2019, UFACTORY, Inc.
5 # All rights reserved.
6 #
7 # Author: Vinman <vinman.wen@ufactory.cc> <vinman.cub@gmail.com>
8 */
9 #ifndef WRAPPER_XARM_API_H_
10 #define WRAPPER_XARM_API_H_
11 
12 #include <iostream>
13 #include <functional>
14 #include <thread>
15 #include <vector>
16 #include <assert.h>
17 #include <cmath>
19 #include "xarm/core/xarm_config.h"
28 
29 #define DEFAULT_IS_RADIAN false
30 #define RAD_DEGREE 57.295779513082320876798154814105
31 #define TIMEOUT_10 10
32 #define NO_TIMEOUT -1
33 #define SDK_VERSION "1.6.0"
34 
35 typedef unsigned int u32;
36 typedef float fp32;
37 
38 struct RobotIqStatus {
39  unsigned char gOBJ = 0;
40  unsigned char gSTA = 0;
41  unsigned char gGTO = 0;
42  unsigned char gACT = 0;
43  unsigned char kFLT = 0;
44  unsigned char gFLT = 0;
45  unsigned char gPR = 0;
46  unsigned char gPO = 0;
47  unsigned char gCU = 0;
48 };
49 
50 class XArmAPI {
51 public:
52  /*
53  * @param port: ip-address(such as "192.168.1.185")
54  * Note: this parameter is required if parameter do_not_open is False
55  * @param is_radian: set the default unit is radians or not, default is False
56  * @param do_not_open: do not open, default is False, if true, you need to manually call the connect interface.
57  * @param check_tcp_limit: reversed, whether checking tcp limit, default is true
58  * @param check_joint_limit: reversed, whether checking joint limit, default is true
59  * @param check_cmdnum_limit: whether checking command num limit, default is true
60  * @param check_robot_sn: whether checking robot sn, default is false
61  * @param check_is_ready: reversed, check robot is ready to move or not, default is true
62  * @param check_is_pause: check robot is pause or not, default is true
63  * @param max_callback_thread_count: max callback thread count, default is -1
64  * Note: greater than 0 means the maximum number of threads that can be used to process callbacks
65  * Note: equal to 0 means no thread is used to process the callback
66  * Note: less than 0 means no limit on the number of threads used for callback
67  * @param max_cmdnum: max cmdnum, default is 256
68  * Note: only available in the param `check_cmdnum_limit` is true
69  */
70  XArmAPI(const std::string &port = "",
71  bool is_radian = DEFAULT_IS_RADIAN,
72  bool do_not_open = false,
73  bool check_tcp_limit = true,
74  bool check_joint_limit = true,
75  bool check_cmdnum_limit = true,
76  bool check_robot_sn = false,
77  bool check_is_ready = true,
78  bool check_is_pause = true,
79  int max_callback_thread_count = -1,
80  int max_cmdnum = 256);
81  ~XArmAPI(void);
82 
83 public:
84  int state; // state
85  int mode; // mode
86  int cmd_num; // cmd cache count
87  fp32 *joints_torque; // joints torque, fp32[7]{servo-1, ..., servo-7}
88  bool *motor_brake_states; // motor brake states, bool[8]{servo-1, ..., servo-7, reversed}
89  bool *motor_enable_states; // motor enable states, bool[8]{servo-1, ..., servo-7, reversed}
90  int error_code; // error code
91  int warn_code; // warn code
92  fp32 *tcp_load; // tcp load, fp32[4]{weight, x, y, z}
93  int collision_sensitivity; // collision sensitivity
94  int teach_sensitivity; // teach sensitivity
95  int device_type; // device type
96  int axis; // robot axis
97  int master_id;
98  int slave_id;
99  int motor_tid;
101  unsigned char version[30]; // version
102  unsigned char sn[40]; // sn
103  int *version_number; // version numbre
104  fp32 tcp_jerk; // tcp jerk
105  fp32 joint_jerk; // joint jerk
106  fp32 rot_jerk; // rot jerk
107  fp32 max_rot_acc; // max rot acc
108  fp32 *tcp_speed_limit; // fp32[2]{min, max}
109  fp32 *tcp_acc_limit; // fp32[2]{min, max}
112 
113  fp32 *angles; // fp32[7]{servo-1, ..., servo-7}
114  fp32 *last_used_angles; // fp32[7]{servo-1, ..., servo-7}
115  fp32 *joint_speed_limit; // fp32[2]{min, max}
116  fp32 *joint_acc_limit; // fp32[2]{min, max}
119  fp32 *position; // fp32[6]{x, y, z, roll, pitch, yaw}
120  fp32 *last_used_position; // fp32[6]{x, y, z, roll, pitch, yaw}
121  fp32 *tcp_offset; // fp32[6]{x, y, z, roll, pitch, yaw}
122  fp32 *gravity_direction; // fp32[3]{x_direction, y_direction, z_direction}
123 
126 
127  fp32 *world_offset; // fp32[6]{x, y, z, roll, pitch, yaw}
129  int count;
130  unsigned char *gpio_reset_config; // unsigned char[2]{cgpio_reset_enable, tgpio_reset_enable}
131 
133 
135 
136  struct RobotIqStatus robotiq_status;
137 
138  fp32 *voltages; // fp32[7]{servo-1, ..., servo-7}
139  fp32 *currents; // fp32[7]{servo-1, ..., servo-7}
140  int is_simulation_robot; // 0: off, 1: on
141  int is_collision_detection; // 0: off, 1: on
143  fp32 *collision_model_params; // fp32[6]{...}
146  int *cgpio_input_digitals; // int[2]{ digital-input-functional-gpio-state, digital-input-configuring-gpio-state }
147  int *cgpio_output_digitals; // int[2]{ digital-output-functional-gpio-state, digital-output-configuring-gpio-state }
148  fp32 *cgpio_intput_anglogs; // fp32[2] {analog-1-input-value, analog-2-input-value}
149  fp32 *cgpio_output_anglogs; // fp32[2] {analog-1-output-value, analog-2-output-value}
150  int *cgpio_input_conf; // fp32[8]{ CI0-conf, ... CI7-conf }
151  int *cgpio_output_conf; // fp32[8]{ CO0-conf, ... CO7-conf }
152 
153 public:
154  /*
155  * xArm has error/warn or not, only available in socket way
156  */
157  bool has_err_warn(void);
158 
159  /*
160  * xArm has error or not, only available in socket way
161  */
162  bool has_error(void);
163 
164  /*
165  * xArm has warn or not, only available in socket way
166  */
167  bool has_warn(void);
168 
169  /*
170  * xArm is connected or not
171  */
172  bool is_connected(void);
173 
174  /*
175  * xArm is reported or not, only available in socket way
176  */
177  bool is_reported(void);
178 
179  /*
180  * Connect to xArm
181  * @param port: port name or the ip address
182  * return:
183  0: success
184  -1: port is empty
185  -2: tcp control connect failed
186  -3: tcp report connect failed
187  */
188  int connect(const std::string &port = "");
189 
190  /*
191  * Disconnect
192  */
193  void disconnect(void);
194 
195  /*no use please*/
196  void _recv_report_data(void);
197 
198  /*
199  * Get the xArm version
200  * @param version:
201  * return: see the API code documentation for details.
202  */
203  int get_version(unsigned char version[40]);
204 
205  /*
206  * Get the xArm sn
207  * @param robot_sn:
208  * return: see the API code documentation for details.
209  */
210  int get_robot_sn(unsigned char robot_sn[40]);
211 
212  /*
213  * Get the xArm state
214  * @param: the state of xArm
215  1: in motion
216  2: sleeping
217  3: suspended
218  4: stopping
219  * return: see the API code documentation for details.
220  */
221  int get_state(int *state);
222 
223  /*
224  * Shutdown the xArm controller system
225  * @param value:
226  1: remote shutdown
227  * return: see the API code documentation for details.
228  */
229  int shutdown_system(int value = 1);
230 
231  /*
232  * Get the cmd count in cache
233  * return: see the API code documentation for details.
234  */
235  int get_cmdnum(int *cmdnum);
236 
237  /*
238  * Get the controller error and warn code
239  * return: see the API code documentation for details.
240  */
241  int get_err_warn_code(int err_warn[2]);
242 
243  /*
244  * Get the cartesian position
245  * @param pose: the position of xArm, like [x(mm), y(mm), z(mm), roll(rad or °), pitch(rad or °), yaw(rad or °)]
246  if default_is_radian is true, the value of roll/pitch/yaw should be in radians
247  if default_is_radian is false, The value of roll/pitch/yaw should be in degrees
248  * return: see the API code documentation for details.
249  */
250  int get_position(fp32 pose[6]);
251 
252  /*
253  * Get the servo angle
254  * @param angles: the angles of the servos, like [servo-1, ..., servo-7]
255  if default_is_radian is true, the value of servo-1/.../servo-7 should be in radians
256  if default_is_radian is false, The value of servo-1/.../servo-7 should be in degrees
257  * return: see the API code documentation for details.
258  */
259  int get_servo_angle(fp32 angles[7]);
260 
261  /*
262  * Motion enable
263  * @param enable: enable or not
264  * @param servo_id: servo id, 1-8, 8(enable/disable all servo)
265  * return: see the API code documentation for details.
266  */
267  int motion_enable(bool enable, int servo_id = 8);
268 
269  /*
270  * Set the xArm state
271  * @param state: state
272  0: sport state
273  3: pause state
274  4: stop state
275  * return: see the API code documentation for details.
276  */
277  int set_state(int state);
278 
279  /*
280  * Set the xArm mode
281  * @param mode: mode
282  0: position control mode
283  1: servo motion mode
284  2: joint teaching mode
285  3: cartesian teaching mode (invalid)
286  4: simulation mode
287  * return: see the API code documentation for details.
288  */
289  int set_mode(int mode);
290 
291  /*
292  * Attach the servo
293  * @param servo_id: servo id, 1-8, 8(attach all servo)
294  * return: see the API code documentation for details.
295  */
296  int set_servo_attach(int servo_id);
297 
298  /*
299  * Detach the servo, be sure to do protective work before unlocking to avoid injury or damage.
300  * @param servo_id: servo id, 1-8, 8(detach all servo)
301  * return: see the API code documentation for details.
302  */
303  int set_servo_detach(int servo_id);
304 
305  /*
306  * Clean the controller error, need to be manually enabled motion and set state after clean error
307  * return: see the API code documentation for details.
308  */
309  int clean_error(void);
310 
311  /*
312  * Clean the controller warn
313  * return: see the API code documentation for details.
314  */
315  int clean_warn(void);
316 
317  /*
318  * Set the arm pause time, xArm will pause sltime second
319  * @param sltime: sleep second
320  * return: see the API code documentation for details.
321  */
322  int set_pause_time(fp32 sltime);
323 
324  /*
325  * Set the sensitivity of collision
326  * @param sensitivity: sensitivity value, 0~5
327  * return: see the API code documentation for details.
328  */
329  int set_collision_sensitivity(int sensitivity);
330 
331  /*
332  * Set the sensitivity of drag and teach
333  * @param sensitivity: sensitivity value, 1~5
334  * return: see the API code documentation for details.
335  */
336  int set_teach_sensitivity(int sensitivity);
337 
338  /*
339  * Set the direction of gravity
340  * @param gravity_dir: direction of gravity, such as [x(mm), y(mm), z(mm)]
341  * return: see the API code documentation for details.
342  */
343  int set_gravity_direction(fp32 gravity_dir[3]);
344 
345  /*
346  * Clean current config and restore system default settings
347  * Note:
348  1. This interface will clear the current settings and restore to the original settings (system default settings)
349  * return: see the API code documentation for details.
350  */
351  int clean_conf(void);
352 
353  /*
354  * Save config
355  * Note:
356  1. This interface can record the current settings and will not be lost after the restart.
357  2. The clean_conf interface can restore system default settings
358  * return: see the API code documentation for details.
359  */
360  int save_conf(void);
361 
362  /*
363  * Set the position
364  MoveLine: Linear motion
365  MoveArcLine: Linear arc motion with interpolation
366  * @param pose: position, like [x(mm), y(mm), z(mm), roll(rad or °), pitch(rad or °), yaw(rad or °)]
367  if default_is_radian is true, the value of roll/pitch/yaw should be in radians
368  if default_is_radian is false, The value of roll/pitch/yaw should be in degrees
369  * @param radius: move radius, if radius is None or radius less than 0, will MoveLine, else MoveArcLine
370  * @param speed: move speed (mm/s, rad/s), default is this.last_used_tcp_speed
371  * @param mvacc: move acceleration (mm/s^2, rad/s^2), default is this.last_used_tcp_acc
372  * @param mvtime: reserved, 0
373  * @param wait: whether to wait for the arm to complete, default is False
374  * @param timeout: maximum waiting time(unit: second), default is no timeout, only valid if wait is true
375  * return: see the API code documentation for details.
376  */
377  int set_position(fp32 pose[6], fp32 radius = -1, fp32 speed = 0, fp32 acc = 0, fp32 mvtime = 0, bool wait = false, fp32 timeout = NO_TIMEOUT);
378  int set_position(fp32 pose[6], fp32 radius = -1, bool wait = false, fp32 timeout = NO_TIMEOUT);
379  int set_position(fp32 pose[6], bool wait = false, fp32 timeout = NO_TIMEOUT);
380 
381  /*
382  * Movement relative to the tool coordinate system
383  * @param pose: the coordinate relative to the current tool coordinate systemion, like [x(mm), y(mm), z(mm), roll(rad or °), pitch(rad or °), yaw(rad or °)]
384  if default_is_radian is true, the value of roll/pitch/yaw should be in radians
385  if default_is_radian is false, The value of roll/pitch/yaw should be in degrees
386  * @param speed: move speed (mm/s, rad/s), default is this.last_used_tcp_speed
387  * @param mvacc: move acceleration (mm/s^2, rad/s^2), default is this.last_used_tcp_acc
388  * @param mvtime: reserved, 0
389  * @param wait: whether to wait for the arm to complete, default is False
390  * @param timeout: maximum waiting time(unit: second), default is no timeout, only valid if wait is true
391  * return: see the API code documentation for details.
392  */
393  int set_tool_position(fp32 pose[6], fp32 speed = 0, fp32 acc = 0, fp32 mvtime = 0, bool wait = false, fp32 timeout = NO_TIMEOUT);
394  int set_tool_position(fp32 pose[6], bool wait = false, fp32 timeout = NO_TIMEOUT);
395 
396  /*
397  * Set the servo angle
398  * @param angles: angles, like [servo-1, ..., servo-7]
399  if default_is_radian is true, the value of servo-1/.../servo-7 should be in radians
400  if default_is_radian is false, The value of servo-1/.../servo-7 should be in degrees
401  * @param servo_id: servo id, 1~7, specify the joint ID to set
402  * @param angle: servo angle, use with servo_id parameters
403  * @param speed: move speed (rad/s or °/s), default is this.last_used_joint_speed
404  if default_is_radian is true, the value of speed should be in radians
405  if default_is_radian is false, The value of speed should be in degrees
406  * @param acc: move acceleration (rad/s^2 or °/s^2), default is this.last_used_joint_acc
407  if default_is_radian is true, the value of acc should be in radians
408  if default_is_radian is false, The value of acc should be in degrees
409  * @param mvtime: reserved, 0
410  * @param wait: whether to wait for the arm to complete, default is False
411  * @param timeout: maximum waiting time(unit: second), default is no timeout, only valid if wait is true
412  * @param radius: move radius, if radius less than 0, will MoveJoint, else MoveArcJoint
413  The blending radius cannot be greater than the track length.
414  * return: see the API code documentation for details.
415  */
416  int set_servo_angle(fp32 angles[7], fp32 speed = 0, fp32 acc = 0, fp32 mvtime = 0, bool wait = false, fp32 timeout = NO_TIMEOUT, fp32 radius = -1);
417  int set_servo_angle(fp32 angles[7], bool wait = false, fp32 timeout = NO_TIMEOUT, fp32 radius = -1);
418  int set_servo_angle(int servo_id, fp32 angle, fp32 speed = 0, fp32 acc = 0, fp32 mvtime = 0, bool wait = false, fp32 timeout = NO_TIMEOUT, fp32 radius = -1);
419  int set_servo_angle(int servo_id, fp32 angle, bool wait = false, fp32 timeout = NO_TIMEOUT, fp32 radius = -1);
420 
421  /*
422  * Servo_j motion, execute only the last instruction, need to be set to servo motion mode(this.set_mode(1))
423  * @param angles: angles, like [servo-1, ..., servo-7]
424  if default_is_radian is true, the value of servo-1/.../servo-7 should be in radians
425  if default_is_radian is false, The value of servo-1/.../servo-7 should be in degrees
426  * @param speed: reserved, move speed (rad/s or °/s)
427  if default_is_radian is true, the value of speed should be in radians
428  if default_is_radian is false, The value of speed should be in degrees
429  * @param acc: reserved, move acceleration (rad/s^2 or °/s^2)
430  if default_is_radian is true, the value of acc should be in radians
431  if default_is_radian is false, The value of acc should be in degrees
432  * @param mvtime: reserved, 0
433  * return: see the API code documentation for details.
434  */
435  int set_servo_angle_j(fp32 angles[7], fp32 speed = 0, fp32 acc = 0, fp32 mvtime = 0);
436 
437  /*
438  * Servo cartesian motion, execute only the last instruction, need to be set to servo motion mode(this.set_mode(1))
439  * @param pose: position, like [x(mm), y(mm), z(mm), roll(rad or °), pitch(rad or °), yaw(rad or °)]
440  if default_is_radian is true, the value of roll/pitch/yaw should be in radians
441  if default_is_radian is false, The value of roll/pitch/yaw should be in degrees
442  * @param speed: reserved, move speed (mm/s)
443  * @param mvacc: reserved, move acceleration (mm/s^2)
444  * @param mvtime: reserved, 0
445  * @param is_tool_coord: is tool coordinate or not
446  * return: see the API code documentation for details.
447  */
448  int set_servo_cartesian(fp32 pose[6], fp32 speed = 0, fp32 acc = 0, fp32 mvtime = 0, bool is_tool_coord = false);
449 
450  /*
451  * The motion calculates the trajectory of the space circle according to the three-point coordinates.
452  The three-point coordinates are (current starting point, pose1, pose2).
453  * @param pose1: cartesian position, [x(mm), y(mm), z(mm), roll(rad or °), pitch(rad or °), yaw(rad or °)]
454  if default_is_radian is true, the value of roll/pitch/yaw should be in radians
455  if default_is_radian is false, The value of roll/pitch/yaw should be in degrees
456  * @param pose2: cartesian position, [x(mm), y(mm), z(mm), roll(rad or °), pitch(rad or °), yaw(rad or °)]
457  if default_is_radian is true, the value of roll/pitch/yaw should be in radians
458  if default_is_radian is false, The value of roll/pitch/yaw should be in degrees
459  * @param percent: the percentage of arc length and circumference of the movement
460  * @param speed: move speed (mm/s, rad/s), default is this.last_used_tcp_speed
461  * @param mvacc: move acceleration (mm/s^2, rad/s^2), default is this.last_used_tcp_acc
462  * @param mvtime: 0, reserved
463  * @param wait: whether to wait for the arm to complete, default is False
464  * @param timeout: maximum waiting time(unit: second), default is no timeout, only valid if wait is True
465  * return: see the API code documentation for details.
466  */
467  int move_circle(fp32 pose1[6], fp32 pose2[6], fp32 percent, fp32 speed = 0, fp32 acc = 0, fp32 mvtime = 0, bool wait = false, fp32 timeout = NO_TIMEOUT);
468 
469  /*
470  * Move to go home (Back to zero)
471  * @param speed: move speed (rad/s or °/s), default is 50 °/s
472  if default_is_radian is true, the value of speed should be in radians
473  if default_is_radian is false, The value of speed should be in degrees
474  * @param acc: move acceleration (rad/s^2 or °/s^2), default is 1000 °/s^2
475  if default_is_radian is true, the value of acc should be in radians
476  if default_is_radian is false, The value of acc should be in degrees
477  * @param mvtime: reserved, 0
478  * @param wait: whether to wait for the arm to complete, default is False
479  * @param timeout: maximum waiting time(unit: second), default is no timeout, only valid if wait is true
480  * return: see the API code documentation for details.
481  */
482  int move_gohome(fp32 speed = 0, fp32 acc = 0, fp32 mvtime = 0, bool wait = false, fp32 timeout = NO_TIMEOUT);
483  int move_gohome(bool wait = false, fp32 timeout = NO_TIMEOUT);
484 
485  /*
486  * Reset
487  * @param wait: whether to wait for the arm to complete, default is False
488  * @param timeout: maximum waiting time(unit: second), default is no timeout, only valid if wait is true
489  * return: see the API code documentation for details.
490  */
491  void reset(bool wait = false, fp32 timeout = NO_TIMEOUT);
492 
493  /*
494  * Emergency stop
495  */
496  void emergency_stop(void);
497 
498  /*
499  * Set the tool coordinate system offset at the end
500  * @param pose_offset: tcp offset, like [x(mm), y(mm), z(mm), roll(rad or °), pitch(rad or °), yaw(rad or °)]
501  if default_is_radian is true, the value of roll/pitch/yaw should be in radians
502  if default_is_radian is false, The value of roll/pitch/yaw should be in degrees
503  * return: see the API code documentation for details.
504  */
505  int set_tcp_offset(fp32 pose_offset[6]);
506 
507  /*
508  * Set the load
509  * @param weight: load weight (unit: kg)
510  * @param center_of_gravity: tcp load center of gravity, like [x(mm), y(mm), z(mm)]
511  * return: see the API code documentation for details.
512  */
513  int set_tcp_load(fp32 weight, fp32 center_of_gravity[3]);
514 
515  /*
516  * Set the translational jerk of Cartesian space
517  * @param jerk: jerk (mm/s^3)
518  * return: see the API code documentation for details.
519  */
520  int set_tcp_jerk(fp32 jerk);
521 
522  /*
523  * Set the max translational acceleration of Cartesian space
524  * @param acc: max acceleration (mm/s^2)
525  * return: see the API code documentation for details.
526  */
527  int set_tcp_maxacc(fp32 acc);
528 
529  /*
530  * Set the jerk of Joint space
531  * @param jerk: jerk (°/s^3 or rad/s^3)
532  if default_is_radian is true, the value of jerk should be in radians
533  if default_is_radian is false, The value of jerk should be in degrees
534  * return: see the API code documentation for details.
535  */
536  int set_joint_jerk(fp32 jerk);
537 
538  /*
539  * Set the max acceleration of Joint space
540  * @param acc: max acceleration (°/s^2 or rad/s^2)
541  if default_is_radian is true, the value of jerk should be in radians
542  if default_is_radian is false, The value of jerk should be in degrees
543  * return: see the API code documentation for details.
544  */
545  int set_joint_maxacc(fp32 acc);
546 
547  /*
548  * Get inverse kinematics
549  * @param pose: source pose, like [x(mm), y(mm), z(mm), roll(rad or °), pitch(rad or °), yaw(rad or °)]
550  if default_is_radian is true, the value of roll/pitch/yaw should be in radians
551  if default_is_radian is false, The value of roll/pitch/yaw should be in degrees
552  * @param angles: target angles, like [servo-1, ..., servo-7]
553  if default_is_radian is true, the value of servo-1/.../servo-7 should be in radians
554  if default_is_radian is false, The value of servo-1/.../servo-7 should be in degrees
555  * return: see the API code documentation for details.
556  */
557  int get_inverse_kinematics(fp32 pose[6], fp32 angles[7]);
558 
559  /*
560  * Get forward kinematics
561  * @param angles: source angles, like [servo-1, ..., servo-7]
562  if default_is_radian is true, the value of servo-1/.../servo-7 should be in radians
563  if default_is_radian is false, The value of servo-1/.../servo-7 should be in degrees
564  * @param pose: target pose, like [x(mm), y(mm), z(mm), roll(rad or °), pitch(rad or °), yaw(rad or °)]
565  if default_is_radian is true, the value of roll/pitch/yaw should be in radians
566  if default_is_radian is false, The value of roll/pitch/yaw should be in degrees
567  * return: see the API code documentation for details.
568  */
569  int get_forward_kinematics(fp32 angles[7], fp32 pose[6]);
570 
571  /*
572  * Check the tcp pose is in limit
573  * @param pose: pose, like [x(mm), y(mm), z(mm), roll(rad or °), pitch(rad or °), yaw(rad or °)]
574  if default_is_radian is true, the value of roll/pitch/yaw should be in radians
575  if default_is_radian is false, The value of roll/pitch/yaw should be in degrees
576  * @param limit: 1: limit, 0: no limit
577  * return: see the API code documentation for details.
578  */
579  int is_tcp_limit(fp32 pose[6], int *limit);
580 
581  /*
582  * Check the joint is in limit
583  * @param angles: angles, like [servo-1, ..., servo-7]
584  if default_is_radian is true, the value of servo-1/.../servo-7 should be in radians
585  if default_is_radian is false, The value of servo-1/.../servo-7 should be in degrees
586  * @param limit: 1: limit, 0: no limit
587  * return: see the API code documentation for details.
588  */
589  int is_joint_limit(fp32 angles[7], int *limit);
590 
591  /*
592  * Set the gripper enable
593  * @param enable: enable or not
594  * return: see the API code documentation for details.
595  */
596  int set_gripper_enable(bool enable);
597 
598  /*
599  * Set the gripper mode
600  * @param mode: 1: location mode, 2: speed mode(no use), 3: torque mode(no use)
601  * return: see the API code documentation for details.
602  */
603  int set_gripper_mode(int mode);
604 
605  /*
606  * Get the gripper position
607  * @param pos: used to store the results obtained
608  * return: see the API code documentation for details.
609  */
610  int get_gripper_position(fp32 *pos);
611 
612  /*
613  * Set the gripper position
614  * @param pos: gripper position
615  * @param wait: wait or not, default is false
616  * @param timeout: maximum waiting time(unit: second), default is 10s, only valid if wait is true
617  * return: see the API code documentation for details.
618  */
619  int set_gripper_position(fp32 pos, bool wait = false, fp32 timeout = 10);
620 
621  /*
622  * Set the gripper speed
623  * @param speed:
624  * return: see the API code documentation for details.
625  */
626  int set_gripper_speed(fp32 speed);
627 
628  /*
629  * Get the gripper error code
630  * @param err: used to store the results obtained
631  * return: see the API code documentation for details.
632  */
633  int get_gripper_err_code(int *err);
634 
635  /*
636  * Clean the gripper error
637  * return: see the API code documentation for details.
638  */
639  int clean_gripper_error(void);
640 
641  /*
642  * Get the digital value of the Tool GPIO
643  * @param io0_value: the digital value of Tool GPIO-0
644  * @param io1_value: the digital value of Tool GPIO-1
645  * return: see the API code documentation for details.
646  */
647  int get_tgpio_digital(int *io0_value, int *io1_value);
648 
649  /*
650  * Set the digital value of the specified Tool GPIO
651  * @param ionum: ionum, 0 or 1
652  * @param value: the digital value of the specified io
653  * @param delay_sec: delay effective time from the current start, in seconds, default is 0(effective immediately)
654  * return: see the API code documentation for details.
655  */
656  int set_tgpio_digital(int ionum, int value, float delay_sec=0);
657 
658  /*
659  * Get the analog value of the specified Tool GPIO
660  * @param ionum: ionum, 0 or 1
661  * @param value: the analog value of the specified tool io
662  * return: see the API code documentation for details.
663  */
664  int get_tgpio_analog(int ionum, float *value);
665 
666  /*
667  * Get the digital value of the specified Controller GPIO
668  * @param digitals: the values of the controller GPIO(0-7)
669  * @param digitals2: the values of the controller GPIO(8-15)
670  * return: see the API code documentation for details.
671  */
672  int get_cgpio_digital(int *digitals, int *digitals2 = NULL);
673 
674  /*
675  * Get the analog value of the specified Controller GPIO
676  * @param ionum: ionum, 0 or 1
677  * @param value: the analog value of the specified controller io
678  * return: see the API code documentation for details.
679  */
680  int get_cgpio_analog(int ionum, fp32 *value);
681 
682  /*
683  * Set the digital value of the specified Controller GPIO
684  * @param ionum: ionum, 0 ~ 7
685  * @param value: the digital value of the specified io
686  * @param delay_sec: delay effective time from the current start, in seconds, default is 0(effective immediately)
687  * return: see the API code documentation for details.
688  */
689  int set_cgpio_digital(int ionum, int value, float delay_sec=0);
690 
691  /*
692  * Set the analog value of the specified Controller GPIO
693  * @param ionum: ionum, 0 or 1
694  * @param value: the analog value of the specified io
695  * return: see the API code documentation for details.
696  */
697  int set_cgpio_analog(int ionum, fp32 value);
698 
699  /*
700  * Set the digital input functional mode of the Controller GPIO
701  * @param ionum: ionum, 0 ~ 7
702  * @param fun: functional mode
703  0: general input
704  1: external emergency stop
705  2: reversed, protection reset
706  3: reversed, reduced mode
707  4: reversed, operating mode
708  5: reversed, three-state switching signal
709  11: offline task
710  12: teaching mode
711  * return: see the API code documentation for details.
712  */
713  int set_cgpio_digital_input_function(int ionum, int fun);
714 
715  /*
716  * Set the digital output functional mode of the specified Controller GPIO
717  * @param ionum: ionum, 0 ~ 7
718  * @param fun: functional mode
719  0: general output
720  1: emergency stop
721  2: in motion
722  11: has error
723  12: has warn
724  13: in collision
725  14: in teaching
726  15: in offline task
727  * return: see the API code documentation for details.
728  */
729  int set_cgpio_digital_output_function(int ionum, int fun);
730 
731  /*
732  * Get the state of the Controller GPIO
733  * @param state: contorller gpio module state and controller gpio module error code
734  state[0]: contorller gpio module state
735  state[0] == 0: normal
736  state[0] == 1:wrong
737  state[0] == 6:communication failure
738  state[1]: controller gpio module error code
739  state[1] == 0: normal
740  state[1] != 0:error code
741  * @param digit_io:
742  digit_io[0]: digital input functional gpio state
743  digit_io[1]: digital input configuring gpio state
744  digit_io[2]: digital output functional gpio state
745  digit_io[3]: digital output configuring gpio state
746  * @param analog:
747  analog[0]: analog-0 input value
748  analog[1]: analog-1 input value
749  analog[2]: analog-0 output value
750  analog[3]: analog-1 output value
751  * @param input_conf: digital(0-7) input functional info
752  * @param output_conf: digital(0-7) output functional info
753  * @param input_conf2: digital(8-15) input functional info
754  * @param output_conf2: digital(8-15) output functional info
755  * return: see the API code documentation for details.
756  */
757  int get_cgpio_state(int *state, int *digit_io, fp32 *analog, int *input_conf, int *output_conf, int *input_conf2 = NULL, int *output_conf2 = NULL);
758 
759  /*
760  * Register the report location callback
761  */
762  int register_report_location_callback(void(*callback)(const fp32 *pose, const fp32 *angles));
763 
764  /*
765  * Register the connect status changed callback
766  */
767  int register_connect_changed_callback(void(*callback)(bool connected, bool reported));
768 
769  /*
770  * Register the state status changed callback
771  */
772  int register_state_changed_callback(void(*callback)(int state));
773 
774  /*
775  * Register the mode changed callback
776  */
777  int register_mode_changed_callback(void(*callback)(int mode));
778 
779  /*
780  * Register the motor enable states or motor brake states changed callback
781  */
782  int register_mtable_mtbrake_changed_callback(void(*callback)(int mtable, int mtbrake));
783 
784  /*
785  * Register the error code or warn code changed callback
786  */
787  int register_error_warn_changed_callback(void(*callback)(int err_code, int warn_code));
788 
789  /*
790  * Register the cmdnum changed callback
791  */
792  int register_cmdnum_changed_callback(void(*callback)(int cmdnum));
793 
794  /*
795  * Register the temperature changed callback
796  */
797  int register_temperature_changed_callback(void(*callback)(const fp32 *temps));
798 
799  /*
800  * Register the value of counter changed callback
801  */
802  int register_count_changed_callback(void(*callback)(int count));
803 
804  /*
805  * Release the location report callback
806  * @param callback: NULL means to release all callbacks;
807  */
808  int release_report_location_callback(void(*callback)(const fp32 *pose, const fp32 *angles) = NULL);
809 
810  /*
811  * Release the connect changed callback
812  * @param callback: NULL means to release all callbacks for the same event
813  */
814  int release_connect_changed_callback(void(*callback)(bool connected, bool reported) = NULL);
815 
816  /*
817  * Release the state changed callback
818  * @param callback: NULL means to release all callbacks for the same event
819  */
820  int release_state_changed_callback(void(*callback)(int state) = NULL);
821 
822  /*
823  * Release the mode changed callback
824  * @param callback: NULL means to release all callbacks for the same event
825  */
826  int release_mode_changed_callback(void(*callback)(int mode) = NULL);
827 
828  /*
829  * Release the motor enable states or motor brake states changed callback
830  * @param callback: NULL means to release all callbacks for the same event
831  */
832  int release_mtable_mtbrake_changed_callback(void(*callback)(int mtable, int mtbrake) = NULL);
833 
834  /*
835  * Release the error warn changed callback
836  * @param callback: NULL means to release all callbacks for the same event
837  */
838  int release_error_warn_changed_callback(void(*callback)(int err_code, int warn_code) = NULL);
839 
840  /*
841  * Release the cmdnum changed callback
842  * @param callback: NULL means to release all callbacks for the same event
843  */
844  int release_cmdnum_changed_callback(void(*callback)(int cmdnum) = NULL);
845 
846  /*
847  * Release the temperature changed callback
848  * @param callback: NULL means to release all callbacks for the same event
849  */
850  int release_temperature_changed_callback(void(*callback)(const fp32 *temps) = NULL);
851 
852  /*
853  * Release the value of counter changed callback
854  * @param callback: NULL means to release all callbacks for the same event
855  */
856  int release_count_changed_callback(void(*callback)(int count) = NULL);
857 
858  /*
859  * Get suction cup state
860  * @param val:
861  0: suction cup is off
862  1: suction cup is on
863  * return: see the API code documentation for details.
864  */
865  int get_suction_cup(int *val);
866  int get_vacuum_gripper(int *val) { return get_suction_cup(val); }
867 
868  /*
869  * Set suction cup
870  * @param on: open suction cup or not
871  * @param wait: wait or not, default is false
872  * @param timeout: maximum waiting time(unit: second), default is 10s, only valid if wait is true
873  * @param delay_sec: delay effective time from the current start, in seconds, default is 0(effective immediately)
874  * return: see the API code documentation for details.
875  */
876  int set_suction_cup(bool on, bool wait = false, float timeout = 3, float delay_sec = 0);
877  int set_vacuum_gripper(bool on, bool wait = false, float timeout = 3, float delay_sec = 0) { return set_suction_cup(on, wait, timeout, delay_sec); }
878 
879  /*
880  * Get gripper version, only for debug
881  * return: see the API code documentation for details.
882  */
883  int get_gripper_version(unsigned char versions[3]);
884 
885  /*
886  * Get servo version, only for debug
887  * return: see the API code documentation for details.
888  */
889  int get_servo_version(unsigned char versions[3], int servo_id = 1);
890 
891  /*
892  * Get tool gpio version, only for debug
893  * return: see the API code documentation for details.
894  */
895  int get_tgpio_version(unsigned char versions[3]);
896 
897  /*
898  * Reload dynamics, only for debug
899  * return: see the API code documentation for details.
900  */
901  int reload_dynamics(void);
902 
903  /*
904  * Turn on/off reduced mode
905  * @param on: on/off
906  * return: see the API code documentation for details.
907  */
908  int set_reduced_mode(bool on);
909 
910  /*
911  * Set the maximum tcp speed of the reduced mode
912  * @param speed: the maximum tcp speed
913  * return: see the API code documentation for details.
914  */
915  int set_reduced_max_tcp_speed(float speed);
916 
917  /*
918  * Set the maximum joint speed of the reduced mode
919  * @param speed: the maximum joint speed
920  if default_is_radian is true, the value of speed should be in radians
921  if default_is_radian is false, The value of speed should be in degrees
922  * return: see the API code documentation for details.
923  */
924  int set_reduced_max_joint_speed(float speed);
925 
926  /*
927  * Get reduced mode
928  * @param mode:
929  0: reduced mode is on
930  1: reduced mode is off
931  * return: see the API code documentation for details.
932  */
933  int get_reduced_mode(int *mode);
934 
935  /*
936  * Get states of the reduced mode
937  * @param on:
938  0: reduced mode is on
939  1: reduced mode is off
940  * @param xyz_list: the tcp boundary, like [reduced_x_max, reduced_x_min, reduced_y_max, reduced_y_min, reduced_z_max, reduced_z_min],
941  * @param tcp_speed: the maximum tcp speed of reduced mode
942  * @param joint_speed: the maximum joint speed of reduced mode
943  if default_is_radian is true, the value of speed should be in radians
944  if default_is_radian is false, The value of speed should be in degrees
945  * @param jrange: the joint range of the reduced mode, like [joint-1-min, joint-1-max, ..., joint-7-min, joint-7-max]
946  if default_is_radian is true, the value of speed should be in radians
947  if default_is_radian is false, The value of speed should be in degrees
948  * @param fense_is_on:
949  0: safety mode is on
950  1: safety mode is off
951  * @param collision_rebound_is_on:
952  0: collision rebound is on
953  1: collision rebound is off
954  * return: see the API code documentation for details.
955  */
956  int get_reduced_states(int *on, int *xyz_list, float *tcp_speed, float *joint_speed, float jrange[14] = NULL, int *fense_is_on = NULL, int *collision_rebound_is_on = NULL);
957 
958  /*
959  * Set the boundary of the safety boundary mode
960  * @param boundary: like [x_max(mm), x_min(mm), y_max(mm), y_min(mm), z_max(mm), z_min(mm)]
961  * return: see the API code documentation for details.
962  */
963  int set_reduced_tcp_boundary(int boundary[6]);
964 
965  /*
966  * Set the joint range of the reduced mode
967  * @param jrange: like [joint-1-min, joint-1-max, ..., joint-7-min, joint-7-max]
968  if default_is_radian is true, the value of speed should be in radians
969  if default_is_radian is false, The value of speed should be in degrees
970  * return: see the API code documentation for details.
971  */
972  int set_reduced_joint_range(float jrange[14]);
973 
974  /*
975  * Turn on/off safety mode
976  * @param on: on/off
977  * return: see the API code documentation for details.
978  */
979  int set_fense_mode(bool on);
980  int set_fence_mode(bool on) { return set_fense_mode(on); };
981 
982  /*
983  * Turn on/off collision rebound
984  * @param on: on/off
985  * return: see the API code documentation for details.
986  */
987  int set_collision_rebound(bool on);
988 
989  /*
990  * Set the base coordinate system offset at the end
991  * @param pose_offset: tcp offset, like [x(mm), y(mm), z(mm), roll(rad or °), pitch(rad or °), yaw(rad or °)]
992  if default_is_radian is true, the value of roll/pitch/yaw should be in radians
993  if default_is_radian is false, The value of roll/pitch/yaw should be in degrees
994  * return: see the API code documentation for details.
995  */
996  int set_world_offset(float pose_offset[6]);
997 
998  /*
999  * Start trajectory recording, only in teach mode, so you need to set joint teaching mode before.
1000  * return: see the API code documentation for details.
1001  */
1002  int start_record_trajectory(void);
1003 
1004  /*
1005  * Stop trajectory recording
1006  * @param filename: the name to save
1007  If the filename is NULL, just stop recording, do not save, you need to manually call `save_record_trajectory` save before changing the mode. otherwise it will be lost
1008  the trajectory is saved in the controller box.
1009  this action will overwrite the trajectory with the same name
1010  empty the trajectory in memory after saving, so repeated calls will cause the recorded trajectory to be covered by an empty trajectory.
1011  * return: see the API code documentation for details.
1012  */
1013  int stop_record_trajectory(char* filename = NULL);
1014 
1015  /*
1016  * Save the trajectory you just recorded
1017  * @param filename: the name to save
1018  the trajectory is saved in the controller box.
1019  this action will overwrite the trajectory with the same name
1020  empty the trajectory in memory after saving, so repeated calls will cause the recorded trajectory to be covered by an empty trajectory.
1021  * return: see the API code documentation for details.
1022  */
1023  int save_record_trajectory(char* filename, float timeout = 10);
1024 
1025  /*
1026  * Load the trajectory
1027  * @param filename: the name of the trajectory to load
1028  * @param timeout: the maximum timeout waiting for loading to complete, default is 10 seconds.
1029  return: see the API code documentation for details.
1030  */
1031  int load_trajectory(char* filename, float timeout = 10);
1032 
1033  /*
1034  * Playback trajectory
1035  * @param times: number of playbacks.
1036  * @param filename: the name of the trajectory to play back
1037  if filename is None, you need to manually call the `load_trajectory` to load the trajectory.
1038  * @param wait: whether to wait for the arm to complete, default is False.
1039  * @param double_speed: double speed, only support 1/2/4, default is 1, only available if version > 1.2.11
1040  * return: see the API code documentation for details.
1041  */
1042  int playback_trajectory(int times = 1, char* filename = NULL, bool wait = false, int double_speed = 1);
1043 
1044  /*
1045  * Get trajectory read/write status
1046  * @param status:
1047  0: no read/write
1048  1: loading
1049  2: load success
1050  3: load failed
1051  4: saving
1052  5: save success
1053  6: save failed
1054  * return: see the API code documentation for details.
1055  */
1056  int get_trajectory_rw_status(int *status);
1057 
1058  /*
1059  * Reset counter value
1060  * return: see the API code documentation for details.
1061  */
1062  int set_counter_reset(void);
1063 
1064  /*
1065  * Set counter plus 1
1066  * return: see the API code documentation for details.
1067  */
1068  int set_counter_increase(void);
1069 
1070  /*
1071  * Set the digital value of the specified Tool GPIO when the robot has reached the specified xyz position
1072  * @param ionum: 0 or 1
1073  * @param value: value
1074  * @param xyz: position xyz, as [x, y, z]
1075  * @param tol_r: fault tolerance radius
1076  * return: see the API code documentation for details.
1077  */
1078  int set_tgpio_digital_with_xyz(int ionum, int value, float xyz[3], float tol_r);
1079 
1080  /*
1081  * Set the digital value of the specified Controller GPIO when the robot has reached the specified xyz position
1082  * @param ionum: 0 ~ 7
1083  * @param value: value
1084  * @param xyz: position xyz, as [x, y, z]
1085  * @param tol_r: fault tolerance radius
1086  * return: see the API code documentation for details.
1087  */
1088  int set_cgpio_digital_with_xyz(int ionum, int value, float xyz[3], float tol_r);
1089 
1090  /*
1091  * Set the analog value of the specified Controller GPIO when the robot has reached the specified xyz position
1092  * @param ionum: 0 ~ 1
1093  * @param value: value, 0~10.0
1094  * @param xyz: position xyz, as [x, y, z]
1095  * @param tol_r: fault tolerance radius
1096  * return: see the API code documentation for details.
1097  */
1098  int set_cgpio_analog_with_xyz(int ionum, float value, float xyz[3], float tol_r);
1099 
1100  /*
1101  * Config the Tool GPIO reset the digital output when the robot is in stop state
1102  * @param on_off: true/false
1103  * return: see the API code documentation for details.
1104  */
1105  int config_tgpio_reset_when_stop(bool on_off);
1106 
1107  /*
1108  * Config the Controller GPIO reset the digital output when the robot is in stop state
1109  * @param on_off: true/false
1110  * return: see the API code documentation for details.
1111  */
1112  int config_cgpio_reset_when_stop(bool on_off);
1113 
1114  /*
1115  * Set the pose represented by the axis angle pose
1116  * @param pose: the axis angle pose, like [x(mm), y(mm), z(mm), rx(rad or °), ry(rad or °), rz(rad or °)]
1117  if default_is_radian is true, the value of rx/ry/rz should be in radians
1118  if default_is_radian is false, The value of rx/ry/rz should be in degrees
1119  * @param speed: move speed (mm/s, rad/s), default is this.last_used_tcp_speed
1120  * @param mvacc: move acceleration (mm/s^2, rad/s^2), default is this.last_used_tcp_acc
1121  * @param mvtime: reserved, 0
1122  * @param is_tool_coord: is tool coordinate or not
1123  * @param relative: relative move or not
1124  * @param wait: whether to wait for the arm to complete, default is False
1125  * @param timeout: maximum waiting time(unit: second), default is no timeout, only valid if wait is true
1126  * return: see the API code documentation for details.
1127  */
1128  int set_position_aa(fp32 pose[6], fp32 speed = 0, fp32 acc = 0, fp32 mvtime = 0, bool is_tool_coord = false, bool relative = false, bool wait = false, fp32 timeout = NO_TIMEOUT);
1129  int set_position_aa(fp32 pose[6], bool is_tool_coord = false, bool relative = false, bool wait = false, fp32 timeout = NO_TIMEOUT);
1130 
1131  /*
1132  * Set the servo cartesian represented by the axis angle pose, execute only the last instruction, need to be set to servo motion mode(self.set_mode(1))
1133  only available if firmware_version >= 1.4.7
1134  * @param pose: the axis angle pose, like [x(mm), y(mm), z(mm), rx(rad or °), ry(rad or °), rz(rad or °)]
1135  if default_is_radian is true, the value of rx/ry/rz should be in radians
1136  if default_is_radian is false, The value of rx/ry/rz should be in degrees
1137  * @param speed: reserved, move speed (mm/s)
1138  * @param mvacc: reserved, move acceleration (mm/s^2)
1139  * @param is_tool_coord: is tool coordinate or not
1140  * @param relative: relative move or not
1141  * return: see the API code documentation for details.
1142  */
1143  int set_servo_cartesian_aa(fp32 pose[6], fp32 speed = 0, fp32 acc = 0, bool is_tool_coord = false, bool relative = false);
1144  int set_servo_cartesian_aa(fp32 pose[6], bool is_tool_coord = false, bool relative = false);
1145 
1146  /*
1147  * Calculate the pose offset of two given points
1148  * @param pose1: position, like [x(mm), y(mm), z(mm), roll/rx(rad or °), pitch/ry(rad or °), yaw/rz(rad or °)]
1149  if default_is_radian is true, the value of roll/rx/pitch/ry/yaw/rz should be in radians
1150  if default_is_radian is false, The value of roll/rx/pitch/ry/yaw/rz should be in degrees
1151  * @param pose2: position, like [x(mm), y(mm), z(mm), roll/rx(rad or °), pitch/ry(rad or °), yaw/rz(rad or °)]
1152  if default_is_radian is true, the value of roll/rx/pitch/ry/yaw/rz should be in radians
1153  if default_is_radian is false, The value of roll/rx/pitch/ry/yaw/rz should be in degrees
1154  * @param offset: the offset between pose1 and pose2
1155  * @param orient_type_in: input attitude notation, 0 is RPY (default), 1 is axis angle
1156  * @param orient_type_out: notation of output attitude, 0 is RPY (default), 1 is axis angle
1157  * return: see the API code documentation for details.
1158  */
1159  int get_pose_offset(float pose1[6], float pose2[6], float offset[6], int orient_type_in = 0, int orient_type_out = 0);
1160 
1161  /*
1162  * Get the pose represented by the axis angle pose
1163  * @param pose: the pose represented by the axis angle pose of xArm, like [x(mm), y(mm), z(mm), rx(rad or °), ry(rad or °), rz(rad or °)]
1164  if default_is_radian is true, the value of rx/ry/rz should be in radians
1165  if default_is_radian is false, The value of rx/ry/rz should be in degrees
1166  * return: see the API code documentation for details.
1167  */
1168  int get_position_aa(fp32 pose[6]);
1169 
1170  /*
1171  * Reset the robotiq gripper (clear previous activation if any)
1172  * @param ret_data: the response from robotiq
1173  * return: see the API code documentation for details.
1174  */
1175  int robotiq_reset(unsigned char ret_data[6] = NULL);
1176 
1177  /*
1178  * If not already activated. Activate the robotiq gripper
1179  * @param wait: whether to wait for the robotiq activate complete, default is true
1180  * @param timeout: maximum waiting time(unit: second), default is 3, only available if wait=true
1181  * @param ret_data: the response from robotiq
1182  * return: see the API code documentation for details.
1183  */
1184  int robotiq_set_activate(bool wait = true, fp32 timeout = 3, unsigned char ret_data[6] = NULL);
1185  int robotiq_set_activate(bool wait = true, unsigned char ret_data[6] = NULL);
1186  int robotiq_set_activate(unsigned char ret_data[6] = NULL);
1187 
1188  /*
1189  * Go to the position with determined speed and force.
1190  * @param pos: position of the gripper. Integer between 0 and 255. 0 being the open position and 255 being the close position.
1191  * @param speed: gripper speed between 0 and 255
1192  * @param force: gripper force between 0 and 255
1193  * @param wait: whether to wait for the robotion motion complete, default is true
1194  * @param timeout: maximum waiting time(unit: second), default is 5, only available if wait=true
1195  * @param ret_data: the response from robotiq
1196  * return: see the API code documentation for details.
1197  */
1198  int robotiq_set_position(unsigned char pos, unsigned char speed = 0xFF, unsigned char force = 0xFF, bool wait = true, fp32 timeout = 5, unsigned char ret_data[6] = NULL);
1199  int robotiq_set_position(unsigned char pos, bool wait = true, fp32 timeout = 5, unsigned char ret_data[6] = NULL);
1200  int robotiq_set_position(unsigned char pos, bool wait = true, unsigned char ret_data[6] = NULL);
1201  int robotiq_set_position(unsigned char pos, unsigned char ret_data[6] = NULL);
1202 
1203  /*
1204  * Open the robotiq gripper
1205  * @param speed: gripper speed between 0 and 255
1206  * @param force: gripper force between 0 and 255
1207  * @param wait: whether to wait for the robotion motion complete, default is true
1208  * @param timeout: maximum waiting time(unit: second), default is 5, only available if wait=true
1209  * @param ret_data: the response from robotiq
1210  * return: see the API code documentation for details.
1211  */
1212  int robotiq_open(unsigned char speed = 0xFF, unsigned char force = 0xFF, bool wait = true, fp32 timeout = 5, unsigned char ret_data[6] = NULL);
1213  int robotiq_open(bool wait = true, fp32 timeout = 5, unsigned char ret_data[6] = NULL);
1214  int robotiq_open(bool wait = true, unsigned char ret_data[6] = NULL);
1215  int robotiq_open(unsigned char ret_data[6] = NULL);
1216 
1217  /*
1218  * Close the robotiq gripper
1219  * @param speed: gripper speed between 0 and 255
1220  * @param force: gripper force between 0 and 255
1221  * @param wait: whether to wait for the robotion motion complete, default is true
1222  * @param timeout: maximum waiting time(unit: second), default is 5, only available if wait=true
1223  * @param ret_data: the response from robotiq
1224  * return: see the API code documentation for details.
1225  */
1226  int robotiq_close(unsigned char speed = 0xFF, unsigned char force = 0xFF, bool wait = true, fp32 timeout = 5, unsigned char ret_data[6] = NULL);
1227  int robotiq_close(bool wait = true, fp32 timeout = 5, unsigned char ret_data[6] = NULL);
1228  int robotiq_close(bool wait = true, unsigned char ret_data[6] = NULL);
1229  int robotiq_close(unsigned char ret_data[6] = NULL);
1230 
1231  /*
1232  * Reading the status of robotiq gripper
1233  * @param ret_data: the response from robotiq
1234  * @param number_of_registers: number of registers, 1/2/3, default is 3
1235  number_of_registers=1: reading the content of register 0x07D0
1236  number_of_registers=2: reading the content of register 0x07D0/0x07D1
1237  number_of_registers=3: reading the content of register 0x07D0/0x07D1/0x07D2
1238 
1239  Note:
1240  register 0x07D0: Register GRIPPER STATUS
1241  register 0x07D1: Register FAULT STATUS and register POSITION REQUEST ECHO
1242  register 0x07D2: Register POSITION and register CURRENT
1243  * return: see the API code documentation for details.
1244  */
1245  int robotiq_get_status(unsigned char ret_data[9], unsigned char number_of_registers = 3);
1246 
1247  /*
1248  * If not already enabled. Enable the bio gripper
1249 
1250  * @param enable: enable or not
1251  * @param wait: whether to wait for the bio gripper enable complete, default is True
1252  * @param timeout: maximum waiting time(unit: second), default is 3, only available if wait=true
1253 
1254  * return: See the code documentation for details.
1255  */
1256  int set_bio_gripper_enable(bool enable, bool wait = true, fp32 timeout = 3);
1257 
1258  /*
1259  * Set the speed of the bio gripper
1260 
1261  * @param speed: speed
1262 
1263  * return: See the code documentation for details.
1264  */
1265  int set_bio_gripper_speed(int speed);
1266 
1267  /*
1268  * Open the bio gripper
1269 
1270  * @param speed: speed value, default is 0 (not set the speed)
1271  * @param wait: whether to wait for the bio gripper motion complete, default is True
1272  * @param timeout: maximum waiting time(unit: second), default is 5, only available if wait=true
1273 
1274  * return: See the code documentation for details.
1275  */
1276  int open_bio_gripper(int speed = 0, bool wait = true, fp32 timeout = 5);
1277  int open_bio_gripper(bool wait = true, fp32 timeout = 5);
1278 
1279  /*
1280  * Close the bio gripper
1281 
1282  * @param speed: speed value, default is 0 (not set the speed)
1283  * @param wait: whether to wait for the bio gripper motion complete, default is True
1284  * @param timeout: maximum waiting time(unit: second), default is 5, only available if wait=true
1285 
1286  * return: See the code documentation for details.
1287  */
1288  int close_bio_gripper(int speed = 0, bool wait = true, fp32 timeout = 5);
1289  int close_bio_gripper(bool wait = true, fp32 timeout = 5);
1290 
1291  /*
1292  * Get the status of the bio gripper
1293 
1294  * @param status: the result of the bio gripper status value
1295  status & 0x03 == 0: stop
1296  status & 0x03 == 1: motion
1297  status & 0x03 == 2: catch
1298  status & 0x03 == 3: error
1299  (status >> 2) & 0x03 == 0: not enabled
1300  (status >> 2) & 0x03 == 1: enabling
1301  (status >> 2) & 0x03 == 2: enabled
1302 
1303  * return: See the code documentation for details.
1304  */
1305  int get_bio_gripper_status(int *status);
1306 
1307  /*
1308  * Get the error code of the bio gripper
1309 
1310  * @param err: the result of the bio gripper error code
1311 
1312  * return: See the code documentation for details.
1313  */
1314  int get_bio_gripper_error(int *err);
1315 
1316  /*
1317  * Clean the error code of the bio gripper
1318 
1319  * return: See the code documentation for details.
1320  */
1321  int clean_bio_gripper_error(void);
1322 
1323  /*
1324  * Set the modbus timeout of the tool gpio
1325 
1326  * @param timeout: timeout, seconds
1327 
1328  * return: See the code documentation for details.
1329  */
1330  int set_tgpio_modbus_timeout(int timeout);
1331 
1332  /*
1333  * Set the modbus baudrate of the tool gpio
1334 
1335  * @param baud: baudrate, 4800/9600/19200/38400/57600/115200/230400/460800/921600/1000000/1500000/2000000/2500000
1336 
1337  * return: See the code documentation for details.
1338  */
1339  int set_tgpio_modbus_baudrate(int baud);
1340 
1341  /*
1342  * Get the modbus baudrate of the tool gpio
1343 
1344  * @param baud: the result of baudrate
1345 
1346  * return: See the code documentation for details.
1347  */
1348  int get_tgpio_modbus_baudrate(int *baud);
1349 
1350  /*
1351  * Send the modbus data to the tool gpio
1352 
1353  * @param modbus_data: send data
1354  * @param modbus_length: the length of the modbus_data
1355  * @param ret_data: the response data of the modbus
1356  * @param ret_length: the length of the response data
1357 
1358  * return: See the code documentation for details.
1359  */
1360  int getset_tgpio_modbus_data(unsigned char *modbus_data, int modbus_length, unsigned char *ret_data, int ret_length);
1361 
1362  /*
1363  * Set the reported torque or electric current
1364 
1365  * @param tau_or_i:
1366  0: torque
1367  1: electric current
1368 
1369  * return: See the code documentation for details.
1370  */
1371  int set_report_tau_or_i(int tau_or_i = 0);
1372 
1373  /*
1374  * Get the reported torque or electric current
1375 
1376  * @param tau_or_i: the result of the tau_or_i
1377 
1378  * return: See the code documentation for details.
1379  */
1380  int get_report_tau_or_i(int *tau_or_i);
1381 
1382  /*
1383  * Set whether to enable self-collision detection
1384 
1385  * @param on: enable or not
1386 
1387  * return: See the code documentation for details.
1388  */
1389  int set_self_collision_detection(bool on);
1390 
1391  /*
1392  * Set the geometric model of the end effector for self collision detection
1393 
1394  * @param tool_type: the geometric model type
1395  0: No end effector, no additional parameters required
1396  1: xArm Gripper, no additional parameters required
1397  2: xArm Vacuum Gripper, no additional parameters required
1398  3: xArm Bio Gripper, no additional parameters required
1399  4: Robotiq-2F-85 Gripper, no additional parameters required
1400  5: Robotiq-2F-140 Gripper, no additional parameters required
1401  21: Cylinder, need additional parameters radius, height
1402  arm->set_collision_tool_model(21, 2, radius, height)
1403  @param radius: the radius of cylinder, (unit: mm)
1404  @param height: the height of cylinder, (unit: mm)
1405  22: Cuboid, need additional parameters x, y, z
1406  arm->set_collision_tool_model(22, 3, x, y, z)
1407  @param x: the length of the cuboid in the x coordinate direction, (unit: mm)
1408  @param y: the length of the cuboid in the y coordinate direction, (unit: mm)
1409  @param z: the length of the cuboid in the z coordinate direction, (unit: mm)
1410 
1411  * @param n: the count of the additional parameters
1412  * @param ...: additional parameters
1413 
1414  * return: See the code documentation for details.
1415  */
1416  int set_collision_tool_model(int tool_type, int n = 0, ...);
1417 
1418  /*
1419  * Set the simulation robot
1420 
1421  * @param on: enable or not
1422 
1423  * return: See the code documentation for details.
1424  */
1425  int set_simulation_robot(bool on);
1426 
1427  /*
1428  * Joint velocity control, need to be set to joint velocity control mode(this.set_mode(4))
1429 
1430  * @param speeds: [spd_J1, spd_J2, ..., spd_J7]
1431  if default_is_radian is true, the value of spd_J1/.../spd_J1 should be in radians
1432  if default_is_radian is false, the value of spd_J1/.../spd_J1 should be in degrees
1433  * @param is_sync: whether all joints accelerate and decelerate synchronously, default is true
1434 
1435  * return: See the code documentation for details.
1436  */
1437  int vc_set_joint_velocity(fp32 speeds[7], bool is_sync = true);
1438 
1439  /*
1440  * Cartesian velocity control, need to be set to cartesian velocity control mode(self.set_mode(5))
1441 
1442  * @param speeds: [spd_x, spd_y, spd_z, spd_rx, spd_ry, spd_rz]
1443  if default_is_radian is true, the value of spd_rx/spd_ry/spd_rz should be in radians
1444  if default_is_radian is false, the value of spd_rx/spd_ry/spd_rz should be in degrees
1445  * @param is_tool_coord: is tool coordinate or not, default is false
1446 
1447  * return: See the code documentation for details.
1448  */
1449  int vc_set_cartesian_velocity(fp32 speeds[6], bool is_tool_coord = false);
1450 
1451  int set_timeout(fp32 timeout);
1452 private:
1453  void _init(void);
1454  void _sync(void);
1455  void _check_version(void);
1456  bool _version_is_ge(int major = 1, int minor = 2, int revision = 11);
1457  void _check_is_pause(void);
1458  int _wait_until_cmdnum_lt_max(void);
1459  int _check_code(int code, bool is_move_cmd = false);
1460  int _wait_move(fp32 timeout);
1461  void _update_old(unsigned char *data);
1462  void _update(unsigned char *data);
1463  template<typename callable_vector, typename callable>
1464  inline int _register_event_callback(callable_vector&& callbacks, callable&& f);
1465  template<typename callable_vector, typename callable>
1466  inline int _release_event_callback(callable_vector&& callbacks, callable&& f);
1467  template<typename callable_vector, class... arguments>
1468  inline void _report_callback(callable_vector&& callbacks, arguments&&... args);
1469  inline void _report_location_callback(void);
1470  inline void _report_connect_changed_callback(void);
1471  inline void _report_state_changed_callback(void);
1472  inline void _report_mode_changed_callback(void);
1473  inline void _report_mtable_mtbrake_changed_callback(void);
1474  inline void _report_error_warn_changed_callback(void);
1475  inline void _report_cmdnum_changed_callback(void);
1476  inline void _report_temperature_changed_callback(void);
1477  inline void _report_count_changed_callback(void);
1478  int _check_modbus_code(int ret, unsigned char *rx_data = NULL);
1479  int _get_modbus_baudrate(int *baud_inx);
1480  int _checkset_modbus_baud(int baudrate, bool check = true);
1481  int _robotiq_set(unsigned char *params, int length, unsigned char ret_data[6]);
1482  int _robotiq_get(unsigned char ret_data[9], unsigned char number_of_registers = 0x03);
1483  int _robotiq_wait_activation_completed(fp32 timeout = 3);
1484  int _robotiq_wait_motion_completed(fp32 timeout = 5, bool check_detected = false);
1485 
1486  int _get_bio_gripper_register(unsigned char *ret_data, int address = 0x00, int number_of_registers = 1);
1487  int _bio_gripper_send_modbus(unsigned char *send_data, int length, unsigned char *ret_data, int ret_length);
1488  int _bio_gripper_wait_motion_completed(fp32 timeout = 5);
1489  int _bio_gripper_wait_enable_completed(fp32 timeout = 3);
1490  int _set_bio_gripper_position(int pos, int speed = 0, bool wait = true, fp32 timeout = 5);
1491  int _set_bio_gripper_position(int pos, bool wait = true, fp32 timeout = 5);
1492 
1493  int _check_gripper_position(fp32 target_pos, fp32 timeout = 10);
1494  int _check_gripper_status(fp32 timeout = 10);
1495  bool _gripper_is_support_status(void);
1496  int _get_gripper_status(int *status);
1497 private:
1498  std::string port_;
1507  // pthread_t report_thread_;
1508  std::thread report_thread_;
1509  std::mutex mutex_;
1510  std::condition_variable cond_;
1512  bool is_tcp_;
1515  bool is_sync_;
1520 
1524 
1526 
1537  int sv3msg_[16];
1538  fp32 trs_msg_[5];
1539  fp32 p2p_msg_[5];
1540  fp32 rot_msg_[2];
1541 
1550  int gripper_version_numbers_[3];
1551 
1554 
1556 
1561 
1562  std::vector<void(*)(const fp32*, const fp32*)> report_location_callbacks_;
1563  std::vector<void(*)(bool, bool)> connect_changed_callbacks_;
1564  std::vector<void(*)(int)> state_changed_callbacks_;
1565  std::vector<void(*)(int)> mode_changed_callbacks_;
1566  std::vector<void(*)(int, int)> mtable_mtbrake_changed_callbacks_;
1567  std::vector<void(*)(int, int)> error_warn_changed_callbacks_;
1568  std::vector<void(*)(int)> cmdnum_changed_callbacks_;
1569  std::vector<void(*)(const fp32*)> temperature_changed_callbacks_;
1570  std::vector<void(*)(int)> count_changed_callbacks_;
1571 };
1572 
1573 #endif
bool is_tcp_
Definition: xarm_api.h:1512
fp32 last_used_tcp_acc
Definition: xarm_api.h:111
int teach_sensitivity
Definition: xarm_api.h:94
bool * motor_brake_states
Definition: xarm_api.h:88
int set_fence_mode(bool on)
Definition: xarm_api.h:980
int major_version_number_
Definition: xarm_api.h:1521
fp32 * collision_model_params
Definition: xarm_api.h:143
fp32 rot_jerk
Definition: xarm_api.h:106
int collision_tool_type
Definition: xarm_api.h:142
std::vector< void(*)(int)> state_changed_callbacks_
Definition: xarm_api.h:1564
int mt_brake_
Definition: xarm_api.h:1527
bool robotiq_is_activated_
Definition: xarm_api.h:1546
ROSCPP_DECL bool check()
unsigned char gCU
Definition: xarm_api.h:47
unsigned char kFLT
Definition: xarm_api.h:43
int master_id
Definition: xarm_api.h:97
fp32 last_used_joint_speed
Definition: xarm_api.h:117
fp32 * last_used_angles
Definition: xarm_api.h:114
bool check_is_ready_
Definition: xarm_api.h:1503
f
int * cgpio_output_conf
Definition: xarm_api.h:151
SocketPort * stream_tcp_report_
Definition: xarm_api.h:1558
fp32 min_tcp_speed_
Definition: xarm_api.h:1529
std::string port_
Definition: xarm_api.h:1498
int motor_tid
Definition: xarm_api.h:99
int axis
Definition: xarm_api.h:96
unsigned int u32
Definition: xarm_api.h:35
int * cgpio_input_digitals
Definition: xarm_api.h:146
fp32 * cgpio_output_anglogs
Definition: xarm_api.h:149
bool is_sync_
Definition: xarm_api.h:1515
int cgpio_state
Definition: xarm_api.h:144
std::vector< void(*)(int)> mode_changed_callbacks_
Definition: xarm_api.h:1565
bool arm_type_is_1300_
Definition: xarm_api.h:1518
unsigned char gACT
Definition: xarm_api.h:42
#define NO_TIMEOUT
Definition: xarm_api.h:32
int mt_able_
Definition: xarm_api.h:1528
int is_simulation_robot
Definition: xarm_api.h:140
int minor_version_number_
Definition: xarm_api.h:1522
bool check_is_pause_
Definition: xarm_api.h:1504
std::vector< void(*)(int, int)> error_warn_changed_callbacks_
Definition: xarm_api.h:1567
fp32 * joint_speed_limit
Definition: xarm_api.h:115
std::vector< void(*)(bool, bool)> connect_changed_callbacks_
Definition: xarm_api.h:1563
fp32 cmd_timeout_
Definition: xarm_api.h:1555
std::vector< void(*)(int)> cmdnum_changed_callbacks_
Definition: xarm_api.h:1568
unsigned char * gpio_reset_config
Definition: xarm_api.h:130
fp32 * gravity_direction
Definition: xarm_api.h:122
SocketPort * stream_tcp_
Definition: xarm_api.h:1557
int modbus_baud_
Definition: xarm_api.h:1542
int collision_sensitivity
Definition: xarm_api.h:93
fp32 joint_jerk
Definition: xarm_api.h:105
UxbusCmd * core
Definition: xarm_api.h:134
long long max_report_interval_
Definition: xarm_api.h:1553
unsigned char gGTO
Definition: xarm_api.h:41
int device_type
Definition: xarm_api.h:95
fp32 max_rot_acc
Definition: xarm_api.h:107
ThreadPool pool
Definition: xarm_api.h:1560
long long sleep_finish_time_
Definition: xarm_api.h:1525
int xarm_gripper_error_code_
Definition: xarm_api.h:1547
std::vector< void(*)(const fp32 *)> temperature_changed_callbacks_
Definition: xarm_api.h:1569
bool bio_gripper_is_enabled_
Definition: xarm_api.h:1545
int get_vacuum_gripper(int *val)
Definition: xarm_api.h:866
int * cgpio_input_conf
Definition: xarm_api.h:150
unsigned char gPR
Definition: xarm_api.h:45
fp32 min_joint_acc_
Definition: xarm_api.h:1535
unsigned char gPO
Definition: xarm_api.h:46
fp32 realtime_tcp_speed
Definition: xarm_api.h:124
int robotiq_error_code_
Definition: xarm_api.h:1549
unsigned char gSTA
Definition: xarm_api.h:40
int bio_gripper_speed_
Definition: xarm_api.h:1543
int state
Definition: xarm_api.h:84
fp32 * currents
Definition: xarm_api.h:139
fp32 max_tcp_speed_
Definition: xarm_api.h:1530
int * cgpio_output_digitals
Definition: xarm_api.h:147
fp32 * joint_acc_limit
Definition: xarm_api.h:116
fp32 max_joint_speed_
Definition: xarm_api.h:1534
unsigned char gFLT
Definition: xarm_api.h:44
std::vector< void(*)(int)> count_changed_callbacks_
Definition: xarm_api.h:1570
int bio_gripper_error_code_
Definition: xarm_api.h:1548
bool ignore_state_
Definition: xarm_api.h:1517
int * version_number
Definition: xarm_api.h:103
int warn_code
Definition: xarm_api.h:91
fp32 min_joint_speed_
Definition: xarm_api.h:1533
fp32 * last_used_position
Definition: xarm_api.h:120
std::thread report_thread_
Definition: xarm_api.h:1508
int mode
Definition: xarm_api.h:85
bool control_box_type_is_1300_
Definition: xarm_api.h:1519
fp32 * temperatures
Definition: xarm_api.h:128
fp32 * tcp_speed_limit
Definition: xarm_api.h:108
fp32 * realtime_joint_speeds
Definition: xarm_api.h:125
fp32 max_tcp_acc_
Definition: xarm_api.h:1532
bool check_robot_sn_
Definition: xarm_api.h:1502
#define DEFAULT_IS_RADIAN
Definition: xarm_api.h:29
fp32 * voltages
Definition: xarm_api.h:138
fp32 max_joint_acc_
Definition: xarm_api.h:1536
fp32 * tcp_load
Definition: xarm_api.h:92
bool check_cmdnum_limit_
Definition: xarm_api.h:1501
bool check_joint_limit_
Definition: xarm_api.h:1500
int slave_id
Definition: xarm_api.h:98
fp32 * joints_torque
Definition: xarm_api.h:87
std::condition_variable cond_
Definition: xarm_api.h:1510
long long last_report_time_
Definition: xarm_api.h:1552
bool ignore_error_
Definition: xarm_api.h:1516
fp32 last_used_joint_acc
Definition: xarm_api.h:118
int is_collision_detection
Definition: xarm_api.h:141
int set_vacuum_gripper(bool on, bool wait=false, float timeout=3, float delay_sec=0)
Definition: xarm_api.h:877
std::vector< void(*)(const fp32 *, const fp32 *)> report_location_callbacks_
Definition: xarm_api.h:1562
int motion_enable(bool enable, xarm_msgs::SetAxis srv, ros::ServiceClient client)
int revision_version_number_
Definition: xarm_api.h:1523
fp32 tcp_jerk
Definition: xarm_api.h:104
int cgpio_code
Definition: xarm_api.h:145
bool is_old_protocol_
Definition: xarm_api.h:1513
bool default_is_radian
Definition: xarm_api.h:132
std::mutex mutex_
Definition: xarm_api.h:1509
int max_cmdnum_
Definition: xarm_api.h:1506
SerialPort * stream_ser_
Definition: xarm_api.h:1559
int cmd_num
Definition: xarm_api.h:86
int count
Definition: xarm_api.h:129
int error_code
Definition: xarm_api.h:90
fp32 * tcp_acc_limit
Definition: xarm_api.h:109
bool is_first_report_
Definition: xarm_api.h:1514
unsigned char gOBJ
Definition: xarm_api.h:39
float fp32
Definition: xarm_api.h:36
bool callback_in_thread_
Definition: xarm_api.h:1505
fp32 min_tcp_acc_
Definition: xarm_api.h:1531
bool is_ready_
Definition: xarm_api.h:1511
bool check_tcp_limit_
Definition: xarm_api.h:1499
fp32 * position
Definition: xarm_api.h:119
fp32 * tcp_offset
Definition: xarm_api.h:121
Definition: ser.h:17
fp32 * angles
Definition: xarm_api.h:113
int motor_fid
Definition: xarm_api.h:100
std::vector< void(*)(int, int)> mtable_mtbrake_changed_callbacks_
Definition: xarm_api.h:1566
fp32 * world_offset
Definition: xarm_api.h:127
fp32 * cgpio_intput_anglogs
Definition: xarm_api.h:148
bool gripper_is_enabled_
Definition: xarm_api.h:1544
fp32 last_used_tcp_speed
Definition: xarm_api.h:110
bool * motor_enable_states
Definition: xarm_api.h:89


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