mirror of
https://github.com/odriverobotics/ODrive.git
synced 2026-08-20 22:14:34 +08:00
allow setting interactive shell variables, fix some warnings
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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):
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
+10
-1
@@ -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")
|
||||
|
||||
+6
-2
@@ -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")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user