If your xArm gipper sometimes open/close even you does not send gripper control commands, and the firmware version of the xArm gripper is equal or earlier than 3.5.0(you can get the xarm gripper firmware version with xArm Studio-Settings-End Efector-xArm Gripper-Get Version )
Please copy the codes and paste to the built-in Python IDE of the xArm Studio, change the ‘192.168.1.xxx’ to the IP address of your xArm control box, and then run it.
import os
import sys
import time
sys.path.append(os.path.join(os.path.dirname(__file__), '../../..'))
from xarm.wrapper import XArmAPI
arm = XArmAPI('192.168.1.XXX')
time.sleep(0.5)
if arm.warn_code != 0:
arm.clean_warn()
if arm.error_code != 0:
arm.clean_error()
def bytes_to_u16(data):
data_u16 = data[0] << 8 | data[1]
return data_u16
def u16_to_bytes(data):
bts = bytes([data // 256 % 256])
bts += bytes([data % 256])
return bts
print(arm.get_gripper_version())
ret = arm.core.gripper_modbus_r16s(0x0105, 1)
print("gripper io ctrl mode:%d"%bytes_to_u16(ret[5:7]))
ret=arm.core.gripper_modbus_w16s(0x1105,u16_to_bytes(1),1)
print(ret)
ret = arm.core.gripper_modbus_r16s(0x0105, 1)
print("gripper io ctrl mode:%d"%bytes_to_u16(ret[5:7]))