Do not waste time & money on this if you are not familiar with linux and openpilot, debug skill required.
- What is openpilot?
- About this
- To do
- Hardware preparation
- Software preparation
- Installation
- Jetson useful links
- Openpilot patch
- To run
- Tuning
- Credits
openpilot is an open source driver assistance system. Currently, openpilot performs the functions of Adaptive Cruise Control (ACC), Automated Lane Centering (ALC), Forward Collision Warning (FCW) and Lane Departure Warning (LDW) for a growing variety of supported car makes, models and model years. In addition, while openpilot is engaged, a camera based Driver Monitoring (DM) feature alerts distracted and asleep drivers.
This project is to showcase how to run openpilot on Nvidia Jetson Xavier NX with minimal changes to openpilot.
The video was recorded on commit 22cf2e6440ca004994f30b7b9e8d0c20de35c52a on 17/05/2021 (v0.8.4).
Simulation:
On road:
- Create build scripts.
- Add patch samples/tutorials.
- On road tests.
- Add sensor support.
- Tuning tutorials.
- Nvidia Jetson Xavier NX
- 32GB+ microsd card (UHS 3 speed minimum)
- Waveshare IMX 219-83 Stereo Camera
- comma.ai Black Panda (or white/grey panda but require more code customization.)
- Jetpack 4.5.1
- While installing, use username "openpilot".
- clone this repo to your home directory (e.g.
cd ~/ && git clone https://github.com/efinilan/xnxpilot.git
) - run:
cd ~/xnxpilot/ && ./1_install.sh
wait for reboot. - run:
cd ~/xnxpilot/ && ./2_install.sh
wait for reboot. - run:
cd ~/xnxpilot/ && ./3_install.sh
wait for reboot. - run:
cd ~/xnxpilot/ && ./4_install.sh
wait for reboot. - Completed, this should be the minimal configuration to run openpilot on Jetson.
Here are a few useful links I found that can potentially improve Jetson performance.
- Useful tips before using Jetson Series(Nano, TX2, Xavier NX, Xavier)
- Script to remove unnecessary stuffs from the Jetson to save disk space (WIP)
- Scripts to help build the 4.9.201 kernel and modules onboard the Jetson Xavier NX (L4T 32.5.1, JetPack 4.5.1).
- Jetson hacks
- Jetson kernel customization
This is based on the openpilot master branch and is constantly changing, so there is no patch that works all the time. Here I will explain why these files are changed so you can update the patches in the future.
Notes: All the sample patches below are based on commit 22cf2e6440ca004994f30b7b9e8d0c20de35c52a on 17/05/2021 (v0.8.4).
This file patches SConstruct
file in the openpilot root folder.
Here we:
- Create a new
arch
calledlinuxarm64
so the reset of the modules will not mis-identify your board asaarch64
orlarch64
used by comma.ai's board. - Setup the right environment path/variables, since it's not
aarch64
orlarch64
, the default configuration uses x64/x86 architecure, however, jetson is arm64 (aarch64) based, so we have to utilize a few libraries fromlarch64
configuration.
This file patches selfdrive/crash.py
so it does not use sentry.io library
Noted openpilot has plan to deprecate sentry.io service so the file may not exist in the future.
Here we:
- keep all the function/method and simply
pass
the logic. - remove everything related to sentry sdk
This file patches selfdrive/manager/manager.py
so it bypass comma.ai registration
Here we:
- Simply give "
00000
" (or whatever you wish) as your dongle_id
This file patches selfdrive/manager/process_config.py
to disable several CPU intense processes.
Here we:
- Disable service including:
manage_athenad
,logcatd
,loggerd
,logmessaged
,updated
,uploader
This file patches selfdrive/thermald/thermald.py
to turn into onroad mode right away.
This is for testing the system locally without waiting for ignition signal.
This file patches selfdrive/modeld/SConscript
to disable use of SNPE
Here we:
- Add a condition when it identify the board as "```linuxarm64``" just like Darwin (Mac), we do not use any of the SNPE library existed on Qualcomm platforms.
This file patches selfdrive/modeld/runners/onnx_runner.py
to use CUDA as execution provider.
When openpilot runs in PC mode, it uses ONNX Runtime to load the AI model, however, it uses CPU as it's execution provider by default.
Here we:
- Changed
CPUExecutionProvider
toCUDAExecutionProvider
This file patches selfdrive/camerad/cameras/camera_webcam.cc
to use gstreamer for video feed.
Only consider this patch if you want to use MIPI camera interface.
Here we:
- Uses gstreamer to get video sources.
- Map driver camera to the 2nd camera of the stereo camera.
First compile with:
cd ~/openpilot
USE_WEBCAM=1 scons -j ($nproc)
Then run it with:
cd ~/openpilot/selfdrive/manager
PASSIVE=0 NOSENSOR=1 USE_WEBCAM=1 ./manager.py
to be able to start openpilot at boot, there are a couple of process we need to do:
- make sure your user
openpilot
has sufficient permissions:
sudo usermod -aG video openpilot
sudo usermod -aG root openpilot
Perhaps the quickest way is to give root privilege, edit /etc/passwd and change your user/grup id to 0, e.g.:
openpilot:x:1000:1000:openpilot,,,:/home/opnpilot:/bin/bash
and change to
openpilot:x:0:0:openpilot,,,:/home/opnpilot:/bin/bash
for some unknown reasons gstreamer is unable to get video position(?) in a non-root environment.
- Create a script to start openpilot, place this file in /home/openpilot/start_op.sh (your home folder):
#!/bin/bash
cd /home/openpilot/openpilot/selfdrive/manager/
PASSIVE=0 NOSENSOR=1 USE_WEBCAM=1 ./managaer
make sure you make it executable:
chmod +x /home/openpilot/start_op.sh
- Modify
/home/openpilot/.bashrc
to use tmux: at the end of the file, make sure you have these:
export PYENV_ROOT="/home/openpilot/.pyenv"
export PATH="/home/openpilot/.pyenv/bin:/home/openpilot/.pyenv/shims:/home/openpilot/.pyenv/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin"
source /home/openpilot/openpilot/tools/openpilot_env.sh
cd /home/openpilot/openpilot
TMUX_SESSION="openpilot"
tmux has-session -t ${TMUX_SESSION} 2>/dev/null
if [ $? != 0 ]; then
tmux new-session -s ${TMUX_SESSION} -n bash -d
tmux send-keys -t ${TMUX_SESSION}:0 'bash /home/openpilot/start_op.sh' C-m
fi
tmux attach-session -t ${TMUX_SESSION}
the first 2~3 line should already be in your .bashrc file (something similar)
- (Optional) Modify
/home/openpilot/.config/lxsession/LXDE/autostart
to start a lxterminal after you boot up. add the line below at the end of the file:
@lxterminal
so now once you logged into one of your terminal/console, it should run openpilot on your first tmux session just like openpilot on EON/C2.