首页 > 代码库 > 使用ros hector_mapping建地图

使用ros hector_mapping建地图

 

ros中建地图方式有两种:

技术分享

首先1、首先下载hector_slam包到你工作空间的src下
命令:

 

cd ~/catkin/srcgit clone https://github.com/tu-darmstadt-ros-pkg/hector_slam.gitcd ..catkin_make 

在~/catkin_ws/src/hector_slam/hector_slam_launch/launch/新建一个demo.launch

<?xml version="1.0"?><launch> <include file="$(find rplidar_ros)/launch/rplidar.launch"/>  <node pkg="tf" type="static_transform_publisher" name="map_to_odom" args="0.0 0.0 0.0 0 0 0.0 /odom /base_link 10"/>  <node pkg="tf" type="static_transform_publisher" name="base_frame_laser" args="0 0 0 0 0 0 /base_link /laser 10"/>  <!--<node pkg="rviz" type="rviz" name="rviz"    args="-d $(find hector_slam_launch)/rviz_cfg/mapping_demo.rviz"/>-->  <include file="$(find hector_mapping)/launch/mapping_default.launch"/>  <node pkg="rviz" type="rviz" name="rviz" args="-d rviz_cfg.rviz"/>  <include file="$(find hector_geotiff)/launch/geotiff_mapper.launch"/></launch>

 修改~/catkin_ws/src/hector_slam/hector_mapping/launch/mapping_default.launch

<?xml version="1.0"?><launch> <arg name="tf_map_scanmatch_transform_frame_name" default="/scanmatcher_frame"/><arg name="base_frame" default="base_link"/><arg name="odom_frame" default="base_link"/><arg name="pub_map_odom_transform" default="true"/> <arg name="scan_subscriber_queue_size" default="5"/><arg name="scan_topic" default="scan"/><arg name="map_size" default="2048"/>  <node pkg="hector_mapping" type="hector_mapping" name="hector_mapping" output="screen">      <!-- Frame names -->   <param name="map_frame" value="http://www.mamicode.com/map" />  <param name="base_frame" value="http://www.mamicode.com/$(arg base_frame)" />  <param name="odom_frame" value="http://www.mamicode.com/$(arg base_frame)" />       <!-- Tf use -->  <param name="use_tf_scan_transformation" value="http://www.mamicode.com/true"/>   <param name="use_tf_pose_start_estimate" value="http://www.mamicode.com/false"/>   <param name="pub_map_odom_transform" value="http://www.mamicode.com/$(arg pub_map_odom_transform)"/>  <!-- Map size / start point -->   <param name="map_resolution" value="http://www.mamicode.com/0.050"/>    <param name="map_size" value="http://www.mamicode.com/$(arg map_size)"/>    <param name="map_start_x" value="http://www.mamicode.com/0.5"/>    <param name="map_start_y" value="http://www.mamicode.com/0.5" />    <param name="map_multi_res_levels" value="http://www.mamicode.com/2" /> <!-- Map update parameters --> <param name="update_factor_free" value="http://www.mamicode.com/0.4"/>  <param name="update_factor_occupied" value="http://www.mamicode.com/0.7" />       <param name="map_update_distance_thresh" value="http://www.mamicode.com/0.2"/><param name="map_update_angle_thresh" value="http://www.mamicode.com/0.9" /> <param name="laser_z_min_value" value = "http://www.mamicode.com/-1.0" />  <param name="laser_z_max_value" value = "http://www.mamicode.com/1.0" />     <!-- Advertising config -->  <param name="advertise_map_service" value="http://www.mamicode.com/true"/>     <param name="scan_subscriber_queue_size" value="http://www.mamicode.com/$(arg scan_subscriber_queue_size)"/> <param name="scan_topic" value="http://www.mamicode.com/$(arg scan_topic)"/>    <param name="tf_map_scanmatch_transform_frame_name" value="http://www.mamicode.com/$(arg tf_map_scanmatch_transform_frame_name)" /> </node></launch>

 

 

我用的是rplidar激光雷达,主要价格比较便宜

修改rplidar驱动文件
在rplidar_ros/src/node.cpp中找到
nh_private.param<std::string>("frame_id", frame_id, "laser_frame");
将其改成:
nh_private.param<std::string>("frame_id", frame_id, "laser");
编译后运行:
roslaunch hector_slam_launch demo.launch

 

使用ros hector_mapping建地图