当前位置: 首页 > 工具软件 > scr2txt > 使用案例 >

基于Ubuntu22.04在ROS2 Humble中编译turtlebot3遇到的坑

姚海
2023-12-01

1. 首先通过一下步骤下载turtlebot3的源码

mkdir -p ~/tb3_ws/src
$ cd ~/tb3_ws
#humble版本
$wget https://raw.githubusercontent.com/ROBOTIS-GIT/turtlebot3/humble-devel/turtlebot3.repos

如果下载失败,可直接编辑该文件(~/tb3_ws/turtlebot3.repos)为如下内容:

repositories:
  turtlebot3/turtlebot3:
    type: git
    url: https://github.com/ROBOTIS-GIT/turtlebot3.git
    version: ros2-devel
  turtlebot3/turtlebot3_msgs:
    type: git
    url: https://github.com/ROBOTIS-GIT/turtlebot3_msgs.git
    version: ros2-devel
  turtlebot3/turtlebot3_simulations:
    type: git
    url: https://github.com/ROBOTIS-GIT/turtlebot3_simulations.git
    version: ros2-devel
  utils/DynamixelSDK:
    type: git
    url: https://github.com/ROBOTIS-GIT/DynamixelSDK.git
    version: ros2-devel
  utils/hls_lfcd_lds_driver:
    type: git
    url: https://github.com/ROBOTIS-GIT/hls_lfcd_lds_driver.git
    version: ros2-devel
  utils/ld08_driver:
    type: git
    url: https://github.com/ROBOTIS-GIT/ld08_driver.git
    version: ros2-devel
$ vcs import src < turtlebot3.repos

注意:如果下载失败,通常是由于github.com的ip地址变化造成的,可以通过修改/etc/hosts来指定正确的ip地址。

2. 如果一切正常,然后开始编译
$ colcon build --symlink-install
现在开始排雷如下:

=>雷1:编译项目ld08_driver时,出现‘auto’ type specifier without trailing return type错误

--- stderr: ld08_driver

/opt/ros/humble/include/rosidl_runtime_cpp/rosidl_runtime_cpp/bounded_vector.hpp:477:3: error: ‘emplace_back’ function uses ‘auto’ type specifier without trailing return type
  477 |   auto

原因: ros2的代码使用了C++14特性,而编译选项却使用C++11

修改: 将编译选项修改为C++14就可以了

file: /home/frank/tb3_ws/src/utils/ld08_driver/CMakeLists.txt

SET(CMAKE_CXX_FLAGS "-std=c++11 ${CMAKE_CXX_FLAGS}")

==>

SET(CMAKE_CXX_FLAGS "-std=c++14 ${CMAKE_CXX_FLAGS}")

注意:在该文件中确保如下设置

if(NOT CMAKE_CXX_STANDARD)
  set(CMAKE_CXX_STANDARD 14)
endif()

在编译,该问题得到解决!

新的问题来了

雷2:编译项目ld08_driver时,出现error: ‘variant’ in namespace ‘std’ does not name a template type错误

--- stderr: ld08_driver

error: ‘variant’ in namespace ‘std’ does not name a template type  786 |   using CallbackInfoVariant = std::variant<

note: ‘std::variant’ is only available from C++17 onwards

原因: 仍然是C++特性和编译选项不兼容造成的,C++文件使用了C++17特性

根据错误提示,“note: ‘std::variant’ is only available from C++17 onwards”才想到方法2。
修改:

1. CMAKE_CXX_STANDARD改为17

if(NOT CMAKE_CXX_STANDARD)
  set(CMAKE_CXX_STANDARD 14)
endif()

==>

if(NOT CMAKE_CXX_STANDARD)
  set(CMAKE_CXX_STANDARD 17)
endif()

2.同时CMAKE_CXX_FLAGS也改为17

SET(CMAKE_CXX_FLAGS "-std=c++14 ${CMAKE_CXX_FLAGS}")

==>

SET(CMAKE_CXX_FLAGS "-std=c++17 ${CMAKE_CXX_FLAGS}")

再编译,该问题得到很好的解决!!

Cheer!!!

 类似资料: