cartographer+turtlebot+hokuyo|安装配置

2024-09-08 09:32

本文主要是介绍cartographer+turtlebot+hokuyo|安装配置,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

cartographer+turtlebot+hokuyo|安装配置


系统:ubuntu 14.04+ros indigo 或 ubuntu 16.04+ros kinetic
平台:turtlebot2
传感器:hokuyo UTM-30LX laser

本文假设已经成功安装ubuntu,ros,以及各种与turtlebot相关的ros package等。本文主要介绍,怎么安装配cartographer+turtlebot+hokuyo,具体的包括安装cartographer, cartographer_ros, cartographer_turtlebot,以及在gazebo仿真环境中使用cartographer等。后续相关的工作会不定期往后续。


文章目录

  • cartographer+turtlebot+hokuyo|安装配置
    • 1.安装cartographer,cartographer_ros,cartographer_turtlebot
      • 1.1 cartographer+cartographer_ros
      • 1.2 cartographer_turtlebot
    • 2.测试数据集
      • 2.1 cartographer_ros数据集
      • 2.2 cartographer_turtlebot
    • 3. turtlebot+hokuyo+cartographer in gazebo
      • 3.1 turtlebot_gazebo仿真环境添加hokuyo
      • 3.2 仿真环境+cartographer
          • debug...
    • 4. turtlebot+hokuyo+cartographer in real world

1.安装cartographer,cartographer_ros,cartographer_turtlebot

1.1 cartographer+cartographer_ros

从师弟那见识了cartographer在实际机器人上进行slam的效果后,马上回来学习学习。由于开始并不知道谷歌研究人员为了方便cartographer在turtlebot机器人上的应用,已经出了cartographer_turtlebot。所以开始我按照谷歌cartographer_ros官网的方式安装,一次性就成功了(打开了科学上网工具)。后来发现还有另一种流行的安装方式,我称之为民间方法,经过亲自测试,也是有效的。所以,本人测试,两种安装方式都是有效的。各自的优缺点列出如下:

  • 谷歌官网安装
    优点:类似于一键安装,所有的安装包都在一个工作空间,便于管理。
    缺点:有些步骤需要科学上网(翻墙)才能成功。

  • 民间安装方法
    优点:每一步是分离开的,可控性更大,可以一个库一个库的安装。
    缺点:基于的github源可能有点老,不知道作者更新了没。

大家可以任意选择一种尝试,不行换另一个就行。在安装过程中,会出现有些库很难安装成功,甚至找不到该库,这是因为ros的国内镜像源的问题,更换源就行了。本次安装,我换了好几次源(易科的、USTC、以及清华大学)。有些库在易科的源下面卡半天,但是换成在USTC源下面很顺利的就安装成功。这是我想强调给大家的,不要盲目的试,不是什么神秘的现象,是你的ros镜像源的问题。重点!!!!

1.2 cartographer_turtlebot

本人偿试了官网的安装方式,安装不成功。也试了git clone到本地再编译的方式也不成功。下面介绍自己在无数次失败后成功的安装方法。

官网的安装方式的特点是,一键搞定。例如,在安装cartographer_ros时,会同时安装cartographer以及其它依赖包。而cartographer_turtlebot是同时依赖cartographer与cartographer_ros的,官网在安装cartographer_turtlebot时会再次把cartographer,cartographer_ros,以及其它依赖包再次安装一遍,这是在用谷歌官网教程安装时要注意的。他是向前包容的,也就是说,理想情况下,我只需要按装官网安装cartographer_turtlebot的方法,执行所有命令就可以了,并不需要提前单独装cartographer_ros,cartographer等。但是,我将安装好的cartographer与cartographer_ros工作空间删掉后,严格按照cartographer_turtlebot官网安装来了一遍,结果没有成功(还好,在删之前,我把工作空间都备份了,所以说备份很重要!!!)。我本来已经放弃使用cartographer_turtlebot了,而是选择研究cartographer_turtlebot里面的launch文件、configuration_files里的文件来模仿它自己写配置文件。后来发现launch文件里只依赖一个cartographer_turtlebot包里生成的node,也就是说该包里只有一个node。于是,我自己建立工作空间,将这个节点.cc文件进行编译。后面还真成功了,下面给出详细的过程。

下面是我在已经安装好cartographer_ros的前提下,安装cartographer_turtlebot的方法。

  • 1.构建ros工作空间
mkdir -p ~/cartographer_turtlebot_ws/src
cd ~/cartographer_turtlebot_ws/src
catkin_init_workspace
cd ..
catkin_make

注意:建立新的工作空间后,记得将source ~/cartographer_turtlebot_ws/devel/setup.bash添加到~/.bashrc文件中

  • 2.建立新的pkg
cd ~/cartographer_turtlebot_ws/src
catkin_create_pkg cartographer_turtlebot
cd ..
catkin_make
  • 3.将cartographer_turtlebot包 git clone到本地
cd ~/Download
git clone https://github.com/googlecartographer/cartographer_turtlebot
  • 4.将~/Download/cartographer_turtlebot/cartographer_turtlebot文件夹下的三个子文件夹cartographer_turtlebot(当复制到目标文件夹后,改名为src),configuration_files,launch全部复制到~/cartographer_turtlebot_ws/src/cartographer_turtlebot。并将复制过来的子文件夹cartographer_turtlebot更名为src。此时的文件目录如下图所示
    在这里插入图片描述

  • 5.对~/cartographer_turtlebot_ws/src/cartographer_turtlebot/CMakeLists.txt文件进行修改,下面直接帖出修改后的文件内容,只需复制该内容替换原来的CMakeLists.txt文件即可。

cmake_minimum_required(VERSION 2.8.3)
project(cartographer_turtlebot)# Compile as C++11
add_compile_options(-std=c++11)set(PACKAGE_DEPENDENCIESroscpproslibsensor_msgs
)find_package(catkin REQUIRED COMPONENTS ${PACKAGE_DEPENDENCIES})
catkin_package(
)include_directories(include ${catkin_INCLUDE_DIRS} ${PCL_INCLUDE_DIRS})
add_executable(cartographer_flat_world_imu_node "src/flat_world_imu_node_main.cc")
target_link_libraries(cartographer_flat_world_imu_node ${catkin_LIBRARIES})
add_dependencies(cartographer_flat_world_imu_node ${catkin_EXPORTED_TARGETS})

~/cartographer_turtlebot_ws/src/cartographer_turtlebot/package.xml先不做修改。

如果后面出了错误,可以偿试在该文件内容的<buildtool_depend>catkin</buildtool_depend>后面添加下面几行内容。

  <build_depend>sensor_msgs</build_depend><build_export_depend>sensor_msgs</build_export_depend><exec_depend>sensor_msgs</exec_depend>
  • 6.编译工作空间
cd ~/cartographer_turtlebot_ws
catkin_make

不出意外,会编译完成。

2.测试数据集

2.1 cartographer_ros数据集

  • 1.下载数据集
# Download the 2D backpack example bag.
wget -P ~/Downloads https://storage.googleapis.com/cartographer-public-data/bags/backpack_2d/cartographer_paper_deutsches_museum.bag
# Download the 3D backpack example bag.
wget -P ~/Downloads https://storage.googleapis.com/cartographer-public-data/bags/backpack_3d/with_intensities/b3-2016-04-05-14-14-00.bag
  • 2.测试数据集
# Launch the 2D backpack demo.
roslaunch cartographer_ros demo_backpack_2d.launch bag_filename:=${HOME}/Downloads/cartographer_paper_deutsches_museum.bag

部分效果如下图所示:
在这里插入图片描述

# Launch the 3D backpack demo.
roslaunch cartographer_ros demo_backpack_3d.launch bag_filename:=${HOME}/Downloads/b3-2016-04-05-14-14-00.bag

数据太大9个G,就不跑了。

2.2 cartographer_turtlebot

  • 1.下载测试数据集
# Download the example bag.
wget -P ~/Downloads https://storage.googleapis.com/cartographer-public-data/bags/turtlebot/cartographer_turtlebot_demo.bag
  • 2.测试结果
# Launch the 2D LIDAR demo.
roslaunch cartographer_turtlebot demo_lidar_2d.launch bag_filename:=${HOME}/Downloads/cartographer_turtlebot_demo.bag

部分结果如下图所示:
在这里插入图片描述

# Launch the 2D depth camera demo.
roslaunch cartographer_turtlebot demo_depth_camera_2d.launch bag_filename:=${HOME}/Downloads/cartographer_turtlebot_demo.bag

部分结果如下图所示:
在这里插入图片描述

# Launch the 3D depth camera demo.
roslaunch cartographer_turtlebot demo_depth_camera_3d.launch bag_filename:=${HOME}/Downloads/cartographer_turtlebot_demo.bag

部分结果如下图所示:
在这里插入图片描述
这个应该是有点问题,不过cartographer_turtlebot肯定是安装成功了。

3. turtlebot+hokuyo+cartographer in gazebo

当实体机器人成本很高,而且不是很方便随处携带时,在仿真软件中进行机器人的研究不失一种很好的替代。在机器人仿真平台中,gazebo更是以其出色的物理引擎,以及与ros完全的接口,被广泛应用。本节主要介绍利用gazebo搭建立turtlebot+hokuyo的仿真环境,并且基于仿真数据实现cartographer的SLAM目的。

3.1 turtlebot_gazebo仿真环境添加hokuyo

由于turtlebot_gazebo包里的turtlebot默认的传感器是kinect,所以核心问题是怎么将kinect更换成hokuyo。该部分可以参照MaxChanger|CSDN博客,本人就是按照他一步一步配置,最后成功在gazebo中运行turtlebot+hokuyo,并能成功发布激光数据。所以,本篇就不重述整个配置过程,只对其中未讲明白的地方进行阐述。主要有以下三点:

  1. CSDN博主RGiant在MaxChanger|CSDN博客的未尾评论的:“步骤3实际修改了3处,不要漏掉:
<sensor_hokuyo parent="base_link" />
  1. MaxChanger|CSDN博客实际上配置的是turtlebot+kinect+hokuyo的过程。如果只是想用hokuyo替换掉kinect的话,可以将步骤中有关kinect的脚本从文件中删掉即可。具体地:步骤3中将kobuki_hexagons_hokuyo.urdf.xacro文件中第12,17注释掉;步骤6中将turtlebot_gazebo.urdf.xacro文件中4-41行注释掉。

  2. MaxChanger|CSDN博客配置完的hokuyo激光视角FOV为 from − 1 2 π -\frac{1}{2}\pi 21π to 1 2 π \frac{1}{2}\pi 21π,而我的hokuyo型号为UTM-30LX,FOV为 from − 3 4 π -\frac{3}{4}\pi 43π to 3 4 π \frac{3}{4}\pi 43π。而该设置与步骤6turtlebot_gazebo.urdf.xacro文件中第89、90行。

<min_angle>-1.570796</min_angle>
<max_angle>1.570796</max_angle>

更改为:

<!-- FOV from -3*pi/4 to 3*pi/4 -->
<min_angle>-2.356194</min_angle> 
<max_angle>2.356194</max_angle>

配置中默认hokuyo安装在turtlebot的前额,如果想安装在正中间,可以将步骤5的第10行由:

<origin xyz="0.10 0 0.435" rpy="0 0.0 0.0" />

改为

<origin xyz="0.0 0 0.435" rpy="0 0.0 0.0" />

注意以上几点后,配置完成后,就可以修改环境变量:

gedit .bashrc
#在最后添加以下内容
#For gazebo 
export  TURTLEBOT_BASE=kobuki
export  TURTLEBOT_STACKS=hexagons
export  TURTLEBOT_3D_SENSOR=hokuyo

之后运行,正常,激光有数据,话题/scan正常

source /opt/ros/indigo/setup.bash
roslaunch turtlebot_gazebo explorer.launch
roslaunch turtlebot_rviz_launchers view_navigation.launch

更改后的机器人turtlebot+激光hokuyo,注意此时Kinect已经不在机器人上了。
在这里插入图片描述
在这里插入图片描述
turtlebot+hokuyo在rviz中显示的:

在这里插入图片描述

turtlebot+hokuyo在gazebo中:
在这里插入图片描述

3.2 仿真环境+cartographer

~/cartographer_turtlebot_ws/src/cartographer_turtlebot/launch文件夹下新建文件turltebot_hokuyo.launch

<!-- turtlebot_hokuyo.launch -->
<launch><param name="/use_sim_time" value="true" /><node name="cartographer_node" pkg="cartographer_ros"type="cartographer_node" args="-configuration_directory$(find cartographer_turtlebot)/configuration_files-configuration_basename turtlebot_hokuyo.lua"output="screen"><!--remap from="base_footprint" to="/base_link" /--><!--remap from="scan" to="/laser_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_in" to="/mobile_base/sensors/imu_data" /><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" /><node name="cartographer_occupancy_grid_node" pkg="cartographer_ros"type="cartographer_occupancy_grid_node" args="-resolution 0.05" />
</launch>

~/cartographer_turtlebot_ws/src/cartographer_turtlebot/configuration_files文件夹下新建文件turltebot_hokuyo.lua


<!-- turtlebot_hokuyo.lua -->
include "map_builder.lua"
include "trajectory_builder.lua"options = {map_builder = MAP_BUILDER,trajectory_builder = TRAJECTORY_BUILDER,map_frame = "map",tracking_frame = "gyro_link",published_frame = "odom",odom_frame = "odom",provide_odom_frame = false,publish_frame_projected_to_2d = false,use_odometry = true,use_nav_sat = false,use_landmarks = false,num_laser_scans = 1,num_multi_echo_laser_scans = 0,num_subdivisions_per_laser_scan = 1,num_point_clouds = 0,lookup_transform_timeout_sec = 0.2,submap_publish_period_sec = 0.3,pose_publish_period_sec = 5e-3,trajectory_publish_period_sec = 30e-3,rangefinder_sampling_ratio = 1.,odometry_sampling_ratio = 0.1,fixed_frame_pose_sampling_ratio = 1.,imu_sampling_ratio = 1.,landmarks_sampling_ratio = 1.,
}MAP_BUILDER.use_trajectory_builder_2d = trueTRAJECTORY_BUILDER_2D.min_range = 0.1
TRAJECTORY_BUILDER_2D.max_range = 8.
TRAJECTORY_BUILDER_2D.missing_data_ray_length = 5.
TRAJECTORY_BUILDER_2D.use_imu_data = false
TRAJECTORY_BUILDER_2D.use_online_correlative_scan_matching = true
TRAJECTORY_BUILDER_2D.motion_filter.max_angle_radians = math.rad(0.1)POSE_GRAPH.constraint_builder.min_score = 0.65
POSE_GRAPH.constraint_builder.global_localization_min_score = 0.7return options

按照以上配置完成后,运行

source /opt/ros/indigo/setup.bash
roslaunch turtlebot_gazebo explorer.launch
roslaunch cartographer_turtlebot turtlebot_hokuyo.launch

gazebo
在这里插入图片描述
rviz
在这里插入图片描述

debug…

大家只需要按照以上过程配置即可,此处记录本人摸索过程遇到的问题,只为记录,大家可以忽略。

当我直接利用原始的turtlebot_urg_lidar_2d.lua文件时,出现错误map_by_time.h:43] Check failed: data.time > std::prev(trajectory.end())->first #831,相关问题及解答网址贴在此处以备查阅map_by_time.h:43,Check failed: data.time > std::prev(trajectory.end())->first #831

我采用这个人的方法,对.lua文件做对应改正后,运行就没问题了。
在这里插入图片描述

到目前,我们已经可以在gazebo仿真利用turtlebot+hokuyo与cartographer进行slam构建地图与定位。

4. turtlebot+hokuyo+cartographer in real world

如果在gazebo中跑通了turtlebot+hokuyo+cartographer,就可以经过一些修改应用于真实的turtlebot机器人。

  • 1.安装配置hokuyo_node
    如果ros是indigo版本,直接运行sudo apt-get install ros-indigo-hokuyo-node安装。如果是kinetic版本,需要从源安装。请先编译完driver_common后再git clone hokuyo_node,编译
cd ~/cartographer_turtlebot_ws/src
git clone https://github.com/ros-drivers/driver_common.git
cd ..
catkin_make
cd ~/cartographer_turtlebot_ws/src
git clone git clone https://github.com/ros-drivers/hokuyo_node.git 
cd ..
catkin_make

运行ls -l /dev/ttyACM0,如果报错,没有目标文件,则说明计算机没有配置ACM串口模块。对一般的PC应该不会出这种情况,我在英伟达的TX2上遇到过这种情况。解决方案请参照本人另一篇博客TX2 安装ttyACM串口驱动。

如果显示crw-rw-XX- 1 root dialout 166, 0 2009-10-27 14:18 /dev/ttyACM0,则正常,然后运行sudo chmod a+rw /dev/ttyACM0

然后turtlebot连接hokuyo,运行

roscore
rosrun hokuyo_node hokuyo_node

查看是否发布激光数据

rostopic echo /scan
  • 2.编定启动launch文件.
cd ~/cartograher_turtlebot_ws/src/cartographer_turtlebot/launch
gedit turtlebot_hokuyo_realworld.launch
<launch><arg name="configuration_basename" /><include file="$(find turtlebot_bringup)/launch/minimal.launch" /><node name="hokuyo_node" pkg="hokuyo_node" type="hokuyo_node"><param name="frame_id" value="hokuyo_link"/></node><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="points2" to="/camera/depth/points" /--></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" /><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" /><node name="cartographer_occupancy_grid_node" pkg="cartographer_ros"type="cartographer_occupancy_grid_node" args="-resolution 0.05" />
</launch>

运行roslaunch cartographer_turtlebot turtlebot_hokuyo_realworld.launch


未完待续…

这篇关于cartographer+turtlebot+hokuyo|安装配置的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1147742

相关文章

MySQL zip安装包配置教程

《MySQLzip安装包配置教程》这篇文章详细介绍了如何使用zip安装包在Windows11上安装MySQL8.0,包括下载、解压、配置环境变量、初始化数据库、安装服务以及更改密码等步骤,感兴趣的朋... 目录mysql zip安装包配置教程1、下载zip安装包:2、安装2.1 解压zip包到安装目录2.2

python安装whl包并解决依赖关系的实现

《python安装whl包并解决依赖关系的实现》本文主要介绍了python安装whl包并解决依赖关系的实现,文中通过图文示例介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面... 目录一、什么是whl文件?二、我们为什么需要使用whl文件来安装python库?三、我们应该去哪儿下

MySQL安装时initializing database失败的问题解决

《MySQL安装时initializingdatabase失败的问题解决》本文主要介绍了MySQL安装时initializingdatabase失败的问题解决,文中通过图文介绍的非常详细,对大家的学... 目录问题页面:解决方法:问题页面:解决方法:1.勾选红框中的选项:2.将下图红框中全部改为英

MySQL9.0默认路径安装下重置root密码

《MySQL9.0默认路径安装下重置root密码》本文主要介绍了MySQL9.0默认路径安装下重置root密码,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们... 目录问题描述环境描述解决方法正常模式下修改密码报错原因问题描述mysqlChina编程采用默认安装路径,

MySQL 中的服务器配置和状态详解(MySQL Server Configuration and Status)

《MySQL中的服务器配置和状态详解(MySQLServerConfigurationandStatus)》MySQL服务器配置和状态设置包括服务器选项、系统变量和状态变量三个方面,可以通过... 目录mysql 之服务器配置和状态1 MySQL 架构和性能优化1.1 服务器配置和状态1.1.1 服务器选项

Python使用国内镜像加速pip安装的方法讲解

《Python使用国内镜像加速pip安装的方法讲解》在Python开发中,pip是一个非常重要的工具,用于安装和管理Python的第三方库,然而,在国内使用pip安装依赖时,往往会因为网络问题而导致速... 目录一、pip 工具简介1. 什么是 pip?2. 什么是 -i 参数?二、国内镜像源的选择三、如何

Python安装时常见报错以及解决方案

《Python安装时常见报错以及解决方案》:本文主要介绍在安装Python、配置环境变量、使用pip以及运行Python脚本时常见的错误及其解决方案,文中介绍的非常详细,需要的朋友可以参考下... 目录一、安装 python 时常见报错及解决方案(一)安装包下载失败(二)权限不足二、配置环境变量时常见报错及

SpringBoot+MyBatis-Flex配置ProxySQL的实现步骤

《SpringBoot+MyBatis-Flex配置ProxySQL的实现步骤》本文主要介绍了SpringBoot+MyBatis-Flex配置ProxySQL的实现步骤,文中通过示例代码介绍的非常详... 目录 目标 步骤 1:确保 ProxySQL 和 mysql 主从同步已正确配置ProxySQL 的

Spring Boot整合log4j2日志配置的详细教程

《SpringBoot整合log4j2日志配置的详细教程》:本文主要介绍SpringBoot项目中整合Log4j2日志框架的步骤和配置,包括常用日志框架的比较、配置参数介绍、Log4j2配置详解... 目录前言一、常用日志框架二、配置参数介绍1. 日志级别2. 输出形式3. 日志格式3.1 PatternL

配置springboot项目动静分离打包分离lib方式

《配置springboot项目动静分离打包分离lib方式》本文介绍了如何将SpringBoot工程中的静态资源和配置文件分离出来,以减少jar包大小,方便修改配置文件,通过在jar包同级目录创建co... 目录前言1、分离配置文件原理2、pom文件配置3、使用package命令打包4、总结前言默认情况下,