使用Turtlebot 2和Rplidar A2实现Cartographer

参考:

TX2+rplidar+cartographer
创客智造-ROS 与 SLAM 入门教程 - cartographer 在 Turltlebot 的应用 3 - 构建地图
Turtlebot 入门教程 - 激光雷达 (Rplidar)gmapping 构建地图
创客智造-Turtlebot 入门 - 创建地图
创客智造-Turtlebot 入门 - 遥控

主机:Jetson TX2
Ubuntu版本:16.04 LTS

Jetson TX2主要的软件安装在Jetson TX2 使用 Rplidar A2 实现 Cartographer已经介绍了,这篇就记录一下如何和Turtlebot2搭配使用。

一:安装cartographer_turtlebot

前提:ROS、cartographer、cartographer_ros、rplidar_ros等都已经安装
官方教程:https://google-cartographer-ros-for-turtlebots.readthedocs.io/en/latest/

# Install wstool and rosdep.
sudo apt-get update
sudo apt-get install -y python-wstool python-rosdep ninja-build

# Create a new workspace in 'catkin_ws'.
mkdir catkin_ws
cd catkin_ws
wstool init src

# Merge the cartographer_turtlebot.rosinstall file and fetch code for dependencies.
wstool merge -t src https://raw.githubusercontent.com/googlecartographer/cartographer_turtlebot/master/cartographer_turtlebot.rosinstall
wstool update -t src

# Install deb dependencies.
# The command 'sudo rosdep init' will print an error if you have already
# executed it since installing ROS. This error can be ignored.
sudo rosdep init
rosdep update
rosdep install --from-paths src --ignore-src --rosdistro=${ROS_DISTRO} -y

# Build and install.
catkin_make_isolated --install --use-ninja
source install_isolated/setup.bash

二:安装turtlebot_apps

需要用到turtlebot_navigation,turtlebot_navigation在turtlebot_apps里面,所以需要安装turtlebot_apps

$ cd   ~/catkint_ws/src
# turtlebot建图依赖包
$ git clone https://github.com/turtlebot/turtlebot_apps 
#编译
$ cd  ~/catkin_ws
$ catkin_make_isolated --install --use-ninja

添加环境变量,在~/.bashrc 最后添加一行:
source install_isolated/setup.bash
刷新配置
$ source ~/.bashrc

$ rospack profile

三、制作雷达驱动启动文件(重点)

1、复制 rplidar.launch 到 rplidar-laser.launch

$ roscd turtlebot_navigation
$ mkdir -p laser/driver
$ sudo cp ~/catkin_ws/src/rplidar_ros/launch/rplidar.launch laser/driver/rplidar_laser.launch

2、打开 rplidar_laser.launch进行修改

检查 frame_id 是否指定为 laser:
<param name="frame_id" type="string" value="laser"/>
3、增加 TF 定义

<node pkg="tf" type="static_transform_publisher" name="base_to_laser" args="0.0 0.0 0.18 0 0.0 0.0 base_link laser 100"/>

4、重新编译

#重新编译
$ cd ~/catkin_ws
$ catkin_make_isolated --install --use-ninja
  • 修改为 args="0.0 0.0 0.18 0 0.0 0.0 为自己的实际安装位置。详情查看,static_transform_publisher 部分

  • static_transform_publisher x y z qx qy qz qw frame_id child_frame_id period_in_ms

  • 这里我假设底盘的中心点为 0,雷达放在机器人托盘中心位置,X 为 0,高度为 18CM,Z 为 0.18m

  • TF 的单位使用米的,测量单位是 CM

  • rplidar_laser.launch修改后的完整代码如下:

<launch>
  <node name="rplidarNode"          pkg="rplidar_ros"  type="rplidarNode" output="screen">
  <param name="serial_port"         type="string" value="/dev/ttyUSB0"/>  
  <param name="serial_baudrate"     type="int"    value="115200"/>
  <param name="frame_id"            type="string" value="laser"/>
  <param name="inverted"            type="bool"   value="false"/>
  <param name="angle_compensate"    type="bool"   value="true"/>
  </node>

  <node pkg="tf" type="static_transform_publisher" name="base_to_laser" args="0.0 0.0 0.18 0 0.0 0.0 base_link laser 100"/>
</launch>

四:使用cartographer_turtlebot构建地图

1、增加 turtlebot_lidar.launch

$ cd ~/catkin_ws/src/cartographer_turtlebot/cartographer_turtlebot/launch
$ touch turtlebot_lidar.launch 
$ vim turtlebot_lidar.launch 

写入如下代码:

<launch>
  <arg name="configuration_basename"/>

  <include file="$(find turtlebot_bringup)/launch/minimal.launch" />

  <node name="cartographer_node" pkg="cartographer_ros"
      type="cartographer_node" args="
          -configuration_directory
              $(find cartographer_turtlebot)/configuration_files
          -configuration_basename $(arg configuration_basename)"
      output="screen">
    <remap from="scan" to="/scan" />
  </node>

  <node name="flat_world_imu_node" pkg="cartographer_turtlebot"
      type="cartographer_flat_world_imu_node" output="screen">
    <remap from="imu_in" to="/mobile_base/sensors/imu_data_raw" />
    <remap from="imu_out" to="/imu" />
  </node>

  <node name="rviz" pkg="rviz" type="rviz" required="true"
      args="-d $(find cartographer_turtlebot
          )/configuration_files/demo_turtlebot.rviz" />

</launch>

2、新增启动文件 turtlebot_lidar_2d.launch

$ cd ~/catkin_ws/src/cartographer_turtlebot/cartographer_turtlebot/launch
$ touch turtlebot_lidar_2d.launch
$ vim turtlebot_lidar_2d.launch

写入如下代码:

<launch>
  <include file="$(find cartographer_turtlebot)/launch/turtlebot_lidar.launch">
    <arg name="configuration_basename" value="turtlebot_urg_lidar_2d.lua" />
  </include>
</launch>

3、重新编译

#重新编译
$ cd ~/catkin_ws
$ catkin_make_isolated --install --use-ninja

4、启动Rplidar A2雷达
打开一个新终端,输入:
$ roslaunch turtlebot_navigation rplidar_laser.launch
5、启动cartographer_turtlebot建地图
再打开一个新终端,输入:
$ roslaunch cartographer_turtlebot turtlebot_lidar_2d.launch
6、使用键盘操作turtlebot2移动
又打开一个新终端,输入:
$ roslaunch turtlebot_teleop keyboard_teleop.launch
按提示利用键盘控制turtlebot2移动建图。
具体以及更多控制方式可参考:创客智造-Turtlebot 入门 - 遥控

五、保存地图

#新建map文件夹用于保存地图
$ mkdir -p ~/map
#启动存图,并将名为lidar_2d的地图文件保存在map文件夹
$ rosrun map_server map_saver -f ~/map/lidar_2d
#查看内容,包含lidar_2d.pgm  lidar_2d.yaml
$ ls ~/map   

大功告成!!!!
https://xrp001.github.io/tutorial/2018/05/26/turtlebot2-rplidara2-cartographer/

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 159,835评论 4 364
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 67,598评论 1 295
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 109,569评论 0 244
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 44,159评论 0 213
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 52,533评论 3 287
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 40,710评论 1 222
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 31,923评论 2 313
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 30,674评论 0 203
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 34,421评论 1 246
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 30,622评论 2 245
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 32,115评论 1 260
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 28,428评论 2 254
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 33,114评论 3 238
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 26,097评论 0 8
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 26,875评论 0 197
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 35,753评论 2 276
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 35,649评论 2 271

推荐阅读更多精彩内容