add requirements and some good changes to python stuff
This commit is contained in:
parent
ee0ff57484
commit
e994d4f898
@ -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
|
PyYAML==5.1
|
||||||
|
requests==2.22.0
|
||||||
|
six==1.12.0
|
||||||
|
urllib3==1.25.3
|
||||||
|
websocket-client==0.56.0
|
||||||
|
@ -17,7 +17,7 @@ log = logging.getLogger("ugv")
|
|||||||
|
|
||||||
class UGVComms:
|
class UGVComms:
|
||||||
MAX_WRITE_RETRY = 5
|
MAX_WRITE_RETRY = 5
|
||||||
RETRY_TIME = 3.0
|
RETRY_TIME = 1.5
|
||||||
|
|
||||||
def __init__(self, serial_port: serial.Serial, on_msg_received=None):
|
def __init__(self, serial_port: serial.Serial, on_msg_received=None):
|
||||||
self.ser = serial_port
|
self.ser = serial_port
|
||||||
@ -54,8 +54,9 @@ class UGVComms:
|
|||||||
last_write_time = time.time()
|
last_write_time = time.time()
|
||||||
if not retry:
|
if not retry:
|
||||||
return
|
return
|
||||||
|
tries = UGVComms.MAX_WRITE_RETRY
|
||||||
with self.ack_cv:
|
with self.ack_cv:
|
||||||
while True:
|
while tries > 0:
|
||||||
if cmdid in self.msg_acks:
|
if cmdid in self.msg_acks:
|
||||||
self.msg_acks.remove(cmdid)
|
self.msg_acks.remove(cmdid)
|
||||||
log.debug("received ack for command")
|
log.debug("received ack for command")
|
||||||
@ -65,7 +66,9 @@ class UGVComms:
|
|||||||
log.warning("retry writing command")
|
log.warning("retry writing command")
|
||||||
self.write_message(gmsg)
|
self.write_message(gmsg)
|
||||||
last_write_time = time.time()
|
last_write_time = time.time()
|
||||||
|
tries -= 1
|
||||||
self.ack_cv.wait(timeout=time_left)
|
self.ack_cv.wait(timeout=time_left)
|
||||||
|
raise TimeoutError("Timeout waiting for command ack")
|
||||||
|
|
||||||
def read_message(self):
|
def read_message(self):
|
||||||
data = self.ser.read_until(terminator=b'\n')
|
data = self.ser.read_until(terminator=b'\n')
|
||||||
|
@ -6,6 +6,10 @@ import time
|
|||||||
import logging
|
import logging
|
||||||
import readline
|
import readline
|
||||||
import yaml
|
import yaml
|
||||||
|
try:
|
||||||
|
from yaml import CLoader as YamlLoader, CDumper as YamlDumper
|
||||||
|
except ImportError:
|
||||||
|
from yaml import YamlLoader, YamlDumper
|
||||||
import types
|
import types
|
||||||
|
|
||||||
from ugv import UGVComms
|
from ugv import UGVComms
|
||||||
@ -87,9 +91,9 @@ class UGV_CLI:
|
|||||||
log.info("set target to (%f, %f)", lat, long)
|
log.info("set target to (%f, %f)", lat, long)
|
||||||
|
|
||||||
@cli_cmd(names=["set_config", "sc"], description="Load configuration from config.yml and send")
|
@cli_cmd(names=["set_config", "sc"], description="Load configuration from config.yml and send")
|
||||||
def set_config(self):
|
def set_config(self, config_file_name="./tools/config.yml"):
|
||||||
with open('./tools/config.yml', 'r') as configfile:
|
with open(config_file_name, 'r') as configfile:
|
||||||
config = yaml.load(configfile)
|
config = yaml.load(configfile, Loader=YamlLoader)
|
||||||
|
|
||||||
if 'REVISION' in config:
|
if 'REVISION' in config:
|
||||||
config_rev = config['REVISION']
|
config_rev = config['REVISION']
|
||||||
@ -170,12 +174,15 @@ class UGV_CLI:
|
|||||||
stopbits=serial.STOPBITS_ONE, bytesize=serial.EIGHTBITS,
|
stopbits=serial.STOPBITS_ONE, bytesize=serial.EIGHTBITS,
|
||||||
timeout=0.5)
|
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 = UGVComms(ser, self.on_msg_received)
|
||||||
self.ugv.start()
|
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
|
last_line = None
|
||||||
try:
|
try:
|
||||||
print("Run 'help' to find out what commands are available")
|
print("Run 'help' to find out what commands are available")
|
||||||
@ -217,4 +224,4 @@ if __name__ == "__main__":
|
|||||||
logging.basicConfig(
|
logging.basicConfig(
|
||||||
format='%(asctime)s [%(name)s] %(levelname)s: %(message)s', datefmt='%Y-%b-%d %H:%M:%S')
|
format='%(asctime)s [%(name)s] %(levelname)s: %(message)s', datefmt='%Y-%b-%d %H:%M:%S')
|
||||||
logging.getLogger().setLevel(logging.INFO)
|
logging.getLogger().setLevel(logging.INFO)
|
||||||
UGV_CLI().start()
|
UGV_CLI().run_cli()
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
import socketio
|
import socketio
|
||||||
import signal
|
|
||||||
import logging
|
import logging
|
||||||
from base64 import b64decode, b64encode
|
from base64 import b64encode
|
||||||
|
from threading import Thread
|
||||||
|
|
||||||
from ugv_cmd import UGV_CLI
|
from ugv_cmd import UGV_CLI
|
||||||
import messages_pb2 as messages
|
import messages_pb2 as messages
|
||||||
@ -13,6 +13,9 @@ def encode_msg(msg: Message):
|
|||||||
return b64encode(data)
|
return b64encode(data)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
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'
|
server_ip = 'localhost'
|
||||||
|
|
||||||
sio = socketio.Client()
|
sio = socketio.Client()
|
||||||
@ -21,6 +24,7 @@ if __name__ == "__main__":
|
|||||||
sio.emit('UGV_MESSAGE', encode_msg(msg), namespace='/ugv')
|
sio.emit('UGV_MESSAGE', encode_msg(msg), namespace='/ugv')
|
||||||
|
|
||||||
ugv_cli = UGV_CLI(on_msg_received)
|
ugv_cli = UGV_CLI(on_msg_received)
|
||||||
|
ugv_cli.start()
|
||||||
|
|
||||||
@sio.on('connect', namespace='/ugv')
|
@sio.on('connect', namespace='/ugv')
|
||||||
def on_connect():
|
def on_connect():
|
||||||
@ -48,7 +52,4 @@ if __name__ == "__main__":
|
|||||||
print("Can't connect to ground server. Retrying in 2 seconds...")
|
print("Can't connect to ground server. Retrying in 2 seconds...")
|
||||||
sio.sleep(2)
|
sio.sleep(2)
|
||||||
|
|
||||||
logging.basicConfig(format='%(asctime)s [%(name)s] %(levelname)s: %(message)s', datefmt='%Y-%b-%d %H:%M:%S')
|
ugv_cli.run_cli()
|
||||||
logging.getLogger().setLevel(logging.INFO)
|
|
||||||
|
|
||||||
ugv_cli.start()
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user