The reInvent Robocar hackathon is just 2 days away. There participants will have 36 hours to improve a standard Donkey Car to race autonomously around the track against other cars. Since I’ll be there as an facilitator and won’t get to race my own car I thought I’d share how I’d try to win this race. These are also features that would be great to add to the standard Donkey Car so please make pull requests after the event if you get them working.
36 hours will blow by. Anyone who’s ever tried a hackathon knows time is your most precious resource. 36 hours is not long enough to solve all the problems. If you attempt too much you’ll risk accomplishing nothing. I'd try to pick the easiest change that will also have a big impact on your lap time.
Current state of Donkey Car. Everyone will start with a Donkey Car 2 can already be manually controlled by your phone, collect images, steering and throttle data and drive it's self using an end to end neural network that runs on a Raspberry Pi.
These neural net (NN) autopilots are made by driving the track 10-20 times to collect training data (images, steering & throttle values) and then training a NN using Keras/Tensorflow to clone the drivers behavior. This approach works but is NOT robust. Here are the some of the things that often go wrong:
Some of the suggestions below would make the autopilot more reliable and potentially much faster.
My hackathon priorities.
Separate the autopilot into vision and control parts.
The current end to end neural network is one monolith that converts a stream of images to steering and throttle values. This makes it very difficult to fix if only part of it is broken. One way to make this more modular is break the end to end net network into two parts, a vision part and a control part.
The vision part would find the location of the lane using either a CV function or NN trained on the output of the CV function. The control part would then adjust the steering and throttle based on the relative lane location.
Make Maps using visual odometry.
This is likely the hardest to do right but will have the biggest gains. Maps are what will cut race times in half and enable longer autonomous trips. One promising approach is to make a map of the track by driving, then plot your desired race line for your car to follow.
Visual Odometry Resources
Add variable rate throttle for the autopilot (easy).
The autopilot you train tries to drive like you did in when you collected training data. You often don't drive as fast as you could for the car's safety. You could make the big throttles are bigger so the autopilot drives faster than you did manually.
Filter image before training.
Right now the Convolution Neural Net (CNN) is responsible for identifying the important features in the images. It’s possible to help the network by highlighting those features. For example:
Augment training data by altering images.
The NNs could be made more robust by training on more data. Augmentting the image data by adding blurs or random shapes and adjusting the white balance can give you more reasonable data to train on.
Keras has a function to augment image data but its a little tricky to alter steering angle when you flip the image. You could write a few image functions that could be included in the record transform function of the training data generator.
Add a PID and/or Kalman filter.
The current network outputs jittery steering. Even when the car is stationary you can see the wheels twitch as the input image changes slightly. This can get better if you train on hundreds of thousands of images it never completely goes away. When the car is going fast around a corner one twitch in the wrong direction can make it go off course and not come back. Adding a PID loop (code) could smooth the steering.
Make the network statefull by adding a recurrent layer.
The default neural network is stateless. Every 30th of a second it uses a single image to make a steering and throttle prediction. Since the most likely next steering angle is going to be the same as the last prediction it would be helpful for the pilot to know the recent steering angles. Recurrent neural network layers loop back on themselves so information can be saved through time which could improve the pilot.
To do this you'd need change the default Keras model to include a recurrent layer and also the batch generator would need to be changed to train on sequences instead of frames. Tawn has talked about doing this.
Predict steering of future frames.
The current autopilot current tries to estimate the steering angle for the input image. This means that by the time the servos move the car has moved passed where it should have. A simple fix for this would be to train the neural network to predict the steering angle 5-20 frames ahead of the current frame. If you really want to get creative you can add additional outputs that predict the steering for the current frame, frame 30, frame 60 and frame 90 like DrClick did here (not on Donkey).
Use the confidence of the network predictions to scale speed or default steering.
The output of the default categorical model is a softmax for 15 categories. This means that the sum of outputs for all 15 categories is 1 and you can use these outputs as the likelihood the car should go in that direction. So if the outputs are all zero except for the center output then the car should definitely go straight. If you are getting values of .4 for steering right and left then you know that the autopilot is unsure where to turn.
Add wheel encoders.
A couple peopled have gotten encoders (code) to work on donkey cars.
Add IMU to model physics of car.
An IMU will give you inputs about the physics of your car to help you estimate speed and rotation. This could help you estimate your place on the track as well as estimate the completion of a turn.
Use an existing model and finish up training with much less data.
Here's a notebook to see how this works.
Here are some things to checkout so you're not learning from scratch on race day.
This is going to be good.
- Roscoe (@daduce)