第 14.5 節

Optimize logs

0瀏覽次數0訪問次數--跳出率--平均停留

In practice, we rarely use RCLCPP_INFO because printing data incurs too much overhead, and industrial control devices like the Nvidia Jetson Xavier may not be able to handle it.

The image below shows the overhead printed on a Raspberry Pi 4B:

Since we want to avoid such a large overhead, yet still be able to view printed data for debugging when necessary, we often use RCLCPP_DEBUG to print data, only printing data when needed.

RCLCPP_DEBUG Core Function

  • Debug Only: Outputs information only during the debugging phase; automatically silent in production environments.
  • Performance Optimization: Completely remove debug code via compile-time options, with zero runtime overhead.
  • Hierarchical Control : Decoupled from other log levels (INFO/WARN/ERROR)

How to print using rclcpp_debug:

Method 1:

ros2 run <package_name> <node_name> --ros-args --log-level debug

Method 2:

from launch import LaunchDescription
from launch_ros.actions import Node

def generate_launch_description():
    return LaunchDescription([
        Node(
            package='my_package',
            executable='my_node',
            name='my_node',
            output='screen',
            parameters=[],
            arguments=['--ros-args', '--log-level', 'debug']
        )
    ])

/opt/ros/humble/include/rcutils/rcutils/logging.h Definition:

音乐页