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

--ros-args argument is always present in launched Node

asked 2023-02-14 08:20:46 -0600

Sam_Prt gravatar image

I am trying to launch a node that requires common command line arguments. In my launch file, I added a Node() instance in my LaunchDescription which contains the package, executable and arguments attributes. However the launched program complains about not knowing about argument --ros-args. I thought it was the ros_arguments attribute in the Node that added the --ros-args argument to the launch command so I don't understand why I am getting this error.

I am running Ubuntu 22.04 and ROS2 Humble.

How can we launch a program from a launch file without the launch file adding the --ros-args argument to the launch command ?

edit retag flag offensive close merge delete

Comments

Can you share your launch file and the code that reads command line arguments?

christophebedard gravatar image christophebedard  ( 2023-02-14 10:48:02 -0600 )edit

Also, can you clarify what exactly is complaining about the --ros-args? Is it your own code, or is ROS 2 itself complaining about it?

christophebedard gravatar image christophebedard  ( 2023-02-14 11:04:26 -0600 )edit

In short, --ros-args is always added to the commandline arguments, but at the end after any arguments: https://github.com/ros2/launch_ros/bl.... If you write code to read these commandline arguments, you might need to filter it out.

christophebedard gravatar image christophebedard  ( 2023-02-14 11:14:38 -0600 )edit

Oh ok, I thought it was more of an either/or logic. Thanks for your help ! Would you like to post an answer so I can accept it ?

Sam_Prt gravatar image Sam_Prt  ( 2023-02-20 02:25:47 -0600 )edit

sure, done!

christophebedard gravatar image christophebedard  ( 2023-02-20 10:34:19 -0600 )edit

Note that I edited my answer to mention rclcpp::init_and_remove_ros_arguments(). It just popped into my head.

christophebedard gravatar image christophebedard  ( 2023-02-21 16:03:35 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted
1

answered 2023-02-20 10:34:11 -0600

updated 2023-02-21 16:03:12 -0600

--ros-argsis always added to the commandline arguments, but at the end, after any arguments: https://github.com/ros2/launch_ros/bl.... If you write code to read these commandline arguments, you might need to filter it out.

You can also ask rclcpp to remove ROS arguments from the arguments vector (argv) when initializing. Then I imagine you wouldn't need to filter it out. See rclcpp::init_and_remove_ros_arguments(): https://github.com/ros2/rclcpp/blob/2...

edit flag offensive delete link more

Question Tools

2 followers

Stats

Asked: 2023-02-14 08:20:46 -0600

Seen: 341 times

Last updated: Feb 21 '23