janzeteachesit / 100-days-of-code

Fork this template for the 100 days journal - to keep yourself accountable
3 stars 4 forks source link

Build your own self driving (toy) car Towards Data Science Medium #144

Open janzeteachesit opened 7 years ago

janzeteachesit commented 7 years ago

Build your own self driving (toy) car – Towards Data Science – Medium http://ift.tt/2uzf7rD aimlnn  STEM Robotics  Build your own self driving (toy) car Bogdan DjukicJul 17 If you are interested in building your own self driving (toy) car and learning some AI concepts along the way, you should stick around and read through. Short intro Application of Deep Learning is disrupting many industries today with ever increasing data and computing power. One of its new battlegrounds is robotics. Deep Learning is changing the robotics landscape in the areas of perception and control which is the key for the success of autonomous vehicles and its broader deployments. Recent advancements in Deep Learning tools (TensorFlow, Keras, etc.) and accessibility of cheap computing platforms (Raspberry Pi) makes experimentation with robotics and AI much more accessible (and fun!) for people outside academia and big tech companies. Goal We’ll take Deep Neural Network described in my Behavior Cloning project from Udacity Self Driving Car nano degree course and run it on a remote controlled (RC) race car using Robotic Operating System (ROS) as a middle-ware. The end goal is to enable robot to autonomously complete the racing track: This is just one of many recent projects in this area and there are quite a few of them if you search the Net. There are even meet-ups (most famous one in Oakland, USA) where people race with these robots and trying to beat the best human time. What my project maybe sets a part from others is the usage of ROS as a connecting layer between the software stack and the metal. This project is really a great example on how Deep Learning can be used to train the car end-to-end to drive itself and solve both perception and control challenges in robotics using AI. How do I build one? Let’s first look at the hardware to get you started: Remote controller car Raspberry Pi 3 Raspberry Pi camera Wide angle lens Servo driver 3D printed mount Since my hardware build is based on Donkey Car, you can get more detailed instructions on hardware assembly here. You’ll notice that there are many options when it comes to choosing your RC car. In my first iteration of this project I went for Elegoo Robot Car Kit which turned out not be good idea since the kit does not have a dedicated servo for controlling the steering angle. This makes modeling your neural network and later integration with the auto-pilot a bit more difficult. With Magnet, you have much better control over the RC car. And the software? If you are in the hurry, you can take software stack from Donkey Car as well. I took the other route and tried to build the brains by myself by looking at Donkey Car project and taking learnings from my previous Udacity projects. I like one of the Richard Feynman’s quotes on this topic: What I cannot create, I do not understand. Know how to solve every problem that has been solved. As I’ve already mentioned, I decided to go for Robotic Operating System (ROS) for the setup as middle-ware between Deep learning based auto-pilot and hardware. It was a steep learning curve, but it totally paid off in the end in terms of size of the complete code base for the project. ROS offers great publisher/subscriber model, distributed nodes support for each component (camera, steering and throttle control, joystick, etc.). It also comes with great debugging and logging capabilities. If you’re new to ROS, I would highly recommend this book which teaches you the basics through fun projects along the way. In my case, I have camera and actuator (steering and throttle) nodes running on the car. Joystick, auto-pilot and training nodes are running on my desktop machine. Inference (neural network predictions) are compute intensive, so had to move it away from Raspberry Pi to beefier machine. Remember that you’ll need Ubuntu Mate distribution in order to run ROS on your Raspberry Pi. Here’s also a link for the ROS node camera support. What about AI? The auto-pilot for the car is based on now famous NVIDIA’s paper which is using Convolutional Neural Network (CNN) to predict the steering angle for the car based only on image input from the camera mounted in front of the car. You can read more on this topic in one of my previous posts. I’ve recently stumbled upon this paper which is exploring some other Deep Neural Network architectures for the same problem. You should check it out! One adjustment I had to do for the CNN compared to my previous Udacity project is introducing data binning. You should consider using it if: A column of continuous numbers has too many unique values to model effectively, so you automatically or manually assign the values to groups, to create a smaller set of discrete ranges. Column of continuous numbers in this case are steering angles for the car which were coming from joystick. I found that this modification improved my model predictions. Throttle on the other hand is fixed at the moment and it is something I would like to use prediction method as well. Conclusion Working on this project was a great way to get to know ROS (both benefits and challenges). It turns out that ROS is used by several autonomous car/minibus companies out there either as their prototyping platform and/or in production. Also, working on hardware can reveal some problems when you take your neural network from simulator and put it on a “real” car. All the code necessary for you to run ROS nodes on your own robot car can be found in my project repo together with helper scripts: And if you live in Berlin, make sure you drop by upcoming Robot Race on July 29th:
Build your own self driving (toy) car – Towards Data Science – Medium
Label: AI-NN-ML
Date: August 08, 2017 at 09:43PM