ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

ROS2 Launch Configuration - how to properly pass arguments?

asked 2020-06-12 03:58:24 -0500

Tejas Kumar shastha gravatar image

updated 2020-06-12 03:58:59 -0500

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!!

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2020-10-01 04:59:12 -0500

luca.fancellu gravatar image

I solved a thing like this following this answer: https://answers.ros.org/question/3226...

edit flag offensive delete link more

Question Tools

2 followers

Stats

Asked: 2020-06-12 03:58:24 -0500

Seen: 5,851 times

Last updated: Oct 01 '20