Search code examples
pythonmultithreadingroboticsisr

Create interrupt (ISR) to create smooth robotic arm motion


My school has a robotic arm (UR-10) that's hooked up to some buttons and I wanted to program it so the arm could move left and right smoothly when those buttons are clicked.

Currently, I'm finding the arm just moves then stops then moves and stops in a jerking fashion.

I wanted to implement an interrupt that could sense while a button is pressed down then the arm would continuously move by iterating through the loop fast enough so the arm would move without stopping. That is until the button is released.

If there is an easier way to implement this I would love to hear it.

Thanks!

Below is my code.

import urx #UR-10 library
from threading import Thread

class UR10(object):
def __init__(self):

    # Establishes connection to UR-10 via IP address
    print("establishing connection")
    Robot = urx.Robot("192.168.100.82")
    self.r = Robot
    print("Robot object is available as robot or r")

    CheckingDigital_Inputs = Thread(target=self.ThreadChecker)
    CheckingDigital_Inputs.setDaemon(True)
    CheckingDigital_Inputs.start()

    MoveThread = Thread(target = self.MoveThread)
    MoveThread.setDaemon(True)
    MoveThread.start()

def ThreadChecker(self):
    while True:
        self.TestingInputs()

def TestingInputs(self):
    #Values = self.r.get_digital_in()

    self.In_1 = self.r.get_digital_in(1)
    self.In_2 = self.r.get_digital_in(2)

    #print("Digital Input 1 is {},  Digital Input 2 is {}".format(Values1, Values2))

def MoveThread(self):
    while True:
        self.LinearMovement()

def LinearMovement(self):
    #print("linear move")
    #need to run at 125khz
    while self.In_1:
        print("move right linear")

        l = 0.05
        v = 0.05
        a = 0.05

        pose = self.r.getl()
        print(pose)
        pose[0] += .01
        self.r.movel(pose, acc=a, vel=v)

Solution

  • The library code you are using says (in its description of a method):

    This method is usefull since any new command from python to robot make the robot stop

    https://github.com/SintefRaufossManufacturing/python-urx/blob/193577c0efed8a24d00bd12b3b6e0c7ffefb9dd9/urx/urrobot.py#L356-L357

    So it may not be possible to have the robot move continuously by issuing a bunch of commands, since it stops every time it gets a new command.

    You need to figure out where the furthest place you want to move the robot to is, issue a command to move it there when the button is first pressed (with wait=False, so that your code doesn't sit around waiting for the robot to finish moving), and then use self.r.stop() to stop the robot whenever the button is released.