UGV Beast Jetson Orin ROS2 7. Navigation and SLAM Mapping
| ||
This tutorial explains how to use Nav2 with SLAM. The following steps show you how to generate an occupancy raster map and move the robot using Nav2. By default, you have completed the main program and remotely connected to the Docker container according to the content in Chapter 1 UGV Beast Jetson Orin ROS2 1. Preparation.
In a Docker container, start the robot's RViz interface and navigation:
ros2 luanch ugv_nav slam_nav.launch.py use_rviz:=true
7.1 Manual exploration
In the RViz interface, you can manually post navigation points for exploration. You can use the Nav2 Goal tool to send the target location and direction to the robot. In the RViz interface, indicate the location (target point) that the robot wants to explore, and the direction of the green arrow is the direction that the robot pan-tilt is facing forward.
Similarly, you can also use the keyboard or joystick to explore remotely. In a new Docker container terminal, run either joystick control or keyboard control node. For details, please refer to UGV Beast Jetson Orin ROS2 3. Use Joystick or Keyboard Control Chapter:
#Joystick control (make sure the joystick receiver is plugged into Jetson Orin Nano) ros2 launch ugv_tools teleop_twist_joy.launch.py #Keyboard control (keep the running keyboard control node active) ros2 run ugv_tools keyboard_ctrl
Alternatively, you can control the robot movement through the web for exploration, please refer to the UGV Beast Jetson Orin ROS2 9. Web-based Control Tool Chapter.
In this way, you can control the movement of the chassis to explore the surrounding environment. As you control the movement of the chassis, the map that the robot has moved will gradually be displayed in the RViz interface.
7.2 Automatic exploration
In addition to manual exploration, you can also directly let the robot explore the map automatically. Note: Automatic exploration needs to be carried out in a closed area. It is generally recommended to conduct automatic exploration in a closed small room, or in the Gazebo simulation map. For details, please refer to UGV Beast Jetson Orin ROS2 11. Gazebo Simulation Debugging.
Keep the robot and navigation instructions running on RViz interface, and then run the automatic exploration instructions in a new Docker container:
ros2 launch explore_lite explore.launch.py
The robot will move and explore within the enclosed area, and the explored area will also be displayed on the RViz interface.
7.3 Save map
After navigation and exploration, you can save the map in a new Docker container terminal. Open a new Docker container terminal, click the ⭐ symbol in the left sidebar, double-click to open Docker's remote terminal, enter username: root, password: jetson.
In the container, go to the workspace of the ROS 2 project for that product:
cd /home/ws/ugv_ws
Add executable permissions to the map saving script:
chmod +x ./save_2d_gmapping_map.sh
Then run the map saving script, as shown below, the map is saved successfully:
./save_2d_gmapping_map.sh
The details in this script are as follows:
cd /home/ws/ugv_ws/src/ugv_main/ugv_nav/maps ros2 run nav2_map_server map_saver_cli -f ./map
After executing the above script file, a 2D raster map named map will be saved. The map is saved in the /home/ws/ugv_ws/src/ugv_main/ugv_nav/maps directory. You can see that two files are generated in the above directory, one is map.pgm and the other is map.yaml.
- map.pgm: This is a raster image of the map (usually a grayscale image file);
- map.yaml: This is the configuration file of the map.