| name | ros2-debugging-tools |
| description | ROS2 调试工具技能 - CLI 调试、GDB、Valgrind、ros2cli、rqt 工具 |
| argument-hint | ROS2调试 OR debugging OR gdb OR valgrind OR CLI |
| user-invocable | true |
ROS2 调试工具技能
ROS2 调试工具使用
何时使用
当需要以下帮助时使用此技能:
- ros2cli 工具
- GDB 调试
- Valgrind 内存分析
- rqt 工具
- 日志管理
核心工具
ros2cli 工具
ros2 topic list
ros2 topic echo /scan
ros2 topic hz /scan
ros2 topic delay /scan
ros2 topic info /scan
ros2 service list
ros2 service call /get_map GetMap
ros2 param list
ros2 param get /node_name param
ros2 param set /node_name param value
ros2 param dump /node_name
ros2 node list
ros2 node info /node_name
ros2 interface list
ros2 interface show sensor_msgs/LaserScan
GDB 调试
colcon build --cmake-args -DCMAKE_BUILD_TYPE=Debug
gdb -ex run --args /path/to/executable
set(CMAKE_BUILD_TYPE Debug)
set(CMAKE_CXX_FLAGS_DEBUG "-g -O0")
ros2 run -d --prefix 'gdb -ex run --args' package_name executable
Valgrind 内存分析
sudo apt install valgrind
valgrind --leak-check=full --show-leak-kinds=all \
--track-origins=yes --error-limit=no \
/path/to/executable
ros2 run -d --prefix 'valgrind --tool=memcheck' package executable
rqt 工具
rqt
rqt_graph
rqt_console
rqt_plot
rqt_topic
rqt_bag
rqt_reconfigure
日志管理
import rclpy
from rclpy.node import Node
class LoggingNode(Node):
def __init__(self):
super().__init__('logging_node')
self.get_logger().set_level(rclpy.logging.LoggingSeverity.INFO)
self.get_logger().debug('Debug message')
self.get_logger().info('Info message')
self.get_logger().warn('Warning message')
self.get_logger().error('Error message')
def configure_logging(self):
"""配置日志"""
pass
常见问题诊断
ros2 daemon stop
ros2 daemon start
ros2 run rqt_graph rqt_graph
ros2 topic echo /scan --full-length
ros2 doctor
ros2 run rqt_topic rqt_topic
valgrind --tool=memcheck --leak-check=full --log-file=memcheck.log ./executable