feat(hardware_interface): implement dynamic command toggling for MockHardware #3241
Open
shlok-mehndiratta wants to merge 1 commit intoros-controls:masterfrom
Open
Conversation
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #3241 +/- ##
==========================================
- Coverage 89.10% 89.06% -0.04%
==========================================
Files 160 160
Lines 19753 19821 +68
Branches 1597 1601 +4
==========================================
+ Hits 17600 17653 +53
- Misses 1486 1498 +12
- Partials 667 670 +3
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
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.
Closes #3214
While working on some controller tests, I realized that the
GenericSystemmock always mirrors commands to states perfectly. This makes it hard to test how high-level controllers or state machines react when the hardware actually stops responding or gets stuck (e.g., communication loss or a physical state-lock).This PR adds a
~/set_command_propagationservice (usingstd_srvs/SetBool) to theGenericSystemmock. It lets you manually "freeze" the command propagation at runtime:data: false: The mock stops updating its state and stays at its last value, ignoring new commands.data: true: Resumes normal mirroring.Implementation Notes
std::atomic<bool>withmemory_order_acquire/releasefor the toggle. This keeps the real-timeread()loop lock-free and safe from the asynchronous service thread without adding mutex overhead.mock_components/GenericSystemplugin. I haven't tested this on physical hardware since it's a simulation-only feature, and it shouldn't have any side effects on real drivers.TestableResourceManagerhelper to support injecting an executor, which allowed me to verify the service logic in a standard unit test.I've verified this both with a new test case (
toggle_command_propagation_service) and manually withros2 service call. All 29 existing tests pass.Hope this helps anyone else trying to simulate hardware gremlins in their tests!
Verification Screenshot
(I'll attach a screenshot here showing the join states freezing after the service call)