当前位置:   article > 正文

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

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相同:

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

        ros-noetic命令有不同 :

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

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

 (2)配置工作空间

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

  1. mkdir cartographer_ws
  2. cd cartographer_ws
  3. wstool init src
  4. wstool merge -t src https://raw.githubusercontent.com/cartographer-project/cartographer_ros/master/cartographer_ros.rosinstall
  5. wstool update -t src
  6. ##备注:这里使用了科学上网,不使用的话可以参考:
  7. https://blog.csdn.net/moshuilangting/article/details/107638034

 (3)安装 cartographer_ros依赖

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

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

(4)安装protobuf

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

protoc --version

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

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

(5)安装abseil-cpp

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

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

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

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

二、报错解决

        使用下面的命令编译:

catkin_make_isolated --install --use-ninja

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

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

  1. //typedef std::vector<uint32_t, typename ContainerAllocator::template rebind<uint32_t>::other > _vertices_type;
  2. //_vertices_type vertices;
  3. typedef std::vector<int32_t, typename ContainerAllocator::template rebind<int32_t>::other > _vertices_type;
  4. _vertices_type vertices;

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

catkin_make_isolated --install --use-ninja

(2)运行demo报错

        下载demo包,运行

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

        roslaunch后报错如下:

  1. /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
  2. process[cartographer_occupancy_grid_node-4]: started with pid [31543]
  3. /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
  4. process[rviz-5]: started with pid [31549]
  5. [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].
  6. log file: /home/elfoot/.ros/log/b3644844-6a44-11ec-bb48-08beac26819a/cartographer_node-3*.log
  7. [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].
  8. log file: /home/elfoot/.ros/log/b3644844-6a44-11ec-bb48-08beac26819a/cartographer_occupancy_grid_node-4*.log
  9. process[playbag-6]: started with pid [31551]
  10. [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")

        (3)最终编译

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

catkin_make_isolated --install --use-ninja

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

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

  1. typedef std::vector<uint32_t, typename ContainerAllocator::template rebind<uint32_t>::other > _vertices_type;
  2. _vertices_type vertices;
  3. //typedef std::vector<int32_t, typename ContainerAllocator::template rebind<int32_t>::other > _vertices_type;
  4. //_vertices_type vertices;

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

三、成功运行

(1)2D

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

 

 

 

 

 

 (2)3D包

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

 四、致谢

        实验室张同学(男)

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

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/IT小白/article/detail/485782
推荐阅读
相关标签