DonkeyCar for JetRacer ROS Tutorial I: Install Jetson Nano
From Waveshare Wiki
DonkeyCar for JetRacer ROS Tutorial
- DonkeyCar for JetRacer ROS Tutorial I: Install Jetson Nano
- DonkeyCar for JetRacer ROS Tutorial II: Setup Linux PC
- DonkeyCar for JetRacer ROS Tutorial III: Web Control
- DonkeyCar for JetRacer ROS Tutorial IV: Joystick Control
- DonkeyCar for JetRacer ROS Tutorial V: Collect Data
- DonkeyCar for JetRacer ROS Tutorial VI: Training Data
- DonkeyCar for JetRacer ROS Tutorial VII: Autonomous Driving
Note: DonkeyCar is already installed by default if you use our configured image, no need to install it again, just skip this tutorial.
Step 1: Install Dependencies
By default, your jetson nano has the image installed and started. Open the control terminal and enter the following command to install the dependency library.
sudo apt-get update sudo apt-get upgrade 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 2: Setup Virtual Environment
pip3 install virtualenv python3 -m virtualenv -p python3 env --system-site-packages source env/bin/activate #enter the virtual environment
- Note: After that, all operations of donkeycar need to be performed in this virtual environment. The newly opened terminal needs to run the source env/bin/activate command to enter this virtual environment.
Step 3: Install Python Dependencies
- Install dependencies by 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
- 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 ../
Step 4: Install Donkeycar
- Get the latest stable version of donkeycar program from Github and install it.
git clone https://github.com/autorope/donkeycar cd donkeycar git fetch --all --tags latestTag=$(git describe --tags `git rev-list --tags --max-count=1`) git checkout $latestTag pip install -e .[nano]
Step 5: Create Donkeycar Example
- Create donkeycar example by the following commands.
donkey createcar --path ~/mycar
After running the program, get the latest stable version of donkeycar program from Github and install it.
Step 6: Modify the Config File
- Open the following file, find the camera parameter setting section to modify the camera parameters:
nano ~/mycar/myconfig.py
- Jetson Nano uses a camera based on Sony IMX219, the camera is changed to CSIC, and the resolution is set to 224*224. Find the camera settings section and uncomment it and modify it as follows.
#CAMERA CAMERA_TYPE = "CSIC" # (PICAM|WEBCAM|CVCAM|CSIC|V4L|MOCK) IMAGE_W = 224 IMAGE_H = 224
- Modify the steering throttle control settings, find the following statement and remove the comment, and modify it as follows.
- Note: Steering is controlled by channel 0, and the throttle is controlled by channel 1. If the default setting is the opposite, it needs to be modified.
PWM_STEERING_THROTTLE = { "PWM_STEERING_PIN": "PCA9685.1:40.0", # PWM output pin for steering servo "PWM_STEERING_SCALE": 1.0, # used to compensate for PWM frequency differents from 60hz; NOT for adjusting steering range "PWM_STEERING_INVERTED": False, # True if hardware requires an inverted PWM pulse "PWM_THROTTLE_PIN": "PCA9685.1:40.1", # PWM output pin for ESC "PWM_THROTTLE_SCALE": 1.0, # used to compensate for PWM frequence differences from 60hz; NOT for increasing/limiting speed "PWM_THROTTLE_INVERTED": False, # True if hardware requires an inverted PWM pulse "STEERING_LEFT_PWM": 512, #pwm value for full left steering "STEERING_RIGHT_PWM": 102, #pwm value for full right steering "THROTTLE_FORWARD_PWM": 512, #pwm value for max forward throttle "THROTTLE_STOPPED_PWM": 307, #pwm value for no movement "THROTTLE_REVERSE_PWM": 102, #pwm value for max reverse throttle }
- The car program realizes the analog PCA9685 chip logic through the RP2040 chip I2C slave control. The PWM range can be set as above, and the steering throttle does not need to be recalibrated.