Skip to content

Commit 69c2c42

Browse files
authored
Merge pull request #252 from srobo/dgt/sr2022-servo-board
Update the servo board docs for SR2022
2 parents 326498d + 6051cac commit 69c2c42

File tree

1 file changed

+35
-32
lines changed

1 file changed

+35
-32
lines changed

programming/sr/servos/index.md

Lines changed: 35 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -10,69 +10,72 @@ Servos
1010
This documentation refers to a feature which is only available on the physical robot kits.
1111
</div>
1212

13-
The `servos` object is used to control a collection of Servo Boards.
14-
Similar to `motors` and `ruggeduinos`, `servos` can be used like a list.
15-
To do something with the **first Servo Board**, you would use:
13+
The `servo_board` object is used to control a collection of Servo Boards.
14+
15+
When a single Servo Board is connected to your robot, you can control it
16+
using the `servo_board` object.
1617

1718
~~~~~ python
18-
R.servos[0].something...
19+
R.servo_board.something...
1920
~~~~~
2021

21-
...because indexes are 0-based (counting starts from 0, not 1).
22-
23-
When you have more than one Servo Board connected to your kit
24-
they will be ordered based upon their serial number.
25-
26-
The SR Part Code of each detected motor board is also printed to the log when your robot starts.
22+
The serial number of each detected Servo Board is printed to the log when your robot starts.
2723
It will look something like this:
2824

2925
~~~~~ not-code
30-
Found the following devices:
31-
- Servos:
32-
0: Servo( serialnum = "SR0LG31" )
26+
sr.robot3.robot INFO - Found Student Robotics Servo Board v4 - srABC1
3327
~~~~~
3428

35-
36-
However, like `motors` and `ruggeduinos`, `servos` is actually a dictionary.
37-
As a result, in `servos` you can also use the SR Part Code of the Servo Board as a key.
38-
For example, if you had a board that was labelled "SR0LG31",
39-
you could do this instead:
29+
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",
4030

4131
~~~~~ python
42-
R.servos["SR0LG31"].something...
32+
R.servo_boards["srABC1"].something...
4333
~~~~~
4434

35+
<div class="warning">
36+
When you have more than one servo board connected to your kit,
37+
you must use `R.servo_boards` and index by serial number. This is so
38+
that the kit knows which servo board you want to control.
39+
</div>
40+
4541
Setting servo positions
4642
-----------------------
4743

48-
The position of servos can range from `-100` to `100` inclusive:
44+
The position of servos can range from `-1` to `1` inclusive:
4945

5046
~~~~~ python
51-
# R.servos[SERVO_BOARD_ID][SERVO_NUMBER] = POS
47+
# R.servo_board.servos[SERVO_NUMBER].position = POS
5248

53-
# set servo 1's position (on the first Servo Board connected, board 0) to 20
54-
R.servos[0][1] = 20
55-
# Set servo 2's position (on the Servo Board with part code SRABC) to -55
56-
R.servos["SRABC"][2] = -55
57-
~~~~~
49+
# set servo 1's position to 0.2
50+
R.servo_board.servos[1].position = 0.2
5851

59-
<div class="warning" markdown="1">
60-
It is important that you use integers (whole numbers, such as `10` instead of
61-
`10.0`) when specifying servo positions.
62-
</div>
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
54+
~~~~~
6355

6456
You can read the last value a servo was set to using similar code:
6557

6658
~~~~~ python
6759
# get the last setting of the second servo on the first Servo Board
68-
lastSetting = R.servos[0][1]
60+
last_setting = R.servo_board.servos[1].position
6961
~~~~~
7062

7163
<div class="info" markdown="1">
7264
While it is possible to retrieve the last position a servo was set to,
7365
this does not guarantee that the servo is currently in that position.
7466
</div>
7567

68+
Turning off a servo
69+
-------------------
70+
71+
You can also set a servo output to be unpowered, so that there is no longer a PWM signal from the output on the servo board.
72+
73+
You can unpower the servo output by setting the position to `None`.
74+
75+
~~~~~ python
76+
r.servo_board.servos[11].position = None
77+
~~~~~
78+
7679
[How the set position relates to the servo angle](#ServoAngle) {#ServoAngle}
7780
-----------------------------------------------
7881

@@ -84,4 +87,4 @@ Some servos are very strong and it could damage the internal gears.
8487
The angle of an RC servo is controlled by the width of a pulse supplied to it periodically.
8588
There is no standard for the width of this pulse and there are differences between manufacturers as to what angle the servo will turn to for a given pulse width.
8689
To be able to handle the widest range of all servos our hardware outputs a very wide range of pulse widths which in some cases will force the servo to try and turn past its internal end-stops.
87-
You should experiment and find what the actual limit of your servos are (it almost certainly won't be -100 and 100) and not drive them past that.
90+
You should experiment and find what the actual limit of your servos are (it almost certainly won't be -1 and 1) and not drive them past that.

0 commit comments

Comments
 (0)