cleanup, move some methods to ursecmon
This commit is contained in:
parent
09e446ec70
commit
9f541a4dea
@ -18,6 +18,7 @@ if __name__ == "__main__":
|
|||||||
a = 0.3
|
a = 0.3
|
||||||
r = 0.01
|
r = 0.01
|
||||||
print("Digital out 0 and 1 are: ", rob.get_digital_out(0), rob.get_digital_out(1) )
|
print("Digital out 0 and 1 are: ", rob.get_digital_out(0), rob.get_digital_out(1) )
|
||||||
|
print("Analog inputs are: ", rob.get_analog_inputs())
|
||||||
j = rob.getj()
|
j = rob.getj()
|
||||||
print("Initial joint configuration is ", j)
|
print("Initial joint configuration is ", j)
|
||||||
t = rob.get_transform()
|
t = rob.get_transform()
|
||||||
|
45
urx/robot.py
45
urx/robot.py
@ -7,7 +7,6 @@ from __future__ import absolute_import # necessary for import tricks to work wit
|
|||||||
|
|
||||||
__author__ = "Olivier Roulet-Dubonnet"
|
__author__ = "Olivier Roulet-Dubonnet"
|
||||||
__copyright__ = "Copyright 2011-2013, Sintef Raufoss Manufacturing"
|
__copyright__ = "Copyright 2011-2013, Sintef Raufoss Manufacturing"
|
||||||
__credits__ = ["Olivier Roulet-Dubonnet"]
|
|
||||||
__license__ = "GPLv3"
|
__license__ = "GPLv3"
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
@ -19,7 +18,7 @@ try:
|
|||||||
import numpy as np
|
import numpy as np
|
||||||
except ImportError:
|
except ImportError:
|
||||||
MATH3D = False
|
MATH3D = False
|
||||||
print("pymath3d library could not be found on this computer, disabling use of matrices")
|
print("python-math3d library could not be found on this computer, disabling use of matrices")
|
||||||
|
|
||||||
from urx import urrtmon
|
from urx import urrtmon
|
||||||
from urx import ursecmon
|
from urx import ursecmon
|
||||||
@ -54,10 +53,10 @@ class URRobot(object):
|
|||||||
self.rtmon = self.get_realtime_monitor()
|
self.rtmon = self.get_realtime_monitor()
|
||||||
#the next 3 values must be conservative! otherwise we may wait forever
|
#the next 3 values must be conservative! otherwise we may wait forever
|
||||||
self.joinEpsilon = 0.01 # precision of joint movem used to wait for move completion
|
self.joinEpsilon = 0.01 # precision of joint movem used to wait for move completion
|
||||||
#URScript is limited in the character length of floats it accepts
|
# It seems URScript is limited in the character length of floats it accepts
|
||||||
self.max_float_length = 6 # FIXME: check max length!!!
|
self.max_float_length = 6 # FIXME: check max length!!!
|
||||||
|
|
||||||
self.secmon.wait() # make sure we get data to not suprise clients
|
self.secmon.wait() # make sure we get data from robot before letting clients access our methods
|
||||||
|
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
@ -143,47 +142,31 @@ class URRobot(object):
|
|||||||
"""
|
"""
|
||||||
get analog input
|
get analog input
|
||||||
"""
|
"""
|
||||||
data = self.secmon.get_all_data()
|
return self.secmon.get_analog_inputs()
|
||||||
return data["MasterBoardData"]["analogInput0"], data["MasterBoardData"]["analogInput1"]
|
|
||||||
|
|
||||||
|
def get_analog_in(self, nb, wait=False):
|
||||||
def get_analog_in(self, nb):
|
|
||||||
"""
|
"""
|
||||||
get analog input
|
get analog input
|
||||||
"""
|
"""
|
||||||
data = self.secmon.get_all_data()
|
return self.secmon.get_analog_in(nb, wait)
|
||||||
return data["MasterBoardData"]["analogInput" + str(nb)]
|
|
||||||
|
|
||||||
def get_digital_in_bits(self):
|
def get_digital_in_bits(self):
|
||||||
"""
|
"""
|
||||||
get digital output
|
get digital output
|
||||||
"""
|
"""
|
||||||
data = self.secmon.get_all_data()
|
return self.secmon.get_digital_in_bits()
|
||||||
return data["MasterBoardData"]["digitalInputBits"]
|
|
||||||
|
|
||||||
def get_digital_in(self, nb):
|
def get_digital_in(self, nb, wait=False):
|
||||||
"""
|
"""
|
||||||
get digital output
|
get digital output
|
||||||
"""
|
"""
|
||||||
data = self.secmon.get_all_data()
|
return self.secmon.get_digital_in(nb, wait)
|
||||||
val = data["MasterBoardData"]["digitalInputBits"]
|
|
||||||
mask = 1 << nb
|
|
||||||
if (val & mask):
|
|
||||||
return 1
|
|
||||||
else:
|
|
||||||
return 0
|
|
||||||
|
|
||||||
def get_digital_out(self, val):
|
def get_digital_out(self, val, wait=False):
|
||||||
"""
|
"""
|
||||||
get digital output
|
get digital output
|
||||||
"""
|
"""
|
||||||
data = self.secmon.get_all_data()
|
return self.secmon.get_digital_out(val , wait)
|
||||||
output = data["MasterBoardData"]["digitalOutputBits"]
|
|
||||||
mask = 1 << val
|
|
||||||
if (output & mask):
|
|
||||||
return 1
|
|
||||||
else:
|
|
||||||
return 0
|
|
||||||
|
|
||||||
def set_analog_out(self, output, val):
|
def set_analog_out(self, output, val):
|
||||||
"""
|
"""
|
||||||
@ -236,7 +219,7 @@ class URRobot(object):
|
|||||||
for i in range(0, 6):
|
for i in range(0, 6):
|
||||||
#Rmq: q_target is an interpolated target we have no control over
|
#Rmq: q_target is an interpolated target we have no control over
|
||||||
if abs(jts["q_actual%s"%i] - jts["q_target%s"%i]) > self.joinEpsilon:
|
if abs(jts["q_actual%s"%i] - jts["q_target%s"%i]) > self.joinEpsilon:
|
||||||
print("Waiting for end move, q_actual is {}, q_target is {}, diff is {}, epsilon is {}".format( jts["q_actual%s"%i], jts["q_target%s"%i] , jts["q_actual%s"%i] - jts["q_target%s"%i], self.joinEpsilon))
|
self.logger.debug("Waiting for end move, q_actual is {}, q_target is {}, diff is {}, epsilon is {}".format( jts["q_actual%s"%i], jts["q_target%s"%i] , jts["q_actual%s"%i] - jts["q_target%s"%i], self.joinEpsilon))
|
||||||
finished = False
|
finished = False
|
||||||
break
|
break
|
||||||
if finished and not self.secmon.is_program_running():
|
if finished and not self.secmon.is_program_running():
|
||||||
@ -410,7 +393,7 @@ class URRobot(object):
|
|||||||
class Robot(URRobot):
|
class Robot(URRobot):
|
||||||
"""
|
"""
|
||||||
Generic Python interface to an industrial robot.
|
Generic Python interface to an industrial robot.
|
||||||
Compare to the URRobot class, this class adds the possibilty to work directly with matrices
|
Compared to the URRobot class, this class adds the possibilty to work directly with matrices
|
||||||
and includes support for calibrating the robot coordinate system
|
and includes support for calibrating the robot coordinate system
|
||||||
"""
|
"""
|
||||||
def __init__(self, host, useRTInterface=False, logLevel = logging.WARN, parserLogLevel=logging.WARN):
|
def __init__(self, host, useRTInterface=False, logLevel = logging.WARN, parserLogLevel=logging.WARN):
|
||||||
@ -499,6 +482,8 @@ class Robot(URRobot):
|
|||||||
if pose != None : #movel does not return anything when wait is False
|
if pose != None : #movel does not return anything when wait is False
|
||||||
return self.csys_inv * m3d.Transform(pose)
|
return self.csys_inv * m3d.Transform(pose)
|
||||||
|
|
||||||
|
set_transform = apply_transform #since we have set_pos, set_orient, we should be consistent and use set for tranform to ..
|
||||||
|
|
||||||
def add_transform_base(self, trans, acc=None, vel=None, wait=True, process=False):
|
def add_transform_base(self, trans, acc=None, vel=None, wait=True, process=False):
|
||||||
"""
|
"""
|
||||||
Add transform expressed in base coordinate
|
Add transform expressed in base coordinate
|
||||||
|
@ -325,6 +325,46 @@ class SecondaryMonitor(Thread):
|
|||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
def get_digital_out(self, nb, wait=False):
|
||||||
|
if wait:
|
||||||
|
self.wait()
|
||||||
|
with self._dictLock:
|
||||||
|
output = self._dict["MasterBoardData"]["digitalOutputBits"]
|
||||||
|
mask = 1 << nb
|
||||||
|
if (output & mask):
|
||||||
|
return 1
|
||||||
|
else:
|
||||||
|
return 0
|
||||||
|
|
||||||
|
def get_digital_in(self, nb, wait=False):
|
||||||
|
if wait:
|
||||||
|
self.wait()
|
||||||
|
with self._dictLock:
|
||||||
|
output = self._dict["MasterBoardData"]["digitalInputBits"]
|
||||||
|
mask = 1 << nb
|
||||||
|
if (output & mask):
|
||||||
|
return 1
|
||||||
|
else:
|
||||||
|
return 0
|
||||||
|
|
||||||
|
def get_analog_in(self, nb, wait=False):
|
||||||
|
if wait:
|
||||||
|
self.wait()
|
||||||
|
with self._dictLock:
|
||||||
|
return self._dict["MasterBoardData"]["analogInput" + str(nb)]
|
||||||
|
|
||||||
|
def get_digital_in_bits(self, wait=False):
|
||||||
|
if wait:
|
||||||
|
self.wait()
|
||||||
|
with self._dictLock:
|
||||||
|
return self._dict["MasterBoardData"]["digitalInputBits"]
|
||||||
|
|
||||||
|
def get_analog_inputs(self, wait=False):
|
||||||
|
if wait:
|
||||||
|
self.wait()
|
||||||
|
with self._dictLock:
|
||||||
|
return self._dict["MasterBoardData"]["analogInput0"], self._dict["MasterBoardData"]["analogInput1"]
|
||||||
|
|
||||||
def is_program_running(self, wait=False):
|
def is_program_running(self, wait=False):
|
||||||
"""
|
"""
|
||||||
return True if robot is executing a program
|
return True if robot is executing a program
|
||||||
|
Loading…
x
Reference in New Issue
Block a user