|
| 1 | +.. _pyb.Servo: |
| 2 | + |
1 | 3 | class Servo -- 3-wire hobby servo driver |
2 | 4 | ======================================== |
3 | 5 |
|
4 | | -Servo controls standard hobby servos with 3-wires (ground, power, signal). |
| 6 | +Servo objects control standard hobby servo motors with 3-wires (ground, power, |
| 7 | +signal). There are 4 positions on the pyboard where these motors can be plugged |
| 8 | +in: pins X1 through X4 are the signal pins, and next to them are 4 sets of power |
| 9 | +and ground pins. |
| 10 | + |
| 11 | +Example usage:: |
| 12 | + |
| 13 | + import pyb |
| 14 | + |
| 15 | + s1 = pyb.Servo(1) # create a servo object on position X1 |
| 16 | + s2 = pyb.Servo(2) # create a servo object on position X2 |
| 17 | + |
| 18 | + s1.angle(45) # move servo 1 to 45 degrees |
| 19 | + s2.angle(0) # move servo 2 to 0 degrees |
5 | 20 |
|
| 21 | + # move servo1 and servo2 synchronously, taking 1500ms |
| 22 | + s1.angle(-60, 1500) |
| 23 | + s2.angle(30, 1500) |
| 24 | + |
| 25 | +.. note:: The Servo objects use Timer(5) to produce the PWM output. You can |
| 26 | + use Timer(5) for Servo control, or your own purposes, but not both at the |
| 27 | + same time. |
6 | 28 |
|
7 | 29 | Constructors |
8 | 30 | ------------ |
9 | 31 |
|
10 | 32 | .. class:: pyb.Servo(id) |
11 | 33 |
|
12 | | - Create a servo object. ``id`` is 1-4. |
| 34 | + Create a servo object. ``id`` is 1-4, and corresponds to pins X1 through X4. |
13 | 35 |
|
14 | 36 |
|
15 | 37 | Methods |
16 | 38 | ------- |
17 | 39 |
|
18 | 40 | .. method:: servo.angle([angle, time=0]) |
19 | 41 |
|
20 | | - Get or set the angle of the servo. |
21 | | - |
| 42 | + If no arguments are given, this function returns the current angle. |
| 43 | + |
| 44 | + If arguments are given, this function sets the angle of the servo: |
| 45 | + |
22 | 46 | - ``angle`` is the angle to move to in degrees. |
23 | | - - ``time`` is the number of milliseconds to take to get to the specified angle. |
| 47 | + - ``time`` is the number of milliseconds to take to get to the specified |
| 48 | + angle. If omitted, then the servo moves as quickly as possible to its |
| 49 | + new position. |
24 | 50 |
|
25 | | -.. method:: servo.calibration([pulse_min, pulse_max, pulse_centre, [pulse_angle_90, pulse_speed_100]]) |
| 51 | +.. method:: servo.speed([speed, time=0]) |
| 52 | + |
| 53 | + If no arguments are given, this function returns the current speed. |
26 | 54 |
|
27 | | - Get or set the calibration of the servo timing. |
| 55 | + If arguments are given, this function sets the speed of the servo: |
| 56 | + |
| 57 | + - ``speed`` is the speed to change to, between -100 and 100. |
| 58 | + - ``time`` is the number of milliseconds to take to get to the specified |
| 59 | + speed. If omitted, then the servo accelerates as quickly as possible. |
28 | 60 |
|
29 | 61 | .. method:: servo.pulse_width([value]) |
30 | 62 |
|
31 | | - Get or set the pulse width in milliseconds. |
| 63 | + If no arguments are given, this function returns the current raw pulse-width |
| 64 | + value. |
32 | 65 |
|
33 | | -.. method:: servo.speed([speed, time=0]) |
| 66 | + If an argument is given, this function sets the raw pulse-width value. |
| 67 | + |
| 68 | +.. method:: servo.calibration([pulse_min, pulse_max, pulse_centre, [pulse_angle_90, pulse_speed_100]]) |
| 69 | + |
| 70 | + If no arguments are given, this function returns the current calibration |
| 71 | + data, as a 5-tuple. |
| 72 | + |
| 73 | + If arguments are given, this function sets the timing calibration: |
34 | 74 |
|
35 | | - Get or set the speed of a continuous rotation servo. |
36 | | - |
37 | | - - ``speed`` is the speed to move to change to, between -100 and 100. |
38 | | - - ``time`` is the number of milliseconds to take to get to the specified speed. |
| 75 | + - ``pulse_min`` is the minimum allowed pulse width. |
| 76 | + - ``pulse_max`` is the maximum allowed pulse width. |
| 77 | + - ``pulse_centre`` is the pulse width corresponding to the centre/zero position. |
| 78 | + - ``pulse_angle_90`` is the pulse width corresponding to 90 degrees. |
| 79 | + - ``pulse_speed_100`` is the pulse width corresponding to a speed of 100. |
0 commit comments