1、The robot arm swings left and right
Introduction of API
API used to control the robot arm swings left anf right is:
Function: Initialize a MyCobot object.
port：The type of data is String, is the port number that controls the robot arm, and the windows system can view it at the port in Device Manager.
Function: Get the angle of the six joint points of the robot arm
Return Value: The type of return value is list, with six elemental data, corresponding to joints 1 to 6.
Function: Set the angle of six joint points at a time.
degrees：The type of parameter is list. The angle data for the six joint points must be included. The angle value range of the six joint points is -180 to 180.
speed：The type pf data is int, value range 0~100. Represents the speed at which the robot arm runs to the specified position, and the higher the value, the greater the speed.
send_angle(id, degree, speed)
Function: Set the angle of a single joint.
id：Represents the joints of the robotic arm, a total of six joints, with a specific representation. For example, joint1 can be:
degree：Represents the angle of the joint, value range -180 to 180.
speed：Represents the speed of the robot arm
Function: Release the robot arm, let it swing manually at will.
Content of code
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 for MyCobot initialization import time # Initialize a myCobot object mc = MyCobot(PI_PORT, PI_BAUD) # Get the coordinates of the current location angle_datas = mc.get_angles() print(angle_datas) # Pass coordinate parameters with a number of columns, let the robot arm move to the specified position mc.send_angles([0, 0, 0, 0, 0, 0], 50) print(mc.is_paused()) # Set the wait time to ensure that the robot arm has reached the specified position # while not mc.is_paused(): time.sleep(2.5) # Move joint 1 to the position of 90 mc.send_angle(Angle.J1.value, 90, 50) # Set the wait time to ensure that the robot arm has reached the specified position time.sleep(2) # Set the number of cycles num = 5 # Let the robot arm swing left and right while num > 0: # Move joint 2 to the position of 50 mc.send_angle(Angle.J2.value, 50, 50) # Set the wait time to ensure that the robot arm has reached the specified position time.sleep(1.5) # Move joint 2 to the position of -50 mc.send_angle(Angle.J2.value, -50, 50) # Set the wait time to ensure that the robot arm has reached to the specified position time.sleep(1.5) num -= 1 # Let the robot arm shrink. You can swing the robot arm manually and then use the get_angles() function to get the number of coordinate columns. # Use this function to get the robot arm to where you want it to be. mc.send_angles([88.68, -138.51, 155.65, -128.05, -9.93, -15.29], 50) # Set the wait time to ensure that the robot arm has reached to the specified position time.sleep(2.5) # Release the robot arm, let it swing manually at will mc.release_all_servos()
Effects as shown