Skip to content

Commit

Permalink
1104 fix user angle in deep learning (#1105)
Browse files Browse the repository at this point in the history
* fix user/angle in complete.py
- that had been renamed user/steering in the PR that
  merged the computer vision template.
- Much code in the deep learning pipeline explicitly
  hard-codes the literal `user/angle` so the deep learning
  code needs to continue to use that label.
- This fix uses the Pipe() part to rename 'user/steering'
  to 'user/angle' immediately after it is emitted by the
  controller part.

* pilot/steering -> pilot/angle

* Fix pipe.py and complete.py
- Pipe.py would output a bad tuple if only one argument
  was being passed throught.  Now it explictly checks.
- This caused complete.py to have invalid 'user/angle' values.
  • Loading branch information
Ezward authored Feb 27, 2023
1 parent 4a78dbb commit de4d97b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 16 deletions.
11 changes: 3 additions & 8 deletions donkeycar/parts/pipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,7 @@ class Pipe:
"""
Just pipe all inputs to the output, so they can be renamed.
"""
def __init__(self):
self.running = True

def run(self, *args):
if self.running:
return args

def shutdown(self):
self.running = False
# seems to be a python bug that takes a single argument
# return makes it into two element tuple with empty last element.
return args if len(args) > 1 else args[0]
20 changes: 12 additions & 8 deletions donkeycar/templates/complete.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
from donkeycar.parts.kinematics import Bicycle, InverseBicycle, BicycleUnnormalizeAngularVelocity
from donkeycar.parts.explode import ExplodeDict
from donkeycar.parts.transform import Lambda
from donkeycar.parts.logger import LoggerPart
from donkeycar.parts.pipe import Pipe
from donkeycar.utils import *

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -132,6 +132,11 @@ def drive(cfg, model_path=None, use_joystick=False, model_type=None,
has_input_controller = hasattr(cfg, "CONTROLLER_TYPE") and cfg.CONTROLLER_TYPE != "mock"
ctr = add_user_controller(V, cfg, use_joystick)

#
# convert 'user/steering' to 'user/angle' to be backward compatible with deep learning data
#
V.add(Pipe(), inputs=['user/steering'], outputs=['user/angle'])

#
# explode the buttons input map into individual output key/values in memory
#
Expand Down Expand Up @@ -387,7 +392,7 @@ def run(self, *components):
#
# collect model inference outputs
#
outputs = ['pilot/steering', 'pilot/throttle']
outputs = ['pilot/angle', 'pilot/throttle']

if cfg.TRAIN_LOCALIZER:
outputs.append("pilot/loc")
Expand Down Expand Up @@ -437,11 +442,10 @@ def run(self, *components):
# based on the choice of user or autopilot drive mode
#
V.add(DriveMode(cfg.AI_THROTTLE_MULT),
inputs=['user/mode', 'user/steering', 'user/throttle',
'pilot/steering', 'pilot/throttle'],
inputs=['user/mode', 'user/angle', 'user/throttle',
'pilot/angle', 'pilot/throttle'],
outputs=['steering', 'throttle'])

V.add(LoggerPart(['steering', 'throttle']), inputs=['steering', 'throttle'])

if (cfg.CONTROLLER_TYPE != "pigpio_rc") and (cfg.CONTROLLER_TYPE != "MM1"):
if isinstance(ctr, JoystickController):
Expand Down Expand Up @@ -471,10 +475,10 @@ def run(self, *components):
# add tub to save data
#
if cfg.USE_LIDAR:
inputs = ['cam/image_array', 'lidar/dist_array', 'user/steering', 'user/throttle', 'user/mode']
inputs = ['cam/image_array', 'lidar/dist_array', 'user/angle', 'user/throttle', 'user/mode']
types = ['image_array', 'nparray','float', 'float', 'str']
else:
inputs=['cam/image_array','user/steering', 'user/throttle', 'user/mode']
inputs=['cam/image_array','user/angle', 'user/throttle', 'user/mode']
types=['image_array','float', 'float','str']

if cfg.HAVE_ODOM:
Expand Down Expand Up @@ -512,7 +516,7 @@ def run(self, *components):
types += ['nparray']

if cfg.RECORD_DURING_AI:
inputs += ['pilot/steering', 'pilot/throttle']
inputs += ['pilot/angle', 'pilot/throttle']
types += ['float', 'float']

if cfg.HAVE_PERFMON:
Expand Down

0 comments on commit de4d97b

Please sign in to comment.