robot-rust 0.1.0

The robot-rust project, bindings for wpilib, ctre, and rev in rust.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.

#pragma once

#include <stdint.h>

#include "hal/Types.h"

/**
 * @defgroup hal_rev_ph REV Pneumatic Hub (PH) Functions
 * @ingroup hal_capi
 * @{
 */

/**
 * The compressor configuration type
 */
HAL_ENUM(HAL_REVPHCompressorConfigType) {
  /** Disabled. */
  HAL_REVPHCompressorConfigType_kDisabled = 0,
  /** Digital. */
  HAL_REVPHCompressorConfigType_kDigital = 1,
  /** Analog. */
  HAL_REVPHCompressorConfigType_kAnalog = 2,
  /** Hybrid. */
  HAL_REVPHCompressorConfigType_kHybrid = 3,
};

/**
 * Storage for REV PH Version
 */
struct HAL_REVPHVersion {
  /** The firmware major version. */
  uint32_t firmwareMajor;
  /** The firmware minor version. */
  uint32_t firmwareMinor;
  /** The firmware fix version. */
  uint32_t firmwareFix;
  /** The hardware minor version. */
  uint32_t hardwareMinor;
  /** The hardware major version. */
  uint32_t hardwareMajor;
  /** The device's unique ID. */
  uint32_t uniqueId;
};

/**
 * Storage for compressor config
 */
struct HAL_REVPHCompressorConfig {
  double minAnalogVoltage;
  double maxAnalogVoltage;
  HAL_Bool forceDisable;
  HAL_Bool useDigital;
};

/**
 * Storage for REV PH Faults
 */
struct HAL_REVPHFaults {
  /** Fault on channel 0. */
  uint32_t channel0Fault : 1;
  /** Fault on channel 1. */
  uint32_t channel1Fault : 1;
  /** Fault on channel 2. */
  uint32_t channel2Fault : 1;
  /** Fault on channel 3. */
  uint32_t channel3Fault : 1;
  /** Fault on channel 4. */
  uint32_t channel4Fault : 1;
  /** Fault on channel 5. */
  uint32_t channel5Fault : 1;
  /** Fault on channel 6. */
  uint32_t channel6Fault : 1;
  /** Fault on channel 7. */
  uint32_t channel7Fault : 1;
  /** Fault on channel 8. */
  uint32_t channel8Fault : 1;
  /** Fault on channel 9. */
  uint32_t channel9Fault : 1;
  /** Fault on channel 10. */
  uint32_t channel10Fault : 1;
  /** Fault on channel 11. */
  uint32_t channel11Fault : 1;
  /** Fault on channel 12. */
  uint32_t channel12Fault : 1;
  /** Fault on channel 13. */
  uint32_t channel13Fault : 1;
  /** Fault on channel 14. */
  uint32_t channel14Fault : 1;
  /** Fault on channel 15. */
  uint32_t channel15Fault : 1;
  /** An overcurrent event occurred on the compressor output. */
  uint32_t compressorOverCurrent : 1;
  /** The compressor output has an open circuit. */
  uint32_t compressorOpen : 1;
  /** An overcurrent event occurred on a solenoid output. */
  uint32_t solenoidOverCurrent : 1;
  /** The input voltage is below the minimum voltage. */
  uint32_t brownout : 1;
  /** A warning was raised by the device's CAN controller. */
  uint32_t canWarning : 1;
  /** The hardware on the device has malfunctioned. */
  uint32_t hardwareFault : 1;
};

/**
 * Storage for REV PH Sticky Faults
 */
struct HAL_REVPHStickyFaults {
  /** An overcurrent event occurred on the compressor output. */
  uint32_t compressorOverCurrent : 1;
  /** The compressor output has an open circuit. */
  uint32_t compressorOpen : 1;
  /** An overcurrent event occurred on a solenoid output. */
  uint32_t solenoidOverCurrent : 1;
  /** The input voltage is below the minimum voltage. */
  uint32_t brownout : 1;
  /** A warning was raised by the device's CAN controller. */
  uint32_t canWarning : 1;
  /** The device's CAN controller experienced a "Bus Off" event. */
  uint32_t canBusOff : 1;
  /** The hardware on the device has malfunctioned. */
  uint32_t hardwareFault : 1;
  /** The firmware on the device has malfunctioned. */
  uint32_t firmwareFault : 1;
  /** The device has rebooted. */
  uint32_t hasReset : 1;
};

#ifdef __cplusplus
extern "C" {
#endif

/**
 * Initializes a PH.
 *
 * @param[in] module             the CAN ID to initialize
 * @param[in] allocationLocation the location where the allocation is occurring
 *                               (can be null)
 * @param[out] status            Error status variable. 0 on success.
 * @return the created PH handle
 */
HAL_REVPHHandle HAL_InitializeREVPH(int32_t module,
                                    const char* allocationLocation,
                                    int32_t* status);

/**
 * Frees a PH handle.
 *
 * @param[in] handle the PH handle
 */
void HAL_FreeREVPH(HAL_REVPHHandle handle);

/**
 * Checks if a solenoid channel number is valid.
 *
 * @param[in] channel the channel to check
 * @return true if the channel is valid, otherwise false
 */
HAL_Bool HAL_CheckREVPHSolenoidChannel(int32_t channel);

/**
 * Checks if a PH module (CAN ID) is valid.
 *
 * @param[in] module the module to check
 * @return true if the module is valid, otherwise false
 */
HAL_Bool HAL_CheckREVPHModuleNumber(int32_t module);

/**
 * Get whether compressor is turned on.
 *
 * @param[in] handle  the PH handle
 * @param[out] status Error status variable. 0 on success.
 * @return true if the compressor is turned on
 */
HAL_Bool HAL_GetREVPHCompressor(HAL_REVPHHandle handle, int32_t* status);

/**
 * Send compressor configuration to the PH.
 *
 * @param[in] handle  the PH handle
 * @param[in] config  compressor configuration
 * @param[out] status Error status variable. 0 on success.
 */
void HAL_SetREVPHCompressorConfig(HAL_REVPHHandle handle,
                                  const HAL_REVPHCompressorConfig* config,
                                  int32_t* status);

/**
 * Disable Compressor.
 *
 * @param[in] handle  the PH handle
 * @param[out] status Error status variable. 0 on success.
 */
void HAL_SetREVPHClosedLoopControlDisabled(HAL_REVPHHandle handle,
                                           int32_t* status);

/**
 * Enables the compressor in digital mode using the digital pressure switch. The
 * compressor will turn on when the pressure switch indicates that the system is
 * not full, and will turn off when the pressure switch indicates that the
 * system is full.
 *
 * @param[in] handle  the PH handle
 * @param[out] status Error status variable. 0 on success.
 */
void HAL_SetREVPHClosedLoopControlDigital(HAL_REVPHHandle handle,
                                          int32_t* status);

/**
 * Enables the compressor in analog mode. This mode uses an analog
 * pressure sensor connected to analog channel 0 to cycle the compressor. The
 * compressor will turn on when the pressure drops below minAnalogVoltage and
 * will turn off when the pressure reaches maxAnalogVoltage. This mode is only
 * supported by the REV PH with the REV Analog Pressure Sensor connected to
 * analog channel 0.
 * @param[in] handle  the PH handle
 * @param[in] minAnalogVoltage The compressor will turn on when the analog
 * pressure sensor voltage drops below this value
 * @param[in] maxAnalogVoltage The compressor will turn off when the analog
 * pressure sensor reaches this value.
 * @param[out] status Error status variable. 0 on success.
 */
void HAL_SetREVPHClosedLoopControlAnalog(HAL_REVPHHandle handle,
                                         double minAnalogVoltage,
                                         double maxAnalogVoltage,
                                         int32_t* status);

/**
 * Enables the compressor in hybrid mode. This mode uses both a digital
 * pressure switch and an analog pressure sensor connected to analog channel 0
 * to cycle the compressor.
 *
 * The compressor will turn on when \a both:
 *
 * - The digital pressure switch indicates the system is not full AND
 * - The analog pressure sensor indicates that the pressure in the system is
 * below the specified minimum pressure.
 *
 * The compressor will turn off when \a either:
 *
 * - The digital pressure switch is disconnected or indicates that the system
 * is full OR
 * - The pressure detected by the analog sensor is greater than the specified
 * maximum pressure.
 *
 * @param[in] handle  the PH handle
 * @param[in] minAnalogVoltage The compressor will turn on when the analog
 * pressure sensor voltage drops below this value and the pressure switch
 * indicates that the system is not full.
 * @param[in] maxAnalogVoltage The compressor will turn off when the analog
 * pressure sensor reaches this value or the pressure switch is disconnected or
 * indicates that the system is full.
 * @param[out] status Error status variable. 0 on success.
 */
void HAL_SetREVPHClosedLoopControlHybrid(HAL_REVPHHandle handle,
                                         double minAnalogVoltage,
                                         double maxAnalogVoltage,
                                         int32_t* status);

/**
 * Get compressor configuration from the PH.
 *
 * @param[in] handle  the PH handle
 * @param[out] status Error status variable. 0 on success.
 * @return compressor configuration
 */
HAL_REVPHCompressorConfigType HAL_GetREVPHCompressorConfig(
    HAL_REVPHHandle handle, int32_t* status);

/**
 * Returns the state of the digital pressure switch.
 *
 * @param[in] handle  the PH handle
 * @param[out] status Error status variable. 0 on success.
 * @return True if pressure switch indicates that the system is full,
 * otherwise false.
 */
HAL_Bool HAL_GetREVPHPressureSwitch(HAL_REVPHHandle handle, int32_t* status);

/**
 * Returns the current drawn by the compressor.
 *
 * @param[in] handle  the PH handle
 * @param[out] status Error status variable. 0 on success.
 * @return The current drawn by the compressor in amps.
 */
double HAL_GetREVPHCompressorCurrent(HAL_REVPHHandle handle, int32_t* status);

/**
 * Returns the raw voltage of the specified analog
 * input channel.
 *
 * @param[in] handle  the PH handle
 * @param[in] channel The analog input channel to read voltage from.
 * @param[out] status Error status variable. 0 on success.
 * @return The voltage of the specified analog input channel in volts.
 */
double HAL_GetREVPHAnalogVoltage(HAL_REVPHHandle handle, int32_t channel,
                                 int32_t* status);

/**
 * Returns the current input voltage for the PH.
 *
 * @param[in] handle  the PH handle
 * @param[out] status Error status variable. 0 on success.
 * @return The input voltage in volts.
 */
double HAL_GetREVPHVoltage(HAL_REVPHHandle handle, int32_t* status);

/**
 * Returns the current voltage of the regulated 5v supply.
 *
 * @param[in] handle  the PH handle
 * @param[out] status Error status variable. 0 on success.
 * @return The current voltage of the 5v supply in volts.
 */
double HAL_GetREVPH5VVoltage(HAL_REVPHHandle handle, int32_t* status);

/**
 * Returns the total current drawn by all solenoids.
 *
 * @param[in] handle  the PH handle
 * @param[out] status Error status variable. 0 on success.
 * @return Total current drawn by all solenoids in amps.
 */
double HAL_GetREVPHSolenoidCurrent(HAL_REVPHHandle handle, int32_t* status);

/**
 * Returns the current voltage of the solenoid power supply.
 *
 * @param[in] handle  the PH handle
 * @param[out] status Error status variable. 0 on success.
 * @return The current voltage of the solenoid power supply in volts.
 */
double HAL_GetREVPHSolenoidVoltage(HAL_REVPHHandle handle, int32_t* status);

/**
 * Returns the hardware and firmware versions of the PH.
 *
 * @param[in] handle  the PH handle
 * @param[out] version The hardware and firmware versions.
 * @param[out] status Error status variable. 0 on success.
 */
void HAL_GetREVPHVersion(HAL_REVPHHandle handle, HAL_REVPHVersion* version,
                         int32_t* status);

/**
 * Gets a bitmask of solenoid values.
 *
 * @param[in] handle  the PH handle
 * @param[out] status Error status variable. 0 on success.
 * @return Bitmask containing the state of the solenoids. The LSB represents
 * solenoid 0.
 */
int32_t HAL_GetREVPHSolenoids(HAL_REVPHHandle handle, int32_t* status);

/**
 * Sets solenoids on a PH.
 *
 * @param[in] handle  the PH handle
 * @param[in] mask Bitmask indicating which solenoids to set. The LSB represents
 * solenoid 0.
 * @param[in] values Bitmask indicating the desired states of the solenoids. The
 * LSB represents solenoid 0.
 * @param[out] status Error status variable. 0 on success.
 */
void HAL_SetREVPHSolenoids(HAL_REVPHHandle handle, int32_t mask, int32_t values,
                           int32_t* status);

/**
 * Fire a single solenoid shot for the specified duration.
 *
 * @param[in] handle  the PH handle
 * @param[in] index solenoid index
 * @param[in] durMs shot duration in ms
 * @param[out] status Error status variable. 0 on success.
 */
void HAL_FireREVPHOneShot(HAL_REVPHHandle handle, int32_t index, int32_t durMs,
                          int32_t* status);

/**
 * Returns the faults currently active on the PH.
 *
 * @param[in] handle  the PH handle
 * @param[out] faults The faults.
 * @param[out] status Error status variable. 0 on success.
 */
void HAL_GetREVPHFaults(HAL_REVPHHandle handle, HAL_REVPHFaults* faults,
                        int32_t* status);

/**
 * Returns the sticky faults currently active on this device.
 *
 * @param[in] handle  the PH handle
 * @param[out] stickyFaults The sticky faults.
 * @param[out] status Error status variable. 0 on success.
 */
void HAL_GetREVPHStickyFaults(HAL_REVPHHandle handle,
                              HAL_REVPHStickyFaults* stickyFaults,
                              int32_t* status);

/**
 * Clears the sticky faults.
 *
 * @param[in] handle  the PH handle
 * @param[out] status Error status variable. 0 on success.
 */
void HAL_ClearREVPHStickyFaults(HAL_REVPHHandle handle, int32_t* status);

/**
 * Get a bitmask of disabled solenoids.
 *
 * @param[in] handle  the PH handle
 * @param[out] status Error status variable. 0 on success.
 * @return Bitmask indicating disabled solenoids. The LSB represents solenoid 0.
 */
int32_t HAL_GetREVPHSolenoidDisabledList(HAL_REVPHHandle handle,
                                         int32_t* status);

#ifdef __cplusplus
}  // extern "C"
#endif
/** @} */