From 16750f79f4fb90654aa9e5103165195444231b16 Mon Sep 17 00:00:00 2001 From: Olivier R-D Date: Mon, 14 Jan 2013 11:19:35 +0100 Subject: [PATCH] cleanup --- urx/__init__.py | 1 + urx/tracker.py | 6 +++--- urx/urrtmon.py | 16 +++------------- urx/urx.py | 11 +++++++++-- 4 files changed, 16 insertions(+), 18 deletions(-) diff --git a/urx/__init__.py b/urx/__init__.py index e500443..b57ff73 100644 --- a/urx/__init__.py +++ b/urx/__init__.py @@ -5,4 +5,5 @@ Python library to control an UR robot through its TCP/IP interface from .urx import Robot, RobotException, URScript +from .tracker import Tracker diff --git a/urx/tracker.py b/urx/tracker.py index b84cd42..e3f91c0 100644 --- a/urx/tracker.py +++ b/urx/tracker.py @@ -1,7 +1,7 @@ import time from multiprocessing import Process, Queue, Event -from urx.urrtmon import URRTMonitor +from urx import urrtmon class Tracker(Process): @@ -18,7 +18,7 @@ class Tracker(Process): def run(self): self._log("Running") - rtmon = URRTMonitor(self.host) + rtmon = urrtmon.URRTMonitor(self.host) rtmon.start() while not self._stop.is_set(): data = rtmon.get_all_data(wait=True) @@ -36,7 +36,7 @@ class Tracker(Process): def get_result(self): self._stop.set() while not self._finished.is_set(): - time.sleep(0.1) + time.sleep(0.01) return self._queue.get() def shutdown(self, join=True): diff --git a/urx/urrtmon.py b/urx/urrtmon.py index c08e7fd..e28e8d5 100644 --- a/urx/urrtmon.py +++ b/urx/urrtmon.py @@ -19,7 +19,6 @@ import socket import struct import time import threading -import datetime import numpy as np @@ -47,6 +46,7 @@ class URRTMonitor(threading.Thread): self._qTarget = None self._tcp = None self._tcp_force = None + self.__recvTime = 0 def __recv_bytes(self, nBytes): ''' Facility method for receiving exactly "nBytes" bytes from @@ -178,18 +178,8 @@ class URRTMonitor(threading.Thread): self.__recv_rt_data() self._rtSock.close() -i = 1 -def dumptcp(): - global i - tcf = urRTMon.getTcp() - pos = tcf[:3] - rot = tcf[3:] - filename = 'robot%d.txt'%i - print('Dumping file: %s (at time %s)' % (filename, str(datetime.datetime.now()))) - f = file(filename,'w') - f.write((3*'%.5f ' + '\n' + 3*'%.5f ') % tuple(tcf)) - i += 1 - + + def startupInteractive(): global urRTMon diff --git a/urx/urx.py b/urx/urx.py index fe89601..2cfcb6a 100644 --- a/urx/urx.py +++ b/urx/urx.py @@ -75,8 +75,9 @@ except ImportError: MATH3D = False print("pymath3d library could not be found on this computer, disabling use of matrices") -#import urrtmon #temproarely disabled -import urx.urparser as urparser +from urx import urrtmon +from urx import urparser +from urx import tracker class RobotException(Exception): @@ -622,6 +623,12 @@ class Robot(object): def cleanup(self): self.robot.cleanup() + def get_tracker(self): + """ + return an object able to track robot move for logging + """ + return tracker.Tracker(self.robot.host) + if not MATH3D: