Skip to content

Commit ddbcc79

Browse files
committed
docs: Add quickref info about Servo; improve Servo docs.
1 parent ce5b5ca commit ddbcc79

3 files changed

Lines changed: 67 additions & 13 deletions

File tree

docs/library/pyb.Servo.rst

Lines changed: 54 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,79 @@
1+
.. _pyb.Servo:
2+
13
class Servo -- 3-wire hobby servo driver
24
========================================
35

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
520

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.
628

729
Constructors
830
------------
931

1032
.. class:: pyb.Servo(id)
1133

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.
1335

1436

1537
Methods
1638
-------
1739

1840
.. method:: servo.angle([angle, time=0])
1941

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+
2246
- ``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.
2450

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.
2654

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.
2860

2961
.. method:: servo.pulse_width([value])
3062

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.
3265

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:
3474

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.

docs/library/pyb.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ Power related functions
9898
If given no arguments, returns a tuple of clock frequencies:
9999
(sysclk, hclk, pclk1, pclk2).
100100
These correspond to:
101+
101102
- sysclk: frequency of the CPU
102103
- hclk: frequency of the AHB bus, core memory and DMA
103104
- pclk1: frequency of the APB1 bus

docs/quickref.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,18 @@ See :ref:`pyb.Pin <pyb.Pin>`. ::
4848
p_in = Pin('X2', Pin.IN, Pin.PULL_UP)
4949
p_in.value() # get value, 0 or 1
5050

51+
Servo control
52+
-------------
53+
54+
See :ref:`pyb.Servo <pyb.Servo>`. ::
55+
56+
from pyb import Servo
57+
58+
s1 = Servo(1) # servo on position 1 (X1, VIN, GND)
59+
s1.angle(45) # move to 45 degrees
60+
s1.angle(-60, 1500) # move to -60 degrees in 1500ms
61+
s1.speed(50) # for continuous rotation servos
62+
5163
External interrupts
5264
-------------------
5365

0 commit comments

Comments
 (0)