Skip to content

Commit

Permalink
push code
Browse files Browse the repository at this point in the history
  • Loading branch information
anla-xu committed Dec 2, 2022
1 parent ac50622 commit d4f09d5
Show file tree
Hide file tree
Showing 5 changed files with 302 additions and 62 deletions.
39 changes: 15 additions & 24 deletions pymycobot/Interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,29 +44,20 @@ def _mesg(self, genre, *args, **kwargs):
return real_command, has_reply

# System status
def get_robot_version(self, id):
def get_robot_version(self):
"""Get cobot version
Args:
id: 0/1/2/3 (ALL/L/R/W)
"""
return self._mesg(ProtocolCode.ROBOT_VERSION, id, has_reply=True)
return self._mesg(ProtocolCode.ROBOT_VERSION, 0, has_reply=True)

def get_system_version(self, id):
def get_system_version(self):
"""Get cobot version
Args:
id: 0/1/2/3 (ALL/L/R/W)
"""
return self._mesg(ProtocolCode.SOFTWARE_VERSION, id, has_reply=True)
return self._mesg(ProtocolCode.SOFTWARE_VERSION, 0, has_reply=True)

def get_robot_id(self, id):
def get_robot_id(self):
"""Detect this robot id
Args:
id: 0/1/2/3 (ALL/L/R/W)
"""
return self._mesg(ProtocolCode.GET_ROBOT_ID, id, has_reply=True)
return self._mesg(ProtocolCode.GET_ROBOT_ID, 0, has_reply=True)

def set_robot_id(self, id, new_id):
"""Set this robot id
Expand Down Expand Up @@ -232,7 +223,7 @@ def send_coord(self, id, coord, data, speed):
"""Send a single coordinate to the robotic arm
Args:
id: 1/2/3 (L/R/W).
id: 1/2 (L/R).
coord: 1 ~ 6 (x/y/z/rx/ry/rz)
data: Coordinate value
speed: 0 ~ 100
Expand Down Expand Up @@ -383,7 +374,7 @@ def jog_angle(self, id, joint_id, direction, speed):
"""Jog control angle.
Args:
id: 1/2/3 (L/R/W).
id: 1/2 (L/R).
joint_id:int 1-6.\n
direction: 0 - decrease, 1 - increase
speed: int (0 - 100)
Expand All @@ -394,7 +385,7 @@ def jog_absolute(self, id, joint_id, angle, speed):
"""Absolute joint control
Args:
id: 1/2/3 (L/R/W).
id: 1/2 (L/R).
joint_id: int 1-6.
angle: int
speed: int (0 - 100)
Expand All @@ -407,7 +398,7 @@ def jog_coord(self, id, coord_id, direction, speed):
"""Jog control coord.
Args:
id: 1/2/3 (L/R/W).
id: 1/2 (L/R).
coord_id: int 1-6 (x/y/z/rx/ry/rz).
direction: 0 - decrease, 1 - increase
speed: int (0 - 100)
Expand All @@ -418,7 +409,7 @@ def jog_increment(self, id, joint_id, increment, speed):
"""step mode
Args:
id: 1/2/3 (L/R/W).
id: 1/2 (L/R).
joint_id: int 1-6.
increment:
speed: int (1 - 100)
Expand All @@ -429,7 +420,7 @@ def jog_stop(self, id):
"""Stop jog moving
Args:
id: 1/2/3 (L/R/W).
id: 1/2 (L/R).
"""
return self._mesg(ProtocolCode.JOG_STOP, id)

Expand Down Expand Up @@ -515,15 +506,15 @@ def get_acceleration(self, id):
"""Read acceleration during all moves
Args:
id: 1/2/3 (L/R/W)
id: 1/2 (L/R)
"""
return self._mesg(ProtocolCode.GET_ACCELERATION, id, has_reply=True)

def set_acceleration(self, id, acc):
"""Set acceleration during all moves
Args:
id: 1/2/3 (L/R/W)
id: 1/2 (L/R)
acc: 1 - 100
"""
return self._mesg(ProtocolCode.SET_ACCELERATION, id, acc)
Expand Down Expand Up @@ -931,7 +922,7 @@ def set_plan_speed(self, id, speed):
"""Set planning speed
Args:
id: 0/1/2/3 (ALL/L/R/W)
id: 0/1/2 (ALL/L/R)
speed (int): (0 ~ 100).
"""
return self._mesg(ProtocolCode.SET_PLAN_SPEED, id, speed)
Expand Down
6 changes: 4 additions & 2 deletions pymycobot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from pymycobot.ultraArm import ultraArm
from pymycobot.mybuddybluetooth import MyBuddyBlueTooth
from pymycobot.mypalletizersocket import MyPalletizerSocket
from pymycobot.myarm import MyArm


__all__ = [
Expand All @@ -33,15 +34,16 @@
"MyBuddyBlueTooth",
"ultraArm",
"MyPalletizerSocket",
"MechArm"
"MechArm",
"MyArm"
]


if sys.platform == "linux":
from pymycobot.mybuddyemoticon import MyBuddyEmoticon
__all__.append("MyBuddyEmoticon")

__version__ = "2.9.9"
__version__ = "3.0.0b2"
__author__ = "Elephantrobotics"
__email__ = "[email protected]"
__git_url__ = "https://github.com/elephantrobotics/pymycobot"
Expand Down
7 changes: 4 additions & 3 deletions pymycobot/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ class ProtocolCode(object):
GET_ANGLE = 0x2C
GET_COORD = 0x2D
SEND_ANGLES_AUTO = 0x2E
SET_SOLUTION_ANGLES = 0x2E
GET_SOLUTION_ANGLES = 0x2F
GET_SOLUTION_ANGLES = 0x2E
SET_SOLUTION_ANGLES = 0x2F

# JOG MODE AND OPERATION
JOG_ANGLE = 0x30
Expand Down Expand Up @@ -289,7 +289,7 @@ def _process_received(self, data, genre, arm=6):

# process valid data
res = []
if data_len in [6, 8, 12, 24, 60]:
if data_len in [6, 8, 12, 14, 24, 60]:
for header_i in range(0, len(valid_data), 2):
one = valid_data[header_i : header_i + 2]
res.append(self._decode_int16(one))
Expand Down Expand Up @@ -413,4 +413,5 @@ def read(self, genre):
pre = k
else:
datas = None
self.log.debug("_read: {}".format(datas))
return datas
88 changes: 55 additions & 33 deletions pymycobot/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,9 +223,10 @@ def send_angle(self, id, degree, speed):
Args:
id : Joint id(genre.Angle)\n
For mycobot: int 1-6.\n
For mypalletizer: int 1-4.
For mypalletizer 340: int 1-3.
for mycobot: int 1-6.\n
for mypalletizer: int 1-4.
for mypalletizer 340: int 1-3.
for myArm: int 1 - 7.
degree : degree value(float)(about -170 ~ 170).
speed : (int) 0 ~ 100
"""
Expand All @@ -241,7 +242,8 @@ def send_angles(self, degrees, speed):
for mycobot: [0.0, 0.0, 0.0, 0.0, 0.0, 0.0].\n
for mypalletizer: [0.0, 0.0, 0.0, 0.0]
for mypalletizer 340: [0.0, 0.0, 0.0]
speed : (int) 0 ~ 100
for myArm: [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0].\n
speed : (int) 1 ~ 100
"""
# self.calibration_parameters(degrees=degrees, speed=speed)
degrees = [self._angle2int(degree) for degree in degrees]
Expand All @@ -263,9 +265,9 @@ def send_coord(self, id, coord, speed):
Args:
id(int) : coord id(genre.Coord)\n
For mycobot: int 1-6.\n
For mypalletizer: int 1-4.
For mypalletizer 340: int 1-3.
for mycobot: int 1-6.\n
for mypalletizer: int 1-4.
for mypalletizer 340: int 1-3.
coord(float) : coord value, mm
speed(int) : 0 ~ 100
"""
Expand Down Expand Up @@ -341,9 +343,10 @@ def jog_angle(self, joint_id, direction, speed):
Args:
joint_id: int
For mycobot: int 1-6.\n
For mypalletizer: int 1-4.
For mypalletizer 340: int 1-3.
for mycobot: int 1-6.\n
for mypalletizer: int 1-4.
for mypalletizer 340: int 1-3.
for myArm: int 1 - 7.
direction: 0 - decrease, 1 - increase
speed: int (0 - 100)
"""
Expand All @@ -354,9 +357,9 @@ def jog_coord(self, coord_id, direction, speed):
Args:
coord_id: int
For mycobot: int 1-6.\n
For mypalletizer: int 1-4.
For mypalletizer 340: int 1-3.
for mycobot: int 1-6.\n
for mypalletizer: int 1-4.
for mypalletizer 340: int 1-3.
direction: 0 - decrease, 1 - increase
speed: int (0 - 100)
"""
Expand All @@ -367,8 +370,9 @@ def jog_absolute(self, joint_id, angle, speed):
Args:
joint_id: int
For mycobot: int 1-6.\n
For mypalletizer: int 1-4.
for mycobot: int 1-6.\n
for mypalletizer: int 1-4.
for myArm: int 1 - 7.
angle: -180 ~ 180
speed: int (0 - 100)
"""
Expand All @@ -378,7 +382,10 @@ def jog_increment(self, joint_id, increment, speed):
"""step mode
Args:
joint_id: int 1-6.
joint_id:
for mycobot: int 1-6.
for mypalletizer: int 1-4.
for myArm: int 1 - 7.
increment:
speed: int (0 - 100)
"""
Expand Down Expand Up @@ -418,6 +425,7 @@ def set_encoder(self, joint_id, encoder):
for mycobot: Joint id 1 - 6
for mypalletizer: Joint id 1 - 4
for mycobot gripper: Joint id 7
for myArm: int 1 - 7.
encoder: The value of the set encoder.
"""
return self._mesg(ProtocolCode.SET_ENCODER, joint_id, [encoder])
Expand All @@ -426,7 +434,7 @@ def get_encoder(self, joint_id):
"""Obtain the specified joint potential value. (mypalletizer 340 does not have this interface)
Args:
joint_id: (int) 1 ~ 6
joint_id: (int) 1 ~ 7
Returns:
encoder: 0 ~ 4096
Expand All @@ -437,8 +445,8 @@ def set_encoders(self, encoders, sp):
"""Set the six joints of the manipulator to execute synchronously to the specified position. (mypalletizer 340 does not have this interface)
Args:
encoders: A encoder list, length 6.
sp: speed 0 ~ 100
encoders: A encoder list.
sp: speed 1 ~ 100
"""
return self._mesg(ProtocolCode.SET_ENCODERS, encoders, sp)

Expand Down Expand Up @@ -491,7 +499,11 @@ def get_joint_min_angle(self, joint_id):
"""Gets the minimum movement angle of the specified joint
Args:
joint_id: (int)
joint_id:
for mycobot: Joint id 1 - 6
for mypalletizer: Joint id 1 - 4
for mycobot gripper: Joint id 7
for myArm: int 1 - 7.
Return:
angle value(float)
Expand All @@ -503,7 +515,11 @@ def get_joint_max_angle(self, joint_id):
"""Gets the maximum movement angle of the specified joint
Args:
joint_id: (int)
joint_id:
for mycobot: Joint id 1 - 6
for mypalletizer: Joint id 1 - 4
for mycobot gripper: Joint id 7
for myArm: int 1 - 7.
Return:
angle value(float)
Expand All @@ -513,10 +529,14 @@ def get_joint_max_angle(self, joint_id):

# Servo control
def is_servo_enable(self, servo_id):
"""Determine whether all steering gears are connected
"""To detect the connection state of a single joint
Args:
servo_id: (int) 1 ~ 6
servo_id:
for mycobot: Joint id 1 - 6
for mypalletizer: Joint id 1 - 4
for mycobot gripper: Joint id 7
for myArm: int 1 - 7.
Return:
0 - disable
Expand All @@ -526,7 +546,7 @@ def is_servo_enable(self, servo_id):
return self._mesg(ProtocolCode.IS_SERVO_ENABLE, servo_id, has_reply=True)

def is_all_servo_enable(self):
"""Determine whether the specified steering gear is connected
"""Detect the connection status of all joints
Return:
0 - disable
Expand All @@ -539,7 +559,7 @@ def set_servo_data(self, servo_id, data_id, value):
"""Set the data parameters of the specified address of the steering gear
Args:
servo_id: Serial number of articulated steering gear, 1 - 6.
servo_id: Serial number of articulated steering gear, 1 - 7.
data_id: Data address.
value: 0 - 4096
"""
Expand Down Expand Up @@ -909,9 +929,10 @@ def set_joint_max(self, id, angle):
Args:
id: int.
For mycobot: int 1-6.\n
For mypalletizer: int 1-4.
For mypalletizer 340: int 1-3.
for mycobot: Joint id 1 - 6
for mypalletizer: Joint id 1 - 4
for mycobot gripper: Joint id 7
for myArm: int 1 - 7.
angle: 0 ~ 180
"""
return self._mesg(ProtocolCode.SET_JOINT_MAX, id, angle)
Expand All @@ -921,9 +942,10 @@ def set_joint_min(self, id, angle):
Args:
id: int.
For mycobot: int 1-6.\n
For mypalletizer: int 1-4.\n
For mypalletizer 340: int 1-3.
for mycobot: Joint id 1 - 6
for mypalletizer: Joint id 1 - 4
for mycobot gripper: Joint id 7
for myArm: int 1 - 7.
angle: 0 ~ 180
"""
return self._mesg(ProtocolCode.SET_JOINT_MIN, id, angle)
Expand All @@ -944,7 +966,7 @@ def set_encoders_drag(self, encoders, speeds): # TODO 22-5-19 need test
"""Send all encoders and speeds
Args:
encoders: encoders list
encoders: encoders list.
speeds: Obtained by the get_servo_speeds() method
"""
return self._mesg(ProtocolCode.SET_ENCODERS_DRAG, encoders, speeds)
Expand Down Expand Up @@ -984,7 +1006,7 @@ def get_servo_last_pdi(self, id):
"""Obtain the pdi of a single steering gear before modification
Args:
id: 1 - 6.0
id: 1 - 6
"""
return self._mesg(ProtocolCode.GET_SERVO_LASTPDI, id, has_reply = True)

Loading

0 comments on commit d4f09d5

Please sign in to comment.