-
Notifications
You must be signed in to change notification settings - Fork 431
Export pid gains as reference #2020
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
base: master
Are you sure you want to change the base?
Export pid gains as reference #2020
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #2020 +/- ##
==========================================
- Coverage 85.13% 85.06% -0.07%
==========================================
Files 144 144
Lines 13968 14021 +53
Branches 1201 1211 +10
==========================================
+ Hits 11891 11927 +36
- Misses 1670 1685 +15
- Partials 407 409 +2
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
christophfroehlich
left a comment
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.
In principle, this looks fine for me.
| switch (gain_type) | ||
| { | ||
| case 0: // P gain | ||
| pids_[i]->set_gains( |
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.
Am I missing something? I think there is no functionality to skip setting the gain by passing a NaN value?
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.
@christophfroehlich , you are right. I am thinking of following fix. What do you think ?
| pids_[i]->set_gains( | |
| auto current_pid_gains = pids_[i]->get_gains(); | |
| for (size_t j = 0; j < GAIN_INTERFACES.size(); ++j) | |
| { | |
| const size_t buffer_index = gains_start_index + i + j * dof_; | |
| const double new_gain_value = reference_interfaces_[buffer_index]; | |
| if (std::isfinite(new_gain_value)) | |
| { | |
| const size_t gain_type = GAIN_TYPES_INDEX[j]; | |
| switch (gain_type) | |
| { | |
| case 0: // P gain | |
| current_pid_gains.p_gain_ = new_gain_value; | |
| pids_[i]->set_gains(current_pid_gains);``` |
| std::vector<double> measured_state_values_; | ||
|
|
||
| inline static const std::vector<std::string> GAIN_INTERFACES = {"p", "i", "d"}; | ||
| inline static const std::vector<size_t> GAIN_TYPES_INDEX = {0, 1, 2}; |
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.
A quick question about convention of ROS Controls, do we follow,
[Storage Specificier] [Modifier] [Type] [Variable Name]
Like: static constexpr bool is_ros = true;
Or
[Modifier] [Storage Specificier] [Type] [Variable Name]
Like: constexpr static bool is_ros = true;
If we follow the above convention, then I think you should change the order of specifier.
Am I missing something, or is the code convention different.
I assumed the first convention because it is used pre-dominantely in other codebase.
Thanks!
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.
hi @thedevmystic,
I checked your recommendation, and you are right. I am going to follow the first convention.
| inline static const std::vector<size_t> GAIN_TYPES_INDEX = {0, 1, 2}; | |
| static inline const std::vector<std::string> GAIN_INTERFACES = {"p", "i", "d"}; | |
| static inline const std::vector<size_t> GAIN_TYPES_INDEX = {0, 1, 2};``` |
understood. I am trying to understand one thing, in my current implementation, when I set if (params_.export_gain_references)
{
total_reference_size += dof_ * GAIN_INTERFACES.size();
}
reference_interfaces_.resize(total_reference_size, std::numeric_limits<double>::quiet_NaN());Because of this, some of the existing tests are failing. If this implementation is correct, should I update the tests so that they handle both cases Test config that I used to reproduce the failure case, along with the corresponding log: test_pid_controller:
ros__parameters:
dof_names:
- joint1
command_interface: position
reference_and_state_interfaces: ["position"]
export_gain_references: true
gains:
joint1: {p: 1.0, i: 2.0, d: 3.0, u_clamp_max: 5.0, u_clamp_min: -5.0}
/workspaces/ros2_control_rolling_dev_docker_ws/src/ros-controls/ros2_controllers/pid_controller/test/test_pid_controller.cpp:88: Failure
Expected equality of these values:
ref_if_conf.size()
Which is: 4
dof_state_values_.size()
Which is: 1
[ FAILED ] PidControllerTest.check_exported_interfaces (6 ms) |
|
I also think implementation is correct @kumar-sanjeeev, Overall, I think some tests need to be updated, but this is just my assumption. |
9914ad5 to
79473e8
Compare
|
hi @christophfroehlich, I have tried few different ways to fix the ABI check, but still haven’t succeeded. Do you have any recommendations? Or is it okay in this feature request, if it breaks ? |
| auto current_pid_gains = pids_[i]->get_gains(); | ||
| for (size_t j = 0; j < GAIN_INTERFACES.size(); ++j) | ||
| { | ||
| const size_t buffer_index = gains_start_index + i + j * dof_; |
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.
| const size_t buffer_index = gains_start_index + i + j * dof_; | |
| const size_t buffer_index = gains_start_index + (j * dof_) + i; |
As the standard formula for index calculation is,
index = base_offset + (row_index * row_size) + column_index.
While the previous one is perfectly fine, this improves general readability and precedence readability.
| gain_references: { | ||
| type: bool, | ||
| default_value: false, | ||
| description: "If true, exports P, I, D gains as reference interfaces to be claimed by preceding controllers", |
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.
If you don't mind me nitpicking on your descriptions, I'll suggest this.
| description: "If true, exports P, I, D gains as reference interfaces to be claimed by preceding controllers", | |
| description: "If true, exports P, I, and D gains as reference interfaces to be claimed by preceding controllers", |
Just for clarity and grammatical consistency.
|
Phenomenal work, @kumar-sanjeeev. And I'm very glad you completed this, and now this is ready for a review. Good luck for ahead! |
This PR includes the following changes:
export_gain_referencesto enable or disable the export of gains (p, i, d) as references.update_and_write_commandsfunction based on the value of export_gain_references.export_gain_references=trueandexport_gain_references=false