Skip to content

Commit 1eb7c3e

Browse files
committed
Fix get_joint_state and add common api(debug)
1 parent 5d1336f commit 1eb7c3e

File tree

5 files changed

+106
-33
lines changed

5 files changed

+106
-33
lines changed

xarm/core/wrapper/uxbus_cmd.py

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,16 @@ def move_line(self, mvpose, mvvelo, mvacc, mvtime, only_check_type=0):
358358
byte_data = bytes([only_check_type])
359359
return self.set_nfp32_with_bytes(XCONF.UxbusReg.MOVE_LINE, txdata, 9, byte_data, 3, timeout=10)
360360

361+
def move_line_common(self, mvpose, mvvelo, mvacc, mvtime, radius=-1, coord=0, is_axis_angle=False, only_check_type=0):
362+
"""
363+
通用指令,固件1.10.0开始支持
364+
"""
365+
txdata = [mvpose[i] for i in range(6)]
366+
_radius = -1 if radius is None else radius
367+
txdata += [mvvelo, mvacc, mvtime, _radius]
368+
byte_data = bytes([coord, int(is_axis_angle), only_check_type])
369+
return self.set_nfp32_with_bytes(XCONF.UxbusReg.MOVE_LINE, txdata, 10, byte_data, 3, timeout=10)
370+
361371
def move_line_aa(self, mvpose, mvvelo, mvacc, mvtime, mvcoord, relative, only_check_type=0):
362372
float_data = [mvpose[i] for i in range(6)]
363373
float_data += [mvvelo, mvacc, mvtime]
@@ -496,6 +506,21 @@ def move_circle(self, pose1, pose2, mvvelo, mvacc, mvtime, percent, only_check_t
496506
byte_data = bytes([only_check_type])
497507
return self.set_nfp32_with_bytes(XCONF.UxbusReg.MOVE_CIRCLE, txdata, 16, byte_data, 3, timeout=10)
498508

509+
def move_circle_common(self, pose1, pose2, mvvelo, mvacc, mvtime, percent, coord=0, is_axis_angle=False, only_check_type=0):
510+
"""
511+
通用指令,固件1.10.0开始支持
512+
"""
513+
txdata = [0] * 16
514+
for i in range(6):
515+
txdata[i] = pose1[i]
516+
txdata[6 + i] = pose2[i]
517+
txdata[12] = mvvelo
518+
txdata[13] = mvacc
519+
txdata[14] = mvtime
520+
txdata[15] = percent
521+
byte_data = bytes([coord, int(is_axis_angle), only_check_type])
522+
return self.set_nfp32_with_bytes(XCONF.UxbusReg.MOVE_CIRCLE, txdata, 16, byte_data, 3, timeout=10)
523+
499524
def set_tcp_jerk(self, jerk):
500525
txdata = [jerk]
501526
return self.set_nfp32(XCONF.UxbusReg.SET_TCP_JERK, txdata, 1)
@@ -540,8 +565,8 @@ def save_conf(self):
540565
def get_joint_pos(self):
541566
return self.get_nfp32(XCONF.UxbusReg.GET_JOINT_POS, 7)
542567

543-
def get_joint_states(self):
544-
return self.get_nfp32_with_datas(XCONF.UxbusReg.GET_JOINT_POS, [3], 1, 21)
568+
def get_joint_states(self, num=3):
569+
return self.get_nfp32_with_datas(XCONF.UxbusReg.GET_JOINT_POS, [num], 1, 7 * num)
545570

546571
def get_tcp_pose(self):
547572
return self.get_nfp32(XCONF.UxbusReg.GET_TCP_POSE, 6)

xarm/version.py

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

xarm/wrapper/xarm_api.py

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -807,7 +807,7 @@ def set_position(self, x=None, y=None, z=None, roll=None, pitch=None, yaw=None,
807807

808808
def set_tool_position(self, x=0, y=0, z=0, roll=0, pitch=0, yaw=0,
809809
speed=None, mvacc=None, mvtime=None, is_radian=None,
810-
wait=False, timeout=None, **kwargs):
810+
wait=False, timeout=None, radius=None, **kwargs):
811811
"""
812812
Movement relative to the tool coordinate system
813813
Note:
@@ -828,6 +828,13 @@ def set_tool_position(self, x=0, y=0, z=0, roll=0, pitch=0, yaw=0,
828828
:param is_radian: the roll/pitch/yaw in radians or not, default is self.default_is_radian
829829
:param wait: whether to wait for the arm to complete, default is False
830830
:param timeout: maximum waiting time(unit: second), default is None(no timeout), only valid if wait is True
831+
:param radius: move radius, if radius is None or radius less than 0, will MoveToolLine, else MoveToolArcLine
832+
only available if firmware_version >= 1.10.110
833+
MoveToolLine: Linear motion
834+
ex: code = arm.set_tool_position(..., radius=None)
835+
MoveToolArcLine: Linear arc motion with interpolation
836+
ex: code = arm.set_tool_position(..., radius=0)
837+
Note: Need to set radius>=0
831838
:param kwargs: reserved
832839
:return: code
833840
code: See the [API Code Documentation](./xarm_api_code.md#api-code) for details.
@@ -836,9 +843,9 @@ def set_tool_position(self, x=0, y=0, z=0, roll=0, pitch=0, yaw=0,
836843
"""
837844
return self._arm.set_tool_position(x=x, y=y, z=z, roll=roll, pitch=pitch, yaw=yaw,
838845
speed=speed, mvacc=mvacc, mvtime=mvtime,
839-
is_radian=is_radian, wait=wait, timeout=timeout, **kwargs)
846+
is_radian=is_radian, wait=wait, timeout=timeout, radius=radius, **kwargs)
840847

841-
def get_servo_angle(self, servo_id=None, is_radian=None):
848+
def get_servo_angle(self, servo_id=None, is_radian=None, is_real=False):
842849
"""
843850
Get the servo angle
844851
Note:
@@ -853,7 +860,7 @@ def get_servo_angle(self, servo_id=None, is_radian=None):
853860
:return: tuple((code, angle list if servo_id is None or 8 else angle)), only when code is 0, the returned result is correct.
854861
code: See the [API Code Documentation](./xarm_api_code.md#api-code) for details.
855862
"""
856-
return self._arm.get_servo_angle(servo_id=servo_id, is_radian=is_radian)
863+
return self._arm.get_servo_angle(servo_id=servo_id, is_radian=is_radian, is_real=is_real)
857864

858865
def set_servo_angle(self, servo_id=None, angle=None, speed=None, mvacc=None, mvtime=None,
859866
relative=False, is_radian=None, wait=False, timeout=None, radius=None, **kwargs):
@@ -936,7 +943,8 @@ def set_servo_cartesian(self, mvpose, speed=None, mvacc=None, mvtime=0, is_radia
936943
return self._arm.set_servo_cartesian(mvpose, speed=speed, mvacc=mvacc, mvtime=mvtime, is_radian=is_radian,
937944
is_tool_coord=is_tool_coord, **kwargs)
938945

939-
def move_circle(self, pose1, pose2, percent, speed=None, mvacc=None, mvtime=None, is_radian=None, wait=False, timeout=None, **kwargs):
946+
def move_circle(self, pose1, pose2, percent, speed=None, mvacc=None, mvtime=None, is_radian=None,
947+
wait=False, timeout=None, is_tool_coord=False, is_axis_angle=False, **kwargs):
940948
"""
941949
The motion calculates the trajectory of the space circle according to the three-point coordinates.
942950
The three-point coordinates are (current starting point, pose1, pose2).
@@ -950,13 +958,17 @@ def move_circle(self, pose1, pose2, percent, speed=None, mvacc=None, mvtime=None
950958
:param is_radian: roll/pitch/yaw value is radians or not, default is self.default_is_radian
951959
:param wait: whether to wait for the arm to complete, default is False
952960
:param timeout: maximum waiting time(unit: second), default is None(no timeout), only valid if wait is True
961+
:param is_tool_coord: is tool coord or not, default is False, only available if firmware_version >= 1.10.110
962+
:param is_axis_angle: is axis angle or not, default is False, only available if firmware_version >= 1.10.110
953963
:param kwargs: reserved
954964
:return: code
955965
code: See the [API Code Documentation](./xarm_api_code.md#api-code) for details.
956966
code < 0: the last_used_tcp_speed/last_used_tcp_acc will not be modified
957967
code >= 0: the last_used_tcp_speed/last_used_tcp_acc will be modified
958968
"""
959-
return self._arm.move_circle(pose1, pose2, percent, speed=speed, mvacc=mvacc, mvtime=mvtime, is_radian=is_radian, wait=wait, timeout=timeout, **kwargs)
969+
return self._arm.move_circle(pose1, pose2, percent, speed=speed, mvacc=mvacc, mvtime=mvtime,
970+
is_radian=is_radian, wait=wait, timeout=timeout,
971+
is_tool_coord=is_tool_coord, is_axis_angle=is_axis_angle, **kwargs)
960972

961973
def move_gohome(self, speed=None, mvacc=None, mvtime=None, is_radian=None, wait=False, timeout=None, **kwargs):
962974
"""
@@ -2395,7 +2407,7 @@ def config_cgpio_reset_when_stop(self, on_off):
23952407
return self._arm.config_io_reset_when_stop(0, on_off)
23962408

23972409
def set_position_aa(self, axis_angle_pose, speed=None, mvacc=None, mvtime=None,
2398-
is_radian=None, is_tool_coord=False, relative=False, wait=False, timeout=None, **kwargs):
2410+
is_radian=None, is_tool_coord=False, relative=False, wait=False, timeout=None, radius=None, **kwargs):
23992411
"""
24002412
Set the pose represented by the axis angle pose
24012413
@@ -2408,12 +2420,19 @@ def set_position_aa(self, axis_angle_pose, speed=None, mvacc=None, mvtime=None,
24082420
:param relative: relative move or not
24092421
:param wait: whether to wait for the arm to complete, default is False
24102422
:param timeout: maximum waiting time(unit: second), default is None(no timeout), only valid if wait is True
2423+
:param radius: move radius, if radius is None or radius less than 0, will MoveLineAA, else MoveArcLineAA
2424+
only available if firmware_version >= 1.10.110
2425+
MoveLineAA: Linear motion
2426+
ex: code = arm.set_position_aa(..., radius=None)
2427+
MoveArcLineAA: Linear arc motion with interpolation
2428+
ex: code = arm.set_position_aa(..., radius=0)
2429+
Note: Need to set radius>=0
24112430
:return: code
24122431
code: See the [API Code Documentation](./xarm_api_code.md#api-code) for details.
24132432
"""
24142433
return self._arm.set_position_aa(axis_angle_pose, speed=speed, mvacc=mvacc, mvtime=mvtime,
24152434
is_radian=is_radian, is_tool_coord=is_tool_coord, relative=relative,
2416-
wait=wait, timeout=timeout, **kwargs)
2435+
wait=wait, timeout=timeout, radius=radius, **kwargs)
24172436

24182437
def set_servo_cartesian_aa(self, axis_angle_pose, speed=None, mvacc=None, is_radian=None, is_tool_coord=False, relative=False, **kwargs):
24192438
"""
@@ -3501,7 +3520,7 @@ def set_allow_approx_motion(self, on_off):
35013520
"""
35023521
return self._arm.set_allow_approx_motion(on_off)
35033522

3504-
def get_joint_states(self, is_radian=None):
3523+
def get_joint_states(self, is_radian=None, num=3):
35053524
"""
35063525
Get the joint states
35073526
Note:
@@ -3514,7 +3533,7 @@ def get_joint_states(self, is_radian=None):
35143533
velocity: the velocities of joints, like [velo-1, ..., velo-7]
35153534
effort: the efforts of joints, like [effort-1, ..., effort-7]
35163535
"""
3517-
return self._arm.get_joint_states(is_radian=is_radian)
3536+
return self._arm.get_joint_states(is_radian=is_radian, num=num)
35183537

35193538
def iden_joint_friction(self, sn=None):
35203539
"""

xarm/x3/base.py

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,10 @@ def is_simulation_robot(self):
454454
def check_is_simulation_robot(self):
455455
return self._check_simulation_mode and self.is_simulation_robot
456456
# return self._check_simulation_mode and self.mode != 4
457+
458+
@property
459+
def is_lite6(self):
460+
return self.axis == 6 and self.device_type == 9
457461

458462
@property
459463
def version(self):
@@ -762,7 +766,7 @@ def connect(self, port=None, baudrate=None, timeout=None, axis=None, arm_type=No
762766
return
763767
if axis in [5, 6, 7]:
764768
self._arm_axis = axis
765-
if arm_type in [3, 5, 6, 7]:
769+
if arm_type in [3, 5, 6, 7, 8, 9, 11]:
766770
self._arm_type = arm_type
767771
self._is_ready = True
768772
self._port = port if port is not None else self._port
@@ -1950,9 +1954,12 @@ def get_position(self, is_radian=None):
19501954
i in range(len(self._position))]
19511955

19521956
@xarm_is_connected(_type='get')
1953-
def get_servo_angle(self, servo_id=None, is_radian=None):
1957+
def get_servo_angle(self, servo_id=None, is_radian=None, is_real=False):
19541958
is_radian = self._default_is_radian if is_radian is None else is_radian
1955-
ret = self.arm_cmd.get_joint_pos()
1959+
if is_real and self.version_is_ge(1, 9, 110):
1960+
ret = self.arm_cmd.get_joint_states(num=1)
1961+
else:
1962+
ret = self.arm_cmd.get_joint_pos()
19561963
ret[0] = self._check_code(ret[0])
19571964
if ret[0] == 0 and len(ret) > 7:
19581965
self._angles = [filter_invaild_number(ret[i], 6, default=self._angles[i-1]) for i in range(1, 8)]
@@ -1964,19 +1971,25 @@ def get_servo_angle(self, servo_id=None, is_radian=None):
19641971
'{:.6f}'.format(self._angles[servo_id - 1] if is_radian else math.degrees(self._angles[servo_id - 1])))
19651972

19661973
@xarm_is_connected(_type='get')
1967-
def get_joint_states(self, is_radian=None):
1974+
def get_joint_states(self, is_radian=None, num=3):
19681975
is_radian = self._default_is_radian if is_radian is None else is_radian
1969-
ret = self.arm_cmd.get_joint_states()
1976+
ret = self.arm_cmd.get_joint_states(num=num)
19701977
ret[0] = self._check_code(ret[0])
19711978
positon = ret[1:8]
1972-
velocity = ret[8:15]
1973-
effort = ret[15:22]
1979+
result = [positon]
1980+
if num >= 2:
1981+
velocity = ret[8:15]
1982+
result.append(velocity)
1983+
if num >= 3:
1984+
effort = ret[15:22]
1985+
result.append(effort)
19741986
if ret[0] == 0:
19751987
if not is_radian:
19761988
for i in range(7):
19771989
positon[i] = math.degrees(positon[i])
1978-
velocity[i] = math.degrees(velocity[i])
1979-
return ret[0], [positon, velocity, effort]
1990+
if num >= 2:
1991+
velocity[i] = math.degrees(velocity[i])
1992+
return ret[0], result
19801993

19811994
@xarm_is_connected(_type='get')
19821995
def get_position_aa(self, is_radian=None):

0 commit comments

Comments
 (0)