Power Board API
There are a few things that can be done with the power board, namely current and voltage sensing, and beeping. See the Power Board hardware page for more details.
Accessing the Power Board
The power board can be accessed using the
power_board property of the
from sr.robot3 import *
robot = Robot()
my_power_board = robot.power_board
Each of the power board’s controllable outputs has a constant whose name closely matches the name of the output:
- H0 :
- H1 :
- L0 :
- L1 :
- L2 : N/A (Not Controllable - This port is used to power the Brain Board)
- L3 :
- 5V :
Both of the 5V outputs are controlled together.
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:
# Turn output H0 off
robot.power_board.outputs[OUT_H0].is_enabled = False
# Turn output L0 on
robot.power_board.outputs[OUT_L0].is_enabled = True
# Find out whether L3 is enabled
# Find the current (in Amps) being used by L3
You can also control all the outputs together:
The power board can report both the battery voltage, in Volts, and the current being drawn from it, in Amps. You can access these values like so:
# Print the battery voltage in volts
# Print the battery current in amps
- A fully charged battery will measure 12.6V.
- The power board will turn off and signal a low battery at 10.2V.
- The discharge curve is roughly linear between 11.4V and 10.4V.
The power board has a piezo buzzer which can beep.
buzz function accepts multiple parameters, depending on what you want to play.
- The first argument is either the note you want to play, or the frequency of the buzzer in Hertz.
- The second argument is the duration of the beep, in seconds.
Note enum provides notes in scientific pitch notation between
You can play other tones by providing a frequency.
The frequency on the buzzer is limited from 8Hz to 10,000Hz
buzz is non-blocking, which means it doesn’t actually wait for the piezo to stop buzzing before continuing with your code.
If you want to wait for the buzzing to stop, use the
# Beep for 0.5s in D.
# Beep for 2s at 400Hz
# Beep for 3s at 250Hz and wait for it to finish
robot.power_board.piezo.buzz(250, 3, blocking=True)
You can manually wait for the start button to be pressed, not only at the start.
This method will block until the start button is pressed. 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!