-
Notifications
You must be signed in to change notification settings - Fork 113
Add derivative filter and discretization #471
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: ros2-master
Are you sure you want to change the base?
Conversation
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## ros2-master #471 +/- ##
===============================================
+ Coverage 78.90% 80.98% +2.08%
===============================================
Files 29 29
Lines 1896 2351 +455
Branches 119 128 +9
===============================================
+ Hits 1496 1904 +408
- Misses 332 378 +46
- Partials 68 69 +1
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
Hi, @christophfroehlich! I still need to fix the existing tests and add new ones. However, the equations are quite large, and the compute_command function has grown a lot. Do you think it’s acceptable (with better organization), or should something be changed? |
IMHO it is acceptable to go further in this direction, thanks! |
double u_max_ = std::numeric_limits<double>::infinity(); /**< Maximum allowable output. */ | ||
double u_min_ = -std::numeric_limits<double>::infinity(); /**< Minimum allowable output. */ | ||
AntiWindupStrategy antiwindup_strat_; /**< Anti-windup strategy. */ | ||
std::string i_method_ = "forward_euler"; /**< Integration method. */ |
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.
why have you chosen a std::string here? Wouldn't a simple enum be more lightweight here? Only thing we loose will be the human readable value in the print method without adding additional logic there. alternative would be a struct like the andiwindup strategy.
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! I change it to struct in commit 2b7a909
gains.d_gain_ = parameter.get_value<double>(); | ||
changed = true; | ||
} | ||
else if (param_name == param_prefix_ + "derivative_filter_time") |
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 suppose you have not added the integration/derivative method here on purpose?
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.
Yes, for now I don’t think anyone would modify the discretization methods during runtime.
Overview
Adds a configurable derivative filter. It also introduces separate discretization method selectors for the I and D terms. Forward Euler remains the default to preserve existing behavior.
What was added/changed in this PR
tf
) applied to the D term.i_method
andd_method
(e.g.,"forward_euler"
,"backward_euler"
,"trapezoidal"
), with"forward_euler"
as the default.tf == 0
.d_term_last_
,d_error_last_
,i_term_last_
,aw_term_last_
) to support trapezoidal (Tustin) and filtered updates.About tests
The packages compile correctly and have passed the pre‑commit and colcon tests. New tests are being added based on formula values to compare with those from
compute_command
.Related PR's
Attachments
Full derivation of the discrete-time PID used in this PR. The document shows the step-by-step development of the equations.
ros2_control_new_discretization_feature.pdf
Final notes
I'm very open to any recommendations to improve this code.