API method details
When using the following function interface, please import our API library at the beginning, otherwise it will not run successfully, that is, enter the following code:
#For Mira series
from pymycobot import Mira
Note: If our API library is not installed, please refer to the 7.1 Environment Building chapter to install it.
1 The overall operating status of the robotic arm
1.1 go_zero()
- Function: The robotic arm returns to zero.
- return value: none
1.2 power_on()
- Function: All joints of the robotic arm are powered on.
- return value: none
1.3 release_all_servos()
- Function: All joints of the robotic arm are powered off
- return value: none
2 Input program control mode (MDI mode)
Note: Different series of manipulators have different limit positions, and the settable attitude values are also different. For details, please refer to the parameter introduction of the corresponding model.
2.1 get_angles_info()
- Function: Get the current angle of the robotic arm.
- return value:
list
a list of float values representing the angles of all joints.
2.2 set_angle(id, degree, speed)
- Function: Sends the specified single joint motion to the specified angle
- Parameter Description:
id
: Representing the joints of the robotic arm, the three-axis has three joints, which can be represented by numbers 1-3.degree
: Indicates the angle of the jointspeed
:Indicates the speed of the robotic arm movement, ranging from 0 to 100 (unit: mm/s).
- return value: none
2.3 set_angles(degrees, speed)
- Function: Send all angles to all joints of the robotic arm
- Parameter Description:
degrees
: (List[float])Including the angle of all joints, the three-axis robot has three joints, so the length is 3, and the representation method is: [20,20,20]speed
: Indicates the speed of the robot arm movement, the value range is 0-100 (unit: mm/s).
- return value: none
2.4 get_coords_info()
- Function: Get the current coordinates of the robotic arm.
- return value:
list
a list containing the coordinates- Three axes: length is 3, followed by
[x, y, z]
- Three axes: length is 3, followed by
2.5 send_coord(id,coord,speed)
- Function: Send a single coordinate value to the robotic arm to move
- Parameter Description:
id
:Represents the coordinates of the robotic arm, the three axes have three coordinates, and there are specific representation methods. X-coordinate notation:"X" or "x"
.coord
: Enter the coordinate value you want to reachspeed
: Indicates the speed of the robot arm movement, the range is 0-100 (unit: mm/s).
- return value: none
2.6 set_coords(coords, speed)
- Function: Send global coordinates to move the robotic arm head from the original point to the point you specify.
- Parameter Description:
coords
:- Three axes: the coordinate value of [x,y,z], the length is 3
speed
: Indicates the speed of the robot arm movement, the range is 0-100 (unit: mm/s).
- return value: none
2.7 get_radians_info()
- Function: Get the current radian value of the robotic arm.
- return value:
list
A list containing all joint radian values.
2.8 set_radians(radians, speed)
- Function: Send radian values to all joints of the robotic arm
- Parameter Description:
radians
: A list of radian values for each joint(List[float]
)speed
: Indicates the speed of the robot arm movement, the range is 0-100 (unit: mm/s).
- return value: none
2.9 set_mode()
- Function: set coordinate mode
- Parameter Description:
0
:Absolute Cartesian mode.1
:Relative Cartesian mode.
- return value: none
2.10 sleep()
- Function: Delay
- Parameter Description:
Time
: delay time (typeInt
)
- return value: none
2.12 set_init_pose()
- Function: Set the current location to a fixed location. For example (0,0,0), set this position as the zero point.
- Parameter Description:
coords
: All coordinates of the robotic armspeed
: Indicates the speed of the robot arm movement, the range is 0-100 (unit: mm/s).
- return value: none
2.13 set_pwm()
- Function: Set PWM duty cycle
- Parameter Description: P: duty cycle, range: 0-255
- return value: none
2.14 set_fan_state()
- Function: set fan status
- Parameter Description:
0
: close1
: open
- return value: none
2.15 get_switch_state()
- Function: Get limit switch status
- Parameter Description:
X
: Whether joint 3 has reached the limitY
: Whether joint 2 has reached the limitZ
: Whether joint 1 has reached the limit
- return value: 有
2.16 set_speed_mode(mode)
- Function: Set speed mode
- Parameter Description:
0
: uniform mode2
: Acceleration and deceleration mode
- return value: none
3 JOG mode and operation
3.1 set_jog_angle(id, direction, speed)
- Function: Set jog mode (angle)
- Parameter Description:
id
: Represents the joint of the robotic arm, which is represented by entering 1~3 according to the joint iddirection
: It mainly controls the moving direction of the robot arm. Input 0 is negative value movement, and input 1 is positive value movementspeed
: Speed 0 ~ 100 (unit: mm/s).
- return value: none
3.2 set_jog_coord(axis, direction, speed)
- Function: Control the robot to move continuously according to the specified coordinates or attitude values
- Parameter Description:
axis
: Represents the joint of the robotic arm, which is represented by x/y/z according to the joint axisdirection
: It mainly controls the moving direction of the robot arm. Input 0 is negative value movement, and input 1 is positive value movementspeed
: Speed 0 ~ 100 (unit: mm/s).
- return value: none
3.3 set_jog_stop()
- Function: Stop continuous movement under jog control
- return value: none
4 IO control
4.1 set_gpio_state(state)
- Function: Set the suction pump status.
- Parameter Description:
state
(int): Input 0 to turn on the suction pump, and input 1 to turn off the suction pump.
- return value: none
4.2 set_gripper_zero()
- Function: Set gripper zero position (set current position to zero position).
- return value: none
4.3 set_gripper_state(state):
- Function: Set the gripper switch
- 参数说明:
state
:Enter 0 to open the jaws and 1 to close the jaws. - return value: none
5 functional interface
5.1 play_gcode_file(filename)
- Function: Play the imported track file.
- Parameter Description:
filename
: track file name
- return value: none
6 Use Cases
6.1 Use of suction pump
import time
import platform
from pymycobot.mira import Mira
# Automatically select the system and connect the robotic arm
if platform.system() == "Windows":
ma = Mira('COM6', 115200)
ma.go_zero()
elif platform.system() == "Linux":
ma = Mira('/dev/ttyUSB0', 115200)
ma.go_zero()
# The position of the robotic arm movement
angles = [
[-81.71, 0.0, 0.0],
[-90.53, 21.77, 47.56],
[-90.53, 0.0, 0.0],
[-59.01, 21.77, 45.84],
[-59.01, 0.0, 0.0]
]
# Absorb small blocks
ma.set_angles(angles[0], 50)
time.sleep(3)
ma.set_angles(angles[1], 50)
time.sleep(3)
# Turn on the suction pump
ma.set_gpio_state(0)
ma.set_angles(angles[2], 50)
time.sleep(3)
ma.set_angles(angles[3], 50)
# Turn off the suction pump
ma.set_gpio_state(1)
time.sleep(3)
ma.set_angles(angles[4], 50)
6.2 夹爪的使用
import time
import platform
from pymycobot import Mira
# Automatically select the system and connect the robotic arm
if platform.system() == "Windows":
ma = Mira('COM6', 115200)
ma.go_zero()
elif platform.system() == "Linux":
ma = Mira('/dev/ttyUSB0', 115200)
ma.go_zero()
# The position of the robotic arm movement
angles = [
[-81.71, 0.0, 0.0],
[-90.53, 21.77, 47.56],
[-90.53, 0.0, 0.0],
[-59.01, 21.77, 45.84],
[-59.01, 0.0, 0.0]
]
ma.set_angles(angles[0], 50)
time.sleep(3)
i = 5
# cycle 5 times
while i > 0:
# Open the jaws
ma.set_gripper_state(0)
time.sleep(2)
# close the jaws
ma.set_gripper_state(1)
time.sleep(2)
i -= 1
6.3 Get point information
import time
import platform
from pymycobot.mira import Mira
def mira_move():
# Automatically select the system and connect the robotic arm
if platform.system() == "Windows":
ma = Mira('COM6', 115200)
# Robot zero calibration
ma.go_zero()
elif platform.system() == "Linux":
ma = Mira('/dev/ttyUSB0', 115200)
ma.go_zero()
# Let the robotic arm reach the angular position at a speed of 50
ma.set_angles([19.48, 0, 0], 50)
# Set the waiting time to ensure that the robotic arm has reached the specified position
time.sleep(2)
ma.set_angles([0, 18.91, 49.85], 50)
time.sleep(3)
ma.set_angles([0, 0, 0], 50)
time.sleep(2)
# Let the robotic arm reach the coordinate position at a speed of 50
ma.set_coords([217.09, 113.01, 98.36], 50)
time.sleep(4)
# Use radians to control the robot arm to return to the zero position
ma.set_radians([0, 0, 0], 50)
time.sleep(3)
ma.set_coords([-6.91, -175.86, 120.0], 50)
time.sleep(4)
ma.set_coords([107.54, -171.23, 117.11], 50)
time.sleep(4)
# Get angular position information
print(ma.get_angles_info())
# Get coordinate location information
print(ma.get_coords_info())
# Get position information in radians
print(ma.get_radians_info())
if __name__ == "__main__":
mira_move()