Skip to content

fix(math): Fix range mapper deadband logic #423

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

Merged
merged 1 commit into from
May 8, 2025

Conversation

finger563
Copy link
Contributor

Description

  • 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

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:
CleanShot 2025-05-08 at 16 53 47

How has this been tested?

Build and run math/example on QtPy ESP32s3 and ensure the output of rm4 matches what we expect.

Screenshots (if appropriate, e.g. schematic, board, console logs, lab pictures):

After:
CleanShot 2025-05-08 at 17 04 12

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation Update
  • Hardware (schematic, board, system design) change
  • Software change

Checklist:

  • My change requires a change to the documentation.
  • I have added / updated the documentation related to this change via either README or WIKI

Software

  • I have added tests to cover my changes.
  • I have updated the .github/workflows/build.yml file to add my new test to the automated cloud build github action.
  • All new and existing tests passed.
  • My code follows the code style of this project.

* 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.
@finger563 finger563 self-assigned this May 8, 2025
@finger563 finger563 requested a review from Copilot May 8, 2025 22:26
@finger563 finger563 added bug Something isn't working math labels May 8, 2025
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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;

Copy link

github-actions bot commented May 8, 2025

✅Static analysis result - no issues found! ✅

@finger563 finger563 merged commit 01f45fa into main May 8, 2025
78 checks passed
@finger563 finger563 deleted the fix/range-mapper-deadband-logic branch May 8, 2025 23:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working math
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants