diff --git a/tools/requirements.txt b/tools/requirements.txt index 8dbbc4a..d30b2c3 100644 --- a/tools/requirements.txt +++ b/tools/requirements.txt @@ -1,2 +1,13 @@ -python-socketio==4.0.1 +certifi==2019.3.9 +chardet==3.0.4 +idna==2.8 +netifaces==0.10.6 +protobuf==3.7.1 +pyserial==3.4 +python-engineio==3.5.2 +python-socketio==4.0.2 PyYAML==5.1 +requests==2.22.0 +six==1.12.0 +urllib3==1.25.3 +websocket-client==0.56.0 diff --git a/tools/ugv.py b/tools/ugv.py index a00512e..25727ea 100755 --- a/tools/ugv.py +++ b/tools/ugv.py @@ -17,7 +17,7 @@ log = logging.getLogger("ugv") class UGVComms: MAX_WRITE_RETRY = 5 - RETRY_TIME = 3.0 + RETRY_TIME = 1.5 def __init__(self, serial_port: serial.Serial, on_msg_received=None): self.ser = serial_port @@ -54,8 +54,9 @@ class UGVComms: last_write_time = time.time() if not retry: return + tries = UGVComms.MAX_WRITE_RETRY with self.ack_cv: - while True: + while tries > 0: if cmdid in self.msg_acks: self.msg_acks.remove(cmdid) log.debug("received ack for command") @@ -65,7 +66,9 @@ class UGVComms: log.warning("retry writing command") self.write_message(gmsg) last_write_time = time.time() + tries -= 1 self.ack_cv.wait(timeout=time_left) + raise TimeoutError("Timeout waiting for command ack") def read_message(self): data = self.ser.read_until(terminator=b'\n') diff --git a/tools/ugv_cmd.py b/tools/ugv_cmd.py index 5a05a78..3b9685b 100755 --- a/tools/ugv_cmd.py +++ b/tools/ugv_cmd.py @@ -6,6 +6,10 @@ import time import logging import readline import yaml +try: + from yaml import CLoader as YamlLoader, CDumper as YamlDumper +except ImportError: + from yaml import YamlLoader, YamlDumper import types from ugv import UGVComms @@ -87,9 +91,9 @@ class UGV_CLI: log.info("set target to (%f, %f)", lat, long) @cli_cmd(names=["set_config", "sc"], description="Load configuration from config.yml and send") - def set_config(self): - with open('./tools/config.yml', 'r') as configfile: - config = yaml.load(configfile) + def set_config(self, config_file_name="./tools/config.yml"): + with open(config_file_name, 'r') as configfile: + config = yaml.load(configfile, Loader=YamlLoader) if 'REVISION' in config: config_rev = config['REVISION'] @@ -170,12 +174,15 @@ class UGV_CLI: stopbits=serial.STOPBITS_ONE, bytesize=serial.EIGHTBITS, timeout=0.5) - readline.parse_and_bind("tab: complete") - readline.set_completer(self.complete_command) - self.ugv = UGVComms(ser, self.on_msg_received) self.ugv.start() - time.sleep(0.2) + + def run_cli(self): + if self.ugv is None: + self.start() + + readline.parse_and_bind("tab: complete") + readline.set_completer(self.complete_command) last_line = None try: print("Run 'help' to find out what commands are available") @@ -217,4 +224,4 @@ if __name__ == "__main__": logging.basicConfig( format='%(asctime)s [%(name)s] %(levelname)s: %(message)s', datefmt='%Y-%b-%d %H:%M:%S') logging.getLogger().setLevel(logging.INFO) - UGV_CLI().start() + UGV_CLI().run_cli() diff --git a/tools/ugv_to_ground.py b/tools/ugv_to_ground.py index 12f677c..21ba7a5 100755 --- a/tools/ugv_to_ground.py +++ b/tools/ugv_to_ground.py @@ -1,8 +1,8 @@ #!/usr/bin/env python3 import socketio -import signal import logging -from base64 import b64decode, b64encode +from base64 import b64encode +from threading import Thread from ugv_cmd import UGV_CLI import messages_pb2 as messages @@ -13,6 +13,9 @@ def encode_msg(msg: Message): return b64encode(data) if __name__ == "__main__": + logging.basicConfig(format='%(asctime)s [%(name)s] %(levelname)s: %(message)s', datefmt='%Y-%b-%d %H:%M:%S') + logging.getLogger().setLevel(logging.INFO) + server_ip = 'localhost' sio = socketio.Client() @@ -21,6 +24,7 @@ if __name__ == "__main__": sio.emit('UGV_MESSAGE', encode_msg(msg), namespace='/ugv') ugv_cli = UGV_CLI(on_msg_received) + ugv_cli.start() @sio.on('connect', namespace='/ugv') def on_connect(): @@ -48,7 +52,4 @@ if __name__ == "__main__": print("Can't connect to ground server. Retrying in 2 seconds...") sio.sleep(2) - logging.basicConfig(format='%(asctime)s [%(name)s] %(levelname)s: %(message)s', datefmt='%Y-%b-%d %H:%M:%S') - logging.getLogger().setLevel(logging.INFO) - - ugv_cli.start() + ugv_cli.run_cli()