fix(firmware): guard invalid servo position reads#86
Open
jun76 wants to merge 1 commit into
Open
Conversation
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.
fix(firmware): guard invalid servo position reads
Summary
Guard servo position reads before converting raw positions into StackChan motion angles.
ReadPos()can return an invalid value, such as-1, when the servo position read fails. Previously that value was converted directly into the current logical angle:With the default yaw zero position,
ReadPos() == -1becomes a large negative yaw angle and is then clamped to the yaw limit. This is consistent with the attached reproduction clip, where the device suddenly turns left by about 90 degrees.invalid_servo_pos.mp4
Because auto angle synchronization uses
getCurrentAngle()as the animation start point, an invalid read can also make the next motion start from an incorrect extreme angle before smoothly animating back to the intended target.This PR validates the raw servo position before using it. If the value is outside the configured raw position limits, the firmware ignores the invalid read and falls back to the last known logical servo angle.
The same validation is also applied when saving the current position as the zero calibration point, so a failed read does not overwrite the stored calibration value.
This PR only addresses firmware-side handling of invalid read results. It does not attempt to diagnose the hardware-side cause of the failed position read.
Changes
ReadPos()results before converting them into motion angles.Testing