WPILibC++ 2025.3.2
Loading...
Searching...
No Matches
PowerDistribution.h
Go to the documentation of this file.
1// Copyright (c) FIRST and other WPILib contributors.
2// Open Source Software; you can modify and/or share it under the terms of
3// the WPILib BSD license file in the root directory of this project.
4
5#pragma once
6
7#include <stdint.h>
8
9#include "hal/Types.h"
10
11/**
12 * @defgroup hal_pd Power Distribution Functions
13 * @ingroup hal_capi
14 * Functions to control Power Distribution devices.
15 * @{
16 */
17
18/**
19 * The types of power distribution devices.
20 */
22 /** Automatically determines the module type */
24 /** CTRE (Cross The Road Electronics) Power Distribution Panel (PDP). */
26 /** REV Power Distribution Hub (PDH). */
28};
29
30/** Use the default module number for the selected module type */
31#define HAL_DEFAULT_POWER_DISTRIBUTION_MODULE -1
32
33#ifdef __cplusplus
34extern "C" {
35#endif
36
37/**
38 * Initializes a Power Distribution Panel.
39 *
40 * @param[in] moduleNumber the module number to initialize
41 * @param[in] type the type of module to initialize
42 * @param[in] allocationLocation the location where the allocation is occurring
43 * @param[out] status Error status variable. 0 on success.
44 * @return the created PowerDistribution handle
45 */
47 int32_t moduleNumber, HAL_PowerDistributionType type,
48 const char* allocationLocation, int32_t* status);
49
50/**
51 * Gets the module number for a specific handle.
52 *
53 * @param[in] handle the module handle
54 * @param[out] status Error status variable. 0 on success.
55 * @return the module number
56 */
58 int32_t* status);
59
60/**
61 * Cleans a PowerDistribution module.
62 *
63 * @param handle the module handle
64 */
66
67/**
68 * Checks if a PowerDistribution channel is valid.
69 *
70 * @param handle the module handle
71 * @param channel the channel to check
72 * @return true if the channel is valid, otherwise false
73 */
75 int32_t channel);
76
77/**
78 * Checks if a PowerDistribution module is valid.
79 *
80 * @param module the module to check
81 * @param type the type of module
82 * @return true if the module is valid, otherwise false
83 */
86
87/**
88 * Gets the type of PowerDistribution module.
89 *
90 * @param[in] handle the module handle
91 * @param[out] status Error status variable. 0 on success.
92 * @return the type of module
93 */
95 HAL_PowerDistributionHandle handle, int32_t* status);
96
97/**
98 * Gets the number of channels for this handle.
99 *
100 * @param[in] handle the handle
101 * @param[out] status Error status variable. 0 on success.
102 * @return number of channels
103 */
105 int32_t* status);
106
107/**
108 * Gets the temperature of the Power Distribution Panel.
109 *
110 * Not supported on the Rev PDH and returns 0.
111 *
112 * @param[in] handle the module handle
113 * @param[out] status Error status variable. 0 on success.
114 * @return the module temperature (celsius)
115 */
117 int32_t* status);
118
119/**
120 * Gets the PowerDistribution input voltage.
121 *
122 * @param[in] handle the module handle
123 * @param[out] status Error status variable. 0 on success.
124 * @return the input voltage (volts)
125 */
127 int32_t* status);
128
129/**
130 * Gets the current of a specific PowerDistribution channel.
131 *
132 * @param[in] handle the module handle
133 * @param[in] channel the channel
134 * @param[out] status Error status variable. 0 on success.
135 * @return the channel current (amps)
136 */
138 HAL_PowerDistributionHandle handle, int32_t channel, int32_t* status);
139
140/**
141 * Gets the current of all channels on the PowerDistribution.
142 *
143 * The array must be large enough to hold all channels.
144 *
145 * @param[in] handle the module handle
146 * @param[out] currents the currents
147 * @param[in] currentsLength the length of the currents array
148 * @param[out] status Error status variable. 0 on success.
149 */
151 HAL_PowerDistributionHandle handle, double* currents,
152 int32_t currentsLength, int32_t* status);
153
154/**
155 * Gets the total current of the PowerDistribution.
156 *
157 * @param[in] handle the module handle
158 * @param[out] status Error status variable. 0 on success.
159 * @return the total current (amps)
160 */
162 int32_t* status);
163
164/**
165 * Gets the total power of the Power Distribution Panel.
166 *
167 * Not supported on the Rev PDH and returns 0.
168 *
169 * @param[in] handle the module handle
170 * @param[out] status Error status variable. 0 on success.
171 * @return the total power (watts)
172 */
174 int32_t* status);
175
176/**
177 * Gets the total energy of the Power Distribution Panel.
178 *
179 * Not supported on the Rev PDH and returns 0.
180 *
181 * @param[in] handle the module handle
182 * @param[out] status Error status variable. 0 on success.
183 * @return the total energy (joules)
184 */
186 int32_t* status);
187
188/**
189 * Resets the PowerDistribution accumulated energy.
190 *
191 * Not supported on the Rev PDH and does nothing.
192 *
193 * @param[in] handle the module handle
194 * @param[out] status Error status variable. 0 on success.
195 */
197 int32_t* status);
198
199/**
200 * Clears any PowerDistribution sticky faults.
201 *
202 * @param[in] handle the module handle
203 * @param[out] status Error status variable. 0 on success.
204 */
206 int32_t* status);
207
208/**
209 * Power on/off switchable channel.
210 *
211 * This is a REV PDH-specific function. This function will no-op on CTRE PDP.
212 *
213 * @param[in] handle the module handle
214 * @param[in] enabled true to turn on switchable channel
215 * @param[out] status Error status variable. 0 on success.
216 */
218 HAL_PowerDistributionHandle handle, HAL_Bool enabled, int32_t* status);
219
220/**
221 * Returns true if switchable channel is powered on.
222 *
223 * This is a REV PDH-specific function. This function will no-op on CTRE PDP.
224 *
225 * @param[in] handle the module handle
226 * @param[out] status Error status variable. 0 on success.
227 * @return the state of the switchable channel
228 */
230 HAL_PowerDistributionHandle handle, int32_t* status);
231
232/**
233 * Power distribution version.
234 */
236 /// Firmware major version number.
238 /// Firmware minor version number.
240 /// Firmware fix version number.
241 uint32_t firmwareFix;
242 /// Hardware minor version number.
244 /// Hardware major version number.
246 /// Unique ID.
247 uint32_t uniqueId;
248};
249
251 /** Breaker fault on channel 0. */
253 /** Breaker fault on channel 1. */
255 /** Breaker fault on channel 2. */
257 /** Breaker fault on channel 3. */
259 /** Breaker fault on channel 4. */
261 /** Breaker fault on channel 5. */
263 /** Breaker fault on channel 6. */
265 /** Breaker fault on channel 7. */
267 /** Breaker fault on channel 8. */
269 /** Breaker fault on channel 9. */
271 /** Breaker fault on channel 10. */
273 /** Breaker fault on channel 12. */
275 /** Breaker fault on channel 13. */
277 /** Breaker fault on channel 14. */
279 /** Breaker fault on channel 15. */
281 /** Breaker fault on channel 16. */
283 /** Breaker fault on channel 17. */
285 /** Breaker fault on channel 18. */
287 /** Breaker fault on channel 19. */
289 /** Breaker fault on channel 20. */
291 /** Breaker fault on channel 21. */
293 /** Breaker fault on channel 22. */
295 /** Breaker fault on channel 23. */
297 /** Breaker fault on channel 24. */
299 /** The input voltage is below the minimum voltage. */
300 uint32_t brownout : 1;
301 /** A warning was raised by the device's CAN controller. */
302 uint32_t canWarning : 1;
303 /** The hardware on the device has malfunctioned. */
304 uint32_t hardwareFault : 1;
305};
306
307/**
308 * Storage for REV PDH Sticky Faults
309 */
311 /** Breaker fault on channel 0. */
313 /** Breaker fault on channel 1. */
315 /** Breaker fault on channel 2. */
317 /** Breaker fault on channel 3. */
319 /** Breaker fault on channel 4. */
321 /** Breaker fault on channel 5. */
323 /** Breaker fault on channel 6. */
325 /** Breaker fault on channel 7. */
327 /** Breaker fault on channel 8. */
329 /** Breaker fault on channel 9. */
331 /** Breaker fault on channel 10. */
333 /** Breaker fault on channel 12. */
335 /** Breaker fault on channel 13. */
337 /** Breaker fault on channel 14. */
339 /** Breaker fault on channel 15. */
341 /** Breaker fault on channel 16. */
343 /** Breaker fault on channel 17. */
345 /** Breaker fault on channel 18. */
347 /** Breaker fault on channel 19. */
349 /** Breaker fault on channel 20. */
351 /** Breaker fault on channel 21. */
353 /** Breaker fault on channel 22. */
355 /** Breaker fault on channel 23. */
357 /** Breaker fault on channel 24. */
359 /** The input voltage is below the minimum voltage. */
360 uint32_t brownout : 1;
361 /** A warning was raised by the device's CAN controller. */
362 uint32_t canWarning : 1;
363 /** The device's CAN controller experienced a "Bus Off" event. */
364 uint32_t canBusOff : 1;
365 /** The hardware on the device has malfunctioned. */
366 uint32_t hardwareFault : 1;
367 /** The firmware on the device has malfunctioned. */
368 uint32_t firmwareFault : 1;
369 /** The device has rebooted. */
370 uint32_t hasReset : 1;
371};
372
373/**
374 * Get the version of the PowerDistribution.
375 *
376 * @param[in] handle the module handle
377 * @param[out] version the HAL_PowerDistributionVersion to populate
378 * @param[out] status Error status variable. 0 on success.
379 */
382 int32_t* status);
383/**
384 * Get the current faults of the PowerDistribution.
385 *
386 * On a CTRE PDP, this will return an object with no faults active.
387 *
388 * @param[in] handle the module handle
389 * @param[out] faults the HAL_PowerDistributionFaults to populate
390 * @param[out] status Error status variable. 0 on success.
391 */
394 int32_t* status);
395
396/**
397 * Gets the sticky faults of the PowerDistribution.
398 *
399 * On a CTRE PDP, this will return an object with no faults active.
400 *
401 * @param[in] handle the module handle
402 * @param[out] stickyFaults the HAL_PowerDistributionStickyFaults to populate
403 * @param[out] status Error status variable. 0 on success.
404 */
407 HAL_PowerDistributionStickyFaults* stickyFaults, int32_t* status);
408
410 int32_t* status);
411
417
419 HAL_PowerDistributionHandle handle, int32_t* count, int32_t* status);
420
422 int32_t count);
423
425 int32_t* status);
426
427#ifdef __cplusplus
428} // extern "C"
429#endif
430/** @} */
double HAL_GetPowerDistributionChannelCurrent(HAL_PowerDistributionHandle handle, int32_t channel, int32_t *status)
Gets the current of a specific PowerDistribution channel.
double HAL_GetPowerDistributionTemperature(HAL_PowerDistributionHandle handle, int32_t *status)
Gets the temperature of the Power Distribution Panel.
void HAL_CleanPowerDistribution(HAL_PowerDistributionHandle handle)
Cleans a PowerDistribution module.
void HAL_StopPowerDistributionStream(HAL_PowerDistributionHandle handle, int32_t *status)
double HAL_GetPowerDistributionTotalPower(HAL_PowerDistributionHandle handle, int32_t *status)
Gets the total power of the Power Distribution Panel.
void HAL_GetPowerDistributionAllChannelCurrents(HAL_PowerDistributionHandle handle, double *currents, int32_t currentsLength, int32_t *status)
Gets the current of all channels on the PowerDistribution.
HAL_PowerDistributionType
The types of power distribution devices.
Definition PowerDistribution.h:21
void HAL_FreePowerDistributionStreamData(HAL_PowerDistributionChannelData *data, int32_t count)
void HAL_ClearPowerDistributionStickyFaults(HAL_PowerDistributionHandle handle, int32_t *status)
Clears any PowerDistribution sticky faults.
HAL_Bool HAL_CheckPowerDistributionModule(int32_t module, HAL_PowerDistributionType type)
Checks if a PowerDistribution module is valid.
int32_t HAL_GetPowerDistributionNumChannels(HAL_PowerDistributionHandle handle, int32_t *status)
Gets the number of channels for this handle.
HAL_PowerDistributionHandle HAL_InitializePowerDistribution(int32_t moduleNumber, HAL_PowerDistributionType type, const char *allocationLocation, int32_t *status)
Initializes a Power Distribution Panel.
double HAL_GetPowerDistributionTotalEnergy(HAL_PowerDistributionHandle handle, int32_t *status)
Gets the total energy of the Power Distribution Panel.
int32_t HAL_GetPowerDistributionModuleNumber(HAL_PowerDistributionHandle handle, int32_t *status)
Gets the module number for a specific handle.
void HAL_GetPowerDistributionFaults(HAL_PowerDistributionHandle handle, HAL_PowerDistributionFaults *faults, int32_t *status)
Get the current faults of the PowerDistribution.
HAL_Bool HAL_GetPowerDistributionSwitchableChannel(HAL_PowerDistributionHandle handle, int32_t *status)
Returns true if switchable channel is powered on.
HAL_PowerDistributionChannelData * HAL_GetPowerDistributionStreamData(HAL_PowerDistributionHandle handle, int32_t *count, int32_t *status)
void HAL_GetPowerDistributionVersion(HAL_PowerDistributionHandle handle, HAL_PowerDistributionVersion *version, int32_t *status)
Get the version of the PowerDistribution.
void HAL_GetPowerDistributionStickyFaults(HAL_PowerDistributionHandle handle, HAL_PowerDistributionStickyFaults *stickyFaults, int32_t *status)
Gets the sticky faults of the PowerDistribution.
HAL_Bool HAL_CheckPowerDistributionChannel(HAL_PowerDistributionHandle handle, int32_t channel)
Checks if a PowerDistribution channel is valid.
double HAL_GetPowerDistributionVoltage(HAL_PowerDistributionHandle handle, int32_t *status)
Gets the PowerDistribution input voltage.
void HAL_StartPowerDistributionStream(HAL_PowerDistributionHandle handle, int32_t *status)
void HAL_SetPowerDistributionSwitchableChannel(HAL_PowerDistributionHandle handle, HAL_Bool enabled, int32_t *status)
Power on/off switchable channel.
struct HAL_PowerDistributionChannelData HAL_PowerDistributionChannelData
HAL_PowerDistributionType HAL_GetPowerDistributionType(HAL_PowerDistributionHandle handle, int32_t *status)
Gets the type of PowerDistribution module.
void HAL_ResetPowerDistributionTotalEnergy(HAL_PowerDistributionHandle handle, int32_t *status)
Resets the PowerDistribution accumulated energy.
double HAL_GetPowerDistributionTotalCurrent(HAL_PowerDistributionHandle handle, int32_t *status)
Gets the total current of the PowerDistribution.
@ HAL_PowerDistributionType_kAutomatic
Automatically determines the module type.
Definition PowerDistribution.h:23
@ HAL_PowerDistributionType_kCTRE
CTRE (Cross The Road Electronics) Power Distribution Panel (PDP).
Definition PowerDistribution.h:25
@ HAL_PowerDistributionType_kRev
REV Power Distribution Hub (PDH).
Definition PowerDistribution.h:27
int32_t HAL_Bool
Definition Types.h:73
HAL_Handle HAL_PowerDistributionHandle
Definition Types.h:65
#define HAL_ENUM(name)
Definition Types.h:76
Definition PowerDistribution.h:412
float current
Definition PowerDistribution.h:413
int32_t channel
Definition PowerDistribution.h:414
uint32_t timestamp
Definition PowerDistribution.h:415
Definition PowerDistribution.h:250
uint32_t channel21BreakerFault
Breaker fault on channel 22.
Definition PowerDistribution.h:294
uint32_t channel4BreakerFault
Breaker fault on channel 4.
Definition PowerDistribution.h:260
uint32_t brownout
The input voltage is below the minimum voltage.
Definition PowerDistribution.h:300
uint32_t channel3BreakerFault
Breaker fault on channel 3.
Definition PowerDistribution.h:258
uint32_t channel0BreakerFault
Breaker fault on channel 0.
Definition PowerDistribution.h:252
uint32_t channel11BreakerFault
Breaker fault on channel 12.
Definition PowerDistribution.h:274
uint32_t hardwareFault
The hardware on the device has malfunctioned.
Definition PowerDistribution.h:304
uint32_t channel16BreakerFault
Breaker fault on channel 17.
Definition PowerDistribution.h:284
uint32_t channel22BreakerFault
Breaker fault on channel 23.
Definition PowerDistribution.h:296
uint32_t channel10BreakerFault
Breaker fault on channel 10.
Definition PowerDistribution.h:272
uint32_t channel14BreakerFault
Breaker fault on channel 15.
Definition PowerDistribution.h:280
uint32_t channel20BreakerFault
Breaker fault on channel 21.
Definition PowerDistribution.h:292
uint32_t channel9BreakerFault
Breaker fault on channel 9.
Definition PowerDistribution.h:270
uint32_t channel1BreakerFault
Breaker fault on channel 1.
Definition PowerDistribution.h:254
uint32_t channel12BreakerFault
Breaker fault on channel 13.
Definition PowerDistribution.h:276
uint32_t channel2BreakerFault
Breaker fault on channel 2.
Definition PowerDistribution.h:256
uint32_t channel7BreakerFault
Breaker fault on channel 7.
Definition PowerDistribution.h:266
uint32_t channel23BreakerFault
Breaker fault on channel 24.
Definition PowerDistribution.h:298
uint32_t channel19BreakerFault
Breaker fault on channel 20.
Definition PowerDistribution.h:290
uint32_t canWarning
A warning was raised by the device's CAN controller.
Definition PowerDistribution.h:302
uint32_t channel5BreakerFault
Breaker fault on channel 5.
Definition PowerDistribution.h:262
uint32_t channel17BreakerFault
Breaker fault on channel 18.
Definition PowerDistribution.h:286
uint32_t channel15BreakerFault
Breaker fault on channel 16.
Definition PowerDistribution.h:282
uint32_t channel8BreakerFault
Breaker fault on channel 8.
Definition PowerDistribution.h:268
uint32_t channel18BreakerFault
Breaker fault on channel 19.
Definition PowerDistribution.h:288
uint32_t channel13BreakerFault
Breaker fault on channel 14.
Definition PowerDistribution.h:278
uint32_t channel6BreakerFault
Breaker fault on channel 6.
Definition PowerDistribution.h:264
Storage for REV PDH Sticky Faults.
Definition PowerDistribution.h:310
uint32_t channel14BreakerFault
Breaker fault on channel 15.
Definition PowerDistribution.h:340
uint32_t channel11BreakerFault
Breaker fault on channel 12.
Definition PowerDistribution.h:334
uint32_t canWarning
A warning was raised by the device's CAN controller.
Definition PowerDistribution.h:362
uint32_t channel15BreakerFault
Breaker fault on channel 16.
Definition PowerDistribution.h:342
uint32_t channel19BreakerFault
Breaker fault on channel 20.
Definition PowerDistribution.h:350
uint32_t brownout
The input voltage is below the minimum voltage.
Definition PowerDistribution.h:360
uint32_t channel23BreakerFault
Breaker fault on channel 24.
Definition PowerDistribution.h:358
uint32_t channel2BreakerFault
Breaker fault on channel 2.
Definition PowerDistribution.h:316
uint32_t channel5BreakerFault
Breaker fault on channel 5.
Definition PowerDistribution.h:322
uint32_t channel9BreakerFault
Breaker fault on channel 9.
Definition PowerDistribution.h:330
uint32_t channel7BreakerFault
Breaker fault on channel 7.
Definition PowerDistribution.h:326
uint32_t firmwareFault
The firmware on the device has malfunctioned.
Definition PowerDistribution.h:368
uint32_t channel16BreakerFault
Breaker fault on channel 17.
Definition PowerDistribution.h:344
uint32_t channel21BreakerFault
Breaker fault on channel 22.
Definition PowerDistribution.h:354
uint32_t hardwareFault
The hardware on the device has malfunctioned.
Definition PowerDistribution.h:366
uint32_t channel6BreakerFault
Breaker fault on channel 6.
Definition PowerDistribution.h:324
uint32_t channel17BreakerFault
Breaker fault on channel 18.
Definition PowerDistribution.h:346
uint32_t channel8BreakerFault
Breaker fault on channel 8.
Definition PowerDistribution.h:328
uint32_t channel3BreakerFault
Breaker fault on channel 3.
Definition PowerDistribution.h:318
uint32_t channel10BreakerFault
Breaker fault on channel 10.
Definition PowerDistribution.h:332
uint32_t hasReset
The device has rebooted.
Definition PowerDistribution.h:370
uint32_t channel1BreakerFault
Breaker fault on channel 1.
Definition PowerDistribution.h:314
uint32_t channel12BreakerFault
Breaker fault on channel 13.
Definition PowerDistribution.h:336
uint32_t channel22BreakerFault
Breaker fault on channel 23.
Definition PowerDistribution.h:356
uint32_t channel13BreakerFault
Breaker fault on channel 14.
Definition PowerDistribution.h:338
uint32_t channel0BreakerFault
Breaker fault on channel 0.
Definition PowerDistribution.h:312
uint32_t channel18BreakerFault
Breaker fault on channel 19.
Definition PowerDistribution.h:348
uint32_t channel4BreakerFault
Breaker fault on channel 4.
Definition PowerDistribution.h:320
uint32_t channel20BreakerFault
Breaker fault on channel 21.
Definition PowerDistribution.h:352
uint32_t canBusOff
The device's CAN controller experienced a "Bus Off" event.
Definition PowerDistribution.h:364
Power distribution version.
Definition PowerDistribution.h:235
uint32_t hardwareMajor
Hardware major version number.
Definition PowerDistribution.h:245
uint32_t firmwareMinor
Firmware minor version number.
Definition PowerDistribution.h:239
uint32_t firmwareMajor
Firmware major version number.
Definition PowerDistribution.h:237
uint32_t hardwareMinor
Hardware minor version number.
Definition PowerDistribution.h:243
uint32_t firmwareFix
Firmware fix version number.
Definition PowerDistribution.h:241
uint32_t uniqueId
Unique ID.
Definition PowerDistribution.h:247