hector_slam

repository·noetic-devel·Indexed 20 days ago

https://github.com/tu-darmstadt-ros-pkg/hector_slam

A ROS package providing a SLAM (Simultaneous Localization and Mapping) system that does not require odometry. It includes the hector_mapping node for mapping lifecycle management, hector_geotiff for generating GeoTIFF maps with plugin support, and tools for compressed map transport via the map_to_image_node. The system provides services for map resetting, trajectory tracking via hector_trajectory_server, and diagnostic monitoring through the hector_debug_info topic.

Tokens
3.7K
Snippets
7
Records
19
Agent score
73%

What's inside hector_slam

  1. Use the map_to_image_node for compressed map transport

    noetic-devel

    The map_to_image_node converts occupancy grid maps (nav_msgs/OccupancyGrid) into images (sensor_msgs/Image) using image_transport. This allows for transmitting map data with significantly lower bandwidth by leveraging image compression plugins.

    It provides two types of image outputs:

    1. Full Map: A single image representing the entire occupancy grid.
    2. Tile Map: A localized image centered around the robot's current position, useful for low-bandwidth remote monitoring.

    Required Inputs:

    • map (topic): Subscribes to nav_msgs/OccupancyGrid.
    • pose (topic): Subscribes to geometry_msgs/PoseStamped (required for the tile-based map).

    Outputs:

    • map_image/full (topic): The full map as a MONO8 encoded image.
    • map_image/tile (topic): A localized tile around the robot as a MONO8 encoded image.
  2. Extend GeoTIFF drawing with MapWriterPluginInterface

    noetic-devel

    The geotiff_node supports a plugin system via pluginlib. You can implement the hector_geotiff::MapWriterPluginInterface to draw custom information (like robot trajectories, object models, or other sensor data) onto the generated GeoTIFF map.

    To use a plugin, include its name in the plugins parameter of the geotiff_node as a space-separated string.

  3. Run the hector_mapping ROS node

    noetic-devel

    The hector_mapping node is the primary entrypoint for the Hector SLAM mapping system. It initializes the hector_slam ROS node and instantiates the HectorMappingRos class, which manages the mapping lifecycle and ROS communication. To use this node, you typically run it via a ROS launch file or the command line, ensuring that the necessary sensor data (like laser scans) and odometry (if used) are being published on the expected topics.

    # Example of running the node via rosrun (assuming the package is built and sourced)
    rosrun hector_mapping hector_mapping_node
  4. Configure the GeoTIFF Map Generator node

    noetic-devel

    The geotiff_node generates GeoTIFF maps by consuming occupancy grids. You can configure its behavior using ROS parameters. The node can either call a service to get the map or subscribe to a topic. It also supports periodic saving and plugin-based extensions for drawing additional data on the map.

    ROS Parameters

    ParameterTypeDefaultDescription
    map_file_pathstring.Directory where maps are saved.
    map_file_base_namestring""Base name for the generated files.
    map_file_postfixstring""A postfix added to the filename.
    draw_background_checkerboardbooltrueWhether to draw a checkerboard background.
    draw_free_space_gridbooltrueWhether to draw a grid over free space.
    use_map_topicboolfalseIf true, the node listens to the map topic instead of calling the map service.
    geotiff_save_perioddouble0.0Interval (in seconds) to automatically save the map. Set to 0.0 to disable periodic saving.
    pluginsstring""A space or tab-separated list of MapWriterPluginInterface plugin names to load.

    Filename Construction

    If global parameters are present in the ROS parameter server, they are appended to the filename in the following order:

    1. /competition
    2. /team
    3. /mission
    4. map_file_postfix (local parameter)
  5. Configure the hector_trajectory_server parameters

    noetic-devel

    The hector_trajectory_server node can be configured using the following private ROS parameters to define coordinate frames and update frequencies:

    ParameterTypeDefaultDescription
    target_frame_namestring"map"The frame in which the trajectory is stored and published.
    source_frame_namestring"base_link"The robot's base frame used as the source for pose transformations.
    trajectory_update_ratedouble4.0Frequency (Hz) at which the current robot pose is sampled and added to the trajectory.
    trajectory_publish_ratedouble0.25Frequency (Hz) at which the full nav_msgs/Path is published to the trajectory topic.
  6. Configure Hector SLAM Parameters

    noetic-devel

    The following parameters are used to configure the behavior of the HectorMappingRos node. These are typically set via ROS parameter server or launch files.

    Frame Configuration

    • p_base_frame_: The base frame of the robot.
    • p_map_frame_: The frame representing the map.
    • p_odom_frame_: The odometry frame.

    Topic Configuration

    • p_scan_topic_: The topic to subscribe to for sensor_msgs/LaserScan data.
    • p_sys_msg_topic_: The topic for system messages (std_msgs/String).
    • p_pose_update_topic_: Topic for publishing pose updates.
    • p_twist_update_topic_: Topic for publishing twist updates.
    • p_odometry_publisher_: Topic for publishing odometry.

    Mapping and Resolution

    • p_map_resolution_: The resolution of the occupancy grid map.
    • p_map_size_: The size of the map.
    • p_map_start_x_: Starting X coordinate of the map.
    • p_map_start_y_: Starting Y coordinate of the map.
    • p_map_multi_res_levels_: Number of multi-resolution levels for the map.
    • p_map_pub_period_: The period at which the map is published.

    Scan and Transform Settings

    • p_pub_map_scanmatch_transform_: Whether to publish the scanmatcher pose directly via TF.
    • p_tf_map_scanmatch_transform_frame_name_: The name of the frame for the scanmatcher transform.
    • p_use_tf_scan_transformation_: Whether to use TF for scan transformations.
    • p_use_tf_pose_start_estimate_: Whether to use TF for the initial pose estimate.
    • p_sqr_laser_min_dist_: Squared minimum laser distance.
    • p_sqr_laser_max_dist_: Squared maximum laser distance.
    • p_laser_z_min_value_: Minimum Z value for laser scans.
    • p_laser_z_max_value_: Maximum Z value for laser scans.

    Update Factors

    • p_update_factor_free_: Update factor for free space.
    • p_update_factor_occupied_: Update factor for occupied space.
    • p_map_update_distance_threshold_: Distance threshold for map updates.
    • p_map_update_angle_threshold_: Angle threshold for map updates.
  7. Configure the TrajectoryMapWriter plugin

    noetic-devel

    The TrajectoryMapWriter plugin for hector_geotiff allows you to draw the robot's trajectory onto a GeoTIFF map. It retrieves trajectory data via a ROS service. You can configure the service name used to fetch the trajectory and the RGB color of the drawn path using ROS parameters under the plugin's private namespace.

    Note: The plugin expects a service of type hector_nav_msgs/GetRobotTrajectory to be available.

    <!-- Example ROS parameter configuration -->
    <param name="trajectory_plugin" type="hector_geotiff_plugins/TrajectoryMapWriter">
      <param name="service_name" value="trajectory" />
      <param name="path_color_r" value="120" />
      <param name="path_color_g" value="0" />
      <param name="path_color_b" value="240" />
    </param>
  8. Get recovery info service

    noetic-devel

    The trajectory_recovery_info service is used to find a path segment that leads out of a specific radius from a given pose. This is useful for recovery behaviors when a robot is stuck.

    Service Type: hector_nav_msgs/GetRecoveryInfo

    Request Fields:

    • request_time: The timestamp of the robot pose to evaluate.
    • request_radius: The radius within which the recovery path must exit.

    Response Fields:

    • req_pose: The pose at the requested time.
    • radius_entry_pose: The pose where the trajectory first exited the requested radius.
    • trajectory_radius_entry_pose_to_req_pose: A nav_msgs/Path containing the poses from the radius entry point to the requested pose.
  9. Control Hector SLAM via ROS Services

    noetic-devel

    The HectorMappingRos interface provides several ROS services to control the mapping lifecycle, including resetting the map, restarting the SLAM process, and pausing/resuming scan processing.

    Available Services

    Service NameService TypeDescription
    reset_map_service_std_srvs/TriggerResets the current map.
    restart_hector_service_hector_mapping/ResetMappingRestarts the Hector SLAM process.
    toggle_scan_processing_service_std_srvs/SetBoolPauses or resumes the processing of incoming laser scans.
    dynamicMapServiceServer_nav_msgs/GetMapProvides a service to retrieve the current map data.
  10. Use the hector_map_server services

    noetic-devel

    The hector_map_server node provides several ROS services to interact with the current occupancy grid map. These services allow you to retrieve the full map, calculate distances to obstacles from a specific point, or find a search position based on a target pose and distance.

    Note: Most services will fail (return false) if a map has not yet been received via the map topic.

    ### Available Services
    
    #### 1. Get the current map
    **Service Name:** `map` (Global namespace)
    **Type:** `nav_msgs/GetMap`
    **Description:** Returns the current `nav_msgs/OccupancyGrid` stored by the server.
    
    #### 2. Get distance to obstacle
    **Service Name:** `~get_distance_to_obstacle` (Private namespace)
    **Type:** `hector_nav_msgs/GetDistanceToObstacle`
    **Description:** Calculates the distance from a provided point to the nearest obstacle in the map. The point's frame is used to perform a TF lookup against the map frame.
    
    #### 3. Get search position
    **Service Name:** `~get_search_position` (Private namespace)
    **Type:** `hector_nav_msgs/GetSearchPosition`
    **Description:** Calculates a new pose (`search_pose`) by taking an input pose (`ooi_pose`) and moving it backwards along its own orientation by a specified `distance`.