默认你的树莓派已经安装镜像并启动。已连接wifi,开启SSH,启动I2C接口和相机,扩展文件系统。 打开控制终端,输入如下命令安装依赖库
- sudo apt-get update
- sudo apt-get upgrade
- sudo apt-get install build-essential python3 python3-dev python3-pip python3-virtualenv python3-numpy python3-picamera -y
- sudo apt-get install python3-pandas python3-rpi.gpio i2c-tools avahi-utils joystick libopenjp2-7-dev libtiff5-dev gfortran -y
- sudo apt-get install libatlas-base-dev libopenblas-dev libhdf5-serial-dev git ntp -y
- sudo apt-get install libilmbase-dev libopenexr-dev libgstreamer1.0-dev libjasper-dev libwebp-dev -y
- sudo apt-get install libatlas-base-dev libavcodec-dev libavformat-dev libswscale-dev libqtgui4 libqt4-test -y
- python3 -m virtualenv -p python3 env --system-site-packages
- echo "source env/bin/activate" >> ~/.bashrc
- source ~/.bashrc
以此方式修改.bashrc会在您每次登录时自动启用此虚拟环境。要返回系统python,您可以输入deactivate。
创建工程项目目录
- mkdir projects
- cd ~/projects
- git clone https://github.com/autorope/donkeycar
- cd donkeycar
- git checkout master
- pip install -e .[pi]
- pip install tensorflow==1.13.1
您可以使用以下方法验证您的tensorflow安装
- python -c "import tensorflow"
如果没有错误则正常安装,出现如下警告是正常的。
- /home/pi/env/lib/python3.5/importlib/_bootstrap.py:222: RuntimeWarning: compiletime version 3.4 of module 'tensorflow.python.framework.fast_tensor_util' does not match runtime version 3.5
- return f(*args, **kwds)
- /home/pi/env/lib/python3.5/importlib/_bootstrap.py:222: RuntimeWarning: builtins.type size changed, may indicate binary incompatibility. Expected 432, got 412
- return f(*args, **kwds)
- sudo apt install python3-opencv
如果安装失败可以尝试如下命令重新安装。
- pip install opencv-python
运行如下命令测试OpenCV是否安装成功。
- python -c "import cv2"
如果没有错误,则说明您已经安装了OpenCV!
注意:如果提示__atomic_fetch_add_8未定义错误。先用deactivate指令退出虚拟环境,运行下面的指令,然后再重新测试一下,
- deactivate
- echo "export LD_PRELOAD=/usr/lib/arm-linux-gnueabihf/libatomic.so.1 " >> ~/.bashrc
- source ~/.bashrc
运行如下命令安装OLED显示服务,OLED会显示当前IP地址,电池电压,充电电流等信息。
- cd ~
- git clone https://github.com/waveshare/pi-display
- cd pi-display
- sudo ./install.sh
- cd ~/projects/donkeycar
- donkey createcar --path ~/mycar
程序运行后~/mycar目录下回自动生成一系列控制donkeycar的文件。