NVIDIA-AI-IOT / jetracer

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

Road Following steering and bias setting problem #47

Closed itsklee closed 2 years ago

itsklee commented 4 years ago

In road_follwing, it looks like setting the value of car.steering and bias Actually, it is set up by adding up the setting value of Bias. It looks like you need to change car.steering_offset to change Bias. Is that right?

road_following.iphnb

from utils import preprocess import numpy as np

STEERING_GAIN = 0.75 STEERING_BIAS = 0.00

car.throttle = 0.15

while True: image = camera.read() image = preprocess(image).half() output = model_trt(image).detach().cpu().numpy().flatten() x = float(output[0]) car.steering = x * STEERING_GAIN + STEERING_BIAS

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_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