WPILibC++ 2024.3.2
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 */
25};
26
27#define HAL_DEFAULT_POWER_DISTRIBUTION_MODULE -1
28
29#ifdef __cplusplus
30extern "C" {
31#endif
32
33/**
34 * Initializes a Power Distribution Panel.
35 *
36 * @param[in] moduleNumber the module number to initialize
37 * @param[in] type the type of module to initialize
38 * @param[in] allocationLocation the location where the allocation is occurring
39 * @param[out] status Error status variable. 0 on success.
40 * @return the created PowerDistribution handle
41 */
43 int32_t moduleNumber, HAL_PowerDistributionType type,
44 const char* allocationLocation, int32_t* status);
45
46/**
47 * Gets the module number for a specific handle.
48 *
49 * @param[in] handle the module handle
50 * @param[out] status Error status variable. 0 on success.
51 * @return the module number
52 */
54 int32_t* status);
55
56/**
57 * Cleans a PowerDistribution module.
58 *
59 * @param handle the module handle
60 */
62
63/**
64 * Checks if a PowerDistribution channel is valid.
65 *
66 * @param handle the module handle
67 * @param channel the channel to check
68 * @return true if the channel is valid, otherwise false
69 */
71 int32_t channel);
72
73/**
74 * Checks if a PowerDistribution module is valid.
75 *
76 * @param module the module to check
77 * @param type the type of module
78 * @return true if the module is valid, otherwise false
79 */
82
83/**
84 * Gets the type of PowerDistribution module.
85 *
86 * @param[in] handle the module handle
87 * @param[out] status Error status variable. 0 on success.
88 * @return the type of module
89 */
91 HAL_PowerDistributionHandle handle, int32_t* status);
92
93/**
94 * Gets the number of channels for this handle.
95 *
96 * @param[in] handle the handle
97 * @param[out] status Error status variable. 0 on success.
98 * @return number of channels
99 */
101 int32_t* status);
102
103/**
104 * Gets the temperature of the Power Distribution Panel.
105 *
106 * Not supported on the Rev PDH and returns 0.
107 *
108 * @param[in] handle the module handle
109 * @param[out] status Error status variable. 0 on success.
110 * @return the module temperature (celsius)
111 */
113 int32_t* status);
114
115/**
116 * Gets the PowerDistribution input voltage.
117 *
118 * @param[in] handle the module handle
119 * @param[out] status Error status variable. 0 on success.
120 * @return the input voltage (volts)
121 */
123 int32_t* status);
124
125/**
126 * Gets the current of a specific PowerDistribution channel.
127 *
128 * @param[in] handle the module handle
129 * @param[in] channel the channel
130 * @param[out] status Error status variable. 0 on success.
131 * @return the channel current (amps)
132 */
134 HAL_PowerDistributionHandle handle, int32_t channel, int32_t* status);
135
136/**
137 * Gets the current of all channels on the PowerDistribution.
138 *
139 * The array must be large enough to hold all channels.
140 *
141 * @param[in] handle the module handle
142 * @param[out] currents the currents
143 * @param[in] currentsLength the length of the currents array
144 * @param[out] status Error status variable. 0 on success.
145 */
147 HAL_PowerDistributionHandle handle, double* currents,
148 int32_t currentsLength, int32_t* status);
149
150/**
151 * Gets the total current of the PowerDistribution.
152 *
153 * @param[in] handle the module handle
154 * @param[out] status Error status variable. 0 on success.
155 * @return the total current (amps)
156 */
158 int32_t* status);
159
160/**
161 * Gets the total power of the Power Distribution Panel.
162 *
163 * Not supported on the Rev PDH and returns 0.
164 *
165 * @param[in] handle the module handle
166 * @param[out] status Error status variable. 0 on success.
167 * @return the total power (watts)
168 */
170 int32_t* status);
171
172/**
173 * Gets the total energy of the Power Distribution Panel.
174 *
175 * Not supported on the Rev PDH and returns 0.
176 *
177 * @param[in] handle the module handle
178 * @param[out] status Error status variable. 0 on success.
179 * @return the total energy (joules)
180 */
182 int32_t* status);
183
184/**
185 * Resets the PowerDistribution accumulated energy.
186 *
187 * Not supported on the Rev PDH and does nothing.
188 *
189 * @param[in] handle the module handle
190 * @param[out] status Error status variable. 0 on success.
191 */
193 int32_t* status);
194
195/**
196 * Clears any PowerDistribution sticky faults.
197 *
198 * @param[in] handle the module handle
199 * @param[out] status Error status variable. 0 on success.
200 */
202 int32_t* status);
203
204/**
205 * Power on/off switchable channel.
206 *
207 * This is a REV PDH-specific function. This function will no-op on CTRE PDP.
208 *
209 * @param[in] handle the module handle
210 * @param[in] enabled true to turn on switchable channel
211 * @param[out] status Error status variable. 0 on success.
212 */
214 HAL_PowerDistributionHandle handle, HAL_Bool enabled, int32_t* status);
215
216/**
217 * Returns true if switchable channel is powered on.
218 *
219 * This is a REV PDH-specific function. This function will no-op on CTRE PDP.
220 *
221 * @param[in] handle the module handle
222 * @param[out] status Error status variable. 0 on success.
223 * @return the state of the switchable channel
224 */
226 HAL_PowerDistributionHandle handle, int32_t* status);
227
228/**
229 * Power distribution version.
230 */
232 /// Firmware major version number.
234 /// Firmware minor version number.
236 /// Firmware fix version number.
237 uint32_t firmwareFix;
238 /// Hardware minor version number.
240 /// Hardware major version number.
242 /// Unique ID.
243 uint32_t uniqueId;
244};
245
271 uint32_t brownout : 1;
272 uint32_t canWarning : 1;
273 uint32_t hardwareFault : 1;
274};
275
276/**
277 * Storage for REV PDH Sticky Faults
278 */
304 uint32_t brownout : 1;
305 uint32_t canWarning : 1;
306 uint32_t canBusOff : 1;
307 uint32_t hasReset : 1;
308};
309
310/**
311 * Get the version of the PowerDistribution.
312 *
313 * @param[in] handle the module handle
314 * @param[out] version the HAL_PowerDistributionVersion to populate
315 * @param[out] status Error status variable. 0 on success.
316 */
319 int32_t* status);
320/**
321 * Get the current faults of the PowerDistribution.
322 *
323 * @param[in] handle the module handle
324 * @param[out] faults the HAL_PowerDistributionFaults to populate
325 * @param[out] status Error status variable. 0 on success.
326 */
329 int32_t* status);
330
331/**
332 * Gets the sticky faults of the PowerDistribution.
333 *
334 * @param[in] handle the module handle
335 * @param[out] stickyFaults the HAL_PowerDistributionStickyFaults to populate
336 * @param[out] status Error status variable. 0 on success.
337 */
340 HAL_PowerDistributionStickyFaults* stickyFaults, int32_t* status);
341
343 int32_t* status);
344
346 float current;
347 int32_t channel;
348 uint32_t timestamp;
350
352 HAL_PowerDistributionHandle handle, int32_t* count, int32_t* status);
353
355 int32_t count);
356
358 int32_t* status);
359
360#ifdef __cplusplus
361} // extern "C"
362#endif
363/** @} */
@ HAL_ENUM
Definition: Value.h:14
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
Definition: PowerDistribution.h:22
@ HAL_PowerDistributionType_kCTRE
Definition: PowerDistribution.h:23
@ HAL_PowerDistributionType_kRev
Definition: PowerDistribution.h:24
int32_t HAL_Bool
Definition: Types.h:73
HAL_Handle HAL_PowerDistributionHandle
Definition: Types.h:65
constexpr auto count() -> size_t
Definition: core.h:1203
type
Definition: core.h:556
Definition: PowerDistribution.h:345
float current
Definition: PowerDistribution.h:346
int32_t channel
Definition: PowerDistribution.h:347
uint32_t timestamp
Definition: PowerDistribution.h:348
Definition: PowerDistribution.h:246
uint32_t channel21BreakerFault
Definition: PowerDistribution.h:268
uint32_t channel4BreakerFault
Definition: PowerDistribution.h:251
uint32_t brownout
Definition: PowerDistribution.h:271
uint32_t channel3BreakerFault
Definition: PowerDistribution.h:250
uint32_t channel0BreakerFault
Definition: PowerDistribution.h:247
uint32_t channel11BreakerFault
Definition: PowerDistribution.h:258
uint32_t hardwareFault
Definition: PowerDistribution.h:273
uint32_t channel16BreakerFault
Definition: PowerDistribution.h:263
uint32_t channel22BreakerFault
Definition: PowerDistribution.h:269
uint32_t channel10BreakerFault
Definition: PowerDistribution.h:257
uint32_t channel14BreakerFault
Definition: PowerDistribution.h:261
uint32_t channel20BreakerFault
Definition: PowerDistribution.h:267
uint32_t channel9BreakerFault
Definition: PowerDistribution.h:256
uint32_t channel1BreakerFault
Definition: PowerDistribution.h:248
uint32_t channel12BreakerFault
Definition: PowerDistribution.h:259
uint32_t channel2BreakerFault
Definition: PowerDistribution.h:249
uint32_t channel7BreakerFault
Definition: PowerDistribution.h:254
uint32_t channel23BreakerFault
Definition: PowerDistribution.h:270
uint32_t channel19BreakerFault
Definition: PowerDistribution.h:266
uint32_t canWarning
Definition: PowerDistribution.h:272
uint32_t channel5BreakerFault
Definition: PowerDistribution.h:252
uint32_t channel17BreakerFault
Definition: PowerDistribution.h:264
uint32_t channel15BreakerFault
Definition: PowerDistribution.h:262
uint32_t channel8BreakerFault
Definition: PowerDistribution.h:255
uint32_t channel18BreakerFault
Definition: PowerDistribution.h:265
uint32_t channel13BreakerFault
Definition: PowerDistribution.h:260
uint32_t channel6BreakerFault
Definition: PowerDistribution.h:253
Storage for REV PDH Sticky Faults.
Definition: PowerDistribution.h:279
uint32_t channel14BreakerFault
Definition: PowerDistribution.h:294
uint32_t channel11BreakerFault
Definition: PowerDistribution.h:291
uint32_t canWarning
Definition: PowerDistribution.h:305
uint32_t channel15BreakerFault
Definition: PowerDistribution.h:295
uint32_t channel19BreakerFault
Definition: PowerDistribution.h:299
uint32_t brownout
Definition: PowerDistribution.h:304
uint32_t channel23BreakerFault
Definition: PowerDistribution.h:303
uint32_t channel2BreakerFault
Definition: PowerDistribution.h:282
uint32_t channel5BreakerFault
Definition: PowerDistribution.h:285
uint32_t channel9BreakerFault
Definition: PowerDistribution.h:289
uint32_t channel7BreakerFault
Definition: PowerDistribution.h:287
uint32_t channel16BreakerFault
Definition: PowerDistribution.h:296
uint32_t channel21BreakerFault
Definition: PowerDistribution.h:301
uint32_t channel6BreakerFault
Definition: PowerDistribution.h:286
uint32_t channel17BreakerFault
Definition: PowerDistribution.h:297
uint32_t channel8BreakerFault
Definition: PowerDistribution.h:288
uint32_t channel3BreakerFault
Definition: PowerDistribution.h:283
uint32_t channel10BreakerFault
Definition: PowerDistribution.h:290
uint32_t hasReset
Definition: PowerDistribution.h:307
uint32_t channel1BreakerFault
Definition: PowerDistribution.h:281
uint32_t channel12BreakerFault
Definition: PowerDistribution.h:292
uint32_t channel22BreakerFault
Definition: PowerDistribution.h:302
uint32_t channel13BreakerFault
Definition: PowerDistribution.h:293
uint32_t channel0BreakerFault
Definition: PowerDistribution.h:280
uint32_t channel18BreakerFault
Definition: PowerDistribution.h:298
uint32_t channel4BreakerFault
Definition: PowerDistribution.h:284
uint32_t channel20BreakerFault
Definition: PowerDistribution.h:300
uint32_t canBusOff
Definition: PowerDistribution.h:306
Power distribution version.
Definition: PowerDistribution.h:231
uint32_t hardwareMajor
Hardware major version number.
Definition: PowerDistribution.h:241
uint32_t firmwareMinor
Firmware minor version number.
Definition: PowerDistribution.h:235
uint32_t firmwareMajor
Firmware major version number.
Definition: PowerDistribution.h:233
uint32_t hardwareMinor
Hardware minor version number.
Definition: PowerDistribution.h:239
uint32_t firmwareFix
Firmware fix version number.
Definition: PowerDistribution.h:237
uint32_t uniqueId
Unique ID.
Definition: PowerDistribution.h:243