add prototype fake robot, more debug logging
This commit is contained in:
65
tools/fakerobot.py
Normal file
65
tools/fakerobot.py
Normal file
@@ -0,0 +1,65 @@
|
||||
import socket
|
||||
import threading
|
||||
import socketserver
|
||||
import time
|
||||
|
||||
class RequestHandler(socketserver.BaseRequestHandler):
|
||||
#def __init__(self, *args, **kwargs):
|
||||
#print(self, *args, **kwargs)
|
||||
#print("Got connection from {}".format( self.client_address[0]) )
|
||||
#socketserver.BaseRequestHandler.__init__(self, *args, **kwargs)
|
||||
|
||||
def handle(self):
|
||||
try:
|
||||
data = str(self.request.recv(1024), 'ascii')
|
||||
except Exception as ex:
|
||||
print("Got exception", ex)
|
||||
else:
|
||||
cur_thread = threading.current_thread()
|
||||
print(cur_thread.name, "received: ", data, )
|
||||
|
||||
def setup(self):
|
||||
print("Got new connection from {}".format( self.client_address) )
|
||||
self.server.handlers.append(self)
|
||||
|
||||
def finish(self):
|
||||
print("Connection from {} lost".format( self.client_address) )
|
||||
self.server.handlers.remove(self)
|
||||
|
||||
class Server(socketserver.ThreadingMixIn, socketserver.TCPServer):
|
||||
def init(self):
|
||||
"""
|
||||
__init__ should not be overriden
|
||||
"""
|
||||
self.handlers = []
|
||||
|
||||
def cleanup(self):
|
||||
for handler in self.handlers:
|
||||
handler.request.shutdown(socket.SHUT_RDWR)
|
||||
handler.request.close()
|
||||
self.shutdown()
|
||||
|
||||
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
# Port 0 means to select an arbitrary unused port
|
||||
host, port = "localhost", 30002 # this is the standard secondary port for a UR robot
|
||||
|
||||
server = Server((host, port), RequestHandler)
|
||||
server.init()
|
||||
server_thread = threading.Thread(target=server.serve_forever)
|
||||
server_thread.daemon = True
|
||||
server_thread.start()
|
||||
print("Fake Universal robot running at ", host, port)
|
||||
try:
|
||||
f = open("packet.bin", "rb")
|
||||
packet = f.read()
|
||||
f.close()
|
||||
while True:
|
||||
time.sleep(0.09) #The real robot published data 10 times a second
|
||||
for handler in server.handlers:
|
||||
handler.request.sendall(packet)
|
||||
finally:
|
||||
print("Shutting down server")
|
||||
server.cleanup()
|
17
tools/get_rob.py
Normal file
17
tools/get_rob.py
Normal file
@@ -0,0 +1,17 @@
|
||||
#!/usr/bin/env python
|
||||
from urx import Robot
|
||||
import math3d
|
||||
from math import pi
|
||||
import logging
|
||||
|
||||
if __name__ == "__main__":
|
||||
try:
|
||||
robot = Robot( 'localhost')#, logLevel=logging.DEBUG, parserLogLevel=logging.DEBUG)
|
||||
r = robot
|
||||
from IPython.frontend.terminal.embed import InteractiveShellEmbed
|
||||
ipshell = InteractiveShellEmbed( banner1="\nStarting IPython shell, robot object is available\n")
|
||||
ipshell(local_ns=locals())
|
||||
finally:
|
||||
if "robot" in dir():
|
||||
robot.cleanup()
|
||||
|
BIN
tools/packet.bin
Normal file
BIN
tools/packet.bin
Normal file
Binary file not shown.
Reference in New Issue
Block a user