Real time control of UR5 CB3 arm

Hi,

I am trying to create a easy script that takes inn sensor data form the position of a hand and use that data to move a UR5 CB3 arm in real time. I think using ROS/ROS2 for this might be a better solution, but for now it seems a bit daunting to learn ROS.

A motion sensor feeds the system with coordinates (X, Y and Z). The idea is to use this directly to set the position of the arm with ‘movej’ or similar.

The code works for first point, and the arm moves to the specified position, but after that the system slows down. I think the arm tries to move to alle the positions data points received from the sensor.

Some ideas of a better way to do this?

code:

import Leap, sys, URBasic, URBasic.urScript, time

host = ‘192.168.12.128’

robotModle = URBasic.robotModel.RobotModel()
robot = URBasic.urScriptExt.UrScriptExt(host=host,robotModel=robotModle)

class SampleListener(Leap.Listener):

def on_frame(self, controller):

    frame = controller.frame()
    for hand in frame.hands:

        x, y, z = (hand.palm_position[0]/500, hand.palm_position[1]/1000, hand.palm_position[2]/500)
        print(x, y, z, frame)
        robot.movel(pose=[z,x,y, -0,3.14,0], a=5000, v=5000)
    time.sleep(1)    

def ExampleurScriptLEAP():

    listener = SampleListener()
    controller = Leap.Controller()
    controller.add_listener(listener)
 
    print("Press Enter to quit...")
    try:
        sys.stdin.readline()
    except KeyboardInterrupt:
        pass
    finally:
        controller.remove_listener(listener)
        robot.close()
    SampleListener.frame = 0

if name == ‘main’:
ExampleurScriptLEAP()

Petter