From 92a7c1812e9527180e9dff36d6543157ccd7aeee Mon Sep 17 00:00:00 2001 From: Olivier R-D Date: Fri, 10 Apr 2015 12:39:19 +0200 Subject: [PATCH] renamed cleanup to close, this is more common --- examples/joystick_control.py | 6 ++--- examples/matrices.py | 2 +- examples/simple.py | 2 +- examples/spnav_control.py | 2 +- examples/test_all.py | 4 +-- examples/test_movep.py | 2 +- tools/fakerobot.py | 4 +-- tools/get_rob.py | 4 +-- urx/robot.py | 5 ++-- urx/urrtmon.py | 48 +++++------------------------------- urx/ursecmon.py | 8 +++--- 11 files changed, 25 insertions(+), 62 deletions(-) diff --git a/examples/joystick_control.py b/examples/joystick_control.py index 0e3367c..9987e5f 100644 --- a/examples/joystick_control.py +++ b/examples/joystick_control.py @@ -114,7 +114,7 @@ class Service(object): time.sleep(0.12)#URX secondday port accepts command at 10Hz, no need to go faster - def cleanup(self): + def close(self): if self.joystick: self.joystick.quit() @@ -135,5 +135,5 @@ if __name__ == "__main__": try: service.loop() finally: - robot.cleanup() - service.cleanup() + robot.close() + service.close() diff --git a/examples/matrices.py b/examples/matrices.py index 1abc791..1a86809 100644 --- a/examples/matrices.py +++ b/examples/matrices.py @@ -33,5 +33,5 @@ if __name__ == "__main__": finally: - rob.cleanup() + rob.close() diff --git a/examples/simple.py b/examples/simple.py index 12d1e7f..1b57a68 100644 --- a/examples/simple.py +++ b/examples/simple.py @@ -23,5 +23,5 @@ if __name__ == "__main__": rob.translate_tool((0, 0, -l), acc=a, vel=v) rob.translate_tool((0, 0, l), acc=a, vel=v) finally: - rob.cleanup() + rob.close() diff --git a/examples/spnav_control.py b/examples/spnav_control.py index 3676e98..d9899da 100644 --- a/examples/spnav_control.py +++ b/examples/spnav_control.py @@ -87,7 +87,7 @@ if __name__ == '__main__': try: service.loop() finally: - robot.cleanup() + robot.close() spnav.spnav_close() diff --git a/examples/test_all.py b/examples/test_all.py index 6824faf..1259c68 100644 --- a/examples/test_all.py +++ b/examples/test_all.py @@ -23,7 +23,7 @@ if __name__ == "__main__": else: do_wait = True - rob = urx.Robot("192.168.1.6", logLevel=logging.INFO) + rob = urx.Robot("192.168.1.6") rob.set_tcp((0, 0, 0, 0, 0, 0)) rob.set_payload(0.5, (0, 0, 0)) try: @@ -99,5 +99,5 @@ if __name__ == "__main__": finally: - rob.cleanup() + rob.close() diff --git a/examples/test_movep.py b/examples/test_movep.py index f60ab82..7be7748 100644 --- a/examples/test_movep.py +++ b/examples/test_movep.py @@ -36,5 +36,5 @@ if __name__ == "__main__": rob.movep(pose, acc=a, vel=v, radius=0, wait=True) finally: - rob.cleanup() + rob.close() diff --git a/tools/fakerobot.py b/tools/fakerobot.py index 66aeb21..2d5df78 100644 --- a/tools/fakerobot.py +++ b/tools/fakerobot.py @@ -34,7 +34,7 @@ class Server(socketserver.ThreadingMixIn, socketserver.TCPServer): """ self.handlers = [] - def cleanup(self): + def close(self): for handler in self.handlers: handler.request.shutdown(socket.SHUT_RDWR) handler.request.close() @@ -63,4 +63,4 @@ if __name__ == "__main__": handler.request.sendall(packet) finally: print("Shutting down server") - server.cleanup() + server.close() diff --git a/tools/get_rob.py b/tools/get_rob.py index f198d41..417497d 100644 --- a/tools/get_rob.py +++ b/tools/get_rob.py @@ -13,10 +13,10 @@ if __name__ == "__main__": else: host = 'localhost' try: - robot = Robot( host )#, logLevel=logging.DEBUG, parserLogLevel=logging.DEBUG) + robot = Robot(host) r = robot embed() finally: if "robot" in dir(): - robot.cleanup() + robot.close() diff --git a/urx/robot.py b/urx/robot.py index da1bd40..16d1d80 100644 --- a/urx/robot.py +++ b/urx/robot.py @@ -360,15 +360,14 @@ class URRobot(object): def stop(self): self.stopj() - def cleanup(self): + def close(self): """ close connection to robot and stop internal thread """ self.logger.info("Closing sockets to robot") - self.secmon.cleanup() + self.secmon.close() if self.rtmon: self.rtmon.stop() - shutdown = cleanup # this might be wrong since we could also shutdown the robot hardware from this script def set_freedrive(self, val): """ diff --git a/urx/urrtmon.py b/urx/urrtmon.py index 5441084..ac87966 100644 --- a/urx/urrtmon.py +++ b/urx/urrtmon.py @@ -32,12 +32,9 @@ class URRTMonitor(threading.Thread): # pose is not included! rtstruct540 = struct.Struct('>d6d6d6d6d6d6d6d6d18d') - def __init__(self, urHost, loglevel=logging.WARNING): + def __init__(self, urHost): threading.Thread.__init__(self) self.logger = logging.getLogger(self.__class__.__name__) - if len(logging.root.handlers) == 0: # dirty hack - logging.basicConfig() - self.logger.setLevel(loglevel) self.daemon = True self._stop_event = True self._dataEvent = threading.Condition() @@ -141,7 +138,7 @@ class URRTMonitor(threading.Thread): timestamp = self.__recvTime pkgsize = struct.unpack('>i', head)[0] self.logger.debug( - 'Received header telling that package is %d bytes long' % + 'Received header telling that package is %s bytes long', pkgsize) payload = self.__recv_bytes(pkgsize - 4) if pkgsize >= 692: @@ -150,7 +147,7 @@ class URRTMonitor(threading.Thread): unp = self.rtstruct540.unpack(payload[:self.rtstruct540.size]) else: self.logger.warning( - 'Error, Received packet of length smaller than 540: ', + 'Error, Received packet of length smaller than 540: %s ', pkgsize) return @@ -165,9 +162,8 @@ class URRTMonitor(threading.Thread): self._ctrlTimestamp - self._last_ctrl_ts) > 0.010: self.logger.warning( - "Error the controller failed to send us a packet: time since last packet {}s ".format( - self._ctrlTimestamp - - self._last_ctrl_ts)) + "Error the controller failed to send us a packet: time since last packet %s s ", + self._ctrlTimestamp - self._last_ctrl_ts) self._last_ctrl_ts = self._ctrlTimestamp self._qActual = np.array(unp[31:37]) self._qTarget = np.array(unp[1:7]) @@ -246,7 +242,7 @@ class URRTMonitor(threading.Thread): #print(self.__class__.__name__+': Stopping') self._stop_event = True - def cleanup(self): + def close(self): self.stop() self.join() @@ -258,35 +254,3 @@ class URRTMonitor(threading.Thread): self._rtSock.close() -def startupInteractive(): - from optparse import OptionParser - from IPython import embed - # Require the urhost arg. - parser = OptionParser() - parser.add_option( - '--debug', - action='store_true', - default=False, - dest='debug') - parser.add_option( - '--start', - action='store_true', - default=False, - dest='start') - opts, args = parser.parse_args() - if len(args) != 1: - raise Exception('Must have argument with ur-host name or ip!') - urHost = args[0] - print('Connecting to UR real-time socket inteface on "%s"' % urHost) - # # Start the connectors - urRTMon = URRTMonitor(urHost, debug=opts.debug) - # # Register for hard shutdown - try: - if opts.start: - urRTMon.start() - embed() - finally: - urRTMon.stop() - -if __name__ == '__main__': - startupInteractive() diff --git a/urx/ursecmon.py b/urx/ursecmon.py index 57494e0..b202c0c 100644 --- a/urx/ursecmon.py +++ b/urx/ursecmon.py @@ -99,7 +99,7 @@ class ParserUtils(object): else: self.logger.debug("Message type parser not implemented %s", tmp) else: - self.logger.debug("Unknown packet type %s with size %s" % (ptype, psize)) + self.logger.debug("Unknown packet type %s with size %s", ptype, psize) return allData @@ -178,12 +178,12 @@ class ParserUtils(object): counter += 1 if counter > limit: self.logger.warn("tried %s times to find a packet in data, advertised packet size: %s, type: %s", counter, psize, ptype) - self.logger.warn("Data length: {}".format(len(data))) + self.logger.warn("Data length: %s", len(data)) limit = limit * 10 elif len(data) >= psize: self.logger.debug("Got packet with size %s and type %s", psize, ptype) if counter: - self.logger.info("Remove {0} bytes of garbage at begining of packet".format(counter)) + self.logger.info("Remove %s bytes of garbage at begining of packet", counter) # ok we we have somehting which looks like a packet" return (data[:psize], data[psize:]) else: @@ -389,7 +389,7 @@ class SecondaryMonitor(Thread): with self._dictLock: return self._dict["RobotModeData"]["isProgramRunning"] - def cleanup(self): + def close(self): self._trystop = True self.join() # with self._dataEvent: #wake up any thread that may be waiting for data before we close. Should we do that?