Performance: Conditional launching
Conditional launching affects the startup time and resource usage of ROS nodes by controlling which nodes are launched based on conditions.
roslaunch my_package conditional_nodes.launch condition:=true
# Only launches nodes if the condition parameter is trueroslaunch my_package all_nodes.launch
# This launches all nodes regardless of need or condition| Pattern | Nodes Started | CPU Usage | Memory Usage | Verdict |
|---|---|---|---|---|
| Unconditional launch | All nodes | High | High | [X] Bad |
| Conditional launch | Only needed nodes | Low | Low | [OK] Good |
IfCondition in a ROS 2 Python launch file to conditionally start a node?use_camera is set to false?
from launch import LaunchDescription
from launch.actions import DeclareLaunchArgument
from launch.conditions import IfCondition
from launch_ros.actions import Node
def generate_launch_description():
return LaunchDescription([
DeclareLaunchArgument('use_camera', default_value='false'),
Node(
package='camera_pkg',
executable='camera_node',
condition=IfCondition('use_camera == "true"')
),
Node(
package='lidar_pkg',
executable='lidar_node'
)
])Node(
package='my_pkg',
executable='my_node',
condition=IfCondition(use_sensor == 'true')
)sim_node or real_node based on a launch argument use_sim. Which launch snippet correctly implements this conditional launching in ROS 2 Python launch file?Pass the test and this pattern moves unknown