MyCobot 280
[toc]
Python API usage instaructions
API (Application Programming Interface), also known as Application Programming Interface functions, are predefined functions. When using the following function interfaces, please import our API library at the beginning by entering the following code, otherwise it will not run successfully:
# Example
from pymycobot import MyCobot280
mc = MyCobot280('COM3')
# Gets the current angle of all joints
angles = mc.get_angles()
print(angles)
# Set 1 joint to move to 40 and speed to 20
mc.send_angle(1, 40, 20)
Arduino UNO Q Connection Modes
When using myCobot 280 with Arduino UNO Q, choose the initialization method according to where the Python program runs.
| Python Runtime Location | Recommended Class | Communication Path |
|---|---|---|
| PC / host computer | MyCobot280Socket |
PC TCP -> UNO Q socket server -> XferBridgeMsg -> firmware |
| UNO Q Debian / App Lab | MyCobot280 |
Python Bridge RPC -> XferBridgeMsg -> firmware |
The UNO Q firmware side does not instantiate pymycobot directly. The firmware only needs to provide XferBridgeMsg; the Python program runs on either the PC or the UNO Q Linux/App Lab environment.
Local Control on UNO Q Debian / App Lab
When the Python program runs in the UNO Q Debian or App Lab environment, use Bridge RPC mode:
from pymycobot import MyCobot280
mc = MyCobot280(unoq_bridge=True)
print(mc.get_system_version())
print(mc.get_angles())
mc.send_angle(5, 0, 60)
- When
unoq_bridge=True, the library does not open or check the/dev/mycobotserial device. baudrateis optional and defaults to1000000; pass it explicitly only when overriding the default.timeoutis specified in seconds and is converted to milliseconds for Bridge RPC.- This mode requires
arduino.app_utils.Bridgein the UNO Q environment. Do not enable it on a normal PC environment where this module is not installed. - The firmware must provide
XferBridgeMsg(frame_hex, timeout_ms, baudrate)and transparently pass through myCobot protocol frames. - Firmware response
FE FE 03 5B 01 FAmeans timeout, andFE FE 03 5B 02 FAmeans partial frame. Whendebug=Trueis enabled,_bridge_errorand the raw frame are written to the log.
Normally, only unoq_bridge=True is required for initialization. In Bridge mode, the port argument is kept only for compatibility with existing code and is not used to access a serial device.
Remote TCP Control from a PC
When the Python program runs on a PC and the robot is connected to UNO Q, start the socket server on UNO Q and use MyCobot280Socket on the PC:
from pymycobot import MyCobot280Socket
mc = MyCobot280Socket("192.168.1.218", 9000, timeout=1.0)
print(mc.get_angles())
mc.send_angle(5, 0, 60)
The UNO Q socket server example is Server_280_UNOQ.py. It uses XferBridgeMsg internally to communicate with the firmware. The PC client still sends and receives the original myCobot protocol frames, so the upper-level API remains the same as normal MyCobot280Socket usage.
In TCP mode, firmware timeout or partial-frame responses are also logged by the UNO Q socket server as _bridge_error with the raw error frame for field diagnostics.
1. System Status
get_modify_version()
Function: Check the robot correction version
Return value: Corrected version number
clear_queue()
Function: Clear the queue data
Return value: 1
check_async_or_sync()
Function: Check whether it is synchronous or asynchronous
Return value:
1: synchronous0: asynchronous
get_system_version()
- function: get system version
- Return value: system version
get_basic_version()
- function: Get basic firmware version for M5 version
- Return value:
floatfirmware version
get_error_information()
function: Obtaining robot error information
Return value:
- 0: No error message.
- 1 ~ 6: The corresponding joint exceeds the limit position.
- 16 ~ 19: Collision protection.
- 32: Kinematics inverse solution has no solution.
- 33 ~ 34: Linear motion has no adjacent solution.
clear_error_information()
- function: Clear robot error message
get_reboot_count()
- function: Get the number of times the machine has been restarted (calculated from the time the firmware is burned)
- Return value:
intNumber of restarts
2. Overall Status
power_on()
function: atom open communication (default open)
Return value:
1- Power on completed.
power_off()
function: Power off of the robotic arm
Return value:
1- Power on completed.
is_power_on()
function: judge whether robot arms is powered on or not
Return value:
1: power on0: power off-1: error
release_all_servos()
- 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- release completed.
focus_servo(servo_id)
function: Power on designated servo
Parameters:
servo_id:int, 1-6
Return value:
1: complete
is_controller_connected()
function: Wether connected with Atom
Return value:
1: succeed0: failed-1: error data
read_next_error()
function: Robot Error Detection
Return value: list len 6
0: No abnormality1: Communication disconnected2: Unstable communication3: Servo abnormality
get_fresh_mode()
function: Query sports mode
Return value:
0: Interpolation mode1: Refresh mode
set_fresh_mode()
function: Set command refresh mode
Parameters:
1: Always execute the latest command first.0: Execute instructions sequentially in the form of a queue.
Return value:
1: complete
set_free_mode()
function: set to free mode
Parameters:
1: open free mode0: close free mode
Return value:
1: complete
is_free_mode()
function: Check if it is free mode
Return value:
1: free mode0: 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: open0: close
Return value:
1: complete
3.MDI Mode and Operation
get_angles()
- function: get the degree of all joints
- Return value:
lista float list of all degree
get_angles_plan()
Function: Get the planned angles of all joints
Return value:
listList of floating points of all degrees
send_angle(id, degree, speed)
- function: send one degree of joint to robot arm
Parameters:
id: Joint id(genre.Angle), range int 1-6degree: degree value(float) | Joint Id | range | | ---- | ---- | | 1 | -168 ~ 168 | | 2 | -135 ~ 135 | | 3 | -150 ~ 150 | | 4 | -145 ~ 145 | | 5 | -155 ~ 160 | | 6 | -180 ~ 180 |speed:the speed and range of the robotic arm's movement 1~100
- Return value:
1: complete
send_angles(angles, speed)
- function: Send all angles to all joints of the robotic arm
- Parameters:
angles: a list of degree value(List[float]), length 6speed: (int) 1 ~ 100
- Return value:
1: complete
get_coords()
- function: Obtain robot arm coordinates from a base based coordinate system
- Return value: a float list of coord:[x, y, z, rx, ry, rz]
get_coords_plan()
- Function: Get the planned coordinates of the robot arm from the reference-based coordinate system
- Return value: List of floating point coordinates: [x, y, z, rx, ry, rz]
send_coord(id, coord, speed)
- function: send one coord to robot arm
- Parameters:
id:send one coord to robot arm, 1-6 corresponds to [x, y, z, rx, ry, rz]coord: coord value(float) | Coord Id | range | | ---- | ---- | | x | -281.45 ~ 281.45 | | y | -281.45 ~ 281.45 | | z | -70 ~ 412.67 | | rx | -180 ~ 180 | | ry | -180 ~ 180 | | rz | -180 ~ 180 |speed: (int) 1-100
- Return value:
1: complete
send_coords(coords, speed, mode)
- function:: Send overall coordinates and posture to move the head of the robotic arm from its original point to your specified point
- Parameters:
- coords: : a list of coords value
[x,y,z,rx,ry,rz],length6 - speed
(int): 1 ~ 100 - mode:
(int)0 - angluar, 1 - linear
- coords: : a list of coords value
- Return value:
1: complete
pause()
- function: Control the instruction to pause the core and stop all movement instructions
- Return value:
1- stopped0- not stop-1- error
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 6speed: (int) 1 ~ 100timeout: default 15 s
- Return value:
1- complete
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 6speed: (int) 1 ~ 100mode: (int) 0 - angular(default), 1 - lineartimeout: default 15 s
- Return value:
1- complete
get_angles_coords()
function: Get joint angles and coordinates
Return value: A list with a length of 12. The first six digits are angle information, and the last six digits are coordinate information.
is_paused()
- function: Check if the program has paused the move command
- Return value:
1- paused0- not paused-1- error
resume()
- function: resume the robot movement and complete the previous command
- Return value:
1- complete
stop()
- function: stop all movements of robot
- Return value:
1- stopped0- not stop-1- error
is_in_position(data, flag)
- function : judge whether in the position.
- Parameters:
- data: Provide a set of data that can be angles or coordinate values. If the input angle length range is 6, and if the input coordinate value length range is 6
- flag data type (value range 0 or 1)
0: angle1: coord
- Return value:
1- true0- false-1- error
is_moving()
- function: judge whether the robot is moving
- Return value:
1moving0not moving-1error
angles_to_coords(angles)
- Function : Convert angles to coordinates.
- Parameters:
angles:listList of floating points for all angles.
- Return value:
listList of floating points for all coordinates.
solve_inv_kinematics(target_coords, current_angles)
- Function : Convert coordinates to angles.
- Parameters:
target_coords:listList of floating points for all coordinates.current_angles:listList of floating points for all angles, current angles of the robot
- Return value:
listList of floating points for all angles.
drag_start_record()
Function : Start trajectory recording.
Return value:
intRecording queue length.
drag_end_record()
Function : End trajectory recording.
Return value:
intRecording queue length.
drag_get_record_data()
Function : Get the recorded trajectory. This interface can be used with the
drag_get_record_leninterface. If the queue length is 0, it returns -1.Return value:
listList of potential values (encoder values) and motion speeds of each joint. eg:[[J1_encoder,J2_encoder,J3_encoder,J4_encoder, J5_encoder, J6_encoder],[J1_run_speed, J2_run_speed, J3_run_speed, J4_run_speed, J5_run_speed, J6_run_speed]]
drag_get_record_len()
Function : Get the total number of recording points.
Return value:
intRecording queue length.
drag_clear_record_data()
Function : Clear the recording track.
Return value:
intRecording queue length.
4. JOG Mode and Operation
jog_angle(joint_id, direction, speed)
- function: jog control angle
- Parameters:
joint_id: Represents the joints of the robotic arm, represented by joint IDs ranging from 1 to 6direction(int): To control the direction of movement of the robotic arm, input0as negative value movement and input1as positive value movementspeed: 1 ~ 100
- Return value:
1: complete
jog_coord(coord_id, direction, speed)
- function: jog control coord.
- Parameters:
coord_id: (int) Coordinate range of the robotic arm: 1~6direction: (int) To control the direction of machine arm movement,0- negative value movement,1- positive value movementspeed: 1 ~ 100
- Return value:
1: complete
jog_rpy(end_direction, direction, speed)
- function: Rotate the end around a fixed axis in the base coordinate system
- Parameters:
end_direction: (int) Roll, Pitch, Yaw (1-3)direction: (int) To control the direction of machine arm movement,1- forward rotation,0- reverse rotationspeed: (int) 1 ~ 100
- Return value:
1: complete
jog_increment_angle(joint_id, increment, speed)
- function: Angle step, single joint angle increment control
- Parameters:
joint_id: 1-6increment: Incremental movement based on the current position anglespeed: 1 ~ 100
- Return value:
1: completed
jog_increment_coord(id, increment, speed)
- function: Coord step, single coord increment control
- Parameters:
id: axis 1-6increment: Incremental movement based on the current position coordspeed: 1 ~ 100
- Return value:
1: completed
set_encoder(joint_id, encoder, speed)
function: Set a single joint rotation to the specified potential value
Parameters
joint_id: (int) 1-6encoder: 0 ~ 4096speed: 1 ~ 100
- Return value:
1: complete
get_encoder(joint_id)
function: Set a single joint rotation to the specified potential value
Parameters
joint_id: (int) 1-6
Return value: (
int) Joint potential value
set_encoders(encoders, speed)
function: Set the six joints of the manipulator to execute synchronously to the specified position.
Parameters
joint_id: (int) 1-6encoder: 0 ~ 4096speed: 1 ~ 100
- Return value:
1: complete
get_encoders()
function: Get the six joints of the manipulator.
Return value: (
list) the list of encoders
5. Running status and Settings
get_joint_min_angle(joint_id)
- function: Gets the minimum movement angle of the specified joint
- Parameters:
joint_id: Enter joint ID (range 1-6)
- Return value:
floatAngle value
get_joint_max_angle(joint_id)
- function: Gets the maximum movement angle of the specified joint
- Parameters:
joint_id: Enter joint ID (range 1-6)
- Return value:
floatAngle value
set_joint_min(id, angle)
- function: Set minimum joint angle limit
- Parameters:
id: Enter joint ID (range 1-6)angle: Refer to the limit information of the corresponding joint in the send_angle() interface, which must not be less than the minimum value
- Return value:
1: complete
set_joint_max(id, angle)
- function: Set maximum joint angle limit
- Parameters:
id: Enter joint ID (range 1-6)angle: Refer to the limit information of the corresponding joint in the send_angle() interface, which must not be greater than the maximum value
- Return value:
1: complete
6. Joint motor control
is_servo_enable(servo_id)
- function: Detecting joint connection status
- Parameters:
servo id1-6 - Return value:
1: Connection successful0: not connected-1: error
is_all_servo_enable()
- function: Detect the status of all joint connections
- Return value:
1: Connection successful0: not connected-1: error
set_servo_calibration(servo_id)
- function: The current position of the calibration joint actuator is the angle zero point
- Parameters:
servo_id: 1 - 6
- Return value:
1: complete
release_servo(servo_id)
- function: Set the specified joint torque output to turn off
- Parameters:
servo_id: 1 ~ 6
- Return value:
1: release successful0: release failed-1: error
focus_servo(servo_id)
- function: Set the specified joint torque output to turn on
- Parameters:
servo_id: 1 ~ 6 - Return value:
1: focus successful0: focus failed-1: error
set_servo_data(servo_id, data_id, value, mode=None)
- function: Set the data parameters of the specified address of the steering gear
- Parameters:
servo_id: (int) joint id 1 - 6data_id: (int) Data addressvalue: (int) 0 - 4096mode: 0 - indicates that value is one byte(default), 1 - 1 represents a value of two bytes.
- Return value:
1: complete
get_servo_data(servo_id, data_id, mode=None)
- function: Read the data parameter of the specified address of the steering gear.
- Parameters:
servo_id: (int) joint id 1 - 6data_id: (int) Data addressmode: 0 - indicates that value is one byte(default), 1 - 1 represents a value of two bytes.
- Return value: 0 ~ 4096
joint_brake(joint_id)
- 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: complete
7. 9g Servo
move_round()
- function:Drive the 9g steering gear clockwise for one revolution
- Return value:
1: complete
set_four_pieces_zero()
- function:Set the zero position of the four-piece motor
- Return value:
1: success0: failed
8. Servo state value
get_servo_speeds()
- function:Get the movement speed of all joints
- Return value: A list unit step/s
get_servo_voltages()
- function:Get joint voltages
- Return value: A list volts < 24 V
get_servo_status()
- function:Get the movement status of all joints
- Return value: A list,[voltage, sensor, temperature, current, angle, overload], a value of
0means no error, a value of1indicates an error
get_servo_temps()
- function:Get joint temperature
- Return value: A list unit ℃
backup_servo_params(servo_id)
- Function: Backs up servo parameters. Requires firmware version 7.4.0 or higher. (Confirms the use of existing parameters.)
Parameters:
servo_id (int): Servo ID; range: 1 ~ 6; 254 - all servos.
Return Value:
1: Complete.
restore_servo_params(servo_id)
- Function: Restores servo parameters. Requires firmware version 7.4.0 or higher. (Effective only if a parameter backup has previously been performed.)
Parameters:
servo_id (int): Servo ID; range: 1 ~ 6; 254 - all servos.
Return Value:
1: Complete.
9. Robotic arm end IO control
set_color(r, g, b)
function: Set the color of the end light of the robotic arm
Parameters:
r (int): 0 ~ 255g (int): 0 ~ 255b (int): 0 ~ 255
- Return value:
1: complete
set_digital_output(pin_no, pin_signal)
- function: set IO statue
- Parameters
pin_no(int): Pin numberpin_signal(int): 0 / 1
- Return value:
1: complete
get_digital_input(pin_no)
- function: read IO statue
- Parameters:
pin_no(int) - Return value: signal
set_pin_mode(pin_no, pin_mode)
- function: Set the state mode of the specified pin in atom.
- Parameters
pin_no(int): Pin numberpin_mode(int): 0 - input, 1 - output, 2 - input_pullup
- Return value:
1: complete
10. Robotic arm end gripper control
set_gripper_state(flag, speed, _type_1=None)
function: Adaptive gripper enable
Parameters:
flag (int): 0 - open 1 - close, 254 - releasespeed (int): 0 ~ 100_type_1 (int):1: Adaptive gripper (default state is 1)2: A nimble hand with 5 fingers3: Parallel gripper4: Flexible gripper
- Return value:
1: complete
set_gripper_value(gripper_value, speed, gripper_type=None)
function: Set the gripper value
Parameters:
gripper_value (int): 0 ~ 100speed (int): 0 ~ 100gripper_type (int):1: Adaptive gripper (default state is 1)2: A nimble hand with 5 fingers3: Parallel gripper4: Flexible gripper
- Return value:
1: complete
gripper_stop()
- Function: Stop gripper movement
- Return value:
1: Completed
set_gripper_calibration()
- function: Set the current position of the gripper to zero
- Return value:
1: complete
is_gripper_moving()
- function: Judge whether the gripper is moving or not
- Return value:
0: not moving1: is moving-1: error data
get_gripper_value()
- function: Get the value of gripper
- Parameters:
gripper_type: (int) default 1- 1: Adaptive gripper
- 3: Parallel gripper
- 4: Flexible gripper
- Return value:gripper value (int)
set_pwm_output(channel, frequency, pin_val)
- function: PWM control
- Parameters:
channel: (int): IO number.frequency: (int): clock frequencypin_val: (int) Duty cycle 0 ~ 256; 128 means 50%
- Return value:
1: complete
set_HTS_gripper_torque(torque)
- function: Set new adaptive gripper torque
- Parameters:
torque: (int): 150 ~ 980
- Return value:
0: Set failed1: Set successful
get_HTS_gripper_torque()
- function: Get gripper torque
- Return value: (int) 150 ~ 980
get_gripper_protect_current()
- function: Get the gripper protection current
- Return value: (int) 1 ~ 500
set_gripper_protect_current(current)
- function: Set the gripper protection current
- Parameters:
current: (int): 1 ~ 500
- Return value:
1: complete
init_gripper()
- function: Initialize gripper
- Return value:
1: complete
11. Set bottom IO input/output status
set_basic_output(pin_no, pin_signal)
- function:Set Base IO Output
- Parameters:
pin_no(int) Pin port numberpin_signal(int): 0 - low. 1 - high
get_basic_input(pin_no)
- function: Read base IO input
- Parameters:
pin_no(int) pin number
- Return value: 0 - low. 1 - high
12. WLAN Setting
set_ssid_pwd(account, password)
- function: Change connected wifi. (Apply to m5)
- Parameters:
account(str) new wifi accountpassword(str) new wifi password
- Return value:
1: complete
get_ssid_pwd()
- function: Get connected wifi account and password. (Apply to m5)
- Return value: (account, password)
set_server_port(port)
- function: Change the connection port of the server
- Parameters:
port(int) The new connection port of the server.
- Return value:
1: complete
13. TOF
get_tof_distance()
- function: Get the detected distance (Requires external distance detector)
- Return value: (int) The unit is mm.
14. Communication mode
set_transponder_mode(mode)
- function: Set basic communication mode
- Parameters:
mode: 0 - Turn off transparent transmission,1 - Open transparent transmission
- Return value:
1: complete
get_transponder_mode()
- function: Get basic communication mode
- Parameters:
- Return value:
1: Open transparent0: Turn off transparent transmission
15. Cartesian space coordinate parameter setting
set_tool_reference(coords)
- function: Set tool coordinate system.
- Parameters:
coords: (list) [x, y, z, rx, ry, rz].
- Return value:
1: complete
get_tool_reference(coords)
- function: Get tool coordinate system.
- Return value: (
list) [x, y, z, rx, ry, rz]
set_world_reference(coords)
- function: Set world coordinate system.
- Parameters:
coords: (list) [x, y, z, rx, ry, rz].
- Return value:
1: complete
get_world_reference()
- function: Get world coordinate system.
- Return value:
list[x, y, z, rx, ry, rz].
set_reference_frame(rftype)
- function: Set base coordinate system.
- Parameters:
rftype: 0 - base 1 - tool. - Return value:
1: complete
get_reference_frame()
- function: Get base coordinate system.
- Return value: (
list) [x, y, z, rx, ry, rz].
set_movement_type(move_type)
- function: Set movement type.
- Parameters:
move_type: 1 - movel, 0 - moveJ.
- Return value:
1: complete
get_movement_type()
- function: Get movement type.
- Return value:
1- movel0- moveJ
set_end_type(end)
- function: Set end coordinate system
- Parameters:
end (int):0- flange,1- tool
- Return value:
1: complete
get_end_type()
- function: Obtain the end coordinate system
- Return value:
0- flange1- tool
16. Raspberry pi -- GPIO
gpio_init()
- function: Init GPIO module, and set BCM mode.
- Return value:
1: complete
gpio_output(pin, v)
function: Set GPIO port output value.
Parameters
pin(int) Pin number.v(int): 0 / 1
- Return value:
1: complete
17. utils (module)
This module supports some helper methods. Use the code entered at the beginning of the file to import the module:
from pymycobot import utils
utils.get_port_list()
Function: Get a list of all current serial port numbers
Return value: Serial port list (
list)
utils.detect_port_of_basic()
Function: Return the first detected serial port number of M5 Basic. (Only one serial port number will be returned)
Return value: Return the detected port number. If no serial port number is detected, it will return: None
MyCobot 280 Socket
Note: raspberryPi version Only supports python3 The robotic arm that uses this class of premise has a server and has been turned on.
Use TCP/IP to control the robotic arm
Client
# demo
from pymycobot import MyCobot280Socket
# Port 9000 is used by default
mc = MyCobot280Socket("192.168.10.10", 9000, timeout=1.0)
res = mc.get_angles()
print(res)
mc.send_angles([0,0,0,0,0,0],20)
...
Server
Server file is in the demo folder,For details, please check the Server_280.py file in the demo folder
For Arduino UNO Q with the Bridge RPC socket server, use Server_280_UNOQ.py. This server calls XferBridgeMsg internally and does not depend on the /dev/mycobot serial device. The client still uses MyCobot280Socket(ip, 9000), and the socket read timeout can be configured with the timeout parameter when needed.
socket control
Note: Most of the methods are the same as the class MyCobot280, only the new methods are listed here.
set_gpio_mode(mode)
function: Set pin coding method.
Parameters
mode(str) "BCM" or "BOARD".
set_gpio_out(pin_no, mode)
function: Set the pin as input or output.
Parameters
pin_no(int) pin id.mode(str) "in" or "out"
set_gpio_output(pin_no, state)
function: Set the pin to high or low level.
Parameters
pin_no(int) pin id.state(int) 0 or 1
get_gpio_in(pin_no)
function: Get pin level status.
Parameters
pin_no(int) pin id.
- Return value:
0is low level1is high level