add direction to moster settings #138
Merged
Merged
Conversation
Introduce a per-axis `direction` sign array to hide wiring polarity from callers and keep a consistent user coordinate frame. stepSize is stored as a positive magnitude while the hardware direction (+1/-1) is tracked separately and applied at the firmware boundary. setup_motor() now accepts an optional `direction` and also consumes a negative stepSize as a direction flip. Updated conversions in position parsing, move preparation, currentPosition updates, and motor status parsing to apply the direction sign when converting between hardware steps and physical (user-frame) units.
Contributor
There was a problem hiding this comment.
Pull request overview
Adds a per-axis hardware-direction sign to Motor so that wiring polarity can be inverted without flipping the user-facing coordinate frame. setup_motor() now stores abs(stepSize) plus a direction (derived from a negative stepSize or passed explicitly), and that sign is applied at the firmware boundary in three places.
Changes:
- Introduce
Motor.direction(int8 array,[A, X, Y, Z], default +1). - Extend
setup_motor()with adirectionkwarg and split sign from magnitude when storingstepSize. - Apply
directionin_callback_motor_status(),move_stepper()(includingcurrentPositionupdates), andget_position().
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+296
to
+306
| # Split sign from magnitude. An explicit `direction` always wins; | ||
| # otherwise the sign of stepSize is consumed and stepSize becomes | ||
| # a positive scale factor. | ||
| if direction is None: | ||
| sign = -1 if stepSize < 0 else 1 | ||
| else: | ||
| sign = -1 if direction < 0 else 1 | ||
| stepSize = abs(stepSize) | ||
|
|
||
| axisIdx = self.xyztTo1230(axis) | ||
| self.direction[axisIdx] = sign |
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.
No description provided.