Skip to content
Mo Chen edited this page Jan 6, 2025 · 10 revisions

Welcome to the ROS2 Tutorial wiki!

Basic ROS2 Tutorials

Quick tips

  • In ROS2, different nodes that represent software packages that perform things like sensor processing and planning.
    • Nodes communicate with each other through topics, services, and actions
  • ros2 run ... will run a single node
  • ros2 launch ... will run multiple nodes at once from a launch file; launch files can be nested

Quickstart for nav2

Typically, there will be at least two computers running during robotics experiments. These computers constantly communicate with each other

  1. A host computer (e.g. a laptop or desktop computer) preferably running Ubuntu (virtual machines highly discouraged)
    • Normally, lots of things need to be installed on the computer, and often packages will not on a different computer with different things installed.
    • Virtual/Conda environments would normally be the solution, but unfortunately ROS2 does not work well with those
    • To make sure code is able to be run on different computers, we will be using a dev container (this repo) with all the right things installed. The dev container will run on the host computer, and anything ROS-related will be run inside the dev container
  2. A computer in a robot
    • Everything ROS-related on robot is installed on the host (i.e. we do not run a dev container on the robot)

Setting up the host computer

  1. Clone this repo
  2. Build the dev container
  3. Run ifconfig in a terminal on the host to obtain the desired network interface
  • It should be something like eth0 or enp39s0 for ethernet connections, or wlan0 for wireless connections

Setting up dev container

  1. Replace eth0 in cyclonedds.xml with the correct network interface obtained from the above
  2. Run turtlebot3 simulation: ros2 launch nav2_bringup tb3_simulation_launch.py headless:=False

Known issues

  • If Gazebo does not load correctly (e.g. the turtlebot is not found), the following may help
    • Stop the simulation (Ctrl + C in terminal) and restart the simulation
    • Run pkill -9 gzclient and/or pkill -9 gzserver in the terminal before restarting the simulation

Installing packages that come with the dev container (including ones we may create as part of a project)

  • Build and source packages
    • colcon build --symlink-install
    • source install/setup.bash
  • Optional: Test a dummy ROS2 launch file in this repo:
    • ros2 launch controller experiment.launch.py

Running Nav2 on the Robot (real world, e.g. TurtleBot3)

  1. Make sure to have the following in ~/.bashrc:
export RMW_IMPLEMENTATION=rmw_cyclonedds_cpp
export ROS_DOMAIN_ID=5 # This domain ID should be the same as the computer's
export CYCLONEDDS_URI=~/ros2_ws/cyclonedds.xml # Make sure the workspace directory is correct
  1. Install cyclonedds if needed: sudo apt install ros-humble-rmw-cyclonedds-cpp
  2. Make sure the the network interface in cyclonedds.xml is correct