Add Stepper motor class #129
Open
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.
Core Implementation:
• Complete Stepper class supporting 4-pin stepper motors (28BYJ-48 + ULN2003)
• Three step sequences: wave, full, half-step for different torque/smoothness needs
• Position tracking with step counting and angle calculation
• Configurable steps-per-revolution and step delays for different motors
API Design Philosophy - Four Complementary Approaches:
DEFAULT DIRECTION (Simplest)
• step(10) - Uses default clockwise direction
• Minimizes cognitive load for basic use cases
CONVENIENCE METHODS (Explicit Intent)
• step_clockwise(10), step_counterclockwise(10)
• rotate_clockwise(90), rotate_counterclockwise(90)
• revolve_clockwise(2), revolve_counterclockwise(2)
• Short aliases: step_cw(), rotate_ccw(), revolve_cw()
• Clear, readable, self-documenting code
PARAMETERIZED METHODS (Flexible Control)
• step(10, direction='cw'|'ccw'|1|-1)
• rotate(90, direction='clockwise'|'counter-clockwise')
• revolution(2, direction=1|-1)
• Supports both string and numeric direction parameters
• Flexible _normalize_direction() handles multiple formats
ALIAS SUPPORT (Compatibility)
• revolve() as alias for revolution()
• StepperMotor as backward-compatible class alias
• Maintains consistency with existing picozero patterns
Technical Features:
• Polymorphic direction parameters (string/numeric) with validation
• Real-time speed control via step_delay property
• Position reset capability for homing/calibration
• Proper resource management with off() and close() methods
• Comprehensive error handling with descriptive messages
Testing Strategy:
• Validates all API approaches for consistency
• Covers edge cases and error conditions
Documentation:
• Added Stepper class to API documentation
• Exported in init.py for public access
• Comprehensive docstrings with parameter details
• Usage examples showing all API patterns