NVIDIA-AI-IOT / jetracer

An autonomous AI racecar using NVIDIA Jetson Nano
MIT License
1.06k stars 319 forks source link

Basic Motion Throttle Offset #118

Closed crother94 closed 2 years ago

crother94 commented 2 years ago

I'm working through the Basic Motion notebook. The steering setup with the gain and offset worked fine, but I'm having some trouble with throttle. A throttle command of zero will drive the wheels, and I have to command a non-zero value (varies depending on the throttle gain sign and magnitude) to stop the wheels. I would imagine that the range of throttle commands should behave such that zero is stopped, 1 is full forward, and -1 is full reverse. I figured the simplest way to fix this behavior would be to add a throttle offset to the nvidia_racecar.py file (included below). However, when I save the changes to nvidia_racecar.py, the basic motion notebook doesn't seem to incorporate the new functionality, and the car behaves exactly as before. Is there some sort of build process I need to complete after making these modifications? Or does the road following neural net not care if a zero throttle command doesn't correspond to zero speed?

from .racecar import Racecar
import traitlets
from adafruit_servokit import ServoKit

class NvidiaRacecar(Racecar):

i2c_address = traitlets.Integer(default_value=0x40)
steering_gain = traitlets.Float(default_value=-0.65)
steering_offset = traitlets.Float(default_value=0)
steering_channel = traitlets.Integer(default_value=0)
throttle_gain = traitlets.Float(default_value=0.8)
throttle_offset = traitlets.Float(default_value=0.2)
throttle_channel = traitlets.Integer(default_value=1)

def __init__(self, *args, **kwargs):
    super(NvidiaRacecar, self).__init__(*args, **kwargs)
    self.kit = ServoKit(channels=16, address=self.i2c_address)
    self.steering_motor = self.kit.continuous_servo[self.steering_channel]
    self.throttle_motor = self.kit.continuous_servo[self.throttle_channel]

@traitlets.observe('steering')
def _on_steering(self, change):
    self.steering_motor.throttle = change['new'] * self.steering_gain + self.steering_offset

@traitlets.observe('throttle')
def _on_throttle(self, change):
    self.throttle_motor.throttle = change['new'] * self.throttle_gain + self.throttle_offset