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
The power board will turn off and signal a low battery at 10.2V.
29
-
The discharge curve is roughly linear between 11.4V and 10.4V.
30
-
31
-
32
16
[Power Outputs](#outputs) {#outputs}
33
17
-------
34
18
@@ -46,29 +30,93 @@ While they are all turned on when your code starts running,
46
30
you can control whether each output is turned on or off like so:
47
31
48
32
~~~~~python
33
+
from sr.robot3 import*
34
+
49
35
# Turn output H0 off
50
-
R.power.output[OUT_H0] =False
36
+
r.power_board.outputs[OUT_H0].is_enabled=False
51
37
52
38
# Turn output L0 on
53
-
R.power.output[OUT_L0] =True
39
+
r.power_board.outputs[OUT_L0].is_enabled =True
40
+
41
+
# Find out whether L3 is enabled
42
+
print(r.power_board.outputs[OUT_L3].is_enabled)
43
+
44
+
# Find the current (in Amps) being used by L3
45
+
print(r.power_board.outputs[OUT_L3].current)
54
46
~~~~~
55
47
56
48
An exception is raised if you try to set an output index which doesn't exist.
57
49
50
+
You can also control all the outputs together:
51
+
52
+
~~~~~python
53
+
r.power_board.outputs.power_off()
54
+
r.power_board.outputs.power_on()
55
+
~~~~~
56
+
57
+
<divclass="warning">
58
+
If you turn off the power output which is powering another of your boards,
59
+
then they will appear to be missing and your code will break if you try to
60
+
control them.
61
+
</div>
62
+
63
+
64
+
[Battery Status](#battery) {#battery}
65
+
-------
66
+
67
+
The power board can report both the battery voltage, in Volts, and the current being drawn from it, in Amps.
68
+
You can access these values like so:
69
+
70
+
~~~~~python
71
+
# Print the battery voltage and current to the log
72
+
print(
73
+
r.power_board.battery_sensor.voltage,
74
+
r.power_board.battery_sensor.current,
75
+
)
76
+
~~~~~
77
+
78
+
A fully charged battery will measure 12.6V.
79
+
The power board will turn off and signal a low battery at 10.2V.
80
+
The discharge curve is roughly linear between 11.4V and 10.4V.
81
+
58
82
59
83
[Beeping](#beeping) {#beeping}
60
84
-------
61
85
62
86
The power board has a piezo buzzer which can beep.
63
87
64
-
The beep function accepts 1 or 2 parameters, `duration` is compulsory and is measured in milliseconds. `note` is optional, but must be one string of `a-g` or `uc`. `frequency` is also optional, and should be an integer. One of `note` and `frequency`, must be given. If both are given, `note` is used.
88
+
The `buzz` function accepts multiple parameters, depending on what you
89
+
want to play. The first argument is the duration of the beep, in
90
+
seconds. The later arguments are either the note you want to play, or
91
+
the frequency of the buzzer (in Hertz). You have to specify which of
92
+
note or frequency you're passing using a keyword argument, your code
93
+
will fail otherwise.
94
+
95
+
Theoretically, the piezo buzzer will buzz at any provided frequency, however
96
+
humans can only hear between [20Hz and 20000Hz][pitch-range].
97
+
98
+
The `Note` enum provides notes in [scientific pitch notation][pitch-notation]
99
+
between `C6` and `C8`. You can play other tones by providing a frequency.
100
+
101
+
<divclass="info">
102
+
Calling `buzz` is non-blocking, which means it doesn't actually wait
103
+
for the piezo to stop buzzing before continuing with your code. If you
104
+
want to wait for the buzzing to stop, add a `sleep` afterwards!
105
+
If you send more than 32 beeps to the robot too quickly, your power board will crash!
106
+
</div>
65
107
66
108
~~~~~python
109
+
from sr.robot3 import Note
110
+
67
111
# Beep for 0.5s in D.
68
-
R.power.beep(500, note='d')
112
+
r.power_board.piezo.buzz(0.5, Note.D6)
69
113
70
114
# Beep for 2s at 400Hz
71
-
R.power.beep(2000, frequency=400)
115
+
r.power_board.piezo.buzz(2, 400)
72
116
~~~~~
73
117
74
118
`ValueError` is raised if the note is not recognised or the frequency is not an integer.
0 commit comments