refactor(calibrate): name the motor-position numbers - #88
Open
cn0303 wants to merge 1 commit into
Open
Conversation
The plausible-encoder-range check was inlined as `pos > 0 and pos < 5000` (and its negation) in three places, with the wrap-around jump threshold (2000) and the minimum-sweep threshold (100) as bare literals elsewhere. Same concepts, slightly different spellings, easy to drift when one changes. Hoist them into named module constants and an `_is_valid_position()` helper, and call it from the three filter sites. Pure refactor, no behaviour change: the helper's bounds are exclusive on both ends, matching the old inline checks. A parametrised boundary test pins that behaviour.
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.
What does this PR do?
calibrate.pydecided "is this a plausible motor-position reading" with bareliterals repeated in three places, plus two more single-use thresholds:
pos <= 0 or pos >= 5000(skip invalid) inget_statuspos > 0 and pos < 5000(keep valid) in_step_range_recording, twiceabs(pos - prev) > 2000: the encoder wrap-around jumprange_diff < 100: the "joint barely moved" warning thresholdSame concepts written slightly differently, so changing the valid range meant
finding every copy and hoping they agreed.
The change
Hoist the values into named module constants and route the three plausible-range
checks through one helper:
The three filter sites become
_is_valid_position(pos)/not _is_valid_position(pos), and the two remaining thresholds read_MAX_POSITION_JUMP/_MIN_CALIBRATION_RANGE.No behaviour change
This is a pure refactor. The helper's bounds are exclusive on both ends, which
matches the old
pos > 0 and pos < 5000exactly (and its negationpos <= 0 or pos >= 5000). The wrap-around and minimum-range thresholds keep their exactvalues.
Testing
Behaviour-preserving, so the proof is the existing calibrate suite staying green
plus a new parametrised boundary test on
_is_valid_positionpinning theexclusive bounds (0 and 5000 both invalid; 1, 4095, 4999 valid).
pytest tests/test_calibrate.py: 15 passed. Full suite: 207 passed (the only 3 failuresare pre-existing on main, in dataset_repair/jobs, unrelated). ruff check and ruff
format green; pre-commit (mypy, bandit, typos) green.
There is no hardware before/after to run here; the values and comparisons are
unchanged, only their names.