WPILibC++ 2027.0.0-alpha-4
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 "wpi/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] busId the bus id
41 * @param[in] moduleNumber the module number to initialize
42 * @param[in] type the type of module to initialize
43 * @param[in] allocationLocation the location where the allocation is occurring
44 * @param[out] status Error status variable. 0 on success.
45 * @return the created PowerDistribution handle
46 */
48 int32_t busId, int32_t moduleNumber, HAL_PowerDistributionType type,
49 const char* allocationLocation, int32_t* status);
50
51/**
52 * Gets the module number for a specific handle.
53 *
54 * @param[in] handle the module handle
55 * @param[out] status Error status variable. 0 on success.
56 * @return the module number
57 */
59 int32_t* status);
60
61/**
62 * Cleans a PowerDistribution module.
63 *
64 * @param handle the module handle
65 */
67
68/**
69 * Checks if a PowerDistribution channel is valid.
70 *
71 * @param handle the module handle
72 * @param channel the channel to check
73 * @return true if the channel is valid, otherwise false
74 */
76 int32_t channel);
77
78/**
79 * Checks if a PowerDistribution module is valid.
80 *
81 * @param module the module to check
82 * @param type the type of module
83 * @return true if the module is valid, otherwise false
84 */
87
88/**
89 * Gets the type of PowerDistribution module.
90 *
91 * @param[in] handle the module handle
92 * @param[out] status Error status variable. 0 on success.
93 * @return the type of module
94 */
96 HAL_PowerDistributionHandle handle, int32_t* status);
97
98/**
99 * Gets the number of channels for this handle.
100 *
101 * @param[in] handle the handle
102 * @param[out] status Error status variable. 0 on success.
103 * @return number of channels
104 */
106 int32_t* status);
107
108/**
109 * Gets the temperature of the Power Distribution Panel.
110 *
111 * Not supported on the Rev PDH and returns 0.
112 *
113 * @param[in] handle the module handle
114 * @param[out] status Error status variable. 0 on success.
115 * @return the module temperature (celsius)
116 */
118 int32_t* status);
119
120/**
121 * Gets the PowerDistribution input voltage.
122 *
123 * @param[in] handle the module handle
124 * @param[out] status Error status variable. 0 on success.
125 * @return the input voltage (volts)
126 */
128 int32_t* status);
129
130/**
131 * Gets the current of a specific PowerDistribution channel.
132 *
133 * @param[in] handle the module handle
134 * @param[in] channel the channel
135 * @param[out] status Error status variable. 0 on success.
136 * @return the channel current (amps)
137 */
139 HAL_PowerDistributionHandle handle, int32_t channel, int32_t* status);
140
141/**
142 * Gets the current of all channels on the PowerDistribution.
143 *
144 * The array must be large enough to hold all channels.
145 *
146 * @param[in] handle the module handle
147 * @param[out] currents the currents
148 * @param[in] currentsLength the length of the currents array
149 * @param[out] status Error status variable. 0 on success.
150 */
152 HAL_PowerDistributionHandle handle, double* currents,
153 int32_t currentsLength, int32_t* status);
154
155/**
156 * Gets the total current of the PowerDistribution.
157 *
158 * @param[in] handle the module handle
159 * @param[out] status Error status variable. 0 on success.
160 * @return the total current (amps)
161 */
163 int32_t* status);
164
165/**
166 * Gets the total power of the Power Distribution Panel.
167 *
168 * Not supported on the Rev PDH and returns 0.
169 *
170 * @param[in] handle the module handle
171 * @param[out] status Error status variable. 0 on success.
172 * @return the total power (watts)
173 */
175 int32_t* status);
176
177/**
178 * Gets the total energy of the Power Distribution Panel.
179 *
180 * Not supported on the Rev PDH and returns 0.
181 *
182 * @param[in] handle the module handle
183 * @param[out] status Error status variable. 0 on success.
184 * @return the total energy (joules)
185 */
187 int32_t* status);
188
189/**
190 * Resets the PowerDistribution accumulated energy.
191 *
192 * Not supported on the Rev PDH and does nothing.
193 *
194 * @param[in] handle the module handle
195 * @param[out] status Error status variable. 0 on success.
196 */
198 int32_t* status);
199
200/**
201 * Clears any PowerDistribution sticky faults.
202 *
203 * @param[in] handle the module handle
204 * @param[out] status Error status variable. 0 on success.
205 */
207 int32_t* status);
208
209/**
210 * Power on/off switchable channel.
211 *
212 * This is a REV PDH-specific function. This function will no-op on CTRE PDP.
213 *
214 * @param[in] handle the module handle
215 * @param[in] enabled true to turn on switchable channel
216 * @param[out] status Error status variable. 0 on success.
217 */
219 HAL_PowerDistributionHandle handle, HAL_Bool enabled, int32_t* status);
220
221/**
222 * Returns true if switchable channel is powered on.
223 *
224 * This is a REV PDH-specific function. This function will no-op on CTRE PDP.
225 *
226 * @param[in] handle the module handle
227 * @param[out] status Error status variable. 0 on success.
228 * @return the state of the switchable channel
229 */
231 HAL_PowerDistributionHandle handle, int32_t* status);
232
233/**
234 * Power distribution version.
235 */
237 /// Firmware major version number.
239 /// Firmware minor version number.
241 /// Firmware fix version number.
242 uint32_t firmwareFix;
243 /// Hardware minor version number.
245 /// Hardware major version number.
247 /// Unique ID.
248 uint32_t uniqueId;
249};
250
252 /** Breaker fault on channel 0. */
254 /** Breaker fault on channel 1. */
256 /** Breaker fault on channel 2. */
258 /** Breaker fault on channel 3. */
260 /** Breaker fault on channel 4. */
262 /** Breaker fault on channel 5. */
264 /** Breaker fault on channel 6. */
266 /** Breaker fault on channel 7. */
268 /** Breaker fault on channel 8. */
270 /** Breaker fault on channel 9. */
272 /** Breaker fault on channel 10. */
274 /** Breaker fault on channel 12. */
276 /** Breaker fault on channel 13. */
278 /** Breaker fault on channel 14. */
280 /** Breaker fault on channel 15. */
282 /** Breaker fault on channel 16. */
284 /** Breaker fault on channel 17. */
286 /** Breaker fault on channel 18. */
288 /** Breaker fault on channel 19. */
290 /** Breaker fault on channel 20. */
292 /** Breaker fault on channel 21. */
294 /** Breaker fault on channel 22. */
296 /** Breaker fault on channel 23. */
298 /** Breaker fault on channel 24. */
300 /** The input voltage is below the minimum voltage. */
301 uint32_t brownout : 1;
302 /** A warning was raised by the device's CAN controller. */
303 uint32_t canWarning : 1;
304 /** The hardware on the device has malfunctioned. */
305 uint32_t hardwareFault : 1;
306};
307
308/**
309 * Storage for REV PDH Sticky Faults
310 */
312 /** Breaker fault on channel 0. */
314 /** Breaker fault on channel 1. */
316 /** Breaker fault on channel 2. */
318 /** Breaker fault on channel 3. */
320 /** Breaker fault on channel 4. */
322 /** Breaker fault on channel 5. */
324 /** Breaker fault on channel 6. */
326 /** Breaker fault on channel 7. */
328 /** Breaker fault on channel 8. */
330 /** Breaker fault on channel 9. */
332 /** Breaker fault on channel 10. */
334 /** Breaker fault on channel 12. */
336 /** Breaker fault on channel 13. */
338 /** Breaker fault on channel 14. */
340 /** Breaker fault on channel 15. */
342 /** Breaker fault on channel 16. */
344 /** Breaker fault on channel 17. */
346 /** Breaker fault on channel 18. */
348 /** Breaker fault on channel 19. */
350 /** Breaker fault on channel 20. */
352 /** Breaker fault on channel 21. */
354 /** Breaker fault on channel 22. */
356 /** Breaker fault on channel 23. */
358 /** Breaker fault on channel 24. */
360 /** The input voltage is below the minimum voltage. */
361 uint32_t brownout : 1;
362 /** A warning was raised by the device's CAN controller. */
363 uint32_t canWarning : 1;
364 /** The device's CAN controller experienced a "Bus Off" event. */
365 uint32_t canBusOff : 1;
366 /** The hardware on the device has malfunctioned. */
367 uint32_t hardwareFault : 1;
368 /** The firmware on the device has malfunctioned. */
369 uint32_t firmwareFault : 1;
370 /** The device has rebooted. */
371 uint32_t hasReset : 1;
372};
373
374/**
375 * Get the version of the PowerDistribution.
376 *
377 * @param[in] handle the module handle
378 * @param[out] version the HAL_PowerDistributionVersion to populate
379 * @param[out] status Error status variable. 0 on success.
380 */
383 int32_t* status);
384/**
385 * Get the current faults of the PowerDistribution.
386 *
387 * On a CTRE PDP, this will return an object with no faults active.
388 *
389 * @param[in] handle the module handle
390 * @param[out] faults the HAL_PowerDistributionFaults to populate
391 * @param[out] status Error status variable. 0 on success.
392 */
395 int32_t* status);
396
397/**
398 * Gets the sticky faults of the PowerDistribution.
399 *
400 * On a CTRE PDP, this will return an object with no faults active.
401 *
402 * @param[in] handle the module handle
403 * @param[out] stickyFaults the HAL_PowerDistributionStickyFaults to populate
404 * @param[out] status Error status variable. 0 on success.
405 */
408 HAL_PowerDistributionStickyFaults* stickyFaults, int32_t* status);
409
411 int32_t* status);
412
418
420 HAL_PowerDistributionHandle handle, int32_t* count, int32_t* status);
421
423 int32_t count);
424
426 int32_t* status);
427
428#ifdef __cplusplus
429} // extern "C"
430#endif
431/** @} */
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
HAL_PowerDistributionHandle HAL_InitializePowerDistribution(int32_t busId, int32_t moduleNumber, HAL_PowerDistributionType type, const char *allocationLocation, int32_t *status)
Initializes a Power Distribution Panel.
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.
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.
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:75
HAL_Handle HAL_PowerDistributionHandle
Definition Types.h:65
#define HAL_ENUM(name)
Definition Types.h:90
Definition PowerDistribution.h:413
float current
Definition PowerDistribution.h:414
int32_t channel
Definition PowerDistribution.h:415
uint64_t timestamp
Definition PowerDistribution.h:416
Definition PowerDistribution.h:251
uint32_t channel21BreakerFault
Breaker fault on channel 22.
Definition PowerDistribution.h:295
uint32_t channel4BreakerFault
Breaker fault on channel 4.
Definition PowerDistribution.h:261
uint32_t brownout
The input voltage is below the minimum voltage.
Definition PowerDistribution.h:301
uint32_t channel3BreakerFault
Breaker fault on channel 3.
Definition PowerDistribution.h:259
uint32_t channel0BreakerFault
Breaker fault on channel 0.
Definition PowerDistribution.h:253
uint32_t channel11BreakerFault
Breaker fault on channel 12.
Definition PowerDistribution.h:275
uint32_t hardwareFault
The hardware on the device has malfunctioned.
Definition PowerDistribution.h:305
uint32_t channel16BreakerFault
Breaker fault on channel 17.
Definition PowerDistribution.h:285
uint32_t channel22BreakerFault
Breaker fault on channel 23.
Definition PowerDistribution.h:297
uint32_t channel10BreakerFault
Breaker fault on channel 10.
Definition PowerDistribution.h:273
uint32_t channel14BreakerFault
Breaker fault on channel 15.
Definition PowerDistribution.h:281
uint32_t channel20BreakerFault
Breaker fault on channel 21.
Definition PowerDistribution.h:293
uint32_t channel9BreakerFault
Breaker fault on channel 9.
Definition PowerDistribution.h:271
uint32_t channel1BreakerFault
Breaker fault on channel 1.
Definition PowerDistribution.h:255
uint32_t channel12BreakerFault
Breaker fault on channel 13.
Definition PowerDistribution.h:277
uint32_t channel2BreakerFault
Breaker fault on channel 2.
Definition PowerDistribution.h:257
uint32_t channel7BreakerFault
Breaker fault on channel 7.
Definition PowerDistribution.h:267
uint32_t channel23BreakerFault
Breaker fault on channel 24.
Definition PowerDistribution.h:299
uint32_t channel19BreakerFault
Breaker fault on channel 20.
Definition PowerDistribution.h:291
uint32_t canWarning
A warning was raised by the device's CAN controller.
Definition PowerDistribution.h:303
uint32_t channel5BreakerFault
Breaker fault on channel 5.
Definition PowerDistribution.h:263
uint32_t channel17BreakerFault
Breaker fault on channel 18.
Definition PowerDistribution.h:287
uint32_t channel15BreakerFault
Breaker fault on channel 16.
Definition PowerDistribution.h:283
uint32_t channel8BreakerFault
Breaker fault on channel 8.
Definition PowerDistribution.h:269
uint32_t channel18BreakerFault
Breaker fault on channel 19.
Definition PowerDistribution.h:289
uint32_t channel13BreakerFault
Breaker fault on channel 14.
Definition PowerDistribution.h:279
uint32_t channel6BreakerFault
Breaker fault on channel 6.
Definition PowerDistribution.h:265
Storage for REV PDH Sticky Faults.
Definition PowerDistribution.h:311
uint32_t channel14BreakerFault
Breaker fault on channel 15.
Definition PowerDistribution.h:341
uint32_t channel11BreakerFault
Breaker fault on channel 12.
Definition PowerDistribution.h:335
uint32_t canWarning
A warning was raised by the device's CAN controller.
Definition PowerDistribution.h:363
uint32_t channel15BreakerFault
Breaker fault on channel 16.
Definition PowerDistribution.h:343
uint32_t channel19BreakerFault
Breaker fault on channel 20.
Definition PowerDistribution.h:351
uint32_t brownout
The input voltage is below the minimum voltage.
Definition PowerDistribution.h:361
uint32_t channel23BreakerFault
Breaker fault on channel 24.
Definition PowerDistribution.h:359
uint32_t channel2BreakerFault
Breaker fault on channel 2.
Definition PowerDistribution.h:317
uint32_t channel5BreakerFault
Breaker fault on channel 5.
Definition PowerDistribution.h:323
uint32_t channel9BreakerFault
Breaker fault on channel 9.
Definition PowerDistribution.h:331
uint32_t channel7BreakerFault
Breaker fault on channel 7.
Definition PowerDistribution.h:327
uint32_t firmwareFault
The firmware on the device has malfunctioned.
Definition PowerDistribution.h:369
uint32_t channel16BreakerFault
Breaker fault on channel 17.
Definition PowerDistribution.h:345
uint32_t channel21BreakerFault
Breaker fault on channel 22.
Definition PowerDistribution.h:355
uint32_t hardwareFault
The hardware on the device has malfunctioned.
Definition PowerDistribution.h:367
uint32_t channel6BreakerFault
Breaker fault on channel 6.
Definition PowerDistribution.h:325
uint32_t channel17BreakerFault
Breaker fault on channel 18.
Definition PowerDistribution.h:347
uint32_t channel8BreakerFault
Breaker fault on channel 8.
Definition PowerDistribution.h:329
uint32_t channel3BreakerFault
Breaker fault on channel 3.
Definition PowerDistribution.h:319
uint32_t channel10BreakerFault
Breaker fault on channel 10.
Definition PowerDistribution.h:333
uint32_t hasReset
The device has rebooted.
Definition PowerDistribution.h:371
uint32_t channel1BreakerFault
Breaker fault on channel 1.
Definition PowerDistribution.h:315
uint32_t channel12BreakerFault
Breaker fault on channel 13.
Definition PowerDistribution.h:337
uint32_t channel22BreakerFault
Breaker fault on channel 23.
Definition PowerDistribution.h:357
uint32_t channel13BreakerFault
Breaker fault on channel 14.
Definition PowerDistribution.h:339
uint32_t channel0BreakerFault
Breaker fault on channel 0.
Definition PowerDistribution.h:313
uint32_t channel18BreakerFault
Breaker fault on channel 19.
Definition PowerDistribution.h:349
uint32_t channel4BreakerFault
Breaker fault on channel 4.
Definition PowerDistribution.h:321
uint32_t channel20BreakerFault
Breaker fault on channel 21.
Definition PowerDistribution.h:353
uint32_t canBusOff
The device's CAN controller experienced a "Bus Off" event.
Definition PowerDistribution.h:365
Power distribution version.
Definition PowerDistribution.h:236
uint32_t hardwareMajor
Hardware major version number.
Definition PowerDistribution.h:246
uint32_t firmwareMinor
Firmware minor version number.
Definition PowerDistribution.h:240
uint32_t firmwareMajor
Firmware major version number.
Definition PowerDistribution.h:238
uint32_t hardwareMinor
Hardware minor version number.
Definition PowerDistribution.h:244
uint32_t firmwareFix
Firmware fix version number.
Definition PowerDistribution.h:242
uint32_t uniqueId
Unique ID.
Definition PowerDistribution.h:248