文章目录
- 前言
- 1. 环境要求
- 2. 安装
- 3. 运行
- 3.1 启动仿真环境
- 3.2 建图
- 3.2.1 启动cartographer节点
- 3.2.2 移动机器人进行建图
- 3.2.3 保存地图
- 3.3 导航定位
- 3.3.1 准备文件
- 3.3.2 运行导航节点
- 3.4 节点关系图
- 参考文献
- 附录 其他几个包的简单安装说明
- 附录A 安装husky机器人环境
- A.1安装基础包
- A.2 安装cartographer支持
- A.3 运行
- 附录B. 安装GVINS
- B.1 安装
- B.2 运行
前言
本文记录在之前已经安装完毕cartographer的workspace的基础上安装turtlebot3完整开发仿真环境的过程。
1. 环境要求
已经按照https://blog.csdn.net/m0_71775106/article/details/127707299文章的说明安装完成了相应的ros环境配置和cartographer。
2. 安装
cd ~/carto_ws/src
git clone https://github.com/ROBOTIS-GIT/turtlebot3.git
git clone https://github.com/ROBOTIS-GIT/turtlebot3_simulations.git
cd ..
rosdep install --from-paths src --ignore-src --rosdistro=${ROS_DISTRO} -y
catkin_make_isolated
echo “export SVGA_VGPU10=0” >> ~/.bashrc
source ~/.bashrc
3. 运行
3.1 启动仿真环境
新建一个Terminal窗口,输入如下命令:
source ~/carto_ws/devel_isolated/setup.bash
export TURTLEBOT3_MODEL=burger
roslaunch turtlebot3_gazebo turtlebot3_state_4.launch
3.2 建图
3.2.1 启动cartographer节点
新建一个Terminal窗口,运行如下命令
source ~/carto_ws/devel_isolated/setup.bash
export TURTLEBOT3_MODEL=burger
roslaucn turtlebot3_slam turtlebot3_slam.launch slam_methods:=cartographer configuration_basename:=turtlebot3_lds_2d_gazebo.lua
在使用gazebo仿真环境的时候,算法配置文件需要使用turtlebot3_lds_2d_gazebo.lua,而非turtlebot3_lds_2d.lua文件,两者区别如下:
22c22
< tracking_frame = "imu_link", -- imu_link, If you are using gazebo, use 'base_footprint' (libgazebo_ros_imu's bug)
---
> tracking_frame = "base_footprint", -- imu_link, If you are using gazebo, use 'base_footprint' (libgazebo_ros_imu's bug)
39c39
< odometry_sampling_ratio = 0.1,
---
> odometry_sampling_ratio = 1.,
41c41
< imu_sampling_ratio = 0.1,
---
> imu_sampling_ratio = 1.,
该launch文件还会启动rviz窗口,供调试查看。
3.2.2 移动机器人进行建图
新建一个Terminal窗口,运行如下命令打开键盘控制界面,可以通过键盘控制机器人进行移动,从而完成建图。
source ~/carto_ws/devel_isolated/setup.bash
export TURTLEBOT3_MODEL=burger
roslaunch turtlebot3_teleop turtlebot3_teleop_key.launch
3.2.3 保存地图
当地图建立完整后,新建一个Terminal串口,运行如下命令,保存地图:
source ~/carto_ws/devel_isolated/setup.bash
export TURTLEBOT3_MODEL=burger
# Finish the trajectory before saving the map
rosservice call /finish_trajectory 0
# Save the pbstream to a local file
rosservice call /write_state "{filename: '/home/<username>/turtlebot3_cartographer_stage_4.pbstream', include_unfinished_submaps: true}"
# Convert the pbstream format to ros map format (pgm and yaml)
rosrun cartographer_ros cartographer_pbstream_to_ros_map -map_filestem=/home/<username>/turtlebot3_cartographer_stage_4 -pbstream_filename=/home/<username>/turtlebot3_cartographer_stage_4.pbstream -resolution=0.05
3.3 导航定位
3.3.1 准备文件
新建文件,~/carto_ws/src/turtlebot3/turtlebot3_slam/config/turtlebot3_lds_2d_gazebo_localization.lua,输入如下内容:
include "turtlebot3_lds_2d_gazebo.lua"
--TRAJECTORY_BUILDER.pure_localization = true
TRAJECTORY_BUILDER.pure_localization_trimmer = {
max_submaps_to_keep = 3,
}
POSE_GRAPH.optimize_every_n_nodes = 50
return options
新建文件,~/carto_ws/src/turtlebot3/turtlebot3_slam/launch/turtlebot3_cartographer_localization.launch,输入如下内容(将其中<username>改为实际值):
<launch>
<!-- Arguments -->
<arg name="model" default="$(env TURTLEBOT3_MODEL)" doc="model type [burger, waffle, waffle_pi]"/>
<arg name="configuration_basename" default="turtlebot3_lds_2d_gazebo_localization.lua"/>
<arg name="open_rviz" default="true"/>
<arg name="load_state_filename" default="/home/<username>/turtlebot3_cartographer_stage_4.pbstream"/>
<!-- TurtleBot3 -->
<include file="$(find turtlebot3_bringup)/launch/turtlebot3_remote.launch">
<arg name="model" value="$(arg model)" />
</include>
<!-- move_base -->
<include file="$(find turtlebot3_navigation)/launch/move_base.launch">
<arg name="model" value="$(arg model)" />
</include>
<!-- cartographer_node -->
<node pkg="cartographer_ros" type="cartographer_node" name="cartographer_node"
args="-configuration_directory $(find turtlebot3_slam)/config
-configuration_basename $(arg configuration_basename)
-load_state_filename $(arg load_state_filename)"
output="screen">
<remap from="/imu" to="/flat_imu"/>
<!--remap from="points2" to="/camera/depth/points" / -->
</node>
<!-- cartographer_occupancy_grid_node -->
<node pkg="cartographer_ros" type="cartographer_occupancy_grid_node"
name="cartographer_occupancy_grid_node"
args="-resolution 0.05" />
<!-- flat_world_imu_node -->
<node pkg="turtlebot3_slam" type="flat_world_imu_node" name="flat_world_imu_node" output="screen">
<remap from="imu_in" to="/imu" />
<remap from="imu_out" to="/flat_imu" />
</node>
<!-- rviz -->
<group if="$(arg open_rviz)">
<node pkg="rviz" type="rviz" name="rviz" required="true"
args="-d $(find turtlebot3_slam)/rviz/turtlebot3_$(arg slam_methods).rviz"/>
</group>
</launch>
3.3.2 运行导航节点
新建一个Terminal,输入如下命令:
source ~/carto_ws/devel_isolated/setup.bash
export TURTLEBOT3_MODEL=burger
roslaunch turtlebot3_slam turtlebot3_cartographer_localization.launch slam_methods:=cartographer
3.4 节点关系图
运行如下命令,可以打开节点关系图进行查看。
rqt_graph
参考文献
- 工作小笔记——基于ROS Melodic的cartographer安装, https://blog.csdn.net/m0_71775106/article/details/127707299
附录 其他几个包的简单安装说明
在目前的ros开发环境,可以轻松的安装其他算法包,这里简单列出几个。文章来源:https://uudwc.com/A/nPknb
附录A 安装husky机器人环境
A.1安装基础包
cd ~/carto_ws/src
git clone -b melodic-devel https://github.com/husky/husky.git
cd ..
rosdep install --from-paths src --ignore-src --rosdistro=${ROS_DISTRO} -y
catkin_make_isolated
echo “export SVGA_VGPU10=0” >> ~/.bashrc
source ~/.bashrc
A.2 安装cartographer支持
cd ~/carto_ws/src
git clone -b melodic-devel https://github.com/husky/husky-cartographer.git
cd ..
rosdep install --from-paths src --ignore-src --rosdistro=${ROS_DISTRO} -y
catkin_make_isolated
A.3 运行
source ~/carto_ws/devel_isolated/setup.bash
export HUSKY_URDF_EXTRAS=$(rospack find husky_description)/urdf/empty.urdf
roslaunch husky_gazebo husky_empty_world.launch
roslaunch teleop_twist_joy teleop.launch
附录B. 安装GVINS
B.1 安装
cd ~/carto_ws/src
git clone https://github.com/HKUST-Aerial-Robotics/gnss_comm.git
git clone https://github.com/HKUST-Aerial-Robotics/GVINS.git
cd ..
rosdep install --from-paths src --ignore-src --rosdistro=${ROS_DISTRO} -y
catkin_make_isolated
B.2 运行
source ~/carto_ws/devel_isolated/setup.bash
roslaunch gvins visensor_f9p.launch
rviz -d ~/carto_ws/src/GVINS/config/gvins_rviz_config.rviz
rosbag play sports_field.bag
上述命令中,rosbag回放文件可以从https://github.com/HKUST-Aerial-Robotics/GVINS-Dataset下载。文章来源地址https://uudwc.com/A/nPknb