This is an autonomous car which I built and programed. It can drive around a track made of cones all by itself. It uses a convolutional neural network (CNN) for perception and a PID controller for driving.
These are the components and steps I used to build my platform:
- I used the following RC car platform as the base traxass 4-Tec 2.0 VXL AWD chassis
- I removed the reciever and speed controller and replaced the motor with the QuicRun Fusion Pro Motor because it allows the car to drive much more steady at slower speeds
- I also replaced the servo with another one that has the same size and specifications as the original one
- I use one LiPo battery to power the entire car including its computer and motor 11.1v 5200mah 80c lipo battery
- The battery is soldered straight to the motor power and connected to the computer via a manual switch
- I added a PCB board to the top of the car for mounting the on-board computer
- I use NVIDIA Jetson Orin Nano as the on-board computer for all the proccessing. I also soldered a connection from the switch to the barrel jack of Jetson.
- I also use Arduino Uno for motor control. All the wire connections will be specified later.
- Another small raised platform is added on top of the main platform to hold the camera. I mounted ZED Mini Stereo Camera onto this small platform.
- Both the camera and the Arduino board are connected to the Jetson via USB
- Both the servo and the motor should be connected to 5V and ground on the Arduino, the third wire on the motor should be connected to pin 9, and the 3rd pin on the servo should be connected to pin 10.
- To make the Arduino board control the motor upload the file
code/controller/arduino_ESC_servo_controller/arduino_ESC_servo_controller.inoto the Arduino board. - To control the motor speed and steering from Jetson download the file
code/controller/Car_Controller.pyto it. This is a class which contains functions for controlling motor speed and servo angle.
All code for autonomous driving is located in code/driving/. To run self-driving runtime, download all the files in that directory and run main.py. The file contains all of the parameters for the runtime like the PID controller gains, cone height, etc.
The following is a detailed description of how my system works:
First the car runtime uses a convolutional neural network (CNN), which I trained, to find the cones in the image. The CNN is able of differentiating between green and orange cones. All the code for the CNN is located in the directory code/cone_detection/. The file cone_finder_AI.py is the program that trains the CNN. There are a few programs I used to create the dataset that are located in code/dataset. I made the dataset by walking around with a camera at car height and recording videos using the collect_raw_images.py. I then automatically pasted prepared images of cones into video frames with another program. This is done by create_dataset.py. The resulting frames are used as the training dataset. The model checkpoint file for the already trained CNN is in the code/driving/ directory.
The driving algorithm is located in the main.py.
- First, it uses the CNN to detect all the cones. It then finds the closest green and orange cone using their mask areas. It assumes that the green cones should always be on the left and the orange cones should always be on the right.
- After that, it finds the center point between the two cones it found.
- If the camera sees only one cone (for example when the car is turning it doesn't see the inside cone, but can still see the outside cone) it will calculate the distance to the outside cone using inverse projection and then use that distance to find a center point some distance away from the outside cone. This distance can be specified with the
NON_VISIBLE_CONE_OFFSETparameter in themain.py. - Finally, it calculates the angle to the center point and uses two PI controllers (a PID controller without the differential part) to calculate the necessary steering angle and to compute the car speed to drive to that center point. The proportional and integral gains for the PI controllers can be adjusted in
main.py.
To see videos of this system in action download the demo videos