Skip to content

SLAM Map Building (Gazebo)

Hint

The operating environment and software and hardware configurations are as follows:

  • PC:Ubuntu (≥20.04) + ROS2 (≥Foxy)

Start the Gazebo simulation environment

Open a new terminal on the PC and enter the following command in the terminal to start the Gazebo simulation environment:

$ ros2 launch originbot_gazebo originbot_navigation_gazebo.launch.py

Wait a few moments, and once you have successfully started, you will see the simulation environment containing the robot model:

image-20230705204647105

Start SLAM and visualization display

Open a new terminal on the PC and enter the following command in the terminal to start the cartographer mapping algorithm:

$ ros2 launch originbot_navigation cartographer_gazebo.launch.py

image-20230705215512805

Hint

Make sure that the originbot_desktop code repository has been downloaded and compiled on the PC side. If it is not convenient to use originbot_desktop code repository, you can also use "ros2 run rviz2 rviz2" to start Rivz2 separately ,and manually add display plug-ins such as map, tf, and laserscan, which can also achieve a similar effect.

Keyboard control mapping

In order for the robot to establish a complete picture of its surroundings, we also need to start a keyboard control node:

$ ros2 run teleop_twist_keyboard teleop_twist_keyboard

Now, we can click the up, down, left and right keys of the keyboard in the keyboard control terminal to control the robot to explore the unknown environment, and the whole map will gradually appear in Rviz.

image-20230705215714453

Save the map

Once the map is complete, you can use the following commands to save the map:

$ ros2 run nav2_map_server map_saver_cli -t map -f cloister

image-20230705220027386

Info

The above command will save the map to the current path of the terminal, and it needs to be copied to the originbot_navigation function package before subsequent navigation use.

图片1