Skip to content

Commit eac0ae9

Browse files
committed
Update servo board content
1 parent fa8ad3e commit eac0ae9

File tree

1 file changed

+31
-35
lines changed

1 file changed

+31
-35
lines changed

programming/servos.md

Lines changed: 31 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -6,64 +6,60 @@ title: Servos Board API
66
Servos Board API
77
================
88

9-
The `servo_board` object is used to control a collection of Servo Boards.
9+
The kit can control multiple servos.
10+
One servo board can control up to 12 servos.
11+
See the [Servo Board](/docs/kit/servo_board) hardware page for more details about this board.
1012

11-
When a single Servo Board is connected to your robot, you can control it
12-
using the `servo_board` object.
1313

14-
~~~~~ python
15-
R.servo_board.something...
16-
~~~~~
17-
18-
The serial number of each detected Servo Board is printed to the log when your robot starts.
19-
It will look something like this:
20-
21-
~~~~~ not-code
22-
sr.robot3.robot INFO - Found Student Robotics Servo Board v4 - srABC1
23-
~~~~~
14+
Accessing the Servo Board
15+
-------------------------
2416

25-
If you have more than one Servo Board attached, you need to specify which one you want to control. This is done using the serial number of the board. For example: if you had a board that was labelled "srABC1",
17+
The servo board can be accessed using the `servo_board` property of the `Robot` object.
2618

2719
~~~~~ python
28-
R.servo_boards["srABC1"].something...
20+
from sr.robot3 import *
21+
robot = Robot()
22+
23+
my_servo_board = robot.servo_board
2924
~~~~~
3025

31-
<div class="warning" markdown="1">
32-
When you have more than one servo board connected to your kit,
33-
you must use `R.servo_boards` and index by serial number. This is so
34-
that the kit knows which servo board you want to control.
35-
</div>
3626

3727
Setting servo positions
3828
-----------------------
3929

40-
Each of the twelve servo outputs can be controlled separately. The servo outputs
41-
are numbered 0-11, see the [Servo Board](/docs/kit/servo_board#connectors) docs
42-
for details of which output is which.
30+
Each of the twelve servo outputs can be controlled separately.
31+
The servo outputs are numbered 0-11, see the [Servo Board](/docs/kit/servo_board#connectors) docs for details of which output is which.
32+
33+
This board object has an array containing the servos connected to it, which can be accessed as servos[0], servos[1], servos[2], etc.
34+
The servo board is labelled so you know which servo is which.
4335

4436
The position of servos can range from `-1` to `1` inclusive:
4537

4638
~~~~~ python
47-
# R.servo_board.servos[SERVO_NUMBER].position = POS
39+
# Set servo 0 position to 0.2
40+
robot.servo_board.servos[0].position = 0.2
4841

49-
# set servo 1's position to 0.2
50-
R.servo_board.servos[1].position = 0.2
51-
52-
# Set servo 2's position (on the Servo Board with serial number srABC) to -0.55
53-
R.servo_boards["srABC"].servos[2].position = -0.55
42+
# Set servo 2 position to -0.55
43+
robot.servo_board.servos[2].position = -0.55
5444
~~~~~
5545

5646
You can read the last value a servo was set to using similar code:
5747

5848
~~~~~ python
59-
# get the last setting of the second servo on the first Servo Board
60-
last_setting = R.servo_board.servos[1].position
49+
# Print the last setting of servo number 1
50+
print(robot.servo_board.servos[1].position))
6151
~~~~~
6252

63-
<div class="info" markdown="1">
64-
While it is possible to retrieve the last position a servo was set to,
65-
this does not guarantee that the servo is currently in that position.
66-
</div>
53+
Disabling servo outputs
54+
-----------------------
55+
56+
Setting a position to `None` will disable an output.
57+
This is the state all the servo outputs are in when the board turns on, where no servo pulses are being sent to the outputs.
58+
59+
~~~~~ python
60+
# disable servo output 5
61+
robot.servo_board.servos[5].position = None
62+
~~~~~
6763

6864
[How the set position relates to the servo angle](#ServoAngle) {#ServoAngle}
6965
-----------------------------------------------

0 commit comments

Comments
 (0)