我进行Tensorflow1.0 API下的Object detection进行目标检测,推荐在树莓派安装ubuntu18.04 + ROS,使用tensorflow API。
TensorFlow1.0 Object detection API下载的地址,我使用了1.13.0:
git clone git://github.com/YuanzhengMa/models/tree/r1.13.0
下载镜像,我下载的石32位的server:
https://cdimage.ubuntu.com/releases/18.04/release/ubuntu-18.04.5-preinstalled-server-armhf+raspi4.img.xz
将树莓派卡插入读卡器,使用官网Raspberry Pi Imager, https://www.raspberrypi.org/software/
格式化后进行刻录:
这时候将卡插回树莓派就可以看到命令行,分别输入以下指令:
- 确保我们的系统为最新
sudo apt-get update
- 更换apt源,打开 source.list
sudo nano /etc/apt/source.list
增加如下:
deb https://mirrors.ustc.edu.cn/ubuntu-ports/ bionic main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu-ports/ bionic-updates main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu-ports/ bionic-backports main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu-ports/ bionic-security main restricted universe multiverse
- 继续更新一次系统
sudo apt-get update
sudo apt-get install ubuntu-desktop
#sudo apt-get install ubuntu-mate-desktop # 安装mate
- 安装远程控制桌面,可以PC,Mac甚至手机端下载VNC viewer进行控制
sudo apt-get install xrdp
- 安装ROS
sudo apt-get update
# ROS wki as reference
# http://wiki.ros.org/melodic/Installation/Ubuntu
# setup your sources.list
sudo sh -c '. /etc/lsb-release && echo "deb http://mirrors.tuna.tsinghua.edu.cn/ros/ubuntu/ `lsb_release -cs` main" > /etc/apt/sources.list.d/ros-latest.list'
5.1 设置source key
sudo apt-key adv --keyserver 'hkp://keyserver.ubuntu.com:80' --recv-key C1CF6E31E6BADE8868B172B4F42ED6FBAB17C654
sudo apt update
5.2 安装ROS-melodic
sudo apt install ros-melodic-desktop-full
5.3 如果提示丢包,我建议kill掉进程后使用fix-missing:
sudo apt-get update
sudo apt install ros-melodic-desktop-full --fix-missing
5.4 环境设置
# It's convenient if the ROS environment variables are automatically added to your bash session every time a new shell is launched:
echo "source /opt/ros/melodic/setup.sh" >> ~/.bashrc
source ~/.bashrc
5.5 安装python以及ROS相关依赖库
sudo apt install python-rosdep python-rosinstall python-rosinstall-generator python-wstool build-essential
5.6 安装rosdep,并执行更新,这个非常容易掉线:
sudo rosdep init
rosdep update
如果失败,改大延迟,提高 rosdep update命中率
sudo apt update
5.6.1 打开 sudo nano sources_list.py
cd /usr/lib/python2.7/dist-packages/rosdep2
# 这里树莓派raspbian buster和他的路径是一致的
sudo nano sources_list.py
5.6.2 在如下download_rosdep_data中,将url更改为"https://ghproxy.com/"+url:
# seconds to wait before aborting download of rosdep data
DOWNLOAD_TIMEOUT = 300.0
def download_rosdep_data(url):
"""
:raises: :exc:`DownloadFailure` If data cannot be
retrieved (e.g. 404, bad YAML format, server down).
"""
try:
# http/https URLs need custom requests to specify the user-agent, since$
# requests from the default user-agent.
url="https://ghproxy.com/"+url
5.6.3 打开sudo nano gbpdistro_support.py,将延迟由15更改为300
# seconds to wait before aborting download of gbpdistro data
DOWNLOAD_TIMEOUT = 300.0
5.6.4 打开sudo nano rep3.py
将DOWNLOAD_TIMEOUT延时15更改为300
cd /usr/lib/python2.7/dist-packages/rosdistro$ ,对init.py原先DEFAULT_INDEX_URL前端加入'https://ghproxy.com/,
最终:DEFAULT_INDEX_URL = 'https://ghproxy.com/https://raw.githubusercontent.com/ros/rosdistro/master/index-v4.yaml'
sudo nano __init__.py
# same version as in:
# - setup.py
# - stdeb.cfg
__version__ = '0.8.3'
# index information
#DEFAULT_INDEX_URL = 'https://raw.githubusercontent.com/ros/rosdistro/master/index-v4.yaml'
DEFAULT_INDEX_URL = 'https://ghproxy.com/https://raw.githubusercontent.com/ros/rosdistro/master/index-v4.yaml'
然后再执行安装rosdep update
ubuntu@ubuntu:~$ sudo apt update
rosdep update
sudo apt update
如果解析域名失败,修改google域名的解决办法:
sudo gedit /etc/resolv.conf
5.6.5 将原有的nameserver这一行注释,并添加以下两行:
nameserver 8.8.8.8 #google域名服务器
nameserver 8.8.4.4 #google域名服务器
5.6.6 保存退出,执行
sudo apt-get update
5.6.7 再执行更新
rosdep update
sudo apt update
- 执行roscore,启动ros程序
roscore
- crtl + alt + T,新建terminal, 运行turtlesim
rosrun turtlesim turtlesim_node
- 再新建终端,ctrl + alt + T,
rosrun turtlesim turtle_teleop_key
修改串口,这个很重要后面ROS控制需要
- 查看当前串口状态,交换蓝牙串口和mini-uart
ls /dev/ -all
cd /boot/firmware
sudo nano config.txt
9.1 在文件最后新增
dtoverlay=miniuart-bt
force_turbo=1
9.2 reboot一下,最终状态为
crw-rw---- 1 root dialout 204, 64 Aug 6 2020 ttyAMA0
crw-rw---- 1 root dialout 4, 64 Aug 6 2020 ttyS0
9.3 打开firmware,将第三第四删除,
cd /boot/firmware
sudo nano nobtcmd.txt
最终修正为
net.ifnames=0 dwc_otg.lpm_enable=0 console=tty1 root=LABEL=writable rootfstype=ext4 elevator=deadline rootwait fixrtc
9.4 reboot一下,查看最终修改状态,查看用户组是否在dailout,查看串口读写权限,安装rosserial测试
crw-rw---- 1 root dialout 204, 64 Aug 6 2020 ttyAMA0
crw-rw---- 1 root dialout 4, 64 Aug 6 2020 ttyS0
9.5 输入:
groups ubuntu
显示ubuntu : ubuntu adm dialout cdrom floppy sudo audio dip video plugdev lxd。。。。。。
- 安装ros-melodic-rosserial
sudo apt install ros-melodic-rosserial ros-melodic-rosserial-arduino
- 启动roscore,设置rosrundiaoyong串口,在未链接外设情况下启动测试rosserial,显示同步15秒超时
roscore
rosrun rosserial_python serial_node.py _port:=/dev/ttyAMA0 _baud:=115200
配置swap
- 配置swap为2GB基本够用,目的是为了防止因为内存不足引起树梅派(如4b1G)catkin_make闹错,因为内存引起的catkin_make报错也可限制核心数量,如-j1或-j2
sudo apt-get install dphys-swapfile
sudo nano /etc/dphys-swapfile
去掉注释#,修改CONF_SWAPSIZE为修改
CONF_SWAPSIZE=2048
- 查看swap是否生效
reboot
free -h
完毕,速度哦