6. ROS1-Mapping Navigation Lesson

6.1 Mapping

6.1.1 SLAM Mapping Principle

  • Introduction to SLAM

SLAM stands for Simultaneous Localization and Mapping.

Localization involves determining the pose of a robot in a coordinate system,, The origin of orientation of the coordinate system can be obtained from the first keyframe, existing global maps, landmarks or GPS data.

Mapping involves creating a map of the surrounding environment perceived by the robot. The basic geometric elements of the map are points. The main purpose of the map is for localization and navigation. Navigation can be divided into guidance and control. Guidance includes global planning and local planning, while control involves controlling the robot’s motion after the planning is done.

  • SLAM Mapping Principle

SLAM mapping is composed of following three processes:

Pre-processing: optimize the raw point cloud data from Lidar by eliminating some defective data or filtering.

Generally, the surrounding environmental information obtained by a Lidar is called as “point cloud”, which represents a portion of the environment that the robot perceive. The collected object information is presented as a series of scattered data information with exact angles and distances.

Matching: the point cloud data of this current local environment is matched by finding the corresponding position on the established map.

The SLAM system calculates the distance and pose changes of Lidar’s relative motion by matching and comparing point clouds at different moments. This process completes the self-localization of the robot.

Map fusion: the new round of data from Lidar is merged into the original map to complete the map update.

With lidar as a signal source, pulse laser emitted by the Lidar’s emitter hits the surrounding obstacles, causing scattering. A portion of the light waves reflects back to the Lidar’s receiver, and by utilizing the principle of laser ranging, the distance from the Lidar to the target point can be calculated. By continuously scanning the target object with pulse lasers, data of all target points on the object can be obtained. After performing imaging processing on this data, an accurate three-dimensional image can be generated.

  • Notes

  1. Begin the mapping process by positioning the robot in front of a straight wall or within an enclosed box. This enhances the Lidar’s capacity to capture a higher density of scanning points.

  2. Initiate a 360-degree scan of the environment using the Lidar to ensure a comprehensive survey of the surroundings. This step is crucial to guarantee the accuracy and completeness of the resulting map.

  3. For larger areas, it’s recommended to complete a full mapping loop before focusing on scanning smaller environmental details. This approach enhances the overall efficiency and precision of the mapping process.

  • Judge Mapping Result

Finally, assess the robot’s navigation process against the following criteria once the mapping is complete:

  1. Ensure that the edges of obstacles within the map are distinctly defined.

  2. Check for any disparities between the map and the actual environment, such as the presence of closed loops or inconsistencies.

  3. Verify the absence of gray areas within the robot’s motion area, indicating areas that haven’t been adequately scanned.

  4. Confirm that the map doesn’t incorporate obstacles that won’t exist during subsequent localization.

  5. Validate the map’s coverage of the entire extent of the robot’s motion area.

  • Mapping Feature Pack

The ‘hiwonder_slam’ robot mapping package comes with pre-installed Gmapping, Hector, Cartographer, Karto, Explore_Lite, Frontier, and RRT mapping algorithms. Activation of different mapping algorithms can be done through the ‘slam.launch’ file within this package.

During startup, the execution of the ‘bringup.launch’ file initializes nodes for the depth camera, robot base, joystick, mobile app, and other components. Subsequently, it determines the suitable launch file for the selected mapping algorithm based on the specified parameters.

<?xml version="1.0"?>
<launch>
    <arg name="sim"         default="false"/>
    <arg name="app"         default="false"/>
    <arg     if="$(arg app)" name="robot_name"  default="/"/>
    <arg unless="$(arg app)" name="robot_name"  default="$(env HOST)"/>
    <arg     if="$(arg app)" name="master_name" default="/"/>
    <arg unless="$(arg app)" name="master_name" default="$(env MASTER)"/>

    <!--建图方法选择-->
    <arg name="slam_methods" default="gmapping" doc="slam type 
        [gmapping, cartographer, hector, karto, frontier, explore, rrt_exploration, rtabmap]"/>

    <arg name="gmapping"        default="gmapping"/>
    <arg name="cartographer"    default="cartographer"/>
    <arg name="hector"          default="hector"/>
    <arg name="karto"           default="karto"/>
    <arg name="frontier"        default="frontier"/>
    <arg name="explore"         default="explore"/>
    <arg name="rrt_exploration" default="rrt_exploration"/>
    <arg name="rtabmap"         default="rtabmap"/>

    <include file="$(find hiwonder_slam)/launch/include/hiwonder_robot.launch">
        <arg name="sim"         value="$(arg sim)"/>
        <arg name="app"         value="$(arg app)"/>
        <arg name="robot_name"  value="$(arg robot_name)"/>
        <arg name="master_name" value="$(arg master_name)"/>
        <arg if="$(eval slam_methods == hector)" name="enable_odom"    value="false"/>
    </include>

    <include file="$(find hiwonder_slam)/launch/include/slam_base.launch">
        <arg name="sim"             value="$(arg sim)"/>
        <arg name="slam_methods"    value="$(arg slam_methods)"/>
        <arg name="robot_name"      value="$(arg robot_name)"/>
    </include>
</launch>

1. Intrinsic Structure of Feature Pack

The above diagram illustrates the internal file structure of the mapping package. The corresponding functionalities are organized as follows:

  1. config: This folder contains algorithm parameter configuration files.

  2. launch: This folder includes launch files for various package functionalities.

  3. maps: Map message files are saved in this folder.

  4. rviz: Simulation maps and robot model files are stored in this folder.

  5. src: Algorithm source files are called from this folder.

  6. CMakeLists.txt: This file serves as a compilation dependency.

  7. package.xml: This file provides a description of the package.

2. Feature Pack Description

  1. Config folder contains the configuration files of the following mapping algorithms, including cartographer, frontier, Gmapping, etc.

For instance, when we examine a section of the configuration file for the Cartographer mapping algorithm, it appears as follows:

master_name = os.getenv("MASTER")
robot_name = os.getenv("HOST")
prefix = os.getenv("prefix")
MAP_FRAME = "map"
ODOM_FRAME = "odom"
BASE_FRAME = "base_footprint"
if(prefix ~= "/")
then
    MAP_FRAME = master_name .. "/" .. MAP_FRAME
    ODOM_FRAME = robot_name .. "/" .. ODOM_FRAME
    BASE_FRAME = robot_name .. "/" .. BASE_FRAME
end

To get a more detailed introduction to this section, you can proceed to study the following content.

  1. The ‘launch’ folder is the directory where various functionalities within the package are initiated, including launch files for different mapping algorithms.

  1. The ‘maps’ folder is intended for storing map message files. To do this, follow the two commands below in the future:

Navigate to the ‘maps’ folder using the command “roscd hiwonder_slam/maps

Execute the command “rosrun map_server map_saver map:=/robot_1/map -f map_01,” where “robot_1” indicates the robot’s name and “map_01” is the map’s name.

This process will save pertinent map details in the ‘maps’ folder, making it easier to make modifications and subsequently invoke navigation functionalities.

  1. The ‘rviz’ folder is designated for storing simulation maps and robot model files. Save the simulation models needed for different mapping algorithms in this folder. This facilitates their later use when launching RVIZ to inspect mapping results

  2. The ‘src’ folder serves as the directory for calling algorithm source files.

    init_pose.py: This script is utilized for initializing the robot’s pose, establishing its current state.

    map_save.py: This script is employed to save map information.

    rrt_map_save.py: Specifically designed for the autonomous mapping algorithm using the RRT algorithm, this script is used to save map information.

  3. Ultimately, ‘CMakeLists.txt’ serves as the dependency file for package compilation, and ‘package.xml’ is employed to specify package version information and load specific function dependencies.

  • Differences in the Usage of Various Mapping Algorithms

The table below offers a concise summary of the distinctions among the mapping algorithms outlined in this manual, acting as a convenient reference for users. Detailed explanations for each algorithm are available in the subsequent sections. Users can choose the most suitable mapping algorithm according to their specific requirements and environmental conditions.

Algorithm Accuracy Immediacy Computational complexity Requirements Applicable scenario
Gmapping High accuracy Real-time Medium The map's features and environment demand a heightened level of perceptibility Real-time mapping and precision are essential for small to medium-sized indoor environments
Hector Relatively accurate Real-time Low There is a high requirement for the update rate of Lidar data to meet the demands of fast-moving robots Fast-moving robots and environments with motion blur conditions
Cartographer High Real-time/ offline High There is a high requirement for the quality and accuracy of sensor data. It necessitates high-quality Lidar and other sensor data, with precision demanded in sensor calibration and alignment Applications requiring high-precision mapping and localization, suitable for both indoor and outdoor environments
Karto Relatively accurate Real-time Medium A higher demand is placed on the features and structures within the environment to achieve accurate scan matching and mapping. Additionally, it has lower requirements for computational resources, making it suitable for platforms with limited resources Small-scale environments, scenarios with limited computational resources, or devices with lower performance
Explore_Lite Low Real-time Low The requirements for mapping precision are relatively low. The emphasis is on discovering new areas and planning paths to these areas The exploration task of autonomous robots in unknown environments
Frontier Exploration Low Real-time Low Mapping precision requirements are relatively modest. The primary focus lies in discovering new areas and planning paths to these regions The exploration task of autonomous robots in unknown environments
RRT Hinges on the quality of the search process Real-time/ offline High While the demands for obstacles and constraints in the environment are relatively low, ensuring viable paths requires a sufficient number of samples and search steps. In complex environments, it may be necessary to increase the number of sampling points and search iterations to enhance accuracy Environments that necessitate path planning, particularly in irregular or uncertain conditions

6.1.2 Gmapping Mapping Algorithm

  • Gmapping Description

Gmapping is an open-source SLAM algorithm based on the Rao-Blackwellized particle filter (RBPF) algorithm. It separates the processes of localization and mapping by initially using a particle filter for localization and then performing scan matching between particles and the existing map. The algorithm continuously corrects odometry errors and adds new scans to the map.

Key Improvements in Gmapping:

Enhanced proposal distribution and selective resampling are introduced to improve the RBPF algorithm.

Advantages of Gmapping:

  1. Real-time construction of indoor maps with a small computational load and high accuracy for small-scale scenes.

  2. Lower requirements for laser frequency and higher robustness compared to Hector.

  3. When building maps for small scenes, Gmapping requires fewer particles and does not need loop closure detection, resulting in lower computational requirements than Cartographer with only a slight decrease in accuracy.

  4. Effective use of wheel odometry information, reducing laser frequency demands.

Drawbacks of Gmapping:

  1. Increasing scene size requires more particles, leading to higher memory and computational requirements.

  2. Not suitable for constructing large-scale maps due to memory and computational limitations.

  3. Lack of loop closure detection may cause map misalignment during loop closure.

  4. Increasing the number of particles to close the map comes at the cost of higher computational load and memory usage.

  5. Practical usage shows errors even with maps of a few thousand square meters.

Comparison with Cartographer:

  1. Gmapping and Cartographer represent two different SLAM approaches—one based on the filtering framework and the other based on the optimization framework.

  2. Gmapping sacrifices space complexity to ensure time complexity, making it unsuitable for constructing large-scale maps.

  3. For instance, constructing a 200x200 meter environmental map with a grid resolution of 5 centimeters and one byte of memory per grid would require 16MB for a single particle carrying the map.

  4. The computational load in Cartographer is higher, and ordinary laptops may struggle to generate good maps due to complex matrix operations, which is why Google developed the ceres library.

  • Mapping Operation Steps

Note

Note: the input command should be case sensitive, and the keywords can be complemented by “Tab” key.

1. Enable Service

  1. Start the robot, and access the robot system desktop using NoMachine.

  2. Double click to open the command line terminal.

  3. Execute the command “sudo systemctl stop start_app_node.service” and press Enter to disable app auto-start service.

    sudo systemctl stop start_app_node.service
    
  4. Open a new terminal, and execute the command “roslaunch hiwonder_slam slam.launch slam_methods:=gmapping” to enable Gmapping mapping node.

    roslaunch hiwonder_slam slam.launch slam_methods:=gmapping
    

The appearance of the following message indicates a successful startup.

These pieces of information provide feedback on key steps and parameters during the mapping process, where m_count 1 indicates that 1 frame of data has been processed, meaning 1 scan of laser data has been handled.

Average Scan Matching Score=212.352: This represents an average scan matching score of 212.352. The scan matching score measures the degree of alignment between each frame of laser data and the map. A lower score indicates better alignment.

neff=100: This signifies that the calculated number of effective particles is 100. The effective particle count (neff) is the number of particles in the particle filter with higher weights, used to assess the accuracy and diversity of the filter.

Registering Scans:Done: This denotes the completion of the registration process for laser scan data. Registration involves matching the laser scan data with the map to estimate the robot’s pose.

update frame 158: This indicates the update of the 158th frame of data. After processing each frame of laser data, the map and particle set are updated.

update ld=0.010789 ad=0.0192138: These values represent the updated linear displacement and angular displacement, which are 0.010789 and 0.0192138, respectively. These values indicate the displacement of the robot in the current frame of data.

Laser Pose= 0.090148 0.0124257 -0.0278112: This represents the pose of the laser, where 0.090148 is the x-coordinate, 0.0124257 is the y-coordinate, and -0.0278112 is the orientation angle.

  1. Open a new command-line terminal, and enter the command ‘roslaunch hiwonder_slam rviz_slam.launch slam_methods:=gmapping’ to initiate the model viewing tool.

    roslaunch hiwonder_slam rviz_slam.launch slam_methods:=gmapping
    

2. Start Mapping

Take keyboard control as example. If you want to control the robot using wireless handle, please refer to the tutorial saved in ‘1. JetRover User Manual/1.7 Wireless Handle Control’.

  1. Open a new command-line terminal, and execute the command ‘roslaunch hiwonder_peripherals teleop_key_control.launch’ to enable the keyboard control node.

    roslaunch hiwonder_peripherals teleop_key_control.launch
    

When the following prompt occurs, it means the keyboard control service is enabled successfully.

  1. Control the robot to move around to map the whole environment by pressing the corresponding keys.

Key Robot’s Action
W Go forward (Press briefly)
S Go backward (Press briefly)
A Turn left (Long press)
D Turn right (Long press)

When controlling the robot’s movement with the keyboard for mapping, it is recommended to lower the robot’s speed. This reduces odometry errors, leading to improved mapping results. As the robot moves, the map in RVIZ will continually grow until the entire environmental map is constructed.

3. Save the Map

  1. Open a new terminal and input the command “roscd hiwonder_slam/maps” and press Enter to enter the folder where the map is stored.

    roscd hiwonder_slam/maps
    
  1. Execute the command ‘rosrun map_server map_saver map:=/robot_1/map -f map_01’ and press Enter to save the map.

robot_1” refers to the robot name, and “map_01” in the command is the name of the map, and you can rename it. If the following prompts occur, the map is kept successfully.

  1. If you want to stop running the program, you can press “Ctrl+C”.

Once you finish experiencing this function, you need to restart the app service through command or restarting the robot. Execute this command “sudo systemctl restart start_app_node.service” to restart the app service. When you hear a beeping sound from the robot, it means that the service is restarted successfully.

sudo systemctl restart start_app_node.service

4. Optimize Mapping Result

For enhanced mapping precision, consider optimizing the odometer settings. The robot’s mapping process heavily relies on the Lidar, and the odometer’s functionality is closely tied to Lidar operations.

The calibrated IMU (Inertial Measurement Unit) data has been successfully integrated into the robot’s system, enabling both mapping and navigation. However, to achieve even greater accuracy, it’s advisable to calibrate the IMU. Detailed instructions on how to perform IMU calibration are available in “3.ROS1-Chassis Motion Control Lesson\3.2 Motion Control\ 3.2.1 IMU, Linear Velocity and Angular Velocity Calibration”.

  • Parameter Explanation

The parameter file can be found at this path: hiwonder_slam\config\gmapping_params.yaml

maxUrange: 5.0            # Capture laser range
maxRange: 12.0            # Laser range
sigma: 0.05               # Standard deviation
kernelSize: 1             # kernel size
lstep: 0.05               # Linear step size 
astep: 0.05               # Angle step size
iterations: 1             # Number of iterations
lsigma: 0.075             # Laser standard deviation
ogain: 3.0                # Gain value
lskip: 0                  # Process all laser. If the computation pressure is huge, the parameter can be set to 1
minimumScore: 30          # minimum matching score
srr: 0.01                 # Error parameters of the motion model
srt: 0.02                 # Error parameters of the motion model
str: 0.01                 # Error parameters of the motion model
stt: 0.02                 # Error parameters of the motion model
linearUpdate: 0.01        # Conduct a single scan when the robot moves a distance in a straight line
angularUpdate: 0.1        # Perform a single scan when the robot rotates by this angle
temporalUpdate: -1.0      # Update time
resampleThreshold: 0.5    # resample threshold 
particles: 100            # number of particle
xmin: -5.0                # minimum X-axis value
ymin: -5.0                # minimum Y-axis value
xmax: 5.0                 # Maximum X-axis value 
ymax: 5.0                 # Maximum Y-axis value
delta: 0.025              # Map resolution
llsamplerange: 0.01       # Linear sampling range
llsamplestep: 0.01        # Linear sample step size
lasamplerange: 0.005      # Sample angle range
lasamplestep: 0.005       # Sample angle step size

To access the detailed tutorials, please refer to this link:http://wiki.ros.org/gmapping

  • Launch File Analysis

1. Path

According to the game, the main files involved are as follows:

  1. slam.launch: Selects the mapping method (Location: /ros_ws/src/hiwonder_slam/launch/slam.launch)

  2. slam_base.launch: Basic topic configuration and startup for mapping functionalities (Location: /ros_ws/src/hiwonder_slam/launch/include/slam_base.launch)

  3. gmapping.launch: Specific topic and parameter configuration for the mapping method (Location: hiwonder_slam/launch/include/gmapping.launch)

2. Structure

The file structure is as below:

Reviewing the document structure, the focus is on selecting mapping methods, initiating mapping functionalities, configuring relevant topics, and adjusting mapping method parameters. For detailed syntax guidelines, please refer to the ‘14.ROS Basics Lesson’.

3. Select Mapping Method

    <arg name="slam_methods" default="gmapping" doc="slam type 
        [gmapping, cartographer, hector, karto, frontier, explore, rrt_exploration, rtabmap]"/>

    <arg name="gmapping"        default="gmapping"/>
    <arg name="cartographer"    default="cartographer"/>
    <arg name="hector"          default="hector"/>
    <arg name="karto"           default="karto"/>
    <arg name="frontier"        default="frontier"/>
    <arg name="explore"         default="explore"/>
    <arg name="rrt_exploration" default="rrt_exploration"/>
    <arg name="rtabmap"         default="rtabmap"/>

Before mapping, it is necessary to choose a mapping method, as shown in the diagram above:

The slam_methods parameter represents the mapping method, with the default value being ‘gmapping.’ The available mapping methods include:

Manual mapping: gmapping, cartographer, hector and karto

Autonomous mapping: frontier and explorerrt_exploration

3D mapping: rtabmap

If using the ‘gmapping’ mapping method, the command line in the terminal when executing this launch file would be:

roslaunch hiwonder_slam slam.launch slam_methods:=gmapping

Here, slam_methods:=[mapping method name] can be modified according to the desired mapping method, for example: slam_methods:=karto.

Based on the current game, the recommended mapping method to choose is slam_methods:= gmapping.

4. Initiate Mapping Function and Related Topic Configuration

    <include file="$(find hiwonder_slam)/launch/include/slam_base.launch">
        <arg name="sim"             value="$(arg sim)"/>
        <arg name="slam_methods"    value="$(arg slam_methods)"/>
        <arg name="robot_name"      value="$(arg robot_name)"/>
    </include>

After choosing the mapping method (slam_methods), the subsequent step involves initiating the mapping functionality and configuring relevant topic names through the use of slam_base.launch. In the provided diagram, <sim> signifies whether simulation is utilized. In this context, it refers to the simulation parameter (sim), which defaults to false, indicating that the node simulation is inactive. <slam_methods> denotes the selected mapping method, set as “gmapping” for this mapping session. <robot_name> specifies the node name of the robot.

For an in-depth examination of the contents of the slam_base.launch file, you can consult the “slam_base.launch Program Analysis”.

5. Mapping Method Parameter Configuration

        <group if="$(eval slam_methods == 'gmapping')">
            <include file="$(find hiwonder_slam)/launch/include/$(arg slam_methods).launch">
                <arg name="scan"        value="$(arg scan_topic)"/>
                <arg name="base_frame"  value="$(arg base_frame)"/>
                <arg name="odom_frame"  value="$(arg odom_frame)"/>
                <arg name="map_frame"   value="$(arg map_frame)"/>
            </include>

In the concurrently executed slam_base.launch file, as depicted above, it includes launch files specific to the selected mapping method. If “gmapping” is the chosen mapping method, it is crucial to focus on the gmapping.launch file for configuring mapping method parameters (located at hiwonder_slam/launch/include/gmapping.launch).

The following provides an overview of the essential contents within the primary startup file, gmapping.launch:

(1) Topic Parameter Configuration

    <!-- Arguments -->
    <arg name="scan"        default="scan"/>
    <arg name="base_frame"  default="base_footprint"/>
    <arg name="odom_frame"  default="odom"/>
    <arg name="map_frame"   default="map"/>

The image above displays configurations for some mapping method topic parameters:

<scan> represents the Lidar scan topic.

<base_frame> denotes the topic name for the robot’s polar coordinate system, set as base_footprint.

<odom_frame> indicates the topic name for odometry, configured as odom.

<map_frame> specifies the topic name for the map, set as map.

After initiating the game, you can use rostopic list to view these configurations.

(2) Basic Parameter Configuration File

    <node pkg="gmapping" type="slam_gmapping" name="hiwonder_slam_gmapping" output="screen">
        <param name="base_frame"    value="$(arg base_frame)"/>
        <param name="odom_frame"    value="$(arg odom_frame)"/>
        <param name="map_frame"     value="$(arg map_frame)"/>
        <remap from="/scan"         to="$(arg scan)"/>
        <rosparam command="load"    file="$(find hiwonder_slam)/config/gmapping_params.yaml" />
    </node>

In the image above, in addition to supplying certain fundamental topics to the gmapping package, there is a corresponding configuration file named gmapping_params.yaml. This file, housing essential parameters, can be found at the path hiwonder_slam/config/gmapping_params.yaml:

map_update_interval: 0.2  # 地图更新速度s, 数值越低地图更新频率越快,但是需要更大的计算负载(map update speed s. The lower the value, the higher the frequency. But larger computational load is required.)
maxUrange: 5.0            # 截取激光范围(intercept laser range)
maxRange: 12.0            # 激光范围(laser range)
sigma: 0.05                
kernelSize: 1
lstep: 0.05
astep: 0.05
iterations: 1
lsigma: 0.075
ogain: 3.0
lskip: 0                  # 为0,表示所有的激光都处理,尽可能为零,如果计算压力过大,可以改成1(set as 0 which means that all laser will be processed. If the computational pressure is overwhelming, you can change it as 1)
minimumScore: 30          # 衡量扫描匹配效果的分数。当大场景中仪器的扫描范围小的时候(5m)可以避免位姿估计跳动太大。也叫最小匹配得分,(score that measure scan matching performance. Narrow scan range in large scene can protect pose estimation from changing rapidly. It is also called minimum matching score)
                          # 它决定了你对激光的一个置信度,越高说明你对激光匹配算法的要求越高,激光的匹配也越容易失败而转去使用里程计数据,(It determines the confidence of laser. The higher the value, the stricter the requirements on laser matching algorithm. And laser matching is also more likely to fail and switch to odometer data)
                          # 而设的太低又会使地图中出现大量噪声(Too low value also results in large amount of noise in the map)

Parameter configuration file segment 1

The following are some key parameters from the gmapping_params.yaml file. Important considerations for these parameters include:

Name Function
map_update_interval Map update rate, measured in seconds (s). Generally, a smaller value increases computational demand
maxUrange Maximum detectable range, representing the extent reachable by laser beams
maxRange Maximum range of the sensor. If there are no obstacles within this range, it should be depicted as free space on the map
sigma Matching method for endpoint matching
lstep Translation optimization step size
astep Rotation optimization step size
lsigma Laser standard deviation for scan matching probability
minimumScore Avoid using a limited-distance laser scanner in large open spaces to achieve optimal matching results
srr: 0.01
srt: 0.02
str: 0.01
stt: 0.02

While the robot is in motion and rotation, it’s crucial to take into account the previously mentioned parameters in association with the mapping method:

Name Function
srr Translation odometer error as a translation function (in radians)
srt Translation odometer error as a rotation function (in radians)
str Rotation odometer error as a translation function (in degrees)
stt Rotation odometer error as a rotation function (in degrees)

Note

Note: It is recommended to maintain the default settings for the above parameters. Modifying them independently is not advised, as it may impact the effectiveness of the game!!!

6.1.3 Hector Mapping Algorithm

  • Hector Description

Hector Slam employs the Gauss-Newton method to tackle the scan-matching problem, demanding precise sensor capabilities. One notable advantage of Hector Slam is its independence from odometry, enabling mapping feasibility in uneven terrains for both aerial drones and ground vehicles. It optimizes laser beam arrays using an existing map, estimates the representation of laser points in the map, and calculates the probability of occupied grids. The Gauss-Newton method resolves the scan-matching problem, determining the rigid transformation (x, y, theta) for the mapped laser point set onto the existing map. To prevent local minima and achieve global optimality, Hector Slam utilizes a multi-resolution map. In navigation, the state estimation incorporates an Inertial Measurement Unit (IMU) through Extended Kalman Filtering (EKF).

Despite its strengths, Hector Slam comes with notable limitations. It necessitates a high update frequency and low Lidar measurement noise. Therefore, maintaining a relatively low robot speed is crucial during mapping to achieve optimal results, leading to the absence of loop closure. Moreover, when odometer data is highly accurate, it struggles to effectively utilize odometry information. To address Hector Slam’s high Lidar frequency requirements, Tuck Robotics, in collaboration with Slamtec, introduces the RPLidarA1-TK version. This version elevates the actual data frequency of the widely-used A1 Lidar from 5.5Hz to 15Hz, significantly enhancing the effectiveness of mapping algorithms like Hector.

The algorithmic workflow of Hector is depicted in the following diagram:

The diagram not only outlines the algorithmic flow for Hector SLAM but also provides a structural overview of the Hector source code. In the future, individuals interested in studying the source code of the Hector SLAM algorithm can use the diagram’s structure as a guide for code analysis and learning.

  1. Related source code and WIKI links for HectorSLAM:

  2. Hector Mapping ROS Wiki: http://wiki.ros.org/hector_mapping

  3. Hector_slam software package: https://github.com/tu-darmstadt-ros-pkg/hector_slam

  • Mapping Operation Steps

Note

Note: the input command should be case sensitive, and the keywords can be complemented using “Tab” key.

1. Enable Service

  1. Start the robot, and access the robot system desktop using NoMachine.

  2. Double click to open the command line terminal.

  3. Execute the command “sudo systemctl stop start_app_node.service” and press Enter to disable app auto-start service.

    sudo systemctl stop start_app_node.service
    
  4. Open a new terminal, and execute the command “roslaunch hiwonder_slam slam.launch slam_methods:=hector” to enable hector mapping node.

    roslaunch hiwonder_slam slam.launch slam_methods:=hector
    
  5. Open a new command-line terminal window and execute the command ‘roslaunch hiwonder_slam rviz_slam.launch slam_methods:=hector’ to launch the model viewing software.

    roslaunch hiwonder_slam rviz_slam.launch slam_methods:=hector
    

2. Start Mapping

Take keyboard control as example. If you want to control the robot using wireless handle, please refer to the tutorial saved in ‘6. ROS1-Mapping Navigation Lesson’.

  1. Open a new command-line terminal, and execute the command ‘roslaunch hiwonder_peripherals teleop_key_control.launch’ to enable the keyboard control node.

    roslaunch hiwonder_peripherals teleop_key_control.launch
    

When the following prompt occurs, it means the keyboard control service is enabled successfully.

  1. Control the robot to move around to map the whole environment by pressing the corresponding keys.

Key Robot’s Action
W Go forward (Press briefly)
S Go backward (Press briefly)
A Turn left (Long press)
D Turn right (Long press)

3. Save the Map

  1. Open a new terminal and input the command “roscd hiwonder_slam/maps” and press Enter to enter the folder where the map is stored.

    roscd hiwonder_slam/maps
    
  2. Execute the command ‘rosrun map_server map_saver map:=/robot_1/map -f map_01’ and press Enter to save the map.

    rosrun map_server map_saver map:=/robot_1/map -f map_01
    

The term “robot_1” in the command represents the robot name, while “map_01” designates the map name. Users can rename them according to their preferences. The appearance of the following prompt confirms the successful saving of the map.

  1. If you want to stop running the program, you can press “Ctrl+C”.

  2. To enable the app service, execute the command ‘sudo systemctl start start_app_node.service’.

    sudo systemctl start start_app_node.service
    

Once you finish experiencing this function, you need to restart the app service through command or restarting the robot. Execute this command “sudo systemctl restart start_app_node.service” to restart the app service. When you hear a beeping sound from the robot, it means that the service is restarted successfully.

sudo systemctl restart start_app_node.service

4. Optimize Program Outcome

For enhanced mapping precision, consider optimizing the odometer settings. The robot’s mapping process heavily relies on the Lidar, and the odometer’s functionality is closely tied to Lidar operations.

The calibrated IMU (Inertial Measurement Unit) data has been successfully integrated into the robot’s system, enabling both mapping and navigation. However, to achieve even greater accuracy, it’s advisable to calibrate the IMU. Detailed instructions on how to perform IMU calibration are available in “3 ROS1-Chassis Motion Control Lesson\ 3.2 Motion Control\ 3.2.1 IMU, Linear Velocity and Angular Velocity Calibration”.

  • Parameter Description

The parameters for the Hector mapping algorithm are defined in the launch file. For a detailed analysis of this aspect, please refer to Section Launch File Analysis.

  • Launch File Analysis

1. Path

According to the game, the main files involved are as follows:

  1. slam.launch: Selects the mapping method (Location: /ros_ws/src/hiwonder_slam/launch/slam.lauch)

  2. slam_base.launch: Basic topic configuration and startup for mapping functionalities (Location: /ros_ws/src/hiwonder_slam/launch/include/slam_base.launch)

  3. hector.launch: Specific topic and parameter configuration for the mapping method (Location:hiwonder_slam/launch/include/hector.launch)

2. Structure

The file structure is as below:

Reviewing the document structure, the focus is on selecting mapping methods, initiating mapping functionalities, configuring relevant topics, and adjusting mapping method parameters. For detailed syntax guidelines, please refer to the ‘14.ROS Basics Lesson’.

3. Select Mapping Method

    <arg name="slam_methods" default="gmapping" doc="slam type 
        [gmapping, cartographer, hector, karto, frontier, explore, rrt_exploration, rtabmap]"/>

    <arg name="gmapping"        default="gmapping"/>
    <arg name="cartographer"    default="cartographer"/>
    <arg name="hector"          default="hector"/>
    <arg name="karto"           default="karto"/>
    <arg name="frontier"        default="frontier"/>
    <arg name="explore"         default="explore"/>
    <arg name="rrt_exploration" default="rrt_exploration"/>
    <arg name="rtabmap"         default="rtabmap"/>

Before mapping, it is necessary to choose a mapping method, as shown in the diagram above:

The slam_methods parameter represents the mapping method, with the default value being ‘gmapping.’ The available mapping methods include:

Manual mapping: gmapping, cartographer, hector and karto

Autonomous mapping: frontier and explorerrt_exploration

3D mapping: rtabmap

If using the ‘gmapping’ mapping method, the command line in the terminal when executing this launch file would be:

roslaunch hiwonder_slam slam.launch slam_methods:=gmapping

Here, slam_methods:=[mapping method name] can be modified according to the desired mapping method, for example: slam_methods:=karto.

Based on the current game, the recommended mapping method to choose is slam_methods:= hector.

4. Initiate Mapping Function and Related Topic Configuration

    <include file="$(find hiwonder_slam)/launch/include/slam_base.launch">
        <arg name="sim"             value="$(arg sim)"/>
        <arg name="slam_methods"    value="$(arg slam_methods)"/>
        <arg name="robot_name"      value="$(arg robot_name)"/>
    </include>

After choosing the mapping method (slam_methods), the subsequent step involves initiating the mapping functionality and configuring relevant topic names through the use of slam_base.launch. In the provided diagram, <sim> signifies whether simulation is utilized. In this context, it refers to the simulation parameter (sim), which defaults to false, indicating that the node simulation is inactive. <slam_methods> denotes the selected mapping method, set as “hector” for this mapping session. <robot_name> specifies the node name of the robot.

For a detailed examination of the contents of the slam_base.launch file, you can consult the “slam_base.launch Program Analysis”.

5. Mapping Method Parameter Configuration

        <group if="$(eval slam_methods == 'hector')">
            <include file="$(find hiwonder_slam)/launch/include/$(arg slam_methods).launch">
                <arg name="scan_topic"  value="$(arg scan_topic)"/>
                <arg name="map_frame"   value="$(arg map_frame)"/>
                <arg name="base_frame"  value="$(arg base_frame)"/>
                <arg name="odom_frame"  value="$(arg base_frame)"/>
            </include>
          </group>

In the concurrently executed slam_base.launch file, as depicted above, it includes launch files specific to the selected mapping method. If “hector” is the chosen mapping method, it is crucial to focus on the hector.launch file for configuring mapping method parameters (located at hiwonder_slam/launch/include/hector.launch).

The following provides an overview of the essential contents within the primary startup file, hector.launch:

(1) Topic Parameter Configuration

    <arg name="tf_map_scanmatch_transform_frame_name" default="scanmatch_frame"/>
    <arg name="base_frame"                  default="base_footprint"/>
    <arg name="odom_frame"                  default="odom"/>
    <arg name="map_frame"                   default="map_frame"/>
    <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="600"/>

<tf_map__scanmath_transform_frame_name> represents the name of the topic for transforming coordinates between the map coordinate system and Lidar coordinate system, set to scanmath_frame.

<base_frame> denotes the topic name for the robot’s polar coordinate system, set to base_footprint.

<odom_frame> refers to the topic name for the odometer, set to odom.

<map_frame> indicates the topic name for the map, set to map.

After initiating the game, you can observe these configurations using the rostopic list command.

(2) Basic Parameter Configuration

In contrast to the gmapping mapping method, the hector mapping method directly configures parameters within the hector.launch file rather than utilizing a yaml file. The primary content of the hector mapping parameter configuration is outlined below:

        <!-- Frame names -->
        <param name="map_frame"     value="$(arg map_frame)" />
        <param name="base_frame"    value="$(arg base_frame)" />
        <param name="odom_frame"    value="$(arg odom_frame)" />

        <!-- Tf use -->
        <param name="use_tf_scan_transformation"    value="true"/>
        <param name="use_tf_pose_start_estimate"    value="false"/>
        <param name="pub_map_scanmatch_transform"   value="true"/>
        <param name="pub_map_odom_transform"        value="$(arg pub_map_odom_transform)"/>

The image above illustrates the setting of topic names for the relevant coordinate system and the logical configuration of tf coordinate transformations. Notably, this mapping method incorporates tf coordinate transformation for Lidar scanning information by setting <use_tf_scan_transformation> to true, a crucial aspect in the mapping process. This facilitates the conversion of Lidar scanning data into assessments of the robot’s movement distance and direction.

        <!-- Map size / start point -->
        <param name="map_pub_period"        value="0.5"/>
        <param name="map_resolution"        value="0.025"/>
        <param name="map_size"              value="$(arg map_size)"/>
        <param name="map_start_x"           value="0.5"/>
        <param name="map_start_y"           value="0.5"/>
        <param name="map_multi_res_levels"  value="2"/>

The configuration for publishing map messages is depicted in the figure above:

Name Function
map_pub_period Map publishing period
map_resolution Map resolution, measured in meters (m), is the length of the grid cell's edge
map_size Map size
map_start_x The x-coordinate of the origin in the map message of the /map topic, with 0.5 representing the center
map_start_y The y-position of the origin in the /map topic's map message, where 0.5 indicates the center
map_multi_res_levels Multiresolution grid level of the map
        <!-- Map update parameters -->
        <param name="update_factor_free"            value="0.4"/>
        <param name="update_factor_occupied"        value="0.9"/>
        <param name="map_update_distance_thresh"    value="0.1"/>
        <param name="map_update_angle_thresh"       value="0.06"/>
        <param name="laser_z_min_value"             value="-0.1"/>
        <param name="laser_z_max_value"             value="0.2"/>
        <param name="laser_min_dist"                value="0.15"/>
        <param name="laser_max_dist"                value="12"/>

After establishing the foundational logical points and dimensions of the map, it is crucial to set the update parameters for the scanning map. As depicted in the above diagram, there are four critical parameters that merit attention:

<laser_z_min_value>: The minimum height for Lidar scanning, measured in meters. Lidar scan information below this height will be disregarded.

<laser_z_max_value>: The maximum height for Lidar scanning, measured in meters. Lidar scan information above this height will be disregarded.

<laser_min_dist>: The minimum distance for Lidar scanning, measured in meters. Lidar scan information closer than this distance will be disregarded.

<laser_max_dist>: The maximum distance for Lidar scanning, measured in meters. Lidar scan information beyond this distance will be disregarded.

Throughout the mapping process using the Hector mapping method, the mapping effectiveness can be fine-tuned through these four parameters. By adjusting these parameters appropriately, you can regulate the range of Lidar scanning, leading to a more precise mapping outcome. If the default settings yield satisfactory results based on initial measurements, it is advisable to maintain them unchanged during use.

Note

Note: It is recommended to maintain the default settings for the above parameters. Modifying them independently is not advised, as it may impact the effectiveness of the game!!!

To get detailed info, please visit this website: http://wiki.ros.org/hector mapping

6.1.4 Karto Mapping Algorithm

  • Karto Description

Karto SLAM is built on the foundation of graph optimization, employing a highly optimized and non-iterative Cholesky decomposition for sparse system decoupling as a solution. The graph optimization method uses the graph mean to represent the map, where each node signifies a position point in the robot’s trajectory along with a dataset of sensor measurements. Calculations and updates occur upon the addition of each new node.

In the ROS version of Karto SLAM, sparse pose adjustment (SPA) is employed, which is associated with scan matching and loop closure detection. The greater the number of landmarks, the higher the memory requirements. Nonetheless, the graph optimization approach provides significant advantages in large environments compared to other methods, as it only involves the graph of points (robot pose), with the map being derived post obtaining the pose.

The algorithmic framework of Karto SLAM is illustrated in the figure below:

From the above diagram, it can be seen that the process is relatively straightforward. The traditional soft real-time operation mechanism of slam involves processing each frame of data upon entry and then returning.

Relevant source code and WIKI links for KartoSLAM:

  1. KartoSLAM ROS Wiki: http://wiki.ros.org/slam_karto

  2. slam_karto software package: https://github.com/ros-perception/slam_karto

  3. open_karto open-source algorithm: https://github.com/ros-perception/open_karto

  • Mapping Operation Steps

Note

Note: the input command should be case sensitive, and the keywords can be complemented using “Tab” key.

1. Enable Service

  1. Start the robot, and access the robot system desktop using NoMachine.

  2. Double click to open the command line terminal.

  3. Execute the command “sudo systemctl stop start_app_node.service” and press Enter to disable app auto-start service.

    sudo systemctl stop start_app_node.service
    
  4. Open a new terminal, and execute the command “roslaunch hiwonder_slam slam.launch slam_methods:=karto” to enable hector mapping node.

    roslaunch hiwonder_slam slam.launch slam_methods:=karto
    
  5. Open a new command-line terminal window and execute the command ‘roslaunch hiwonder_slam rviz_slam.launch slam_methods:=karto’ to launch the model viewing software.

    roslaunch hiwonder_slam rviz_slam.launch slam_methods:=karto
    

2. Start Mapping

  1. If you want to control the robot using wireless handle, please refer to the tutorial saved in ‘6.ROS1- Mapping Navigation lesson’.

  2. Open a new command-line terminal, and execute the command ‘roslaunch hiwonder_peripherals teleop_key_control.launch’ to enable the keyboard control node.

    roslaunch hiwonder_peripherals teleop_key_control.launch
    

When the following prompt occurs, it means the keyboard control service is enabled successfully.

  1. Control the robot to move around to map the whole environment by pressing the corresponding keys.

Key Robot’s Action
W Go forward (Press briefly)
S Go backward (Press briefly)
A Turn left (Long press)
D Turn right (Long press)

3. Save the Map

  1. Open a new terminal and input the command “roscd hiwonder_slam/maps” and press Enter to enter the folder where the map is stored.

    roscd hiwonder_slam/maps
    
  2. Execute the command ‘rosrun map_server map_saver map:=/robot_1/map -f map_01’ and press Enter to save the map.

    rosrun map_server map_saver map:=/robot_1/map -f map_01
    

The term “robot_1” in the command represents the robot name, while “map_01” designates the map name. Users can rename them according to their preferences. The appearance of the following prompt confirms the successful saving of the map.

  1. If you want to stop running the program, you can press ‘Ctrl+C’.

Once you finish experiencing this function, you need to restart the app service through command or restarting the robot. Execute this command “sudo systemctl restart start_app_node.service” to restart the app service. When you hear a beeping sound from the robot, it means that the service is restarted successfully.

sudo systemctl restart start_app_node.service

4. Optimize Program Outcome

For enhanced mapping precision, consider optimizing the odometer settings. The robot’s mapping process heavily relies on the Lidar, and the odometer’s functionality is closely tied to Lidar operations.

The calibrated IMU (Inertial Measurement Unit) data has been successfully integrated into the robot’s system, enabling both mapping and navigation. However, to achieve even greater accuracy, it’s advisable to calibrate the IMU. Detailed instructions on how to perform IMU calibration are available in “3 ROS1-Chassis Motion Control Lesson\ 3.2 Motion Control\ 3.2.1 IMU, Linear Velocity and Angular Velocity Calibration”.

  • Launch File Analysis

1. Path

According to the game, the main files involved are as follows:

  1. slam.launch: Selects the mapping method (Location: /ros_ws/src/hiwonder_slam/launch/slam.lauch)

  2. slam_base.launch: Basic topic configuration and startup for mapping functionalities (Location: /ros_ws/src/hiwonder_slam/launch/include/slam_base.launch)

  3. karto.launch: Specific topic and parameter configuration for the mapping method(Location: hiwonder_slam/launch/include/karto.launch

2. Structure

The file structure is as below:

Reviewing the document structure, the focus is on selecting mapping methods, initiating mapping functionalities, configuring relevant topics, and adjusting mapping method parameters. For detailed syntax guidelines, please refer to the ‘14.ROS Basics Lesson’.

3. Select Mapping Method

    <arg name="slam_methods" default="gmapping" doc="slam type 
        [gmapping, cartographer, hector, karto, frontier, explore, rrt_exploration, rtabmap]"/>

    <arg name="gmapping"        default="gmapping"/>
    <arg name="cartographer"    default="cartographer"/>
    <arg name="hector"          default="hector"/>
    <arg name="karto"           default="karto"/>
    <arg name="frontier"        default="frontier"/>
    <arg name="explore"         default="explore"/>
    <arg name="rrt_exploration" default="rrt_exploration"/>
    <arg name="rtabmap"         default="rtabmap"/>

The slam_methods parameter represents the mapping method, with the default value being ‘gmapping.’ The available mapping methods include:

Manual mapping: gmapping, cartographer, hector and karto

Autonomous mapping: frontier and explorerrt_exploration

3D mapping: rtabmap

If using the ‘gmapping’ mapping method, the command line in the terminal when executing this launch file would be:

roslaunch hiwonder_slam slam.launch slam_methods:=gmapping

Here, slam_methods:=[mapping method name] can be modified according to the desired mapping method, for example: slam_methods:=karto.

Based on the current game, the recommended mapping method to choose is slam_methods:= karto.

4. Initiate Mapping Function and Related Topic Configuration

    <include file="$(find hiwonder_slam)/launch/include/slam_base.launch">
        <arg name="sim"             value="$(arg sim)"/>
        <arg name="slam_methods"    value="$(arg slam_methods)"/>
        <arg name="robot_name"      value="$(arg robot_name)"/>
    </include>

After choosing the mapping method (slam_methods), the subsequent step involves initiating the mapping functionality and configuring relevant topic names through the use of slam_base.launch. In the provided diagram, <sim> signifies whether simulation is utilized. In this context, it refers to the simulation parameter (sim), which defaults to false, indicating that the node simulation is inactive. <slam_methods> denotes the selected mapping method, set as “karto” for this mapping session. <robot_name> specifies the node name of the robot.

For a detailed examination of the contents of the slam_base.launch file, you can consult the “slam_base.launch Program Analysis”.

5. Mapping Method Parameter Configuration

        <group if="$(eval slam_methods == 'karto')">
            <include file="$(find hiwonder_slam)/launch/include/$(arg slam_methods).launch">
                <arg name="map_frame"   value="$(arg map_frame)"/>
                <arg name="base_frame"  value="$(arg base_frame)"/>
                <arg name="odom_frame"  value="$(arg odom_frame)"/>
            </include>
        </group>

In the concurrently executed slam_base.launch file, as depicted above, it includes launch files specific to the selected mapping method. If “karto” is the chosen mapping method, it is crucial to focus on the karto.launch file for configuring mapping method parameters (located at hiwonder_slam/launch/include/karto.launch).

The following provides an overview of the essential contents within the primary startup file, karto.launch:

    <arg name="map_frame"  default="map"/>
    <arg name="odom_frame" default="odom"/>
    <arg name="base_frame" default="base_footprint"/>

<map_frame>: Map topic name, set to ‘map’.

<odom_frame>: Odometry topic name, set to ‘odom’.

<base_frame>: Robot’s polar coordinate system topic name, set to ‘base_footprint’.

    <node pkg="slam_karto" type="slam_karto" name="slam_karto" output="screen">
        <param name="map_frame"             value="$(arg map_frame)"/>
        <param name="odom_frame"            value="$(arg odom_frame)"/>
        <param name="base_frame"            value="$(arg base_frame)"/>
        <param name="map_update_interval"   value="5"/>
        <param name="resolution"            value="0.025"/>
    </node>

The diagram above shows how to start and configure key parameters for mapping with the Karto package:

<map_update_interval>: Controls how often the map updates, defaulting to 5 milliseconds.

<resolution>: Sets the map resolution.

While you can customize these during mapping, sticking to the default settings is recommended for the best results. The robot is pre-calibrated for accurate mapping with these defaults.

Note

Note: It is recommended to maintain the default settings for the above parameters. Modifying them independently is not advised, as it may impact the effectiveness of the game!!!

To get detailed info, please visit this website: http://wiki.ros.org/slam_karto

6.1.5 Cartographer Mapping Algorithm

  • Cartographer Description

Cartographer’s core principle is to rectify errors that accumulate during map creation using closed-loop detection. It does this by dividing the map into submaps, each consisting of laser scans. As new scans are added to a submap, their optimal positions are estimated based on existing data and sensor input. While errors during short-term submap creation are deemed acceptable, over time, with more submaps, errors between them grow. To address this, Cartographer optimizes submap poses through closed-loop detection, essentially transforming it into a pose optimization challenge. Once a submap is finished (no new scans added), it is incorporated into loop closure detection, considering all created submaps. When a new scan is added to the map, Cartographer looks for a match in existing submaps. If a close match is found, it employs a scan match strategy to establish closed loops. The strategy involves examining a window near the estimated pose of the newly added laser scan, searching for a potential match within that window. Successful matches introduce closed-loop constraints to the pose optimization problem. Cartographer’s primary focus is on creating local submaps that fuse multi-sensor data and implementing a scan match strategy for closed-loop detection.

The Cartographer system can be broadly divided into two components:

Local SLAM (Frontend):

Task: Creation and maintenance of Submaps.

Challenge: Accumulation of mapping errors over time.

Configuration Parameters: Defined in /src/cartographer/configuration_files/trajectory_builder_2d.lua and /src/cartographer/configuration_files/trajectory_builder_3d.lua.

Global SLAM (Backend):

Task: Loop Closure detection and resolution.

Approach: Formulated as an optimization problem with pixel-accurate matching, solved using the Branch-and-Bound Approach (BBA).

Detailed Method: Refer to the paper “Real-Time Loop Closure in 2D LIDAR SLAM.”

Additional Task in 3D: Determines the direction of gravity based on IMU data.

In summary, the Local SLAM generates improved subgraphs, while the Global SLAM performs global optimization and aligns various subgraphs in the most fitting pose.

The process begins with sensor input, where Laser data undergoes Scan Matching after two filters to construct a submap. New Laser Scans are inserted into the appropriate position of the maintained submap. The determination of the optimal pose for insertion is achieved through Ceres Scan Matching. The estimated optimal pose is integrated with odometry and IMU data to project the pose at the next moment.

Cartographer software pack:

https://github.com/cartographer-project/cartographer

  • Mapping Operation Steps

Note

Note: the input command should be case sensitive, and keywords can be complemented using Tab key.

1. Enable Service

  1. Start the robot, and access the robot system desktop using NoMachine.

  2. Double click to open the command line terminal.

  3. Execute the command “sudo systemctl stop start_app_node.service” and press Enter to disable app auto-start service.

    sudo systemctl stop start_app_node.service
    
  4. Open a new terminal, and execute the command “roslaunch hiwonder_slam slam.launch slam_methods:=cartographer” to enable cartographer mapping node.

    roslaunch hiwonder_slam slam.launch slam_methods:=cartographer
    
  5. Open a new command-line terminal window and execute the command ‘roslaunch hiwonder_slam rviz_slam.launch slam_methods:=cartographer’ to launch the model viewing software.

    roslaunch hiwonder_slam rviz_slam.launch slam_methods:=cartographer
    

2. Start Mapping

If you want to control the robot using wireless handle, please refer to the tutorial saved in ‘6 ROS1-Mapping & Navigation’.

  1. Open a new command-line terminal, and execute the command ‘roslaunch hiwonder_peripherals teleop_key_control.launch’ to enable the keyboard control node.

    roslaunch hiwonder_peripherals teleop_key_control.launch
    

When the following prompt occurs, it means the keyboard control service is enabled successfully.

  1. Control the robot to move around to map the whole environment by pressing the corresponding keys.

Key Robot’s Action
W Go forward (Press briefly)
S Go backward (Press briefly)
A Turn left (Long press)
D Turn right (Long press)

3. Save the Map

  1. Open a new terminal and input the command “roscd hiwonder_slam/maps” and press Enter to enter the folder where the map is stored.

    roscd hiwonder_slam/maps
    
  2. Execute the command ‘rosrun map_server map_saver map:=/robot_1/map -f map_01’ and press Enter to save the map.

    rosrun map_server map_saver map:=/robot_1/map -f map_01
    

The term “robot_1” in the command represents the robot name, while “map_01” designates the map name. Users can rename them according to their preferences. The appearance of the following prompt confirms the successful saving of the map.

  1. If you want to stop running the program, you can press “Ctrl+C”.

  2. To enable the app service, execute the command ‘sudo systemctl start start_app_node.service’.

Once you finish experiencing this function, you need to restart the app service through command or restarting the robot. Execute this command “sudo systemctl restart start_app_node.service” to restart the app service. When you hear a beeping sound from the robot, it means that the service is restarted successfully.

sudo systemctl restart start_app_node.service

4. Optimize Program Outcome

For enhanced mapping precision, consider optimizing the odometer settings. The robot’s mapping process heavily relies on the Lidar, and the odometer’s functionality is closely tied to Lidar operations.

The calibrated IMU (Inertial Measurement Unit) data has been successfully integrated into the robot’s system, enabling both mapping and navigation. However, to achieve even greater accuracy, it’s advisable to calibrate the IMU. Detailed instructions on how to perform IMU calibration are available in “3 ROS1-Chassis Motion Control Lesson\ 3.2 Motion Control\ 3.2.1 IMU, Linear Velocity and Angular Velocity Calibration”.

  • Parameter Description

The parameter file can be accessed in this path: /ros_ws/src/hiwonder_slam/config/cartographer_params.lua

master_name = os.getenv("MASTER")       -- Obtain the value of the system environment variable MASTER
robot_name = os.getenv("HOST")             -- Obtain the value of the   system environment variable HOST
prefix = os.getenv("prefix")             -- Obtain the value of the system environment variable prefix
MAP_FRAME = "map"                              -- name of the default map coordinate system
ODOM_FRAME = "odom"                            -- name of the default odometer coordinate system
BASE_FRAME = "base_footprint"                  -- name of the default base coordinate system
if(prefix ~= "/") then
    MAP_FRAME = master_name .. "/" .. MAP_FRAME
    ODOM_FRAME = robot_name .. "/" .. ODOM_FRAME
    BASE_FRAME = robot_name .. "/" .. BASE_FRAME
end

options = {
map_builder = MAP_BUILDER,    -- configuration info of map_builder.lua
trajectory_builder = TRAJECTORY_BUILDER,   -- comfiguration info of trajectory_builder.lua
map_frame = MAP_FRAME,              -- name of the map coordinate system
 tracking_frame = BASE_FRAME,      -- convert all sensor data to this coordinate system
  published_frame = ODOM_FRAME,     -- publishing coordinate system of tf: map -> odom
  odom_frame = ODOM_FRAME,               -- name of odometers coordinate system 
  provide_odom_frame = false,                -- whether offer odoms tf 
  publish_frame_projected_to_2d = false,     -- Whether to project the coordinate system onto a plane

  use_odometry = true,                       -- Whether to use odometer
  use_nav_sat = false,                       -- Whether to use gps
  use_landmarks = false,                     -- Whether to use landmark
  num_laser_scans = 1,                      -- Whether to use Single-line laser data
  num_multi_echo_laser_scans = 0,  --whether to use multi_echo_laser_scans data
  num_subdivisions_per_laser_scan = 1,       -- 1 frame of data is divided into several times for processing
  num_point_clouds = 0,                      -- Whether to use point cloud data

  lookup_transform_timeout_sec = 0.2,        -- Timeout when looking for tf
  submap_publish_period_sec = 0.3,       -- Time interval for publishing data
  pose_publish_period_sec = 5e-3,            -- Posture interval
  trajectory_publish_period_sec = 30e-3,     -- Track release time interval

  rangefinder_sampling_ratio = 1.,           -- Sampling frequency of sensor data
  odometry_sampling_ratio = 1.,              -- Sampling frequency of odometer data
  fixed_frame_pose_sampling_ratio = 1.,      -- Fixed frame pose sampling frequency
  imu_sampling_ratio = 1.,                   -- Sampling frequency of IMU data
  landmarks_sampling_ratio = 1.,             -- Sampling frequency of landmarks data
}
MAP_BUILDER.use_trajectory_builder_2d = true    -- Use the 2D trajectory builder and the relevant parameters below

Cartographer offers a wide range of configurable parameters, and we won’t list them all here. For an in-depth understanding of Cartographer’s algorithm, please consult the official documentation on Cartographer’s GitHub repository: https://github.com/cartographer-project/cartographer

  • Launch File Analysis

1. Path

According to the game, the main files involved are as follows:

  1. slam.launch: Selects the mapping method (Location: /ros_ws/src/hiwonder_slam/launch/slam.lauch)

  2. slam_base.launch: Basic topic configuration and startup for mapping functionalities(Location: /ros_ws/src/hiwonder_slam/launch/include/slam_base.launch)

  3. cartographer.launch: Specific topic and parameter configuration for the mapping method(Location: hiwonder_slam/launch/include/cartographer.launch

2. Structure

The file structure is as below:

Reviewing the document structure, the focus is on selecting mapping methods, initiating mapping functionalities, configuring relevant topics, and adjusting mapping method parameters. For detailed syntax guidelines, please refer to the ‘14.ROS Basics Lesson’.

3. Select Mapping Method

    <arg name="slam_methods" default="gmapping" doc="slam type 
        [gmapping, cartographer, hector, karto, frontier, explore, rrt_exploration, rtabmap]"/>

    <arg name="gmapping"        default="gmapping"/>
    <arg name="cartographer"    default="cartographer"/>
    <arg name="hector"          default="hector"/>
    <arg name="karto"           default="karto"/>
    <arg name="frontier"        default="frontier"/>
    <arg name="explore"         default="explore"/>
    <arg name="rrt_exploration" default="rrt_exploration"/>
    <arg name="rtabmap"         default="rtabmap"/>

The slam_methods parameter represents the mapping method, with the default value being ‘gmapping.’ The available mapping methods include:

Manual mapping: gmapping, cartographer, hector and karto

Autonomous mapping: frontier and explorerrt_exploration

3D mapping: rtabmap

If using the ‘gmapping’ mapping method, the command line in the terminal when executing this launch file would be:

roslaunch hiwonder_slam slam.launch slam_methods:=gmapping

Here, slam_methods:=[mapping method name] can be modified according to the desired mapping method, for example: slam_methods:=karto.

Based on the current game, the recommended mapping method to choose is slam_methods:= cartographer.

4. Initiate Mapping Function and Related Topic Configuration

    <include file="$(find hiwonder_slam)/launch/include/slam_base.launch">
        <arg name="sim"             value="$(arg sim)"/>
        <arg name="slam_methods"    value="$(arg slam_methods)"/>
        <arg name="robot_name"      value="$(arg robot_name)"/>
    </include>

After choosing the mapping method (slam_methods), the subsequent step involves initiating the mapping functionality and configuring relevant topic names through the use of slam_base.launch. In the provided diagram, <sim> signifies whether simulation is utilized. In this context, it refers to the simulation parameter (sim), which defaults to false, indicating that the node simulation is inactive. <slam_methods> denotes the selected mapping method, set as “cartographer” for this mapping session. <robot_name> specifies the node name of the robot.

For a detailed examination of the contents of the slam_base.launch file, you can consult the “slam_base.launch Program Analysis”.

5. Mapping Method Parameter Configuration

        <group if="$(eval slam_methods == 'cartographer')">
            <include file="$(find hiwonder_slam)/launch/include/$(arg slam_methods).launch">
                <arg name="sim"        value="$(arg sim)"/>
                <arg name="prefix"     value="$(arg robot_name)"/>
            </include>
        </group>

In the concurrently launched slam_base.launch file, as shown in the figure above, it contains the launch file for the respective mapping method. According to the cartographer mapping method used in this mapping process, attention should be given to the mapping method’s parameter configuration file, specifically the hector.launch file (location: hiwonder_slam/launch/include/cartographer.launch).

The following provides the main content of the cartographer.launch launch file:

    <arg name="sim"             default="false"/>
    <param name="/use_sim_time" value="$(arg sim)"/>
    <arg name="prefix"          default=""/>
    <env name="prefix"          value="$(arg prefix)"/>

Disable simulation by setting <sim> to false.

Establish <prefix> as the default environment prefix; keep it empty.

args="-configuration_directory $(find hiwonder_slam)/config -configuration_basename cartographer_params.lua"

For the cartographer mapping method, it is necessary to configure the parameters associated with the mapping process. The configuration is performed using the cartographer_params.lua file (located at hiwonder_slam/config/cartographer_params.lua). The following provides a detailed analysis of the main content within the parameter configuration file:

map_frame = MAP_FRAME,        -- 地图坐标系的名字(map coordinate system name)
  tracking_frame = BASE_FRAME,  -- 将所有传感器数据转换到这个坐标系下(transfer all the sensor data to this coordinate system)
  published_frame = ODOM_FRAME, -- tf: map -> odom
  odom_frame = ODOM_FRAME,      -- 里程计的坐标系名字(odometer coordinate system name)
  provide_odom_frame = false,   -- 是否提供odom的tf, 如果为true,则tf树为map->odom->footprint(whether tf of odom is provided. If true, tf tree is map->odom->footprint)

The parameters depicted in the figure above denote fundamental coordinate system configurations. These configurations facilitate the exchange of node information between diverse sensors and coordinates throughout the mapping process. For detailed explanations of these parameters, please consult the notes provided at the end of the file.

use_odometry = true,                      -- 是否使用里程计,如果使用要求一定要有odom的tf(whether to use odometer. tf of odom is required when in use)
  use_nav_sat = false,                      -- 是否使用gps(whether to use gps)
  use_landmarks = false,                    -- 是否使用landmark(whether to use landmark)
  num_laser_scans = 1,                      -- 是否使用单线激光数据(whether to use single-line laser data)
  num_multi_echo_laser_scans = 0,           -- 是否使用multi_echo_laser_scans数据(whether to use multi_echo_laser_scans data)
  num_subdivisions_per_laser_scan = 1,      -- 1帧数据被分成几次处理,一般为1(one frame of data is divided into several parts for processing. In general, it is set as 1)
  num_point_clouds = 0,                     -- 是否使用点云数据(whether to use point cloud)

The parameters in the above figure encompass logical configurations for odom, gps, landmarks, lidar data segmentation (subdivisions_per_laser_scan), and point cloud data (point_clouds). Detailed explanations for these parameters are available in the comments at the end of the file.

  rangefinder_sampling_ratio = 1.,          -- 传感器数据的采样频率(sampling frequency of sensor data)
  odometry_sampling_ratio = 1.,
  fixed_frame_pose_sampling_ratio = 1.,
  imu_sampling_ratio = 1.,
  landmarks_sampling_ratio = 1.,

<rangefinder_sampling_ratio>: Represents the sampling frequency of the ranging sensor. If the function package utilizes ranging sensors during the cartographer mapping algorithm, it can be set and obtained through measurement parameters. The default setting is 1; otherwise, if invalid, maintain the default value of 1.

<odometry_sampling_ratio>: Sampling frequency for odometry.

<fixed_frame_pose_sampling_ratio>: Sampling frequency for fixed position frame.

<imu_sampling_ratio>: Sampling frequency for imu.

<landmarks_sampling_ratio>: Sampling frequency for landmarks. Although the previous setting for landmarks was deemed impractical, the default open setting does not impact the actual mapping effect.

TRAJECTORY_BUILDER_2D.submaps.num_range_data = 35
TRAJECTORY_BUILDER_2D.min_range = 0.15
TRAJECTORY_BUILDER_2D.max_range = 10.
TRAJECTORY_BUILDER_2D.use_imu_data = false
TRAJECTORY_BUILDER_2D.missing_data_ray_length = 1.
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

TRAJECTORY_BUILDER_2D is a class within the cartographer mapping algorithm that encompasses logical parameter settings and details on acquiring these parameters:

Name Function
num_range_data The submap layer's data range
use_imu_data Utilization of IMU data
min_range Minimum distance for the laser
max_range Maximum distance for the laser
min_z Most laser scans are for acquiring low heights
max_z Maximum height obtained by lidar scan
missing_data_ray_length If the value falls outside the range between min_range and max_range, it defaults to the specified value after exceeding the set data range
use_online_correlative_scan_matching Application of CSM laser matching

It also includes another class, the real_time_correlative_scan_matcher:

Name Function
linear_search_window Angle search range
translation_delta_cost_weight The translation cost weight implies that the matching score must be higher as the distance from the initial value increases in order to be deemed reliable. This can be interpreted as setting a limit on the parameters.
rotation_delta_cost_weight Rotation cost weight

Note

Note: It is recommended to maintain the default settings for the above parameters. Modifying them independently is not advised, as it may impact the effectiveness of the game!!!

6.1.6 Frontier Autonomous Mapping

  • Frontier Description

Frontier autonomous mapping involves utilizing the Gmapping mapping algorithm as a foundation and incorporating mapping navigation, path planning, automatic obstacle avoidance, and other functionalities. This enables the robot to autonomously reach designated target points without human control (via handle or keyboard) while simultaneously conducting mapping.

The implementation of Frontier’s autonomous mapping comprises two main components: the mapping algorithm and navigation.

Various mapping algorithms can be employed, such as Gmapping, Hector, Karto, and Cartographer. This lesson specifically utilizes the Gmapping algorithm.

In terms of navigation, once one or more target points are set for the robot, it automatically performs path planning and initiates movement. In the event of encountering obstacles during movement, the robot updates its path through a local optimizer to navigate around the obstacles.

frontier_exploration software pack:

https://github.com/paulbovbel/frontier_exploration

  • Mapping Operation Steps

Note

Notice:

  • Prior to initiating, ensure the construction of a sealed environment and preposition the robot inside. It is crucial to maintain airtight conditions.

  • When entering commands, strict case sensitivity is required, and the “Tab” key can be used to auto-complete keywords.

1. Start Mapping

  1. Start the robot, and access the robot system desktop using NoMachine.

  2. Double click to open the command line terminal.

  3. Execute the command “sudo systemctl stop start_app_node.service” and press Enter to disable app auto-start service.

    sudo systemctl stop start_app_node.service
    
  4. Open a new terminal, and execute the command “roslaunch hiwonder_slam slam.launch slam_methods:=frontier” to enable mapping service.

    roslaunch hiwonder_slam slam.launch slam_methods:=frontier
    
  5. Open a new command-line terminal window and execute the command ‘roslaunch hiwonder_slam rviz_slam.launch slam_methods:=frontier’ to launch the model viewing software.

    roslaunch hiwonder_slam rviz_slam.launch slam_methods:=frontier
    

2. Save Map

  1. Open a new command-line terminal, and execute the command ‘roscd hiwonder_slam/maps’, then hit Enter to navigate to the folder containing the map.

    roscd hiwonder_slam/maps
    
  2. Run the command ‘rosrun map_server map_saver map:=/robot_1/map -f map_01’ and hit Enter to save the map.

    rosrun map_server map_saver map:=/robot_1/map -f map_01
    

The term “robot_1” in the command represents the robot name, while “map_01” designates the map name. Users can rename them according to their preferences. The appearance of the following prompt confirms the successful saving of the map.

  1. If you want to stop running the program, you can press “Ctrl+C”.

  2. To enable the app service, execute the command ‘sudo systemctl start start_app_node.service’.

    sudo systemctl start start_app_node.service
    

3. Optimize Program Outcome

For enhanced mapping precision, consider optimizing the odometer settings. The robot’s mapping process heavily relies on the Lidar, and the odometer’s functionality is closely tied to Lidar operations.

The calibrated IMU (Inertial Measurement Unit) data has been successfully integrated into the robot’s system, enabling both mapping and navigation. However, to achieve even greater accuracy, it’s advisable to calibrate the IMU. Detailed instructions on how to perform IMU calibration are available in “3 ROS1-Chassis Motion Control Lesson\3.2 Motion Control\ 3.2.1 IMU, Linear Velocity and Angular Velocity Calibration”.

  • Parameter Description

The parameter file can be found at the path “hiwonder_slam/config/frontier_points.yaml.” The defined points in this file are utilized for planning the robot’s exploration path and setting navigation points.

points:
  - [1.0, 1.0]
  - [4.5, 5.0]
  - [10.0, 3.0]
  - [2.0, 7.8]
  - [3.0, 4.0]
  - [0.0, -2.0]
  - [5.0, 33.0]
  - [6.0, 28.0]
  • Launch File Analysis

1. Path

According to the game, the main files involved are as follows:

  1. slam.launch: Selects the mapping method (Location: /ros_ws/src/hiwonder_slam/launch/slam.lauch)

  2. slam_base.launch: Basic topic configuration and startup for mapping functionalities(Location: /ros_ws/src/hiwonder_slam/launch/include/slam_base.launch)

  3. frontier.launch: Specific topic and parameter configuration for the mapping method (Location: hiwonder_slam/launch/include/frontier.launch)

2. Structure

The file structure is as below:

Reviewing the document structure, the focus is on selecting mapping methods, initiating mapping functionalities, configuring relevant topics, and adjusting mapping method parameters. For detailed syntax guidelines, please refer to the ‘14.ROS Basics Lesson’.

3. Select Mapping Method

    <arg name="slam_methods" default="gmapping" doc="slam type 
        [gmapping, cartographer, hector, karto, frontier, explore, rrt_exploration, rtabmap]"/>

    <arg name="gmapping"        default="gmapping"/>
    <arg name="cartographer"    default="cartographer"/>
    <arg name="hector"          default="hector"/>
    <arg name="karto"           default="karto"/>
    <arg name="frontier"        default="frontier"/>
    <arg name="explore"         default="explore"/>
    <arg name="rrt_exploration" default="rrt_exploration"/>
    <arg name="rtabmap"         default="rtabmap"/>

The slam_methods parameter represents the mapping method, with the default value being ‘gmapping.’ The available mapping methods include:

Manual mapping: gmapping, cartographer, hector and karto

Autonomous mapping: frontier and explorerrt_exploration

3D mapping: rtabmap

If using the ‘gmapping’ mapping method, the command line in the terminal when executing this launch file would be:

roslaunch hiwonder_slam slam.launch slam_methods:=gmapping

Here, slam_methods:=[mapping method name] can be modified according to the desired mapping method, for example: slam_methods:=karto.

Based on the current game, the recommended mapping method to choose is slam_methods:= frontier.

4. Initiate Mapping Function and Related Topic Configuration

    <include file="$(find hiwonder_slam)/launch/include/slam_base.launch">
        <arg name="sim"             value="$(arg sim)"/>
        <arg name="slam_methods"    value="$(arg slam_methods)"/>
        <arg name="robot_name"      value="$(arg robot_name)"/>
    </include>

After choosing the mapping method ‘slam_methods,’ it is necessary to initiate the mapping function using ‘slam_base.launch’ and configure the relevant topic name.

As illustrated above, <sim> determines whether simulation is utilized, referring to the ‘sim’ parameter above. The default is ‘false,’ indicating no simulation. <slam_methods> denotes the mapping method, which, in this case, is set to ‘explore.’ <robot_name> represents the node name of the robot.

The image below displays the frontier section within ‘slam_base.launch.’ Subsequently, the main content of this summary focuses on this aspect.

        <group if="$(eval slam_methods == 'frontier')">
            <include file="$(find hiwonder_slam)/launch/include/gmapping.launch">
                <arg name="scan"        value="$(arg scan_topic)"/>
                <arg name="base_frame"  value="$(arg base_frame)"/>
                <arg name="odom_frame"  value="$(arg odom_frame)"/>
                <arg name="map_frame"   value="$(arg map_frame)"/>
            </include>
            <include file="$(find hiwonder_slam)/launch/include/$(arg slam_methods).launch">
                <arg name="global_frame"        value="$(arg map_frame)"/>
                <arg name="robot_base_frame"    value="$(arg base_frame)"/>
                <arg name="odom_frame"          value="$(arg odom_frame)"/>
                <arg name="map_topic"           value="$(arg map_topic)"/>
                <arg name="map_frame"           value="$(arg map_frame)"/>
                <arg name="odom_topic"          value="$(arg odom_topic)"/>
                <arg name="scan_topic"          value="$(arg scan_topic)"/>
                <arg name="clicked_point"       value="$(arg clicked_point)"/>
                <arg name="move_base_result"    value="$(arg move_base_result)"/>
                <arg name="cmd_vel_topic"       value="$(arg cmd_vel_topic)"/>
            </include>
        </group>

Given the game’s focus on independent mapping, the Gmapping mapping algorithm is integrated with the navigation algorithm throughout the mapping process. For an in-depth analysis of Gmapping content, please consult the ‘Gmapping Mapping Algorithm Launch File Analysis

Upon examination of the figure above, a notable distinction from the manual mapping in the previous course is apparent. In addition to the parameters like scan, base_frame, odom_frame, and map_frame, several other parameters are defined and loaded into the ‘frontier.launch’ file. These include:

  1. ‘global_frame’ [global coordinate system], set to ‘map_frame’ [map coordinate system].

  2. ‘clicked_frame’ [target point click coordinates], set to ‘clicked_point’ [“topic_prefix)/clicked_point”], where ‘topic_prefix)/clicked_point’ corresponds to the default value of ‘clicked_point’ in the launch document

  3. ‘cmd_vel_topic’ [Robot speed topic], set to ‘cmd_vel_topic’ [‘topic_prefix)/hiwonder_controller/cmd_vel’], corresponding to the default value of ‘cmd_vel_topic’ in the launch document.

For detailed information about the contents of the ‘slam_base.launch’ file, please refer to ‘slam_base.launch Program Analysis.

5. Mapping Method Parameter Configuration

Using the functionality provided in this game, you can locate the ‘frontier.launch’ file at: ‘hiwonder_slam/launch/include/frontier.launch’

The basic parameter configuration is shown in the figure below

    <arg name="global_frame"        default="map"/>
    <arg name="robot_base_frame"    default="base_footprint"/>
    <arg name="odom_frame"          default="odom"/>
    <arg name="map_topic"           default="map"/>
    <arg name="map_frame"           default="map"/>
    <arg name="odom_topic"          default="odom"/>
    <arg name="scan_topic"          default="scan"/>
    <arg name="clicked_point"       default="clicked_point"/>
    <arg name="move_base_result"    default="move_base_result"/>
    <arg name="cmd_vel_topic"       default="hiwonder_controller/cmd_vel"/>

Includes configurations for various topic coordinate systems (global_frame [global coordinate system], robot_base_frame [robot’s base coordinate system], odom_frame [odometer coordinate system], map_frame [map coordinate system]), and settings for specific topics (map_topic [map topic], odom_topic [odometer topic], scan_topic [radar scan topic]).

  1. Explanation of loading parameters in the function package for initiating path planning

        <include file="$(find hiwonder_navigation)/launch/include/move_base.launch">
            <arg name="cmd_vel_topic"                   value="$(arg cmd_vel_topic)" />
            <arg name="global_costmap_map_topic"        value="$(arg map_topic)"/>
            <arg name="global_costmap_sensor_frame"     value="$(arg robot_base_frame)"/>
            <arg name="global_costmap_sensor_topic"     value="$(arg scan_topic)"/>
            <arg name="global_costmap_global_frame"     value="$(arg global_frame)"/>
            <arg name="global_costmap_robot_base_frame" value="$(arg robot_base_frame)"/>
            <arg name="local_costmap_map_topic"         value="$(arg map_topic)"/>
            <arg name="local_costmap_sensor_frame"      value="$(arg robot_base_frame)"/>
            <arg name="local_costmap_sensor_topic"      value="$(arg scan_topic)"/>
            <arg name="local_costmap_global_frame"      value="$(arg odom_frame)"/>
            <arg name="local_costmap_robot_base_frame"  value="$(arg robot_base_frame)"/>
            <arg name="virtual_wall_map_frame"          value="$(arg map_frame)"/>
            <arg name="teb_odom_topic"                  value="$(arg odom_topic)"/>
            <arg name="teb_map_frame"                   value="$(arg odom_frame)"/>
        </include>
    
  2. Configuration of the robot speed topic ‘cmd_vel_topic.’

  3. Setting the global cost map parameter message name (global_costmap_[…]) and local cost map parameter name (local_costmap_[…]).

  4. Configuration of ‘teb_odom_topic’ [odom topic of teb path planning algorithm] and ‘teb_map_frame’ [map coordinate system of teb path planning algorithm].

Note

Note: It is recommended to maintain the default settings for the above parameters. Modifying them independently is not advised, as it may impact the effectiveness of the game!!!

To get detailed information, please visit this link: http://wiki.ros.org/explore_lite

6.1.7 Explore_Lite Autonomous Mapping

  • Explore_Lite Description

Explorer_Lite mapping, also known as exploration mapping, is a fully automated mapping method that operates without the need for human control or manual setting of target points. Upon activating this game, the robot initiates movement. While in motion, the robot autonomously navigates, avoids obstacles, and simultaneously builds maps.

The implementation of Explorer_Lite mapping can be divided into two primary components: the mapping algorithm and movement.

Various mapping algorithms can be utilized, such as Gmapping, Hector, Karto, and Cartographer. This lesson specifically employs the Gmapping algorithm.

The robot’s movement route is planned based on the map currently under construction. The robot continuously explores by moving towards the boundaries of the existing map until the mapping of the current area is complete.

Explore_Lite software pack link: https://github.com/hrnr/m-explore

  • Mapping Operation Steps

Note

Notice:

  • Prior to initiating, ensure the construction of a sealed environment and preposition the robot inside. It is crucial to maintain airtight conditions!

  • When entering commands, strict case sensitivity is required, and the “Tab” key can be used to auto-complete keywords.

1. Enable Service

  1. Start the robot, and access the robot system desktop using NoMachine.

  2. Double click to open the command line terminal.

  3. Execute the command “sudo systemctl stop start_app_node.service” and press Enter to disable app auto-start service.

    sudo systemctl stop start_app_node.service
    
  4. Open a new terminal, and execute the command “roslaunch hiwonder_slam slam.launch slam_methods:=explore” to enable mapping service.

    roslaunch hiwonder_slam slam.launch slam_methods:=explore
    
  5. Open a new command-line terminal window and execute the command ‘roslaunch hiwonder_slam rviz_slam.launch slam_methods:=explore’ to launch the model viewing software.

    roslaunch hiwonder_slam rviz_slam.launch slam_methods:=explore
    

2. Save the Map

  1. Open a new terminal and input the command “roscd hiwonder_slam/maps” and press Enter to navigate to the folder where the map is stored.

    roscd hiwonder_slam/maps
    
  2. Execute the command ‘rosrun map_server map_saver map:=/robot_1/map -f map_01’ and press Enter to save the map.

    rosrun map_server map_saver map:=/robot_1/map -f map_01
    

The term “robot_1” in the command represents the robot name, while “map_01” designates the map name. Users can rename them according to their preferences. The appearance of the following prompt confirms the successful saving of the map.

  1. If you want to stop running the program, you can press “Ctrl+C”.

  2. To enable the app service, execute the command ‘sudo systemctl start start_app_node.service’.

    sudo systemctl start start_app_node.service
    

3. Optimize Program Outcome

For enhanced mapping precision, consider optimizing the odometer settings. The robot’s mapping process heavily relies on the Lidar, and the odometer’s functionality is closely tied to Lidar operations.

The calibrated IMU (Inertial Measurement Unit) data has been successfully integrated into the robot’s system, enabling both mapping and navigation. However, to achieve even greater accuracy, it’s advisable to calibrate the IMU. Detailed instructions on how to perform IMU calibration are available in “3 ROS1-Chassis Motion Control Lesson\3.2 Motion Control\3.2.1 IMU, Linear Velocity and Angular Velocity Calibration”.

  • Launch File Analysis

1. Path

According to the game, the main files involved are as follows:

  1. slam.launch: Selects the mapping method (Location: /ros_ws/src/hiwonder_slam/launch/slam.lauch)

  2. slam_base.launch: Basic topic configuration and startup for mapping functionalities(Location: /ros_ws/src/hiwonder_slam/launch/include/slam_base.launch)

  3. explore.launch: Specific topic and parameter configuration for the mapping method (Location: hiwonder_slam/launch/include/explore.launch)

2. Structure

The file structure is as below:

Reviewing the document structure, the focus is on selecting mapping methods, initiating mapping functionalities, configuring relevant topics, and adjusting mapping method parameters. For detailed syntax guidelines, please refer to the ‘14.ROS Basics Lesson’.

3. Select Mapping Method

    <arg name="slam_methods" default="gmapping" doc="slam type 
        [gmapping, cartographer, hector, karto, frontier, explore, rrt_exploration, rtabmap]"/>

    <arg name="gmapping"        default="gmapping"/>
    <arg name="cartographer"    default="cartographer"/>
    <arg name="hector"          default="hector"/>
    <arg name="karto"           default="karto"/>
    <arg name="frontier"        default="frontier"/>
    <arg name="explore"         default="explore"/>
    <arg name="rrt_exploration" default="rrt_exploration"/>
    <arg name="rtabmap"         default="rtabmap"/>

The slam_methods parameter represents the mapping method, with the default value being ‘gmapping.’ The available mapping methods include:

Manual mapping: gmapping, cartographer, hector and karto

Autonomous mapping: frontier and explorerrt_exploration

3D mapping: rtabmap

If using the ‘gmapping’ mapping method, the command line in the terminal when executing this launch file would be:

roslaunch hiwonder_slam slam.launch slam_methods:=gmapping

Here, slam_methods:=[mapping method name] can be modified according to the desired mapping method, for example: slam_methods:=karto.

Based on the current game, the recommended mapping method to choose is slam_methods:= explore.

4. Initiate Mapping Function and Related Topic Configuration

    <include file="$(find hiwonder_slam)/launch/include/slam_base.launch">
        <arg name="sim"             value="$(arg sim)"/>
        <arg name="slam_methods"    value="$(arg slam_methods)"/>
        <arg name="robot_name"      value="$(arg robot_name)"/>
    </include>

Upon choosing the mapping method ‘slam_methods,’ the mapping function needs to be initiated through ‘slam_base.launch,’ and the relevant topic name should be configured.

As depicted in the figure above, <sim> denotes whether simulation is employed, referring to the aforementioned ‘sim’ parameter. The default is ‘false,’ indicating that node simulation is not initiated. <slam_methods> designates the mapping method, and for this case, it is set to “explore.” <robot_name> represents the node name of the robot.

The image below illustrates the ‘explore’ section in ‘slam_base.launch.’ The subsequent part of this summary elaborates on its main content.

        <group if="$(eval slam_methods == 'explore')">
            <include file="$(find hiwonder_slam)/launch/include/gmapping.launch">
                <arg name="scan"        value="$(arg scan_topic)"/>
                <arg name="base_frame"  value="$(arg base_frame)"/>
                <arg name="odom_frame"  value="$(arg odom_frame)"/>
                <arg name="map_frame"   value="$(arg map_frame)"/>
            </include>
            <include file="$(find hiwonder_slam)/launch/include/$(arg slam_methods).launch">
                <arg name="map_topic"               value="$(arg map_topic)"/>
                <arg name="base_frame"              value="$(arg base_frame)"/>
                <arg name="costmap_topic"           value="$(arg costmap_topic)"/>
                <arg name="costmap_updates_topic"   value="$(arg costmap_updates_topic)"/>
            </include>
            <!-- 启动路径规划算法包(start path planning algorithm) -->
            <include file="$(find hiwonder_navigation)/launch/include/move_base.launch">
                <arg name="cmd_vel_topic"                   value="$(arg cmd_vel_topic)"/>
                <arg name="global_costmap_map_topic"        value="$(arg map_topic)"/>
                <arg name="global_costmap_sensor_frame"     value="$(arg base_frame)"/>
                <arg name="global_costmap_sensor_topic"     value="$(arg scan_topic)"/>
                <arg name="global_costmap_global_frame"     value="$(arg map_frame)"/>
                <arg name="global_costmap_robot_base_frame" value="$(arg base_frame)"/>
                <arg name="local_costmap_map_topic"         value="$(arg map_topic)"/>
                <arg name="local_costmap_sensor_frame"      value="$(arg base_frame)"/>
                <arg name="local_costmap_sensor_topic"      value="$(arg scan_topic)"/>
                <arg name="local_costmap_global_frame"      value="$(arg odom_frame)"/>
                <arg name="local_costmap_robot_base_frame"  value="$(arg base_frame)"/>
                <arg name="virtual_wall_map_frame"          value="$(arg map_frame)"/>
                <arg name="teb_odom_topic"                  value="$(arg odom_topic)"/>
                <arg name="teb_map_frame"                   value="$(arg odom_frame)"/>
            </include>
        </group>

The code snippet displayed in the above image utilizes three launch files:

  1. gmapping.launch: For a detailed explanation of the primary content, please consult the “Analysis of Gmapping Mapping Algorithm Launch File.”

  2. The launch folder in the function package hiwonder_slam within this game includes a folder named include. For specifics, please refer to Map Construction Method Parameter Configuration.

  3. move_base.launch: This launch file handles the robot’s posture planning during the mapping process. For a comprehensive understanding, please review the “move_base.launch file analysis” in the current tutorial folder.

    For the precise contents of the slam_base.launch file, kindly refer to the “slam_base.launch Program Analysis.”

5. Mapping Method Parameter Configuration

Using the functionality provided in this game, you can find the location of the ‘explore.launch’ file at: ‘hiwonder_slam/launch/include/explore.launch

    <arg name="base_frame"              default="base_footprint"/>
    <arg name="costmap_topic"           default="map"/>
    <arg name="costmap_updates_topic"   default="map_updates"/>
    <arg name="map_topic"               default="map"/>
    <arg name="map_save_path"           default="$(find hiwonder_slam)/maps/explore"/>

The key point to note is the ‘map_save_path.’ After completing the mapping using the Explore_Lite algorithm, the map is not automatically saved through instructions. The default location for saving the map is ‘hiwonder_slam/maps/explore.’ Typically, commands are used to save the map.

    <node pkg="explore_lite" type="explore" respawn="false" name="explore" output="screen">
        <param name="map_topic"             value="$(arg map_topic)"/>
        <param name="map_save_path"         value="$(arg map_save_path)"/>
        <param name="robot_base_frame"      value="$(arg base_frame)"/>
        <param name="costmap_topic"         value="$(arg costmap_topic)"/>
        <param name="costmap_updates_topic" value="$(arg costmap_updates_topic)"/>
        <param name="visualize"             value="true"/>
        <param name="planner_frequency"     value="0.33"/>
        <param name="progress_timeout"      value="20.0"/>
        <param name="potential_scale"       value="3.0"/>
        <param name="orientation_scale"     value="0.0"/>
        <param name="gain_scale"            value="1.0"/>
        <param name="transform_tolerance"   value="0.3"/>
        <param name="min_frontier_size"     value="0.5"/>
    </node>

In addition to the topic parameter settings for the map, robot coordinates, and cost map, attention should also be given to the following parameters:

  1. <planner_frequency>: Path planner frequency, with a value of 0.33. Typically, adjusting this parameter is done to control the speed of the robot’s autonomous mobile mapping and the frequency of map updates. An excessively large or small value can impact the robot’s movement direction and mapping speed.

  2. <progress_timeout>: Function package running timeout, set to 20 seconds. In the event of program termination due to abnormality or a stuck process, there is a 20-second detection time. If this time is exceeded, the current function package will abandon the current goal and continue running.

  3. <potential_scale>: Distance weight to the boundary, with a value of 3.0. While directly changing this value won’t affect the judgment of the safe distance to the boundary, it is recommended to keep the default setting.

  4. <orientation_scale>: Distance weight of the robot’s frontier direction, with a value of 0.0.

  5. <gain_scale\>: Boundary gain value, set to 1.0. As a multiplicative gain value, it does not affect the value of potential_scale.

  6. <transform_tolerance>: Turning tolerance of the robot during movement, set to 0.3. It is advisable to retain the default value.

  7. <min_frontier_size>: Minimum threshold for the size of the boundary, with a value of 0.5. It is recommended to keep the default setting.

Note

Note: It is recommended to maintain the default settings for the above parameters. Modifying them independently is not advised, as it may impact the effectiveness of the game!!!

6.1.8 RRT Exploration Mapping

  • RRT Description

The term “RRT” refers to the Rapidly Expanding Random Tree Algorithm, a widely utilized motion planning algorithm over the past decade. This algorithm employs a probability-based sampling approach to navigate through the state space, utilizing random sampling points to guide the search towards unexplored regions. The primary objective is to establish a planned path from the starting point to the target point, while also conducting collision detection on sampled points in the state space, eliminating the need for space modeling.

The original RRT algorithm initiates with an initial point as the root node and generates a random expansion by sampling and adding leaf nodes. As the tree expands, if a leaf node reaches the target point or enters the target area, it becomes part of the tree. The planned path from the initial to the target point is then determined through backtracking within the random tree structure.

It works following the steps below:

  1. Begin by creating a tree with the starting point as the root node and defining the target point.

  2. Retrieve map data.

  3. Randomly select a point on the map, denoted as p_rand.

  4. Traverse the entire existing tree to identify the point closest to p_rand, marked as p_near.

  5. Extend the distance from p_near to the random point p_rand by one step, with the step length recorded as Delta. This results in a new point, labeled as p_new.

  6. Check if the newly created point, p_new, lies on an obstacle. If it does, exit this loop and restart from step 3.

  7. Integrate the newly generated point, p_new, into the entire tree.

  8. If the distance from the p_new point to the target point falls below a specific threshold, conclude the search and visualize the entire path.

RRT Software Pack:

https://github.com/RoboJackets/rrt

  • Mapping Operation Steps

Note

Notice:

  • Prior to initiating, ensure the construction of a sealed environment and preposition the robot inside. It is crucial to maintain airtight conditions!

  • When entering commands, strict case sensitivity is required, and the “Tab” key can be used to auto-complete keywords.

1. Enable Service

  1. Start the robot, and access the robot system desktop using NoMachine.

  2. Double click to open the command line terminal.

  3. Execute the command “sudo systemctl stop start_app_node.service” and press Enter to disable app auto-start service.

    sudo systemctl stop start_app_node.service
    
  4. Open a new terminal, and execute the command “roslaunch hiwonder_slam slam.launch slam_methods:=rrt_exploration” to enable mapping service.

Note

Note: Once you activate the mapping service, the robot will autonomously plan a path and commence mapping. Therefore, ensure to position it on the ground before powering it on.

roslaunch hiwonder_slam slam.launch slam_methods:=rrt_exploration
  1. Open a new command-line terminal window and execute the command ‘roslaunch hiwonder_slam rviz_slam.launch slam_methods:=rrt_exploration’ to launch the model viewing software.

    roslaunch hiwonder_slam rviz_slam.launch slam_methods:=rrt_exploration
    

2. Start Mapping

  1. To initiate, select the option highlighted in the red box at the top of the window, as illustrated below. Subsequently, click on an blank area on the map. It is essential to set a total of five points. The first four points define the exploration area, while the fifth point serves as the starting point for positioning (ensure to click in front of the car, avoiding clicking directly on the car). Once these settings are configured, commence the exploration and mapping process.

3. Save the Map

  1. Open a new terminal and input the command “roscd hiwonder_slam/maps” and press Enter to navigate to the folder where the map is stored.

    roscd hiwonder_slam/maps
    
  2. Execute the command ‘rosrun map_server map_saver map:=/robot_1/map -f map_01’ and press Enter to save the map.

    rosrun map_server map_saver map:=/robot_1/map -f map_01
    

The term “robot_1” in the command represents the robot name, while “map_01” designates the map name. Users can rename them according to their preferences. The appearance of the following prompt confirms the successful saving of the map.

  1. If you want to stop running the program, you can press “Ctrl+C”.

  2. To enable the app service, execute the command ‘sudo systemctl start start_app_node.service’.

    sudo systemctl start start_app_node.service
    

4. Optimize Program Outcome

For enhanced mapping precision, consider optimizing the odometer settings. The robot’s mapping process heavily relies on the Lidar, and the odometer’s functionality is closely tied to Lidar operations.

The calibrated IMU (Inertial Measurement Unit) data has been successfully integrated into the robot’s system, enabling both mapping and navigation. However, to achieve even greater accuracy, it’s advisable to calibrate the IMU. Detailed instructions on how to perform IMU calibration are available in “3 Chassis Motion Control Lesson\3.2 Motion Control\3.2.1 IMU, Linear Velocity and Angular Velocity Calibration”.

  • Parameter Description

You can access the parameter file at the following path: “hiwonder_slam/launch/include/rrt_exploration.launch.”

maxUrange: Intercept the laser range, clipping laser data to this value.

maxRange: Laser range; if the area within the laser range without obstacles should be displayed as free space on the map, set maxUrange < the maximum range of the actual radar <= maxRange.

sigma: Sigma value for the greedy endpoint matching method.

kernelSize: Kernel size for finding laser matching relationships.

lstep: Optimization step size for translation.

astep: 0.05

iterations: 1

lsigma: 0.075

ogain: 3.0

lskip: 0 means all lasers are processed and should be as close to zero as possible. If the calculated pressure is too high, it can be changed to 1.

minimumScore: Score measuring the scan matching effect. Higher values increase the requirements for the laser matching algorithm, making it more prone to failure and switch to using odometer data. Setting it too low can introduce noise in the map.

srr: Linear error of the odometry in the linear equation.

srt: Linear error of the odometry in the rotation equation.

str: Odometer rotation error in the linear equation.

stt: Rotation error of the odometer in the rotation equation.

linearUpdate: The robot performs a scan when it runs this far in a straight line; unit is meters.

angularUpdate: Scan once when the robot rotates this much; unit is radians.

temporalUpdate: -1.0

resampleThreshold: 0.5

particles: Number of particles; a crucial parameter.

xmin: Minimum initial map size (m).

ymin: Minimum initial map size (m).

xmax: Maximum initial map size (m).

ymax: Maximum initial map size (m).

delta: Map resolution.

llsamplerange: Shift the likelihood domain of the sampling range.

llsamplestep: Shift the likelihood domain of the sampling step.

  • Launch File Analysis

1. Path

According to the game, the main files involved are as follows:

  1. slam.launch: Selects the mapping method (Location: /ros_ws/src/hiwonder_slam/launch/slam.lauch)

  2. slam_base.launch: Basic topic configuration and startup for mapping functionalities(Location: /ros_ws/src/hiwonder_slam/launch/include/slam_base.launch)

  3. rrt_exploration:Specific topic and parameter configuration for the mapping method(Location: hiwonder_slam/launch/include/rrt_exploration.launch

2. Structure

The file structure is as below:

Reviewing the document structure, the focus is on selecting mapping methods, initiating mapping functionalities, configuring relevant topics, and adjusting mapping method parameters. For detailed syntax guidelines, please refer to the ‘ROS Basics Lesson’.

3. Select Mapping Method

It corresponds to slam.launch file.

    <arg name="slam_methods" default="gmapping" doc="slam type 
        [gmapping, cartographer, hector, karto, frontier, explore, rrt_exploration, rtabmap]"/>

    <arg name="gmapping"        default="gmapping"/>
    <arg name="cartographer"    default="cartographer"/>
    <arg name="hector"          default="hector"/>
    <arg name="karto"           default="karto"/>
    <arg name="frontier"        default="frontier"/>
    <arg name="explore"         default="explore"/>
    <arg name="rrt_exploration" default="rrt_exploration"/>
    <arg name="rtabmap"         default="rtabmap"/>

Prior to constructing a map, it is crucial to select a mapping method, as illustrated in the figure above:

The slam_methods parameter represents the mapping method, with the default value being ‘gmapping.’ The available mapping methods include:

Manual mapping: gmapping, cartographer, hector and karto

Autonomous mapping: frontier and explorerrt_exploration

3D mapping: rtabmap

If using the ‘gmapping’ mapping method, the command line in the terminal when executing this launch file would be:

roslaunch hiwonder_slam slam.launch slam_methods:=gmapping

Here, slam_methods:=[mapping method name] can be modified according to the desired mapping method, for example: slam_methods:=karto.

Based on the current game, the recommended mapping method to choose is slam_methods:= rrt_exploration.

4. Initiate Mapping Function and Related Topic Configuration

    <include file="$(find hiwonder_slam)/launch/include/slam_base.launch">
        <arg name="sim"             value="$(arg sim)"/>
        <arg name="slam_methods"    value="$(arg slam_methods)"/>
        <arg name="robot_name"      value="$(arg robot_name)"/>
    </include>

Once the mapping method slam_methods has been selected, initiate the mapping function by executing slam_base.launch and configuring the relevant topic name.

In the provided example, <sim> denotes whether simulation is utilized, referencing the parameter sim. The default value is false, indicating that the node simulation is not activated. <slam_methods> specifies the mapping method, and for this specific case, it is set to “rrt_exploration”. <robot_name> represents the node name of the robot.

Refer to the image below for the section related to rrt_exploration within slam_base.launch. The subsequent section of this summary outlines its primary content.

        <group if="$(eval slam_methods == 'rrt_exploration')">
            <include file="$(find hiwonder_slam)/launch/include/gmapping.launch">
                <arg name="scan"        value="$(arg scan_topic)"/>
                <arg name="base_frame"  value="$(arg base_frame)"/>
                <arg name="odom_frame"  value="$(arg odom_frame)"/>
                <arg name="map_frame"   value="$(arg map_frame)"/>
            </include>
            <!-- 启动路径规划算法包(start path planning algorithm) -->
            <include file="$(find hiwonder_navigation)/launch/include/move_base.launch">
                <arg name="cmd_vel_topic"                   value="$(arg cmd_vel_topic)"/>
                <arg name="global_costmap_map_topic"        value="$(arg map_topic)"/>
                <arg name="global_costmap_sensor_frame"     value="$(arg base_frame)"/>
                <arg name="global_costmap_sensor_topic"     value="$(arg scan_topic)"/>
                <arg name="global_costmap_global_frame"     value="$(arg map_frame)"/>
                <arg name="global_costmap_robot_base_frame" value="$(arg base_frame)"/>
                <arg name="local_costmap_map_topic"         value="$(arg map_topic)"/>
                <arg name="local_costmap_sensor_frame"      value="$(arg base_frame)"/>
                <arg name="local_costmap_sensor_topic"      value="$(arg scan_topic)"/>
                <arg name="local_costmap_global_frame"      value="$(arg odom_frame)"/>
                <arg name="local_costmap_robot_base_frame"  value="$(arg base_frame)"/>
                <arg name="virtual_wall_map_frame"          value="$(arg map_frame)"/>
                <arg name="teb_odom_topic"                  value="$(arg odom_topic)"/>
                <arg name="teb_map_frame"                   value="$(arg odom_frame)"/>
            </include>
            <!-- 启动自探索建图算法包(start autonomous exploring mapping algorithm) -->
            <include file="$(find hiwonder_slam)/launch/include/rrt_exploration.launch">
                <arg name="namespace"       value="$(arg robot_prefix)"/>
                <arg name="n_robots"        value="$(arg robot_number)"/>
                <arg name="map_topic"       value="$(arg map_topic)"/>
                <arg name="odom_topic"      value="$(arg odom_topic)"/>
                <arg name="robot_base"      value="$(arg base_frame)"/>
                <arg name="global_frame"    value="$(arg map_frame)"/>
            </include>
        </group>

The code snippet displayed in the above image utilizes three launch files:

  1. gmapping.launch: Refer to “Analysis of Gmapping Mapping Algorithm Launch File” for detailed information on the main content.

  2. move_base.launch: Explore the robot posture planning aspects during the mapping process by referring to the “move_base.launch file analysis” in the current tutorial folder.

  3. The hiwonder_slam function package for this game contains a folder named include. Delve into the details by consulting Mapping Method Parameter Configuration.

    For specific contents within the slam_base.launch file, consult “slam_base.launch Program Analysis.”

5. Mapping Method Parameter Configuration

Within the function package of this game, you can find the rrt_exploration.launch file at the following location: “hiwonder_slam/launch/include/rrt_exploration.launch.”

The subsequent figure displays pertinent topics, the name of the robot coordinate system, and the initialization of logical parameters.

    <arg name="eta"                     value="0.5"/>
    <arg name="Geta"                    value="2.0"/>
    <arg name="map_topic"               default="map"/>
    <arg name="odom_topic"              default="odom"/>
    <arg name="robot_base"              default="base_footprint"/>
    <arg name="global_frame"            default="map"/>
    <arg name="namespace"               default="/robot_"/>
    <arg name="n_robots"                default="1"/>
    <arg name="robot_name"              value="$(arg namespace)$(arg n_robots)"/>
    <param name="namespace_init_count"  value="1"/>
  1. <eta>: Boundary growth rate, utilized for detecting the growth rate of RRT. A larger value makes the RRT planning algorithm traverse branches more quickly, but it also increases the computational load. The default value is 0.5, and it is recommended to keep it as such.

  2. <Geta>: The lateral weight value of the boundary growth rate, used in conjunction with eta.

  3. <map_topic>: Map topic message, <odom_topic>: Odometer topic message, <robot_base>: Machine <global_frame>: Human initial attitude message in the global coordinate system.

  4. <namespace>: Robot namespace, <n_robots>: Robot number settings, <robot_name>: Robot name, <namespace_init_count>: Initialize namespace count.

The accompanying figure illustrates the initiation of the rrt global detector and rrt local detector function packages along with relevant parameter settings.

    <node pkg="rrt_exploration" type="global_rrt_detector" name="global_detector" output="screen">
        <param name="eta"               value="$(arg Geta)"/>
        <param name="map_topic"         value="$(arg map_topic)"/>
        <param name="clicked_point"     value="/$(arg robot_name)/clicked_point"/>
        <param name="detected_points"   value="detected_points"/>
        <param name="shapes"            value="/$(arg robot_name)/global_detector_shapes"/>
    </node>
    
    <node pkg="rrt_exploration" type="local_rrt_detector" name="local_detector" output="screen">
        <param name="eta"               value="$(arg eta)"/>
        <param name="map_topic"         value="$(arg map_topic)"/>
        <param name="robot_frame"       value="$(arg robot_base)"/>
        <param name="clicked_point"     value="/$(arg robot_name)/clicked_point"/>
        <param name="detected_points"   value="detected_points"/>
        <param name="shapes"            value="/$(arg robot_name)/local_detector_shapes"/>
    </node>

For analogous parameter and variable names, please consult the prior point and maintain the default parameters.

The subsequent figure illustrates the execution file (filter.py) for the boundary filtering algorithm of the RRT algorithm.

    <node pkg="rrt_exploration" type="filter.py" name="filter" output="screen">
        <param name="map_topic"                     value="$(arg map_topic)"/>
        <param name="robot_frame"                   value="base_footprint"/>
        <param name="info_radius"                   value="0.8"/>
        <param name="costmap_clearing_threshold"    value="70"/>
        <param name="goals_topic"                   value="/$(arg robot_name)/detected_points"/>
        <param name="namespace"                     value="/$(arg namespace)"/>
        <param name="n_robots"                      value="$(arg n_robots)"/>
        <param name="rate"                          value="100"/>
        <param name="global_costmap_topic"          value="/move_base/global_costmap/costmap"/>
    </node>
  1. <info_radius>: The boundary expansion range is increased by 0.8 times based on the original grid.

  2. <costmap_clearing_threshold>: Cost map clearing threshold. If the cost of the detected map result is below this specified value, the identified unit will be disregarded in raster information.

  3. <goals_topic>: RRT detector target point topic.

  4. <rate>: RRT detector detection update frequency.

  5. <global_costmap_topic>: Global cost map topic.

The accompanying figure displays the execution file (assigner.py) for setting the priority of the robot’s movement direction.

    <node pkg="rrt_exploration" type="assigner.py" name="assigner" output="screen">
        <param name="map_topic"                 value="$(arg map_topic)"/>
        <param name="global_frame"              value="$(arg global_frame)"/>
        <param name="robot_frame"               value="base_footprint"/>
        <param name="info_radius"               value="1"/>
        <param name="info_multiplier"           value="3.0"/>
        <param name="hysteresis_radius"         value="3.0"/>
        <param name="hysteresis_gain"           value="2.0"/>
        <param name="frontiers_topic"           value="/$(arg robot_name)/filtered_points"/>
        <param name="n_robots"                  value="$(arg n_robots)"/>
        <param name="namespace"                 value="/$(arg namespace)"/>
        <param name="delay_after_assignement"   value="0.5"/>
        <param name="rate"                      value="100"/>
        <param name="plan_service"              value="/move_base/GlobalPlanner/make_plan"/>
    </node>
  1. <info_radius>: The boundary expansion range is increased by 0.8 times based on the original grid.

  2. <info_multiplier>: Border polygon expansion, with the expansion value set to 3.0.

  3. <hysteresis_radius>: The Lidar scanning retention radius, which cannot be lower than the Lidar scanning radius and is generally set to 3.0.

  4. <hysteresis_gain>: Lidar scanning gain, typically set to 2.0.

  5. <frontiers_topic>: Information messages regarding the frontier direction of the robot.

  6. <plane_service>: Path message service

The following image depicts the main contents of the executable file for saving the map after RRT exploration.

    <node pkg="hiwonder_slam" type="rrt_map_save.py" name="map_save" output="screen">
        <param name="map_frame"         value="$(arg global_frame)"/>
        <param name="odom_topic"        value="$(arg odom_topic)"/>
        <param name="clicked_point"     value="/$(arg robot_name)/clicked_point"/>
        <param name="wait_finish_time"  value="5"/>
    </node>
  1. <clicked_point> defines five points in the area. The first four points represent the corners of the square areas to be explored, while the last point designates the starting point of the tree, indicating where the robot commences its operation.

  2. <wait_finish_time> denotes the waiting time for messages after reaching the target. Although this parameter is flexible, it is advisable to set it greater than 3 seconds to ensure the complete establishment of the map.

Note

Note: It is recommended to maintain the default settings for the above parameters. Modifying them independently is not advised, as it may impact the effectiveness of the game!!!

6.1.9 ORBSLAM2 and ORBSLAM3 Mapping

  • ORBSLAM2 and ORBSLAM3 Description

ORB-SLAM2 for binocular and RGB-D cameras is an extension of our monocular feature ORB-SLAM. The system overview is depicted in the figure, and it primarily operates with three parallel threads:

  1. Tracking Thread: Tracks the camera in each frame by identifying features that match the local map and minimizing the reprojection error.

  2. Local Mapping Thread: Manages the local map and optimizes it by performing local Bundle Adjustment (BA).

  3. Loop Closure Thread: Detects large loops and corrects accumulated drift through pose graph optimization. This thread initiates the fourth thread, which conducts full Bundle Adjustment after optimizing the pose graph, ultimately calculating the optimal Structure-from-Motion (SfM) solution.

The system relies on ORB features for tracking, mapping, and location identification. These features demonstrate robustness to rotation and scaling, invariance to camera auto-gain and auto-exposure, as well as adaptability to lighting changes. Feature extraction and matching are fast, allowing real-time operation with good precision/recall performance in bag-of-words location recognition.

Development Status: ORB-SLAM2 currently achieves high accuracy and outperforms other methods in the KITTI visual odometry benchmark, particularly excelling in achieving zero-drift positioning in previously mapped areas.

Comparison with ORB-SLAM3:

Feature Extraction and Descriptors: ORB-SLAM2 uses ORB features and descriptors, whereas ORB-SLAM3 employs SuperPoint features and SuperPoint descriptors, based on convolutional neural networks for enhanced robustness and accuracy.

Attitude Estimation: ORB-SLAM2 utilizes the EPnP algorithm for attitude estimation, while ORB-SLAM3 opts for the PnP algorithm, known for greater efficiency and accuracy.

Semantic Information: ORB-SLAM3 supports the input and processing of semantic information, allowing the integration of semantic data with visual information to enhance the SLAM system’s robustness and accuracy.

Multi-Camera System: ORB-SLAM3 supports mapping and positioning for multi-camera systems, processing visual information from multiple cameras simultaneously.

The following figure is a system overview diagram of ORB-SLAM3, which includes ORB-SLAM2.

The process involves the following steps:

  1. ORB Feature Extraction:

Extract ORB features from the image.

  1. Pose Estimation:

Perform pose estimation based on the previous frame or initialize the pose through global relocation.

  1. Local Map Tracking:

Track the reconstructed local map based on the estimated pose.

  1. Pose Optimization:

Optimize the pose and determine new keyframes.

  1. Map Point Generation:

Insert new keyframes into the map to generate new map points.

  1. Map Verification:

Verify the map and delete redundant keyframes.

  1. Local Map Generation:

Obtain the local map for matching.

  1. Matching:

Perform matching on the local maps.

  1. Map Fusion:

Fuse the maps together.

  1. Global Map Adjustment:

Adjust the global map based on the fused maps.

  1. ORBSLAM2 software pack:https://github.com/ethz-asl/orb_slam_2_ros

  2. ORBSLAM3 software pack:https://github.com/shanpenghui/ORB_SLAM3_Fixed

  • Mapping Operation Steps

1. Enable ORBSLAM2 Mapping

  1. Start the robot, and access the robot system desktop using NoMachine.

  2. Double click to open the command line terminal.

  3. Execute the command “sudo systemctl stop start_app_node.service” and press Enter to disable app auto-start service.

    sudo systemctl stop start_app_node.service
    
  4. Open a new terminal, and execute the command “roslaunch hiwonder_example orb_slam2_rgbd.launch” to enable mapping service.

    roslaunch hiwonder_example orb_slam2_rgbd.launch
    

When the window below appears, it indicates that the service has been successfully enabled.

  1. Open a new command-line terminal window and execute the command ‘roslaunch hiwonder_peripherals teleop_key_control.launch robot_name:=/’ to enable the keyboard control service.

    roslaunch hiwonder_peripherals teleop_key_control.launch robot_name:=/
    

When the following prompt occurs, it means the keyboard control service is enabled successfully.

  1. Control the robot to move around to map the whole environment by pressing the corresponding keys.

Key Robot’s Action
W Go forward (Press briefly)
S Go backward (Press briefly)
A Turn left (Long press)
D Turn right (Long press)
  1. Controlling the robot’s movements via the keyboard allows you to observe an increase in the collection of feature points, enhancing the potential for three-dimensional modeling.

  1. Use the short-cut ‘Ctrl+C’ to terminate each program running on different terminal.

2. Enable ORBSLAM3 Mapping

  1. Start the robot, and access the robot system desktop using NoMachine.

  2. Double click to open the command line terminal.

  3. Execute the command “sudo systemctl stop start_app_node.service” and press Enter to disable app auto-start service.

    sudo systemctl stop start_app_node.service
    
  4. Open a new command line terminal, and execute the command ‘roslaunch hiwonder_example orb_slam3_rgbd.launch’, then hit Enter to enable the mapping service.

    roslaunch hiwonder_example orb_slam3_rgbd.launch
    

When the interface below appears, it indicates that the service has been successfully enabled.

  1. Open a new command-line terminal, and execute this command ‘roslaunch hiwonder_peripherals teleop_key_control.launch robot_name:=/’ to enable the keyboard control service.

    roslaunch hiwonder_peripherals teleop_key_control.launch robot_name:=/
    

When the following prompt occurs, it means the keyboard control service is enabled successfully.

  1. Control the robot to move around to map the whole environment by pressing the corresponding keys.

Key Robot’s Action
W Go forward (Press briefly)
S Go backward (Press briefly)
A Turn left (Long press)
D Turn right (Long press)
  1. Controlling the robot’s movements via the keyboard allows you to observe an increase in the collection of feature points, enhancing the potential for three-dimensional modeling.

  1. Utilize the shortcut ‘Ctrl+C’ to terminate each program running on different terminals.

6.1.10 RTAB-VSLAM 3D Mapping & Navigation

  • RTAB-VSLAM Description

RTAB-VSLAM is an appearance-based real-time 3D mapping open-source library. It implements loop closure detection through memory management methods. The map size is constrained to ensure loop closure detection is consistently processed within a fixed time limit. This approach satisfies the demands for online mapping of extensive and enduring environments.

  • RTAB-VSLAM Working Principle

RTAB-VSLAM 3D mapping employs feature mapping, offering the advantage of rich feature points in general scenes, good scene adaptability, and the ability to use feature points for localization. However, it has drawbacks, such as a time-consuming feature point calculation method, limited information usage leading to loss of image details, diminished effectiveness in weak-texture areas, and susceptibility to feature point matching errors, impacting results significantly.

After extracting features from images, the algorithm proceeds to match features at different timestamps, leading to loop detection. Upon completion of matching, data is categorized into long-term memory and short-term memory. Long-term memory data is utilized for matching future data, while short-term memory data is employed for matching current time-continuous data.

During the operation of the RTAB-VSLAM algorithm, it initially uses short-term memory data to update positioning points and build maps. As data from a specific future timestamp matches long-term memory data, the corresponding long-term memory data is integrated into short-term memory data for updating positioning and map construction.

RTAB-VSLAM software package link: https://github.com/introlab/rtabmap

  • Enable Lidar Mapping

  1. Start the robot, and access the robot system desktop using NoMachine.

  2. Double click to open the command line terminal.

  3. Execute the command “sudo systemctl stop start_app_node.service” and press Enter to disable app auto-start service.

    sudo systemctl stop start_app_node.service
    
  4. Open a new terminal, and execute the command “roslaunch hiwonder_slam slam.launch slam_methods:=rtabmap” to enable mapping service.

    roslaunch hiwonder_slam slam.launch slam_methods:=rtabmap
    
  5. Open a new command-line terminal window and execute the command ‘roslaunch hiwonder_slam rviz_slam.launch slam_methods:=rtabmap’ to launch the model viewing software.

    roslaunch hiwonder_slam rviz_slam.launch slam_methods:=rtabmap
    

While constructing the map, you can observe the point cloud data captured by the depth camera, as shown below:

  1. Open a new command-line terminal, and execute this command ‘roslaunch hiwonder_peripherals teleop_key_control.launch robot_name:=/’ to enable the keyboard control service.

    roslaunch hiwonder_peripherals teleop_key_control.launch robot_name:=/
    

When the following prompt occurs, it means the keyboard control service is enabled successfully.

  1. Control the robot to move around to map the whole environment by pressing the corresponding keys.

Key Robot’s Action
W Go forward (Press briefly)
S Go backward (Press briefly)
A Turn left (Long press)
D Turn right (Long press)
  1. After mapping, utilize the shortcut ‘Ctrl+C’ to terminate each program running on different terminals.

Note

Note: 3D mapping does not require manual saving of the map. When you use “Ctrl+C” to terminate the mapping command, the map will be automatically saved.

After completing the game experience, you can initiate the mobile APP service through commands or restart the robot. The mobile APP functions will be inactive if the service is not turned on. (The mobile APP service will automatically start if the robot is restarted.)

To restart the mobile APP service, enter the command “sudo systemctl restart start_app_node.service” and wait for a single beep from the buzzer, indicating that the service startup is complete.

sudo systemctl restart start_app_node.service

6.1.11 App Mapping

This section will provide instructions on controlling the robot to build the map using ‘Make A Map’.

  • APP Installation

The installation packages for the mobile apps ‘Make A Map’ and ‘Map Nav’ are located in the directory ‘Mapping Navigation Lesson -> App Installation Package’. Users can import these packages into their mobile phones for installation.

Note

Note: Only installation packages for Android systems are provided for the app.

If you open the mapping, click on desktop icon to verify the Lidar model (The default Lidar model is “G4”). If the Lidar has been changed, update the Lidar model to the corresponding one and save the changes for them to take effect.

  • App Mapping

1. Enable Service

  1. Start the robot, and access the robot system desktop using NoMachine.

  2. Double click to open the command line terminal.

  3. Execute the command “sudo systemctl stop start_app_node.service” and press Enter to disable app auto-start service.

    sudo systemctl stop start_app_node.service
    
  4. Open a new command-line terminal, and execute the command ‘roslaunch hiwonder_slam slam.launch app:=true’ to enable the mapping service.

    roslaunch hiwonder_slam slam.launch app:=true
    
  1. Utilize the shortcut ‘Ctrl+C’ to terminate each program running on different terminals.

2. Make A Map Connection

  1. Connect to the WiFi generated by the robot in settings. Password is “hiwonder”.

  1. Open “Make A Map” app, and select “http://192.168.149.1:11311/” in “Master URI” field, then click “CONNECT”.

3. Introduction to Make A Map

Note

Note:

  • The icon enclosed in red frame in below figure serves no practical purpose. To save the map, refer to step 11.2.4.

  • If there is no map on the yellow frame, you can click-on to check whether the Lidar model is correct. The default Lidar model set in the system image is G4. If the Lidar you are using other Lidar model, please change it to corresponding model.

The app interface is divided into three zones. The live camera feed is displayed in the green frame, the map is display on the yellow frame, and the blue frame is for controlling the robot.

  1. Drag the arrow in the blue frame to control robot to move and map.

  2. The map robot makes is displayed on the yellow frame. Robot speed will be displayed on the blue frame.

4. Save Map

  1. Return to NoMachine interface, and double-click to open command-line terminal.

  2. Open a new command-line terminal, and execute the command “roscd hiwonder_slam/maps” and press Enter to save the map to the corresponding folder.

    roscd hiwonder_slam/maps
    
  3. Input command “rosrun map_server map_saver map:=/map -f map_01” and press Enter to save the map.

    rosrun map_server map_saver map:=/map -f map_01
    

map_01” is the name of the map, and you can rename the map. If the following hints occur, the map is saved successfully.

  1. After experiencing the game, you can execute the command or restart the robot to enable app service. Please note that the app functions of the robot will be invalid if the app service is not enabled.

Execute this command “sudo systemctl restart start_app_node.service” to restart the app service.

sudo systemctl restart start_app_node.service