I am trying to declare two string parameters vid
and pid
for a serial communication node in ROS2. However, when I use the following launch file to pass my parameters:
<launch>
<node pkg="serial" exec="serial">
<param name="vid" type="str" value="0483"/>
<param name="pid" type="str" value="5740"/>
</node>
</launch>
I got the following error:
[serial-1] terminate called after throwing an instance of 'rclcpp::exceptions::InvalidParameterTypeException'
[serial-1] what(): parameter 'vid' has invalid type: Wrong parameter type, parameter {vid} is of type {string}, setting it to {double} is not allowed.
It seems like my type specification was never respected by roslaunch
.
According to the official documentation it seems like ROS2 removed support for explicit type declaration. I want to understand the rationale behind this change and find out possible alternative approaches (without moving away from xml format).
Update: Add C++ source code for reproducibility
class SerialNode: public rclcpp::Node {
SerialNode(): Node("serial") {
declare_parameter<std::string>("pid", "");
declare_parameter<std::string>("vid", "");
declare_parameter<int>("baud", 115200);
const auto vid = get_parameter("vid").as_string();
const auto pid = get_parameter("pid").as_string();
const auto baud = get_parameter("baud").as_int();
}
/* irrelevant code omitted ... */
}
Update:
- The python version of launch file also produces identical error.
- I added a letter
x
in front of my values (i.e.x0483
andx5740
instead of0483
and5740
), then the parameters are successfully passed as strings. I think this is a very strong proof that my code is not causing this error.
[serial-1] No serial port found for device x0483:x5740