autorope / donkeycar

Open source hardware and software platform to build a small scale self driving car.
http://www.donkeycar.com
MIT License
3.16k stars 1.3k forks source link

Allow a custom throttle in deep learning template #1115

Open Ezward opened 1 year ago

Ezward commented 1 year ago

Throttle can be difficult to learn from data unless there is a lot of data. This is because throttle is much harder to duplicate from run to run than steering for the human driver, so it is harder to learn from the resulting data. It would be useful to have an algorithmic approach to throttle that could be configured.

Both the path follow and the computer vision templates allow a algorithmic throttle control to be used when in autopilot mode, but they do it differently. The path follow template allows a constant throttle by setting USE_CONSTANT_THROTTLE = True and using PID_THROTTLE as the throttle value.

PID_THROTTLE = 0.50                 # constant throttle value during path following
USE_CONSTANT_THROTTLE = False       # whether or not to use the constant throttle or variable throttle captured during path recording

The computer vision template implements a more sophisticated approach that allows throttle to be varied between a minimum and maximum based on the steering value (slow down when turning; speed up when going straight). There are initial, minimum, and maximum values that can be specified; so this is a constant step controller, which is easy to tune. Also, by making min, max and initial the same and step = 0, it can create a constant throttle.

THROTTLE_MAX = 0.3    # maximum throttle value the controller will produce
THROTTLE_MIN = 0.15   # minimum throttle value the controller will produce
THROTTLE_INITIAL = THROTTLE_MIN  # initial throttle value
THROTTLE_STEP = 0.05  # how much to change throttle when on/off line (adding/subtracting respectively)

Perhaps the computer vision throttle control is a capability we should add to all templates. It is implemented using the pixel offset of the line, but we should change this to be based on the steering value and implement a standalone part to separate throttle control from steering control in the computer vision template, then use that same part in the other templates.

Or for the deep learning template we may want something even more sophisticated; use a lambda to convert the steering value to a throttle and allow the user to provide the implementation in the configuration. That would allow the user maximum flexibility over how the throttle value is calculated.

Yann377 commented 1 year ago

Hi, I'm an IT student, I'm going to work on it as part of my computer science studies :-)

Ezward commented 10 months ago

@Yann377 Great, this is a good project. The documentation has a discussion of the donkeycar software architecture, that is a good place to start. The deep learning template is here https://github.com/autorope/donkeycar/blob/main/donkeycar/templates/complete.py.

This is the line where the deep learning model is added to the vehicle pipeline. So when running in autpilot mode, that is the first place that a throttle value will be created. So you want your part that creates its own throttle value to run after that. We have a couple of other parts in the vehicle pipeline that modify throttle; the Stop Sign Detector runs runs a separate model that detects a stop sign and sets the throttle to zero if it finds one. The AI Launcher sets a constant throttle for a short time the first time the car is put into auto-pilot mode, so it can 'launch' the car really fast down the first straight in a race. Notice that both of them run just after the deep learning model. I think you want your part to run before both of those, but after the deep learning model.

So your part will take as input the steering and throttle values that the deep learning model output. It will then apply some function to the steering value to calculate a new throttle value and output that, thus overwriting the value the model created, so your value gets used instead.