The file servo.py declares 2 classes of interest.
servo.AngularServo(pin, min_us=400, max_us=2200, ms_per_degree=3, max_angle=180, frequency=50)
min_us | is the smallest pulse the servo will accept |
max_us | the longest pulse the servo will accept |
ms_per_degree | sets the time required for the servo to physically rotate, setting this to None makes the class return control to the caller before the servo has finished moving leaving it up to the caller to have a sufficient delay before moving the servo again. |
max_angle | the number of degrees between the minimum pulse and maximum pulse note you should derive this with calibration experiments. my 180 degree servo actually has ~200 degrees of revolution. |
frequency | the frequency of data transfer |
The data sheet for my servo has the following characteristics, the actual values i've derived through calibration experiments are in the third column.
Property | data sheet | derived value |
min_us | 1000us | 200us |
max_us | 2000us | 2200us |
ms_per_degree | 2ms | 3ms |
max_angle | 180 | 200 |
Angular servo has 2 methods
servo.angle(degrees)
which moves the servo to the given angle if called with no arguments it returns the actual angle the servo is at which may be different to the last call to servo.angle(dwell)
. Angles are expressed as both positive and negative numbers a 180 degre servo has angles int the range [-90,90]
servo.off()
this stops the servo rotating immediately it probably invalidates calls to servo.angle()
. it is used internally, but may be required to avoid a disaster.
servo.ContinuousServo(pin, min_us=400, stop_us=1500, max_us=2200, frequency=50)
min_us | is the smallest pulse the servo will accept |
stop_us | the pulse that puts the servo in the neutral position and stopped |
max_us | the longest pulse the servo will accept |
frequency | the frequency of data transfer |
Continuous servo has 2 methods.
servo.speed(percentage)
percentage is in the range [-100,100]. -100% full speed backwards and 100% full speed forwards.
servo.off()
this is primarily an internal method, but may be of use in disaster avoidance. It's more normal with a continuous servo to call servo.speed(0)
this will issue a pules of stop_us
and bring the servo to a halt
Both Angular servo and Continuous servo have a private method _pulse(period, snooze=None)
sends a pulse of period micr seconds to the servo then sleep for snooze milli seconds allowing the servo to move. This is only documented as pulses of a period less than zero are delivered as a raw number of positive micro seconds and aren't capped by min_us
and max_us
. This is useful for servo calibration and should not be used in production code