6、Use of gripper

Introduction of API

1、is_gripper_moving()

Function:Determine if the gripper is running.

Return parameter:

1 means running, 0 means no, and -1 indicates an error

2、set_encoder(joint_id, encoder)

Function:Turn the specified joint point to the specified position

Parameter Description

joint_id:value range 1-7, Represents 1 to 6 joint points and grippers respectively.

encoder:Value range 0~4096,2048 means 0 when the value range is -180--180

3、set_encoders(encoders, sp)

Function:Let the robot arm move to the specified position.

Parameter Description:

encoders:A list collection of six int elements, with the order of six encoder data representing the position of 1 to 6 joint points.

sp:Indicates the rotate speed of the robot arm.

4、get_encoder(joint_id)

Function:Gets encoder data for the specified joint point.

Parameter Description

joint_id:Value range 1-7, reprents 1-6 joint points and grippers respectively.

Return value:

encoder:Indicate the encoder data information of this joint

5、set_gripper_value(value, speed)

Function:Let the gripper turn to the specified position at the specified speed.

Parameter Description:

value:Indicates where the claws are to be reached, value range 0~4096。

speed:Indicates how much speed it turns, value range 0~100。

6、get_gripper_value()

Function:Get the encoder data information of gripper

Return value:

encoder:the data information of gripper

7、set_gripper_state(flag, speed)

Function:Let the gripper reach the specified state at the specified speed.

Parameter Description

flag:1 means claws are closed and 0 means claws are open.

speed:Indicates how quickly the specified state has been reached,value range 0~100。

Content of code

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
from pymycobot.mycobot import MyCobot
import time


def gripper_test(mc):
    print("Start check IO part of api\n")
    # Check if the gripper is moving
    flag = mc.is_gripper_moving()
    print("Is gripper moving: {}".format(flag))
    time.sleep(1)

    # Set the current position to (2048).
    # Use it when you are sure you need it.
    # Gripper has been initialized for a long time. Generally, there
    # is no need to change the method.
    # mc.set_gripper_ini()
    # Set joint point 1, let it rotates to the position 2048
    mc.set_encoder(1, 2048)
    time.sleep(2)
    # Set 6 joint position, let the robot arm rotates to the position at 20 speeds.
    mc.set_encoders([1024, 1024, 1024, 1024, 1024, 1024], 20)
    time.sleep(3)
    # Get location information for joint point 1
    print(mc.get_encoder(1))
    # Set the gripper rotate to the position 2048
    mc.set_encoder(7, 2048)
    time.sleep(3)
    # Set the gripper rotate to the position 1300
    mc.set_encoder(7, 1300)
    time.sleep(3)

    # Set the gripper to the state 2048 at 70 speeds.
    mc.set_gripper_value(2048, 70)
    time.sleep(3)
    # Set the gripper to the state 1500 at 70 speeds.
    mc.set_gripper_value(1500, 70)
    time.sleep(3)

    # Set the state of gripper,Let it open its paws quickly at 70 speeds
    mc.set_gripper_state(0, 70)
    time.sleep(3)
    # Set the state of gripper,Let it close its paws quickly at 70 speeds
    mc.set_gripper_state(1, 70)
    time.sleep(3)

    # Get the value of gripper
    print("")
    print(mc.get_gripper_value())


if __name__ == "__main__":
    # Initialize a MyCobot object
    mc = MyCobot(PI_PORT, PI_BAUD)
    # Let it move to the zero position
    mc.set_encoders([2048, 2048, 2048, 2048, 2048, 2048], 20)
    time.sleep(3)
    gripper_test(mc)

Effects as shown

2

results matching ""

    No results matching ""