学习记录02

本文为毕业设计及论文的环境搭建及算法配置。
转载请注明出处。

2.1 建图功能包配置

在src文件夹下打开终端,创建功能包gazebo_map,并编译

catkin_create_pkg gazebo_map
catkin_make

在gazebo_map中打开终端并创建四个文件夹

mkdir cfg launch map rviz

cfg文件夹--------存储传感器与算法配置文件
launch文件夹—存储节点启动文件
map---------------存储建图完成后的图片和配置文件(yaml)
rviz----------------存储rviz可视化模型

2.2 利用cartographer建图

安装cartographer
打开终端键入

sudo apt-get install ros-melodic-cartographer-ros

复制carto包中的demo_revo_lds.launch文件至gazebo_map/launch目录下
该启动文件用于打开rviz用于可视化建图

复制carto包中的revo_lds.lua文件至gazebo_map/cfg目录下

cp cartographer_ros/cartographer_ros/launch/demo_revo_lds.launch gazebo_test_ws/src/gazebo_map/launch
cp cartographer_ros/cartographer_ros/configuration_files/revo_lds.lua gazebo_test_ws/src/gazebo_map/cfg

将demo_revo_lds.launch重命名为cartographer_demo.launch
将原内容删除,复制以下代码(自己创建launch文件会出错??)

<!--
  Copyright 2016 The Cartographer Authors

  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
-->

<launch>
  <param name="/use_sim_time" value="true" />

  <node name="cartographer_node" pkg="cartographer_ros"
      type="cartographer_node" args="
          -configuration_directory $(find gazebo_map)/cfg 
          -configuration_basename lidar_info.lua"
      output="screen">
   <remap from="scan" to="scan" />
  </node>

  <node name="cartographer_occupancy_grid_node" pkg="cartographer_ros"
      type="cartographer_occupancy_grid_node" args="-resolution 0.05" />

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

</launch>

将revo_lds.lua重命名为lidar_info.lua
同理

-- Copyright 2016 The Cartographer Authors
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
--      http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.

include "map_builder.lua"
include "trajectory_builder.lua"

options = {
  map_builder = MAP_BUILDER,                    
  trajectory_builder = TRAJECTORY_BUILDER,      --
  map_frame = "map",                            --一般为“map”.用来发布submap的ROS帧ID.
  tracking_frame = "base_link",                 --SLAM算法要跟踪的ROS 帧ID
	published_frame = "base_link",                --用来发布pose的帧ID
  odom_frame = "odom",                          --只要当有里程计信息的时候才会使用。即provide_odom_frame=true
  provide_odom_frame = true,                    --如果为true,the local, non-loop-closed, continuous pose将会在map_frame里以odom_frame发布
  publish_frame_projected_to_2d = false,        --如果为true,则已经发布的pose将会被完全成2D的pose,没有roll,pitch或者z-offset
  use_odometry = false,                         --如果为true,需要提供里程计信息,并话题/odom会订阅nav_msgs/Odometry类型的消息,在SLAM过程中也会使用这个消息进行建图
  use_nav_sat = false,                          --如果为true,会在话题/fix上订阅sensor_msgs/NavSatFix类型的消息,并且在globalSLAM中会用到
  use_landmarks = false,                        --如果为true,会在话题/landmarks上订阅cartographer_ros_msgs/LandmarkList类型的消息,并且在SLAM过程中会用到
  num_laser_scans = 1,                          --SLAM可以输入的/scan话题数目的最大值
  num_multi_echo_laser_scans = 0,               --SLAM可以输入sensor_msgs/MultiEchoLaserScan话题数目的最大值
  num_subdivisions_per_laser_scan = 1,          --将每个接收到的(multi_echo)激光scan分割成的点云数。 细分scam可以在扫描仪移动时取消scanner获取的scan。 
                                                --有一个相应的trajectory builder option可将细分扫描累积到将用于scan_matching的点云中
  num_point_clouds = 0,                         --SLAM可以输入的sensor_msgs/PointCloud2话题数目的最大值
  lookup_transform_timeout_sec = 0.2,           --使用tf2查找transform的超时时间(秒)
  submap_publish_period_sec = 0.3,              --发布submap的时间间隔(秒)
  pose_publish_period_sec = 5e-3,               --发布pose的时间间隔,值为5e-3的时候为200HZ
  trajectory_publish_period_sec = 30e-3,        --发布trajectory markers(trajectory的节点)的时间间隔,值为30e-3为30ms
  rangefinder_sampling_ratio = 1.,              --测距仪的固定采样ratio
  odometry_sampling_ratio = 0.1,                --里程计的固定采样ratio
  fixed_frame_pose_sampling_ratio = 1.,         --****采样频率
  imu_sampling_ratio = 1.,                      --IMU message的固定采样ratio
  landmarks_sampling_ratio = 1.,                --landmarks message的固定采样ratio
}   

MAP_BUILDER.use_trajectory_builder_2d = true

TRAJECTORY_BUILDER_2D.submaps.num_range_data = 35     
TRAJECTORY_BUILDER_2D.min_range = 0.3
TRAJECTORY_BUILDER_2D.max_range = 8.
TRAJECTORY_BUILDER_2D.missing_data_ray_length = 1.
TRAJECTORY_BUILDER_2D.use_imu_data = false
TRAJECTORY_BUILDER_2D.use_online_correlative_scan_matching = true
TRAJECTORY_BUILDER_2D.real_time_correlative_scan_matcher.linear_search_window = 0.1
TRAJECTORY_BUILDER_2D.real_time_correlative_scan_matcher.translation_delta_cost_weight = 10.
TRAJECTORY_BUILDER_2D.real_time_correlative_scan_matcher.rotation_delta_cost_weight = 1e-1

POSE_GRAPH.optimization_problem.huber_scale = 1e2
POSE_GRAPH.optimize_every_n_nodes = 35
POSE_GRAPH.constraint_builder.min_score = 0.65

return options

2.3 配置rviz

roslaunch gazebo_pkg icra.launch					#新开终端输入下一命令
roslaunch gazebo_map cartographer_demo.launch

请添加图片描述执行第二条代码时若遇到cartographer包没有安装现象,执行命令

sudo apt-get install ros-melodic-cartographer*

等待安装完毕(若其中还遇到其他功能包缺失现象按照error提示安装即可),重新执行三条指令。
rviz启动后点击左下角add
在topic中选择laserscan, map
在display中选择robotmodel
添加完毕后,点击左上角file—>save config as 文件命名为cartographer_demo.rviz存储在gazebo_map/rviz目录下

2.4 开始建图

roslaunch gazebo_pkg race.launch

roslaunch gazebo_map cartographer_demo.launch

rosrun teleop_twist_keyboard teleop_twist_keyboard.py

控制小车对每个位置都进行探索,尽量缓慢,保证建图精度

若所建地图不够好,请自行调整阈值参数。–occ为无法通行的阈值,–free为可通行的阈值。
若–occ过高,则可能出现墙体边缘出现灰色未探索地块;若–occ过低,则无墙体部分可能会被凭空建墙。
若–free过高,则可能出现墙体被认为是自由区域;若–free过低,则自由区域可能出现灰色未探索地块。

保存地图

安装map_server

sudo apt-get install ros-melodic-map-server
source ~/.bashrc

保存地图,命名为icra_map

rosrun map_server map_saver --occ 70 --free 30 -f icra_map

保存的地图在工作空间中根目录,即study01中,将图片和yaml文件都剪切到gazebo_map/map文件夹下

请添加图片描述后续需要考虑如何提高建图的精度,图中有较多不清晰及断点处

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值