|
| 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! |
0 commit comments