diff --git a/Firmware/fibre/python/fibre/__init__.py b/Firmware/fibre/python/fibre/__init__.py index 757d852c..7309c8b2 100644 --- a/Firmware/fibre/python/fibre/__init__.py +++ b/Firmware/fibre/python/fibre/__init__.py @@ -1,5 +1,5 @@ -from fibre.discovery import find_any, find_all -from fibre.utils import Event, Logger -from fibre.protocol import ChannelBrokenException, ChannelDamagedException -from fibre.shell import launch_shell +from .discovery import find_any, find_all +from .utils import Event, Logger +from .protocol import ChannelBrokenException, ChannelDamagedException +from .shell import launch_shell diff --git a/Firmware/fibre/python/fibre/shell.py b/Firmware/fibre/python/fibre/shell.py index 8b8d82d6..378d48d7 100644 --- a/Firmware/fibre/python/fibre/shell.py +++ b/Firmware/fibre/python/fibre/shell.py @@ -4,10 +4,10 @@ import platform import threading import fibre -interactive_variables = {} -discovered_devices = [] - -def did_discover_device(device, branding_short, branding_long, logger, app_shutdown_token): +def did_discover_device(device, + interactive_variables, discovered_devices, + branding_short, branding_long, + logger, app_shutdown_token): """ Handles the discovery of new devices by displaying a message and making the device available to the interactive @@ -40,6 +40,7 @@ def did_lose_device(interactive_name, logger, app_shutdown_token): logger.warn("Oh no {} disappeared".format(interactive_name)) def launch_shell(args, + interactive_variables, print_banner, print_help, logger, app_shutdown_token, branding_short="dev", branding_long="device"): @@ -51,10 +52,13 @@ def launch_shell(args, The names of the variables can be customized by setting branding_short. """ + discovered_devices = [] + globals().update(interactive_variables) + # Connect to device logger.debug("Waiting for {}...".format(branding_long)) fibre.find_all(args.path, args.serial_number, - lambda dev: did_discover_device(dev, branding_short, branding_long, logger, app_shutdown_token), + lambda dev: did_discover_device(dev, interactive_variables, discovered_devices, branding_short, branding_long, logger, app_shutdown_token), app_shutdown_token, app_shutdown_token, logger=logger) diff --git a/Firmware/fibre/python/fibre/udp_transport.py b/Firmware/fibre/python/fibre/udp_transport.py index 0846f2a2..d0e4c2f0 100644 --- a/Firmware/fibre/python/fibre/udp_transport.py +++ b/Firmware/fibre/python/fibre/udp_transport.py @@ -25,7 +25,7 @@ class UDPTransport(fibre.protocol.PacketSource, fibre.protocol.PacketSink): def get_packet(self, deadline): # TODO: implement deadline - data, addr = self.sock.recvfrom(1024) + data, _ = self.sock.recvfrom(1024) return data def discover_channels(path, serial_number, callback, cancellation_token, channel_termination_token, logger): diff --git a/Firmware/fibre/tools/fibre-shell b/Firmware/fibre/tools/fibre-shell index b50419c9..b6765452 100755 --- a/Firmware/fibre/tools/fibre-shell +++ b/Firmware/fibre/tools/fibre-shell @@ -7,7 +7,7 @@ import sys import os sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.realpath(__file__))) + "/python") -import fibre + from fibre import Logger, Event # Parse arguments @@ -54,4 +54,4 @@ def print_help(args, have_devices): pass import fibre -fibre.launch_shell(args, print_banner, print_help, logger, app_shutdown_token) +fibre.launch_shell(args, {}, print_banner, print_help, logger, app_shutdown_token) diff --git a/tools/odrive/__init__.py b/tools/odrive/__init__.py index 598d9a3f..c95f471a 100644 --- a/tools/odrive/__init__.py +++ b/tools/odrive/__init__.py @@ -1,10 +1,9 @@ +import fibre +find_any = fibre.find_any +find_all = fibre.find_all + # Standard convention is to add a __version__ attribute to the package from .version import get_version_str __version__ = get_version_str() del get_version_str - - -import fibre -find_any = fibre.find_any -find_all = fibre.find_all diff --git a/tools/odrive/enums.py b/tools/odrive/enums.py index 52b1e610..c492f9a0 100644 --- a/tools/odrive/enums.py +++ b/tools/odrive/enums.py @@ -27,7 +27,7 @@ MOTOR_TYPE_HIGH_CURRENT = 0 #MOTOR_TYPE_LOW_CURRENT = 1 MOTOR_TYPE_GIMBAL = 2 -CTRL_MODE_VOLTAGE_CONTROL = 0, -CTRL_MODE_CURRENT_CONTROL = 1, -CTRL_MODE_VELOCITY_CONTROL = 2, +CTRL_MODE_VOLTAGE_CONTROL = 0 +CTRL_MODE_CURRENT_CONTROL = 1 +CTRL_MODE_VELOCITY_CONTROL = 2 CTRL_MODE_POSITION_CONTROL = 3 diff --git a/tools/odrive/shell.py b/tools/odrive/shell.py index e9ab97bd..ba704066 100644 --- a/tools/odrive/shell.py +++ b/tools/odrive/shell.py @@ -4,8 +4,9 @@ import platform import threading import fibre import odrive +import odrive.enums from odrive.utils import start_liveplotter -from odrive.enums import * # pylint: disable=W0614 +#from odrive.enums import * # pylint: disable=W0614 def print_banner(): print('Please connect your ODrive.') @@ -74,7 +75,15 @@ def launch_shell(args, logger, printer, app_shutdown_token): "odrv0", "odrv1", ... """ + interactive_variables = { + 'start_liveplotter': start_liveplotter + } + + # Expose all enums from odrive.enums + interactive_variables.update({k: v for (k, v) in odrive.enums.__dict__.items() if not k.startswith("_")}) + fibre.launch_shell(args, + interactive_variables, print_banner, print_help, logger, app_shutdown_token, branding_short="odrv", branding_long="ODrive") diff --git a/tools/odrivetool b/tools/odrivetool index 854e0c48..fa81f4f8 100755 --- a/tools/odrivetool +++ b/tools/odrivetool @@ -5,10 +5,14 @@ ODrive command line utility from __future__ import print_function import sys +import os import argparse -import odrive + +sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.realpath(__file__))) + "/Firmware/fibre/python") + import fibre.discovery -from fibre.utils import Logger, Event +from fibre import Logger, Event +import odrive #print("Refer to install instructions at http://docs.odriverobotics.com/#downloading-and-installing-tools")