Skip to content

Conversation

ViktorCVS
Copy link
Contributor

@ViktorCVS ViktorCVS commented Sep 16, 2025

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

  • Added a first-order derivative filter (tf) applied to the D term.
  • Introduced per-term discretization selectors: i_method and d_method (e.g., "forward_euler", "backward_euler", "trapezoidal"), with "forward_euler" as the default.
  • Implemented discrete D-term updates for the supported methods, including filtered forms; falls back to unfiltered behavior when tf == 0.
  • Added internal state (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

Why is this a draft?

  • Some tests are still missing. I’ve already started adding them.
  • Existing tests need to be adjusted to accommodate the new parameters.

Final notes

I'm very open to any recommendations to improve this code.

@codecov-commenter
Copy link

codecov-commenter commented Sep 16, 2025

Codecov Report

❌ Patch coverage is 79.89130% with 37 lines in your changes missing coverage. Please review.
✅ Project coverage is 78.93%. Comparing base (534eaf3) to head (7c62e5a).

Files with missing lines Patch % Lines
control_toolbox/src/pid.cpp 60.75% 28 Missing and 3 partials ⚠️
control_toolbox/include/control_toolbox/pid.hpp 69.23% 3 Missing and 1 partial ⚠️
control_toolbox/src/pid_ros.cpp 92.00% 0 Missing and 2 partials ⚠️
Additional details and impacted files
@@               Coverage Diff               @@
##           ros2-master     #471      +/-   ##
===============================================
+ Coverage        78.86%   78.93%   +0.06%     
===============================================
  Files               29       29              
  Lines             1893     2046     +153     
  Branches           119      123       +4     
===============================================
+ Hits              1493     1615     +122     
- Misses             332      362      +30     
- Partials            68       69       +1     
Flag Coverage Δ
unittests 78.93% <79.89%> (+0.06%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
...ontrol_toolbox/include/control_toolbox/pid_ros.hpp 100.00% <ø> (ø)
control_toolbox/test/pid_ros_parameters_tests.cpp 100.00% <100.00%> (ø)
control_toolbox/test/pid_tests.cpp 100.00% <100.00%> (ø)
control_toolbox/src/pid_ros.cpp 70.37% <92.00%> (+2.50%) ⬆️
control_toolbox/include/control_toolbox/pid.hpp 61.36% <69.23%> (+0.38%) ⬆️
control_toolbox/src/pid.cpp 72.58% <60.75%> (-11.16%) ⬇️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ViktorCVS
Copy link
Contributor Author

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?

@christophfroehlich
Copy link
Contributor

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!

@christophfroehlich christophfroehlich linked an issue Sep 17, 2025 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add option to PID for Forward/Backward integration
3 participants