Gripper control

It is mainly used to inspect and operate the robot arm. First install and connect the gripper onto the robot arm. 1. For an adaptive gripper, insert it on the pin on the atom, as shown in the following figure:

7.5-1

For an electric gripper, insert it into the 485 interface on the top, as shown in the following figure:

Note: myCobot 280-m5 has no electric gripper, only myCobot 320-m5 has an electric gripper.

7.5-2

1 is_gripper_moving( )

  • Function: to determine whether the gripper is running.
  • Return value:
    • 0: means that the gripper is not running.
    • 1: means that the gripper is running.
    • -1: means an error.

2 set_gripper_value(value, speed)

  • Function: to make the gripper rotate to a specified position at a specified speed.
  • Description of parameters:
    • value: means the position to be reached by the gripper, ranging from 0 to 256.
    • speed: means the speed of rotation, ranging from 0 to 100.
  • Return value: None

3 get_gripper_value()

  • Function: to obtain the data information on the encoder of the gripper.
  • Return value: to obtain the data information of the gripper.

4 set_gripper_int()

  • Function: to set the initial position of the gripper. Set the current position to 2048
  • return value: None

5 set_gripper_state(flag, speed)

  • Function: to make the gripper enter a specified state at a specified speed. 、
  • Description of parameters:
    • flag: 1 means that the gripper is closed, 0 means thatthe gripper is open.
    • speed: means the speed at which the gripper reaches a specified state, ranging from 0 to 100.
  • Return value: None

Cases

For more cases and running result videos, see 7.7 Use Cases.

from pymycobot.mycobot import MyCobot        
from pymycobot import PI_PORT, PI_BAUD  # When using the Raspberry Pi version of mycobot, these two variables can be referenced to initialize MyCobot
import time
#Enter the above code to import the packages required by the project

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 to rotate to the position of 2048
    mc.set_encoder(1, 2048)
    time.sleep(2)
    # Set six joint positions and let the robotic arm rotate to this position at a speed of 20
    mc.set_encoders([1024, 1024, 1024, 1024, 1024, 1024], 20)
    time.sleep(3)
    # Get the position information of joint point 1
    print(mc.get_encoder(1))
    # Set the gripper to rotate to the position of 2048
    mc.set_encoder(7, 2048)
    time.sleep(3)
    # Set the gripper to rotate to the position of 1300
    mc.set_encoder(7, 1300)
    time.sleep(3)

    # Let the gripper reach the state of 2048 at a speed of 70
    mc.set_gripper_value(2048, 70)
    time.sleep(3)
    # Let the gripper reach the state of 1500 at a speed of 70
    mc.set_gripper_value(1500, 70)
    time.sleep(3)

    # Set the state of the gripper to quickly open the gripper at a speed of 70
    mc.set_gripper_state(0, 70)
    time.sleep(3)
    # Set the state of the gripper so that it quickly closes the gripper at a speed of 70
    mc.set_gripper_state(1, 70)
    time.sleep(3)

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


if __name__ == "__main__":
    # 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 Raspberry Pi version below
    mc = MyCobot(PI_PORT, PI_BAUD)
    # make it move to zero position
    mc.set_encoders([2048, 2048, 2048, 2048, 2048, 2048], 20)
    time.sleep(3)
    gripper_test(mc)

results matching ""

    No results matching ""