Appearance
Using Power Supplies
A Rockface power supply tool provides DC power to the device it's connected to.
In the rockface
python library, power supply tools are represented using the rockface.tools.psu.PSUTool
type:
py
from rockface import Rig
from rockface.tools.psu import PSUTool
rig = Rig.find_by_name("my-rig")
psu = rig.tools["my-psu"]
assert isinstance(psu, PSUTool)
Examples continue from the above
For brevity, the rest of the examples on this page will continue on from the above example, with the psu
variable set to a PSUTool
instance.
Turning On and Off
A power supply can be turned on and off using its enabled
property. This property can also be read to discover the current state:
py
print("Turning the power on")
psu.enabled = True
print("The power is", "on" if psu.enabled else "off")
print("Turning the power off")
psu.enabled = False
Configuring
So far we've turned a power supply on and off, but we haven't set the voltage we want to see at its output, nor have we set a limit on its output current. This section describes how to configure these aspects of the power supply, as well as some other parameters. All of this configuration is done via the config
property of the PSUTool
object.
Voltage Setpoint
The voltage setpoint can be configured using the config.voltage
property:
py
# A setpoint voltage of 3V please
psu.config.voltage = 3
What is a voltage setpoint?
This is the voltage that the power supply will try to drive its output to. This doesn't meant that the output will always be at this voltage — for example the output voltage may be lower than the setpoint due to a current limit.
Current Limit
The current limit can be set using the config.current_limit
property:
py
# A current limit of 100mA
psu.config.current_limit = 0.1
Power supply tools have two possible current limit modes: "trip" and "limiting". You can set and get this mode using the config.current_limit_mode
property:
py
from rockface.tools.psu import CurrentLimitMode
# Use limiting mode
psu.config.current_limit_mode = CurrentLimitMode.LIMITING
print("The current limit mode is", psu.config.current_limit_mode)
# Switch back to trip mode
psu.config.current_limit_mode = CurrentLimitMode.TRIP
Trip Mode
This is the default current limit mode. In this mode, the power supply will "trip" if its load draws more current than the configured limit. When this happens, it will turn its output off and enter into a "tripped" state.
The tripped state of the power supply can be retrieved using its tripped
property:
py
if psu.tripped:
print("The power supply has tripped")
While it is tripped, attempts to turn the power supply back on, or to change to a different current limit mode will result in an exception being raised. This is to ensure that hardware faults are not compounded by indiscriminately continuing past them.
To clear the tripped state, set the tripped
property to False
:
py
psu.tripped = False
# Now the power supply can be turned back on again
psu.enabled = True
The tripped state will also be cleared when the power supply tool is reset.
Limiting Mode
When the current limit mode is set to "limiting mode", the power supply will deliver up to the configured limit, and will reduce its output voltage to maintain this.
Discovering Capabilities
Power supply tools come in different shapes and sizes. Your rig will have been fitted with the most appropriate power supply to meet your needs.
The capabilities of your power supply tool are available through its spec
property. Through this property, you can discover the minimum and maximum voltages that your power supply tool can output:
py
print("Minimum voltage:", psu.spec.voltage.min)
print("Maximum voltage:", psu.spec.voltage.max)
print("Minimum current:", psu.spec.current.min)
print("Maximum current:", psu.spec.current.max)
The voltage setpoint and current limit of power supplies have resolutions associated with them. These can be discovered from the spec
property too:
py
print("Voltage setpoint resolution:", psu.spec.voltage.setpoint_resolution)
print("Current limit resolution:", psu.spec.current.limit_resolution)
The resolution with which a power supply can sense the voltage at its output, or the current it is delivering, might be different from the resolution with which the voltage setpoint and current limit can be set. These are also available via the spec
property:
py
print("Voltage sense resolution:", psu.spec.voltage.sense_resolution)
print("Current sense resolution:", psu.spec.current.sense_resolution)
Sensing
The power supply can measure the voltage that is at its output:
py
print(f"Voltage at output: {psu.voltage}V")
It can also measure the current it is delivering to its load:
py
print(f"Current from output: {psu.current}A")
Reset
A power supply can be reset using its reset
method:
py
psu.reset()
The power supply will always be reset at the end of a session (when the rig lock is dropped). Its output will be turned off, and its configuration will return to default:
- Current limit: 0A
- Voltage setpoint: Closest voltage to zero within the capabilities of the supply.