0
$\begingroup$

Rosanswers logo

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 ?


Originally posted by Sam_Prt on ROS Answers with karma: 28 on 2023-02-14

Post score: 0


Original comments

Comment by christophebedard on 2023-02-14:
Can you share your launch file and the code that reads command line arguments?

Comment by christophebedard on 2023-02-14:
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?

Comment by christophebedard on 2023-02-14:
In short, --ros-args is always added to the commandline arguments, but at the end after any arguments: https://github.com/ros2/launch_ros/blob/6daacbce4bade7ed40f86f16a30a08b4d7ee9272/launch_ros/launch_ros/actions/node.py#L209. If you write code to read these commandline arguments, you might need to filter it out.

Comment by Sam_Prt on 2023-02-20:
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 ?

Comment by christophebedard on 2023-02-20:
sure, done!

Comment by christophebedard on 2023-02-21:
Note that I edited my answer to mention rclcpp::init_and_remove_ros_arguments(). It just popped into my head.

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

--ros-args is always added to the commandline arguments, but at the end, after any arguments: https://github.com/ros2/launch_ros/blob/6daacbce4bade7ed40f86f16a30a08b4d7ee9272/launch_ros/launch_ros/actions/node.py#L209. 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/28e4b1bd738c23e3ede2c70bf35786ce829ae910/rclcpp/include/rclcpp/utilities.hpp#L140


Originally posted by christophebedard with karma: 641 on 2023-02-20

This answer was ACCEPTED on the original site

Post score: 1

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.