Skip to content

Commit

Permalink
push code
Browse files Browse the repository at this point in the history
  • Loading branch information
anla-xu committed Apr 29, 2022
1 parent 2149bdb commit 0d919a5
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 25 deletions.
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@
"yview",
"zhang"
],
"restructuredtext.confPath": ""
"restructuredtext.confPath": "",
"python.formatting.provider": "black"
}
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# ChangeLog for pymycobot

## v2.7.5 (2022-4-29)

- release v2.7.5
- Fixed an issue where the M5 would restart when the serial port was initialized for the first time.
- New interface: `get_tool_reference`,`set_tool_reference`,`set_world_reference`,`get_world_reference`,`set_reference_frame`,`get_reference_frame`,`set_movement_type`,`get_movement_type`,`set_end_type`,`get_end_type`,`get_plan_speed`,`get_plan_acceleration`,`set_plan_speed`,`set_plan_acceleration`,`get_servo_speeds`,`get_servo_currents`,`get_servo_voltages`,`get_servo_status`,`get_servo_temps`.

## v2.7.4 (2021-12-15)

- release v2.7.4
Expand Down
34 changes: 34 additions & 0 deletions demo/350servo_info.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# encoding=utf-8
import matplotlib.pyplot as plt
import matplotlib.font_manager as font_manager
from pymycobot import MyCobot

mc = MyCobot("COM12", 115200)

POINTS = 7
sin_list = [0] * (POINTS -1)
indx = 0

fig, ax = plt.subplots()
ax.set_ylim([0, 3250])
ax.set_xlim([1, 6])
ax.set_autoscale_on(False)
ax.set_xticks(range(0, 3250, 500))
ax.set_yticks(range(0, 11, 1))
ax.grid(True)

line_sin, = ax.plot([i for i in range(1,POINTS)], sin_list, label='Current', color='cornflowerblue')
ax.legend(loc='upper center', ncol=4, prop=font_manager.FontProperties(size=10))

def sin_output(ax):
global sin_list, line_sin
sin_list = sin_list[1:] + mc.get_servo_currents() # get current
# print(sin_list)
line_sin.set_ydata(sin_list)
ax.draw_artist(line_sin)
ax.figure.canvas.draw()

timer = fig.canvas.new_timer(interval=100)
timer.add_callback(sin_output, ax)
timer.start()
plt.show()
2 changes: 1 addition & 1 deletion pymycobot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"MyCobotSocket"
]

__version__ = "2.7.4"
__version__ = "2.7.5"
__author__ = "Elephantrobotics"
__email__ = "[email protected]"
__git_url__ = "https://github.com/elephantrobotics/pymycobot"
Expand Down
2 changes: 0 additions & 2 deletions pymycobot/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,8 +261,6 @@ def write(self, command, method=None):
self.log.debug("_write: {}".format(command))
self._serial_port.write(command)
self._serial_port.flush()
time.sleep(0.05)


def read(self):
time.sleep(0.1)
Expand Down
60 changes: 40 additions & 20 deletions pymycobot/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,9 @@ def send_angle(self, id, degree, speed):
"""Send one degree of joint to robot arm.
Args:
id : Joint id(genre.Angle), int 1-6
id : Joint id(genre.Angle)\n
For mycobot: int 1-6.\n
For mypalletizer: int 1-4.
degree : degree value(float)(about -170 ~ 170).
speed : (int) 0 ~ 100
"""
Expand All @@ -199,9 +201,9 @@ def send_angles(self, degrees, speed):
"""Send the degrees of all joints to robot arm.
Args:
degrees : a list of degree values(List[float]), length 6.
example for mycobot [0.0, 0.0, 0.0, 0.0, 0.0, 0.0]
example for mypalletizer [0.0, 0.0, 0.0, 0.0]
degrees: a list of degree values(List[float]), length 6 or 4.\n
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]
speed : (int) 0 ~ 100
"""
self.calibration_parameters(degrees=degrees, speed=speed)
Expand All @@ -213,16 +215,18 @@ def get_coords(self):
Return:
list : A float list of coord
for mycobot -[x, y, z, rx, ry, rz],
for mypalletizer -[x, y, z, θ]
for mycobot: [x, y, z, rx, ry, rz]\n
for mypalletizer: [x, y, z, θ]
"""
return self._mesg(ProtocolCode.GET_COORDS, has_reply=True)

def send_coord(self, id, coord, speed):
"""Send one coord to robot arm.
Args:
id(int) : coord id(genre.Coord), 1 ~ 6
id(int) : coord id(genre.Coord)\n
For mycobot: int 1-6.\n
For mypalletizer: int 1-4.
coord(float) : coord value, mm
speed(int) : 0 ~ 100
"""
Expand All @@ -234,9 +238,9 @@ def send_coords(self, coords, speed, mode):
"""Send all coords to robot arm.
Args:
coords: a list of coords value(List[float]), length 6.
for mycobot :[x(mm), y, z, rx(angle), ry, rz]
for mypalletizer: [x, y, z, θ]
coords: a list of coords value(List[float]), length 6 or 4.
for mycobot :[x(mm), y, z, rx(angle), ry, rz]\n
for mypalletizer: [x, y, z, θ]
speed : (int) 0 ~ 100
mode : (int) 0 - angluar, 1 - linear
"""
Expand Down Expand Up @@ -290,7 +294,9 @@ def jog_angle(self, joint_id, direction, speed):
"""Jog control angle.
Args:
joint_id: (int) 1 ~ 6.
joint_id:
For mycobot: int 1-6.\n
For mypalletizer: int 1-4.
direction: 0 - decrease, 1 - increase
speed: int (0 - 100)
"""
Expand All @@ -300,7 +306,9 @@ def jog_coord(self, coord_id, direction, speed):
"""Jog control coord.
Args:
coord_id: (int) 1 ~ 6
coord_id:
For mycobot: int 1-6.\n
For mypalletizer: int 1-4.
direction: 0 - decrease, 1 - increase
speed: int (0 - 100)
"""
Expand Down Expand Up @@ -493,17 +501,19 @@ def release_servo(self, servo_id):
"""Power off designated servo
Args:
for mycobot: servo_id: 1 - 6
for mypalletizer: servo_id: 1 - 4
servo_id:
for mycobot: 1 - 6.\n
for mypalletizer: 1 - 4
"""
return self._mesg(ProtocolCode.RELEASE_SERVO, servo_id)

def focus_servo(self, servo_id):
"""Power on designated servo
Args:
for mycobot: servo_id: 1 - 6
for mypalletizer: servo_id: 1 - 4
servo_id:
for mycobot: 1 - 6\n
for mypalletizer: 1 - 4
"""
return self._mesg(ProtocolCode.FOCUS_SERVO, servo_id)

Expand Down Expand Up @@ -774,11 +784,17 @@ def get_servo_speeds(self):
return self._mesg(ProtocolCode.GET_SERVO_SPEED, has_reply=True)

def get_servo_currents(self):
"""Get joint current (Only for mycobot 350)"""
"""Get joint current (Only for mycobot 350)
return: mA
"""
return self._mesg(ProtocolCode.GET_SERVO_CURRENTS, has_reply=True)

def get_servo_voltages(self):
"""Get joint voltages (Only for mycobot 350)"""
"""Get joint voltages (Only for mycobot 350)
return: volts
"""
return self._mesg(ProtocolCode.GET_SERVO_VOLTAGES, has_reply=True)

def get_servo_status(self):
Expand All @@ -793,7 +809,9 @@ def set_joint_max(self, id, angle):
"""Set the joint maximum angle
Args:
id: 1 - 6
id:
For mycobot: int 1-6.\n
For mypalletizer: int 1-4.
angle: 0 ~ 180
"""
return self._mesg(ProtocolCode.SET_JOINT_MAX, id, angle)
Expand All @@ -802,7 +820,9 @@ def set_joint_min(self, id, angle):
"""Set the joint minimum angle
Args:
id: 1 - 6
id:
For mycobot: int 1-6.\n
For mypalletizer: int 1-4.
angle: 0 ~ 180
"""
return self._mesg(ProtocolCode.SET_JOINT_MIN, id, angle)
3 changes: 2 additions & 1 deletion pymycobot/mycobot.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,8 @@ def _mesg(self, genre, *args, **kwargs):
return r
else:
return res

elif genre in [ProtocolCode.GET_SERVO_VOLTAGES]:
return [self._int2coord(angle) for angle in res]
else:
return res
return None
Expand Down

0 comments on commit 0d919a5

Please sign in to comment.