当前位置:   article > 正文

Turtlebot3+Cartographer配置运行_galactic turtlebot3 cartographer

galactic turtlebot3 cartographer
一、安装Cartographer
  1. 首先安装ubuntu对应的ROS内核版本(如:Noetic、Melodic、Lunar等版本,注意:要和ubuntu的版本对应)。

ros对应不同的ubuntu版本有不同的版本名字:

ubuntu16.04对应ros-kinetic;

ubuntu18.04对应ros-melodic;

ubuntu20.04对应ros-noetic。

如在Ubuntu20.04上,要安装ros应该用:

sudo apt-get install ros-noetic-desktop-full

参考:https://blog.csdn.net/qaqlalala/article/details/127818168

  1. 再安装cartographer_ros

参考:

(1)官网:https://google-cartographer-ros.readthedocs.io/en/latest/compilation.html#building-installation

(2)保姆级别的安装:https://blog.csdn.net/m0_45805756/article/details/126309855

(3)常见的update错误解决方法:https://blog.csdn.net/Kenny_GuanHua/article/details/116845781

注意:我的cartographer_ros安装目录是google_ws

二、安装Turtlebot3
  1. 安装Turtlebot3

将Turtlebot3安装在cartographer_ros安装目录中,这是因为方便环境变量设置,否则,可能找不到cartographer算法模块。

turtlebot3_simulations:包含了更丰富的仿真文件(如一些rviz和gazebo的launch文件)

turtlebot3:功能包中继承了了TurtleBot3的机器人文件、SLAM和导航功能包、遥控功能包和bringup功能包等

turtlebot3包下载地址:https://github.com/ROBOTIS-GIT/turtlebot3

turtlebot3_simulations包下载地址:https://github.com/ROBOTIS-GIT/turtlebot3_simulations

turtlebot3 wiki简介:http://wiki.ros.org/turtlebot3

主要是两种型号:Burger 和 Waffle Pi:

参数如下:

  1. cd ~/google_ws/src
  2. git clone https://github.com/ROBOTIS-GIT/turtlebot3.git
  3. git clone https://github.com/ROBOTIS-GIT/turtlebot3_simulations.git
  4. cd ..
  5. rosdep install --from-paths src --ignore-src --rosdistro=${ROS_DISTRO} -y
  6. catkin_make_isolated
  1. 启动Turtlebot3仿真环境

首先启动一个Terminal窗口

(1)设置环境变量:source ~/google_ws/devel_isolated/setup.bash

(2)设置默认的 TURTLEBOT3_MODEL。turtlebot3有三个版本,burger、waffle和waffle_pi,其中waffle_pi版本中配备的传感器最全面。

(3)运行。turtlebot3_gazebo是turtlebot3的包名,turtlebot3_stage_4.launch是要运行的文件名称。

这一步的作用是先创建好一个需要仿真的模拟环境。

  1. source ~/google_ws/devel_isolated/setup.bash
  2. export TURTLEBOT3_MODEL=burger
  3. roslaunch turtlebot3_gazebo turtlebot3_stage_4.launch
  1. 开始建图

再新建一个Terminal窗口,运行:

  1. source ~/google_ws/devel_isolated/setup.bash
  2. export TURTLEBOT3_MODEL=burger
  3. roslaunch turtlebot3_slam turtlebot3_slam.launch slam_methods:=cartographer configuration_basename:=turtlebot3_lds_2d_gazebo.lua

这一步的功能是调用相应的建图算法对上一步的环境进行建图。(slam_methods:=cartographer指定SLAM建图算法是cartographer)

每一个terminal都要运行:source ~/google_ws/devel_isolated/setup.bash和export TURTLEBOT3_MODEL=burger,设置环境变量。

  1. source ~/google_ws/devel_isolated/setup.bash
  2. export TURTLEBOT3_MODEL=burger

turtlebot3_slam是turtlebot3的包名;slam_methods:=cartographer是设置slam的算法(支持gmapping, cartographer, hector, karto, frontier_exploration这几个slam算法);configuration_basename:=turtlebot3_lds_2d_gazebo.lua可以自行设置lua配置文件。

这一步中会自动调用rviz,对建图过程进行可视化。

  1. 手动控制建图

再新建一个Terminal窗口,运行如下命令打开键盘控制界面,可以通过键盘控制机器人进行移动,从而完成建图。

  1. source ~/google_ws/devel_isolated/setup.bash
  2. export TURTLEBOT3_MODEL=burger
  3. roslaunch turtlebot3_teleop turtlebot3_teleop_key.launch

通过键盘进行控制小车的运行。

w和x:线速度;

a和d:角速度;

s:停止

三、分析

(1)首先看看roslaunch命令行:

roslaunch turtlebot3_gazebo turtlebot3_stage_4.launch

这句话是说:调用turtlebot3_gazebo功能包中的turtlebot3_stage_4.launch文件来启动仿真环境。

我们来看看配置文件turtlebot3_stage_4.launch:

目录:google_ws/src/turtlebot3_simulations/turtlebot3_gazebo/launch/turtlebot3_stage_4.launch

  1. <launch>
  2. <arg name="model" default="$(env TURTLEBOT3_MODEL)" doc="model type [burger, waffle, waffle_pi]"/>
  3. <arg name="x_pos" default="-0.7"/>
  4. <arg name="y_pos" default="0.0"/>
  5. <arg name="z_pos" default="0.0"/>
  6. <!--首先启动一个empty_world.launch(空的world),这个world的参数有:world_name、pauseduse_sim_time等-->
  7. <include file="$(find gazebo_ros)/launch/empty_world.launch">
  8. <arg name="world_name" value="$(find turtlebot3_gazebo)/worlds/turtlebot3_stage_4.world"/>
  9. <arg name="paused" value="false"/>
  10. <arg name="use_sim_time" value="true"/>
  11. <arg name="gui" value="true"/>
  12. <arg name="headless" value="false"/>
  13. <arg name="debug" value="false"/>
  14. </include>
  15. <param name="robot_description" command="$(find xacro)/xacro --inorder $(find turtlebot3_description)/urdf/turtlebot3_$(arg model).urdf.xacro" />
  16.  
  17. <!--最后启动一个节点spawn_urdf,属于gazebo_ros包,类型是spawn_model,传入上述的arg参数-->
  18. <node name="spawn_urdf" pkg="gazebo_ros" type="spawn_model" args="-urdf -model turtlebot3_burger -x $(arg x_pos) -y $(arg y_pos) -z $(arg z_pos) -param robot_description" />
  19. </launch>

(2)再来看看命令:

source ~/google_ws/devel_isolated/setup.bash

export TURTLEBOT3_MODEL=burger

roslaunch turtlebot3_slam turtlebot3_slam.launch slam_methods:=cartographer configuration_basename:=turtlebot3_lds_2d_gazebo.lua

这个命令是:调用turtlebot3_slam功能包中的turtlebot3_slam.launch文件启动建图功能,参数是:slam_methods和configuration_basename。

a.首先我们来看看配置文件turtlebot3_lds_2d_gazebo.lua。

目录:google_ws/src/turtlebot3/turtlebot3_slam/config/turtlebot3_lds_2d_gazebo.lua

  1. #turtlebot3_lds_2d_gazebo.lua
  2. -- Copyright 2016 The Cartographer Authors
  3. --
  4. -- Licensed under the Apache License, Version 2.0 (the "License");
  5. -- you may not use this file except in compliance with the License.
  6. -- You may obtain a copy of the License at
  7. --
  8. -- http://www.apache.org/licenses/LICENSE-2.0
  9. --
  10. -- Unless required by applicable law or agreed to in writing, software
  11. -- distributed under the License is distributed on an "AS IS" BASIS,
  12. -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. -- See the License for the specific language governing permissions and
  14. -- limitations under the License.
  15. include "map_builder.lua"
  16. include "trajectory_builder.lua"
  17. options = {
  18. map_builder = MAP_BUILDER,
  19. trajectory_builder = TRAJECTORY_BUILDER,
  20. map_frame = "map", --地图坐标系的名字
  21. tracking_frame = "base_footprint", -- imu_link, If you are using gazebo, use 'base_footprint' (libgazebo_ros_imu's bug)
  22. published_frame = "odom", -- 设置为tf树最顶端的坐标系名称,设置完成后cartographer会发布map->published_frame的坐标系
  23. odom_frame = "odom", -- 里程计的坐标系名字
  24. provide_odom_frame = false, -- 是否提供odom的tf, 如果为true,则tf树为map->odom->footprint,如果为false,则tf树为map->published_frame
  25. publish_frame_projected_to_2d = false, -- 是否将坐标系投影到平面上,一般为false
  26. use_odometry = true, --是否使用里程计,如果使用要求一定要有odom的tf
  27. use_nav_sat = false, --是否使用gps
  28. use_landmarks = false, --是否使用landmark
  29. num_laser_scans = 1, --是否使用单线激光数据并设置订阅topic的数量
  30. num_multi_echo_laser_scans = 0, --是否使用multi_echo_laser_scans并设置订阅topic的数量
  31. num_subdivisions_per_laser_scan = 1, --1帧数据被分成几次处理,一般为1
  32. num_point_clouds = 0, -- 是否使用16线点云数据
  33. lookup_transform_timeout_sec = 0.2,-- 查找tf时的超时时间
  34. submap_publish_period_sec = 0.3,-- 发布数据的时间间隔
  35. pose_publish_period_sec = 5e-3,
  36. trajectory_publish_period_sec = 30e-3,
  37. -- 传感器数据的采样频率
  38. rangefinder_sampling_ratio = 1., --设置为0.1则表示每10帧数据使用1帧数据
  39. odometry_sampling_ratio = 1.,
  40. fixed_frame_pose_sampling_ratio = 1.,
  41. imu_sampling_ratio = 1.,
  42. landmarks_sampling_ratio = 1.,
  43. }
  44. --修改之前5个lua文件参数可以使用这种方式
  45. MAP_BUILDER.use_trajectory_builder_2d = true -- 进行2D建图
  46. TRAJECTORY_BUILDER_2D.min_range = 0.1 --激光的最近有效距离
  47. TRAJECTORY_BUILDER_2D.max_range = 3.5 --激光最远的有效距离
  48. TRAJECTORY_BUILDER_2D.missing_data_ray_length = 3. --无效激光数据设置距离为该数值
  49. TRAJECTORY_BUILDER_2D.use_imu_data = true --是否使用imu数据
  50. TRAJECTORY_BUILDER_2D.use_online_correlative_scan_matching = true
  51. TRAJECTORY_BUILDER_2D.motion_filter.max_angle_radians = math.rad(0.1)
  52. POSE_GRAPH.constraint_builder.min_score = 0.65
  53. POSE_GRAPH.constraint_builder.global_localization_min_score = 0.7
  54. return options

b.我们再来看看启动文件

目录:google_ws/src/turtlebot3/turtlebot3_slam/launch/turtlebot3_slam.launch

  1. <!-- turtlebot3_slam.launch -->
  2. <launch>
  3. <!-- Arguments -->
  4. <!-- 自己可以设置模型的名称,如:burger, waffle, waffle_pi,一般通过export TURTLEBOT3_MODEL=burger来设置 -->
  5. <arg name="model" default="$(env TURTLEBOT3_MODEL)" doc="model type [burger, waffle, waffle_pi]"/>
  6. <!-- 自己可以设置slam算法 -->
  7. <arg name="slam_methods" default="gmapping" doc="slam type [gmapping, cartographer, hector, karto, frontier_exploration]"/>
  8. <!-- 配置文件的路径,默认是turtlebot3_lds_2d.lua,但是该参数在命令行中被指定为:turtlebot3_lds_2d_gazebo.lua -->
  9. <arg name="configuration_basename" default="turtlebot3_lds_2d.lua"/>
  10. <!-- true:表示默认启动rviz -->
  11. <arg name="open_rviz" default="true"/>
  12. <!-- TurtleBot3 -->
  13. <!-- 启动TurtleBot3包中robot的外形配置文件 -->
  14. <include file="$(find turtlebot3_bringup)/launch/turtlebot3_remote.launch">
  15. <arg name="model" value="$(arg model)" />
  16. </include>
  17. <!-- SLAM: Gmapping, Cartographer, Hector, Karto, Frontier_exploration, RTAB-Map -->
  18. <!-- 启动TurtleBot3的算法配置文件 -->
  19. <include file="$(find turtlebot3_slam)/launch/turtlebot3_$(arg slam_methods).launch">
  20. <arg name="model" value="$(arg model)"/>
  21. <arg name="configuration_basename" value="$(arg configuration_basename)"/>
  22. </include>
  23. <!-- rviz -->
  24. <!-- 启动vriz配置文件 -->
  25. <group if="$(arg open_rviz)">
  26. <node pkg="rviz" type="rviz" name="rviz" required="true"
  27. args="-d $(find turtlebot3_slam)/rviz/turtlebot3_$(arg slam_methods).rviz"/>
  28. </group>
  29. </launch>

c.我们看看TurtleBot3包中robot的外形配置文件turtlebot3_remote.launch

google_ws/src/turtlebot3/turtlebot3_slam/turtlebot3_bringup/launch/turtlebot3_remote.launch

  1. <launch>
  2. <arg name="model" default="$(env TURTLEBOT3_MODEL)" doc="model type [burger, waffle, waffle_pi]"/>
  3. <!-- 多机协同,默认为空 -->
  4. <arg name="multi_robot_name" default=""/>
  5. <!-- 使用include函数将description.launch.xml文件包含进来 -->
  6. <include file="$(find turtlebot3_bringup)/launch/includes/description.launch.xml">
  7. <arg name="model" value="$(arg model)" />
  8. </include>
  9. <node pkg="robot_state_publisher" type="robot_state_publisher" name="robot_state_publisher">
  10. <param name="publish_frequency" type="double" value="50.0" />
  11. <param name="tf_prefix" value="$(arg multi_robot_name)"/>
  12. </node>
  13. </launch>

d.我们看看description.launch.xml文件

目录:google_ws/src/turtlebot3/turtlebot3_slam/turtlebot3_bringup/launch/includes/description.launch.xml

  1. <launch>
  2. <arg name="model"/>
  3. <!--使用xacro类型的文件来描述robot的外形,并用xacro命令进行解析,最后形成urdf类型文件,方便gazebo识别-->
  4. <!--urdf描述语言不能进行逻辑判断等高级操作,而xacro类型文件支持高级语法,如变量定义、逻辑判断-->
  5. <arg name="urdf_file" default="$(find xacro)/xacro --inorder '$(find turtlebot3_description)/urdf/turtlebot3_$(arg model).urdf.xacro'" />
  6. <param name="robot_description" command="$(arg urdf_file)" />
  7. </launch>

f.最后我们看看我们看看turtlebot3_$(arg model).urdf.xacro文件,由于model我们通过export TURTLEBOT3_MODEL=burger命令设置为burger,所以,该文件是:turtlebot3_burger.urdf.xacro

目录:google_ws/src/turtlebot3/turtlebot3_description/urdf/turtlebot3_burger.urdf.xacro

注意base_link和base_footprint的区别:

base_link是固定在机器人本体上的坐标系,通常选择机器人腰部。

base_footprint表示机器人base_link原点在地面上的投影,区别base_link之处是其“z”坐标不同。

一般为了模型不陷入地面,base_footprint的“z”坐标比base_link高。

  1. <?xml version="1.0" ?>
  2. <robot name="turtlebot3_burger" xmlns:xacro="http://ros.org/wiki/xacro">
  3. <xacro:include filename="$(find turtlebot3_description)/urdf/common_properties.xacro"/>
  4. <xacro:include filename="$(find turtlebot3_description)/urdf/turtlebot3_burger.gazebo.xacro"/>
  5. <link name="base_footprint"/>
  6. <!--设置joint(关节名为base_joint),将base_link连接到base_footprint上面-->
  7. <joint name="base_joint" type="fixed">
  8. <parent link="base_footprint"/>
  9. <child link="base_link"/>
  10. <!--相对于base_footprint坐标系,base_link在base_footprint上方0.01米处,没有旋转-->
  11. <origin xyz="0.0 0.0 0.010" rpy="0 0 0"/>
  12. </joint>
  13. <link name="base_link">
  14. <visual>
  15. <origin xyz="-0.032 0 0.0" rpy="0 0 0"/>
  16. <geometry>
  17. <mesh filename="package://turtlebot3_description/meshes/bases/burger_base.stl" scale="0.001 0.001 0.001"/>
  18. </geometry>
  19. <material name="light_black"/>
  20. </visual>
  21. <collision>
  22. <origin xyz="-0.032 0 0.070" rpy="0 0 0"/>
  23. <geometry>
  24. <box size="0.140 0.140 0.143"/>
  25. </geometry>
  26. </collision>
  27. <inertial>
  28. <origin xyz="0 0 0" rpy="0 0 0"/>
  29. <mass value="8.2573504e-01"/>
  30. <inertia ixx="2.2124416e-03" ixy="-1.2294101e-05" ixz="3.4938785e-05"
  31. iyy="2.1193702e-03" iyz="-5.0120904e-06"
  32. izz="2.0064271e-03" />
  33. </inertial>
  34. </link>
  35. <joint name="wheel_left_joint" type="continuous">
  36. <parent link="base_link"/>
  37. <child link="wheel_left_link"/>
  38. <origin xyz="0.0 0.08 0.023" rpy="-1.57 0 0"/>
  39. <axis xyz="0 0 1"/>
  40. </joint>
  41. <link name="wheel_left_link">
  42. <visual>
  43. <origin xyz="0 0 0" rpy="1.57 0 0"/>
  44. <geometry>
  45. <mesh filename="package://turtlebot3_description/meshes/wheels/left_tire.stl" scale="0.001 0.001 0.001"/>
  46. </geometry>
  47. <material name="dark"/>
  48. </visual>
  49. <collision>
  50. <origin xyz="0 0 0" rpy="0 0 0"/>
  51. <geometry>
  52. <cylinder length="0.018" radius="0.033"/>
  53. </geometry>
  54. </collision>
  55. <inertial>
  56. <origin xyz="0 0 0" />
  57. <mass value="2.8498940e-02" />
  58. <inertia ixx="1.1175580e-05" ixy="-4.2369783e-11" ixz="-5.9381719e-09"
  59. iyy="1.1192413e-05" iyz="-1.4400107e-11"
  60. izz="2.0712558e-05" />
  61. </inertial>
  62. </link>
  63. <joint name="wheel_right_joint" type="continuous">
  64. <parent link="base_link"/>
  65. <child link="wheel_right_link"/>
  66. <origin xyz="0.0 -0.080 0.023" rpy="-1.57 0 0"/>
  67. <axis xyz="0 0 1"/>
  68. </joint>
  69. <link name="wheel_right_link">
  70. <visual>
  71. <origin xyz="0 0 0" rpy="1.57 0 0"/>
  72. <geometry>
  73. <mesh filename="package://turtlebot3_description/meshes/wheels/right_tire.stl" scale="0.001 0.001 0.001"/>
  74. </geometry>
  75. <material name="dark"/>
  76. </visual>
  77. <collision>
  78. <origin xyz="0 0 0" rpy="0 0 0"/>
  79. <geometry>
  80. <cylinder length="0.018" radius="0.033"/>
  81. </geometry>
  82. </collision>
  83. <inertial>
  84. <origin xyz="0 0 0" />
  85. <mass value="2.8498940e-02" />
  86. <inertia ixx="1.1175580e-05" ixy="-4.2369783e-11" ixz="-5.9381719e-09"
  87. iyy="1.1192413e-05" iyz="-1.4400107e-11"
  88. izz="2.0712558e-05" />
  89. </inertial>
  90. </link>
  91. <joint name="caster_back_joint" type="fixed">
  92. <parent link="base_link"/>
  93. <child link="caster_back_link"/>
  94. <origin xyz="-0.081 0 -0.004" rpy="-1.57 0 0"/>
  95. </joint>
  96. <link name="caster_back_link">
  97. <collision>
  98. <origin xyz="0 0.001 0" rpy="0 0 0"/>
  99. <geometry>
  100. <box size="0.030 0.009 0.020"/>
  101. </geometry>
  102. </collision>
  103. <inertial>
  104. <origin xyz="0 0 0" />
  105. <mass value="0.005" />
  106. <inertia ixx="0.001" ixy="0.0" ixz="0.0"
  107. iyy="0.001" iyz="0.0"
  108. izz="0.001" />
  109. </inertial>
  110. </link>
  111. <joint name="imu_joint" type="fixed">
  112. <parent link="base_link"/>
  113. <child link="imu_link"/>
  114. <origin xyz="-0.032 0 0.068" rpy="0 0 0"/>
  115. </joint>
  116. <link name="imu_link"/>
  117. <joint name="scan_joint" type="fixed">
  118. <parent link="base_link"/>
  119. <child link="base_scan"/>
  120. <origin xyz="-0.032 0 0.172" rpy="0 0 0"/>
  121. </joint>
  122. <!--Laser link的配置-->
  123. <link name="base_scan">
  124. <visual>
  125. <origin xyz="0 0 0.0" rpy="0 0 0"/>
  126. <geometry>
  127. <mesh filename="package://turtlebot3_description/meshes/sensors/lds.stl" scale="0.001 0.001 0.001"/>
  128. </geometry>
  129. <material name="dark"/>
  130. </visual>
  131. <collision>
  132. <origin xyz="0.015 0 -0.0065" rpy="0 0 0"/>
  133. <geometry>
  134. <cylinder length="0.0315" radius="0.055"/>
  135. </geometry>
  136. </collision>
  137. <inertial>
  138. <mass value="0.114" />
  139. <origin xyz="0 0 0" />
  140. <inertia ixx="0.001" ixy="0.0" ixz="0.0"
  141. iyy="0.001" iyz="0.0"
  142. izz="0.001" />
  143. </inertial>
  144. </link>
  145. </robot>
参考文献

https://blog.csdn.net/m0_71775106/article/details/128303582

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

闽ICP备14008679号