SLAM with hector_mapping

Get the real vehicle at our store!



REMINDER: configure your environment before starting this tutorial.


First of all we are going to download hector_mapping ROS package. This package is a SLAM approach that can be used without odometry and even in platforms that exhibit roll/pitch motion (of the sensor, the platform or both). It reads the laser from the rover and returns 2D pose estimation.

Download and compile this package by running:

cd ~/simulation/ros_catkin_ws/src
git clone https://github.com/tu-darmstadt-ros-pkg/hector_slam
cd ~/simulation/ros_catkin_ws
source devel/setup.bash
catkin_make --pkg hector_mapping

Before launching the simulation, we are going to modify to set the base and odom frames for the SLAM node to be able to create the map. Modify hector_mapping/launch/mapping_default.launch and replace

<arg name="base_frame" default="base_footprint"/>
<arg name="odom_frame" default="nav"/>

with

<arg name="base_frame" default="sonar2_link"/>
<arg name="odom_frame" default="sonar2_link"/>

Now, let's launch the simulation.

source ~/simulation/ros_catkin_ws/devel/setup.bash
cd ~/simulation/ardupilot/APMrover2
../Tools/autotest/sim_vehicle.sh -j 4 -f Gazebo
# once MAVProxy has launched completely, load the parameters
param load /[path_to_your_home_directory]/simulation/ardupilot/Tools/Frame_params/3DR_Rover.param
# NOTE: replace [path_to_your_home_directory] with the actual path to your home directory.
# Example: param load /home/john/simulation/ardupilot/Tools/Frame_params/3DR_Rover.param
param set SYSID_MYGCS 1

In another terminal

source ~/simulation/ros_catkin_ws/devel/setup.bash
roslaunch ardupilot_sitl_gazebo_plugin rover_maze.launch

This will spawn the Erle-Rover inside a maze.

Figure 1 - General view of the simulation. The rover will be spawned inside a maze.

Run the SLAM node by running:

cd ~/simulation/ros_catkin_ws
source devel/setup.bash
roslaunch hector_mapping mapping_default.launch

To see the map that the node is publishing, you can use rviz (install it by running sudo apt-get install ros-indigo-rviz if you haven't already):

rosrun rviz rviz

Once rviz has been launched, add a new display (Ctrl+N) and inside the By Topic tab select Map inside /map and press OK.

Figure 2 - Choose /map topic and press OK

Then, on the left panel, in Display>Global Options>Fixed Frame select sonar2_link.

Figure 3 - Select sonar2_link as Fixed Frame

Now you should be able to see the following, which is the partial map generated by the SLAM node:

Figure 4 - Partial map on Rviz

If we want the SLAM node to generate the whole map, we should move the rover through the maze like we did in the 2nd tutorial. Run the explorer node by running:

cd ~/simulation/ros_catkin_ws
source devel/setup.bash
rosrun erle_rover_explorer erle_rover_explorer.py

This will open the following window and start moving the rover trough the maze

Figure 5 - Window frame showing the result of the node

The blue lines represent the laser readings and the red line the direction that the rover needs to follow. The number is simply the angle that the line has with the Y axis.

Once the rover has exited the maze, you should be able to see the final result of the map in rviz.

Figure 6 - Full map on Rviz

Which is pretty similar to the original:

Figure 7 - Original map on Gazebo

If besides simulation, you're interested in translating these behaviors to real scenarios you can purchase the real vehicle at our store