Implementing Autonomous Driving with Nav2
This section covers how to apply autonomous driving to Moby-RP using the Nav2 stack of ROS2.
Preparation
- A map of the environment is required for autonomous driving. Please prepare a map of the environment where autonomous driving will be performed, referring to the SLAM.
- To run the Nav2 stack, Moby's control node and LiDAR node must be running. Please run the Moby control node according to the instructions in the Launching Moby Control Node.
How to run
1. Run Nav2 stack
-
If you followed the example in the SLAM, you would have created a
default_map.yaml
file in the/home/user/
path. You can run the Nav2 node for autonomous driving with the following command and load the map from that file: -
The RViz screen opens, and you can see Moby's current position displayed along with the map.
2. Correct the current position
When starting autonomous driving for the first time, Moby's position may be inaccurate. You can manually specify the current position using the 2D Pose Estimate feature in RViz.
-
In the RViz window, click the 2D Pose Estimate button.
-
Click on the part of the map that you think is Moby's current location, then press and drag to set the direction as well.
Set the initial position and enter driving goal commands in RViz
-
You can see Moby's position being updated. Set the position so that the LaserScan measurement points match the map well.
-
There is limitation in manually specifying the current position accurately. If you start moving the robot using a joystick, the localization algorithm updates and converges to a more accurate position gradually.
- For robot operation using a joystick, please refer to the Basic Operation chapter.
3. Saving the Starting Position
To avoid manually adjusting the position every time you start the Nav2 stack, you can fix and save the starting position.
-
Move to the starting position for the Nav2 stack and open a new terminal to check the current position with the command below:
-
Parameters including the starting position of moby_navigation are saved in the following paths:
~/ros2_ws/src/moby-ros2/moby_navigation/param/moby_rp.yaml
~/ros2_ws/install/moby_navigation/share/moby_navigation/param/moby_rp.yaml
- Enter the position value obtained from the command above in the initial_pose item of the two parameter files.
- In the case of orientation, a 4-digit quaternion value is displayed, but the parameter to enter in the file is a single yaw angle. You can use an online converter for converting from quaternion to yaw angle.
Saving the autonomous driving starting position
-
Now, whenever the Nav2 stack starts, it always begins at the saved position.
-
Among the two file paths above, the first one is the path of the original file, and the second one is the path where the package is installed when built. The actual file being used is the second file, but if you rebuild the ros2_ws workspace later, the second file will be overwritten by the first file. Therefore, it is recommended to either change the first file, rebuild the workspace, and apply the changes, or change both files directly when changing parameters.
4. Perform autonomous driving
-
Click the 2D Nav Goal button on the RViz screen.
-
Just like in 2D Pose Estimate, click on the desired destination on the map screen, and while holding down the mouse button, drag to set the direction.
-
Now Moby will move to the specified destination.
- During the movement, the Cancel button on the RViz control panel is activated, allowing you to cancel the autonomous driving.
- When the reached message is displayed in the RViz control panel's Feedback, the movement is complete.
Changes in the driving control panel during and upon completion of autonomous driving
Configuration of navigation2.launch.py File
- The Nav2 stack configuration-related information for Moby-RP is defined in the parameter file at the following path. For more detailed information about the file configuration, please refer to Nav2 documentation.
Name | Type | Description | Default Value |
---|---|---|---|
map | string | Map file path | ~/moby-ros2/install/moby_navigation/share/ moby_navigation/map/default_map.yaml |
params_file | string | Nav2 parameter file | ~/ros2_ws/install/moby_navigation/share/ moby_navigation/param/moby_rp.yaml |
launch_rviz | bool | Whether to launch RViz screen | true |