Skip to content

Commit 70f8e3c

Browse files
committed
Import sbot's docs for power and motor API
2 parents 5552157 + 89aedef commit 70f8e3c

File tree

2 files changed

+155
-0
lines changed

2 files changed

+155
-0
lines changed

docs/api/power-board.md

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
# Power Board API
2+
3+
The power board can be accessed using the `power_board` property of
4+
the `Robot` object.
5+
6+
```python
7+
my_power_board = r.power_board
8+
```
9+
10+
## Power outputs
11+
12+
The six outputs of the power board are grouped together as `power_board.outputs`.
13+
14+
The power board's six outputs can be turned on and off using the
15+
`power_on` and `power_off` functions of the group respectively.
16+
17+
!!! tip
18+
`power_on` is called when you set up your robot, so
19+
this doesn't need to be called manually. The ports will come on
20+
automatically as soon as your robot is ready, before the start button is
21+
pressed.
22+
23+
```python
24+
r.power_board.outputs.power_off()
25+
r.power_board.outputs.power_on()
26+
```
27+
28+
You can also get information about and control each output in the group.
29+
An output is indexed using the appropriate `PowerOutputPosition`.
30+
31+
```python
32+
from sbot import PowerOutputPosition
33+
34+
r.power_board.outputs[PowerOutputPosition.H0].is_enabled = True
35+
r.power_board.outputs[PowerOutputPosition.L3].is_enabled = False
36+
37+
boolean_value = r.power_board.outputs[PowerOutputPosition.L2].is_enabled
38+
39+
current_amps = r.power_board.outputs[PowerOutputPosition.H1].current
40+
```
41+
42+
!!! warning
43+
The motor and servo boards are powered through these
44+
power outputs, whilst the power is off, you won't be able to control
45+
your motors or servos. They will register as a missing board and your code will
46+
break if you try and control them.
47+
48+
## Battery Sensor
49+
50+
The power board has some sensors that can monitor the status of your battery.
51+
This can be useful for checking the charge status of your battery.
52+
53+
```python
54+
battery_voltage = r.power_board.battery_sensor.voltage
55+
battery_current_amps = r.power_board.battery_sensor.current
56+
```
57+
58+
## Buzzing 🐝
59+
60+
The power board has a piezo sounder which can buzz.
61+
62+
The `buzz` function accepts two parameters. The first argument is the duration of the beep, in seconds.
63+
The second argument is either the note you want to play, or the frequency of the buzzer (in Hertz).
64+
65+
Theoretically, the piezo buzzer will buzz at any provided frequency,
66+
however humans can only hear between [20Hz and
67+
20000Hz](https://en.wikipedia.org/wiki/Hearing_range#Humans).
68+
69+
The `Note` enum provides notes in [scientific pitch notation](https://en.wikipedia.org/wiki/Scientific_pitch_notation) between
70+
`C6` and `C8`. You can play other tones by providing a frequency.
71+
72+
!!! tip
73+
Calling `buzz` is non-blocking, which means it doesn't
74+
actually wait for the piezo to stop buzzing before continuing with your
75+
code. If you want to wait for the buzzing to stop, add a
76+
`sleep` afterwards! If you send more than 32 beeps to the robot too
77+
quickly, your power board will crash!
78+
79+
```python
80+
from sbot import Note
81+
82+
# Buzz for half a second in D6.
83+
r.power_board.piezo.buzz(0.5, Note.D6)
84+
85+
# Buzz for 2 seconds at 400Hz
86+
r.power_board.piezo.buzz(2, 400)
87+
```
88+
89+
## Start Button
90+
91+
You can manually wait for the start button to be pressed, not only at
92+
the start.
93+
94+
```python
95+
r.wait_start()
96+
```
97+
98+
This may be useful for debugging, but be sure to remove it in the
99+
competition, as you won't be allowed to touch the start button after a match has begun!

docs/api/servo-board.md

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# Servo Board API
2+
3+
The kit can control multiple servos simultaneously. One Servo Board can
4+
control up to twelve servos.
5+
6+
## Accessing the Servo Board
7+
8+
The servo board can be accessed using the `servo_board` property of
9+
the `Robot` object.
10+
11+
```python
12+
my_servo_board = r.servo_board
13+
```
14+
15+
This board object has an array containing the servos connected to it,
16+
which can be accessed as `servos[0]`, `servos[1]`, `servos[2]`, etc.
17+
The servo board is labelled so you know which servo is which.
18+
19+
!!! tip
20+
Remember that lists start counting at 0.
21+
22+
## Setting servo positions
23+
24+
The position of servos can range from `-1` to `1` inclusive:
25+
26+
```python
27+
# set servo 1's position to 0.2
28+
r.servo_board.servos[1].position = 0.2
29+
30+
# Set servo 2's position to -0.55
31+
r.servo_board.servos[2].position = -0.55
32+
```
33+
34+
You can read the last value a servo was set to using similar code:
35+
36+
```python
37+
last_position = r.servo_board.servos[11].position
38+
```
39+
40+
!!! warning
41+
While it is possible to retrieve the last position a servo was set to, this does not guarantee that the servo is currently in that position.
42+
43+
## How the set position relates to the servo angle
44+
45+
!!! danger
46+
You should be careful about forcing a servo to drive past its end stops. Some servos are very strong and it could damage the internal gears.
47+
48+
The angle of an RC servo is controlled by the width of a pulse supplied
49+
to it periodically. There is no standard for the width of this pulse and
50+
there are differences between manufacturers as to what angle the servo
51+
will turn to for a given pulse width. To be able to handle the widest
52+
range of all servos our hardware outputs a very wide range of pulse
53+
widths which in some cases will force the servo to try and turn past its
54+
internal end-stops. You should experiment and find what the actual limit
55+
of your servos are (it almost certainly won't be -1 and 1) and not
56+
drive them past that.

0 commit comments

Comments
 (0)