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.