Joint control
For a serial multi-joint robot, the control of the joint space is to control the variables of each joint so as to make each joint reaches a target position at a certain speed.
Notice: When setting the angle, the values corresponding to different manipulators are different. For the specific limit value, please refer to the parameter introduction of the corresponding manipulator.
1 Single-joint control
1.1 send_angle(id, degree, speed)
- Function: to sends a specified single joint motion to a specified angle.
- Description of parameters:
id
: to stand for the joints of a robot arm. Six axis means that the robot arm has six joints, and four-axis means it has four joints. There are specific representation methods therefor.The method to represent the joint 1:Angle.J1.value
. (It can also be represented by numbers 1-6.)degree
: means the angle of a joint.speed
: means the movement speed of the robot arm, ranging from 0 to 100.
Return value: None
1.2 set_encoder(joint_id, encoder)
- Function: to sends a specified single joint motion to a specified potential value.
Description of parameters:
joint_id
: to stand for the joints of a robot arm. Six axismeans that the robot arm has six joints, and four-axis means it has four joints. There are specific representation methods therefor. The method to represent the joint 1:` Angle.J1.value`. (It can also be represented by numbers 1-6.)
encoder
:means the potential value of the robot arm, ranging from 0 - 4096.
- Return value: None
2 Multi-joint control
2.1 get_angles()
Function: to get the angels of all joints.
Return value:
List
: a list of floating point values which represent the angles of all joints
2.2 send_angles(degrees, speed)
- Function: to send all angles to all joints.
- Description of parameters:
degrees
: (List [float]) contains the angles of all joints. A six-axis robot has six joints, so the length is 6; and the four-axis length is 4. The representation method is [20, 20, 20, 20, 20, 20]; value range: about -170 - 170. Each joint of the four-axis robot is different. See the table above for details.speed
: means the movement speed of the robot arm, ranging from 0 to 100.
- Return value: None
2.3 set_encoders(encoders, sp)
- Function: Send potential values to all joints of the robotic arm.
- Description of parameters:
encoder
: means the potential of the robot arm, ranging from 0 - 4096. Six axis length is 6, and four axis length is 4. The way to represent:[2048, 2048, 2048, 2048, 2048, 2048].sp
: means the movement speed of the robot arm, ranging from 0 to 100.
- Return value: None
2.4 sync_send_angles(degrees, speed, timeout=7)
- Function: to send an angle synchronously; return when reaching a target point.
- Description of parameters:
degrees
: A list of angle values of each jointList[float]
.speed
: (int
) means the movement speed of the robot arm, ranging from 0 to 100.timeout
: The default time is 7s.
2.5 get_radians()
- Function: to get the radian of all joints.
- Return value:
list
: a list containing radian values of all joints.
2.6 send_radians(radians, speed)
- Function: to send radian values to all joints.
- Description of parameters:
radians
: means the radian values of the robot arm, ranging from -5 to 5.
- Return value:
list
: a list containing radian values of all joints.
3 Cases
For more cases and running result videos, see 7.7 Use Cases
from pymycobot.mycobot import MyCobot
from pymycobot.genre import Angle
from pymycobot import PI_PORT, PI_BAUD # When using the Raspberry Pi version of mycobot, you can refer to these two variables to initialize MyCobot
import time
# MyCobot class initialization requires two parameters:
# The first is the serial port string, such as:
# linux: "/dev/ttyUSB0"
# or "/dev/ttyAMA0"
# windows: "COM3"
# The second is the baud rate::
# M5 version is: 115200
#
# Example:
# mycobot-M5:
# linux:
# mc = MyCobot("/dev/ttyUSB0", 115200)
# or mc = MyCobot("/dev/ttyAMA0", 115200)
# windows:
# mc = MyCobot("COM3", 115200)
# mycobot-raspi:
# mc = MyCobot(PI_PORT, PI_BAUD)
#
# Initialize a MyCobot object
# Create object code here for windows version
mc = MyCobot("COM3", 115200)
#By passing the angle parameter, let each joint of the robotic arm move to the position corresponding to [0, 0, 0, 0, 0, 0]
mc.send_angles([0, 0, 0, 0, 0, 0], 50)
# Set the waiting time to ensure that the robotic arm has reached the specified position
time.sleep(2.5)
# Move joint 1 to the 90 position
mc.send_angle(Angle.J1.value, 90, 50)
# Set the waiting time to ensure that the robotic arm has reached the specified position
time.sleep(2)
# The following code can make the robotic arm swing left and right
# set the number of loops
while num > 0:
# Move joint 2 to the 50 position
mc.send_angle(Angle.J2.value, 50, 50)
# Set the waiting time to ensure that the robotic arm has reached the specified position
time.sleep(1.5)
# Move joint 2 to the -50 position
mc.send_angle(Angle.J2.value, -50, 50)
# Set the waiting time to ensure that the robotic arm has reached the specified position
time.sleep(1.5)
num -= 1
#Make the robotic arm retract. You can manually swing the robotic arm, and then use the get_angles() function to get the coordinate sequence,
# use this function to let the robotic arm reach the position you want.
mc.send_angles([88.68, -138.51, 155.65, -128.05, -9.93, -15.29], 50)
# Set the waiting time to ensure that the robotic arm has reached the specified position
time.sleep(2.5)
# Let the robotic arm relax, you can manually swing the robotic arm
mc.release_all_servos()