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

how to specify launch argument type in ros2 launch command?

asked 2022-09-09 01:45:36 -0600

vrichard gravatar image

updated 2022-09-10 23:15:39 -0600

I have a ROS2 node which takes a 'username' string argument. I can normally run the node like this:

ros2 launch my_pkg launch.py username:=XXX

In my case, my username is composed of digits only, like so:

ros2 launch my_pkg launch.py username:=12345

The issue then is that ros2 launch fails because:

 rclpy.exceptions.InvalidParameterTypeException: Trying to set parameter 'username' to '12345' of type 'INTEGER', expecting type 'STRING'

surrounding 12345 with quotes like "12345" or '12345' does not help. How can I tell ROS my argument is a String and not an integer?

This can be reproduced with this node: https://github.com/LORD-MicroStrain/n...

$ ros2 launch ntrip_client ntrip_client_launch.py username:=12345
[INFO] [launch]: All log files can be found below /home/vrichard/.ros/log/2022-09-11-13-05-38-795894-vr-desktop-702025
[INFO] [launch]: Default logging verbosity is set to INFO
[INFO] [ntrip_ros.py-1]: process started with pid [702095]
[ntrip_ros.py-1] Traceback (most recent call last):
[ntrip_ros.py-1]   File "/home/vrichard/test/install/ntrip_client/lib/ntrip_client/ntrip_ros.py", line 153, in <module>
[ntrip_ros.py-1]     node = NTRIPRos()
[ntrip_ros.py-1]   File "/home/vrichard/test/install/ntrip_client/lib/ntrip_client/ntrip_ros.py", line 26, in __init__
[ntrip_ros.py-1]     self.declare_parameters(
[ntrip_ros.py-1]   File "/opt/ros/galactic/lib/python3.8/site-packages/rclpy/node.py", line 491, in declare_parameters
[ntrip_ros.py-1]     self._set_parameters(
[ntrip_ros.py-1]   File "/opt/ros/galactic/lib/python3.8/site-packages/rclpy/node.py", line 736, in _set_parameters
[ntrip_ros.py-1]     raise InvalidParameterTypeException(
[ntrip_ros.py-1] rclpy.exceptions.InvalidParameterTypeException: Trying to set parameter 'username' to '12345' of type 'INTEGER', expecting type 'STRING'
[ERROR] [ntrip_ros.py-1]: process has died [pid 702095, exit code 1, cmd '/home/vrichard/test/install/ntrip_client/lib/ntrip_client/ntrip_ros.py --ros-args -r __node:=ntrip_client_node -r __ns:=/ntrip_client --params-file /tmp/launch_params_cmiltczq'].

I don't think the launch file is doing any weird thing. The 'username' parameter is just declared with a default string value: https://github.com/LORD-MicroStrain/n...

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
0

answered 2022-09-10 23:23:57 -0600

vrichard gravatar image

@shonigmann was close to the actual answer. It is possible to force the value to be intepreted as string by surrounding the param:=value pair with quotes and surrounding the value itself aswell. Like so:

ros2 launch ntrip_client ntrip_client_launch.py "username:='12345'"
edit flag offensive delete link more
1

answered 2022-09-10 15:02:25 -0600

shonigmann gravatar image

So the error actually appears to be due to a Node expecting a Parameter of a string type, and something is getting lost in the Argument/LaunchConfiguration -> Parameter conversion.

You can force the launch system to interpret the argument as a String type by surrounding the name:=value pair in quotes as suggested in the node arguments docs, e.g. ros2 launch my_pkg launch.py "username:=12345"

edit flag offensive delete link more

Comments

Thank you for the feedback. Surrounding the pair with quotes does not change anything. The 12345 value is still interpreted as integer and the node fails to run. I have updated the description to give a reproducible example.

vrichard gravatar image vrichard  ( 2022-09-10 23:17:01 -0600 )edit

Question Tools

2 followers

Stats

Asked: 2022-09-09 01:45:36 -0600

Seen: 1,850 times

Last updated: Sep 10 '22