Cartographer(一)ubuntu系统Cartographer_ros配置与运行

0.参考资料与前言:

github仓库地址:

https://github.com/cartographer-project/cartographer_ros/tree/masterhttps://github.com/cartographer-project/cartographer_ros/tree/master

Catorgrapher_ros官方文档:

https://google-cartographer-ros.readthedocs.io/en/latest/compilation.htmlhttps://google-cartographer-ros.readthedocs.io/en/latest/compilation.html        硬件设备为ubuntu18与ros melodic,因为近几天移植到ubuntu16的工控机上,所以理论上也对ubuntu16有参考意义

一、编译与安装

(1)安装编译工具

        kinetic与melodic相同:

sudo apt-get update
sudo apt-get install -y python-wstool python-rosdep ninja-build stow

        ros-noetic命令有不同 :

sudo apt-get update
sudo apt-get install -y python3-wstool python3-rosdep ninja-build stow

Cartographer(一)ubuntu系统Cartographer_ros配置与运行_第1张图片

(注:上图中google源没有成功更新可以不用管,不到万不得已不要将此源删除)

Cartographer(一)ubuntu系统Cartographer_ros配置与运行_第2张图片 (2)配置工作空间

        我的工作空间取名为cartographer_ws,可以取名为其他

mkdir cartographer_ws
cd cartographer_ws
wstool init src
wstool merge -t src https://raw.githubusercontent.com/cartographer-project/cartographer_ros/master/cartographer_ros.rosinstall
wstool update -t src

##备注:这里使用了科学上网,不使用的话可以参考:
https://blog.csdn.net/moshuilangting/article/details/107638034

Cartographer(一)ubuntu系统Cartographer_ros配置与运行_第3张图片Cartographer(一)ubuntu系统Cartographer_ros配置与运行_第4张图片 (3)安装 cartographer_ros依赖

        参考Cartographer_ros官方文档,执行以下步骤:

sudo rosdep init
#####上面这句如果安装过ros会报错,但不影响
rosdep update
rosdep install --from-paths src --ignore-src --rosdistro=${ROS_DISTRO} -y

(4)安装protobuf

        在ubuntu18和ubuntu20中,好像时ros自带的有protobuf,可以使用下面的命令进行验证:

protoc --version

        ubuntu16.04不自带protobuf,需要额外安装,安装步骤如下:

cd cartographer_ws
./src/cartographer/scripts/install_proto3.sh

(5)安装abseil-cpp

        ubuntu16、18、20都需要安装abseil-cpp:

cd cartographer_ws
./src/cartographer/scripts/install_abseil.sh

        在官方文档中,说可能需要卸载ROS正在使用的abseil-cpp,命令如下,但我没有卸载,没有影响,说明及命令如下:

###Due to conflicting versions you might need to uninstall the ROS abseil-cpp using
sudo apt-get remove ros-${ROS_DISTRO}-abseil-cpp

二、报错解决

        使用下面的命令编译:

catkin_make_isolated --install --use-ninja

(1)pcl_conversions内容问题???----此步骤可先不执行

/opt/ros/melodic/include/pcl_conversions/pcl_conversions.h: In function ‘void pcl_conversions::fromPCL(const pcl::Vertices&, pcl_msgs::Vertices&)’:
/opt/ros/melodic/include/pcl_conversions/pcl_conversions.h:356:30: error: no match for ‘operator=’ (operand types are ‘pcl_msgs::Vertices_ >::_vertices_type {aka std::vector}’ and ‘const Indices {aka const std::vector}’)
     vert.vertices = pcl_vert.vertices;
                              ^~~~~~~~
In file included from /usr/include/c++/7/vector:69:0,
                 from /home/elfoot/unmanned_system_2021/catographer_ws2/install_isolated/include/cartographer/io/image.h:21,
                 from /home/elfoot/unmanned_system_2021/catographer_ws2/install_isolated/include/cartographer/io/submap_painter.h:22,
                 from /home/elfoot/unmanned_system_2021/catographer_ws2/src/cartographer_ros/cartographer_ros/cartographer_ros/msg_conversion.h:21,
                 from /home/elfoot/unmanned_system_2021/catographer_ws2/src/cartographer_ros/cartographer_ros/cartographer_ros/msg_conversion.cc:17:
/usr/include/c++/7/bits/vector.tcc:179:5: note: candidate: std::vector<_Tp, _Alloc>& std::vector<_Tp, _Alloc>::operator=(const std::vector<_Tp, _Alloc>&) [with _Tp = unsigned int; _Alloc = std::allocator]
     vector<_Tp, _Alloc>::
     ^~~~~~~~~~~~~~~~~~~
######省略
/usr/include/c++/7/bits/stl_vector.h:1229:7: note:   no known conversion for argument 1 from ‘pcl_msgs::Vertices_ >::_vertices_type {aka std::vector}’ to ‘std::vector&’
[32/43] Building CXX object CMakeFiles/cartographer_ros.dir/cartographer_ros/node.cc.o
ninja: build stopped: subcommand failed.
<== Failed to process package 'cartographer_ros': 
  Command '['/home/elfoot/unmanned_system_2021/catographer_ws2/install_isolated/env.sh', 'ninja', '-j20', '-l20']' returned non-zero exit status 1

Reproduce this error by running:
==> cd /home/elfoot/unmanned_system_2021/catographer_ws2/build_isolated/cartographer_ros && /home/elfoot/unmanned_system_2021/catographer_ws2/install_isolated/env.sh ninja -j20 -l20

Command failed, exiting.

         编译时第一个报错如上,好像是pcl_conversions的问题;参考博客:https://blog.csdn.net/weixin_46181372/article/details/111130390https://blog.csdn.net/weixin_46181372/article/details/111130390

        对/opt/ros/melodic/include/pcl_msgs/Vertices.h进行sudo权限修改,因为Vertices.h文件中本来就是uint32_t,而上述博客要改为uint32_t;于是抱着试一试的态度,将uint32_t改为int32_t

   //typedef std::vector::other >  _vertices_type;
  //_vertices_type vertices;
   typedef std::vector::other >  _vertices_type;
  _vertices_type vertices;

        删除编译得到的build_isolated、devel_isolated、install_isolated文件,重新运行编译,编译通过:

catkin_make_isolated --install --use-ninja

(2)运行demo报错

        下载demo包,运行

wget -P ~/Downloads https://storage.googleapis.com/cartographer-public-data/bags/backpack_2d/cartographer_paper_deutsches_museum.bag
source install_isolated setup.bash
roslaunch cartographer_ros demo_backpack_2d.launch bag_filename:=${HOME}/Downloads/cartographer_paper_deutsches_museum.bag

        roslaunch后报错如下:

/home/elfoot/unmanned_system_2021/catographer_ws/install_isolated/lib/cartographer_ros/cartographer_node: error while loading shared libraries: libpcl_common.so.1.11: cannot open shared object file: No such file or directory
process[cartographer_occupancy_grid_node-4]: started with pid [31543]
/home/elfoot/unmanned_system_2021/catographer_ws/install_isolated/lib/cartographer_ros/cartographer_occupancy_grid_node: error while loading shared libraries: libpcl_common.so.1.11: cannot open shared object file: No such file or directory
process[rviz-5]: started with pid [31549]
[cartographer_node-3] process has died [pid 31542, exit code 127, cmd /home/elfoot/unmanned_system_2021/catographer_ws/install_isolated/lib/cartographer_ros/cartographer_node -configuration_directory /home/elfoot/unmanned_system_2021/catographer_ws/install_isolated/share/cartographer_ros/configuration_files -configuration_basename backpack_2d.lua echoes:=horizontal_laser_2d __name:=cartographer_node __log:=/home/elfoot/.ros/log/b3644844-6a44-11ec-bb48-08beac26819a/cartographer_node-3.log].
log file: /home/elfoot/.ros/log/b3644844-6a44-11ec-bb48-08beac26819a/cartographer_node-3*.log
[cartographer_occupancy_grid_node-4] process has died [pid 31543, exit code 127, cmd /home/elfoot/unmanned_system_2021/catographer_ws/install_isolated/lib/cartographer_ros/cartographer_occupancy_grid_node -resolution 0.05 __name:=cartographer_occupancy_grid_node __log:=/home/elfoot/.ros/log/b3644844-6a44-11ec-bb48-08beac26819a/cartographer_occupancy_grid_node-4.log].
log file: /home/elfoot/.ros/log/b3644844-6a44-11ec-bb48-08beac26819a/cartographer_occupancy_grid_node-4*.log
process[playbag-6]: started with pid [31551]
[ERROR] [1640960384.918870492]: PluginlibFactory: The plugin for class 'Submaps' failed to load.  Error: Failed to load library /home/elfoot/unmanned_system_2021/catographer_ws/install_isolated/lib//libcartographer_rviz.so. Make sure that you are calling the PLUGINLIB_EXPORT_CLASS macro in the library code, and that names are consistent between this macro and your XML. Error string: Could not load library (Poco exception = libpcl_common.so.1.11: 无法打开共享对象文件: 没有那个文件或目录)

        我giao,cartographer_ros这个包生成的程序居然找的pcl为pcl-1.11,并且没有找到libpcl_common.so.1.11;我吐了,怎么能找到pcl-1.11........

        后来发现ros-melodic自带pcl-1.11,于是在cartographer_ros的CMakeLists.txt文件中进行修改,修改如下:

gedit xxx/catographer_ws/src/cartographer_ros/cartographer_ros/CMakeLists.txt

        添加,具体位置如下图:

set(PCL_DIR "/usr/share/pcl-1.8")

Cartographer(一)ubuntu系统Cartographer_ros配置与运行_第5张图片

        (3)最终编译

        接着(2), 删除第二次编译得到的build_isolated、devel_isolated、install_isolated文件,重新运行编译:

catkin_make_isolated --install --use-ninja

        会发现出现与(1)中相似的错误:

Cartographer(一)ubuntu系统Cartographer_ros配置与运行_第6张图片

        最后挣扎以下,把 Vertices.h文件改回来

   typedef std::vector::other >  _vertices_type;
  _vertices_type vertices;
   //typedef std::vector::other >  _vertices_type;
  //_vertices_type vertices;

         继续重新编译,这次编译可以成功运行

Cartographer(一)ubuntu系统Cartographer_ros配置与运行_第7张图片

三、成功运行

(1)2D

source install_isolated/setup.bash
roslaunch cartographer_ros demo_backpack_2d.launch bag_filename:=${HOME}/Downloads/cartographer_paper_deutsches_museum.bag
#####bag包为2D的,前面二(2)已经下载了
#####更多到官方文档:https://google-cartographer-ros.readthedocs.io/en/latest/demos.html

Cartographer(一)ubuntu系统Cartographer_ros配置与运行_第8张图片

Cartographer(一)ubuntu系统Cartographer_ros配置与运行_第9张图片

 Cartographer(一)ubuntu系统Cartographer_ros配置与运行_第10张图片

Cartographer(一)ubuntu系统Cartographer_ros配置与运行_第11张图片

Cartographer(一)ubuntu系统Cartographer_ros配置与运行_第12张图片

 

 

 

 

 (2)3D包

wget -P ~/Downloads https://storage.googleapis.com/cartographer-public-data/bags/backpack_3d/with_intensities/b3-2016-04-05-14-14-00.bag
roslaunch cartographer_ros demo_backpack_3d.launch bag_filename:=${HOME}/Downloads/b3-2016-04-05-14-14-00.bag
#####此为3D的包

 四、致谢

        实验室张同学(男)

        在宿舍等我的马同学、巴同学、林同学,希望没把我门外 

@meng 

你可能感兴趣的:(无人驾驶车辆学习,自动驾驶,人工智能,机器学习)