网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。
一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!
<launch>
<param name="robot\_description"
textfile="$(find cartographer\_ros)/urdf/my\_backpack\_3d.urdf" />//换成自己的机器人配置文件
<node name="robot\_state\_publisher" pkg="robot\_state\_publisher"
type="robot\_state\_publisher" />
<node name="cartographer\_node" pkg="cartographer\_ros"
type="cartographer\_node" args="
-configuration_directory $(find cartographer_ros)/configuration_files
-configuration_basename my_robot_3d.lua" //换成自己配置文件
output="screen">
<remap from="points2" to="/rfans\_driver/rfans\_points" />//换成自己的bag包数据中的点云话题
</node>
<node name="cartographer\_occupancy\_grid\_node" pkg="cartographer\_ros"
type="cartographer\_occupancy\_grid\_node" args="-resolution 0.05" />
</launch>
会看点云话题吗?用这个命令查看
# rosbag info \*\*\*\*\*.bag
看到这个topics中sensor_msgs/PointCloud2的这个话题类型了吗?前面的就是你自己数据的点云话题,我的点云话题是/rfans_driver/rfans_points,所以在launch文件中,把点云话题改成自己的
3. 配置lua文件
首先看一下使用官方backpack_3d.lua文件生成图的效果
include "map\_builder.lua"
include "trajectory\_builder.lua"
options = {
map_builder = MAP\_BUILDER,
trajectory_builder = TRAJECTORY\_BUILDER,
map_frame = "map",
tracking_frame = "base\_link",
published_frame = "base\_link",
odom_frame = "odom",
provide_odom_frame = true,
publish_frame_projected_to_2d = false,
use_odometry = false,
use_nav_sat = false,
use_landmarks = false,
num_laser_scans = 0,
num_multi_echo_laser_scans = 0,
num_subdivisions_per_laser_scan = 1,
num_point_clouds = 2,
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 = 1.,
fixed_frame_pose_sampling_ratio = 1.,
imu_sampling_ratio = 1.,
landmarks_sampling_ratio = 1.,
}
TRAJECTORY\_BUILDER\_3D.num_accumulated_range_data = 160
MAP\_BUILDER.use_trajectory_builder_3d = true
MAP\_BUILDER.num_background_threads = 7
POSE\_GRAPH.optimization_problem.huber_scale = 5e2
POSE\_GRAPH.optimize_every_n_nodes = 320
POSE\_GRAPH.constraint_builder.sampling_ratio = 0.03
POSE\_GRAPH.optimization_problem.ceres_solver_options.max_num_iterations = 10
POSE\_GRAPH.constraint_builder.min_score = 0.62
POSE\_GRAPH.constraint_builder.global_localization_min_score = 0.66
return options
看一下官方3d bag包跑出来的效果
看起来效果还可以吧
再看一下我建的图
我先说一下这张图的问题:1.为什么没有出现白色区域(已知区域)2.为什么有这么多的噪点
后来重新调整了lua文件
my_robot_3d.lua
include "map\_builder.lua"
include "trajectory\_builder.lua"
options = {
map_builder = MAP\_BUILDER,
trajectory_builder = TRAJECTORY\_BUILDER,
map_frame = "map",
tracking_frame = "base\_link", --imu
published_frame = "base\_link", --laser
odom_frame = "odom",
provide_odom_frame = false,
publish_frame_projected_to_2d = false,
use_odometry = false,
use_nav_sat = false,
use_landmarks = false,
num_laser_scans =0,
num_multi_echo_laser_scans = 0,
num_subdivisions_per_laser_scan = 1,
num_point_clouds = 1,
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 = 1, --1.
fixed_frame_pose_sampling_ratio = 1.,
imu_sampling_ratio = 1.,
landmarks_sampling_ratio = 1.,
}
TRAJECTORY\_BUILDER\_2D.min_z = 0.1
TRAJECTORY\_BUILDER\_2D.max_z = 1.5
TRAJECTORY\_BUILDER\_3D.num_accumulated_range_data = 1 --1
TRAJECTORY\_BUILDER\_3D.min_range = 1.3 --houjia
TRAJECTORY\_BUILDER\_3D.max_range = 25. --houjia
TRAJECTORY\_BUILDER\_3D.use_online_correlative_scan_matching = true --houjia
--TRAJECTORY\_BUILDER\_3D.submaps.num_range_data=90.
MAP\_BUILDER.use_trajectory_builder_3d = true
MAP\_BUILDER.num_background_threads = 7
POSE\_GRAPH.optimization_problem.huber_scale = 5e2
POSE\_GRAPH.optimize_every_n_nodes = 60
POSE\_GRAPH.constraint_builder.sampling_ratio = 0.03
POSE\_GRAPH.optimization_problem.ceres_solver_options.max_num_iterations = 10
POSE\_GRAPH.constraint_builder.min_score = 0.62
POSE\_GRAPH.constraint_builder.global_localization_min_score = 0.66
return options
出现了如下效果图,噪点没有了,至关重要的一个参数是TRAJECTORY_BUILDER_3D.use_online_correlative_scan_matching = true
这个参数的作用就是开启实时的闭环检测来进行前段的扫描匹配,所以生成的图效果非常好,就是计算量会增大,消耗更多CPU。
但是这个图还是不能用来导航啊,只有灰色和黑色区域(也就是障碍物和未知区域)。
现在剩下的问题就是要解决白色区域了
1.2在线或离线生成pbstream文件,再转成pgm,yaml文件
在线生成pbstream文件,还是启动上个方法的launch文件
# roslaunch cartographer_ros my_demo_backpack_3d.launch bag_filename:=${HOME}/Downloads/\*\*\*.bag
在rviz生成图了之后,启动一个新终端使用如下命令:
# rosservice call /finish_trajectory 0 //停止接受传感器数据
# rosservice call /write_state /home/路径/\*\*\*.pbstream //生成pbstream文件
接下来就是生成pgm文件
# roslaunch cartographer_ros assets_writer_ros_map.launch bag_filenames:=${HOME}/Downloads/2020-04-29-11-25-22.bag pose_graph_filename:=${HOME}/Downloads/2020-04-29-11-25-22.bag.pbstream
把bag文件路径和pbstream文件路径改成你自己的,生成图如下:
但是在路线闭环的情况下,就会出现激光雷达的波纹信息,如下图
虽然这种方法有白色可通行区域,但这个雷达波纹和行车轨迹看起来很恶心啊。
离线的方法我就不说了,效果是一样的。离线生成启动的launch文件是
roslaunch cartographer_ros offline_backpack_3d.launch bag_filenames:=${HOME}/Downloads/2020-05-13-16-37-40.bag
一样把launch文件换成自己的点云话题!运行完之后会直接生成pbstream文件
2.最终方案!使用3d点云数据直接在rviz上生成2d图(导航图,栅格图)
这种方法是需要里程计/odom信息,不用imu信息
先贴自己配置图
demo_zch_2d.launch
<launch>
<param name="/use\_sim\_time" value="true" />
<!-- <node pkg="tf" type="static\_transform\_publisher" name="base\_laser\_broadcaster" args="0 0 0 0 0 0 laserbase\_footprint /base\_footprint 20" /> -->
<include file="$(find cartographer\_ros)/launch/zch\_rslidar\_2d.launch" />
<node name="cartographer\_node" pkg="cartographer\_ros"
type="cartographer\_node" args="
-configuration_directory
$(find cartographer_ros)/configuration_files
-configuration_basename zch_rslidar_2d.lua"//你自己的lua文件
output="screen">
<remap from="/odom" to="/odom" /> //你自己的里程计话题
<remap from="/points2" to="/rfans\_driver/rfans\_points" /> //你自己的点云话题
</node>
<node name="rviz" pkg="rviz" type="rviz" required="true"
args="-d $(find cartographer\_ros)/configuration\_files/rslidar\_2d.rviz" />
<node name="cartographer\_occupancy\_grid\_node" pkg="cartographer\_ros"
type="cartographer\_occupancy\_grid\_node" args="-resolution 0.05" />
</launch>
zch_rslidar_2d.launch
<launch>
<param name="robot\_description"
textfile="$(find cartographer\_ros)/urdf/my\_backpack\_3d.urdf" />
<node name="robot\_state\_publisher" pkg="robot\_state\_publisher"
type="robot\_state\_publisher" />
</launch>
zch_rslidar_2d.lua
include "map\_builder.lua"
include "trajectory\_builder.lua"
options = {
map_builder = MAP\_BUILDER,
trajectory_builder = TRAJECTORY\_BUILDER,
map_frame = "map",
tracking_frame = "base\_link",
published_frame = "base\_link",
odom_frame = "odom",
provide_odom_frame = true,
publish_frame_projected_to_2d = false,
use_odometry = true,
use_nav_sat = false,
use_landmarks = false,
num_laser_scans = 0,
num_multi_echo_laser_scans = 0,
num_subdivisions_per_laser_scan = 1,
![img](https://img-blog.csdnimg.cn/img_convert/ad8a79cf30dc0ac7216b8ea9d7fcd888.png)
![img](https://img-blog.csdnimg.cn/img_convert/c2ece18a977883f132dc53ad92b72d4a.png)
**网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。**
**[需要这份系统化的资料的朋友,可以添加戳这里获取](https://bbs.csdn.net/topics/618668825)**
**一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!**
1715737718562)]
[外链图片转存中...(img-EbhUTRlK-1715737718563)]
**网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。**
**[需要这份系统化的资料的朋友,可以添加戳这里获取](https://bbs.csdn.net/topics/618668825)**
**一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!**