Threading event wait instead of CPU burning wait
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
XMLRPC client scripts added
This commit is contained in:
parent
229f4ca6e4
commit
9b85e3a633
@ -15,6 +15,7 @@ import logging
|
|||||||
import logging.config
|
import logging.config
|
||||||
from xmlrpc.server import SimpleXMLRPCServer
|
from xmlrpc.server import SimpleXMLRPCServer
|
||||||
from configparser import ConfigParser
|
from configparser import ConfigParser
|
||||||
|
|
||||||
# from pynput.keyboard import Listener, Key
|
# from pynput.keyboard import Listener, Key
|
||||||
|
|
||||||
SCRIPT_DIR = os.path.dirname(__file__)
|
SCRIPT_DIR = os.path.dirname(__file__)
|
||||||
@ -25,7 +26,7 @@ config = config_object['DEFAULT']
|
|||||||
|
|
||||||
# TODO: export these to json?
|
# TODO: export these to json?
|
||||||
# Config file name
|
# Config file name
|
||||||
#CONFIG_FILE = 'path.xlsx'
|
# CONFIG_FILE = 'path.xlsx'
|
||||||
|
|
||||||
CONFIG_FILE = os.path.join(SCRIPT_DIR, "path.xlsx")
|
CONFIG_FILE = os.path.join(SCRIPT_DIR, "path.xlsx")
|
||||||
|
|
||||||
@ -39,7 +40,11 @@ j_acc = 0
|
|||||||
l_speed = 0
|
l_speed = 0
|
||||||
l_acc = 0
|
l_acc = 0
|
||||||
|
|
||||||
jogging_wait = {"Master": False, "Slave": False}
|
# jogging_wait = {"Master": False, "Slave": False}
|
||||||
|
jogging_event = {
|
||||||
|
'Master': threading.Event(),
|
||||||
|
'Slave': threading.Event()
|
||||||
|
}
|
||||||
|
|
||||||
path_master = {}
|
path_master = {}
|
||||||
path_slave = {}
|
path_slave = {}
|
||||||
@ -253,52 +258,56 @@ def read_path_waypoints_from_file():
|
|||||||
return path_master, path_slave
|
return path_master, path_slave
|
||||||
|
|
||||||
|
|
||||||
def on_press(key):
|
# def on_press(key):
|
||||||
try:
|
# try:
|
||||||
# logging.debug("Key pressed: {0}".format(key))
|
# # logging.debug("Key pressed: {0}".format(key))
|
||||||
|
#
|
||||||
if hasattr(key, 'char'):
|
# if hasattr(key, 'char'):
|
||||||
if key.char == 'f':
|
# if key.char == 'f':
|
||||||
jogging_wait['Master'] = True
|
# jogging_wait['Master'] = True
|
||||||
|
#
|
||||||
elif key.char == 'e':
|
# elif key.char == 'e':
|
||||||
jogging_wait['Slave'] = True
|
# jogging_wait['Slave'] = True
|
||||||
|
#
|
||||||
except AttributeError:
|
# except AttributeError:
|
||||||
logging.debug("Special key pressed: {0}".format(key))
|
# logging.debug("Special key pressed: {0}".format(key))
|
||||||
|
#
|
||||||
|
#
|
||||||
def on_release(key):
|
# def on_release(key):
|
||||||
try:
|
# try:
|
||||||
# logging.debug("Key released: {0}".format(key))
|
# # logging.debug("Key released: {0}".format(key))
|
||||||
|
#
|
||||||
if hasattr(key, 'char'):
|
# if hasattr(key, 'char'):
|
||||||
if key.char == 'f':
|
# if key.char == 'f':
|
||||||
jogging_wait['Master'] = False
|
# jogging_wait['Master'] = False
|
||||||
|
#
|
||||||
elif key.char == 'e':
|
# elif key.char == 'e':
|
||||||
jogging_wait['Slave'] = False
|
# jogging_wait['Slave'] = False
|
||||||
|
#
|
||||||
except AttributeError:
|
# except AttributeError:
|
||||||
logging.debug("Special key pressed: {0}".format(key))
|
# logging.debug("Special key pressed: {0}".format(key))
|
||||||
|
|
||||||
|
|
||||||
def master_jogging_wait():
|
def master_jogging_wait():
|
||||||
if config.getboolean('JOGGING_ENABLE'):
|
if config.getboolean('JOGGING_ENABLE'):
|
||||||
logging.debug("Master-Fred: Press 'f' to continue")
|
logging.debug("Master-Fred: Press 'f' to continue")
|
||||||
|
|
||||||
while not jogging_wait['Master']:
|
# while not jogging_wait['Master']:
|
||||||
pass
|
# pass
|
||||||
jogging_wait['Master'] = False
|
# jogging_wait['Master'] = False
|
||||||
|
jogging_event['Master'].clear()
|
||||||
|
jogging_event['Master'].wait()
|
||||||
|
|
||||||
|
|
||||||
def slave_jogging_wait():
|
def slave_jogging_wait():
|
||||||
if config.getboolean('JOGGING_ENABLE'):
|
if config.getboolean('JOGGING_ENABLE'):
|
||||||
logging.debug("Slave-Erik: Press 'e' to continue")
|
logging.debug("Slave-Erik: Press 'e' to continue")
|
||||||
|
|
||||||
while not jogging_wait['Slave']:
|
# while not jogging_wait['Slave']:
|
||||||
pass
|
# pass
|
||||||
jogging_wait['Slave'] = False
|
# jogging_wait['Slave'] = False
|
||||||
|
jogging_event['Slave'].clear()
|
||||||
|
jogging_event['Slave'].wait()
|
||||||
|
|
||||||
|
|
||||||
def master_operate_gripper(target_width):
|
def master_operate_gripper(target_width):
|
||||||
@ -821,21 +830,21 @@ def slave_thread(sync_event, path):
|
|||||||
|
|
||||||
|
|
||||||
class RemoteFuncs:
|
class RemoteFuncs:
|
||||||
def signal(self, robot):
|
def signalMaster(self):
|
||||||
if robot == 'M':
|
# jogging_wait['Master'] = True
|
||||||
jogging_wait['Master'] = True
|
jogging_event['Master'].set()
|
||||||
return 0
|
return 0
|
||||||
elif robot == 'S':
|
|
||||||
jogging_wait['Slave'] = True
|
def signalSlave(self):
|
||||||
return 0
|
# jogging_wait['Slave'] = True
|
||||||
else:
|
jogging_event['Slave'].set()
|
||||||
logging.debug("Wrong XMLRPC signal input. Value: {0}".format(robot))
|
return 0
|
||||||
return 1
|
|
||||||
|
|
||||||
|
|
||||||
class ServerThread(threading.Thread):
|
class ServerThread(threading.Thread):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
threading.Thread.__init__(self)
|
threading.Thread.__init__(self)
|
||||||
|
self.daemon = True
|
||||||
self.localServer = SimpleXMLRPCServer(('0.0.0.0', 8888))
|
self.localServer = SimpleXMLRPCServer(('0.0.0.0', 8888))
|
||||||
self.localServer.register_instance(RemoteFuncs())
|
self.localServer.register_instance(RemoteFuncs())
|
||||||
|
|
||||||
@ -883,7 +892,6 @@ if __name__ == '__main__':
|
|||||||
|
|
||||||
logging.info('Spawning XMLRPC listener thread')
|
logging.info('Spawning XMLRPC listener thread')
|
||||||
xmlrpcServer = ServerThread()
|
xmlrpcServer = ServerThread()
|
||||||
xmlrpcServer.daemon = True
|
|
||||||
xmlrpcServer.start()
|
xmlrpcServer.start()
|
||||||
|
|
||||||
# listener = Listener(on_press=on_press, on_release=on_release)
|
# listener = Listener(on_press=on_press, on_release=on_release)
|
||||||
|
8
signalMaster.py
Normal file
8
signalMaster.py
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
import xmlrpc.client
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
IP = '127.0.0.1'
|
||||||
|
PORT = '8888'
|
||||||
|
|
||||||
|
s = xmlrpc.client.ServerProxy("http://{0}:{1}".format(IP, PORT))
|
||||||
|
print(s.signalMaster())
|
8
signalSlave.py
Normal file
8
signalSlave.py
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
import xmlrpc.client
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
IP = '127.0.0.1'
|
||||||
|
PORT = '8888'
|
||||||
|
|
||||||
|
s = xmlrpc.client.ServerProxy("http://{0}:{1}".format(IP, PORT))
|
||||||
|
print(s.signalSlave())
|
Loading…
Reference in New Issue
Block a user