The Jetson Nano was released by NVIDIA in March 2019 as a competitor to the Raspberry Pi. It has 256 CUDA cores - making it significantly more powerful than the Raspberry Pi at graphics intensive operations.
The Donkey Car platform was developed a number of years ago and is comprised of a community of more than 5000+ people around the world. It is an open-source project with the aim of creating cheap autonomous cars.
When the Jetson Nano was released, everyone got really excited of the possibilities for a cheap, powerful autonomous car kit.
Getting StartedYou will need the following for this tutorial:
- Jetson Nano
- 64 GB SD Card
- Robo HAT MM1
- Raspberry Pi V2 Camera
- Car Body
- 3D Printed Parts
- Battery
Optional Parts:
- Backup LiPo Battery
- Larger 4000 mAh Battery
- Keyboard, Mouse and Screen
Part 1 - Initial Set UpNVIDIA have released a guide for setting up the Jetson Nano for the first time. It is reliable and should be followed carefully.
Part 2 - Tips and Tricks - More Memory
Credit:@JetsonHacks
The Jetson Nano only has a limited amount of RAM. This is a major issue when doing anything with AI. To elevate some of these issues, it is highly recommended to add more swap. This can be done with the below commands.
git clone https://github.com/JetsonHacksNano/installSwapfile
cd installSwapfile
./installSwapfile
The next thing to do is to restart the Jetson Nano to ensure that this setting is enabled.
sudo shutdown -r now
Part 3 - Tips and Tricks - More Power
The Jetson Nano has two different power modes. They are dependant on which type of power you are using. If you are using the DC barrel jack with a 5V 4 Amp power supply, you are able to enable high power mode (10 Watt).
sudo nvpmodel 0
If you are only using the micro USB port for power, it is better to use the low power mode (5W) as USB cannot provide the same current.
sudo nvpmodel 1
Part 4 - Update and Upgrade
Before continuing with this guide, it is recommended to install updates at this point. This way, you are guaranteed to have the latest features enabled. Make sure you are connected to a WiFi or Ethernet connection.
sudo apt update
sudo apt upgrade
Now that the Jetson Nano is completely up to date. We can begin installing the Donkey Car software pre-requisites. These will include Python 3 and tools used for installing software.
sudo apt-get install build-essential python3 python3-dev python3-pip python3-pandas python3-opencv python3-h5py libhdf5-serial-dev hdf5-tools nano ntp
Part 1 - Virtual Environment
Donkey Car is dependant on using a Virtual Python Environment to work effectively. You must set one up for it to work.
pip3 install virtualenv
python3 -m virtualenv -p
python3 env --system-site-packages
echo "source env/bin/activate" >> ~/.bashrc
source ~/.bashrc
You will end up with a (donkey) string in front of your console box.
Part 2 - Donkey Car
The latest Donkey Car for Jetson Nano code is on the official donkey car repository.
mkdir -p ~/projects
cd ~/projects
git clone https://github.com/autorope/donkeycar
git checkout master
cd donkeycar
pip3 install -e .[nano]
This may take a long time (up to 1 hour or more). So leave the Jetson Nano and come back a bit later.
ALTERNATIVE: If you want to use the absolute latest Donkey Car code you can use the dev
branch; but be warned some of it is not as tested.
git checkout dev
cd donkeycar
pip3 install -e .[nano]
Part 3 - Tensorflow
The Jetson Nano has a special version of Tensorflow that needs to be installed to enable access to the on-board GPU.
pip install --extra-index-url https://developer.download.nvidia.com/compute/redist/jp/v42 tensorflow-gpu==1.13.1+nv19.3
Part 4 - Donkey Car Create and Setup Application
You need to create a new donkey car.
donkey createcar ~/mycar
Then update your configuration file (myconfig.py
) to look like the below. Uncomment these lines and change accordingly:
CONTROLLER_TYPE='MM1'
. . .
HAVE_ROBOHAT = True
MM1_STEERING_MID = 1500
MM1_MAX_FORWARD = 2000
MM1_STOPPED_PWM = 1500
MM1_MAX_REVERSE = 1000
MM1_SHOW_STEERING_VALUE = False
#serial
MM1_SERIAL_PORT = '/dev/ttyTHS1'
Changing the serial port is important as the default Donkey Car behaviour is to use the Raspberry Pi's Serial Port.
You should now have all the software installed to make the donkey car work.
Part 5 - Configuration
There are some small configuration steps to take before the software can fully work.
Enable access to serial port:
sudo gpasswd --add ${USER} dialout
Enable access to I2C:
sudo usermod -a -G i2c ${USER}
The last step is to stop the GUI from running on your Jetson Nano. It takes up a lot of Memory (RAM) and this makes it hard to train the neural networks in later steps. You do not need it for Donkey Car, so we will remove it.
sudo systemctl set-default multi-user.target
Step 3 - Build your carHardware Guide video by Adam Conway (Donkey Car Community)
Many people have also come up with their own custom 3D printed designs that better fit the Jetson Nano and Robo HAT MM1. You can ask about them in the Donkey Car Discord.Step 4 - Drive your car
To drive your car, there are a number of different options. You can use a PS4 Controller but this requires additional configuration. The easiest method is using the Robo HAT MM1 and the RC Controller that came with your car body.
Follow the Hardware Guide on Hackster.io - Step 1 & 2 Only
Step 1 - Hardware Setup of Robo HAT MM1 (from above guide)
Step 2 - CircuitPython Setup of Robo HAT MM1 (from above guide)
Then it is as simple as starting up your car:
cd ~/mycar
python3 manage.py drive --js
It will start to take pictures and store them with the information from the RC Controller.
Step 5 - Training your car**NOT RECOMMENDED WITH JETSON NANO**
Since we already installed all the software on the Jetson Nano, we are able to use the Jetson Nano for training the neural network as well. This saves on the complication of setting up a second computer or if you are out in the field.
python3 manage.py train --tub tubs/ --model model/mymodel.hdf5
Depending on how many pictures have been taken, it could take between 40 minutes to multiple hours for the Jetson Nano to train the neural network.
**RECOMMENDED**
It is better to follow the Donkey Car Documentation for training with a computer.
Step 6 - AutopilotTo use your autopilot that you created above:
python3 manage.py drive --model model/mymodel.hdf5
ConclusionThere is more potential with the Jetson Nano to use other methods like OpenCV to control the car. This is something the Donkey Car community are already working on and is an interesting area of research.
This was a fun project to work on and I look forward to seeing what others can do with it to.
Comments