adafruit / Adafruit_CircuitPython_ServoKit

CircuitPython helper library for the PWM/Servo FeatherWing, Shield and Pi HAT kits.
MIT License
69 stars 29 forks source link

ServoKit: Add an interface to set min_pulse and max_pulse #52

Open T-Mosher opened 2 weeks ago

T-Mosher commented 2 weeks ago

The interface for objects created with ServoKit include settings for the i2c address, reference clock speed, and pulse frequency. What's missing in order to fully calibrate a servo is the ability to set the min_pulse and max_pulse parameters.

class ServoKit:
    def __init__(
        self,
        *,
        channels: int,
        i2c: Optional[I2C] = None,
        address: int = 0x40,
        reference_clock_speed: int = 25000000,
        frequency: int = 50
    ) -> None:
        if channels not in [8, 16]:
            raise ValueError("servo_channels must be 8 or 16!")
        self._items = [None] * channels
        self._channels = channels
        if i2c is None:
            i2c = board.I2C()
        self._pca = PCA9685(
            i2c, address=address, reference_clock_speed=reference_clock_speed
        )
        self._pca.frequency = frequency

        self._servo = _Servo(self)
        self._continuous_servo = _ContinuousServo(self)

It may be possible to get to the min_pulse and max_pulse parameters by referencing down into the Servo and adafruit_motor classes, but this isn't simple or obvious in the way it could be.

T-Mosher commented 2 weeks ago

Reference from this forum thread: https://forums.adafruit.com/viewtopic.php?p=1019856#p1019856