DonkeyCar for JetRacer ROS 教程一、Jetson nano安装

来自Waveshare Wiki
跳转至: 导航搜索

DonkeyCar for JetRacer ROS 教程目录


注意:使用我们配置好的镜像默认已经安装DonkeyCar,无需再安装,跳过此教程操作即可。

步骤1、安装依赖

默认你的jetson nano已经安装镜像并启动。打开控制终端,输入如下命令安装依赖库

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

步骤2、设置虚拟环境

pip3 install virtualenv
python3 -m virtualenv -p python3 env --system-site-packages
source env/bin/activate  #进入虚拟环境

  • 注意:之后donkeycar所以操作都需要在此虚拟环境中进行,新开的终端需要运行source env/bin/activate命令进入此虚拟环境。

步骤3、安装python依赖库

  • 通过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

步骤4、安装Donkeycar

  • 从Github获取最新稳定版donkeycar程序并安装
git clone https://github.com/autorope/donkeycar
cd donkeycar
git fetch --all --tags
git checkout 4.5.0
pip install -e .[nano]

步骤5、创建Donkeycar实例

  • 使用以下命令创建donkeycar实例
donkey createcar --path ~/mycar

程序运行后~/mycar目录下回自动生成一系列控制donkeycar的文件。

步骤6、修改配置文件

  • 打开如下文件,找到摄像头参数设置部分修改摄像头参数
nano ~/mycar/myconfig.py
  • Jetson Nano使用基于Sony IMX219的相机,摄像头改为CSIC,分辨率设置为224*224.找到摄像头设置部分并去掉注释并修改如下。
#CAMERA
CAMERA_TYPE = "CSIC"   # (PICAM|WEBCAM|CVCAM|CSIC|V4L|MOCK)
IMAGE_W = 224
IMAGE_H = 224
  • 修改转向油门控制设置,找到如下语句并去掉注释,修改如下。
  • 注意:转向通过0通道控制,油门通过1通道控制,如默认设置相反,需要修改。
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
}
  • 小车程序实现通过RP2040芯片I2C从机控制模拟PCA9685芯片逻辑,PWM范围设置如上既可,转向油门不需要再校准。