fix(math): Fix range mapper deadband logic#423
Merged
Conversation
* Fix issue in range mapper which could occur if the center and range deadzones overlapped * More explicitly allow uni-directional output mappings when min==center or max==center * Flesh out test cases for floating point precision issues and values around the deadbands It was found that the output could be discontinuous if the center deadzone overlapped with one of the range deadzones. The solution was to better handle the case that there are unidirectional output distributions (e.g. where center==min or center==max) and to better handle how the deadbands are calculated. Build and run `math/example` on QtPy ESP32s3 and ensure the output of `rm4` matches what we expect.
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR addresses a bug in the range mapper logic by improving how deadbands are handled when the center overlaps with the minimum or maximum values, and enhances test coverage for floating point precision issues.
- Adjust deadband logic in the range mapper to support uni-directional output mappings
- Update test cases in the math example to validate the new behavior and floating point edge cases
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| components/math/include/range_mapper.hpp | Updated deadband handling logic and refactored condition checks for uni-directional mappings. |
| components/math/example/main/math_example.cpp | Modified test configuration and expanded test cases to cover edge cases around center, min, and max values. |
Comments suppressed due to low confidence (1)
components/math/example/main/math_example.cpp:196
- [nitpick] Consider renaming 'oob_range' to 'out_of_bounds_range' for improved clarity.
static constexpr float oob_range = deadband * 3.0f;
|
✅Static analysis result - no issues found! ✅ |
sodank808
approved these changes
May 8, 2025
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.
Description
Motivation and Context
It was found that the output could be discontinuous if the center deadzone overlapped with one of the range deadzones. The solution was to better handle the case that there are unidirectional output distributions (e.g. where center==min or center==max) and to better handle how the deadbands are calculated.
Before:

How has this been tested?
Build and run
math/exampleon QtPy ESP32s3 and ensure the output ofrm4matches what we expect.Screenshots (if appropriate, e.g. schematic, board, console logs, lab pictures):
After:

Types of changes
Checklist:
Software
.github/workflows/build.ymlfile to add my new test to the automated cloud build github action.