Learn ROS-ROS2 with Real Code Examples
Updated Nov 27, 2025
Practical Examples
Simulate a robot in Gazebo and control it via ROS2 nodes
Subscribe to a camera topic and process images
Use LIDAR data for obstacle avoidance
Implement a navigation stack for autonomous movement
Coordinate multiple robots using ROS2 DDS communication
Troubleshooting
Ensure ROS/ROS2 environment is sourced correctly
Check that topic names match between publisher and subscriber
Verify message and service definitions are built
Inspect logs using `ros2 topic echo` or `rqt_console`
Confirm network configuration for multi-machine ROS2 setups
Testing Guide
Use rostest or pytest for unit testing nodes
Simulate sensors and actuators for testing
Monitor topic communication with `ros2 topic list` and `echo`
Validate services and actions through test scripts
Use CI/CD pipelines for automated ROS2 builds and tests
Deployment Options
Deploy nodes on embedded computers like Raspberry Pi or Nvidia Jetson
Containerize ROS2 applications with Docker
Run simulation-only nodes on development machines
Distribute multi-robot nodes across networked computers
Cross-compile ROS2 packages for ARM architectures
Tools Ecosystem
roscore (ROS1) or `ros2 daemon` (ROS2) for communication management
RViz for 3D visualization
Gazebo for simulation
rqt plugins for monitoring topics, nodes, and parameters
Colcon or Catkin build tools
Integrations
Connect to hardware via ROS2 drivers
Interface with AI/ML modules for perception
Communicate with cloud services or IoT platforms
Integrate with custom middleware or ROS1 bridges
Simulation and testing with Gazebo or Webots
Productivity Tips
Use launch files to run multiple nodes efficiently
Leverage ROS2 lifecycle nodes for clean startup/shutdown
Use ROS2 composition for reduced overhead
Containerize workspaces for reproducibility
Document and modularize packages for easier collaboration
Challenges
Understanding ROS2 DDS and QoS policies
Debugging distributed systems
Hardware-software integration across platforms
Real-time performance tuning
Migrating legacy ROS1 packages to ROS2