Hi all,
I was wondering has any made any progress on programming xArm using RoboDK?
i tried to move a linear movement and it have failed to move the robot arm.
A picture is shown below the output on the terminal.
the code generated by the post processor is also shown below.
# Program automatically generated by RoboDK using the post processor for uFactory uArm robots
# Run this file with Python to run the program on the robot
#
# Make sure the xArm Python library is installed or available in the path
import sys
sys.path.insert(0,"C:/RoboDK/Python")
# Import the xArm library
from xarm.wrapper import XArmAPI
def print_message(arg):
print(arg)
def UpdateStatus(arg):
pass
ROBOTCOM_UNKNOWN = -1000
ROBOTCOM_CONNECTION_PROBLEMS = -3
ROBOTCOM_DISCONNECTED = -2
ROBOTCOM_NOT_CONNECTED = -1
ROBOTCOM_READY = 0
ROBOTCOM_WORKING = 1
ROBOTCOM_WAITING = 2
nDOFs_MIN = 6
class ComRobot:
"""Robot class for programming xArm robots"""
LAST_MSG = None # Keep a copy of the last message received
CONNECTED = False # Connection status is known at all times
UARMAPI = None #XArmAPI("127.0.0.1")
BUFFER_SIZE = None
TIMEOUT = None
#Speed and accelerations
LINEARSPEED = 100
LINEARACELL = 30
JOINTSPEED = 100
JOINTACELL = 80
LAST_TARGET_JOINTS = []
# This is executed when the object is created
def __init__(self):
self.BUFFER_SIZE = 512 # bytes
self.TIMEOUT = 5 * 60 # seconds: it must be enough time for a movement to complete
# self.TIMEOUT = 10 # seconds
# destructor
def __del__(self):
self.disconnect()
# Disconnect from robot
def disconnect(self):
self.CONNECTED = False
if self.UARMAPI:
try:
self.UARMAPI.disconnect()
except OSError:
return False
return True
# Connect to robot
def connect(self, ip, port=-1):
global ROBOT_MOVING
self.disconnect()
#print_message('Connecting to robot %s:%i' % (ip, port))
print_message('Connecting to robot %s' % (ip))
# Create new socket connection
UpdateStatus(ROBOTCOM_WORKING)
try:
self.UARMAPI = XArmAPI(ip, do_not_open=False)
self.UARMAPI.motion_enable(enable=True)
self.UARMAPI.set_mode(0)
self.UARMAPI.set_state(state=0)
self.UARMAPI.reset(wait=True)
#self.UARMAPI.register_report_callback(self.monitoringCallback, report_cartesian=False, report_joints=True,
# report_state=False, report_error_code=False, report_warn_code=False,
# report_mtable=False, report_mtbrake=False, report_cmd_num=False)
except Exception as e:
print_message(str(e))
return False
version = self.UARMAPI.version
print_message("API Version:" + str(version))
self.CONNECTED = True
ROBOT_MOVING = False
sys.stdout.flush()
return True
def recv_acknowledge(self):
while True:
#cartesianPosition = self.UARMAPI.get_position(is_radian=False)
jointPosition = self.UARMAPI.angles
print_joints(jointPosition, True)
self.UARMAPI.motion_enable
done = False
if done == True:
break
if self.UARMAPI.angles == self.LAST_TARGET_JOINTS:
done = True
if self.UARMAPI.connected != True:
return False
if self.UARMAPI.has_error == True:
print_message("Error code:" + str(self.UARMAPI.error_code) )
self.UARMAPI.clean_error
return False
if self.UARMAPI.has_warn == True:
print_message("Warning code:" + str(self.UARMAPI.warn_code) )
self.UARMAPI.clean_warn
return False
return True
def MoveJ(self,joints):
try:
self.UARMAPI.set_mode(mode=1) #Mode 1 corresponds to moving
self.UARMAPI.motion_enable(True)
self.UARMAPI.set_servo_angle_j(joints,self.JOINTSPEED,self.JOINTACELL,is_radian=False)
self.LAST_TARGET_JOINTS = joints
except Exception as e:
print_message(str(e))
return False
return True
def MoveL(self,joints):
global nDOFs_MIN
xyzwpr = joints[nDOFs_MIN:]
try:
self.UARMAPI.set_mode(mode=1) #Mode 1 corresponds to moving
self.UARMAPI.motion_enable(True)
self.UARMAPI.set_position(x=xyzwpr[0], y=xyzwpr[1], z=xyzwpr[2], roll=xyzwpr[3], pitch=xyzwpr[4], yaw=xyzwpr[5], speed=self.LINEARSPEED, wait=False)
self.LAST_TARGET_JOINTS = joints
except Exception as e:
print_message(str(e))
return False
return True
def MoveC(self,joints):
try:
self.UARMAPI.set_mode(mode=1) #Mode 1 corresponds to moving
self.UARMAPI.motion_enable(True)
self.UARMAPI.move_circle(pose1=joints[0:6], pose2=joints[7:], percent=50, speed=self.JOINTSPEED, mvacc=self.JOINTACELL, wait=True)
self.LAST_TARGET_JOINTS = joints
except Exception as e:
print_message(str(e))
return False
return True
def getJoints(self):
if (self.UARMAPI.default_is_radian == True):
jointPosition = self.UARMAPI.angles
for i in range(0,len(jointPosition)):
jointPosition[i] = math.degrees(jointPosition[i])
else:
#cartesianPosition = self.UARMAPI.get_position(is_radian=False)
jointPosition = self.UARMAPI.angles
return jointPosition
def setSpeed(self, speed_values):
# speed_values[0] = speed_values[0] # linear speed in mm/s
# speed_values[1] = speed_values[1] # joint speed in mm/s
# speed_values[2] = speed_values[2] # linear acceleration in mm/s2
# speed_values[3] = speed_values[3] # joint acceleration in deg/s2
if (speed_values[0] != -1):
self.LINEARSPEED = speed_values[0]
if (speed_values[1] != -1):
self.JOINTSPEED = speed_values[1]
if (speed_values[2] != -1):
self.LINEARACELL = speed_values[2]
if (speed_values[3] != -1):
self.JOINTACELL = speed_values[3]
return True
def setTool(self,tool_pose):
self.UARMAPI.set_tcp_offset(tool_pose)
return True
def Pause(self,timeMS):
import time
time.sleep(timeMS/1000)
return True
def setRounding(self,rounding):
self.UARMAPI.set_tcp_jerk(rounding)
return True
def setDO(self,digital_IO_State):
self.UARMAPI.set_cgpio_digital_output_function(digital_IO_State[0],digital_IO_State[1])
return True
def WaitDI(self,digital_IO_Num):
import time
start = time.time()
ioNumber = digital_IO_Num[0]
ioState = self.UARMAPI.get_tgpio_digital(ioNumber)
desiredState = digital_IO_Num[1]
try:
timeout = digital_IO_Num[2]
except Exception as e:
e = e
timeout = 0
while not (ioState == desiredState) and (time.time() - start) < timeout:
ioState = self.UARMAPI.get_tgpio_digital(ioNumber)
time.sleep(0.1)
return True
def ConnectRobot():
# Connect to the robot
global robot
ROBOT_IP = "192.168.1.236"
robot = ComRobot()
while not robot.connect(ROBOT_IP):
print_message("Retrying connection...")
import time
time.sleep(0.5)
print_message("Connected to robot: " + ROBOT_IP)
# Program Start: Prog1
def Prog1():
global robot
# Generating program: Prog1
#Program generated by RoboDK v5.1.0 for uFactory xArm6 on 17/09/2020 17:47:18
#Using nominal kinematics.
#robot ref frame set to 0.000, 0.000, 0.000, -0.000, 0.000, -0.000
robot.MoveL([61.279700,10.094400,-43.257900,0.000080,33.163400,61.279600,207.000, 377.776, 196.404, -180.000, -0.000, 0.000])
robot.MoveL([0.000037,-0.000001,0.000000,0.000153,0.000003,-0.000116,207.000, 0.000, 112.002, -180.000, -0.000, 0.000])
return
if __name__ == "__main__":
# Connect to the robot and run the program
ConnectRobot()
Prog1()
Thanks very much if you can help me out.