This is python API for mycobot.
We support Python2, Python3.5 or later.
Catalogue:
Import to your project:
# for mycobot
from pymycobot import MyCobot
# for mypalletizer
# from pymycobot import MyPalletizer
Note: If no parameter is given, there is no parameter; if no return value is given, there is no return value
-
Prototype:
power_on()
-
Description:Atom open communication (default open).
-
Prototype:
power_off()
-
Description: Atom turn off communication.
-
Prototype:
is_power_on()
-
Description: Adjust robot arm whether power on.
-
Returns
1
: power on0
: power off-1
: error
-
Prototype:
release_all_servos()
-
Description: Set robot arm into free moving mode.
-
Prototype:
is_controller_connected()
-
Description: Check if connected with Atom.
-
Returns
1
: connected0
: not connected-1
: error
-
Prototype:
get_angles()
-
Description: Get the degree of all joints.
-
Returns:
list
: A float list of all degree.
-
Prototype:
send_angles(id, degree, speed)
-
Description: Send one degree of joint to robot arm.
-
Parameters
id
: Joint id(genre.Angle
) / int 1-6degree
: degree value(float
) (about -170 ~ 170)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)
-
Prototype:
send_angles(degrees, speed)
-
Description: Send the degrees of all joints to robot arm.
-
Parameters
-
degrees
: a list of degree value(List[float]
), length 6. -
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)
-
Prototype:
get_radians()
-
Description: Get the radians of all joints.
-
Returns:
list
: A float list of radian.
-
Prototype:
send_radians(radians, speed)
-
Description: Send the radians of all joint to robot arm.
-
Parameters:
radians
: a list of radian value(List[float]
), length 6.speed
: (int
) 0 ~ 100
-
Example
from pymycobot.mycobot import MyCobot from pymycobot.genre import Angle mycobot = MyCobot('/dev/ttyUSB0') mycobot.send_angles_by_radian([1,1,1,1,1,1], 70)
-
Prototype:
get_coords()
-
Description: Get the Coords from robot arm, coordinate system based on base.
-
Returns:
list
: A float list of coord -[x, y, z, rx, ry, rz]
-
Prototype:
get_coords(id, coord, speed)
-
Description: 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)
-
Prototype:
send_coords(coords, speed, mode)
-
Description: 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)
-
Prototype:
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.
-
Prototype:
sync_send_coords(coords, speed, mode, timeout=7)
-
Description: 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.
-
Prototype:
is_in_position(data, flag)
-
Description: Judge whether in the position.
-
Parameters
data
: A data list, angles or coords, length 6.flag
: Tag the data type,0
- angles,1
- coords.
-
Returns
1
- true0
- false-1
- error
-
Prototype:
jog_angle(joint_id, direction, speed)
-
Description: Jog control angle
-
Parameters
joint_id
: (int
) 1 ~ 6direction
:0
- decrease,1
- increasespeed
: 0 ~ 100
-
Prototype:
jog_coord(coord_id, direction, speed)
-
Description: Jog control coord.
-
Parameters
coord_id
: (int
) 1 ~ 6direction
:0
- decrease,1
- increasespeed
: 0 ~ 100
-
Prototype:
jog_stop()
-
Description: Stop jog moving.
-
Prototype:
pause()
-
Description: Pause movement.
-
Prototype:
resume()
-
Description: Recovery movement.
-
Prototype:
stop()
-
Description: Stop moving.
-
Prototype:
is_paused()
-
Description: Judge whether the manipulator pauses or not.
-
Returns :
1
- paused0
- not paused-1
- error
-
Prototype:
set_encoder(joint_id, encoder)
-
Description: Set a single joint rotation to the specified potential value.
-
Parameters
joint_id
: (int
) 1 ~ 6encoder
: 0 ~ 4096
-
Prototype:
get_encoder(joint_id)
-
Description:Obtain the specified joint potential value.
-
Parameters:
joint_id
: (int
) 1 ~ 6 -
Returns:
encoder
: 0 ~ 4096
-
Prototype:
set_encoders(encoders, sp)
-
Description: Set the six joints of the manipulator to execute synchronously to the specified position.
-
Parameters:
encoders
: A encoder list, length 6.sp
: speed 0 - 100
-
Prototype:
get_encoders()
-
Description: Get the six joints of the manipulator.
-
Returns: the list of encoder (
list
)
-
Prototype:
get_speed()
-
Description: Get speed.
-
Returns: speed: (
int
)
-
Prototype:
set_speed(speed)
-
Description: Set speed.
-
Parameters: speed: (
int
) 0 ~ 100
-
Prototype:
get_joint_min_angle()
-
Description: Gets the minimum movement angle of the specified joint
-
Parameters:
joint_id
: (int
) -
Returns: angle value (
float
)
-
Prototype:
get_joint_max_angle()
-
Description: Gets the maximum movement angle of the specified joint
-
Parameters:
joint_id
: (int
) -
Returns: angle value (
float
)
-
Prototype:
is_servo_enable(servo_id)
-
Description: Determine whether all steering gears are connected
-
Parameters:
servo_id
(int
) 1 ~ 6 -
Returns
0
: disable1
: enable-1
: error
-
Prototype:
is_all_servo_enable()
-
Description: Determine whether the specified steering gear is connected
-
Returns
0
: disable1
: enable-1
: error
-
Prototype:
set_servo_data(servo_no, data_id, value)
-
Description: Set the data parameters of the specified address of the steering gear.
-
Parameters:
servo_no
: Serial number of articulated steering gear, 1 - 6.data_id
: Data address.value
: 0 - 4096
-
Prototype:
get_servo_data(servo_no, data_id)
-
Description: Read the data parameter of the specified address of the steering gear.
-
Parameters:
servo_no
: Serial number of articulated steering gear, 1 - 6.data_id
: Data address.
-
Returns:
value
: 0 - 40960
: disable1
: enable-1
: error
-
Prototype:
set_servo_calibration(servo_no)
-
Description: 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.
-
Prototype:
release_servo(servo_id)
-
Description: Power off designated servo
-
Parameters:
servo_id
: 1 ~ 6
-
Prototype:
focus_servo(servo_id)
-
Description: Power on designated servo
-
Parameters:
servo_id
: 1 ~ 6
-
Prototype:
set_color(r, g, b)
-
Description: Set the color of the light on the top of the robot arm.
-
Parameters
r
: 0 ~ 255g
: 0 ~ 255b
: 0 ~ 255
-
Prototype:
set_pin_mode(pin_no, pin_mode)
-
Description: 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_pullup
-
Parameters
pin_no
(int):pin_signal
(int): 0 / 1
-
Parameters:
pin_no
(int) -
Return: signal value
-
Prototype:
set_pwm_output(channel, frequency, pin_val)
-
Description: PWM control.
-
Parameters
channel
(int
): IO number.frequency
(int
): clock frequencypin_val
(int
): Duty cycle 0 ~ 256; 128 means 50%
-
Prototype:
get_gripper_value()
-
Description: Get gripper value
-
Return: gripper value (int)
-
Prototype:
set_gripper_state(flag, speed)
-
Description: Set gripper switch state
-
Parameters
flag
(int
): 0 - open, 1 - closespeed
(int
): 0 ~ 100
-
Prototype:
set_gripper_value(value, speed)
-
Description: Set gripper value
-
Parameters
value
(int): 0 ~ 100speed
(int): 0 ~ 100
-
Prototype:
set_gripper_ini()
-
Description: Set the current position to zero, set current position value is
2048
.
-
Prototype:
is_gripper_moving()
-
Description: Judge whether the gripper is moving or not
-
Returns
0
: not moving1
: is moving-1
: error data
-
Prototype:
get_basic_input(pin_no)
-
Description: Get bottom pin.
-
Parameters
pin_no
(int
) Pin number.
-
Return:
pin_signal
(int
) 0 / 1
-
Prototype:
set_basic_output(pin_no, pin_signal)
-
Description: Set bottom pin.
-
Parameters
pin_no
(int
) Pin number.pin_signal
(int
): 0 / 1
-
Prototype:
set_ssid_pwd(account, password)
-
Description: Change connected wifi.(Apply to m5 or seeed)
-
Parameters
account
(str
) new wifi account.password
(str
): new wifi password.
-
Prototype:
get_ssid_pwd()
-
Description: Get connected wifi account and password.(Apply to m5 or seeed)
-
Return:
(account, password)
.
-
Prototype:
set_server_port(port)
-
Description: Change the connection port of the server.
-
Parameters
port
(int
) The new connection port of the server.
-
Prototype:
get_tof_distance()
-
Description: Get the detected distance (Requires external distance detector).
-
Return:
int
The unit is mm.
-
Prototype:
gpio_init()
-
Description: Init GPIO module, and set BCM mode.
-
Prototype:
gpio_output(pin, v)
-
Description: Set GPIO port output value.
-
Parameters
pin
(int
) Pin number.v
(int
): 0 / 1
from pymycobot import Angle
Description
Instance class of joint. It's recommended to use this class to select joint.
from pymycobot import Coord
Description
Instance class of coord. It's recommended to use this class to select coord.
This module support some help method.
Usage:
from pymycobot import utils
-
Prototype:
get_port_list()
-
Description: Get the all serial port list.
-
Return: serial port list (
list
)
-
Prototype:
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
) orNone
-
Example:
from pymycobot import MyCobot, utils port = utils.detect_port_of_basic() if port is None: raise Exception('Detection failed.') mycobot = MyCobot(port, 115200)
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
# demo
from pymycobot import MyCobotSocket
# Port 9000 is used by default
mc = MyCobotSocket("192.168.10.10","9000")
mc.connect("/dev/ttyAMA0","1000000")
res = mc.get_angles()
print(res)
mc.send_angles([0,0,0,0,0,0],20)
...
Server file is in the demo folder
Note: Most of the methods are the same as the class mycobot, only the new methods are listed here.
-
Prototype:
connect(serialport, baudrate, timeout)
-
Description: Connect the robot arm through the serial port and baud rate
-
Parameters
serialport
: (str
) default/dev/ttyAMA0
.baudrate
: default1000000
.timeout
: default0.1
.
-
Prototype:
set_gpio_mode(mode)
-
Description: Set pin coding method.
-
Parameters
mode
(str
) "BCM" or "BOARD".
-
Prototype:
set_gpio_out(pin_no, mode)
-
Description: Set the pin as input or output.
-
Parameters
pin_no
(int
) pin id.mode
(str
) "in" or "out"
-
Prototype:
set_gpio_output(pin_no, state)
-
Description: Set the pin to high or low level.
-
Parameters
pin_no
(int
) pin id.state
(int
) 0 or 1
-
Prototype:
get_gpio_in(pin_no)
-
Description: Get pin level status.
-
Parameters
pin_no
(int
) pin id.
# Set up the demo of the suction pump
import time
from pymycobot import MyCobotSocket
# connect server
m = MyCobotSocket("192.168.10.10", '9000')
# default serialport:/dev/ttyAMA0 Baudrate:1000000
m.connect()
m.set_gpio_mode("BCM")
m.set_gpio_out(20, "out")
m.set_gpio_out(21, "out")
# open
m.set_gpio_output(20, 0)
m.set_gpio_output(21, 0)
time.sleep(3)
# close
m.set_gpio_output(20, 1)
m.set_gpio_output(21, 1)
More demo can go to here.