Skip to content

Commit e96a2a5

Browse files
authored
SR2024 - Update Section - Power board API
2 parents fa8ad3e + e8b0ee9 commit e96a2a5

File tree

1 file changed

+60
-55
lines changed

1 file changed

+60
-55
lines changed

programming/power.md

Lines changed: 60 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
---
2+
redirect_from:
3+
- /programming/sr/power
24
layout: page
35
title: Power Board API
46
---
@@ -7,121 +9,124 @@ Power Board API
79
===============
810

911
There are a few things that can be done with the power board, namely current and voltage sensing, and beeping.
10-
As there is only one power board, it is not accessed like a list like `motors` and is instead accessed directly, for example:
12+
See the [Power Board](/docs/kit/power_board) hardware page for more details.
13+
14+
15+
Accessing the Power Board
16+
-------------------------
17+
18+
The power board can be accessed using the `power_board` property of the `Robot` object.
1119

1220
~~~~~ python
13-
R.power_board.something...
21+
from sr.robot3 import *
22+
robot = Robot()
23+
24+
my_power_board = robot.power_board
1425
~~~~~
1526

16-
[Power Outputs](#outputs) {#outputs}
17-
-------
1827

19-
Each of the power board's controllable outputs has a constant whose name closely
20-
matches the name of the output:
28+
Power Outputs
29+
-------------
30+
31+
Each of the power board's controllable outputs has a constant whose name closely matches the name of the output:
2132

2233
* H0 : `OUT_H0`
2334
* H1 : `OUT_H1`
2435
* L0 : `OUT_L0`
2536
* L1 : `OUT_L1`
26-
* L2 : N/A (Not Controllable)
37+
* L2 : N/A (Not Controllable - This port is used to power the Brain Board)
2738
* L3 : `OUT_L3`
2839
* 5V : `OUT_FIVE_VOLT`
2940

30-
Both of the 5V outputs are controlled simultaneously.
41+
Both of the 5V outputs are controlled together.
3142

32-
While they are all turned on when your code starts running,
33-
you can control whether each output is turned on or off like so:
43+
All the ports are turned on when your code starts running, you can then control whether each output is turned on or off like so:
3444

3545
~~~~~ python
36-
from sr.robot3 import *
37-
3846
# Turn output H0 off
39-
R.power_board.outputs[OUT_H0].is_enabled = False
47+
robot.power_board.outputs[OUT_H0].is_enabled = False
4048

4149
# Turn output L0 on
42-
R.power_board.outputs[OUT_L0].is_enabled = True
50+
robot.power_board.outputs[OUT_L0].is_enabled = True
4351

4452
# Find out whether L3 is enabled
45-
print(R.power_board.outputs[OUT_L3].is_enabled)
53+
print(robot.power_board.outputs[OUT_L3].is_enabled)
4654

4755
# Find the current (in Amps) being used by L3
48-
print(R.power_board.outputs[OUT_L3].current)
56+
print(robot.power_board.outputs[OUT_L3].current)
4957
~~~~~
5058

51-
An exception is raised if you try to set an output index which doesn't exist.
52-
5359
You can also control all the outputs together:
5460

5561
~~~~~ python
56-
R.power_board.outputs.power_off()
57-
R.power_board.outputs.power_on()
62+
robot.power_board.outputs.power_off()
63+
robot.power_board.outputs.power_on()
5864
~~~~~
5965

6066
<div class="warning">
61-
If you turn off the power output which is powering another of your boards,
62-
then they will appear to be missing and your code will break if you try to
63-
control them.
67+
If you turn off the power output which is powering another one of your boards,
68+
they will appear to be missing and your code will break if you try to control them.
6469
</div>
6570

6671

67-
[Battery Status](#battery) {#battery}
68-
-------
72+
Battery Status
73+
--------------
6974

7075
The power board can report both the battery voltage, in Volts, and the current being drawn from it, in Amps.
7176
You can access these values like so:
7277

7378
~~~~~ python
74-
# Print the battery voltage and current to the log
75-
print(
76-
R.power_board.battery_sensor.voltage,
77-
R.power_board.battery_sensor.current,
78-
)
79+
# Print the battery voltage in volts
80+
print(robot.power_board.battery_sensor.voltage)
81+
82+
# Print the battery current in amps
83+
print(robot.power_board.battery_sensor.current)
7984
~~~~~
8085

81-
A fully charged battery will measure 12.6V.
82-
The power board will turn off and signal a low battery at 10.2V.
83-
The discharge curve is roughly linear between 11.4V and 10.4V.
86+
- A fully charged battery will measure 12.6V.
87+
- The power board will turn off and signal a low battery at 10.2V.
88+
- The discharge curve is roughly linear between 11.4V and 10.4V.
8489

8590

86-
[Beeping](#beeping) {#beeping}
91+
Beeping
8792
-------
8893

8994
The power board has a piezo buzzer which can beep.
9095

91-
The `buzz` function accepts multiple parameters, depending on what you
92-
want to play. The first argument is the duration of the beep, in
93-
seconds. The later arguments are either the note you want to play, or
94-
the frequency of the buzzer (in Hertz). You have to specify which of
95-
note or frequency you're passing using a keyword argument, your code
96-
will fail otherwise.
96+
The `buzz` function accepts multiple parameters, depending on what you want to play.
97+
- The first argument is either the note you want to play, or the frequency of the buzzer in Hertz.
98+
- The second argument is the duration of the beep, in seconds.
9799

98-
Theoretically, the piezo buzzer will buzz at any provided frequency, however
99-
humans can only hear between [20Hz and 20000Hz][pitch-range].
100+
The `Note` enum provides notes in [scientific pitch notation](https://en.wikipedia.org/wiki/Scientific_pitch_notation) between `C6` and `C8`.
101+
You can play other tones by providing a frequency.
100102

101-
The `Note` enum provides notes in [scientific pitch notation][pitch-notation]
102-
between `C6` and `C8`. You can play other tones by providing a frequency.
103+
The frequency on the buzzer is limited from 8Hz to 10,000Hz
103104

104105
<div class="info" markdown="1">
105-
Calling `buzz` is non-blocking, which means it doesn't actually wait
106-
for the piezo to stop buzzing before continuing with your code. If you
107-
want to wait for the buzzing to stop, use the <code>blocking</code> argument!
106+
Calling `buzz` is non-blocking, which means it doesn't actually wait for the piezo to stop buzzing before continuing with your code.
107+
If you want to wait for the buzzing to stop, use the `blocking` argument.
108108
</div>
109109

110110
~~~~~ python
111-
from sr.robot3 import Note
112-
113111
# Beep for 0.5s in D.
114-
R.power_board.piezo.buzz(0.5, Note.D6)
112+
R.power_board.piezo.buzz(Note.D6, 0.5)
115113

116114
# Beep for 2s at 400Hz
117-
R.power_board.piezo.buzz(2, 400)
115+
R.power_board.piezo.buzz(400, 2)
118116

119117
# Beep for 3s at 250Hz and wait for it to finish
120-
R.power_board.piezo.buzz(3, 250, blocking=True)
118+
R.power_board.piezo.buzz(250, 3, blocking=True)
121119
~~~~~
122120

123-
`ValueError` is raised if the note is not recognised or the frequency is not an integer.
124121

122+
Start Button
123+
------------
124+
125+
You can manually wait for the start button to be pressed, not only at the start.
126+
127+
~~~~~ python
128+
robot.wait_start()
129+
~~~~~
125130

126-
[pitch-range]: https://en.wikipedia.org/wiki/Hearing_range#Humans
127-
[pitch-notation]: https://en.wikipedia.org/wiki/Scientific_pitch_notation
131+
This method will block until the start button is pressed.
132+
This may be useful for testing, but be sure to remove it in the competition, as you won't be allowed to touch the start button after a match has begun!

0 commit comments

Comments
 (0)