diff --git a/.vscode/settings.json b/.vscode/settings.json index b5c53fa..0070c39 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -16,5 +16,6 @@ "yview", "zhang" ], - "restructuredtext.confPath": "" + "restructuredtext.confPath": "", + "python.formatting.provider": "black" } diff --git a/CHANGELOG.md b/CHANGELOG.md index c4ea7d2..715e02a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/demo/350servo_info.py b/demo/350servo_info.py new file mode 100644 index 0000000..ef65306 --- /dev/null +++ b/demo/350servo_info.py @@ -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() \ No newline at end of file diff --git a/pymycobot/__init__.py b/pymycobot/__init__.py index 1491b21..944e267 100644 --- a/pymycobot/__init__.py +++ b/pymycobot/__init__.py @@ -20,7 +20,7 @@ "MyCobotSocket" ] -__version__ = "2.7.4" +__version__ = "2.7.5" __author__ = "Elephantrobotics" __email__ = "weiquan.xu@elephantrobotics.com" __git_url__ = "https://github.com/elephantrobotics/pymycobot" diff --git a/pymycobot/common.py b/pymycobot/common.py index 82873b0..6d1e51e 100644 --- a/pymycobot/common.py +++ b/pymycobot/common.py @@ -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) diff --git a/pymycobot/generate.py b/pymycobot/generate.py index c22d4ef..f1b0f26 100644 --- a/pymycobot/generate.py +++ b/pymycobot/generate.py @@ -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 """ @@ -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) @@ -213,8 +215,8 @@ 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) @@ -222,7 +224,9 @@ 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 """ @@ -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 """ @@ -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) """ @@ -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) """ @@ -493,8 +501,9 @@ 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) @@ -502,8 +511,9 @@ 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) @@ -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): @@ -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) @@ -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) diff --git a/pymycobot/mycobot.py b/pymycobot/mycobot.py index 062dbd2..2c061ec 100755 --- a/pymycobot/mycobot.py +++ b/pymycobot/mycobot.py @@ -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