Browse Source

CLI completion

master
Alex Mikhalev 6 years ago
parent
commit
dfcf050761
  1. 10
      tools/ugv.py
  2. 16
      tools/ugv_cmd.py

10
tools/ugv.py

@ -9,18 +9,18 @@ import time @@ -9,18 +9,18 @@ import time
import binascii
from base64 import b64decode, b64encode
from e32 import E32
import messages_pb2 as messages
from google.protobuf.message import Message
log = logging.getLogger("ugv")
class UGVComms(E32):
class UGVComms:
MAX_WRITE_RETRY = 5
RETRY_TIME = 3.0
def __init__(self, serial_port: serial.Serial):
E32.__init__(self, serial_port)
self.ser = serial_port
self.msg_acks = []
self.ack_cv = threading.Condition()
self.next_command_id = 1
@ -118,7 +118,7 @@ class UGVComms(E32): @@ -118,7 +118,7 @@ class UGVComms(E32):
msg = self.read_message()
self.process_message(msg)
except serial.SerialException:
if not self.ser.is_open or not self.is_running: # port was probably just closed
if not self.ser.is_open or not self.is_running: # port was probably just closed
return
log.error("serial error", exc_info=True)
return
@ -146,7 +146,7 @@ def main(): @@ -146,7 +146,7 @@ def main():
# ugv.write_command(cmd)
cmd.type = messages.CMD_SET_CONFIG
cmd.config.angle_pid.kp = 0.10
cmd.config.angle_pid.ki = 0#.00005
cmd.config.angle_pid.ki = 0 # .00005
cmd.config.angle_pid.kd = 0.4
cmd.config.angle_pid.max_output = 0.5
cmd.config.angle_pid.max_i_error = 15.0

16
tools/ugv_cmd.py

@ -55,6 +55,7 @@ class UGV_CLI: @@ -55,6 +55,7 @@ class UGV_CLI:
'get_status': self.get_status,
's': self.get_status,
}
self.ugv = None
pass
@cli_cmd(names=["help", "h", "?"], description="Print this help message")
@ -128,12 +129,21 @@ class UGV_CLI: @@ -128,12 +129,21 @@ class UGV_CLI:
log.info("last status (%.4f seconds ago): %s",
last_status_delay, self.ugv.last_status)
def find_command(self, name):
@staticmethod
def find_command(name):
for cmd in cli_commands:
if name in cmd.names:
return cmd
return None
@staticmethod
def complete_command(text, state):
options = [name for cmd in cli_commands for name in cmd.names if name.startswith(text)]
if state < len(options):
return options[state]
else:
return None
def start(self):
self.is_running = True
@ -144,6 +154,10 @@ class UGV_CLI: @@ -144,6 +154,10 @@ class UGV_CLI:
ser = serial.serial_for_url(ser_url, baudrate=9600, parity=serial.PARITY_NONE,
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.ugv.start()
time.sleep(0.2)

Loading…
Cancel
Save