-
Notifications
You must be signed in to change notification settings - Fork 436
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Set parameters from inside callbacks #1789
Conversation
Signed-off-by: Aditya Pande <aditya050995@gmail.com>
Signed-off-by: Aditya Pande <aditya050995@gmail.com>
Example usage :
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you explain what is the current behavior when calling set_parameter()
from a parameter callback and how does this PR solve the issue?
I took a quick look and the approach taken here seems to be fairly complicated.
@@ -929,7 +929,7 @@ class Node : public std::enable_shared_from_this<Node> | |||
RCLCPP_PUBLIC | |||
RCUTILS_WARN_UNUSED | |||
OnSetParametersCallbackHandle::SharedPtr | |||
add_on_set_parameters_callback(OnParametersSetCallbackType callback); | |||
add_on_set_parameters_callback(OnParametersSetCallbackType callback, bool allowRecursion = false); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't like the idea of having an allowRecursion
, we should either always support recursion or not at all.
nit
add_on_set_parameters_callback(OnParametersSetCallbackType callback, bool allowRecursion = false); | |
add_on_set_parameters_callback(OnParametersSetCallbackType callback, bool allow_recursion = false); |
Is the current issue iterator invalidation here? rclcpp/rclcpp/src/rclcpp/node_interfaces/node_parameters.cpp Lines 274 to 284 in 9e445bd
|
@ivanpauno curently, if you call
As discussed with @wjwwood and @clalancette , we want to enable this functionality, to make sort of "meta-parameters" that can trigger other parameter actions. Of course this can lead to an infinite recursion (where parameters can call each other in a circular manner) and users can mess up things easily. Thus we wanted an explicit flag, or a new callback group container that would hold such callbacks which can be used from inside other callbacks. I've also added a We could consider removing the |
The "on set parameter" callbacks doesn't seem to be a good for this though.
Could you give an example of where this is needed? That might help me to understand the issue in a better way. |
After a discussion with @jacobperron @clalancette @mjeronimo @ivanpauno and looking at #1190, #609, it was decided that ros-simulation/gazebo_ros_pkgs#1312 would use Parameter Event handler to reflect the true values of the slip parameters, and the ideal solution in Another major issue with this PR was that the callbacks are meant to be validation callbacks, and setting parameters inside them is not the intended use case. If one of the |
This PR aims to add a way to set parameters from inside another parameter's callback.
Current approach :
allowRecursion
boolean flag toadd_on_set_parameters
method.set_parameters_atomically
is called from inside another parameter's callback.TODO for current approach :
add_on_set_parameters
,remove_on_set_parameters
,undeclare_parameters
Concerns
Suggested alternatives
update_parameters
which would update the parameters without triggering their callbacks. This would not solve the overall problem exactly, but would be much simpler to debug and understand.get_parameters
?Original model :
Current approach :