Skip to content

Latest commit

 

History

9 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 

Repository files navigation

ros2_nav_sim

A ROS 2 simulation package for autonomous navigation with the Sambot robot, using Gazebo Harmonic for simulation and Nav2 for mapping and autonomous navigation.

Prerequisites

Setup

Create a workspace and clone the repository in src folder and build it:

mkdir -p ~/nav2_ws/src
cd ~/nav2_ws/src 
git clone https://github.com/ariccspstk/ros2_nav_sim.git
cd ~/nav2_ws

Install any missing dependencies using rosdep:

rosdep update
rosdep install --from-paths src --ignore-src -r -y

Then build the workspace:

colcon build
source install/setup.bash

Usage

1. Launch the simulation

Opens Gazebo and RViz with the Sambot robot spawned in the arena:

ros2 launch my_robot_description gazebo_sim.launch.py

2. Start SLAM mapping

In a new terminal, start mapping the arena:

ros2 launch my_robot_description slam.launch.py

Note: In RViz, make sure the Map display's topic is set to /map so you can see the map being built in real time as you drive the robot around.

3. Drive the robot with teleop

In another terminal, use the keyboard to drive the robot around and build up the map:

ros2 run teleop_twist_keyboard teleop_twist_keyboard --ros-args -p stamped:=true -r /cmd_vel:=/demo/cmd_vel

Drive around until the arena is fully mapped.

4. Save the map

Create the maps folder if it doesn't already exist:

mkdir -p ~/nav2_ws/src/my_robot_description/maps

Once the arena is fully mapped, save it:

ros2 run nav2_map_server map_saver_cli -f ~/nav2_ws/src/ros2_nav_sim/my_robot_description/maps/arena_map

This saves arena_map.yaml and arena_map.pgm to the maps directory.

5. Rebuild and launch autonomous navigation

Rebuild the workspace so the newly saved map is picked up:

cd ~/nav2_ws
colcon build
source install/setup.bash

Relaunch the simulation:

ros2 launch ros2_nav_sim gazebo_sim.launch.py

In a new terminal, launch Nav2 to begin autonomous navigation using the saved map:

ros2 launch ros2_nav_sim nav2.launch.py

You can now set navigation goals for the robot through RViz using the saved map.

Note: Once nav2.launch.py is up, RViz won't have an initial pose for the robot and the frames won't align correctly until you set one. In RViz, click 2D Pose Estimate, then click and drag on the map at the robot's actual position/orientation in the arena. This localizes the robot against the map and loads the frames correctly (make sure RViz's Global Options > Fixed Frame is set to map). Only after this step will Nav2 be able to plan and navigate accurately.

Workflow Summary

Step Command Purpose
1 gazebo_sim.launch.py Launch Gazebo + RViz simulation
2 slam.launch.py Start SLAM mapping
3 teleop_twist_keyboard Manually drive the robot to map the arena
4 map_saver_cli Save the completed map
5 colcon build + gazebo_sim.launch.py + nav2.launch.py Rebuild and run autonomous navigation

Notes

  • Make sure to source your workspace (source install/setup.bash) in every new terminal before running the above commands.
  • The /cmd_vel topic is remapped to /demo/cmd_vel for teleop control.

About

Playing with ros2 navigation in simulation

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages