-
Notifications
You must be signed in to change notification settings - Fork 412
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
process hangs in parameter change callback #824
Comments
There is a bug in rclcpp, and there is a bug in your callback. The rclcpp problem is that when the callback is called, the Parameters implementation is holding a lock. Calling any of the other Parameter APIs also tries to acquire that lock, so it deadlocks. I fixed it for the The problem with your callback is that you are not allowed to declare, undeclare, or set parameters during the callback. In the same pull request above (which will be in Eloquent), I added explicit checks and an exception if you try to do this. Since the callback is called when doing any of the parameter modifications, doing it essentially recursively seems like it would lead to trouble. So my suggestion for you is to think about why you are trying to undeclare parameters in the callback, and do something else. I'm going to close this issue out for now, but feel free to keep commenting or reopen if you have additional thoughts here. |
@clalancette |
I'm not a big fan of having parameters invisible. If they are invisible, there is no way for a user to introspect your node ( Instead, I'd suggest just declaring them during the constructor, and then in your |
Yeah, this should be a better way to handle my case. Thanks for your suggestion. |
Steps to reproduce issue
ros2 param set <node_name> <param_name> <param_value>
Expected behavior
set parameter successfully
Actual behavior
the process of ros2 param hangs without any feedback. When I was trying to terminate the application with Ctrl+C, it also fails with the output "[INFO] [rclcpp]: signal_handler(signal_value=2)", but no return.
Additional information
the parameter change callback that I implemented:
auto callback = [this] (const std::vectorrclcpp::Parameter & params)
{
auto result = rcl_interfaces::msg::SetParametersResult();
result.successful = true;
for (auto & param : params) {
if (param.get_name() == "enabled") {
if (param.get_type() == rclcpp::ParameterType::PARAMETER_BOOL) {
if (param.as_bool() == true && enable_ == false) {
RCLCPP_INFO(node_.get_logger(), "toggle on");
enable_ = true;
} else if (param.as_bool() == false && enable_ == true) {
RCLCPP_INFO(node_.get_logger(), "toggle off");
enable_= false;
this->undeclare_parameter("param1");
this->undeclare_parameter("param2");
this->undeclare_parameter("param3");
} else {
result.successful = false;
result.reason = "Parameter is equal to the previous value. Do nothing.";
}
} else {
result.successful = false;
result.reason = "Type should be boolean.";
}
}
}
return result;
}
I found only when I add the 3 lines in bold, the issue occurs. If I don't undeclare parameter in this callback, it seems that everything is ok. Is there any problem in the usage of rclcpp?
The text was updated successfully, but these errors were encountered: