ROS2 Launch Configuration - how to properly pass arguments?
I would like to pass command line arguments to my launch file when launching from terminal, and then pass this value as a command line argument to a lifecycle node brought up by this launch file. I followed some answers like this, and this, while also trying to follow examples like this. So far what I have written is (the relevant bits):
from launch.actions import DeclareLaunchArgument, IncludeLaunchDescription
from launch.launch_description_sources import PythonLaunchDescriptionSource
from launch.substitutions import LaunchConfiguration,ThisLaunchFileDir
from launch import LaunchDescription
from launch_ros import get_default_launch_description
from launch.launch_context import LaunchContext
...
def generate_launch_description(argv=sys.argv[1:]):
ld = launch.LaunchDescription()
...
port=LaunchConfiguration('port')
declare_port_cmd = DeclareLaunchArgument(
'port',
default_value='/dev/ttyACM0',
description='Port for serial comm')
...
# Prepare the marvel node.
context = LaunchContext()
marvel_node = launch_ros.actions.LifecycleNode(
node_name='marvelmind_nav', package='marvelmind_nav', node_executable='marvelmind_nav', output='screen',
arguments=[port.perform(context),'9600'])
...
ld.add_action(marvel_node)
ld.add_action(declare_port_cmd)
ls.include_launch_description(ld)
return ld
What I would like to do is :
ros2 launch <this_package> <this_launch> port:=/dev/ttyACM1
and have it pass the argument to my node as a command line argument correctly, which would be the equivalent of running :
ros2 run <this_package> marvelmind_nav /dev/ttyACM1
Unfortunately, I get this message:
[ERROR] [launch]: Caught exception in launch (see debug for traceback): launch configuration 'port' does not exist
I am not quite sure what I miss here, and look forward to any help.
Thank you!!