diff --git a/CHANGELOG.md b/CHANGELOG.md index c90cb3d..7a46eda 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # ChangeLog for pymycobot +## v3.6.3 (2024-10-17) + +- release v3.6.3 +- Fix bug and add new function + ## v3.6.2 (2024-10-11) - release v3.6.2 diff --git a/docs/MechArm_270_en.md b/docs/MechArm_270_en.md index ffdbe4a..1924e43 100644 --- a/docs/MechArm_270_en.md +++ b/docs/MechArm_270_en.md @@ -72,7 +72,7 @@ mc.send_angle(1, 40, 20) - Attentions:After the joint is disabled, it needs to be enabled to control within 1 second - **Parameters**:`data`(optional):The way to relax the joints. The default is damping mode, and if the 'data' parameter is provided, it can be specified as non damping mode (1- Undamping). -#### `focus_servos(servo_id)` +#### `focus_servo(servo_id)` - **function:** Power on designated servo @@ -114,6 +114,21 @@ mc.send_angle(1, 40, 20) - `1`: Always execute the latest command first. - `0`: Execute instructions sequentially in the form of a queue. +#### `focus_all_servos()` + +- **Function:** All servos are powered on + +- **Return value:** +- `1`: complete + +#### `set_vision_mode()` + +- **Function:** Set the vision tracking mode, limit the posture flipping of send_coords in refresh mode. (Applicable only to vision tracking function) + +- **Parameter:** + - `1`: open + - `0`: close + ### 3.MDI Mode and Operation #### `get_angles()` @@ -182,20 +197,22 @@ mc.send_angle(1, 40, 20) - `0` - not stop - `-1` - error -#### `sync_send_angles(angles, speed)` +#### `sync_send_angles(angles, speed, timeout=15)` - **function:** Send the angle in synchronous state and return when the target point is reached - **Parameters:** - `angles`: a list of degree value(`List[float]`), length 6 - `speed`: (`int`) 1 ~ 100 + - `timeout`: default 15 s -#### `sync_send_coords(coords, mode, speed)` +#### `sync_send_coords(coords, speed, mode=0, timeout=15)` - **function:** Send the coord in synchronous state and return when the target point is reached - **Parameters:** - `coords`: a list of coord value(`List[float]`), length 6 - `speed`: (`int`) 1 ~ 100 - `mode`: (`int`) 0 - angular(default), 1 - linear + - `timeout`: default 15 s #### `get_angles_coords()` @@ -244,6 +261,21 @@ mc.send_angle(1, 40, 20) - `0` not moving - `-1` error +#### `angles_to_coords(angles)` + +- **Function** : Convert angles to coordinates. +- **Parameters:** + - `angles`: `list` List of floating points for all angles. +- **Return value**: `list` List of floating points for all coordinates. + +#### `solve_inv_kinematics(target_coords, current_angles)` + +- **Function** : Convert coordinates to angles. +- **Parameters:** + - `target_coords`: `list` List of floating points for all coordinates. + - `current_angles`: `list` List of floating points for all angles, current angles of the robot +- **Return value**: `list` List of floating points for all angles. + ### 4. JOG Mode and Operation #### `jog_angle(joint_id, direction, speed)` @@ -270,14 +302,24 @@ mc.send_angle(1, 40, 20) - `direction`: (`int`) To control the direction of machine arm movement, `1` - forward rotation, `0` - reverse rotation - `speed`: (`int`) 1 ~ 100 -#### `jog_increment(joint_id, increment, speed)` +#### `jog_increment_angle(joint_id, increment, speed)` -- **function:** Single joint angle increment control +- **function:** Angle step, single joint angle increment control - **Parameters**: - `joint_id`: 1-6 - `increment`: Incremental movement based on the current position angle - `speed`: 1 ~ 100 +#### `jog_increment_coord(id, increment, speed)` + +- **function:** Coord step, single coord increment control +- **Parameters**: + - `id`: axis 1-6 + - `increment`: Incremental movement based on the current position coord + - `speed`: 1 ~ 100 +- **Return value:** + - `1`: completed + #### `set_encoder(joint_id, encoder, speed)` - **function**: Set a single joint rotation to the specified potential value diff --git a/docs/MechArm_270_zh.md b/docs/MechArm_270_zh.md index 338f2b0..ff09722 100644 --- a/docs/MechArm_270_zh.md +++ b/docs/MechArm_270_zh.md @@ -71,7 +71,7 @@ mc.send_angle(1, 40, 20) - **功能:** 放松所有机械臂关节 - **参数**:`data`(可选):关节放松方式,默认为阻尼模式,若提供 `data`参数可指定为非阻尼模式(1-Undamping)。 -#### `focus_servos(servo_id)` +#### `focus_servo(servo_id)` - **功能:** 单个舵机上电 @@ -113,6 +113,24 @@ mc.send_angle(1, 40, 20) - `1`: 总是首先执行最新的命令。 - `0`: 以队列的形式按顺序执行指令。 +#### `focus_all_servos()` + +- **功能:** 所有舵机上电 + +- **返回值:** +- `1`: complete + +#### `set_vision_mode()` + +- **功能:** 设置视觉跟踪模式,限制刷新模式下send_coords的姿态翻转。(仅适用于视觉跟踪功能) + +- **参数:** + - `1`: 打开 + - `0`: 关闭 + +- **返回值:** + - `1`: 完成 + ### 3. MDI运行与操作 #### `get_angles()` @@ -181,20 +199,22 @@ mc.send_angle(1, 40, 20) - `0` - 没有停止 - `-1` - 错误 -#### `sync_send_angles(angles, speed)` +#### `sync_send_angles(angles, speed, timeout=15)` - **功能:** 同步状态下发送角度,到达目标点后返回 - **参数:** - `angles`:角度值列表(`List[float]`),长度 6 - `speed`:(`int`)1 ~ 100 + - `timeout`: 默认15秒 -#### `sync_send_coords(coords, mode, speed)` +#### `sync_send_coords(coords, speed,mode=0, timeout=15)` - **功能:** 同步状态下发送坐标,到达目标点后返回 - **参数:** - `coords`:坐标值列表(`List[float]`),长度6 - `speed`:(`int`)1~100 - `mode`:(`int`)0-非线性(默认),1-直线运动 + - `timeout`: 默认15秒 #### `get_angles_coords()` @@ -243,6 +263,21 @@ mc.send_angle(1, 40, 20) - `0` 未运动 - `-1` 错误 +#### `angles_to_coords(angles)` + +- **功能** : 将角度转为坐标。 +- **参数:** + - `angles`:`list` 所有角度的浮点列表。 +- **返回值**: `list` 所有坐标的浮点列表。 + +#### `solve_inv_kinematics(target_coords, current_angles)` + +- **功能** : 将坐标转为角度。 +- **参数:** + - `target_coords`: `list` 所有坐标的浮点列表。 + - `current_angles`: `list` 所有角度的浮点列表,机械臂当前角度 +- **返回值**: `list` 所有角度的浮点列表。 + ### 4. JOG运行与操作 #### `jog_angle(joint_id, direction, speed)` @@ -269,22 +304,32 @@ mc.send_angle(1, 40, 20) - `direction`: (`int`) 控制机臂运动方向,`1` - 正转,`0` - 反转 - `speed`: (`int`) 1 ~ 100 -#### `jog_increment(joint_id, increment, speed)` +#### `jog_increment_angle(joint_id, increment, speed)` -- **功能**:单关节角度增量控制 +- **功能**:角度步进,单关节角度增量控制 - **参数**: - `joint_id`:1-6 - `increment`:基于当前位置角度的增量移动 - `speed`:1~100 +#### `jog_increment_coord(id, increment, speed)` + +- **功能**:坐标步进,单坐标增量控制 +- **参数**: + - `id`:坐标 id 1-6 + - `increment`:基于当前位置坐标的增量移动 + - `speed`:1~100 +- **返回值**: +- `1`:完成 + #### `set_encoder(joint_id,coder,speed)` - **功能**:设置单关节旋转为指定的潜在值 - **参数** - - `joint_id`:(`int`) 1-6 - - `encoder`:0~4096 - - `speed`:1~100 + - `joint_id`:(`int`) 1-6 + - `encoder`:0~4096 + - `speed`:1~100 #### `get_encoder(joint_id)` diff --git a/docs/MyCobot_280_en.md b/docs/MyCobot_280_en.md index 9596fa3..5014811 100644 --- a/docs/MyCobot_280_en.md +++ b/docs/MyCobot_280_en.md @@ -80,7 +80,7 @@ mc.send_angle(1, 40, 20) - **Return value:** - `1` - release completed. -#### `focus_servos(servo_id)` +#### `focus_servo(servo_id)` - **function:** Power on designated servo @@ -147,6 +147,24 @@ mc.send_angle(1, 40, 20) - `1`: free mode - `0`: on-free mode +#### `focus_all_servos()` + +- **Function:** All servos are powered on + +- **Return value:** +- `1`: complete + +#### `set_vision_mode()` + +- **Function:** Set the vision tracking mode, limit the posture flipping of send_coords in refresh mode. (Applicable only to vision tracking function) + +- **Parameter:** + - `1`: open + - `0`: close + +- **Return value:** + - `1`: complete + ### 3.MDI Mode and Operation #### `get_angles()` @@ -223,24 +241,26 @@ mc.send_angle(1, 40, 20) - `0` - not stop - `-1` - error -#### `sync_send_angles(angles, speed)` +#### `sync_send_angles(angles, speed, timeout=15)` - **function:** Send the angle in synchronous state and return when the target point is reached - **Parameters:** - `angles`: a list of degree value(`List[float]`), length 6 - `speed`: (`int`) 1 ~ 100 + - `timeout`: default 15 s - **Return value:** - - `1`: complete + - `1` - complete -#### `sync_send_coords(coords, mode, speed)` +#### `sync_send_coords(coords, speed, mode=0, timeout=15)` - **function:** Send the coord in synchronous state and return when the target point is reached - **Parameters:** - `coords`: a list of coord value(`List[float]`), length 6 - `speed`: (`int`) 1 ~ 100 - `mode`: (`int`) 0 - angular(default), 1 - linear + - `timeout`: default 15 s - **Return value:** - - `1`: complete + - `1` - complete #### `get_angles_coords()` @@ -291,6 +311,21 @@ mc.send_angle(1, 40, 20) - `0` not moving - `-1` error +#### `angles_to_coords(angles)` + +- **Function** : Convert angles to coordinates. +- **Parameters:** + - `angles`: `list` List of floating points for all angles. +- **Return value**: `list` List of floating points for all coordinates. + +#### `solve_inv_kinematics(target_coords, current_angles)` + +- **Function** : Convert coordinates to angles. +- **Parameters:** + - `target_coords`: `list` List of floating points for all coordinates. + - `current_angles`: `list` List of floating points for all angles, current angles of the robot +- **Return value**: `list` List of floating points for all angles. + ### 4. JOG Mode and Operation #### `jog_angle(joint_id, direction, speed)` @@ -323,13 +358,25 @@ mc.send_angle(1, 40, 20) - **Return value:** - `1`: complete -#### `jog_increment(joint_id, increment, speed)` +#### `jog_increment_angle(joint_id, increment, speed)` -- **function:** Single joint angle increment control +- **function:** Angle step, single joint angle increment control - **Parameters**: - `joint_id`: 1-6 - `increment`: Incremental movement based on the current position angle - `speed`: 1 ~ 100 +- **Return value:** + - `1`: completed + +#### `jog_increment_coord(id, increment, speed)` + +- **function:** Coord step, single coord increment control +- **Parameters**: + - `id`: axis 1-6 + - `increment`: Incremental movement based on the current position coord + - `speed`: 1 ~ 100 +- **Return value:** + - `1`: completed #### `set_encoder(joint_id, encoder, speed)` diff --git a/docs/MyCobot_280_zh.md b/docs/MyCobot_280_zh.md index 5a0cd71..333e100 100644 --- a/docs/MyCobot_280_zh.md +++ b/docs/MyCobot_280_zh.md @@ -78,7 +78,7 @@ mc.send_angle(1, 40, 20) - **返回值:** - `1` - 释放完成。 -#### `focus_servos(servo_id)` +#### `focus_servo(servo_id)` - **功能:** 单个舵机上电 @@ -145,6 +145,24 @@ mc.send_angle(1, 40, 20) - `1`: 自由移动模式 - `0`: 非自由移动模式 +#### `focus_all_servos()` + +- **功能:** 所有舵机上电 + +- **返回值:** +- `1`: complete + +#### `set_vision_mode()` + +- **功能:** 设置视觉跟踪模式,限制刷新模式下send_coords的姿态翻转。(仅适用于视觉跟踪功能) + +- **参数:** + - `1`: 打开 + - `0`: 关闭 + +- **返回值:** + - `1`: 完成 + ### 3. MDI运行与操作 #### `get_angles()` @@ -221,24 +239,26 @@ mc.send_angle(1, 40, 20) - `0` - 没有停止 - `-1` - 错误 -#### `sync_send_angles(angles, speed)` +#### `sync_send_angles(angles, speed, timeout=15)` - **功能:** 同步状态下发送角度,到达目标点后返回 - **参数:** -- `angles`:角度值列表(`List[float]`),长度 6 -- `speed`:(`int`)1 ~ 100 + - `angles`:角度值列表(`List[float]`),长度 6 + - `speed`:(`int`)1 ~ 100 + - `timeout`: 默认15秒 - **返回值:** -- `1`:完成 + - `1`:完成 -#### `sync_send_coords(coords, mode, speed)` +#### `sync_send_coords(coords, speed, mode=0, timeout=15)` - **功能:** 同步状态下发送坐标,到达目标点后返回 - **参数:** -- `coords`:坐标值列表(`List[float]`),长度6 -- `speed`:(`int`)1~100 -- `mode`:(`int`)0-非线性(默认),1-直线运动 + - `coords`:坐标值列表(`List[float]`),长度6 + - `speed`:(`int`)1~100 + - `mode`:(`int`)0-非线性(默认),1-直线运动 + - `timeout`: 默认15秒 - **返回值:** -- `1`:完成 + - `1`:完成 #### `get_angles_coords()` @@ -277,9 +297,9 @@ mc.send_angle(1, 40, 20) - `0`: 角度 - `1`: 坐标 - **返回值**: -- `1` - 到达 -- `0` - 未到达 -- `-1 ` - 错误 + - `1` - 到达 + - `0` - 未到达 + - `-1` - 错误 #### `is_moving()` @@ -289,6 +309,21 @@ mc.send_angle(1, 40, 20) - `0` 未运动 - `-1` 错误 +#### `angles_to_coords(angles)` + +- **功能** : 将角度转为坐标。 +- **参数:** + - `angles`:`list` 所有角度的浮点列表。 +- **返回值**: `list` 所有坐标的浮点列表。 + +#### `solve_inv_kinematics(target_coords, current_angles)` + +- **功能** : 将坐标转为角度。 +- **参数:** + - `target_coords`: `list` 所有坐标的浮点列表。 + - `current_angles`: `list` 所有角度的浮点列表,机械臂当前角度 +- **返回值**: `list` 所有角度的浮点列表。 + ### 4. JOG运行与操作 #### `jog_angle(joint_id, direction, speed)` @@ -321,22 +356,34 @@ mc.send_angle(1, 40, 20) - **返回值:** - `1`: 完成 -#### `jog_increment(joint_id, increment, speed)` +#### `jog_increment_angle(joint_id, increment, speed)` -- **功能**:单关节角度增量控制 +- **功能**:关节步进,单关节角度增量控制 - **参数**: -- `joint_id`:1-6 -- `increment`:基于当前位置角度的增量移动 -- `speed`:1~100 + - `joint_id`:1-6 + - `increment`:基于当前位置角度的增量移动 + - `speed`:1~100 +- **返回值**: +- `1`:完成 + +#### `jog_increment_coord(id, increment, speed)` + +- **功能**:坐标步进,单坐标增量控制 +- **参数**: + - `id`:坐标 id 1-6 + - `increment`:基于当前位置坐标的增量移动 + - `speed`:1~100 +- **返回值**: +- `1`:完成 #### `set_encoder(joint_id,coder,speed)` - **功能**:设置单关节旋转为指定的潜在值 - **参数** - - `joint_id`:(`int`) 1-6 - - `encoder`:0~4096 - - `speed`:1~100 + - `joint_id`:(`int`) 1-6 + - `encoder`:0~4096 + - `speed`:1~100 - **返回值**: - `1`:完成 diff --git a/docs/MyCobot_320_en.md b/docs/MyCobot_320_en.md index e7bcc56..ff56763 100644 --- a/docs/MyCobot_320_en.md +++ b/docs/MyCobot_320_en.md @@ -42,10 +42,14 @@ mc.send_angle(1, 40, 20) #### `power_on()` - **function:** atom open communication (default open) +- **Return value:** + - `1`: completed #### `power_off()` - **function:** Power off of the robotic arm +- **Return value:** + - `1`: completed #### `is_power_on()` @@ -56,18 +60,22 @@ mc.send_angle(1, 40, 20) - `0`: power off - `-1`: error -#### `release_all_servos()` +#### `release_all_servos(data=None)` - **function:** release all robot arms - Attentions:After the joint is disabled, it needs to be enabled to control within 1 second - **Parameters**:`data`(optional):The way to relax the joints. The default is damping mode, and if the 'data' parameter is provided, it can be specified as non damping mode (1- Undamping). +- **Return value:** + - `1`: completed -#### `focus_servos(servo_id)` +#### `focus_servo(servo_id)` - **function:** Power on designated servo - **Parameters:** - `servo_id:` int, 1-6 +- **Return value:** + - `1`: completed #### `is_controller_connected()` @@ -103,6 +111,45 @@ mc.send_angle(1, 40, 20) - **Parameters:** - `1`: Always execute the latest command first. - `0`: Execute instructions sequentially in the form of a queue. +- **Return value:** + - `1`: completed + +#### `get_robot_status()` + +- **Function:** Get the robot self-check status to see if important parameters are normal. + +- **Abnormal description:** + - 0: Communication abnormality, please check whether the line, servo firmware version is normal, whether the power is plugged in, whether the firmware is burned correctly, whether the baud rate is correct, etc. + - 1: The servo motor model is wrong and the motor needs to be replaced + - 2: The servo motor firmware version is low and needs to be upgraded using FD + - 3: The servo motor p value is abnormal, the default is 32, this abnormality will be automatically restored + - 4: The servo motor D value is abnormal, the default is 8, this abnormality will be automatically restored + - 5: The servo motor I value is abnormal, the default is 0, this abnormality will be automatically restored + - 6: The servo motor clockwise insensitive zone parameter is abnormal, the default is 3, this abnormality will be automatically restored + - 7: The servo motor counterclockwise insensitive zone parameter is abnormal, the default is 3, this abnormality will be automatically restored + - 8: The servo motor phase is abnormal, this abnormality will be automatically restored + - 9: The servo motor return delay is abnormal, the default is 0, this abnormality will be automatically restored + - 10: The servo motor minimum starting force is abnormal, the default is 0, this abnormality will be automatically restored + - 11: The servo motor is abnormal. When the servo is abnormal, the machine cannot be controlled. Please query the servo feedback interface get_servo_status to check the specific error. + - 255: Unknown error + +#### `focus_all_servos()` + +- **Function:** All servos are powered on + +- **Return value:** + - `1`: complete + +#### `set_vision_mode()` + +- **Function:** Set the vision tracking mode, limit the posture flipping of send_coords in refresh mode. (Applicable only to vision tracking function) + +- **Parameter:** + - `1`: open + - `0`: close + +- **Return value:** + - `1`: complete ### 3.MDI Mode and Operation @@ -120,13 +167,15 @@ mc.send_angle(1, 40, 20) | Joint Id | range | | ---- | ---- | | 1 | -170 ~ 170 | - | 2 | -120 ~ 120 | - | 3 | -148 ~ 148 | - | 4 | -120 ~ 135 | + | 2 | -137 ~ 137 | + | 3 | -151 ~ 142 | + | 4 | -148 ~ 148 | | 5 | -169 ~ 169 | | 6 | -180 ~ 180 | - `speed`:the speed and range of the robotic arm's movement 1~100 +- **Return value:** + - `1`: completed #### `send_angles(angles, speed)` @@ -134,6 +183,8 @@ mc.send_angle(1, 40, 20) - **Parameters:** - `angles`: a list of degree value(`List[float]`), length 6 - `speed`: (`int`) 1 ~ 100 +- **Return value:** + - `1`: completed #### `get_coords()` @@ -155,6 +206,8 @@ mc.send_angle(1, 40, 20) | ry | -180 ~ 180 | | rz | -180 ~ 180 | - `speed`: (`int`) 1-100 +- **Return value:** + - `1`: completed #### `send_coords(coords, speed, mode)` @@ -163,6 +216,8 @@ mc.send_angle(1, 40, 20) - coords: : a list of coords value `[x,y,z,rx,ry,rz]`,length6 - speed`(int)`: 1 ~ 100 - mode: `(int)` 0 - angluar, 1 - linear +- **Return value:** + - `1`: completed #### `pause()` @@ -172,20 +227,26 @@ mc.send_angle(1, 40, 20) - `0` - not stop - `-1` - error -#### `sync_send_angles(angles, speed)` +#### `sync_send_angles(angles, speed, timeout=15)` - **function:** Send the angle in synchronous state and return when the target point is reached - **Parameters:** - `angles`: a list of degree value(`List[float]`), length 6 - `speed`: (`int`) 1 ~ 100 + - `timeout`: default 15 s +- **Return value:** + - `1`: completed -#### `sync_send_coords(coords, mode, speed)` +#### `sync_send_coords(coords, speed, mode=0, timeout=15)` - **function:** Send the coord in synchronous state and return when the target point is reached - **Parameters:** - `coords`: a list of coord value(`List[float]`), length 6 - `speed`: (`int`) 1 ~ 100 - `mode`: (`int`) 0 - angular(default), 1 - linear + - `timeout`: default 15 s +- **Return value:** + - `1`: completed #### `get_angles_coords()` @@ -204,6 +265,8 @@ mc.send_angle(1, 40, 20) #### `resume()` - **function:** resume the robot movement and complete the previous command +- **Return value:** + - `1`: completed #### `stop()` @@ -243,6 +306,8 @@ mc.send_angle(1, 40, 20) - `joint_id`: Represents the joints of the robotic arm, represented by joint IDs ranging from 1 to 6 - `direction(int)`: To control the direction of movement of the robotic arm, input `0` as negative value movement and input `1` as positive value movement - `speed`: 1 ~ 100 +- **Return value:** + - `1`: completed #### `jog_coord(coord_id, direction, speed)` @@ -251,6 +316,8 @@ mc.send_angle(1, 40, 20) - `coord_id`: (`int`) Coordinate range of the robotic arm: 1~6 - `direction`: (`int`) To control the direction of machine arm movement, `0` - negative value movement, `1` - positive value movement - `speed`: 1 ~ 100 +- **Return value:** + - `1`: completed #### `jog_rpy(end_direction, direction, speed)` @@ -259,14 +326,28 @@ mc.send_angle(1, 40, 20) - `end_direction`: (`int`) Roll, Pitch, Yaw (1-3) - `direction`: (`int`) To control the direction of machine arm movement, `1` - forward rotation, `0` - reverse rotation - `speed`: (`int`) 1 ~ 100 +- **Return value:** + - `1`: completed -#### `jog_increment(joint_id, increment, speed)` +#### `jog_increment_angle(joint_id, increment, speed)` -- **function:** Single joint angle increment control +- **function:** Angle step, single joint angle increment control - **Parameters**: - `joint_id`: 1-6 - `increment`: Incremental movement based on the current position angle - `speed`: 1 ~ 100 +- **Return value:** + - `1`: completed + +#### `jog_increment_coord(id, increment, speed)` + +- **function:** Coord step, single coord increment control +- **Parameters**: + - `id`: axis 1-6 + - `increment`: Incremental movement based on the current position coord + - `speed`: 1 ~ 100 +- **Return value:** + - `1`: completed #### `set_encoder(joint_id, encoder, speed)` @@ -277,6 +358,8 @@ mc.send_angle(1, 40, 20) - `joint_id`: (`int`) 1-6 - `encoder`: 0 ~ 4096 - `speed`: 1 ~ 100 +- **Return value:** + - `1`: completed #### `get_encoder(joint_id)` @@ -297,6 +380,8 @@ mc.send_angle(1, 40, 20) - `joint_id`: (`int`) 1-6 - `encoder`: 0 ~ 4096 - `speed`: 1 ~ 100 +- **Return value:** + - `1`: completed #### `get_encoders()` @@ -326,6 +411,8 @@ mc.send_angle(1, 40, 20) - **Parameters:** - `id` : Enter joint ID (range 1-6) - `angle`: Refer to the limit information of the corresponding joint in the [send_angle()](#send_angleid-degree-speed) interface, which must not be less than the minimum value +- **Return value:** + - `1`: completed #### `set_joint_max(id, angle)` @@ -333,6 +420,8 @@ mc.send_angle(1, 40, 20) - **Parameters:** - `id` : Enter joint ID (range 1-6) - `angle`: Refer to the limit information of the corresponding joint in the [send_angle()](#send_angleid-degree-speed) interface, which must not be greater than the maximum value +- **Return value:** + - `1`: completed ### 6. Joint motor control @@ -358,6 +447,8 @@ mc.send_angle(1, 40, 20) - **function:** The current position of the calibration joint actuator is the angle zero point - **Parameters**: - `servo_id`: 1 - 6 +- **Return value:** + - `1`: completed #### `release_servo(servo_id)` @@ -368,6 +459,8 @@ mc.send_angle(1, 40, 20) - `1`: release successful - `0`: release failed - `-1`: error +- **Return value:** + - `1`: completed #### `focus_servo(servo_id)` @@ -386,6 +479,8 @@ mc.send_angle(1, 40, 20) - `data_id`: (`int`) Data address - `value`: (`int`) 0 - 4096 - `mode`: 0 - indicates that value is one byte(default), 1 - 1 represents a value of two bytes. +- **Return value:** + - `1`: completed #### `get_servo_data(servo_id, data_id, mode=None)` @@ -401,6 +496,8 @@ mc.send_angle(1, 40, 20) - **function:** Make it stop when the joint is in motion, and the buffer distance is positively related to the existing speed - **Parameters**: - `joint_id`: (`int`) joint id 1 - 6 +- **Return value:** + - `1`: completed ### 7. Servo state value @@ -424,6 +521,13 @@ mc.send_angle(1, 40, 20) - **function**:Get the movement status of all joints - **Return value**: A list,[voltage, sensor, temperature, current, angle, overload], a value of `0` means no error, a value of `1` indicates an error +- **Abnormal description**: + - 0: Servo motor undervoltage/overvoltage, check the voltage, if it is 0, you need to modify the servo parameters; if it is greater than the actual value, the heat sink may be damaged + - 1: Servo motor magnetic encoding abnormality + - 2: Servo motor overtemperature + - 3: Servo motor overcurrent + - 5: Servo motor overload + #### `get_servo_temps()` - **function**:Get joint temperature @@ -434,6 +538,8 @@ mc.send_angle(1, 40, 20) - **function:** Set void compensation mode - **Parameters**: - `mode`: (`int`) 0 - close, 1 - open +- **Return value:** + - `1`: completed ### 8. Robotic arm end IO control @@ -448,6 +554,8 @@ mc.send_angle(1, 40, 20) - `g (int)`: 0 ~ 255 - `b (int)`: 0 ~ 255 +- **Return value:** + - `1`: completed #### `set_digital_output(pin_no, pin_signal)` @@ -455,6 +563,8 @@ mc.send_angle(1, 40, 20) - **Parameters** - `pin_no` (int): Pin number - `pin_signal` (int): 0 / 1 +- **Return value:** + - `1`: completed #### `get_digital_input(pin_no)` @@ -468,6 +578,8 @@ mc.send_angle(1, 40, 20) - **Parameters** - `pin_no` (int): Pin number - `pin_mode` (int): 0 - input, 1 - output, 2 - input_pullup +- **Return value:** + - `1`: completed ### 9. Robotic arm end gripper control @@ -490,6 +602,8 @@ mc.send_angle(1, 40, 20) - `3` : Parallel gripper - `4` : Flexible gripper +- **Return value:** + - `1`: completed #### `set_gripper_value(gripper_value, speed, gripper_type=None)` @@ -510,26 +624,36 @@ mc.send_angle(1, 40, 20) - `3` : Parallel gripper - `4` : Flexible gripper +- **Return value:** + - `1`: completed #### `set_gripper_calibration()` - **function**: Set the current position of the gripper to zero +- **Return value:** + - `1`: completed #### `init_eletric_gripper()` - **function**: Electric gripper initialization (it needs to be initialized once after inserting and removing the gripper) +- **Return value:** + - `1`: completed #### `set_eletric_gripper(status)` - **function**: Set Electric Gripper Mode - **Parameters**: - `status`: 0 - open, 1 - close. +- **Return value:** + - `1`: completed #### `set_gripper_mode(mode)` - **function**: Set gripper mode - **Parameters**: - `mode`: 0 - transparent transmission. 1 - Port Mode. +- **Return value:** + - `1`: completed #### `get_gripper_mode()` @@ -545,6 +669,8 @@ mc.send_angle(1, 40, 20) - **Parameters**: - `pin_no` (`int`) Pin port number - `pin_signal` (`int`): 0 - low. 1 - high +- **Return value:** + - `1`: completed #### `get_basic_input(pin_no)` @@ -561,6 +687,8 @@ mc.send_angle(1, 40, 20) - **Parameters:** - `account` (`str`) new wifi account - `password` (`str`) new wifi password +- **Return value:** + - `1`: completed #### `get_ssid_pwd()` @@ -572,6 +700,8 @@ mc.send_angle(1, 40, 20) - **function:** Change the connection port of the server - **Parameters:** - `port` (`int`) The new connection port of the server. +- **Return value:** + - `1`: completed ### 12. TOF @@ -587,6 +717,8 @@ mc.send_angle(1, 40, 20) - **function:** Set tool coordinate system. - **Parameters**: - `coords`: (`list`) [x, y, z, rx, ry, rz]. +- **Return value:** + - `1`: completed #### `get_tool_reference(coords)` @@ -599,6 +731,8 @@ mc.send_angle(1, 40, 20) - **function:** Set world coordinate system. - **Parameters**: - `coords`: (`list`) [x, y, z, rx, ry, rz]. +- **Return value:** + - `1`: completed #### `get_world_reference()` @@ -610,6 +744,8 @@ mc.send_angle(1, 40, 20) - **function:** Set base coordinate system. - **Parameters:** - `rftype`: 0 - base 1 - tool. +- **Return value:** + - `1`: completed #### `get_reference_frame()` @@ -621,6 +757,8 @@ mc.send_angle(1, 40, 20) - **function:** Set movement type. - **Parameters**: - `move_type`: 1 - movel, 0 - moveJ. +- **Return value:** + - `1`: completed #### `get_movement_type()` @@ -634,6 +772,8 @@ mc.send_angle(1, 40, 20) - **function:** Set end coordinate system - **Parameters:** - `end (int)`: `0` - flange, `1` - tool +- **Return value:** + - `1`: completed #### `get_end_type()` @@ -678,6 +818,209 @@ from pymycobot import utils - **Return value:** Return the detected port number. If no serial port number is detected, it will return: None +### 16. Pro force-controlled gripper + +#### `set_pro_gripper(gripper_id, address, value)` + +- **Function**: Set the parameters of the Pro force-controlled gripper. You can set a variety of parameter functions. For details, please see the table below. +- **Parameter**: + - `gripper_id` (`int`): Gripper ID, default 14, value range 1 ~ 254. + - `address` (`int`): The command number of the gripper. + - `value`: The parameter value corresponding to the command number. + + | Function | gripper_id | address | value| + | ---- | ---- |---- |----- | + | Set gripper ID | 14 | 3 | 1 ~ 254 | + | Set gripper enable status | 14 | 10 | 0 or 1, 0 - off enable; 1 - on enable | + | Set gripper clockwise runnable error | 14 | 21 | 0 ~ 16 | + | Set gripper counterclockwise runnable error | 14 | 23 | 0 ~ 16 | + | Set gripper minimum starting force | 14 | 25 | 0 ~ 254 | + | IO output settings | 14 | 29 | 0, 1, 16, 17 | + | Set IO opening angle | 14 | 30 | 0 ~ 100 | + | Set IO closing angle | 14 | 31 | 0 ~ 100 | + | Set servo virtual position value | 14 | 41 | 0 ~ 100 | + | Set clamping current | 14 | 43 | 1 ~ 254 | + +- **Return value**: + - Please refer to the following table: + + | Function | return | + | ---- | ---- | + | Set gripper ID | 0 - Failure; 1 - Success | + | Set gripper enable status | 0 - Failure; 1 - Success | + | Set gripper clockwise runnable error | 0 - Failure; 1 - Success | + | Set gripper counterclockwise runnable error | 0 - Failure; 1 - Success | + | Set gripper minimum starting force | 0 - Failure; 1 - Success | + | IO output setting | 0 - Failure; 1 - Success | + | Set IO opening angle | 0 - Failure; 1 - Success | + | Set IO closing angle | 0 - Failed; 1 - Success | + | Set servo virtual position value | 0 - Failed; 1 - Success | + | Set holding current | 0 - Failed; 1 - Success | + +#### `get_pro_gripper(gripper_id, address)` + +- **Function**: Get the parameters of the Pro force-controlled gripper, and you can get a variety of parameter functions. For details, please see the table below. +- **Parameter**: + - `gripper_id` (`int`): Gripper ID, default 14, value range 1 ~ 254. + - `address` (`int`): The command number of the gripper. + + | Function | gripper_id | address | + | ---- | ---- |---- | + | Read firmware major version number | 14 | 1 | + | Read firmware minor version number | 14 | 2 | + | Read gripper ID | 14 | 3 | + | Read gripper clockwise runnable error | 14 | 22 | + | Read gripper counterclockwise runnable error | 14 | 24 | + | Read gripper minimum starting force | 14 | 26 | + | Read IO opening angle | 14 | 34 | + | Read IO closing angle | 14 | 35 | + | Get the amount of data in the current queue | 14 | 40 | + | Read servo virtual position value | 14 | 42 | + | Read the clamping current | 14 | 44 | + +- **Return value**: + - See the following table (if the return value is -1, it means that no data can be read): + + | Function | return | + | ---- | ---- | + | Read the firmware major version number | Major version number | + | Read the firmware minor version number | Minor version number | + | Read the gripper ID | 1 ~ 254 | + | Read the gripper clockwise runnable error | 0 ~ 254 | + | Read the gripper counterclockwise runnable error | 0 ~ 254 | + | Read the gripper minimum starting force | 0 ~ 254 | + | Read the IO opening angle | 0 ~ 100 | + | Read the IO closing angle | 0 ~ 100 | + | Get the amount of data in the current queue | Return the amount of data in the current absolute control queue | + | Read the servo virtual position value | 0 ~ 100 | + | Read the clamping current | 1 ~ 254 | + +#### `set_pro_gripper_angle(gripper_id, gripper_angle)` + +- **Function**: Set the force-controlled gripper angle. +- **Parameter**: + - `gripper_id` (`int`): Gripper ID, default 14, value range 1 ~ 254. + - `gripper_angle` (`int`): Gripper angle, value range 0 ~ 100. +- **Return value**: + - 0 - Failed + - 1 - Success + +#### `get_pro_gripper_angle(gripper_id)` + +- **Function**: Read the angle of the force-controlled gripper. +- **Parameter**: + - `gripper_id` (`int`): Gripper ID, default 14, value range 1 ~ 254. +- **Return value**: `int` 0 ~ 100 + +#### `set_pro_gripper_open(gripper_id)` + +- **Function**: Open the force-controlled gripper. +- **Parameter**: + - `gripper_id` (`int`): Gripper ID, default 14, value range 1 ~ 254. +- **Return value**: + - 0 - Failed + - 1 - Success + +#### `set_pro_gripper_close(gripper_id)` + +- **Function**: Close the force-controlled gripper. +- **Parameter**: + - `gripper_id` (`int`): Gripper ID, default 14, value range 1 ~ 254. +- **Return value**: + - 0 - Failed + - 1 - Success + +#### `set_pro_gripper_calibration(gripper_id)` + +- **Function**: Set the zero position of the force-controlled gripper. (The zero position needs to be set first when using it for the first time) +- **Parameter**: + - `gripper_id` (`int`): Gripper ID, default 14, value range 1 ~ 254. +- **Return value**: + - 0 - Failed + - 1 - Success + +#### `get_pro_gripper_status(gripper_id)` + +- **Function**: Read the gripping status of the force-controlled gripper. +- **Parameter**: + - `gripper_id` (`int`): Gripper ID, default 14, value range 1 ~ 254. +- **Return value:** + - `0` - Moving. + - `1` - Stopped moving, no object was detected. + - `2` - Stopped moving, object was detected. + - `3` - After the object was detected, it fell. + +#### `set_pro_gripper_torque(gripper_id, torque_value)` + +- **Function**: Set the torque of the force-controlled gripper. +- **Parameter**: + - `gripper_id` (`int`): Gripper ID, default 14, value range 1 ~ 254. + - `torque_value` (`int`): Torque value, value range 100 ~ 300. +- **Return value**: + - 0 - Failed + - 1 - Success + +#### `get_pro_gripper_torque(gripper_id)` + +- **Function**: Read the torque of the force-controlled gripper. +- **Parameter**: + - `gripper_id` (`int`): Gripper ID, default 14, value range 1 ~ 254. +- **Return value:** (`int`) 100 ~ 300 + +#### `set_pro_gripper_speed(gripper_id, speed)` + +- **Function**: Set the force-controlled gripper speed. +- **Parameter**: + - `gripper_id` (`int`): Gripper ID, default 14, value range 1 ~ 254. + - `speed` (int): Gripper movement speed, value range 1 ~ 100. +- **Return value**: + - 0 - Failed + - 1 - Success + +#### `get_pro_gripper_default_speed(gripper_id, speed)` + +- **Function**: Read the default speed of the force-controlled gripper. +- **Parameter**: + - `gripper_id` (`int`): Gripper ID, default 14, value range 1 ~ 254. +- **Return value**: Gripper default movement speed, range 1 ~ 100. + +#### `set_pro_gripper_abs_angle(gripper_id, gripper_angle)` + +- **Function**: Set the absolute angle of the force-controlled gripper. +- **Parameter**: + - `gripper_id` (`int`): Gripper ID, default 14, value range 1 ~ 254. + - `gripper_angle` (`int`): Gripper angle, value range 0 ~ 100. +- **Return value**: + - 0 - Failed + - 1 - Success + +#### `set_pro_gripper_pause(gripper_id)` + +- **Function**: Pause motion. +- **Parameter**: + - `gripper_id` (`int`) Gripper ID, default 14, value range 1 ~ 254. +- **Return value**: + - 0 - Failed + - 1 - Success + +#### `set_pro_gripper_resume(gripper_id)` + +- **Function**: Motion recovery. +- **Parameter**: + - `gripper_id` (`int`) Gripper ID, default 14, value range 1 ~ 254. +- **Return value**: + - 0 - Failed + - 1 - Success + +#### `set_pro_gripper_stop(gripper_id)` + +- **Function**: Stop motion. +- **Parameter**: + - `gripper_id` (`int`) Gripper ID, default 14, value range 1 ~ 254. +- **Return value**: + - 0 - Failed + - 1 - Success + ## MyCobot 320 Socket > Note: diff --git a/docs/MyCobot_320_zh.md b/docs/MyCobot_320_zh.md index c169870..acb5ac7 100644 --- a/docs/MyCobot_320_zh.md +++ b/docs/MyCobot_320_zh.md @@ -42,10 +42,14 @@ mc.send_angle(1, 40, 20) #### `power_on()` - **功能:** atom 打开通信(默认打开) +- **返回值:** + - `1`: 完成 #### `power_off()` - **功能:** 机械臂掉电 +- **返回值:** + - `1`: 完成 #### `is_power_on()` @@ -56,17 +60,21 @@ mc.send_angle(1, 40, 20) - `0`: 掉电 - `-1`: 错误 -#### `release_all_servos()` +#### `release_all_servos(data=None)` - **功能:** 放松所有机械臂关节 - **参数**:`data`(可选):关节放松方式,默认为阻尼模式,若提供 `data`参数可指定为非阻尼模式(1-Undamping)。 +- **返回值:** + - `1`: 完成 -#### `focus_servos(servo_id)` +#### `focus_servo(servo_id)` - **功能:** 单个舵机上电 - **参数:** -- `servo_id:` int, 1-6 + - `servo_id:` int, 1-6 +- **返回值:** + - `1`: 完成 #### `is_controller_connected()` @@ -92,8 +100,8 @@ mc.send_angle(1, 40, 20) - **功能:** 查询运动模式 - **返回值:** -- `0`: 插补模式 -- `1`: 刷新模式 + - `0`: 插补模式 + - `1`: 刷新模式 #### `set_fresh_mode()` @@ -102,6 +110,45 @@ mc.send_angle(1, 40, 20) - **参数:** - `1`: 总是首先执行最新的命令。 - `0`: 以队列的形式按顺序执行指令。 +- **返回值:** + - `1`: 完成 + +#### `get_robot_status()` + +- **功能:** 获取机器人自检状态,看重要参数是否都正常。 + +- **异常说明:** + - 0: 通信异常,请检查线路、舵机固件版本是否正常、电源是否插上、固件是否烧录正确,波特率是否正确等 + - 1: 伺服电机型号错误,需要更换电机 + - 2: 伺服电机固件版本较低,需要使用FD升级 + - 3: 伺服电机p值异常,默认32,此异常会自动恢复 + - 4: 伺服电机D值异常,默认8,此异常会自动恢复 + - 5: 伺服电机I值异常,默认0,此异常会自动恢复 + - 6: 伺服电机顺时针不灵敏区参数异常,默认3,此异常会自动恢复 + - 7: 伺服电机逆时针不灵敏区参数异常,默认3,此异常会自动恢复 + - 8: 伺服电机相位异常,此异常会自动恢复 + - 9: 伺服电机返回延时异常,默认0,此异常会自动恢复 + - 10: 伺服电机最小启动力异常,默认0,此异常会自动恢复 + - 11: 伺服电机异常,当舵机异常时,无法控制机器运动,请查询舵机反馈接口get_servo_status,查看具体报错 + - 255: 未知错误 + +#### `focus_all_servos()` + +- **功能:** 所有舵机上电 + +- **返回值:** +- `1`: complete + +#### `set_vision_mode()` + +- **功能:** 设置视觉跟踪模式,限制刷新模式下send_coords的姿态翻转。(仅适用于视觉跟踪功能) + +- **参数:** + - `1`: 打开 + - `0`: 关闭 + +- **返回值:** + - `1`: 完成 ### 3. MDI运行与操作 @@ -119,13 +166,15 @@ mc.send_angle(1, 40, 20) | 关节 Id | 范围 | | ---- | ---- | | 1 | -170 ~ 170 | - | 2 | -120 ~ 120 | - | 3 | -148 ~ 148 | - | 4 | -120 ~ 135 | + | 2 | -137 ~ 137 | + | 3 | -151 ~ 142 | + | 4 | -148 ~ 148 | | 5 | -169 ~ 169 | | 6 | -180 ~ 180 | - `speed`:机械臂运动速度及范围 1~100 +- **返回值:** + - `1`: 完成 #### `send_angles(angles, speed)` @@ -133,6 +182,8 @@ mc.send_angle(1, 40, 20) - **参数:** - `angles`:度数列表(`List[float]`),长度 6 - `speed`:(`int`)1 ~ 100 +- **返回值:** + - `1`: 完成 #### `get_coords()` @@ -154,6 +205,8 @@ mc.send_angle(1, 40, 20) | ry | -180 ~ 180 | | rz | -180 ~ 180 | - `speed`:(`int`)1-100 +- **返回值:** + - `1`: 完成 #### `send_coords(coords, speed, mode)` @@ -162,6 +215,8 @@ mc.send_angle(1, 40, 20) - `coords`: 坐标列表,值`[x,y,z,rx,ry,rz]`,长度6 - `speed` (`int`):1 ~ 100 - `mode:`(`int`) 0 - 非线性,1 - 直线运动 +- **返回值:** + - `1`: 完成 #### `pause()` @@ -171,20 +226,26 @@ mc.send_angle(1, 40, 20) - `0` - 没有停止 - `-1` - 错误 -#### `sync_send_angles(angles, speed)` +#### `sync_send_angles(angles, speed, timeout=15)` - **功能:** 同步状态下发送角度,到达目标点后返回 - **参数:** - `angles`:角度值列表(`List[float]`),长度 6 - `speed`:(`int`)1 ~ 100 + - `timeout`: 默认15秒 +- **返回值:** + - `1`: 完成 -#### `sync_send_coords(coords, mode, speed)` +#### `sync_send_coords(coords, speed, mode=0, timeout=15)` - **功能:** 同步状态下发送坐标,到达目标点后返回 - **参数:** - `coords`:坐标值列表(`List[float]`),长度6 - `speed`:(`int`)1~100 - `mode`:(`int`)0-非线性(默认),1-直线运动 + - `timeout`: 默认15秒 +- **返回值:** + - `1`: 完成 #### `get_angles_coords()` @@ -203,6 +264,8 @@ mc.send_angle(1, 40, 20) #### `resume()` - **功能:** 恢复机器人运动并完成上一个命令 +- **返回值:** + - `1`: 完成 #### `stop()` @@ -242,6 +305,8 @@ mc.send_angle(1, 40, 20) - `joint_id`:表示机械臂的关节,用关节ID表示,范围是1~6 - `direction(int)`:控制机械臂运动的方向,输入`0`为负值运动,输入`1`为正值运动 - `speed`:1~100 +- **返回值:** + - `1`: 完成 #### `jog_coord(coord_id, direction, speed)` @@ -250,6 +315,8 @@ mc.send_angle(1, 40, 20) - `coord_id`: (`int`) 机械臂坐标范围:1~6 - `direction`: (`int`) 控制机臂运动方向,`0` - 负值运动,`1` - 正值运动 - `speed`: 1 ~ 100 +- **返回值:** + - `1`: 完成 #### `jog_rpy(end_direction, direction, speed)` @@ -258,23 +325,37 @@ mc.send_angle(1, 40, 20) - `end_direction`: (`int`) Roll、Pitch、Yaw(1-3) - `direction`: (`int`) 控制机臂运动方向,`1` - 正转,`0` - 反转 - `speed`: (`int`) 1 ~ 100 +- **返回值:** + - `1`: 完成 -#### `jog_increment(joint_id, increment, speed)` +#### `jog_increment_angle(joint_id, increment, speed)` -- **功能**:单关节角度增量控制 +- **功能**:角度步进,单关节角度增量控制 - **参数**: -- `joint_id`:1-6 -- `increment`:基于当前位置角度的增量移动 -- `speed`:1~100 + - `joint_id`:1-6 + - `increment`:基于当前位置角度的增量移动 + - `speed`:1~100 +- **返回值:** + - `1`: 完成 + +#### `jog_increment_coord(id, increment, speed)` + +- **功能**:坐标步进,单坐标增量控制 +- **参数**: + - `id`:坐标 id 1-6 + - `increment`:基于当前位置坐标的增量移动 + - `speed`:1~100 +- **返回值**: +- `1`:完成 #### `set_encoder(joint_id,coder,speed)` - **功能**:设置单关节旋转为指定的潜在值 - **参数** - - `joint_id`:(`int`) 1-6 - - `encoder`:0~4096 - - `speed`:1~100 + - `joint_id`:(`int`) 1-6 + - `encoder`:0~4096 + - `speed`:1~100 #### `get_encoder(joint_id)` @@ -324,6 +405,8 @@ mc.send_angle(1, 40, 20) - **参数:** - `id` : 输入关节ID(范围1-6) - `angle`: 参考 [send_angle()](#send_angleid-degree-speed) 接口中对应关节的限制信息,不得小于最小值 +- **返回值:** + - `1`: 完成 #### `set_joint_max(id, angle)` @@ -331,6 +414,8 @@ mc.send_angle(1, 40, 20) - **参数:** - `id` :输入关节ID(范围1-6) - `angle`:参考 [send_angle()](#send_angleid-degree-speed) 接口中对应关节的限制信息,不得大于最大值 +- **返回值:** + - `1`: 完成 ### 6. 关节电机控制 @@ -356,6 +441,8 @@ mc.send_angle(1, 40, 20) - **功能:** 校准指定关节,设置当前位置为角度零点,对应电位值为2048 - **参数**: - `servo_id`: 1 - 6 +- **返回值:** + - `1`: 完成 #### `release_servo(servo_id)` @@ -384,6 +471,8 @@ mc.send_angle(1, 40, 20) - `data_id`: (`int`) 数据地址 - `value`: (`int`) 0 - 4096 - `mode`: 0 - 表示值为一个字节(默认),1 - 1 表示值为两个字节。 +- **返回值:** + - `1`: 完成 #### `get_servo_data(servo_id, data_id, mode=None)` @@ -399,6 +488,8 @@ mc.send_angle(1, 40, 20) - **功能:** 使关节在运动时停止,缓冲距离与现有速度正相关 - **参数**: - `joint_id`: (`int`) 关节id 1 - 6 +- **返回值:** + - `1`: 完成 ### 7. 伺服状态值 @@ -422,6 +513,13 @@ mc.send_angle(1, 40, 20) - **功能**:获取所有关节的运动状态 - **返回值**: 列表,[电压,传感器,温度,电流,角度,过载],值为`0`表示无错误,值为`1`表示有错误 +- **异常说明**: + - 0: 伺服电机欠压/过压,查看电压,如果为0,需要修改舵机参数;如果大于实际,可能散热片损坏 + - 1: 伺服电机磁编码异常 + - 2: 伺服电机过温 + - 3: 伺服电机过流 + - 5: 伺服电机过载 + #### `get_servo_temps()` - **功能**:获取关节温度 @@ -439,13 +537,17 @@ mc.send_angle(1, 40, 20) - `g (int)`: 0 ~ 255 - `b (int)`: 0 ~ 255 - + - **返回值:** + - `1`: 完成 + #### `set_digital_output(pin_no, pin_signal)` - **功能:** 设置IO状态 - **参数** - `pin_no` (int): 引脚号 - `pin_signal` (int): 0 / 1, 输入0表示设置为运行状态,输入1表示停止状态 +- **返回值:** + - `1`: 完成 #### `get_digital_input(pin_no)` @@ -459,6 +561,8 @@ mc.send_angle(1, 40, 20) - **参数** - `pin_no` (int): 引脚号 - `pin_mode` (int): 0 - 运行状态, 1 - 停止状态, 2 - 上拉模式 +- **返回值:** + - `1`: 完成 ### 9. 机械臂末端夹爪控制 @@ -481,6 +585,8 @@ mc.send_angle(1, 40, 20) - `3` : 平行夹爪 - `4` : 柔性夹爪 +- **返回值:** + - `1`: 完成 #### `set_gripper_value(gripper_value, speed, gripper_type=None)` @@ -501,26 +607,36 @@ mc.send_angle(1, 40, 20) - `3` : 平行夹爪 - `4` : 柔性夹爪 +- **返回值:** + - `1`: 完成 #### `set_gripper_calibration()` - **功能**: 将夹爪的当前位置设置为零位 +- **返回值:** + - `1`: 完成 #### `init_eletric_gripper()` - **功能**:电动夹爪初始化(插入和移除夹爪后需初始化一次) +- **返回值:** + - `1`: 完成 #### `set_eletric_gripper(status)` - **功能**:设置电动夹爪模式 - **参数**: - `status`:0 - 打开,1 - 关闭。 +- **返回值:** + - `1`: 完成 #### `set_gripper_mode(mode)` - **功能**:设置夹爪模式 - **参数**: - `mode`:0 - 透明传输。1 - 端口模式。 +- **返回值:** + - `1`: 完成 #### `get_gripper_mode()` @@ -536,6 +652,8 @@ mc.send_angle(1, 40, 20) - **参数**: - `pin_no` (`int`) 设备底部标注的编号仅取数字部分 - `pin_signal` (`int`): 0 - 低电平,设置为运行状态. 1 - 高电平,停止状态。 +- **返回值:** + - `1`: 完成 #### `get_basic_input(pin_no)` @@ -552,6 +670,8 @@ mc.send_angle(1, 40, 20) - **参数:** - `account`: (`str`) 新的 wifi 账户 - `password`: (`str`) 新的 wifi 密码 +- **返回值:** + - `1`: 完成 #### `get_ssid_pwd()` @@ -563,6 +683,8 @@ mc.send_angle(1, 40, 20) - **功能:** 更改服务器的连接端口 - **参数:** - `port`: (`int`) 服务器的新连接端口 +- **返回值:** + - `1`: 完成 ### 12. TOF @@ -578,6 +700,8 @@ mc.send_angle(1, 40, 20) - **功能:** 设置工具坐标系 - **参数**: - `coords`: (`list`) [x, y, z, rx, ry, rz]. +- **返回值:** + - `1`: 完成 #### `get_tool_reference(coords)` @@ -589,6 +713,8 @@ mc.send_angle(1, 40, 20) - **功能:** 设置世界坐标系 - **参数**: - `coords`: (`list`) [x, y, z, rx, ry, rz]. +- **返回值:** + - `1`: 完成 #### `get_world_reference()` @@ -600,6 +726,8 @@ mc.send_angle(1, 40, 20) - **功能:** 设置基坐标系 - **参数:** - `rftype`: 0 - 基坐标(默认) 1 - 世界坐标. +- **返回值:** + - `1`: 完成 #### `get_reference_frame()` @@ -611,6 +739,8 @@ mc.send_angle(1, 40, 20) - **功能:** 设置移动类型 - **参数**: - `move_type`: 1 - movel, 0 - moveJ. +- **返回值:** + - `1`: 完成 #### `get_movement_type()` @@ -624,6 +754,8 @@ mc.send_angle(1, 40, 20) - **功能:** 设置末端坐标系 - **参数:** - `end (int)`: `0` - 法兰(默认), `1` - 工具 +- **返回值:** + - `1`: 完成 #### `get_end_type()` @@ -668,6 +800,209 @@ from pymycobot import utils - **返回值:** 返回检测到的端口号,如果没有监测到串口号则返回:None +### 16. Pro 力控夹爪 + +#### `set_pro_gripper(gripper_id, address, value)` + +- **功能**:设置Pro力控夹爪参数,可以设置多种参数功能。具体请查看如下表格。 +- **参数**: + - `gripper_id` (`int`): 夹爪ID,默认14,取值范围 1 ~ 254。 + - `address` (`int`): 夹爪的指令序号。 + - `value` :指令序号对应的参数值。 + + | 功能 | gripper_id | address | value| + | ---- | ---- |---- |----- | + | 设置夹爪ID | 14 | 3 | 1 ~ 254 | + | 设置夹爪使能状态 | 14 | 10 | 0或者1, 0 - 掉使能; 1 - 上使能 | + | 设置夹爪顺时针可运行误差 | 14 | 21 | 0 ~ 16 | + | 设置夹爪逆时针可运行误差 | 14 | 23 | 0 ~ 16 | + | 设置夹爪最小启动力 | 14 | 25 | 0 ~ 254 | + | IO输出设置 | 14 | 29 | 0, 1, 16, 17 | + | 设置IO张开角度 | 14 | 30 | 0 ~ 100 | + | 设置IO闭合角度 | 14 | 31 | 0 ~ 100 | + | 设置舵机虚位数值 | 14 | 41 | 0 ~ 100 | + | 设置夹持电流 | 14 | 43 | 1 ~ 254 | + +- **返回值**: + - 请查看如下表格: + + | 功能 | return | + | ---- | ---- | + | 设置夹爪ID | 0 - 失败; 1 - 成功 | + | 设置夹爪使能状态 | 0 - 失败; 1 - 成功 | + | 设置夹爪顺时针可运行误差 | 0 - 失败; 1 - 成功 | + | 设置夹爪逆时针可运行误差 | 0 - 失败; 1 - 成功 | + | 设置夹爪最小启动力 | 0 - 失败; 1 - 成功 | + | IO输出设置 | 0 - 失败; 1 - 成功 | + | 设置IO张开角度 | 0 - 失败; 1 - 成功 | + | 设置IO闭合角度 | 0 - 失败; 1 - 成功 | + | 设置舵机虚位数值 | 0 - 失败; 1 - 成功 | + | 设置夹持电流 | 0 - 失败; 1 - 成功 | + +#### `get_pro_gripper(gripper_id, address)` + +- **功能**:获取Pro力控夹爪参数,可以获取多种参数功能。具体请查看如下表格。 +- **参数**: + - `gripper_id` (`int`): 夹爪ID,默认14,取值范围 1 ~ 254。 + - `address` (`int`): 夹爪的指令序号。 + + | 功能 | gripper_id | address | + | ---- | ---- |---- | + | 读取固件主版本号 | 14 | 1 | + | 读取固件次版本号 | 14 | 2 | + | 读取夹爪ID | 14 | 3 | + | 读取夹爪顺时针可运行误差 | 14 | 22 | + | 读取夹爪逆时针可运行误差 | 14 | 24 | + | 读取夹爪最小启动力 | 14 | 26 | + | 读取IO张开角度 | 14 | 34 | + | 读取IO闭合角度 | 14 | 35 | + | 获取当前队列的数据量 | 14 | 40 | + | 读取舵机虚位数值 | 14 | 42 | + | 读取夹持电流 | 14 | 44 | + +- **返回值**: + - 查看如下表格(若返回值为 -1,则表示读不到数据): + + | 功能 | return | + | ---- | ---- | + | 读取固件主版本号 | 主版本号 | + | 读取固件次版本号 | 次版本号 | + | 读取夹爪ID | 1 ~ 254 | + | 读取夹爪顺时针可运行误差 | 0 ~ 254 | + | 读取夹爪逆时针可运行误差 | 0 ~ 254 | + | 读取夹爪最小启动力 | 0 ~ 254 | + | 读取IO张开角度 | 0 ~ 100 | + | 读取IO闭合角度 | 0 ~ 100 | + | 获取当前队列的数据量 | 返回当前绝对控制队列中的数据量 | + | 读取舵机虚位数值 | 0 ~ 100 | + | 读取夹持电流 | 1 ~ 254 | + +#### `set_pro_gripper_angle(gripper_id, gripper_angle)` + +- **功能**:设置力控夹爪角度。 +- **参数**: + - `gripper_id` (`int`): 夹爪ID,默认14,取值范围1 ~ 254。 + - `gripper_angle` (`int`): 夹爪角度,取值范围 0 ~ 100。 +- **返回值**: + - 0 - 失败 + - 1 - 成功 + +#### `get_pro_gripper_angle(gripper_id)` + +- **功能**:读取力控夹爪角度。 +- **参数**: + - `gripper_id` (`int`): 夹爪ID,默认14,取值范围 1 ~ 254。 +- **返回值**:`int` 0 ~ 100 + +#### `set_pro_gripper_open(gripper_id)` + +- **功能**:打开力控夹爪。 +- **参数**: + - `gripper_id` (`int`): 夹爪ID,默认14,取值范围 1 ~ 254。 +- **返回值**: + - 0 - 失败 + - 1 - 成功 + +#### `set_pro_gripper_close(gripper_id)` + +- **功能**:关闭力控夹爪。 +- **参数**: + - `gripper_id` (`int`): 夹爪ID,默认14,取值范围 1 ~ 254。 +- **返回值**: + - 0 - 失败 + - 1 - 成功 + +#### `set_pro_gripper_calibration(gripper_id)` + +- **功能**:设置力控夹爪零位。(首次使用需要先设置零位) +- **参数**: + - `gripper_id` (`int`): 夹爪ID,默认14,取值范围 1 ~ 254。 +- **返回值**: + - 0 - 失败 + - 1 - 成功 + +#### `get_pro_gripper_status(gripper_id)` + +- **功能**:读取力控夹爪夹持状态。 +- **参数**: + - `gripper_id` (`int`): 夹爪ID,默认14,取值范围 1 ~ 254。 +- **返回值:** + - `0` - 正在运动。 + - `1` - 停止运动,未检测到夹到物体。 + - `2` - 停止运动,检测到夹到物体。 + - `3` - 检测到夹到物体之后,物体掉落。 + +#### `set_pro_gripper_torque(gripper_id, torque_value)` + +- **功能**:设置力控夹爪扭矩。 +- **参数**: + - `gripper_id` (`int`): 夹爪ID,默认14,取值范围 1 ~ 254。 + - `torque_value` (`int`) :扭矩值,取值范围 100 ~ 300。 +- **返回值**: + - 0 - 失败 + - 1 - 成功 + +#### `get_pro_gripper_torque(gripper_id)` + +- **功能**:读取力控夹爪扭矩。 +- **参数**: + - `gripper_id` (`int`): 夹爪ID,默认14,取值范围 1 ~ 254。 +- **返回值:** (`int`) 100 ~ 300 + +#### `set_pro_gripper_speed(gripper_id, speed)` + +- **功能**:设置力控夹爪速度。 +- **参数**: + - `gripper_id` (`int`): 夹爪ID,默认14,取值范围 1 ~ 254。 + - `speed` (int): 夹爪运动速度,取值范围 1 ~ 100。 +- **返回值**: + - 0 - 失败 + - 1 - 成功 + +#### `get_pro_gripper_default_speed(gripper_id, speed)` + +- **功能**:读取力控夹爪默认速度。 +- **参数**: + - `gripper_id` (`int`): 夹爪ID,默认14,取值范围 1 ~ 254。 +- **返回值**:夹爪默认运动速度,范围 1 ~ 100。 + +#### `set_pro_gripper_abs_angle(gripper_id, gripper_angle)` + +- **功能**:设置力控夹爪绝对角度。 +- **参数**: + - `gripper_id` (`int`): 夹爪ID,默认14,取值范围 1 ~ 254。 + - `gripper_angle` (`int`): 夹爪角度,取值范围 0 ~ 100。 +- **返回值**: + - 0 - 失败 + - 1 - 成功 + +#### `set_pro_gripper_pause(gripper_id)` + +- **功能**:暂停运动。 +- **参数**: + - `gripper_id` (`int`) 夹爪ID,默认14,取值范围 1 ~ 254。 +- **返回值**: + - 0 - 失败 + - 1 - 成功 + +#### `set_pro_gripper_resume(gripper_id)` + +- **功能**:运动恢复。 +- **参数**: + - `gripper_id` (`int`) 夹爪ID,默认14,取值范围 1 ~ 254。 +- **返回值**: + - 0 - 失败 + - 1 - 成功 + +#### `set_pro_gripper_stop(gripper_id)` + +- **功能**:停止运动。 +- **参数**: + - `gripper_id` (`int`) 夹爪ID,默认14,取值范围 1 ~ 254。 +- **返回值**: + - 0 - 失败 + - 1 - 成功 + ## MyCobot 320 Socket > 注意: diff --git a/pymycobot/__init__.py b/pymycobot/__init__.py index 647719f..d42aafa 100644 --- a/pymycobot/__init__.py +++ b/pymycobot/__init__.py @@ -85,7 +85,7 @@ from pymycobot.mybuddyemoticon import MyBuddyEmoticon __all__.append("MyBuddyEmoticon") -__version__ = "3.6.2" +__version__ = "3.6.3" __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 28c6232..bf8c3a9 100644 --- a/pymycobot/common.py +++ b/pymycobot/common.py @@ -63,6 +63,7 @@ class ProtocolCode(object): IS_FREE_MODE = 0x1B COBOTX_GET_ANGLE = 0x1C POWER_ON_ONLY = 0x1D + SET_VISION_MODE = 0x1D SET_CONTROL_MODE = 0x1E GET_CONTROL_MODE = 0x1F FOCUS_ALL_SERVOS = 0x18 @@ -791,7 +792,7 @@ def read(self, genre, method=None, command=None, _class=None, timeout=None): ProtocolCode.JOG_INCREMENT, ProtocolCode.JOG_INCREMENT_COORD, ProtocolCode.COBOTX_SET_SOLUTION_ANGLES]: wait_time = 300 - elif _class in ["MyCobot", "MyCobotSocket"]: + elif _class in ["MyCobot", "MyCobotSocket", "MyCobot320", "MyCobot320Socket"]: if genre == ProtocolCode.GET_ROBOT_STATUS: wait_time = 75 data = b"" diff --git a/pymycobot/error.py b/pymycobot/error.py index 5c2ea6a..dd34387 100644 --- a/pymycobot/error.py +++ b/pymycobot/error.py @@ -811,7 +811,7 @@ def calibration_parameters(**kwargs): raise MyCobot320DataException( "The range of 'gripper_id' in {} is 1 ~ 254, but the received value is {}".format(parameter, gripper_id)) - invalid_addresses = [1, 2, 4, 5, 6, 7, 8, 9, 11, 12, 13, 14, 16, 18, 20, 22, 24, 26, 27, 28, 32, 33, + invalid_addresses = [1, 2, 4, 5, 6, 7, 8, 9, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 22, 24, 26, 27, 28, 32, 33, 36, 37, 38, 39, 40, 42, 44] if address < 1 or address > 44: @@ -833,7 +833,7 @@ def calibration_parameters(**kwargs): raise MyCobot320DataException( "Error in parameter '{}': Value for address={} must be 0 or 1, but the received value is {}".format( parameter, address, data)) - elif address in [15, 17, 19, 25]: + elif address in [25]: if data < 0 or data > 254: raise MyCobot320DataException( "Error in parameter '{}': The range of 'value' for address={} is 0 ~ 254, but the received value is {}".format( @@ -858,7 +858,7 @@ def calibration_parameters(**kwargs): raise MyCobot320DataException( "The range of 'gripper_id' in {} is 1 ~ 254, but the received value is {}".format(parameter, gripper_id)) - invalid_addresses = [3, 5, 6, 10, 15, 17, 19, 21, 23, 25, 29, 30, 31, 34, 35, 41, 43] + invalid_addresses = [5, 6, 10, 15, 16, 17, 18, 19, 20, 21, 23, 25, 29, 30, 31, 34, 35, 41, 43] if address < 1 or address > 44: raise MyCobot320DataException( "The range of 'address' in {} is 1 ~ 44, but the received value is {}".format(parameter, diff --git a/pymycobot/generate.py b/pymycobot/generate.py index 50cb2f8..e7642ba 100644 --- a/pymycobot/generate.py +++ b/pymycobot/generate.py @@ -475,6 +475,12 @@ def focus_servo(self, servo_id): self.calibration_parameters(class_name=self.__class__.__name__, id=servo_id) return self._mesg(ProtocolCode.FOCUS_SERVO, servo_id) + def focus_all_servos(self): + """Power on all servo + + """ + return self._mesg(ProtocolCode.FOCUS_SERVO, 0) + # Atom IO def set_color(self, r=0, g=0, b=0): """Set the light color on the top of the robot arm. diff --git a/pymycobot/mecharm270.py b/pymycobot/mecharm270.py index a10271a..bb76c44 100644 --- a/pymycobot/mecharm270.py +++ b/pymycobot/mecharm270.py @@ -179,7 +179,7 @@ def _res(self, real_command, has_reply, genre): ProtocolCode.SET_FOUR_PIECES_ZERO ]: return self._process_single(res) - elif genre in [ProtocolCode.GET_ANGLES]: + elif genre in [ProtocolCode.GET_ANGLES, ProtocolCode.SOLVE_INV_KINEMATICS]: return [self._int2angle(angle) for angle in res] elif genre in [ProtocolCode.GET_COORDS, ProtocolCode.GET_TOOL_REFERENCE, ProtocolCode.GET_WORLD_REFERENCE]: if res: @@ -283,7 +283,7 @@ def sync_send_angles(self, degrees, speed, timeout=15): Args: degrees: a list of degree values(List[float]), length 6. speed: (int) 0 ~ 100 - timeout: default 7s. + timeout: default 15s. """ t = time.time() self.send_angles(degrees, speed) @@ -301,7 +301,7 @@ def sync_send_coords(self, coords, speed, mode=0, timeout=15): coords: a list of coord values(List[float]) speed: (int) 0 ~ 100 mode: (int): 0 - angular(default), 1 - linear - timeout: default 7s. + timeout: default 15s. """ t = time.time() self.send_coords(coords, speed, mode) @@ -345,6 +345,29 @@ def jog_rpy(self, end_direction, direction, speed): self.calibration_parameters(class_name=self.__class__.__name__, end_direction=end_direction, speed=speed) return self._mesg(ProtocolCode.JOG_ABSOLUTE, end_direction, direction, speed) + def jog_increment_angle(self, joint_id, increment, speed): + """ angle step mode + + Args: + joint_id: int 1-6. + increment: Angle increment value + speed: int (0 - 100) + """ + self.calibration_parameters(class_name=self.__class__.__name__, id=joint_id, speed=speed) + return self._mesg(ProtocolCode.JOG_INCREMENT, joint_id, [self._angle2int(increment)], speed) + + def jog_increment_coord(self, id, increment, speed): + """coord step mode + + Args: + id: axis id 1 - 6. + increment: Coord increment value + speed: int (1 - 100) + """ + self.calibration_parameters(class_name=self.__class__.__name__, id=id, speed=speed) + value = self._coord2int(increment) if id <= 3 else self._angle2int(increment) + return self._mesg(ProtocolCode.JOG_INCREMENT_COORD, id, [value], speed) + def set_HTS_gripper_torque(self, torque): """Set new adaptive gripper torque @@ -605,6 +628,46 @@ def get_end_type(self): """ return self._mesg(ProtocolCode.GET_END_TYPE, has_reply=True) + def angles_to_coords(self, angles): + """ Convert angles to coordinates + + Args: + angles : A float list of all angle. + + Return: + list: A float list of all coordinates. + """ + angles = [self._angle2int(angle) for angle in angles] + return self._mesg(ProtocolCode.GET_COORDS, angles, has_reply=True) + + def solve_inv_kinematics(self, target_coords, current_angles): + """ Convert target coordinates to angles + + Args: + target_coords: A float list of all coordinates. + current_angles : A float list of all angle. + + Return: + list: A float list of all angle. + """ + angles = [self._angle2int(angle) for angle in current_angles] + coord_list = [] + for idx in range(3): + coord_list.append(self._coord2int(target_coords[idx])) + for angle in target_coords[3:]: + coord_list.append(self._angle2int(angle)) + return self._mesg(ProtocolCode.SOLVE_INV_KINEMATICS, coord_list, angles, has_reply=True) + + def set_vision_mode(self, flag): + """Set the visual tracking mode to limit the posture flipping of send_coords in refresh mode. + (Only for visual tracking function) + + Args: + flag: 0/1; 0 - close; 1 - open + """ + self.calibration_parameters(class_name=self.__class__.__name__, flag=flag) + return self._mesg(ProtocolCode.SET_VISION_MODE, flag) + # Other def wait(self, t): time.sleep(t) diff --git a/pymycobot/mecharmsocket.py b/pymycobot/mecharmsocket.py index 1de2b0d..300cd1c 100644 --- a/pymycobot/mecharmsocket.py +++ b/pymycobot/mecharmsocket.py @@ -175,7 +175,7 @@ def _mesg(self, genre, *args, **kwargs): ProtocolCode.SET_FOUR_PIECES_ZERO ]: return self._process_single(res) - elif genre in [ProtocolCode.GET_ANGLES]: + elif genre in [ProtocolCode.GET_ANGLES, ProtocolCode.SOLVE_INV_KINEMATICS]: return [self._int2angle(angle) for angle in res] elif genre in [ProtocolCode.GET_COORDS, ProtocolCode.GET_TOOL_REFERENCE, ProtocolCode.GET_WORLD_REFERENCE]: if res: @@ -281,7 +281,7 @@ def sync_send_angles(self, degrees, speed, timeout=15): Args: degrees: a list of degree values(List[float]), length 6. speed: (int) 0 ~ 100 - timeout: default 7s. + timeout: default 15s. """ t = time.time() self.send_angles(degrees, speed) @@ -299,7 +299,7 @@ def sync_send_coords(self, coords, speed, mode=0, timeout=15): coords: a list of coord values(List[float]) speed: (int) 0 ~ 100 mode: (int): 0 - angular(default), 1 - linear - timeout: default 7s. + timeout: default 15s. """ t = time.time() self.send_coords(coords, speed, mode) @@ -325,6 +325,29 @@ def jog_rpy(self, end_direction, direction, speed): self.calibration_parameters(class_name=self.__class__.__name__, end_direction=end_direction, speed=speed) return self._mesg(ProtocolCode.JOG_ABSOLUTE, end_direction, direction, speed) + def jog_increment_angle(self, joint_id, increment, speed): + """ angle step mode + + Args: + joint_id: int 1-6. + increment: Angle increment value + speed: int (0 - 100) + """ + self.calibration_parameters(class_name=self.__class__.__name__, id=joint_id, speed=speed) + return self._mesg(ProtocolCode.JOG_INCREMENT, joint_id, [self._angle2int(increment)], speed) + + def jog_increment_coord(self, id, increment, speed): + """coord step mode + + Args: + id: axis id 1 - 6. + increment: Coord increment value + speed: int (1 - 100) + """ + self.calibration_parameters(class_name=self.__class__.__name__, id=id, speed=speed) + value = self._coord2int(increment) if id <= 3 else self._angle2int(increment) + return self._mesg(ProtocolCode.JOG_INCREMENT_COORD, id, [value], speed) + def set_HTS_gripper_torque(self, torque): """Set new adaptive gripper torque @@ -622,6 +645,46 @@ def get_gpio_in(self, pin_no): """ return self._mesg(ProtocolCode.GET_GPIO_IN, pin_no, has_reply=True) + def angles_to_coords(self, angles): + """ Convert angles to coordinates + + Args: + angles : A float list of all angle. + + Return: + list: A float list of all coordinates. + """ + angles = [self._angle2int(angle) for angle in angles] + return self._mesg(ProtocolCode.GET_COORDS, angles, has_reply=True) + + def solve_inv_kinematics(self, target_coords, current_angles): + """ Convert target coordinates to angles + + Args: + target_coords: A float list of all coordinates. + current_angles : A float list of all angle. + + Return: + list: A float list of all angle. + """ + angles = [self._angle2int(angle) for angle in current_angles] + coord_list = [] + for idx in range(3): + coord_list.append(self._coord2int(target_coords[idx])) + for angle in target_coords[3:]: + coord_list.append(self._angle2int(angle)) + return self._mesg(ProtocolCode.SOLVE_INV_KINEMATICS, coord_list, angles, has_reply=True) + + def set_vision_mode(self, flag): + """Set the visual tracking mode to limit the posture flipping of send_coords in refresh mode. + (Only for visual tracking function) + + Args: + flag: 0/1; 0 - close; 1 - open + """ + self.calibration_parameters(class_name=self.__class__.__name__, flag=flag) + return self._mesg(ProtocolCode.SET_VISION_MODE, flag) + # Other def wait(self, t): time.sleep(t) diff --git a/pymycobot/myagv.py b/pymycobot/myagv.py index e3bf3f0..ad6ba7e 100644 --- a/pymycobot/myagv.py +++ b/pymycobot/myagv.py @@ -12,6 +12,7 @@ class ProtocolCode(enum.Enum): HEADER = 0xFE RESTORE = [0x01, 0x00] SET_LED = [0x01, 0x02] + SET_LED_MODE = [0x01, 0x0A] GET_FIRMWARE_VERSION = [0x01, 0x03] GET_MOTORS_CURRENT = [0x01, 0x04] GET_BATTERY_INFO = [0x01, 0x05] @@ -123,7 +124,6 @@ def _mesg(self, genre, *args, **kwargs): elif genre == ProtocolCode.GET_BATTERY_INFO.value: command.append(6) else: - # del command[2] command.append(sum(command[2:]) & 0xff) self._write(command) if has_reply: @@ -162,6 +162,16 @@ def set_led(self, mode, R, G, B): calibration_parameters(class_name=self.__class__.__name__, rgb=[R, G, B], led_mode=mode) return self._mesg(ProtocolCode.SET_LED.value, mode, R, G, B) + def set_led_mode(self, mode: int): + """Set the LED light mode + + Args: + mode (int): 0 - charging mode, 1 - DIY mode + """ + if mode not in [0, 1]: + raise ValueError("mode must be 0 or 1") + return self._mesg(ProtocolCode.SET_LED_MODE.value, mode) + def get_firmware_version(self): """Get firmware version number """ @@ -195,9 +205,11 @@ def get_battery_info(self): def __basic_move_control(self, *genre, timeout: int = 5): t = time.time() self.__movement = True - while time.time() - t < timeout and self.__movement is True: + while time.time() - t < timeout: + if self.__movement is False: + break self._mesg(*genre) - time.sleep(0.05) + time.sleep(0.1) self.stop() def go_ahead(self, speed: int, timeout: int = 5): @@ -238,7 +250,7 @@ def pan_left(self, speed, timeout=5): """ if not (0 < speed < 128): raise ValueError("pan_left_speed must be between 1 and 127") - self.__basic_move_control(128, 128, 128 + speed, timeout=timeout) + self.__basic_move_control(128, 128 + speed, 128, timeout=timeout) def pan_right(self, speed: int, timeout=5): """ @@ -280,9 +292,8 @@ def counterclockwise_rotation(self, speed: int, timeout=5): def stop(self): """stop-motion""" - if self.__movement is True: - self._mesg(128, 128, 128) - self.__movement = False + self.__movement = False + self._mesg(128, 128, 128) def get_mcu_info(self, version: float = None) -> list: """ @@ -386,12 +397,3 @@ def get_gyro_state(self): def get_modified_version(self): return self._mesg(ProtocolCode.GET_MODIFIED_VERSION.value, has_reply=True) - - # def get_battery_voltage(self, num=1): - # """Get battery voltage - - # Args: - # num (int, optional): Battery ID number. Defaults to 1. - # """ - # mcu_data = self.get_mcu_info() - # return self._mesg(ProtocolCode.GET_BATTERY_INFO.value, has_reply = True) diff --git a/pymycobot/mycobot280.py b/pymycobot/mycobot280.py index 3d11f31..ef51d5b 100644 --- a/pymycobot/mycobot280.py +++ b/pymycobot/mycobot280.py @@ -183,7 +183,7 @@ def _res(self, real_command, has_reply, genre): ProtocolCode.SET_FOUR_PIECES_ZERO ]: return self._process_single(res) - elif genre in [ProtocolCode.GET_ANGLES]: + elif genre in [ProtocolCode.GET_ANGLES, ProtocolCode.SOLVE_INV_KINEMATICS]: return [self._int2angle(angle) for angle in res] elif genre in [ProtocolCode.GET_COORDS, ProtocolCode.GET_TOOL_REFERENCE, ProtocolCode.GET_WORLD_REFERENCE]: if res: @@ -304,7 +304,7 @@ def sync_send_angles(self, degrees, speed, timeout=15): Args: degrees: a list of degree values(List[float]), length 6. speed: (int) 0 ~ 100 - timeout: default 7s. + timeout: default 15s. """ t = time.time() self.send_angles(degrees, speed) @@ -322,7 +322,7 @@ def sync_send_coords(self, coords, speed, mode=0, timeout=15): coords: a list of coord values(List[float]) speed: (int) 0 ~ 100 mode: (int): 0 - angular(default), 1 - linear - timeout: default 7s. + timeout: default 15s. """ t = time.time() self.send_coords(coords, speed, mode) @@ -366,6 +366,29 @@ def jog_rpy(self, end_direction, direction, speed): self.calibration_parameters(class_name=self.__class__.__name__, end_direction=end_direction, speed=speed) return self._mesg(ProtocolCode.JOG_ABSOLUTE, end_direction, direction, speed) + def jog_increment_angle(self, joint_id, increment, speed): + """ angle step mode + + Args: + joint_id: int 1-6. + increment: Angle increment value + speed: int (0 - 100) + """ + self.calibration_parameters(class_name=self.__class__.__name__, id=joint_id, speed=speed) + return self._mesg(ProtocolCode.JOG_INCREMENT, joint_id, [self._angle2int(increment)], speed) + + def jog_increment_coord(self, id, increment, speed): + """coord step mode + + Args: + id: axis id 1 - 6. + increment: Coord increment value + speed: int (1 - 100) + """ + self.calibration_parameters(class_name=self.__class__.__name__, id=id, speed=speed) + value = self._coord2int(increment) if id <= 3 else self._angle2int(increment) + return self._mesg(ProtocolCode.JOG_INCREMENT_COORD, id, [value], speed) + def set_HTS_gripper_torque(self, torque): """Set new adaptive gripper torque @@ -638,6 +661,46 @@ def get_end_type(self): """ return self._mesg(ProtocolCode.GET_END_TYPE, has_reply=True) + def angles_to_coords(self, angles): + """ Convert angles to coordinates + + Args: + angles : A float list of all angle. + + Return: + list: A float list of all coordinates. + """ + angles = [self._angle2int(angle) for angle in angles] + return self._mesg(ProtocolCode.GET_COORDS, angles, has_reply=True) + + def solve_inv_kinematics(self, target_coords, current_angles): + """ Convert target coordinates to angles + + Args: + target_coords: A float list of all coordinates. + current_angles : A float list of all angle. + + Return: + list: A float list of all angle. + """ + angles = [self._angle2int(angle) for angle in current_angles] + coord_list = [] + for idx in range(3): + coord_list.append(self._coord2int(target_coords[idx])) + for angle in target_coords[3:]: + coord_list.append(self._angle2int(angle)) + return self._mesg(ProtocolCode.SOLVE_INV_KINEMATICS, coord_list, angles, has_reply=True) + + def set_vision_mode(self, flag): + """Set the visual tracking mode to limit the posture flipping of send_coords in refresh mode. + (Only for visual tracking function) + + Args: + flag: 0/1; 0 - close; 1 - open + """ + self.calibration_parameters(class_name=self.__class__.__name__, flag=flag) + return self._mesg(ProtocolCode.SET_VISION_MODE, flag) + # Other def wait(self, t): time.sleep(t) diff --git a/pymycobot/mycobot280socket.py b/pymycobot/mycobot280socket.py index 1760517..c0a5b0f 100644 --- a/pymycobot/mycobot280socket.py +++ b/pymycobot/mycobot280socket.py @@ -181,7 +181,7 @@ def _mesg(self, genre, *args, **kwargs): ProtocolCode.SET_FOUR_PIECES_ZERO ]: return self._process_single(res) - elif genre in [ProtocolCode.GET_ANGLES]: + elif genre in [ProtocolCode.GET_ANGLES, ProtocolCode.SOLVE_INV_KINEMATICS]: return [self._int2angle(angle) for angle in res] elif genre in [ProtocolCode.GET_COORDS, ProtocolCode.GET_TOOL_REFERENCE, ProtocolCode.GET_WORLD_REFERENCE]: if res: @@ -303,7 +303,7 @@ def sync_send_angles(self, degrees, speed, timeout=15): Args: degrees: a list of degree values(List[float]), length 6. speed: (int) 0 ~ 100 - timeout: default 7s. + timeout: default 15s. """ t = time.time() self.send_angles(degrees, speed) @@ -321,7 +321,7 @@ def sync_send_coords(self, coords, speed, mode=0, timeout=15): coords: a list of coord values(List[float]) speed: (int) 0 ~ 100 mode: (int): 0 - angular(default), 1 - linear - timeout: default 7s. + timeout: default 15s. """ t = time.time() self.send_coords(coords, speed, mode) @@ -365,6 +365,29 @@ def jog_rpy(self, end_direction, direction, speed): self.calibration_parameters(class_name=self.__class__.__name__, end_direction=end_direction, speed=speed) return self._mesg(ProtocolCode.JOG_ABSOLUTE, end_direction, direction, speed) + def jog_increment_angle(self, joint_id, increment, speed): + """ angle step mode + + Args: + joint_id: int 1-6. + increment: Angle increment value + speed: int (0 - 100) + """ + self.calibration_parameters(class_name=self.__class__.__name__, id=joint_id, speed=speed) + return self._mesg(ProtocolCode.JOG_INCREMENT, joint_id, [self._angle2int(increment)], speed) + + def jog_increment_coord(self, id, increment, speed): + """coord step mode + + Args: + id: axis id 1 - 6. + increment: Coord increment value + speed: int (1 - 100) + """ + self.calibration_parameters(class_name=self.__class__.__name__, id=id, speed=speed) + value = self._coord2int(increment) if id <= 3 else self._angle2int(increment) + return self._mesg(ProtocolCode.JOG_INCREMENT_COORD, id, [value], speed) + def set_HTS_gripper_torque(self, torque): """Set new adaptive gripper torque @@ -674,6 +697,46 @@ def get_gpio_in(self, pin_no): """ return self._mesg(ProtocolCode.GET_GPIO_IN, pin_no, has_reply=True) + def angles_to_coords(self, angles): + """ Convert angles to coordinates + + Args: + angles : A float list of all angle. + + Return: + list: A float list of all coordinates. + """ + angles = [self._angle2int(angle) for angle in angles] + return self._mesg(ProtocolCode.GET_COORDS, angles, has_reply=True) + + def solve_inv_kinematics(self, target_coords, current_angles): + """ Convert target coordinates to angles + + Args: + target_coords: A float list of all coordinates. + current_angles : A float list of all angle. + + Return: + list: A float list of all angle. + """ + angles = [self._angle2int(angle) for angle in current_angles] + coord_list = [] + for idx in range(3): + coord_list.append(self._coord2int(target_coords[idx])) + for angle in target_coords[3:]: + coord_list.append(self._angle2int(angle)) + return self._mesg(ProtocolCode.SOLVE_INV_KINEMATICS, coord_list, angles, has_reply=True) + + def set_vision_mode(self, flag): + """Set the visual tracking mode to limit the posture flipping of send_coords in refresh mode. + (Only for visual tracking function) + + Args: + flag: 0/1; 0 - close; 1 - open + """ + self.calibration_parameters(class_name=self.__class__.__name__, flag=flag) + return self._mesg(ProtocolCode.SET_VISION_MODE, flag) + # Other def wait(self, t): time.sleep(t) diff --git a/pymycobot/mycobot320.py b/pymycobot/mycobot320.py index 1bc8589..55d9eff 100644 --- a/pymycobot/mycobot320.py +++ b/pymycobot/mycobot320.py @@ -61,6 +61,7 @@ class MyCobot320(CommandGenerator): get_servo_temps() get_servo_last_pdi() set_void_compensate() + get_robot_status() # Coordinate transformation set_tool_reference() @@ -286,7 +287,7 @@ def sync_send_angles(self, degrees, speed, timeout=15): Args: degrees: a list of degree values(List[float]), length 6. speed: (int) 0 ~ 100 - timeout: default 7s. + timeout: default 15s. """ t = time.time() self.send_angles(degrees, speed) @@ -304,7 +305,7 @@ def sync_send_coords(self, coords, speed, mode=0, timeout=15): coords: a list of coord values(List[float]) speed: (int) 0 ~ 100 mode: (int): 0 - angular(default), 1 - linear - timeout: default 7s. + timeout: default 15s. """ t = time.time() self.send_coords(coords, speed, mode) @@ -330,6 +331,29 @@ def jog_rpy(self, end_direction, direction, speed): self.calibration_parameters(class_name=self.__class__.__name__, end_direction=end_direction, speed=speed) return self._mesg(ProtocolCode.JOG_ABSOLUTE, end_direction, direction, speed) + def jog_increment_angle(self, joint_id, increment, speed): + """ angle step mode + + Args: + joint_id: int 1-6. + increment: Angle increment value + speed: int (0 - 100) + """ + self.calibration_parameters(class_name=self.__class__.__name__, id=joint_id, speed=speed) + return self._mesg(ProtocolCode.JOG_INCREMENT, joint_id, [self._angle2int(increment)], speed) + + def jog_increment_coord(self, id, increment, speed): + """coord step mode + + Args: + id: axis id 1 - 6. + increment: Coord increment value + speed: int (1 - 100) + """ + self.calibration_parameters(class_name=self.__class__.__name__, id=id, speed=speed) + value = self._coord2int(increment) if id <= 3 else self._angle2int(increment) + return self._mesg(ProtocolCode.JOG_INCREMENT_COORD, id, [value], speed) + # Basic for raspberry pi. def gpio_init(self): """Init GPIO module, and set BCM mode.""" @@ -687,7 +711,7 @@ def get_pro_gripper_default_speed(self, gripper_id): return self.get_pro_gripper(gripper_id, ProGripper.GET_GRIPPER_DEFAULT_SPEED) def set_pro_gripper_abs_angle(self, gripper_id, gripper_angle): - """ Set the gripper speed + """ Set the gripper absolute angle Args: gripper_id (int): 1 ~ 254 @@ -731,6 +755,21 @@ def get_atom_version(self): """ return self._mesg(ProtocolCode.GET_ATOM_VERSION, has_reply=True) + def get_robot_status(self): + """Get robot status + """ + return self._mesg(ProtocolCode.GET_ROBOT_STATUS, has_reply=True) + + def set_vision_mode(self, flag): + """Set the visual tracking mode to limit the posture flipping of send_coords in refresh mode. + (Only for visual tracking function) + + Args: + flag: 0/1; 0 - close; 1 - open + """ + self.calibration_parameters(class_name=self.__class__.__name__, flag=flag) + return self._mesg(ProtocolCode.SET_VISION_MODE, flag) + # Other def wait(self, t): time.sleep(t) diff --git a/pymycobot/mycobot320socket.py b/pymycobot/mycobot320socket.py index 0e8b10d..e2120ee 100644 --- a/pymycobot/mycobot320socket.py +++ b/pymycobot/mycobot320socket.py @@ -60,6 +60,7 @@ class MyCobot320Socket(CommandGenerator): get_servo_temps() get_servo_last_pdi() set_void_compensate() + get_robot_status() # Coordinate transformation set_tool_reference() @@ -286,7 +287,7 @@ def sync_send_angles(self, degrees, speed, timeout=15): Args: degrees: a list of degree values(List[float]), length 6. speed: (int) 0 ~ 100 - timeout: default 7s. + timeout: default 15s. """ t = time.time() self.send_angles(degrees, speed) @@ -304,7 +305,7 @@ def sync_send_coords(self, coords, speed, mode=0, timeout=15): coords: a list of coord values(List[float]) speed: (int) 0 ~ 100 mode: (int): 0 - angular(default), 1 - linear - timeout: default 7s. + timeout: default 15s. """ t = time.time() self.send_coords(coords, speed, mode) @@ -330,6 +331,29 @@ def jog_rpy(self, end_direction, direction, speed): self.calibration_parameters(class_name=self.__class__.__name__, end_direction=end_direction, speed=speed) return self._mesg(ProtocolCode.JOG_ABSOLUTE, end_direction, direction, speed) + def jog_increment_angle(self, joint_id, increment, speed): + """ angle step mode + + Args: + joint_id: int 1-6. + increment: Angle increment value + speed: int (0 - 100) + """ + self.calibration_parameters(class_name=self.__class__.__name__, id=joint_id, speed=speed) + return self._mesg(ProtocolCode.JOG_INCREMENT, joint_id, [self._angle2int(increment)], speed) + + def jog_increment_coord(self, id, increment, speed): + """coord step mode + + Args: + id: axis id 1 - 6. + increment: Coord increment value + speed: int (1 - 100) + """ + self.calibration_parameters(class_name=self.__class__.__name__, id=id, speed=speed) + value = self._coord2int(increment) if id <= 3 else self._angle2int(increment) + return self._mesg(ProtocolCode.JOG_INCREMENT_COORD, id, [value], speed) + # Basic for raspberry pi. def gpio_init(self): """Init GPIO module, and set BCM mode.""" @@ -723,7 +747,7 @@ def get_pro_gripper_default_speed(self, gripper_id): return self.get_pro_gripper(gripper_id, ProGripper.GET_GRIPPER_DEFAULT_SPEED) def set_pro_gripper_abs_angle(self, gripper_id, gripper_angle): - """ Set the gripper speed + """ Set the gripper absolute angle Args: gripper_id (int): 1 ~ 254 @@ -767,6 +791,21 @@ def get_atom_version(self): """ return self._mesg(ProtocolCode.GET_ATOM_VERSION, has_reply=True) + def get_robot_status(self): + """Get robot status + """ + return self._mesg(ProtocolCode.GET_ROBOT_STATUS, has_reply=True) + + def set_vision_mode(self, flag): + """Set the visual tracking mode to limit the posture flipping of send_coords in refresh mode. + (Only for visual tracking function) + + Args: + flag: 0/1; 0 - close; 1 - open + """ + self.calibration_parameters(class_name=self.__class__.__name__, flag=flag) + return self._mesg(ProtocolCode.SET_VISION_MODE, flag) + # Other def wait(self, t): time.sleep(t)