🤖

Crash Course on Navigation with ROS 2

Jul 16, 2024

Crash Course on Navigation to Stack with ROS 2

Introduction

  • Target Audience: Beginners or those needing a refresher on the basics of Nav2.
  • Content Overview: Install Nav2 stack, generate a map with SLAM, navigate using the map, and use TurtleBot 3 in simulation.
  • Requirements: ROS 2 Humble installed on Ubuntu 22.04, preferably as a dual boot (not in VM). Basic knowledge of ROS 2.

Installing Nav2 Stack

  • Ensure ROS 2 Humble is installed (source /opt/ros/humble/setup.bash in .bashrc).
  • Update system: sudo apt update
  • Install packages: sudo apt install ros-humble-navigation2 ros-humble-nav2-bringup sudo apt install ros-humble-turtlebot3*

Starting the TurtleBot 3 Simulation

  • Source TurtleBot 3 model: export TURTLEBOT3_MODEL=waffle (add to .bashrc).
  • Run Gazebo to simulate the environment: ros2 launch turtlebot3_gazebo turtlebot3_world.launch.py
  • Start teleoperation node: ros2 run turtlebot3_teleop teleop_keyboard

Generating a Map with SLAM

  • Open three terminals:
    1. Launch TurtleBot 3 in Gazebo.
    2. Launch Cartographer for SLAM: ros2 launch turtlebot3_cartographer cartographer.launch.py use_sim_time:=true
    3. Start teleoperation node to move robot.
  • Move the robot around to generate the map. Ensure full exploration of the space.
  • Save the generated map: mkdir -p ~/maps ros2 run nav2_map_server map_saver_cli -f ~/maps/mymap

Understanding the Map Files

  • .pgm file: Image of the map where white represents free space, black represents obstacles, and gray represents unknown regions.
  • .yaml file: Metadata that includes image, resolution (meters per pixel), origin, negate, and occupied_thresh and free_thresh for defining occupied and free space probabilities.

Fixing Navigation 2 Issues

  • Change DDS from Fast DDS to Cyclone DDS: sudo apt install ros-humble-rmw-cyclone-dds-cpp export RMW_IMPLEMENTATION=rmw_cyclone_dds_cpp (add `export RMW_IMPLEMENTATION=rmw_cyclone_dds_cpp` to `.bashrc`)
  • Edit turtlebot3_navigation2 parameter file: sudo nano /opt/ros/humble/share/turtlebot3_navigation2/param/waffle.yaml # Modify 'robot_model_type' parameter robot_model_type: nav2_amcl::DifferentialMotionModel

Making the Robot Navigate Using the Map

  • Start the simulation: ros2 launch turtlebot3_gazebo turtlebot3_world.launch.py
  • Launch navigation with the saved map: ros2 launch turtlebot3_navigation2 navigation2.launch.py use_sim_time:=true map:=~/maps/mymap.yaml
  • In RViz, set the initial 2D pose estimate to align the robot with the map.
  • Use the 2D Nav Goal tool in RViz to set a destination for the robot.

Waypoint Navigation

  • Click on Waypoint Nav Tool in RViz.
  • Set multiple waypoints on the map and start Waypoint following.
  • Use Start Nav Through Poses for continuous navigation through waypoints (less stable).

Conclusion

  • This crash course provides foundational knowledge to start with Nav2.
  • For advanced understanding, including custom worlds, robots, and programming, refer to the extended course with over 6 hours of video content and practice activities.