最近,我參加了航天智慧物流的線上賽,成績還沒出來,我負責的是cartograher建圖部分,我現在總結一下自己的一些學習和遇到的坑,方便大家學習cartographer,
怎么安裝cartograher我就不說了,網上都有詳細的教程,在我的百度網盤里也有現成的包,鏈接:https://pan.baidu.com/s/1IL1rBxCwxqoYnz_jtQ9eyg
提取碼:sirb
大家下下來,直接編譯就可以了,,我想講的是怎么實作cartographer仿真建圖并且保證成功, 當然你需要有學習過ros的一些基礎,
我只寫在仿真環境中的建圖,因為實際建圖是雷達不同,launch檔案的配置不同,如果不會配置可以大家交流,我的手持雷達建圖配置如下:
<launch>
<node pkg="tf" type="static_transform_publisher" name="base_link_to_laser4"
args="0.0 0.0 0.2 0.0 0.0 0.0 /base_link /velodyne 40" />
<include file="$(find my_navigation)/launch/cartographer_demo.launch"/>
<include file="$(find velodyne_pointcloud)/launch/VLP16_points.launch"/>
</launch>
下面是是仿真實作的具體內容,我默認大家是有一個仿真環境的,并且有一輛可移動小車, 如果沒有我已經上傳到百度網盤上了:鏈接:https://pan.baidu.com/s/1rug9U0etBWP2_KboPbww6Q
提取碼:sirb
下載后記得編譯,
It’s show time.
一:我在cartographer_ws/src/cartographer_ros/cartographer_ros/launch/cartographer_demo.launch下創建了cartographer_demo.launch檔案,具體內容如下:
<launch>
<param name="/use_sim_time" value="true" />
<node name="cartographer_node" pkg="cartographer_ros"
type="cartographer_node" args="
-configuration_directory $(find cartographer_ros)/configuration_files
-configuration_basename lidar.lua"
output="screen">
<remap from="scan" to="scan" />
</node>
<!-- cartographer_occupancy_grid_node -->
<node pkg="cartographer_ros" type="cartographer_occupancy_grid_node"
name="cartographer_occupancy_grid_node"
args="-resolution 0.05" />
<node name="rviz" pkg="rviz" type="rviz" required="true"
args="-d $(find cartographer_ros)/configuration_files/demo_2d.rviz" />
</launch>
其實這個檔案下面有很多demo檔案,你可以改來用,你需要注意的是以下幾點:
1.在demo中添加`
<node pkg="cartographer_ros" type="cartographer_occupancy_grid_node"
name="cartographer_occupancy_grid_node"
args="-resolution 0.05" />
這個是實作建圖必不可少的部分,
2.代碼<param name="/use_sim_time" value="true" />在仿真時value 為true,但當你需要實際建圖時,一定要改為false,不然它會報錯,其實就是時間戳的問題,這里我就不過多贅述,
3.我們需要注意代碼
<node name="cartographer_node" pkg="cartographer_ros" type="cartographer_node" args=" -configuration_directory $(find cartographer_ros)/configuration_files -configuration_basename lidar.lua"中lidar.lua,你需要改為自己的lua檔案,不用怕不懂,我下面會對這個lua檔案進行介紹,
二:下面是我的lidar.lua檔案的具體內容,這個檔案至關重要,網上有很多教程配置,大家一定要去看看,值得一提的是每次修改后,你需要重新編譯,因為lua檔案,它呼叫了別的檔案,引數修改后會有一個整體的影響,一些重要代碼的作用我已經標出,
include "map_builder.lua"
include "trajectory_builder.lua"
options = {
map_builder = MAP_BUILDER,
trajectory_builder = TRAJECTORY_BUILDER,
map_frame = "map",
tracking_frame = "base_footprint", #改為自己激光雷達的frame_id,通常情況都是laser
published_frame = "base_footprint", #改為自己激光雷達的frame_id,通常情況都是laser
odom_frame = "odom",
provide_odom_frame = true,
publish_frame_projected_to_2d = false,
use_odometry = true, #是否使用Odom資料在這里決定,改變之后記得編譯
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 = 1.,
fixed_frame_pose_sampling_ratio = 1.,
imu_sampling_ratio = 1.,
landmarks_sampling_ratio = 1.,
}
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
use_pose_extrapolator = on
TRAJECTORY_BUILDER.collate_landmarks = on
POSE_GRAPH.optimization_problem.huber_scale = 1e2
POSE_GRAPH.optimize_every_n_nodes = 35
POSE_GRAPH.constraint_builder.min_score = 0.65
return options
如果你下載的是我的包,首先對兩個作業空間間進行編譯,
在 cartographer_ws 下,執行 catkin_make_isolated --install --use-ninja
在 new_ws 下,執行 catkin_make
在.bashrc 檔案底部加入:source ~/cartographer_ws/install_isolated/setup.bash 和
source ~/new_ws/devel/setup.bash
下面的三個launch檔案都在new_ws下:
運行 1:roslaunch my_gazebo robot_laser_gazebo.launch
2:rosrun teleop_twist_keyboard teleop_twist_keyboard.py
3:roslaunch my_navigation cartographer_demo.launch
如果第二步不能成功,運行 sudo apt-get install ros-melodic-teleop-twist-keyboard
上述作業完成后就能移動鍵盤進行仿真建圖啦,
下面附上建圖效果:


轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/275089.html
標籤:其他
