树莓派4B安装ROS(Kinetic版本)


文章目录

  • ROS安装
        • 树莓派系统
        • 安装 boosttrap 依赖
        • 初始化 rosdep
        • 创建 catkin 工作空间
        • 下载 ROS 功能包清单文件
        • 解决功能包依赖
        • 去除 libboost1.67 ,安装 libboost1.58
        • 编译、安装 ROS(Desktop版本有191个包)
  • 编译报错处理
      • 1. 编译报错(python-empy)
      • 2. 编译报错(opencv)
          • 2.1 找不到 cuda.hpp 文件
          • 2.2 缺少 *.i 文件
          • 2.3 cv2.cpp 文件报错
      • 3.编译报错(qt_gui_cpp)
      • 4.编译报错(tf2)
      • 5.编译报错(rviz)
  • 运行报错处理
      • RVIZ启动报错
  • 参考链接
  • 附件

ROS安装

树莓派系统

1
2
3
4
Distributor ID: Raspbian
Description:    Raspbian GNU/Linux 10 (buster)
Release:    10
Codename:   buster

安装 boosttrap 依赖

1
sudo apt-get install python-rosdep python-rosinstall-generator python-wstool python-rosinstall build-essential

初始化 rosdep

1
2
sudo rosdep init
rosdep update

这边需要说明下,执行sudo rosdep init时,如果不翻墙,很大可能会失败

创建 catkin 工作空间

1
2
mkdir ~/ros_catkin_ws
cd ~/ros_catkin_ws

下载 ROS 功能包清单文件

1
2
rosinstall_generator desktop --rosdistro kinetic --deps --wet-only --tar > kinetic-desktop-wet.rosinstall
wstool init -j8 src kinetic-desktop-wet.rosinstall

有3个选择
1、Desktop-Full:ROS, rqt, rviz, robot-generic libraries, 2D/3D simulators, navigation and 2D/3D perception
2、Desktop: ROS, rqt, rviz, and robot-generic libraries
3、ROS-Comm:ROS package, build, and communication libraries. No GUI tools
这边选择Desktop版本

执行完命令后,会开始同步安装ROS需要的功能包,下载的功能包在~/ros_catkin_ws/src
如果下载失败,或者中断,可以执行以下命令继续更新

1
wstool update -j 4 -t src

解决功能包依赖

1
rosdep install --from-paths src --ignore-src --rosdistro kinetic -y

执行完后会自动去下载缺少的依赖软件

去除 libboost1.67 ,安装 libboost1.58

1
2
3
4
5
6
7
8
9
10
11
12
13
sudo apt remove libboost1.67-dev
sudo apt autoremove
sudo apt install -y libboost1.58-dev libboost1.58-all-dev
sudo apt install -y g++-5 gcc-5
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-5 10
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-5 20
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-5 10
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-5 20
sudo update-alternatives --install /usr/bin/cc cc /usr/bin/gcc 30
sudo update-alternatives --set cc /usr/bin/gcc
sudo update-alternatives --install /usr/bin/c++ c++ /usr/bin/g++ 30
sudo update-alternatives --set c++ /usr/bin/g++
sudo apt install -y python-rosdep python-rosinstall-generator python-wstool python-rosinstall build-essential cmake

编译、安装 ROS(Desktop版本有191个包)

1
sudo ./src/catkin/bin/catkin_make_isolated --install -DCMAKE_BUILD_TYPE=Release --install-space /opt/ros/kinetic

编译报错处理

1. 编译报错(python-empy)

1
2
3
4
5
6
CMake Error at cmake/empy.cmake:29 (message):
  Unable to find either executable 'empy' or Python module 'em'...  try
  installing the package 'python-empy'
Call Stack (most recent call first):
  cmake/all.cmake:164 (include)
  CMakeLists.txt:8 (include)

解决办法

1
sudo apt-get install python-empy

2. 编译报错(opencv)

2.1 找不到 cuda.hpp 文件
1
2
3
4
5
In file included from /home/pi/ros_catkin_ws/src/opencv3/modules/stitching/include/opencv2/stitching.hpp:49:0,
                 from /home/pi/ros_catkin_ws/src/opencv3/modules/stitching/src/precomp.hpp:59,
                 from /home/pi/ros_catkin_ws/build_isolated/opencv3/install/modules/stitching/opencv_stitching_pch_dephelp.cxx:1:
/home/pi/ros_catkin_ws/src/opencv3/modules/stitching/include/opencv2/stitching/detail/matchers.hpp:52:42: fatal error: opencv2/xfeatures2d/cuda.hpp: No such file or directory
compilation terminated.

解决办法

一般cuda.hpp文件在你的路径/opencv3/opencv_contrib/xfeatures2d/include/opencv2/xfeatures2d/cuda.hpp可以使用find命令查找

1
sudo find / -name "cuda.hpp"

然后直接在报错的文件上添加cuda.hpp文件的绝对路径

1
2
3
#  include "opencv2/xfeatures2d/cuda.hpp"
改为
#  include "你的路径/opencv3/opencv_contrib/xfeatures2d/include/opencv2/xfeatures2d/cuda.hpp/opencv2/xfeatures2d/cuda.hpp"

找不到文件opencv2/xfeatures2d.hppopencv2/xfeatures2d/nonfree.hpp等的错误都可以用这种方式来解决

2.2 缺少 *.i 文件
1
2
/home/pi/ros_catkin_ws/src/opencv3/opencv_contrib/xfeatures2d/src/boostdesc.cpp:646:37: fatal error: boostdesc_bgm.i: No such file or directory
compilation terminated.

解决办法

下载缺少的文件,放在opencv3/opencv_contrib/xfeatures2d/src

1
2
3
4
5
6
7
8
9
10
11
curl https://raw.githubusercontent.com/opencv/opencv_3rdparty/34e4206aef44d50e6bbcd0ab06354b52e7466d26/boostdesc_lbgm.i > 0ae0675534aa318d9668f2a179c2a052-boostdesc_lbgm.i
curl https://raw.githubusercontent.com/opencv/opencv_3rdparty/34e4206aef44d50e6bbcd0ab06354b52e7466d26/boostdesc_binboost_256.i > e6dcfa9f647779eb1ce446a8d759b6ea-boostdesc_binboost_256.i
curl https://raw.githubusercontent.com/opencv/opencv_3rdparty/34e4206aef44d50e6bbcd0ab06354b52e7466d26/boostdesc_binboost_128.i > 98ea99d399965c03d555cef3ea502a0b-boostdesc_binboost_128.i
curl https://raw.githubusercontent.com/opencv/opencv_3rdparty/34e4206aef44d50e6bbcd0ab06354b52e7466d26/boostdesc_binboost_064.i > 202e1b3e9fec871b04da31f7f016679f-boostdesc_binboost_064.i
curl https://raw.githubusercontent.com/opencv/opencv_3rdparty/34e4206aef44d50e6bbcd0ab06354b52e7466d26/boostdesc_bgm_hd.i > 324426a24fa56ad9c5b8e3e0b3e5303e-boostdesc_bgm_hd.i
curl https://raw.githubusercontent.com/opencv/opencv_3rdparty/34e4206aef44d50e6bbcd0ab06354b52e7466d26/boostdesc_bgm_bi.i > 232c966b13651bd0e46a1497b0852191-boostdesc_bgm_bi.i
curl https://raw.githubusercontent.com/opencv/opencv_3rdparty/34e4206aef44d50e6bbcd0ab06354b52e7466d26/boostdesc_bgm.i > 0ea90e7a8f3f7876d450e4149c97c74f-boostdesc_bgm.i
curl https://raw.githubusercontent.com/opencv/opencv_3rdparty/fccf7cd6a4b12079f73bbfb21745f9babcd4eb1d/vgg_generated_120.i > 151805e03568c9f490a5e3a872777b75-vgg_generated_120.i
curl https://raw.githubusercontent.com/opencv/opencv_3rdparty/fccf7cd6a4b12079f73bbfb21745f9babcd4eb1d/vgg_generated_64.i > 7126a5d9a8884ebca5aea5d63d677225-vgg_generated_64.i
curl https://raw.githubusercontent.com/opencv/opencv_3rdparty/fccf7cd6a4b12079f73bbfb21745f9babcd4eb1d/vgg_generated_48.i > e8d0dcd54d1bcfdc29203d011a797179-vgg_generated_48.i
curl https://raw.githubusercontent.com/opencv/opencv_3rdparty/fccf7cd6a4b12079f73bbfb21745f9babcd4eb1d/vgg_generated_80.i > 7cd47228edec52b6d82f46511af325c5-vgg_generated_80.i

新建文件,把以上代码复制到空文件下,保存,文件格式为sh,如download.sh,之后执行./download.sh即可下载到当前文件夹

2.3 cv2.cpp 文件报错
1
2
/home/pi/ros_catkin_ws/src/opencv3/modules/python/src2/cv2.cpp:885:34: error: invalid conversion from ‘const char*’ to ‘char*’ [-fpermissive]
     char* str = PyString_AsString(obj);

解决办法

打开cv2.cpp文件,在出错的地方修改以下代码

1
2
3
char* str = PyString_AsString(obj);
改为
char* str = const_cast<char *>(PyString_AsString(obj));

3.编译报错(qt_gui_cpp)

1
2
3
4
5
6
Traceback (most recent call last):
  File "/opt/ros/kinetic/share/python_qt_binding/cmake/sip_configure.py", line 85, in <module>
    sip_dir, sip_flags = get_sip_dir_flags(config)
  File "/opt/ros/kinetic/share/python_qt_binding/cmake/sip_configure.py", line 65, in get_sip_dir_flags
    raise FileNotFoundError('The sip directory for PyQt5 could not be located. Please ensure' +
NameError: global name 'FileNotFoundError' is not defined

解决办法

1
sudo apt-get install pyqt5-dev

4.编译报错(tf2)

1
2
/home/pi/ros_catkin_ws/src/geometry2/tf2/src/buffer_core.cpp:126:34: error: ‘logWarn’ was not declared in this scope
     logWarn("%s",ss.str().c_str());

logWarnlogError等未定义

解决办法

编辑/usr/include/console_bridge/console.h文件,添加以下内容

1
2
3
4
#define logWarn CONSOLE_BRIDGE_logWarn
#define logError CONSOLE_BRIDGE_logError
#define logDebug CONSOLE_BRIDGE_logDebug
#define logInform CONSOLE_BRIDGE_logInform

5.编译报错(rviz)

1
2
3
4
5
6
7
8
9
10
11
12
13
-- Checking for modules 'OGRE;OGRE-Overlay'
--   No package 'OGRE' found
--   No package 'OGRE-Overlay' found
-- Checking for module 'OGRE'
--   No package 'OGRE' found
CMake Error at /usr/share/cmake-3.13/Modules/FindPkgConfig.cmake:452 (message):
  A required package was not found
Call Stack (most recent call first):
  /usr/share/cmake-3.13/Modules/FindPkgConfig.cmake:622 (_pkg_check_modules_internal)
  CMakeLists.txt:53 (pkg_check_modules)


-- Configuring incomplete, errors occurred!

这种情况是缺少OGRE,直接去官方下载、安装OGRE源码

解决办法

ogre(github),选择1.8.0版本下载(其他版本可能会编译失败),下载完ogre源码后,解压到文件夹,如ogre,安装编译ogre源码所需依赖

1
sudo apt install build-essential automake libtool libfreetype6-dev libfreeimage-dev libzzip-dev libxrandr-dev libxaw7-dev freeglut3-dev libgl1-mesa-dev libglu1-mesa-dev libpoco-dev libtbb-dev doxygen libcppunit-dev

接下来编译ogre源码

1
2
3
4
5
cd ogre
mkdir build && cd build
cmake ..
make -j4
sudo make install

运行报错处理

RVIZ启动报错

1
error while loading shared libraries: libXXX.so.X: cannot open shared object file: No such file

解决办法

1
sudo ldconfig

参考链接

http://wiki.ros.org/kinetic/Installation/Source
http://wiki.ros.org/ROSberryPi/Installing%20ROS%20Kinetic%20on%20the%20Raspberry%20Pi
https://blog.csdn.net/weixin_44152895/article/details/102882502
https://blog.csdn.net/l1216766050/article/details/79774219
https://blog.csdn.net/hejinwei_1987/article/details/7685522
https://eleccelerator.com/wiki/index.php?title=Raspbian_Buster_ROS_RealSense#Problem:_logWarn_or_logError_not_declared_in_scope
https://blog.csdn.net/qq_33662995/article/details/98658661
https://blog.csdn.net/yjk13703623757/article/details/53217377

附件

百度网盘 提取码:b6a3
包含树莓派系统opencv源码ogre1.8.1源码boost_*.i等文件