use the python logging modules everywhere
This commit is contained in:
parent
3ed2040f28
commit
c2c8ab9941
41
urx/urx.py
41
urx/urx.py
@ -68,6 +68,7 @@ __status__ = "Development"
|
|||||||
from threading import Thread, Lock, Condition
|
from threading import Thread, Lock, Condition
|
||||||
import socket
|
import socket
|
||||||
import time
|
import time
|
||||||
|
import logging
|
||||||
|
|
||||||
|
|
||||||
MATH3D = True
|
MATH3D = True
|
||||||
@ -92,6 +93,7 @@ class SecondaryMonitor(Thread):
|
|||||||
"""
|
"""
|
||||||
def __init__(self, host):
|
def __init__(self, host):
|
||||||
Thread.__init__(self)
|
Thread.__init__(self)
|
||||||
|
self.logger = logging.getLogger(self.__class__.__name__)
|
||||||
self._lock = Lock()
|
self._lock = Lock()
|
||||||
self._s_secondary = None
|
self._s_secondary = None
|
||||||
self._dict = {}
|
self._dict = {}
|
||||||
@ -117,6 +119,7 @@ class SecondaryMonitor(Thread):
|
|||||||
|
|
||||||
with self._lock:
|
with self._lock:
|
||||||
prog.strip()
|
prog.strip()
|
||||||
|
self.logger.debug("Sending program: prog")
|
||||||
self._queue.append(prog.encode() + b"\n")
|
self._queue.append(prog.encode() + b"\n")
|
||||||
|
|
||||||
|
|
||||||
@ -140,15 +143,13 @@ class SecondaryMonitor(Thread):
|
|||||||
with self._dictLock:
|
with self._dictLock:
|
||||||
self._dict = urparser.parse(data)
|
self._dict = urparser.parse(data)
|
||||||
except urparser.ParsingException as ex:
|
except urparser.ParsingException as ex:
|
||||||
self._log("Error parsing data from urrobot: " + str(ex) )
|
self.logger.warn("Error parsing data from urrobot: " + str(ex) )
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if "RobotModeData" not in self._dict:
|
if "RobotModeData" not in self._dict:
|
||||||
self._log( "Got a packet from robot without RobotModeData, strange ...")
|
self.logger.warn( "Got a packet from robot without RobotModeData, strange ...")
|
||||||
continue
|
continue
|
||||||
|
|
||||||
#print data["RobotModeData"]
|
|
||||||
|
|
||||||
if self._dict["RobotModeData"]["robotMode"] == 0 \
|
if self._dict["RobotModeData"]["robotMode"] == 0 \
|
||||||
and self._dict["RobotModeData"]["isRealRobotEnabled"] == True \
|
and self._dict["RobotModeData"]["isRealRobotEnabled"] == True \
|
||||||
and self._dict["RobotModeData"]["isEmergencyStopped"] == False \
|
and self._dict["RobotModeData"]["isEmergencyStopped"] == False \
|
||||||
@ -158,7 +159,7 @@ class SecondaryMonitor(Thread):
|
|||||||
self.running = True
|
self.running = True
|
||||||
else:
|
else:
|
||||||
if self.running == True:
|
if self.running == True:
|
||||||
print("Robot not running: ", self._dict["RobotModeData"])
|
self.logger.error("Robot not running: " + str( self._dict["RobotModeData"]))
|
||||||
self.running = False
|
self.running = False
|
||||||
with self._dataEvent:
|
with self._dataEvent:
|
||||||
self._dataEvent.notifyAll()
|
self._dataEvent.notifyAll()
|
||||||
@ -215,9 +216,6 @@ class SecondaryMonitor(Thread):
|
|||||||
with self._lock:
|
with self._lock:
|
||||||
self._s_secondary.close()
|
self._s_secondary.close()
|
||||||
|
|
||||||
def _log(self, msg):
|
|
||||||
print(self.__class__.__name__, ": ", msg)
|
|
||||||
|
|
||||||
|
|
||||||
class URRobot(object):
|
class URRobot(object):
|
||||||
"""
|
"""
|
||||||
@ -228,13 +226,15 @@ class URRobot(object):
|
|||||||
The RT interfaces is only used for the getForce related methods
|
The RT interfaces is only used for the getForce related methods
|
||||||
Rmq: A program sent to the robot i executed immendiatly and any running program is stopped
|
Rmq: A program sent to the robot i executed immendiatly and any running program is stopped
|
||||||
"""
|
"""
|
||||||
def __init__(self, host, useRTInterface=False, debug=False):
|
def __init__(self, host, useRTInterface=False):
|
||||||
|
self.logger = logging.getLogger(self.__class__.__name__)
|
||||||
self.host = host
|
self.host = host
|
||||||
self.debug = debug
|
|
||||||
|
self.logger.info("Opening secondary monitor socket")
|
||||||
self.secmon = SecondaryMonitor(self.host) #data from robot at 10Hz
|
self.secmon = SecondaryMonitor(self.host) #data from robot at 10Hz
|
||||||
|
|
||||||
if useRTInterface:
|
if useRTInterface:
|
||||||
|
self.logger.info("Opening real-time monitor socket")
|
||||||
self.rtmon = urrtmon.URRTMonitor(self.host)# som information is only available on rt interface
|
self.rtmon = urrtmon.URRTMonitor(self.host)# som information is only available on rt interface
|
||||||
else:
|
else:
|
||||||
self.rtmon = None
|
self.rtmon = None
|
||||||
@ -415,8 +415,6 @@ class URRobot(object):
|
|||||||
"""
|
"""
|
||||||
l = self.getl()
|
l = self.getl()
|
||||||
newl = [v + l[i] for i, v in enumerate(tpose)]
|
newl = [v + l[i] for i, v in enumerate(tpose)]
|
||||||
if self.debug:
|
|
||||||
print("going to: ", newl)
|
|
||||||
return self.movel(newl, acc, vel, wait )
|
return self.movel(newl, acc, vel, wait )
|
||||||
|
|
||||||
def movel(self, tpose, acc=0.01, vel=0.01, wait=True):
|
def movel(self, tpose, acc=0.01, vel=0.01, wait=True):
|
||||||
@ -427,8 +425,6 @@ class URRobot(object):
|
|||||||
#todo: should check joints input and velocity
|
#todo: should check joints input and velocity
|
||||||
tpose = [round(i, 2) for i in tpose]
|
tpose = [round(i, 2) for i in tpose]
|
||||||
prog = "movel(p%s, a=%s, v=%s)" % (tpose, acc, vel)
|
prog = "movel(p%s, a=%s, v=%s)" % (tpose, acc, vel)
|
||||||
if self.debug:
|
|
||||||
print("Sending: ", prog)
|
|
||||||
self.sendProgram(prog)
|
self.sendProgram(prog)
|
||||||
if not wait:
|
if not wait:
|
||||||
return None
|
return None
|
||||||
@ -448,8 +444,7 @@ class URRobot(object):
|
|||||||
pose = self.secmon.getCartesianInfo()
|
pose = self.secmon.getCartesianInfo()
|
||||||
if pose:
|
if pose:
|
||||||
pose = [pose["X"], pose["Y"], pose["Z"], pose["Rx"], pose["Ry"], pose["Rz"]]
|
pose = [pose["X"], pose["Y"], pose["Z"], pose["Rx"], pose["Ry"], pose["Rz"]]
|
||||||
if self.debug:
|
self.logger.debug("Current pose from robot: " + str(pose))
|
||||||
print("Got linear position from robot: ", pose)
|
|
||||||
return pose
|
return pose
|
||||||
|
|
||||||
def movels(self, joints, acc, vel , radius, wait=True):
|
def movels(self, joints, acc, vel , radius, wait=True):
|
||||||
@ -493,10 +488,8 @@ class URRobot(object):
|
|||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def _log(self, msg):
|
|
||||||
print("urrobot: ", self.__class__.__name__, ": ", msg)
|
|
||||||
|
|
||||||
def cleanup(self):
|
def cleanup(self):
|
||||||
|
self.logger.info("Closing sockets to robot")
|
||||||
self.secmon.cleanup()
|
self.secmon.cleanup()
|
||||||
if self.rtmon:
|
if self.rtmon:
|
||||||
self.rtmon.stop()
|
self.rtmon.stop()
|
||||||
@ -510,8 +503,10 @@ class Robot(object):
|
|||||||
and includes support for calibrating the robot coordinate system
|
and includes support for calibrating the robot coordinate system
|
||||||
and style portet to PEP 8
|
and style portet to PEP 8
|
||||||
"""
|
"""
|
||||||
def __init__(self, host, useRTInterface=False, debug=False):
|
def __init__(self, host, useRTInterface=False):
|
||||||
self.robot = URRobot(host, useRTInterface, debug)
|
self.robot = URRobot(host, useRTInterface)
|
||||||
|
self.logger = logging.getLogger(self.__class__.__name__)
|
||||||
|
logging.basicConfig(level=logging.DEBUG, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
|
||||||
self.default_linear_acceleration = 0.01
|
self.default_linear_acceleration = 0.01
|
||||||
self.default_linear_velocity = 0.01
|
self.default_linear_velocity = 0.01
|
||||||
|
|
||||||
@ -654,7 +649,7 @@ if __name__ == "__main__":
|
|||||||
#p = r.sendProgram(open("examples/example.prog").read(), wait=False)
|
#p = r.sendProgram(open("examples/example.prog").read(), wait=False)
|
||||||
|
|
||||||
from IPython.frontend.terminal.embed import InteractiveShellEmbed
|
from IPython.frontend.terminal.embed import InteractiveShellEmbed
|
||||||
ipshell = InteractiveShellEmbed( banner1="\nStarting IPython shell, robot object is available\n")
|
ipshell = InteractiveShellEmbed( banner1="\n\n robot object is available \n\n")
|
||||||
ipshell(local_ns=locals())
|
ipshell(local_ns=locals())
|
||||||
|
|
||||||
finally:
|
finally:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user