运行线程时出现运行时错误

时间:2018-07-11 22:41:53

标签: python multithreading runtime-error robotics

我的学校有一个UR10协作机器人,我正在尝试对其进行编程,因此在按住数字输入时手臂会向左移动,但是当我多次执行此操作或在告诉手臂进行以下操作后尝试执行其他任务我得到一个运行时错误。

我对python线程还比较陌生,我认为这可能是我的问题,但我不确定。这是我的代码。

import URBasic
from threading import Event, Thread

class UR10(object):
    def __init__(self):
        #logging.basicConfig(level=logging.INFO)
        # robot = urx.Robot("localhost")
        # Establishes connection to UR-10 via IP address
        # print("establishing connection")
        # Robot = urx.Robot("IP ADDRESS FOR UR10")

        host = '192.168.100.82'
        print("Robot object is available as robot or r")

        self.acc = .9
        self.vel = .9

        self.RobotModel = URBasic.robotModel.RobotModel()
        self.r = URBasic.urScriptExt.UrScriptExt(host=host, robotModel=self.RobotModel)
        self.r.reset_error()

        self.DigInputsDefault = False
        self.PreviousBtn_Value = 0
        self.ButtonVal = 0
        self.CurrentBtn_Val = 0

        self.Start = True
        self.Send_Stop = False

        print("move")
        #self.r.movel(pose=[-0.0244, -0.6092, 0.4377, -0.2924, 2.2109, -2.1756], a=.05, v=self.vel)
        pose = [-0.0244, -0.6092, 0.4377, -0.2924, 2.2109, -2.1756]
        self.r.movel(pose, a=.05, v=self.vel)


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

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

        MoveStopThread = Thread(target = self.StopMove)
        MoveStopThread.setDaemon(True)
        MoveStopThread.start()

        FreeDriveThread = Thread(target=self.FreeDrive)
        FreeDriveThread.setDaemon(True)
        FreeDriveThread.start()

    def FreeDrive(self):
        while True:
            self.Teaching()
    def Teaching(self):
        #print("self.FreeDriveSignal is........{}".format(self.FreeDriveSignal))
        while self.FreeDriveSignal:
            self.r.freedrive_mode(self)
            #enters free drive mode and closes it after 1 sec. Constantly looping so as long as button was clicked then free drive is enabled.
        else:
            pass

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

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

        self.ButtonVal = self.r.get_in(0, False)

        self.In_1 = self.r.get_in(1, False)
        self.In_2 = self.r.get_in(2, False)

        self.CurrentBtn_Val = self.ButtonVal
        #checks to see if the button state has changed
        if (self.PreviousBtn_Value == 0) & (self.CurrentBtn_Val == 1):
            print("Button has been pressed")
            print("free drive state has changed")
            print("Digital Input is........{}".format(self.DigInputsDefault))
            self.DigInputsDefault = not self.DigInputsDefault
            print("Digital After press confirmation........{}".format(self.DigInputsDefault))
        else:
            pass

        self.FreeDriveSignal = self.DigInputsDefault
        self.PreviousBtn_Value = self.CurrentBtn_Val

    def StopMove(self):
        while True:
            self.MoveStopper()
    def MoveStopper(self):
        self.r.reset_error()
        if (self.In_1 == False) & (self.Send_Stop == False):
            #print(self.Send_Stop)

            if self.Start == False:
                self.Send_Stop = True #send signal to stop
            else:
                pass
            #pose = self.r.get_actual_tcp_pose()
            #self.r.movel(pose, a = .015, v =.2)
            self.r.stopj(.05)

        elif self.Send_Stop == True:
            pass

    def MoveThread(self):
        while True:
            self.LinearMovement()
    def LinearMovement(self):
        if (self.In_1 == True) & (self.Send_Stop == True): #have input and we have already stopped previously
            self.r.reset_error()

            self.Send_Stop = False
            v = [.025, 0, 0, 0, 0, 0]
            self.r.speedl(v, a=.015, t=100, aRot=None, wait = True)
            self.r.reset_error()
        elif (self.In_1 == True):
            self.r.reset_error()
            self.Send_Stop = False

            v = [.025, 0, 0, 0, 0, 0]
            a = 0.025
            self.r.speedl(v, a=.015, t=100, aRot=None, wait=False)
            self.r.reset_error()
        else:
            pass

Robee = UR10()

该错误发生在MoveStopper()中,我得到的主要两个错误是

RuntimeError:启动之前无法加入线程

RuntimeError:机器人程序执行错误!!! *特定于URbasic库

通过搜索RopeRobotics URInterface可以找到URbasic

0 个答案:

没有答案