Get Your Jetson Nano/Xavier NX Working

donkey

Step 1: Flash Operating System

These instructions work for Jetpack 4.5.1. They are known to NOT work on Jetpack 4.6 or 4.6.1.

This installs the official Nvidia build of Tensorflow 2.3.1; make sure you are using the same version of Tensorflow on your host PC if you are using one. Using a different version of Tensorflow to train your network may result in errors when you attempt to use it as an autopilot.

Visit the official Nvidia Jetson Nano Getting Started Guide or Nvidia Xavier NX Getting Started Guide. Work through the Prepare for Setup, Writing Image to the microSD Card, and Setup and First Boot instructions, then return here.

Once you're done with the setup, ssh into your vehicle. Use the the terminal for Ubuntu or Mac. Putty for windows.

Step 2: Free up the serial port (optional. Only needed if you're using the Robohat MM1)

sudo usermod -aG dialout <your username>
sudo systemctl disable nvgetty

Step 3: Install System-Wide Dependencies

First install some packages with apt-get.

sudo apt-get update -y
sudo apt-get upgrade -y
sudo apt-get install -y libhdf5-serial-dev hdf5-tools libhdf5-dev zlib1g-dev zip libjpeg8-dev liblapack-dev libblas-dev gfortran
sudo apt-get install -y python3-dev python3-pip
sudo apt-get install -y libxslt1-dev libxml2-dev libffi-dev libcurl4-openssl-dev libssl-dev libpng-dev libopenblas-dev
sudo apt-get install -y git nano
sudo apt-get install -y openmpi-doc openmpi-bin libopenmpi-dev libopenblas-dev

Step 4: Setup Virtual Environment

pip3 install virtualenv
python3 -m virtualenv -p python3 env --system-site-packages
echo "source ~/env/bin/activate" >> ~/.bashrc
source ~/.bashrc

Step 5: Setup Python Dependencies

Next, you will need to install packages with pip:

pip3 install -U pip testresources setuptools
pip3 install -U futures==3.1.1 protobuf==3.12.2 pybind11==2.5.0
pip3 install -U cython==0.29.21 pyserial
pip3 install -U future==0.18.2 mock==4.0.2 h5py==2.10.0 keras_preprocessing==1.1.2 keras_applications==1.0.8 gast==0.3.3
pip3 install -U absl-py==0.9.0 py-cpuinfo==7.0.0 psutil==5.7.2 portpicker==1.3.1 six requests==2.24.0 astor==0.8.1 termcolor==1.1.0 wrapt==1.12.1 google-pasta==0.2.0
pip3 install -U gdown

# This will install tensorflow as a system package
pip3 install --pre --extra-index-url https://developer.download.nvidia.com/compute/redist/jp/v45 tensorflow==2.3.1

Finally, you can install PyTorch:

wget https://nvidia.box.com/shared/static/p57jwntv436lfrd78inwl7iml6p13fzh.whl
cp p57jwntv436lfrd78inwl7iml6p13fzh.whl torch-1.8.0-cp36-cp36m-linux_aarch64.whl
pip3 install torch-1.8.0-cp36-cp36m-linux_aarch64.whl
sudo apt-get install libjpeg-dev zlib1g-dev libpython3-dev libavcodec-dev libavformat-dev libswscale-dev
mkdir -p ~/projects; cd ~/projects
git clone -b v0.9.0 https://github.com/pytorch/vision torchvision
cd torchvision 
python setup.py install
cd ../

Optionally, you can install the RPi.GPIO clone for Jetson Nano from here. This is not required for default setup, but can be useful if using LED or other GPIO driven devices.

Step 5: Install Donkeycar Python Code

  • Change to a dir you would like to use as the head of your projects. Assuming you've already made the projects directory above, you can use that:
cd ~/projects
  • Get the latest donkeycar from Github.

    Note: There are currently version updates happening on the main branch so you might rather want to checkout the latest stable release as explained below.

git clone https://github.com/autorope/donkeycar
cd donkeycar
git checkout main
pip3 install -e .[nano]
  • Alternatively, to get the latest stable release
git clone https://github.com/autorope/donkeycar
cd donkeycar
git fetch --all --tags -f
latestTag=$(git describe --tags `git rev-list --tags --max-count=1`)
git checkout $latestTag
pip install -e .[nano]

Step 6: (Optional) Fix for pink tint on CSIC cameras

If you're using a CSIC camera you may have a pink tint on the images. As described here, this fix will remove it.

wget https://www.dropbox.com/s/u80hr1o8n9hqeaj/camera_overrides.isp
sudo cp camera_overrides.isp /var/nvidia/nvcam/settings/
sudo chmod 664 /var/nvidia/nvcam/settings/camera_overrides.isp
sudo chown root:root /var/nvidia/nvcam/settings/camera_overrides.isp

Step 7: (Optional) Install PyGame for USB camera

If you plan to use a USB camera, you will also want to setup pygame:

sudo apt-get install python-dev libsdl1.2-dev libsdl-image1.2-dev libsdl-mixer1.2-dev libsdl-ttf2.0-dev libsdl1.2-dev libsmpeg-dev python-numpy subversion libportmidi-dev ffmpeg libswscale-dev libavformat-dev libavcodec-dev libfreetype6-dev

pip install pygame

Later on you can add the CAMERA_TYPE="WEBCAM" in myconfig.py.


Next, create your Donkeycar application.