Increase PID ROS wrapper test coverage #484
Merged
christophfroehlich merged 12 commits intoros-controls:ros2-masterfrom Sep 26, 2025
Merged
Increase PID ROS wrapper test coverage #484christophfroehlich merged 12 commits intoros-controls:ros2-masterfrom
christophfroehlich merged 12 commits intoros-controls:ros2-masterfrom
Conversation
Adds a new test in pid_ros_parameters_tests.cpp that verifies PidROS::reset() honors the save_i_term ROS parameter. Using an integral-only controller makes the effect of retaining vs. clearing the I-term directly observable without P/D noise. The test confirms the integral is cleared when false and retained when true.
…term for PidROS::reset() and added new test for reset(bool save_i_term) Reworked the test for the void PidROS::reset() that had a mistake to use an I-only controller initialized via initialize_from_args with large finite clamps and to snapshot the integral state using a zero-error compute_command(0.0, dt) so assertions match the controller’s step semantics. The test now explicitly toggles the save_i_term ROS parameter and verifies that reset() clears or retains the I-term accordingly. Added a new test to cover the void PidROS::reset(bool save_i_term) method, asserting that reset(false) clears and reset(true) preserves the integral state using the same snapshot approach.
… that verifies the overload honors the supplied error_dot and publishes a consistent PidState. Using gains P=1, I=0, D=1 and wide output limits, the test expects cmd = e + e_dot, subscribes to /pid_state, and asserts the message’s error, timestep (converted to seconds), and output match the compute step. Test is placed in pid_ros_publisher_tests.cpp
… and verifies key fields are printed (gains, limits, anti-windup info, errors, command) without brittle formatting assumptions. The test initializes a deterministic PID state, avoids saturation effects, and ensures INFO output from the dedicated logger is correctly emitted.
Add a GTest that verifies PidROS::get_current_cmd() returns the current command across scenarios: default is 0 after init, it round-trips values set via set_current_cmd(), and it reflects commands produced by compute_command() (including saturation to ±5). Also sanity-checks a large finite value to ensure simple delegation to the underlying PID is robust.
It verifies round-trip behavior (set_current_cmd to get_current_cmd) for positive, negative, and large finite values, then confirms compute_command() remains stable (saturates as expected) and get_current_cmd() reflects the last computed output.
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## ros2-master #484 +/- ##
===============================================
+ Coverage 78.90% 80.77% +1.86%
===============================================
Files 29 29
Lines 1896 2023 +127
Branches 119 124 +5
===============================================
+ Hits 1496 1634 +138
+ Misses 332 320 -12
- 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:
|
saikishor
reviewed
Sep 22, 2025
…blePidROS construction and initialize_from_args() for clearer readability.
Contributor
Author
|
Ready for re-review @saikishor I believe I have addressed all your initial feedback |
Member
christophfroehlich
left a comment
There was a problem hiding this comment.
Overall LGTM, some minor comments
…r and executor.spin_some() in publisher test. This removes the deprecation warning and aligns with the guidance in ros-controls#488.
…ack fired, the received PidState is non-null, and its output matches the computed command.
edeb343
into
ros-controls:ros2-master
25 checks passed
mergify Bot
pushed a commit
that referenced
this pull request
Sep 26, 2025
(cherry picked from commit edeb343)
christophfroehlich
pushed a commit
that referenced
this pull request
Sep 26, 2025
8 tasks
8 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Overview
This PR increases test coverage for control_toolbox::PidROS, focusing on methods that previously had little or no coverage. (as described in #409)
What changed
files changed are:
Added 6 tests to cover these methods in the below files
In control_toolbox/test/pid_ros_parameters_tests.cpp, we added five tests: two I-only tests that check reset() and reset(bool) either clear or keep the integral term; one PI test that calls print_values() and captures the log output; and two P-only tests that cover get_current_cmd() and set_current_cmd(), using tight limits so the results are predictable.
In control_toolbox/test/pid_ros_publisher_tests.cpp, we added one test that runs the publisher end-to-end on a LifecycleNode and confirms a PidState message is published.
Before every commit I made sure to build the package locally, run colcon test and do pre-commit commands. All tests passed and no formatting was flagged.
Notes for Reviewer
This is my first contribution to ros2_control, so I am very open to feedback and am happy to make any changes that are requested.
I can remove comments after a initial review has been made?