Troubleshooting Common ROS 2 Issues
This guide covers common issues you may encounter when working with ROS 2 and provides solutions to help you resolve them quickly.
Environment and Setup Issues
"Command 'ros2' not found"
Problem: The ros2 command is not recognized in your terminal.
Solutions:
-
Source the ROS 2 environment:
source /opt/ros/humble/setup.bash -
Add to your shell profile to make it permanent:
echo "source /opt/ros/humble/setup.bash" >> ~/.bashrc
source ~/.bashrc -
Check if ROS 2 is properly installed:
ls /opt/ros/humble/
Python Import Errors
Problem: Getting import errors when trying to use ROS 2 Python libraries.
Solutions:
-
Check your Python environment:
python3 -c "import rclpy; print('rclpy imported successfully')" -
Install Python packages if needed:
pip3 install ros-humble-rclpy ros-humble-std-msgs -
Use the correct Python version (3.8+ for Humble).
Communication Issues
Nodes Can't Communicate
Problem: Publisher and subscriber nodes can't see each other's messages.
Solutions:
-
Check that both nodes are on the same ROS domain:
echo $ROS_DOMAIN_ID
# Set if needed: export ROS_DOMAIN_ID=42 -
Verify topic names match exactly:
ros2 topic list # Check what topics exist
ros2 topic info /your_topic_name # Check topic details -
Check network configuration:
export ROS_LOCALHOST_ONLY=0 # If communicating across machines -
Verify QoS compatibility between publisher and subscriber.
Services Not Responding
Problem: Service clients timeout waiting for responses.
Solutions:
-
Ensure service server is running:
ros2 service list # Check if service exists -
Verify service name matches exactly.
-
Check for blocking operations in the service callback.
Build and Package Issues
Package Doesn't Build
Problem: colcon build fails with errors.
Solutions:
-
Check dependencies are installed:
rosdep install --from-paths src --ignore-src -r -y -
Verify package.xml dependencies match your setup.py requirements.
-
Clean build artifacts and rebuild:
rm -rf build/ install/ log/
colcon build -
Check for syntax errors in Python files before building.
Module Not Found After Build
Problem: Getting "Module not found" errors after building.
Solutions:
-
Source the install setup:
source install/setup.bash -
Verify entry points in setup.py are correctly defined.
-
Check the package structure matches ROS 2 conventions.
Performance Issues
High CPU Usage
Problem: ROS 2 nodes consume excessive CPU resources.
Solutions:
-
Reduce message publishing rates in timers.
-
Use appropriate QoS settings:
# Reduce history depth if you don't need old messages
qos_profile = QoSProfile(depth=1) # Instead of 10 -
Optimize callback functions to be lightweight.
Memory Leaks
Problem: Memory usage grows continuously.
Solutions:
-
Properly destroy nodes in shutdown:
node.destroy_node()
rclpy.shutdown() -
Check for circular references in your code.
-
Monitor with system tools:
htop # Or other system monitoring tools
Jetson Orin Nano Specific Issues
Resource Constraints
Problem: Limited CPU/RAM on Jetson platform.
Solutions:
-
Optimize for ARM64 architecture when building.
-
Reduce node complexity or number of concurrent nodes.
-
Monitor system resources:
nvidia-smi # Check GPU usage
free -h # Check RAM usage
top # Check CPU usage
Power Management
Problem: Node performance affected by power states.
Solutions:
- Set Jetson to maximum performance mode:
sudo nvpmodel -m 0 # Maximum performance
sudo jetson_clocks # Lock clocks to maximum
Debugging Techniques
Using ROS 2 Command Line Tools
# List all active nodes
ros2 node list
# Get information about a specific node
ros2 node info /node_name
# List all topics
ros2 topic list
# Echo messages from a topic
ros2 topic echo /topic_name MessageType
# Check topic statistics
ros2 topic hz /topic_name
# Call a service
ros2 service call /service_name ServiceType "{request: data}"
Logging and Debugging
# In your nodes, use proper logging
self.get_logger().debug('Debug message')
self.get_logger().info('Info message')
self.get_logger().warn('Warning message')
self.get_logger().error('Error message')
self.get_logger().fatal('Fatal message')
Using RViz2 for Visualization
# Launch RViz2 for visual debugging
ros2 run rviz2 rviz2
Common Error Messages and Solutions
"No executable found"
Error: ros2 run package_name executable_name fails.
Solution:
- Check that you've sourced the install setup:
source install/setup.bash - Verify the executable name matches your entry point in setup.py
- Ensure the package was built successfully
"Topic/Service already exists"
Error: Getting warnings about existing topics/services.
Solution: This is usually not a problem, but if you need clean state:
# Restart the daemon to clear old registrations
pkill -f ros
# Or set a different domain ID
export ROS_DOMAIN_ID=43
"Failed to load entry point"
Error: When running a node, getting "Failed to load entry point" error.
Solution:
- Check your setup.py entry points format
- Verify the module and function exist
- Check for Python syntax errors in your files
Network Troubleshooting
Multi-Machine Communication
Problem: Nodes on different machines can't communicate.
Solutions:
-
Ensure same ROS_DOMAIN_ID on all machines:
export ROS_DOMAIN_ID=42 -
Check firewall settings to allow ROS 2 traffic (DDS uses various ports).
-
Verify network connectivity:
ping other_machine_ip -
Set appropriate ROS_LOCALHOST_ONLY:
export ROS_LOCALHOST_ONLY=0
Debugging Tools
Built-in ROS 2 Tools
rqt_graph: Visualize the ROS graphrqt_console: View log messagesrqt_plot: Plot numeric values over timeros2 doctor: Check system configuration
System Monitoring
# Monitor ROS 2 processes
htop -p $(pgrep -f ros2)
# Check network usage
netstat -tuln | grep -i ros
# Monitor disk space
df -h
Best Practices for Avoiding Issues
Code Quality
- Always handle exceptions in callbacks
- Use proper resource management (cleanup nodes, close files)
- Validate inputs before processing
- Use appropriate logging levels
Development Workflow
- Test in simulation first before running on hardware
- Use version control to track changes
- Write unit tests for critical functionality
- Document your code and interfaces clearly
Getting Help
When to Seek Help
- Issues persist after trying multiple solutions
- Unclear error messages
- Performance problems affecting system operation
Resources
- ROS 2 Documentation: https://docs.ros.org/
- ROS Answers: https://answers.ros.org/
- ROS Discourse: https://discourse.ros.org/
- GitHub Issues: For specific packages
Quick Reference Commands
# Essential troubleshooting commands
ros2 node list # List all nodes
ros2 topic list # List all topics
ros2 service list # List all services
ros2 action list # List all actions
ros2 param list /node_name # List node parameters
ros2 doctor # Check system health
# Environment check
printenv | grep ROS # Check ROS environment variables
source /opt/ros/humble/setup.bash # Source ROS environment
Next Steps
After resolving your immediate issues:
- Review the security and performance considerations for production use
- Learn about advanced ROS 2 features like Actions and Parameters
- Explore integration with the Jetson Orin Nano hardware
- Consider using launch files to manage complex multi-node systems