1
1
---
2
+ redirect_from :
3
+ - /programming/sr/power
2
4
layout : page
3
5
title : Power Board API
4
6
---
@@ -7,121 +9,124 @@ Power Board API
7
9
===============
8
10
9
11
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.
11
19
12
20
~~~~~ python
13
- R.power_board.something...
21
+ from sr.robot3 import *
22
+ robot = Robot()
23
+
24
+ my_power_board = robot.power_board
14
25
~~~~~
15
26
16
- [ Power Outputs] ( #outputs ) {#outputs}
17
- -------
18
27
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:
21
32
22
33
* H0 : ` OUT_H0 `
23
34
* H1 : ` OUT_H1 `
24
35
* L0 : ` OUT_L0 `
25
36
* L1 : ` OUT_L1 `
26
- * L2 : N/A (Not Controllable)
37
+ * L2 : N/A (Not Controllable - This port is used to power the Brain Board )
27
38
* L3 : ` OUT_L3 `
28
39
* 5V : ` OUT_FIVE_VOLT `
29
40
30
- Both of the 5V outputs are controlled simultaneously .
41
+ Both of the 5V outputs are controlled together .
31
42
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:
34
44
35
45
~~~~~ python
36
- from sr.robot3 import *
37
-
38
46
# Turn output H0 off
39
- R .power_board.outputs[OUT_H0 ].is_enabled = False
47
+ robot .power_board.outputs[OUT_H0 ].is_enabled = False
40
48
41
49
# Turn output L0 on
42
- R .power_board.outputs[OUT_L0 ].is_enabled = True
50
+ robot .power_board.outputs[OUT_L0 ].is_enabled = True
43
51
44
52
# 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)
46
54
47
55
# 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)
49
57
~~~~~
50
58
51
- An exception is raised if you try to set an output index which doesn't exist.
52
-
53
59
You can also control all the outputs together:
54
60
55
61
~~~~~ 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()
58
64
~~~~~
59
65
60
66
<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.
64
69
</div >
65
70
66
71
67
- [ Battery Status] ( #battery ) {#battery}
68
- -------
72
+ Battery Status
73
+ --------------
69
74
70
75
The power board can report both the battery voltage, in Volts, and the current being drawn from it, in Amps.
71
76
You can access these values like so:
72
77
73
78
~~~~~ 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 )
79
84
~~~~~
80
85
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.
84
89
85
90
86
- [ Beeping] ( #beeping ) {#beeping}
91
+ Beeping
87
92
-------
88
93
89
94
The power board has a piezo buzzer which can beep.
90
95
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.
97
99
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 .
100
102
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
103
104
104
105
<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.
108
108
</div >
109
109
110
110
~~~~~ python
111
- from sr.robot3 import Note
112
-
113
111
# 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 )
115
113
116
114
# Beep for 2s at 400Hz
117
- R.power_board.piezo.buzz(2 , 400 )
115
+ R.power_board.piezo.buzz(400 , 2 )
118
116
119
117
# 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 )
121
119
~~~~~
122
120
123
- ` ValueError ` is raised if the note is not recognised or the frequency is not an integer.
124
121
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
+ ~~~~~
125
130
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