You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: programming/sr/servos/index.md
+35-32Lines changed: 35 additions & 32 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -10,69 +10,72 @@ Servos
10
10
This documentation refers to a feature which is only available on the physical robot kits.
11
11
</div>
12
12
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.
16
17
17
18
~~~~~python
18
-
R.servos[0].something...
19
+
R.servo_board.something...
19
20
~~~~~
20
21
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.
27
23
It will look something like this:
28
24
29
25
~~~~~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
33
27
~~~~~
34
28
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",
40
30
41
31
~~~~~python
42
-
R.servos["SR0LG31"].something...
32
+
R.servo_boards["srABC1"].something...
43
33
~~~~~
44
34
35
+
<divclass="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
+
45
41
Setting servo positions
46
42
-----------------------
47
43
48
-
The position of servos can range from `-100` to `100` inclusive:
44
+
The position of servos can range from `-1` to `1` inclusive:
# 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
58
51
59
-
<divclass="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
+
~~~~~
63
55
64
56
You can read the last value a servo was set to using similar code:
65
57
66
58
~~~~~python
67
59
# 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
69
61
~~~~~
70
62
71
63
<divclass="info"markdown="1">
72
64
While it is possible to retrieve the last position a servo was set to,
73
65
this does not guarantee that the servo is currently in that position.
74
66
</div>
75
67
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
+
76
79
[How the set position relates to the servo angle](#ServoAngle) {#ServoAngle}
77
80
-----------------------------------------------
78
81
@@ -84,4 +87,4 @@ Some servos are very strong and it could damage the internal gears.
84
87
The angle of an RC servo is controlled by the width of a pulse supplied to it periodically.
85
88
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.
86
89
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