树莓派4B-buster安装ROS Melodic流程

安装ROS Melodic

树莓派4B配置:

RAM: 2G
SD卡: 32G【装了opencv等其他杂七杂八的16g可能有点不够】
系统:  Buster【2020-02-13-raspbian-buster.img】

参考文献

安装参考1:ros官网
安装参考2:kinetic
安装参考3:meldic
安装参考4:注释

说明:

  我曾经用buster安装ros-kinetic,但在后面安装好mavros执行roslaunch mavros px4.launch时报错:exit code -11,百度不到解决这个错误的方法。后来在github上了解到有人用ubuntu14安装出现了这个问题然后安装对应版本的ros即可。我转而百度一下对照表,buster对应ubuntu18.04应该安装melodic。
  在安装前最好先备份下系统,安装melodic照着wiki来就行了,melodic不需要改成gcc5。

开始安装

  国内博客都是照着ros官网安装的,只是多了一些注意点和错误解决。我用的是清华源,这种基本配置就不讲了。

1. Prerequisites

sudo sh -c 'echo "deb http://packages.ros.org/ros/ubuntu $(lsb_release -sc) main" > /etc/apt/sources.list.d/ros-latest.list'
sudo apt-key adv --keyserver hkp://ha.pool.sks-keyservers.net:80 --recv-key C1CF6E31E6BADE8868B172B4F42ED6FBAB17C654
sudo apt-get update
sudo apt-get upgrade
sudo apt install -y python-rosdep python-rosinstall-generator python-wstool python-rosinstall build-essential cmake
sudo rosdep init
rosdep update

  这里一般会出现rosdep init和rosdep update失败
第一步:修改以下文件第40行timeout改的大一点(默认15),我改了15000

 sudo vim /usr/lib/python2.7/dist-packages/rosdep2/gbpdistro_support.py

第二步:修改host。最后一行添加 199.232.68.133 raw.githubusercontent.com
这个ip是谋篇博客抄的比自己搜的好用。当然也可以https://githubusercontent.com.ipaddress.com/raw.githubusercontent.com把找到的ip地址填上去。

sudo vi /etc/hosts

  这样的话一般都可以成功init,但update成功率还是很低。如果init成功,但update一直失败,则直接照着这篇做 rosdep update,我试了4次就成功了。

下面不要看,直接看2.Installation
  先把init得到的旧20-default.list文件删除,然后再init直到成功,后再update。可以试试不同的host。这个要是很多很多次,如果一个时间点失败大几十次,最好换个点再来,我是第二天早上成功的。

sudo rm /etc/ros/rosdep/sources.list.d/20-default.list
sudo rosdep init
rosdep update

2.Installation

  建立工作空间并安装comm版本ros

mkdir -p ~/ros_catkin_ws
cd ~/ros_catkin_ws
rosinstall_generator ros_comm --rosdistro melodic --deps --wet-only --tar > melodic-ros_comm-wet.rosinstall
wstool init src melodic-ros_comm-wet.rosinstall

  如果wstool init中断,那么直接运行下面的代码,继续执行编译。-j4是4个文件一起编译,这样比不加会编译的快点,也可以-j2 -j4 -j8。如果wstool init卡住长时间still active建议直接ctrl+c重新来。
  如果使用该命令出现error什么的,建议换-j?或者不加试试,我多次出现error后用-j2成功的。

wstool update -j4 -t src

  安装依赖

cd ~/ros_catkin_ws
rosdep install -y --from-paths src --ignore-src --rosdistro melodic -r --os=debian:buster

  编译和添加环境,这里不需要箱安装kxxx版一样改成gcc5

sudo ./src/catkin/bin/catkin_make_isolated --install -DCMAKE_BUILD_TYPE=Release --install-space /opt/ros/melodic -j4

  这里可能会报错Unable to find either executable 'empy' or Python module 'em'... try installing the package 'python-empy'

解决方法
sudo apt-get install python-empy

source /opt/ros/melodic/setup.bash
echo "source /opt/ros/melodic/setup.bash" >> ~/.bashrc

  到这里其实已经可以测试了,在终端输入roscore如果没有报错就已经是成功安装好了。但最好还需要执行下下面步骤。
   运行roscore出现报错
   问题1ImportError: No module named 'defusedxml'

sudo pip install defusedxml

   问题2ImportError: No module named 'netifaces'

sudo pip install netifaces

   问题3:这里可能出现另一个问题。安装好上面的包后roscore不报错,但重启后运行roscore会出现import netifacesdist-packages/netifaces.so: file too short的报错。卸载netifaces后再次安装,出现zipfile.BadZipFile: File is not a zip file,换用豆瓣的镜像源后成功。

sudo pip uninstall netifaces
sudo pip install netifaces -i http://pypi.douban.com/simple/ --trusted-host pypi.douban.com

3.Maintaining a Source Checkout

  进一步安装依赖

cd ~/ros_catkin_ws
rosinstall_generator ros_comm ros_control joystick_drivers --rosdistro melodic --deps --wet-only --tar > melodic-custom_ros.rosinstall
wstool merge -t src melodic-custom_ros.rosinstall

  这边的wstool也可以-j2 -j4 -j8 编译,不加也行。

wstool update -j4 -t src
rosdep install --from-paths src --ignore-src --rosdistro melodic -y -r --os=debian:buster
sudo ./src/catkin/bin/catkin_make_isolated --install -DCMAKE_BUILD_TYPE=Release --install-space /opt/ros/melodic -j4

melodic安转改一段落,下面是kinetic安装时需要改gcc版本

  查看gcc版本,我是5和8

ls /usr/bin/gcc*

  配置g++,选择g++5

sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-5 50
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-8 40
sudo update-alternatives --config g++

  配置gcc,选择gcc5

sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-5 50
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-8 40
sudo update-alternatives --config gcc

  查看当前版本

gcc -v
g++ -v

  改gcc时注意更改为gcc5.5和g++5。GCC和G++都要,只改一个编译会报错,如果报错了,就要用sudo rm -rdelete build_isolated and devel_isolated两个包,不然你改了也没用。

你可能感兴趣的:(树莓派,raspberry,pi,ubuntu)