Skip to content

Conversation

brentru
Copy link
Member

@brentru brentru commented Apr 23, 2025

This pull request introduces support for pwm.proto and servo.proto messages, as part of the WipperSnapper_Proto v2 API refactor.

PWM Support:

  • New PWMController class to manage PWM operations
  • API for attaching, detaching, duty cycle control, and frequency control
  • Support for ESP32x LEDC API and Arduino Wiring API

Servo Support:

  • New ServoController class to manage servo operations
  • API for attaching, writing pulse width values, and removing servos
  • Support for ESP32x LEDC API and the Arduino Servo library

Resolves: #641

@brentru brentru changed the title V2 API - Add PWM, v2 API - Add PWM and Servo Support Apr 23, 2025
@brentru
Copy link
Member Author

brentru commented Apr 23, 2025

Testing: pwm.proto

Test Setup:

  • ESP32, Wokwi Simulator with 1x LED for PWMWriteDuty.
  • Feather ESP32-S2 with 1x Piezo Speaker for PWMWriteFrequency
    Unit Tests:
  • PWMAdd ✅ 2025-04-22
    • Called with valid parameters ✅ 2025-04-22
    • Called with invalid parameters (non-PWM capable pins) ✅ 2025-04-22
    • Called with GPIO pin that already has a PWM channel in-use ✅ 2025-04-22
    • Invalid frequency range value of 0Hz ✅ 2025-04-22
    • Invalid resolution range value of 0 bits ✅ 2025-04-22
  • PWMAdded ✅ 2025-04-22
    • Returns from a call to PWMAdd with valid params. with true boolean field and valid pin value ✅ 2025-04-22
    • Returns from a call to PWMAdd with invalid params with false boolean field and valid pin value ✅ 2025-04-22
  • PWMWriteDuty ✅ 2025-04-22
    • Test 0% duty cycle (fully off) ✅ 2025-04-22
    • Test 50% duty cycle (half on) ✅ 2025-04-22
    • Test 100% duty cycle (fully on) ✅ 2025-04-22
    • Test 25% ✅ 2025-04-22
    • Test 500% duty cycle (exceeds range) ✅ 2025-04-22
  • PWMWriteFrequency
    • Test minimum frequency.
    • Test 1kHz, 5kHz, 10kHz tones
    • Test maximum frequency
  • PWMRemove ✅ 2025-04-22
    • Remove an previously initialized PWM Pin ✅ 2025-04-22
    • Remove a non-previously initialized PWM Pin ✅ 2025-04-22

Integration Test(s)

  • Add 2x PWM components ✅ 2025-04-22
    • Add LED 1 on D12 ✅ 2025-04-22
    • Add LED2 on D13 ✅ 2025-04-22
    • Set LED1 ✅ 2025-04-22
    • Remove LED1 ✅ 2025-04-22
    • Attempt to set LED 1 - should be an error ✅ 2025-04-22
    • Set LED 2 - should be OK ✅ 2025-04-22
    • Remove LED 2 ✅ 2025-04-22
    • Attempt to set LED2 ✅ 2025-04-22

@brentru
Copy link
Member Author

brentru commented Apr 23, 2025

Testing: servo.proto

Test Setup:

  • ESP32, Wokwi Simulator with 3x Servo Motors

Unit Tests:

  • Message: ServoAdd
    • Test create a servo with valid parameters
      • Parameters Tested: D13, 50Hz, 500uS, 2500uS
    • Test create a servo with identical pin name as already initialized servo
    • Test add servo to D13, and another to D15
  • Message: ServoAdded
    • Did ServoAdd test .proto file wrappers updated #1 return a ServoAdded message to the broker?
      • ServoAdded contains the same pin name?
      • ServoAdded contains success boolean set to true
    • Did ServoAdd test .proto file wrappers updated #2 return a ServoAdded message to the broker?
      • ServoAdded contains the same pin name?
      • Expected Error: ServoAdded contains success boolean set to false
  • Message ServoRemove
    • Test remove a valid servo pin
    • Test remove an invalid servo pin
      • Input: A pin which wasn't initialized as a servo
  • Message ServoWrite
    • Valid ServoWrite message
      • Ensure servo angle matches pulse_width
    • Boundary tests
      • pulse_width to 0uS minimum
      • pulse_width to 2500uS maximum
      • pulse_width to an out of range value
    • Invalid pin/empty pin
      • Expected Error:
    • Test writing before adding
      Integration Tests
  • Servo Lifecycle
    • Add servo to pin D13 with default params.
    • Verify ServoAdded success field is true
    • Test writing 45deg, 90deg, 135deg, 180deg, 0 deg, 180deg positions to the servo
      • 0°500μs45°1000μs90°1500μs135°2000μs180°2500μs
    • Test removing servo
  • Multiple Servos
    • Add servo to pin D13 with default params.
      • Verify ServoAdded
    • Add servo to pin D12 with default params
      • Verify ServoAdded
    • Write both servos to different positions
      • servo d13 to 1000uS
      • servo d12 to 2000uS
    • Remove both servos
  • Weird issue at 2500 boundary - isn't writing full 2500?
    • Go to 2000
    • Go to 2500
    • Go to 500 (zero)

@brentru
Copy link
Member Author

brentru commented Apr 24, 2025

✅ Tested PWMWriteFrequency with an Adafruit FunHouse ESP32S2

@brentru
Copy link
Member Author

brentru commented Apr 24, 2025

✅ Performed self review, pushing to tyeth for final review

@brentru brentru requested a review from tyeth April 24, 2025 15:51
@brentru brentru merged commit 5f4a8e4 into migrate-api-v2 Apr 25, 2025
38 checks passed
@brentru brentru deleted the add-pwm-api-v2 branch April 25, 2025 15:06
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.

2 participants