-
Notifications
You must be signed in to change notification settings - Fork 434
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
declare_parameter<T>(param_name)
fails
#1691
Comments
ros2/rclcpp#1691 Signed-off-by: Tomoya Fujita <Tomoya.Fujita@sony.com>
This one is unfortunate, but I don't think we can solve it. When we decided to make parameters "strongly typed" by default (#1522), we didn't originally support to declare them uninitialized. We later relaxed that requirement (#1681), and it is now possible to do the following: rclcpp::ParameterValue param = node->declare_parameter("integer_override_not_given", rclcpp::PARAMETER_INTEGER); The return type here is a The templated version returns directly the real parameter type and not an // What do we return if the parameter is uninitialized?
int64_t param = node->declare_parameter<int64_t>("integer_override_not_given"); So I don't think we can fix this for the templated version, and the non-template method should be used when you want to allow the parameter to be uninitialized. TBH, I completely forgot about the templated overload when we introduced #1681. @jacobperron what do you think? |
IMHO the clean way would be to avoid using 'type' to indicate whether a parameter is initialized or not. It makes sense to have a separate Just my two cents... |
"type" doesn't indicate if a parameter is initialized or not. |
Sorry, let me put it another way. You said it:
What I'm suggesting here is to return a ParameterValue of type |
Thanks for clarifying! I would just focus in making the error message more clear, but I will wait for @jacobperron input first. |
I also overlooked the template overload... we could certainly improve the error message. rclcpp::ParameterValue param = node->declare_parameter("foo", rclcpp::PARAMETER_INTEGER);
if (param.get_type() == rclcpp::PARAMETER_NOT_SET) {
// Parameter is unset
} So, I'm not sure if a new "initialized" member adds value. |
It might be valuable to support returning a rclcpp::ParameterValue param = node->declare_parameter<int64_t>("foo"); Then we wouldn't get an exception, and could check if the parameter is set before actually accessing the value. |
The templated declare_parameter method needs an override (or default value) since it returns the actual parameter value, otherwise we get an exception. To correctly declare a parameter without a default value, we should use a different signature. Related upstream issue: ros2/rclcpp#1691 Signed-off-by: Jacob Perron <jacob@openrobotics.org>
It's not possible to have two overloads with the same argument and different return value, so the only way to do that is to change the return value of the current method. For the moment, I will improve the error message. |
…a-ros-pkg#675) The templated declare_parameter method needs an override (or default value) since it returns the actual parameter value, otherwise we get an exception. To correctly declare a parameter without a default value, we should use a different signature. Related upstream issue: ros2/rclcpp#1691 Signed-off-by: Jacob Perron <jacob@openrobotics.org>
…a-ros-pkg#675) The templated declare_parameter method needs an override (or default value) since it returns the actual parameter value, otherwise we get an exception. To correctly declare a parameter without a default value, we should use a different signature. Related upstream issue: ros2/rclcpp#1691 Signed-off-by: Jacob Perron <jacob@openrobotics.org>
* Fix runtime exception thrown when parameter override not provided (#675) The templated declare_parameter method needs an override (or default value) since it returns the actual parameter value, otherwise we get an exception. To correctly declare a parameter without a default value, we should use a different signature. Related upstream issue: ros2/rclcpp#1691 Signed-off-by: Jacob Perron <jacob@openrobotics.org> * Fix different time sources error (#679) Signed-off-by: Christophe Bedard <bedard.christophe@gmail.com> Co-authored-by: Jacob Perron <jacob@openrobotics.org> Co-authored-by: Christophe Bedard <bedard.christophe@gmail.com>
When trying to run the constructor throws an exception: "Component constructor threw an exception: Statically typed parameter 'use_gps_time' must be initialized." This problem is described here: ros2/rclcpp#1691 Solve this by using the non-template way of declaring the parameters.
[implement_teleop_node-11] [ERROR] robot.implement.implement_teleop: Declare parameter joystick_mapping.axes.up_down_implement : Statically typed parameter 'joystick_mapping.axes.up_down_implement' must be initialized. ref : ros2/rclcpp#1691
Bug report
Required Info:
Steps to reproduce issue
Try to run the following code:
Expected behavior
Run and exit successfully.
Actual behavior
Compiles but in runtime exits due to an exception. Full output:
Additional information
This call fails:
(This is not specific to
std::string
)Here's my understanding of why this happens: Under the hood,
rclcpp
declares an uninitialized parameter and tries to return it as a typed object (code here). However, it seems thatrclcpp
keeps track of uninitialized parameters by assigningnot set
type to them (code here), even if they are typed. So this boils down to contradictory typing (string
type implied by template argument,not set
type implied by the node being uninitialized...)Interestingly the
mynode.declare_parameter<T>(param_name)
function call is actually included in the tests (code here) and they are passing without errors. The reason that the error doesn't manifest there is that in the same test file, a default value is defined for the parameter (code here). This means the parameter gets initialized (and therefore loses thenot set
type) beforemynode.declare_parameter<T>(param_name)
finishes.The text was updated successfully, but these errors were encountered: