Skip to content

Conversation

pjbRPF
Copy link
Contributor

@pjbRPF pjbRPF commented Oct 16, 2025

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:

  1. DEFAULT DIRECTION (Simplest)
    • step(10) - Uses default clockwise direction
    • Minimizes cognitive load for basic use cases

  2. 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

  3. 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

  4. 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

@pjbRPF pjbRPF requested a review from MarcScott October 16, 2025 13:25
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:

1. DEFAULT DIRECTION (Simplest)
   • step(10) - Uses default clockwise direction
   • Minimizes cognitive load for basic use cases

2. 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

3. 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

4. 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
pjbRPF and others added 2 commits October 17, 2025 16:42
- Add MotionSensor section to recipes.rst (missing from previous merge)
- Add Stepper section to recipes.rst with comprehensive examples
- Update changelog.rst with v0.5.0 entries for both classes
- Organize motor sections together for better flow
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant