Skip to content

Commit d1e5b8b

Browse files
committed
[feat] Added sync parameter to gpio api to control whether to execute in motion queue
1 parent 45f82f9 commit d1e5b8b

File tree

7 files changed

+142
-78
lines changed

7 files changed

+142
-78
lines changed

doc/api/xarm_api.md

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
xArm-Python-SDK API Documentation (V1.14.0): class XArmAPI in module xarm.wrapper.xarm_api
1+
xArm-Python-SDK API Documentation (V1.14.2): class XArmAPI in module xarm.wrapper.xarm_api
22

33
## class __XArmAPI__
44
****************************************
@@ -686,13 +686,15 @@ xArm-Python-SDK API Documentation (V1.14.0): class XArmAPI in module xarm.wrappe
686686
>     code: See the [API Code Documentation](./xarm_api_code.md#api-code) for details.
687687
688688

689-
#### def __close_lite6_gripper__(self):
689+
#### def __close_lite6_gripper__(self, sync=True):
690690

691691
> Close the gripper of Lite6 series robotic arms
692692
> Note:
693693
>     1. only available if firmware_version >= 1.10.0
694694
>     2. this API can only be used on Lite6 series robotic arms
695695
>
696+
> :param sync: whether to execute in the motion queue, set to False to execute immediately(default is True)
697+
>     1. only available if firmware_version >= 2.4.101
696698
> :return: code
697699
>     code: See the [API Code Documentation](./xarm_api_code.md#api-code) for details.
698700
@@ -1853,13 +1855,15 @@ xArm-Python-SDK API Documentation (V1.14.0): class XArmAPI in module xarm.wrappe
18531855
>     code: See the [API Code Documentation](./xarm_api_code.md#api-code) for details.
18541856
18551857

1856-
#### def __open_lite6_gripper__(self):
1858+
#### def __open_lite6_gripper__(self, sync=True):
18571859

18581860
> Open the gripper of Lite6 series robotic arms
18591861
> Note:
18601862
>     1. only available if firmware_version >= 1.10.0
18611863
>     2. this API can only be used on Lite6 series robotic arms
18621864
>
1865+
> :param sync: whether to execute in the motion queue, set to False to execute immediately(default is True)
1866+
>     1. only available if firmware_version >= 2.4.101
18631867
> :return: code
18641868
>     code: See the [API Code Documentation](./xarm_api_code.md#api-code) for details.
18651869
@@ -2476,12 +2480,14 @@ xArm-Python-SDK API Documentation (V1.14.0): class XArmAPI in module xarm.wrappe
24762480
>     code: See the [API Code Documentation](./xarm_api_code.md#api-code) for details.
24772481
24782482

2479-
#### def __set_cgpio_analog__(self, ionum, value):
2483+
#### def __set_cgpio_analog__(self, ionum, value, sync=True):
24802484

24812485
> Set the analog value of the specified Controller GPIO
24822486
>
24832487
> :param ionum: 0 or 1
24842488
> :param value: value
2489+
> :param sync: whether to execute in the motion queue, set to False to execute immediately(default is True)
2490+
>     1. only available if firmware_version >= 2.4.101
24852491
> :return: code
24862492
>     code: See the [API Code Documentation](./xarm_api_code.md#api-code) for details.
24872493
@@ -2498,13 +2504,16 @@ xArm-Python-SDK API Documentation (V1.14.0): class XArmAPI in module xarm.wrappe
24982504
>     code: See the [API Code Documentation](./xarm_api_code.md#api-code) for details.
24992505
25002506

2501-
#### def __set_cgpio_digital__(self, ionum, value, delay_sec=None):
2507+
#### def __set_cgpio_digital__(self, ionum, value, delay_sec=None, sync=True):
25022508

25032509
> Set the digital value of the specified Controller GPIO
25042510
>
25052511
> :param ionum: 0~15
25062512
> :param value: value
25072513
> :param delay_sec: delay effective time from the current start, in seconds, default is None(effective immediately)
2514+
> :param sync: whether to execute in the motion queue, set to False to execute immediately(default is True)
2515+
>     1. only available if firmware_version >= 2.4.101
2516+
> &ensp;&ensp;&ensp;&ensp;2. only available if delay_sec <= 0
25082517
> :return: code
25092518
> &ensp;&ensp;&ensp;&ensp;code: See the [API Code Documentation](./xarm_api_code.md#api-code) for details.
25102519
@@ -2758,7 +2767,7 @@ xArm-Python-SDK API Documentation (V1.14.0): class XArmAPI in module xarm.wrappe
27582767
> Set the gripper enable
27592768
>
27602769
> :param enable: enable or not
2761-
> &ensp;Note such as code = arm.set_gripper_enable(True) #turn on the Gripper
2770+
> &ensp;&ensp;&ensp;&ensp;Note: such as code = arm.set_gripper_enable(True) #turn on the Gripper
27622771
> :return: code
27632772
> &ensp;&ensp;&ensp;&ensp;code: See the [API Code Documentation](./xarm_api_code.md#api-code) for details.
27642773
@@ -2768,7 +2777,7 @@ xArm-Python-SDK API Documentation (V1.14.0): class XArmAPI in module xarm.wrappe
27682777
> Set the gripper mode
27692778
>
27702779
> :param mode: 0: location mode
2771-
> &ensp;Note such as code = arm.set_gripper_mode(0)
2780+
> &ensp;&ensp;&ensp;&ensp;Note: such as code = arm.set_gripper_mode(0)
27722781
> :return: code
27732782
> &ensp;&ensp;&ensp;&ensp;code: See the [API Code Documentation](./xarm_api_code.md#api-code) for details.
27742783
@@ -3455,13 +3464,16 @@ xArm-Python-SDK API Documentation (V1.14.0): class XArmAPI in module xarm.wrappe
34553464
> &ensp;&ensp;&ensp;&ensp;code: See the [API Code Documentation](./xarm_api_code.md#api-code) for details.
34563465
34573466

3458-
#### def __set_tgpio_digital__(self, ionum, value, delay_sec=None):
3467+
#### def __set_tgpio_digital__(self, ionum, value, delay_sec=None, sync=True):
34593468

34603469
> Set the digital value of the specified Tool GPIO
34613470
>
34623471
> :param ionum: 0 or 1
34633472
> :param value: value
34643473
> :param delay_sec: delay effective time from the current start, in seconds, default is None(effective immediately)
3474+
> :param sync: whether to execute in the motion queue, set to False to execute immediately(default is True)
3475+
> &ensp;&ensp;&ensp;&ensp;1. only available if firmware_version >= 2.4.101
3476+
> &ensp;&ensp;&ensp;&ensp;2. only available if delay_sec <= 0
34653477
> :return: code
34663478
> &ensp;&ensp;&ensp;&ensp;code: See the [API Code Documentation](./xarm_api_code.md#api-code) for details.
34673479
@@ -3553,7 +3565,7 @@ xArm-Python-SDK API Documentation (V1.14.0): class XArmAPI in module xarm.wrappe
35533565
> &ensp;&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;code >= 0: the last_used_tcp_speed/last_used_tcp_acc will be modified
35543566
35553567

3556-
#### def __set_vacuum_gripper__(self, on, wait=False, timeout=3, delay_sec=None):
3568+
#### def __set_vacuum_gripper__(self, on, wait=False, timeout=3, delay_sec=None, sync=True):
35573569

35583570
> Set vacuum gripper state
35593571
>
@@ -3563,6 +3575,9 @@ xArm-Python-SDK API Documentation (V1.14.0): class XArmAPI in module xarm.wrappe
35633575
> :param wait: wait or not, default is False
35643576
> :param timeout: wait time, unit:second, default is 3s
35653577
> :param delay_sec: delay effective time from the current start, in seconds, default is None(effective immediately)
3578+
> :param sync: whether to execute in the motion queue, set to False to execute immediately(default is True)
3579+
> &ensp;&ensp;&ensp;&ensp;1. only available if firmware_version >= 2.4.101
3580+
> &ensp;&ensp;&ensp;&ensp;2. only available if delay_sec <= 0
35663581
> :return: code
35673582
> &ensp;&ensp;&ensp;&ensp;code: See the [API Code Documentation](./xarm_api_code.md#api-code) for details.
35683583
@@ -3593,13 +3608,15 @@ xArm-Python-SDK API Documentation (V1.14.0): class XArmAPI in module xarm.wrappe
35933608
> &ensp;&ensp;&ensp;&ensp;code: See the [API Code Documentation](./xarm_api_code.md#api-code) for details.
35943609
35953610

3596-
#### def __stop_lite6_gripper__(self):
3611+
#### def __stop_lite6_gripper__(self, sync=True):
35973612

35983613
> Stop the gripper of Lite6 series robotic arms
35993614
> Note:
36003615
> &ensp;&ensp;&ensp;&ensp;1. only available if firmware_version >= 1.10.0
36013616
> &ensp;&ensp;&ensp;&ensp;2. this API can only be used on Lite6 series robotic arms
36023617
>
3618+
> :param sync: whether to execute in the motion queue, set to False to execute immediately(default is True)
3619+
> &ensp;&ensp;&ensp;&ensp;1. only available if firmware_version >= 2.4.101
36033620
> :return: code
36043621
> &ensp;&ensp;&ensp;&ensp;code: See the [API Code Documentation](./xarm_api_code.md#api-code) for details.
36053622

xarm/core/wrapper/uxbus_cmd.py

Lines changed: 38 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,13 @@ def get_nu8(self, funcode, num):
110110
return self.recv_modbus_response(funcode, ret, num, self._G_TOUT)
111111

112112
@lock_require
113-
def set_nu16(self, funcode, datas, num):
113+
def set_nu16(self, funcode, datas, num, additional_bytes=None):
114114
hexdata = convert.u16s_to_bytes(datas, num)
115-
ret = self.send_modbus_request(funcode, hexdata, num * 2)
115+
if additional_bytes is not None:
116+
hexdata += additional_bytes
117+
ret = self.send_modbus_request(funcode, hexdata, num * 2 + len(additional_bytes))
118+
else:
119+
ret = self.send_modbus_request(funcode, hexdata, num * 2)
116120
if ret == -1:
117121
return [XCONF.UxbusState.ERR_NOTTCP]
118122
ret = self.recv_modbus_response(funcode, ret, 0, self._S_TOUT)
@@ -679,11 +683,15 @@ def gripper_clean_err(self):
679683
return self.gripper_addr_w16(XCONF.ServoConf.RESET_ERR, 1)
680684

681685
@lock_require
682-
def tgpio_addr_w16(self, addr, value, bid=XCONF.TGPIO_HOST_ID):
686+
def tgpio_addr_w16(self, addr, value, bid=XCONF.TGPIO_HOST_ID, additional_bytes=None):
683687
txdata = bytes([bid])
684688
txdata += convert.u16_to_bytes(addr)
685689
txdata += convert.fp32_to_bytes(value)
686-
ret = self.send_modbus_request(XCONF.UxbusReg.TGPIO_W16B, txdata, 7)
690+
if additional_bytes is not None:
691+
txdata += additional_bytes
692+
ret = self.send_modbus_request(XCONF.UxbusReg.TGPIO_W16B, txdata, 7 + len(additional_bytes))
693+
else:
694+
ret = self.send_modbus_request(XCONF.UxbusReg.TGPIO_W16B, txdata, 7)
687695
if ret == -1:
688696
return [XCONF.UxbusState.ERR_NOTTCP] * (7 + 1)
689697

@@ -734,7 +742,7 @@ def tgpio_get_digital(self):
734742
value[4] = (ret[1] & 0x0008) >> 3
735743
return value
736744

737-
def tgpio_set_digital(self, ionum, value):
745+
def tgpio_set_digital(self, ionum, value, sync=None):
738746
tmp = 0
739747
if ionum == 1:
740748
tmp = tmp | 0x0100
@@ -758,7 +766,10 @@ def tgpio_set_digital(self, ionum, value):
758766
tmp = tmp | 0x0008
759767
else:
760768
return [-1, -1]
761-
return self.tgpio_addr_w16(XCONF.ServoConf.DIGITAL_OUT, tmp)
769+
if sync is not None:
770+
return self.tgpio_addr_w16(XCONF.ServoConf.DIGITAL_OUT, tmp, additional_bytes=bytes([sync]))
771+
else:
772+
return self.tgpio_addr_w16(XCONF.ServoConf.DIGITAL_OUT, tmp)
762773

763774
def tgpio_get_analog1(self):
764775
ret = self.tgpio_addr_r16(XCONF.ServoConf.ANALOG_IO1)
@@ -1014,30 +1025,39 @@ def cgpio_get_analog2(self):
10141025
value[1] = ret[1] * 10.0 / 4095.0
10151026
return value
10161027

1017-
def cgpio_set_auxdigit(self, ionum, value):
1028+
def cgpio_set_auxdigit(self, ionum, value, sync=None):
10181029
tmp = [0] * 2
10191030
if ionum > 7:
10201031
tmp[1] = tmp[1] | (0x0100 << (ionum - 8))
10211032
if value:
10221033
tmp[1] = tmp[1] | (0x0001 << (ionum - 8))
1034+
if sync is not None:
1035+
return self.set_nu16(XCONF.UxbusReg.CGPIO_SET_DIGIT, tmp, 2, additional_bytes=bytes([sync]))
1036+
else:
1037+
return self.set_nu16(XCONF.UxbusReg.CGPIO_SET_DIGIT, tmp, 2)
10231038
else:
10241039
tmp[0] = tmp[0] | (0x0100 << ionum)
10251040
if value:
10261041
tmp[0] = tmp[0] | (0x0001 << ionum)
1027-
return self.set_nu16(XCONF.UxbusReg.CGPIO_SET_DIGIT, tmp, 2 if ionum > 7 else 1)
1028-
# tmp = [0] * 1
1029-
# tmp[0] = tmp[0] | (0x0100 << ionum)
1030-
# if value:
1031-
# tmp[0] = tmp[0] | (0x0001 << ionum)
1032-
# return self.set_nu16(XCONF.UxbusReg.CGPIO_SET_DIGIT, tmp, 1)
1033-
1034-
def cgpio_set_analog1(self, value):
1042+
if sync is not None:
1043+
return self.set_nu16(XCONF.UxbusReg.CGPIO_SET_DIGIT, tmp, 1, additional_bytes=bytes([sync]))
1044+
else:
1045+
return self.set_nu16(XCONF.UxbusReg.CGPIO_SET_DIGIT, tmp, 1)
1046+
# return self.set_nu16(XCONF.UxbusReg.CGPIO_SET_DIGIT, tmp, 2 if ionum > 7 else 1)
1047+
1048+
def cgpio_set_analog1(self, value, sync=None):
10351049
txdata = [int(value / 10.0 * 4095.0)]
1036-
return self.set_nu16(XCONF.UxbusReg.CGPIO_SET_ANALOG1, txdata, 1)
1050+
if sync is not None:
1051+
return self.set_nu16(XCONF.UxbusReg.CGPIO_SET_ANALOG1, txdata, 1, additional_bytes=bytes([sync]))
1052+
else:
1053+
return self.set_nu16(XCONF.UxbusReg.CGPIO_SET_ANALOG1, txdata, 1)
10371054

1038-
def cgpio_set_analog2(self, value):
1055+
def cgpio_set_analog2(self, value, sync=None):
10391056
txdata = [int(value / 10.0 * 4095.0)]
1040-
return self.set_nu16(XCONF.UxbusReg.CGPIO_SET_ANALOG2, txdata, 1)
1057+
if sync is not None:
1058+
return self.set_nu16(XCONF.UxbusReg.CGPIO_SET_ANALOG2, txdata, 1, additional_bytes=bytes([sync]))
1059+
else:
1060+
return self.set_nu16(XCONF.UxbusReg.CGPIO_SET_ANALOG2, txdata, 1)
10411061

10421062
def cgpio_set_infun(self, num, fun):
10431063
txdata = [int(num), int(fun)]

xarm/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = '1.14.1'
1+
__version__ = '1.14.2'

0 commit comments

Comments
 (0)