Skip to content

Conversation

dijidiji
Copy link

Description

I've gone over the servo and DC motor functions that were added to SplashKit recently, per the related planner card.

Changes:

  • Cleaned up comments and removed extra whitespace
  • Added a separate brake_motor function, to activate the braking mode on a motor module.
  • stop_motor now allows the motor to coast to a stop.
  • Added the functions get the PWM range of a pin using the pigpio API. This was necessary because of an issue where set_motor_speed would function incorrectly if the user changed the PWM range with raspi_set_pwm_range (the speed function assumed a default range of 255).
  • set_motor_speed now scales to the PWM range returned by pigpio for the enable pin.
  • Removed PWM pin checks from the servo pulse width functions. Pigpio uses software PWM unless specified, which is supported on all pins. If hardware PWM support is needed, we should add a separate function to do that.
  • open_servo now sets a min_angle and max_angle variables for a given servo_device. This defaults to 0 and 180, as in the original code, but now allows a user to specify a range of motion for the servo.
  • set_servo_angle is no longer clamped to a 0..180 degree range and works with an arbitrary angle range.
  • set_servo_value maps an input range of 0..1 to the PWM range. This is useful when a user doesn't know the angle range of a servo, which makes the angle setting function unintuitive. This is handy because many servo datasheets don't specify their range of motion and a user may not want to measure it themselves in the case that it doesn't match the default 180 degrees.

Notes:

  1. _motor_data has a motor_driver_type variable which doesn't seem to be used anywhere. I've left this for now since I'm unsure about what to do with it. I'm assuming it's to implement functions specific to certain motor modules.
  2. Similarly, I don't have a variety of modules to test with, so I've only made changes that correspond to the original code, which assumed a L298N.
  3. I wasn't sure of what the safe PWM range for a servo is, so I left it the same as in the original code.

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as
    expected)
  • Documentation (update or new)

How Has This Been Tested?

This still needs to be tested with a variety of hardware modules. I'll try to get my hands on a couple of motor modules and servos soon.

Testing Checklist

  • Tested with sktest
  • Tested with skunit_tests

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have requested a review from ... on the Pull Request

dijidiji and others added 9 commits August 19, 2025 19:10
The pigpio uses software PWM for the PWM and servo functions,
which is supported on all GPIO pins. So, these functions were changed
to be similar to the other GPIO functions.
If hardware PWM is to be added, it should use hardware_PWM from pigpio.
Servos are now opened with min_angle and max_angle variables. These are
optional in the signature and default to 0 and 180, following the original
code.
set_servo_angle functions the same as before but maps to this range, rather
than the static range of 0..180 it was before.
set_servo_value takes an input from 0 to 1 and maps it to the PWM range.
This is useful when the user doesn't know the angle range of a servo,
in which case set_servo_angle is unintuitive.
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