-
Notifications
You must be signed in to change notification settings - Fork 334
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
[IMUSensorBroadcaster] Create ParamListener and get parameters on configure #795
Conversation
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.
Thanks for pointing this out, it seems that I introduced the issue.
But I'm not sure why this fails, having a look at JTC
ros2_controllers/joint_trajectory_controller/src/joint_trajectory_controller.cpp
Lines 53 to 59 in f62fc3a
controller_interface::CallbackReturn JointTrajectoryController::on_init() | |
{ | |
try | |
{ | |
// Create the parameter listener and get the parameters | |
param_listener_ = std::make_shared<ParamListener>(get_node()); | |
params_ = param_listener_->get_params(); |
the param_listener is created and get_params() called also in the on_init method.
@bmagyar @destogl where is the correct place doing this? Is this documented somewhere?
ros2_controllers/doc/writing_new_controller.rst
Lines 55 to 58 in f62fc3a
3. Implement the ``on_init`` method. The first line usually calls the parent ``on_init`` method. | |
Here is the best place to initialize the variables, reserve memory, and most importantly, declare node parameters used by the controller. If everything works fine return ``controller_interface::return_type::OK`` or ``controller_interface::return_type::ERROR`` otherwise. | |
4. Write the ``on_configure`` method. Parameters are usually read here, and everything is prepared so that the controller can be started. |
vs
https://github.com/ros-controls/ros2_control/blob/e07736011bf28895596cf10dcb7cbcdb40d86daa/hardware_interface/doc/writing_new_hardware_component.rst?plain=1#L48-L52
I think you are onto something! Even recent code such as the toy controller I created for the roscon workshop does the same in the I think we need to take a closer look at generate_parameter_library and find where validation happens. On first read I don't see anything wrong with moving those two lines into |
Maybe @tylerjw can help to answer how to use generate_parameter_library properly here? |
I don't think there is any harm in moving this into on_configure. The constructor for the parameter listener sets up callbacks to ROS that will validate when a parameter is set. This includes if parameters have been set during launch it will then call the validation function and might fail. The reading of the parameters from ros happens when you call the get function. This behavior of validating in a callback might be a bit confusing for some users but it is the interface we have from ROS. |
thanks @tylerjw, best-practice would be then doing it in on_configure of all lifecycle nodes? |
Maybe, I'm not confident on the best way to use a lifecycle node. |
Hello! As far as I have checked, It seems like we can declare params in the I think for the same reason, we get the parameters of the |
I discussed this with @saikishor
But I still don't know why |
Hello @YueErro! Can you please check if the fix in the PR : ros-controls/ros2_control#1145, address your issue directly with the |
Fyi I'm happy to merge this PR if you get a green CI |
@tylerjw and @christophfroehlich will your fix of those issues in Generate Parameter Library be beckported to humble? If yes, then there is not need for fixing this. |
Yes, I will backport to humble. |
Hi,
It seems there is a very similar issue as in #698. The
IMUSensorBroadcaster
stopped working for me.After looking for the issue, I've found that there is a validation of the parameter
sensor_name
(added here), that is failing always because the parameters have not been loaded into the node yet and then, the parameter is empty at that point.I have the parameter declared in the yaml file that I'm loading in the node but the error I'm having is the following:
I guess the same happens with the validation of the parameter
frame_id
(added here).By creating the
ParamListener
and reading the parameters on configure instead of on init is working for me:I would like to have also a backport for
humble
.Thank you in advance!