Servo Shield and movement speed

I’m looking for a way to slow down the movement speed of the servos while using the servo shield example code. The only way I can figure out how to make this work right now is to send a bunch of intermediate steps instead of just the final position with a speed value. Doing it the way I have below will probably restrict the processing for individual image processing tasks I will need to add in. Any ideas?

# Servo Shield Example.
#
# This example demonstrates the servo shield. Please follow these steps:
#
#   1. Connect a servo to any PWM output.
#   2. Connect a 3.7v battery (or 5V source) to VIN and GND.
#   3. Copy pca9685.py and servo.py to OpenMV and reset it.
#   4. Connect and run this script in the IDE.

import time
from servo import Servos
from machine import I2C, Pin

i2c = I2C(sda=Pin('P5'), scl=Pin('P4'))
servo = Servos(i2c, address=0x40, freq=50, min_us=650, max_us=2800, degrees=180)

while True:
    for j in range(45, 135, 5): 
        for i in range(0, 8):
            servo.position(i, j)
        time.sleep(50)
    for j in range(135, 45, -5): 
        for i in range(0, 8):
            servo.position(i, j)
        time.sleep(50)

Ben

https://docs.openmv.io/library/pyb.Servo.html#pyb.Servo.speed

Thank you, I must have missed that in my quick look through of the code.

Ben

Is that available for the servo shield? I’m getting a “Servos object has no attribute ‘speed’”

Ben

Oh, I see, you want to do this on the servo shield.

No, it is not. If you want to do this then you will probably need to add a timer callback and use the MicroPython schedule method or directly edit the servo position in a timer interrupt.

Please read the interrupt section on the MicroPython language guide.

With the servo shield this is going to be hard to do. The chip we are using is meant for PWM control of LEDs. It’s used for servo control by folks a lot too. But, given this, it has no support for changing the pulse with without you telling it what the new width needs to be. So, this has to be done during an interrupt. But, if you try to do I2C data transfer during an interrupt you’re going to block other methods while moving I2C data.

will do, I’ll search down that path.

Ben