Servo PWM and Raspberry Pi with Adafruit 16 Channel Servo Driver

servo_01

Typical PWM Signal with common servos :

Explications : 

  1. Device Granularity (Servo resolution) :      2^12 bits = 4096 units
  2. Cycle Time (period of signal) :  20ms  (Hitec specs : 20ms)
  3. Frequency :  Freq = 1 / cycle time  = 1 / 0.020 = 50 Hz (Hitec specs : 50Hz)
  4. Time per Unit (time per tick)(resolution) :    Cycle Time / Granularity = 0.02 / 4096 = 4,88.10^-6 = 4,9 us
  5. Pulse width :  SecurePulseWidth = PulseWidth /4,9 us
POSITION DEGREE PulseWidth SecurePulseWidth
LEFT (fully ccw) 0 degrees .5 ms (Hitec specs : 0.9ms) 0.0005/0.0000049 = 102    0.0009/0.0000049= 184 )
CENTER (neutral) 90 degrees 1.5 ms (Hitec specs : 1.5ms) 0.0015/0.0000049 = 306  ( 0.0015/0.0000049= 306 )
RIGHT (fully cw) 180 degrees 2 ms (Hitec specs : 2.1ms) 0.002/0.0000049 = 408   0.0021/0.0000049= 429 )

Python Program :

from Adafruit_PWM_Servo_Driver import PWM
import time

pwm = PWM(0x40)
pwm.setPWMFreq(50)

while (True):
    puWidth = input('Enter a pulse width value between 184 and 429 (center = 306) : ')
    if puWidth > 183 and puWidth < 430:
        print'OK'
        pwm.setPWM(0, 0, puWidth)
        pwm.setPWM(1, 0, puWidth)
    else:
        print'Invalid pulse width!'

Références :

https://learn.adafruit.com/adafruit-16-channel-servo-driver-with-raspberry-pi/library-reference

https://www.raspberrypi.org/forums/viewtopic.php?t=32826

 

Soyez le premier à commenter

Poster un Commentaire

Votre adresse de messagerie ne sera pas publiée.


*