Development
Debugging
Tips dan tools untuk debugging ROS 2 dan robot OP3
Debugging
Panduan debugging untuk project BASCORRO menggunakan ROS 2 tools dan teknik umum.
ROS 2 CLI Tools
Node Inspection
# List all nodes
ros2 node list
# Node info
ros2 node info /ball_detector
# Output:
# Subscribers:
# /camera/image_raw: sensor_msgs/msg/Image
# Publishers:
# /ball_position: geometry_msgs/msg/PointTopic Debugging
# List all topics
ros2 topic list
# Topic info
ros2 topic info /ball_position
# Echo topic (see messages)
ros2 topic echo /ball_position
# Echo with rate limit
ros2 topic echo /ball_position --once
# Publish test message
ros2 topic pub /cmd_vel geometry_msgs/msg/Twist \
"{linear: {x: 0.1}, angular: {z: 0.0}}"
# Check publishing rate
ros2 topic hz /camera/image_rawService Debugging
# List services
ros2 service list
# Service type
ros2 service type /reset_simulation
# Call service
ros2 service call /reset_simulation std_srvs/srv/EmptyParameter Debugging
# List parameters
ros2 param list /ball_detector
# Get parameter
ros2 param get /ball_detector camera_height
# Set parameter
ros2 param set /ball_detector camera_height 0.5Visualization Tools
RQT
# Launch RQT
rqt
# Useful plugins:
# - Node Graph (visualize nodes & topics)
# - Image View (see camera feed)
# - Plot (graph numeric values)
# - Console (see log messages)RViz2
# Launch RViz
rviz2
# Add displays:
# - TF (coordinate frames)
# - Image (camera)
# - Marker (custom visualization)
# - PointCloud2 (3D points)Image Debugging
# View camera feed
ros2 run rqt_image_view rqt_image_view
# Select topic: /camera/image_raw or /debug_imageLogging
Log Levels
| Level | Use Case |
|---|---|
| DEBUG | Detailed debugging info |
| INFO | Normal operation info |
| WARN | Potential issues |
| ERROR | Errors (recoverable) |
| FATAL | Critical errors |
Python Logging
# Log messages
self.get_logger().debug('Detailed info')
self.get_logger().info('Normal info')
self.get_logger().warn('Warning!')
self.get_logger().error('Error occurred')
self.get_logger().fatal('Critical failure')C++ Logging
RCLCPP_DEBUG(this->get_logger(), "Detailed info");
RCLCPP_INFO(this->get_logger(), "Normal info");
RCLCPP_WARN(this->get_logger(), "Warning!");
RCLCPP_ERROR(this->get_logger(), "Error occurred");
RCLCPP_FATAL(this->get_logger(), "Critical failure");Set Log Level
# At runtime
ros2 run <package> <node> --ros-args --log-level debug
# Specific logger
ros2 run <package> <node> --ros-args \
--log-level my_node:=debugCommon Issues
Node Doesn't Start
# Check if package built
ros2 pkg list | grep <package>
# Check executable exists
ros2 run <package> <node> --help
# Check dependencies
rosdep install --from-paths src --ignore-src -r -yTopics Not Connecting
# Check QoS compatibility
ros2 topic info /topic_name -v
# Common QoS issues:
# - Publisher/subscriber have different reliability
# - Different durability settingsTF Errors
# View TF tree
ros2 run tf2_tools view_frames
# Look up specific transform
ros2 run tf2_ros tf2_echo odom base_link
# Common errors:
# - "Could not find a connection" → missing TF publisher
# - "Lookup would require extrapolation" → time sync issueCamera Issues
# Check if camera detected
ls /dev/video*
# Check camera info
v4l2-ctl --list-devices
# Adjust camera settings
v4l2-ctl -d /dev/video0 --list-ctrls
v4l2-ctl -d /dev/video0 --set-ctrl=exposure_auto=1Python Debugging
Print Debugging
# Quick print
print(f"ball_position: {x}, {y}")
# With type info
print(f"image type: {type(image)}, shape: {image.shape}")PDB (Python Debugger)
import pdb
def my_function():
x = calculate_something()
pdb.set_trace() # Breakpoint here
return xOpenCV Image Debugging
import cv2
# Save intermediate images
cv2.imwrite('/tmp/debug_mask.png', mask)
cv2.imwrite('/tmp/debug_edges.png', edges)
# Show in window (if display available)
cv2.imshow('Debug', image)
cv2.waitKey(1)C++ Debugging
GDB
# Build with debug symbols
colcon build --cmake-args -DCMAKE_BUILD_TYPE=Debug
# Run with GDB
gdb --args ros2 run <package> <node>
# GDB commands:
# run - start program
# break <line> - set breakpoint
# next - next line
# step - step into function
# print <var> - print variable
# backtrace - show call stackSanitizers
# In CMakeLists.txt
add_compile_options(-fsanitize=address)
add_link_options(-fsanitize=address)Performance Debugging
CPU Profiling
# Check node CPU usage
top
htop
# ROS 2 specific
ros2 topic hz /camera/image_raw # Check rate
ros2 topic delay /camera/image_raw # Check latencyTiming
import time
start = time.time()
# ... code to measure ...
elapsed = time.time() - start
self.get_logger().info(f'Processing took {elapsed*1000:.1f} ms')Bottleneck Detection
import cProfile
cProfile.run('my_function()')Simulation Debugging
Webots
# Verbose output
webots --stdout --stderr world.wbt
# Log file
webots --log-file=webots.log world.wbtReset Simulation
# Reset via service
ros2 service call /supervisor/reset_simulation std_srvs/srv/EmptyRecording & Playback
ROS 2 Bags
# Record topics
ros2 bag record /camera/image_raw /imu/data
# Record all topics
ros2 bag record -a
# Playback
ros2 bag play rosbag2_*/
# Info
ros2 bag info rosbag2_*/Bag files sangat berguna untuk mereproduksi bug yang sulit di-debug secara real-time.
Checklist: Bug Not Reproducing?
- Sama persis workspace version?
- Sama environment variables?
- Sama hardware?
- Sama kondisi (lighting, battery, etc.)?
- Ada race condition (timing-dependent)?
- Coba record bag saat bug terjadi