Complete the code to include a condition that launches the node only if the parameter 'use_node' is true.
launch_ros.actions.Node(
package='my_package',
executable='my_node',
condition=launch.conditions.[1](LaunchConfiguration('use_node'))
)The IfCondition checks if the given launch configuration or parameter is true to launch the node.
Complete the code to declare a launch argument named 'enable_sensor' with default value 'false'.
DeclareLaunchArgument(
'enable_sensor',
default_value='[1]',
description='Enable the sensor node'
)
The default value for the argument should be the string 'false' to disable the sensor by default.
Fix the error in the condition to launch the node only if 'enable_sensor' is true.
Node(
package='sensor_pkg',
executable='sensor_node',
condition=launch.conditions.[1](LaunchConfiguration('enable_sensor'))
)IfCondition correctly launches the node when the launch configuration 'enable_sensor' is true.
Fill both blanks to create a launch description that declares a launch argument 'run_camera' and launches the camera node only if 'run_camera' is true.
DeclareLaunchArgument(
'run_camera',
default_value='false'
)
camera_node = Node(
package='camera_pkg',
executable='camera_node',
condition=launch.conditions.[1](LaunchConfiguration('[2]'))
)The node launches only if the 'run_camera' argument is true using IfCondition and the correct argument name.
Fill all three blanks to create a launch description that declares 'use_lidar' argument, sets a parameter 'lidar_enabled' based on it, and launches the lidar node only if 'use_lidar' is true.
use_lidar_arg = DeclareLaunchArgument(
'use_lidar',
default_value='false'
)
lidar_node = Node(
package='lidar_pkg',
executable='lidar_node',
parameters=[{'lidar_enabled': LaunchConfiguration('[1]')}],
condition=launch.conditions.[2](LaunchConfiguration('[3]'))
)The parameter and condition both use the 'use_lidar' argument, and IfCondition launches the node only if true.
