Introduction to API
API or Application Programming Interface refers to a number of preset programs. Before utilization, it is required to import API library:
from pymycobot.mycobot import MyCobot
Notice: Functions with return value are required to use
print()
to print value. For example, if you want to get the speed value, typeprint(get_speed())
, instead ofget_speed()
.
myCobot
1 Overall Status
1.1 power_on()
Function: Atom open communication (default open)
Return Value: None
1.2 power_off()
Function: Atom turn off communication
Return Value: None
1.3 is_power_on()
Function: judge whether robot arms is powered on or not
Return Value:
1
: power on0
: power off-1
: error
1.4 release_all_servos
- Function: release all robot arms
- Return Value: None
1.5 is_controller_connected
Function: check if connected with Atom.
Return Value:
1
: connected0
: not connected-1
: error
1.6 read_next_error()
Fuction: Robot Error Detection.
Return Value
0
: No abnormality1
: Communication disconnected2
: Unstable communication3
: Servo abnormality
1.7 set_fresh_mode(mode)
- Fuction: Set command refresh mode
- Parameters
- mode – int
1 - Always execute the latest command first.
0 - Execute instructions sequentially in the form of a queue.
- mode – int
1 - Always execute the latest command first.
- Return Value None
1.8 get_fresh_mode()
Fuction: get command refresh mode
Return Value
- 1 - Always execute the latest command first.
- 0 - Execute instructions sequentially in the form of a queue.
2 Operating Mode
2.1pause()
- Function: pause motion
- Return Value: None
2.2 stop()
- Function: stop motion
- Return Value: None
2.3 resume()
- Function: resume motion
- Return Value: None
2.4 is_paused()
- Function: judge whether motion pauses or not
- Return Value:
1
: pause0
: not pause-1
: error
2.5 get_speed()
- Function: get motion speed
- Return Value: range from 0-100
2.6 set_speed()
- Function: set motion speed
Parameter: range from 0-100
Return Value: None
2.7 get_joint_min_angle(joint_id)
- Function: get minimum speed of a joint
- Parameter: range from 1-6 or 1-4
- Return Value: angle value
2.8 get_joint_max_angle(joint_id)
- Function: get maximum speed of a joint
- Parameter: range from 1-6 or 1-4
- Return Value: angle value
2.9 is_servo_enable(servo id)
- Function: judge whether a servo is enabled
- Parameter: range from 1-6 or 1-4
- Return Value:
1
: enabled0
: not enabled-1
: error
2.10 is_all_servo_enable()
- Function: judge whether all servos are enabled
- Return Value:
1
: enabled0
: not enabled-1
: error
2.11 release_servo(servo_id)
- Function: release a servo
- Parameter: range from 1-6 or 1-4
- Return Value:
1
: enabled0
: not enabled-1
: error
2.12 get_tof_distance()
- Function: get tested distance
- Return Value: distance value
2.13 get_error_information()
- Function: get error message.
- Return Value:
- 0: no error message.
- 1 ~ 6: The corresponding joint exceeds the limit.
- 16 ~ 19: collision protection.
- 32: Kinematics inverse solution has no solution.
- 33 ~ 34: Linear motion has no adjacent solution.
2.14 clear_error_information()
- Function: clear error message
2.15 set_joint_min(id,angle)
Function: Sets the minimum angle for the specified joint.
Parameters:
id
: (int
)- for mycobot / mecharm: int 1-6.
- for mypalletizer: int 1-4.
- for myArm: int 1 - 7.
angle
: 0 - 180.
- Return Value: None
2.16 set_joint_max(id,angle)
- Function: Sets the maximum angle of the specified joint.
- Parameter:
id
: (int
) joint id- for mycobot / mecharm: int 1-6.
- for mypalletizer: int 1-4.
- for myArm: int 1 - 7.
angle
: 0 - 180
- Return Value: None
2.17 get_basic_version()
- Function: Get basic firmware version.
- Return Value:
version
(float
)
2.18 set_communicate_mode(mode)
- Function: Set basic communication mode.
- Parameter:
mode
(int
) 0 - Turn off transparent transmission. 1 - Open transparent transmission
- Return Value: None
3 MDI Mode
Notice: Different types of manipulators have different limits, and the angle and coordinate limits that can be set are also different. Refer to the parameter introduction section.
3.1 get_angles()
- Function: get the degree of all joints.
- Returns: A float list of all degree.
3.2 send_angle(id, degree, speed)
Function: Send one degree of joint to robot arm.
Parameters
id
: Joint id(genre.Angle
) / int 1-6degree
: degree value(float
)speed
: (int
) 0 ~ 100
##Example:
from pymycobot.mycobot import MyCobot
from pymycobot.genre import Angle
mycobot = MyCobot('/dev/ttyUSB0')
mycobot.send_angle(Angle.J2.value, 10, 50)
3.3 send_angles(degrees, speed)
- Function: Send the degrees of all joints to robot arm.
Parameters:
degrees
: a list of degree value(List[float]
), length 6 or 4.speed
: (int
) 0 ~ 100
##Example:
from pymycobot.mycobot import MyCobot
from pymycobot.genre import Angle
mycobot = MyCobot('/dev/ttyUSB0')
mycobot.send_angles([0,0,0,0,0,0], 80)
3.4 get_coords()
Function: get the Coords from robot arm, coordinate system based on base.
Returns: A float list of coord:
[x, y, z, rx, ry, rz]
or[x, y, z, rx]
3.5 send_coord(id, coord, speed)
Function: send one coord to robot arm.
Parameters:
id
: coord id(genre.Coord
) / int 1-6coord
: coord value(float
)speed
: (int
) 0 ~ 100
##Example:
from pymycobot.mycobot import MyCobot
from pymycobot.genre import Coord
mycobot = MyCobot('/dev/ttyUSB0')
mycobot.send_coord(Coord.X.value, -40, 70)
3.6 send_coords(coords, speed, mode)
- Function: send all coords to robot arm.
- Parameters:
coords
: a list of coords value(List[float]
), length 6.speed
: (int
) 0 ~ 100mode
: (int
):0
- angular,1
- linear
##Example:
from pymycobot.mycobot import MyCobot
from pymycobot.genre import Coord
mycobot = MyCobot('/dev/ttyUSB0')
mycobot.send_coords([160, 160, 160, 0, 0, 0], 70, 0)
3.7 get_encoders()
- Function: get encoders of all joint
- Parameter: a list of encoder values, at the length of 4 or 6
3.8 get_encoder(joint_id)
- Function: get encoders of a joint
- Parameter: joint ID, ranging from 1-4 or 1-6
3.9 get_radians()
- Function: get the radians of all joints
- Returns: A float list of radian
3.10 send_radians(radians, speed)
- Function: send the radians of all joint to robot arm.
- Parameter:
radians
: a list of radian value(List[float]
), length 6 or 4.speed
: (int
) 0 ~ 100
##Example:
from pymycobot.mycobot import MyCobot
from pymycobot.genre import Angle
mycobot = MyCobot('/dev/ttyUSB0')
mycobot.send_radian([1,1,1,1,1,1], 70)
3.11 sync_send_angles(degrees, speed, timeout=7)
Description: send the angle in synchronous state and return when the target point is reached
Parameters:
degrees
: a list of degree value(List[float]
), length 6.speed
: (int
) 0 ~ 100timeout
: default 7s.
3.12 sync_send_coords(coords, speed, mode, timeout=7)
Function: send the coord in synchronous state and return when the target point is reached
Parameters:
coords
: a list of coords value(List[float]
)speed
: (int
) 0 ~ 100mode
: (int
):0
- angular,1
- lineartimeout
: default 7s.
3.13 is_in_position(data, flag)
Function: judge whether in the position.
Parameters:
data
: A data list, angles or coords, length 6 or 4.flag
: Tag the data type,0
- angles,1
- coords.
Return Value:
1
- true0
- false-1
- error
3.14 is_moving()
- Function: judge whether the robot is moving
- Return Value:
1
moving0
not moving-1
error
3.15 set_color(r, g, b)
- Function: set the color of RGB light panel
- Parameters:
R
: 0-255G
: 0-255B
: 0-255
- Return Value: None
3.16 get_radians()
- Function: get radians of all arms
- Return Value: a list of radian values
3.17 send_radians(radians, speed)
- Function: send radians and speed to all arms
- Parameters:
radians
: radians values of armsspeed
: speed of arms
3.18 set_encoders_drag(encoders,speeds)
- Function: Send all encoders and speeds
- Parameters:
encoders
(list
) : encoders list.speeds
: Obtained by the get_servo_speeds() method
- Return Value: None
3.19 get_solution_angles()
- Function: Get zero space deflection angle value.(
This interface is only applicable to MyArm
) - Return Value: angles
3.20 set_solution_angles(angle,speed)
Function: Set zero space deflection angle value.(
This interface is only applicable to MyArm
)Parameters:
angle
: Angle of joint 1.speed
: 1 - 100.
Return Value: None
3.21 set_transponder_mode(mode)
Function: Set serial port transmission mode.(
This interface is only applicable to MyArm
)Parameters:
mode
:0
: Turn off transparent transmission1
: Turn on transparent transmission, verify all data2
: Turn on transparent transmission, only verify communication forwarding mode configuration information
Return Value: None
3.22 get_transponder_mode()
Function: Obtain the configuration information of serial transmission mode.(
This interface is only applicable to MyArm
)Return Value:
0
: Turn off transparent transmission1
: Turn on transparent transmission, verify all data2
: Turn on transparent transmission, only verify communication forwarding mode configuration information (default is 0)
4 JOG Mode
4.1 jog_angle(joint_id, direction, speed)
Function: jog control angle
Parameters:
joint_id
: (int
) 1 ~ 6direction
:0
- decrease,1
- increasespeed
: 0 ~ 100
4.2 jog_coord(coord_id, direction, speed)
Function: jog control coord.
Parameters:
coord_id
: (int
) 1 ~ 6direction
:0
- decrease,1
- increasespeed
: 0 ~ 100
4.3jog_stop()
- Function: stop jog moving
- Return Value: None
4.4 pause()
- Function: Pause motion
- Return Value: None
4.5 resume()
- Function: recovery motion
- Return Value: None
4.6 stop()
- Function: stop motion
- Return Value: None
4.7 is_paused()
- Function: judge whether the manipulator pauses or not
- Returns :
1
- paused0
- not paused-1
- error
4.8 set_encoder(joint_id, encoder)
Function: set a single joint rotation to the specified potential value.
Parameters:
joint_id
: (int
) 1 ~ 6 or 1~4encoder
: 0 ~ 4096
4.9 get_encoder(joint_id)
- Function: obtain the specified joint potential value.
- Parameters:
joint_id
: (int
) 1 ~ 6 or 1~4 - Returns:
encoder
: 0 ~ 4096
4.10 set_encoders(encoders, sp)
Function: Set the six joints of the manipulator to execute synchronously to the specified position.
Parameters:
encoders
: A encoder list, length 6.speed
: speed 0 - 100
4.11 get_encoders()
Function: get the six joints of the manipulator.
Returns: a list of encoder (
list
)
4.12 jog_absolute(joint_id,angle,spedd)
- Function: Jog absolute angle.
- Parameters:
joint_id
: (int
)- for mycobot / mecharm: int 1-6.
- for mypalletizer: int 1-4.
- for myArm: int 1 - 7.
direction
:speed
: 0 ~ 100
- Returns: None
4.13 jog_increment(joint_id,angle,speed)
- Function: Setp mode.
- Parameters:
coord_id
: (int
)- for mycobot / mecharm: int 1-6.
- for mypalletizer: int 1-4.
- for myArm: int 1 - 7.
direction
:speed
: 0 ~ 100
- Returns: None
5 Servo Control
5.1 set_servo_calibration(servo_no)
- Function: the current position of the calibration joint actuator is the angle zero point, and the corresponding potential value is 2048.
- Parameters:
servo_no
: Serial number of articulated steering gear, 1 - 6.
- Return Value: None
5.2 focus_servo(servo_id)
- Function: power on designated servo
- Parameters:
servo_id
: 1 ~ 6 or 1~4 - Return Value: None
5.3 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
: 1~7 - Return Value: None
5.4 get_servo_speeds()
- Function: Get joint velocity.
- Return Value:
list
Speed of each joint.
5.5 get_servo_currents()
- Function: Get joint current.
- Return Value:
list
Current of each joint.
5.6 get_servo_voltages()
- Function: Get joint voltage.
- Return Value:
list
Voltage of each joint.
5.7 get_servo_temps()
- Function: Get the temperature of each joint.
- Return Value:
list
the temperature of each joint.
5.8 get_servo_status()
- Function: power on designated servo
- Return Value:
list
the state of each joint.
6 Atom IO Control
6.1 set_pin_mode(pin_no, pin_mode)
- Function: set the state mode of the specified pin in atom
- Parameters:
pin_no
(int): Pin number.pin_mode
(int): 0 - input, 1 - output, 2 - input_pullupReturn Value: None
6.2 set_digital_output(pin_no, pin_signal)
- Function: set digital state of a pin
Parameters
pin_no
(int):pin_signal
(int): 0 / 1
Return Value: None
6.3 get_digital_input(self, pin_no)
- Function: get digital state of a pin
- Parameters:
pin_no
(int) - Return Value: signal value
6.4 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: None
7 Gripper Control
7.2 set_gripper_value(value, speed, gripper_type=None)
- Function: Let the gripper rotate to the specified position at the specified speed
- Parameter Description:
value
: Indicates the position that the clamping jaw wants to reach, the value range is 0~100speed
: indicates the speed at which to rotate, the value range is 0~100gripper_type
: Gripper type, the default is adaptive gripper1
: Adaptive gripper3
: Parallel jaws4
: Flexible gripper
- Return value: None
7.3 get_gripper_value(gripper_type=None)
- Function: Get the current position data information of the gripper
- Parameter Description:
gripper_type
: Gripper type, the default is adaptive gripper1
: Adaptive gripper3
: Parallel jaws4
: Flexible gripper
- Return value: Gripper data information
7.4 set_gripper_state(flag, speed, _type=None)
- Function: Let the gripper enter the specified state at the specified speed
- Parameter Description:
flag
: 1 means the clamping jaw is closed, 0 means the clamping jaw is open.speed
: Indicates how fast to reach the specified state, the value range is 0~100_type
: Gripper type, the default is adaptive gripper1
: Adaptive gripper2
: Five-fingered dexterity3
: Parallel jaws4
: Flexible gripper
- Return value: None
7.6 set_eletric_gripper(status)
- Function: Set gripper mode (only for 350)
- Parameter description:
status
: 1 means the clamping jaw is closed, 0 means the clamping jaw is open. - Return value: None
7.7 set_gripper_mode(status)
- Function: Set gripper mode
- Parameter description:
status
: 1 transparent transmission mode, 0 I/O mode
- Return value: None
7.8 get_gripper_mode()
- Function: Get gripper status
- Return value:
status(int)
: 0 - Transparent transmission mode 1 - I/O mode
7.12 init_gripper()
- Function: Initialize gripper
- Return value: 0 - initialization failed; 1 - initialization successful
8 Basic IO Control
8.1 get_basic_input(pin_no)
- Function: get bottom pin
- Parameters:
pin_no
(int
) Pin number.- Return Value:
0
: in working state1
: not in working state
8.2 set_basic_output(pin_no, pin_signal)
Function: set bottom pin
Parameters:
pin_no
(int
) Pin numberpin_signal
(int
): 0 / 1
9 Socket Control
The robotic arm needs to open the server, the server file is here.
# for mycobot,mecharm
from pymycobot import MyCobotSocket
mc = MyCobotSocket("192.168.1.10", 9000)
print(mc.get_angles())
10 TCPIP
10.1 set_ssid_pwd(account, password)
Function: change connected wifi (apply to m5 or seeed)
Parameters
account
(str
) : new wifi account.password
(str
): new wifi password.
Return Value: None
10.2 get_ssid_pwd()
Function: get connected wifi account and password (apply to M5 or seed)
Return Value: present WIFI account and password
10.3 set_server_port(port)
Function: change the connection port of the server
Parameters
port
(int
): the new connection port of the server
Return Value: None
11 utils (Module)
Import utils
before using it:
from pymycobot import utils
11.1 utils.get_port_list()
Function: get the all serial port list
Return Value: serial port list (
list
)
11.2 utils.detect_port_of_basic()
Description: Returns the serial port string of the first detected M5 Basic. If it is not found, it returns
None
.Return: detected port (
str
) or `None
##Example:
from pymycobot import MyCobot, utils
port = utils.detect_port_of_basic()
if port is None:
raise Exception('Detection failed.')
mycobot = MyCobot(port, 115200)
12 Raspberry PI—GPIO
Import pymycobot
first:
from pymycobot import MyCobot
12.1 gpio_init()
- Function: init GPIO module, and set BCM mode
- Return Value: None
12.2 set_gpio_mode()
Function: set pin coding method.
Parameters
mode
(str
) "BCM" or "BOARD"
- Return Value: None
12.3 set_gpio_output(pin_no, state)
Function: set GPIO port output value.
Parameters:
pin
(int
): pin numberv
(int
): 0 / 1
Return Value: None
12.4 get_gpio_in(pin_no)
- Function: get pin level status.
- Parameters:
pin_no
(int
) pin id
- Return Value:
0
:low1
: high
12.5 gpio_output(pin,v)
- Function: Set GPIO port output value.
- Parameters:
pin
(int
) Pin number.v
(int
): 0 / 1
- Return Value: None
12.6 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"
Return Value: None
13 Coordinate Transformation
13.1 set_tool_reference(coords)
Function: Set tool coordinate system.
Parameters:
coords
: (list
) [x, y, z, rx, ry, rz].
Return:None
13.2 set_world_reference(coords)
Function: Set world coordinate system.
Parameters:
coords
: (list
) [x, y, z, rx, ry, rz].
- Return:None
13.3 get_world_reference()
Function: Get world coordinate system.
Return:
list
[x, y, z, rx, ry, rz].
13.4 set_reference_frame(rftype)
Function: Set base coordinate system.
Parameters:
rftype
: 0 - base 1 - tool.
Return:None
13.5 get_reference_frame()
Function: Get base coordinate system.
Return: 0 - base 1 - tool.
13.6 set_movement_type(move_type)
Function: Set movement type.
Parameters:
move_type
: 1 - movel, 0 - moveJ.
Return:None
13.7 get_movement_type()
Function: Get movement type.
Return: 1 - movel, 0 - moveJ.
13.8 set_end_type(end)
- Function: Set end coordinate system.
- Parameters:
end
: 0 - flange, 1 - tool.
- Return:None
13.9 get_end_type()
Function: Get end coordinate system.
Return: 0 - flange, 1 - tool.
14 Speed Planning
14.1 get_plan_speed()
Function: Get planning speed.
Return: [
movel planning speed
,movej planning speed
].
14.2 get_plan_acceleration()
Function: Get planning acceleration.
Return: [
movel planning acceleration
,movej planning acceleration
].