xArm6 RoboDK

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.
image

    # 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.

Maybe add a sleep(2) after every “motion enable” command will work. Please give a try and let us know the result. Thanks
self.UARMAPI.motion_enable(enable=True)
time.sleep(2)

I had some luck using the program from RoboDK, but it did not work for me without significant changes. I referred to the SDK examples to adjust the program from RoboDK, which set up xArm state, mode, … differently. I think the SDK and/or use of it could be documented much better since I feel that using it requires a bit more understanding of xARM attributes that are referenced with the functions. I suspect, but have not proven it yet, that there are some initializations needed and attributes to track to achieve what you desire. But, again, that is not clear in the very simple descriptions in SDK API docs.

It’s better to read the “xarm user manual” and part of the “xarm developer manual” before use the arm python sdk.

Do you have an example of the edited code you changed?
May i use yours as a reference?

I got it working but I can’t upload a file here since I’m new. I posted it on robodk’s forum. message me if you can’t find it.

For anyone looking at alternate tools to program the xArm (disclaimer: self promotion) -

In case it’s any help, I’d like to point you to the tool I’m developing called Rebellum at r4robot.com . It’s free to download and I’d be happy to tailor features to user needs as I continue to develop the app.

If you find it useful, you can use promo code REBELLUM100 for a free month of the full feature app.

Please feel free to message me at antonio@r4robot.com

Curious to hear what you all think and very happy to take any feedback,

Antonio

Seems cool,let me try

Failed to sign up the shopify pay account, any way I can download without registration?

Hi Daniel, thanks for giving it a shot! I’ve added direct download links in the homepage under “Download Now”. Let me know if you run into any issues. The Windows version hasn’t been certified yet, so you’ll get a warning when downloading, but the Mac version is certified.

Hi,
I download the software and give a try. That’s quite cool, simple and very easy to use.
Maybe you develop it based on the xArm Python SDK and PyQT6?
And I encounter a problem while using it.
When I connect the robot, it will enable the robot automatically, and when I disconnect the robot, it disable the robot automatically.

With the version V1.00.03 we can control and program the robot, but we can also do that with UFACTORY Studio, so I think you may already have ideas to add more features in the software.
If you have any questions or problems while developing the software, welcome to contact us,
my Email: daniel.wang@ufactory.cc

Hi Daniel,

Thanks again for trying the software! The behavior you mentioned happens by design - it’s one click to get the robot ready for motion (if the emergency stop is not pressed), and motors are disabled upon disconnection.

It’s true that this software does much the same as UFACTORY Studio, but this software was originally developed for a small micro greens farm where the farmers did not have the time or interest to learn Python and play with blockly. I’m also planning to add Computer Vision so that the robot can learn to recognize objects and respond to visual input via webcams - that’ll be more interesting and I’d love to have you try that when it’s ready.

Thanks again for the help and support,

Antonio

Hi Antonio,
Add Computer Vision to the software is cool, looking forward to have a try, please do let me know when it’s ready.
Thanks

1 Like