Skip to content

Commit 54d6c7d

Browse files
committed
[feat] add set_tgpio_monitor_params/get_tgpio_monitor_params
1. add `set_tgpio_monitor_params`/`get_tgpio_monitor_params` 2. fix get_servo_version/get_tgpio_version
1 parent d2b3547 commit 54d6c7d

File tree

5 files changed

+94
-21
lines changed

5 files changed

+94
-21
lines changed

doc/api/xarm_api.md

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -529,7 +529,7 @@ xArm-Python-SDK API Documentation (V1.17.3): class XArmAPI in module xarm.wrappe
529529

530530
> Get the monitor params of the external device
531531
> Note:
532-
>     1. only available if firmware_version >= 2.7.110
532+
>     1. only available if firmware_version >= 2.7.100
533533
>
534534
> :return: tuple((code, params)), only when code is 0, the returned result is correct.
535535
>     code: See the [API Code Documentation](./xarm_api_code.md#api-code) for details.
@@ -1170,6 +1170,17 @@ xArm-Python-SDK API Documentation (V1.17.3): class XArmAPI in module xarm.wrappe
11701170
> Get the timeout of the Robot RS485 (please use get_rs485_timeout replace)
11711171
11721172

1173+
#### def __get_tgpio_monitor_params__(self):
1174+
1175+
> Get the monitor params of the TGPIO
1176+
> Note:
1177+
>     1. only available if firmware_version >= 2.7.101
1178+
>
1179+
> :return: tuple((code, params)), only when code is 0, the returned result is correct.
1180+
>     code: See the [API Code Documentation](./xarm_api_code.md#api-code) for details.
1181+
>     params: [io_type, frequency]
1182+
1183+
11731184
#### def __get_tgpio_output_digital__(self, ionum=None):
11741185

11751186
> Get the digital value of the specified Tool GPIO output
@@ -2377,7 +2388,7 @@ xArm-Python-SDK API Documentation (V1.17.3): class XArmAPI in module xarm.wrappe
23772388

23782389
> Set the monitor params of the external device
23792390
> Note:
2380-
>     1. only available if firmware_version >= 2.7.110
2391+
>     1. only available if firmware_version >= 2.7.100
23812392
>     2. after it is turned on, the position/speed/current information of the external device will be reported through port 30000
23822393
>     3. once an error occurs, you need to re call to monitor
23832394
>
@@ -2386,8 +2397,7 @@ xArm-Python-SDK API Documentation (V1.17.3): class XArmAPI in module xarm.wrappe
23862397
>     1: xArm Gripper
23872398
>     2: xArm Gripper G2
23882399
>     3: BIO Gripper G2
2389-
>     4: Robotiq 2F-85
2390-
>     5: Robotiq 2F-140
2400+
>     4: Robotiq 2F-85/Robotiq 2F-140
23912401
> :param frequency: the frequency of communication with the external device
23922402
>
23932403
> :return code
@@ -3397,6 +3407,22 @@ xArm-Python-SDK API Documentation (V1.17.3): class XArmAPI in module xarm.wrappe
33973407
> Set the timeout of the Robot RS485 (please use set_rs485_timeout)
33983408
33993409

3410+
#### def __set_tgpio_monitor_params__(self, io_type, frequency):
3411+
3412+
> Set the monitor params of the TGPIO
3413+
> Note:
3414+
>     1. only available if firmware_version >= 2.7.101
3415+
>     2. after it is turned on, the information of the TGPIO will be reported through port 30000
3416+
>
3417+
> :param io_type: the type of the TGPIO
3418+
>     0: Turn off monitoring
3419+
>     1: Turn on monitoring
3420+
> :param frequency: the frequency of communication with the TGPIO
3421+
>
3422+
> :return code
3423+
>     code: See the [API Code Documentation](./xarm_api_code.md#api-code) for details.
3424+
3425+
34003426
#### def __set_timeout__(self, timeout):
34013427

34023428
> Set the timeout of cmd response

xarm/wrapper/xarm_api.py

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4552,7 +4552,7 @@ def set_external_device_monitor_params(self, dev_type, frequency):
45524552
"""
45534553
Set the monitor params of the external device
45544554
Note:
4555-
1. only available if firmware_version >= 2.7.110
4555+
1. only available if firmware_version >= 2.7.100
45564556
2. after it is turned on, the position/speed/current information of the external device will be reported through port 30000
45574557
3. once an error occurs, you need to re call to monitor
45584558
@@ -4561,8 +4561,7 @@ def set_external_device_monitor_params(self, dev_type, frequency):
45614561
1: xArm Gripper
45624562
2: xArm Gripper G2
45634563
3: BIO Gripper G2
4564-
4: Robotiq 2F-85
4565-
5: Robotiq 2F-140
4564+
4: Robotiq 2F-85/Robotiq 2F-140
45664565
:param frequency: the frequency of communication with the external device
45674566
45684567
:return code
@@ -4574,13 +4573,42 @@ def get_external_device_monitor_params(self):
45744573
"""
45754574
Get the monitor params of the external device
45764575
Note:
4577-
1. only available if firmware_version >= 2.7.110
4576+
1. only available if firmware_version >= 2.7.100
45784577
45794578
:return: tuple((code, params)), only when code is 0, the returned result is correct.
45804579
code: See the [API Code Documentation](./xarm_api_code.md#api-code) for details.
45814580
params: [dev_type, frequency]
45824581
"""
4583-
return self._arm.get_external_device_monitor_params()
4582+
return self._arm.get_external_device_monitor_params()
4583+
4584+
def set_tgpio_monitor_params(self, io_type, frequency):
4585+
"""
4586+
Set the monitor params of the TGPIO
4587+
Note:
4588+
1. only available if firmware_version >= 2.7.101
4589+
2. after it is turned on, the information of the TGPIO will be reported through port 30000
4590+
4591+
:param io_type: the type of the TGPIO
4592+
0: Turn off monitoring
4593+
1: Turn on monitoring
4594+
:param frequency: the frequency of communication with the TGPIO
4595+
4596+
:return code
4597+
code: See the [API Code Documentation](./xarm_api_code.md#api-code) for details.
4598+
"""
4599+
return self._arm.set_tgpio_monitor_params(io_type, frequency)
4600+
4601+
def get_tgpio_monitor_params(self):
4602+
"""
4603+
Get the monitor params of the TGPIO
4604+
Note:
4605+
1. only available if firmware_version >= 2.7.101
4606+
4607+
:return: tuple((code, params)), only when code is 0, the returned result is correct.
4608+
code: See the [API Code Documentation](./xarm_api_code.md#api-code) for details.
4609+
params: [io_type, frequency]
4610+
"""
4611+
return self._arm.get_tgpio_monitor_params()
45844612

45854613
############################ OLD API #############################
45864614

xarm/x3/base.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2809,4 +2809,10 @@ def set_external_device_monitor_params(self, dev_type, frequency):
28092809
return self.set_common_param(15, [dev_type, frequency])
28102810

28112811
def get_external_device_monitor_params(self):
2812-
return self.get_common_param(15)
2812+
return self.get_common_param(15)
2813+
2814+
def set_tgpio_monitor_params(self, io_type, frequency):
2815+
return self.set_common_param(16, [io_type, frequency])
2816+
2817+
def get_tgpio_monitor_params(self):
2818+
return self.get_common_param(16)

xarm/x3/gpio.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,18 +55,18 @@ def get_tgpio_version(self):
5555

5656
code = 0
5757

58-
if ret1[0] == 0 and len(ret1) == 2:
59-
versions[0] = ret1[1]
58+
if ret1[0] in [0, 1, 2] and len(ret1) > 1:
59+
versions[0] = ret1[1] if abs(ret1[1]) < 1000 else 0
6060
else:
6161
code = ret1[0]
6262

63-
if ret2[0] == 0 and len(ret2) == 2:
64-
versions[1] = ret2[1]
63+
if ret2[0] in [0, 1, 2] and len(ret2) > 1:
64+
versions[1] = ret2[1] if abs(ret2[1]) < 1000 else 0
6565
else:
6666
code = ret2[0]
6767

68-
if ret3[0] == 0 and len(ret3) == 2:
69-
versions[2] = ret3[1]
68+
if ret3[0] in [0, 1, 2] and len(ret3) > 1:
69+
versions[2] = ret3[1] if abs(ret3[1]) < 1000 else 0
7070
else:
7171
code = ret3[0]
7272
# if code != 0:

xarm/x3/servo.py

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -347,18 +347,31 @@ def get_servo_version(self, servo_id=1):
347347
def _get_servo_version(id_num):
348348
versions = ['*', '*', '*']
349349
ret1 = self.get_servo_addr_16(id_num, 0x0801)
350-
ret2 = self.get_servo_addr_16(id_num, 0x0802)
351-
ret3 = self.get_servo_addr_16(id_num, 0x0803)
350+
ret = self.get_servo_debug_msg()
351+
if ret[1][id_num-1]['code'] != 0:
352+
ret1 = self.arm_cmd.servo_error_addr_r32(id_num, 0x0801)
353+
ret2 = self.arm_cmd.servo_error_addr_r32(id_num, 0x0802)
354+
ret3 = self.arm_cmd.servo_error_addr_r32(id_num, 0x0803)
355+
if len(ret1) > 1:
356+
ret1[1] = ret1[1] >> 16
357+
if len(ret2) > 1:
358+
ret2[1] = ret2[1] >> 16
359+
if len(ret3) > 1:
360+
ret3[1] = ret3[1] >> 16
361+
else:
362+
ret2 = self.get_servo_addr_16(id_num, 0x0802)
363+
ret3 = self.get_servo_addr_16(id_num, 0x0803)
364+
352365
code = 0
353-
if ret1[0] == 0:
366+
if ret1[0] in [0, 1, 2] and len(ret1) > 1 and ret1[1] < 1000:
354367
versions[0] = ret1[1]
355368
else:
356369
code = ret1[0]
357-
if ret2[0] == 0:
370+
if ret2[0] in [0, 1, 2] and len(ret2) > 1 and ret2[1] < 1000:
358371
versions[1] = ret2[1]
359372
else:
360373
code = ret2[0]
361-
if ret3[0] == 0:
374+
if ret3[0] in [0, 1, 2] and len(ret3) > 1 and ret3[1] < 1000:
362375
versions[2] = ret3[1]
363376
else:
364377
code = ret3[0]

0 commit comments

Comments
 (0)