pros-sys 0.8.1

EFI for the PROS rust bindings
Documentation
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
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
use core::ffi::c_uint;

pub const IMU_MINIMUM_DATA_RATE: c_uint = 5;

pub const E_IMU_STATUS_CALIBRATING: c_uint = 0x01;
pub const E_IMU_STATUS_ERROR: c_uint = 0xFF;
pub type imu_status_e_t = c_uint;

#[repr(packed, C)]
pub struct quaternion_s_t {
    pub x: f64,
    pub y: f64,
    pub z: f64,
    pub w: f64,
}

#[repr(C)]
pub struct imu_raw_s {
    pub x: f64,
    pub y: f64,
    pub z: f64,
    pub w: f64,
}

pub type imu_gyro_s_t = imu_raw_s;
pub type imu_accel_s_t = imu_raw_s;

#[repr(packed, C)]
pub struct euler_s_t {
    pub pitch: f64,
    pub roll: f64,
    pub yaw: f64,
}

extern "C" {
    /**
    Calibrate IMU

    Calibration takes approximately 2 seconds, but this function only blocks
    until the IMU status flag is set properly to E_IMU_STATUS_CALIBRATING,
    with a minimum blocking time of 5ms.

    This function uses the following values of errno when an error state is
    reached:
    ENXIO - The given value is not within the range of V5 ports (1-21).
    ENODEV - The port cannot be configured as an Inertial Sensor
    EAGAIN - The sensor is already calibrating, or time out setting the status flag.

    \param port
           The V5 Inertial Sensor port number from 1-21
    \return 1 if the operation was successful or PROS_ERR if the operation
    failed setting errno.
    */
    pub fn imu_reset(port: u8) -> i32;
    /**
    Calibrate IMU and Blocks while Calibrating

    Calibration takes approximately 2 seconds and blocks during this period,
    with a timeout for this operation being set a 3 seconds as a safety margin.
    Like the other reset function, this function also blocks until the IMU
    status flag is set properly to E_IMU_STATUS_CALIBRATING, with a minimum
    blocking time of 5ms and a timeout of 1 second if it's never set.

    This function uses the following values of errno when an error state is
    reached:
    ENXIO - The given value is not within the range of V5 ports (1-21).
    ENODEV - The port cannot be configured as an Inertial Sensor
    EAGAIN - The sensor is already calibrating, or time out setting the status flag.

    \param port
           The V5 Inertial Sensor port number from 1-21
    \return 1 if the operation was successful or PROS_ERR if the operation
    failed (timing out or port claim failure), setting errno.
    */
    pub fn imu_reset_blocking(port: u8) -> i32;
    /**
    Set the Inertial Sensor's refresh interval in milliseconds.

    The rate may be specified in increments of 5ms, and will be rounded down to
    the nearest increment. The minimum allowable refresh rate is 5ms. The default
    rate is 10ms.

    As values are copied into the shared memory buffer only at 10ms intervals,
    setting this value to less than 10ms does not mean that you can poll the
    sensor's values any faster. However, it will guarantee that the data is as
    recent as possible.

    This function uses the following values of errno when an error state is
    reached:
    ENXIO - The given value is not within the range of V5 ports (1-21).
    ENODEV - The port cannot be configured as an Inertial Sensor
    EAGAIN - The sensor is still calibrating

    \param port
             The V5 Inertial Sensor port number from 1-21
    \param rate The data refresh interval in milliseconds
    \return 1 if the operation was successful or PROS_ERR if the operation
    failed, setting errno.
    */
    pub fn imu_set_data_rate(port: u8, rate: u32) -> i32;
    /**
    Get the total number of degrees the Inertial Sensor has spun about the z-axis

    This value is theoretically unbounded. Clockwise rotations are represented
    with positive degree values, while counterclockwise rotations are represented
    with negative ones.

    This function uses the following values of errno when an error state is
    reached:
    ENXIO - The given value is not within the range of V5 ports (1-21).
    ENODEV - The port cannot be configured as an Inertial Sensor
    EAGAIN - The sensor is still calibrating

    \param  port
                     The V5 Inertial Sensor port number from 1-21
    \return The degree value or PROS_ERR_F if the operation failed, setting
    errno.
    */
    pub fn imu_get_rotation(port: u8) -> f64;
    /**
    Get the Inertial Sensor's heading relative to the initial direction of its
    x-axis

    This value is bounded by [0,360). Clockwise rotations are represented with
    positive degree values, while counterclockwise rotations are represented with
    negative ones.

    This function uses the following values of errno when an error state is
    reached:
    ENXIO - The given value is not within the range of V5 ports (1-21).
    ENODEV - The port cannot be configured as an Inertial Sensor
    EAGAIN - The sensor is still calibrating

    \param  port
                     The V5 Inertial Sensor port number from 1-21
    \return The degree value or PROS_ERR_F if the operation failed, setting
    errno.
    */
    pub fn imu_get_heading(port: u8) -> f64;
    /**
    Get a quaternion representing the Inertial Sensor's orientation

    This function uses the following values of errno when an error state is
    reached:
    ENXIO - The given value is not within the range of V5 ports (1-21).
    ENODEV - The port cannot be configured as an Inertial Sensor
    EAGAIN - The sensor is still calibrating

    \param  port
                     The V5 Inertial Sensor port number from 1-21
    \return The quaternion representing the sensor's orientation. If the
    operation failed, all the quaternion's members are filled with PROS_ERR_F and
    errno is set.
    */
    pub fn imu_get_quaternion(port: u8) -> quaternion_s_t;
    /**
    Get the Euler angles representing the Inertial Sensor's orientation

    This function uses the following values of errno when an error state is
    reached:
    ENXIO - The given value is not within the range of V5 ports (1-21).
    ENODEV - The port cannot be configured as an Inertial Sensor
    EAGAIN - The sensor is still calibrating

    \param  port
                     The V5 Inertial Sensor port number from 1-21
    \return The Euler angles representing the sensor's orientation. If the
    operation failed, all the structure's members are filled with PROS_ERR_F and
    errno is set.
    */
    pub fn imu_get_euler(port: u8) -> euler_s_t;
    /**
    Get the Inertial Sensor's pitch angle bounded by (-180,180)

    This function uses the following values of errno when an error state is
    reached:
    ENXIO - The given value is not within the range of V5 ports (1-21).
    ENODEV - The port cannot be configured as an Inertial Sensor
    EAGAIN - The sensor is still calibrating

    \param  port
                     The V5 Inertial Sensor port number from 1-21
    \return The pitch angle, or PROS_ERR_F if the operation failed, setting
    errno.
    */
    pub fn imu_get_pitch(port: u8) -> f64;
    /**
    Get the Inertial Sensor's roll angle bounded by (-180,180)

    This function uses the following values of errno when an error state is
    reached:
    ENXIO - The given value is not within the range of V5 ports (1-21).
    ENODEV - The port cannot be configured as an Inertial Sensor
    EAGAIN - The sensor is still calibrating

    \param  port
                     The V5 Inertial Sensor port number from 1-21
    \return The roll angle, or PROS_ERR_F if the operation failed, setting errno.
    */
    pub fn imu_get_roll(port: u8) -> f64;
    /**
    Get the Inertial Sensor's roll angle bounded by (-180,180)

    This function uses the following values of errno when an error state is
    reached:
    ENXIO - The given value is not within the range of V5 ports (1-21).
    ENODEV - The port cannot be configured as an Inertial Sensor
    EAGAIN - The sensor is still calibrating

    \param  port
                     The V5 Inertial Sensor port number from 1-21
    \return The roll angle, or PROS_ERR_F if the operation failed, setting errno.
    */
    pub fn imu_get_yaw(port: u8) -> f64;
    /**
    Get the Inertial Sensor's raw gyroscope values

    This function uses the following values of errno when an error state is
    reached:
    ENXIO - The given value is not within the range of V5 ports (1-21).
    ENODEV - The port cannot be configured as an Inertial Sensor
    EAGAIN - The sensor is still calibrating

    \param  port
                     The V5 Inertial Sensor port number from 1-21
    \return The raw gyroscope values. If the operation failed, all the
    structure's members are filled with PROS_ERR_F and errno is set.
    */
    pub fn imu_get_gyro_rate(port: u8) -> imu_gyro_s_t;
    /**
    Get the Inertial Sensor's raw accelerometer values

    This function uses the following values of errno when an error state is
    reached:
    ENXIO - The given value is not within the range of V5 ports (1-21).
    ENODEV - The port cannot be configured as an Inertial Sensor
    EAGAIN - The sensor is still calibrating

    \param  port
                     The V5 Inertial Sensor port number from 1-21
    \return The raw accelerometer values. If the operation failed, all the
    structure's members are filled with PROS_ERR_F and errno is set.
    */
    pub fn imu_get_accel(port: u8) -> imu_accel_s_t;
    /**
    Get the Inertial Sensor's status

    This function uses the following values of errno when an error state is
    reached:
    ENXIO - The given value is not within the range of V5 ports (1-21).
    ENODEV - The port cannot be configured as an Inertial Sensor
    EAGAIN - The sensor is still calibrating

    \param  port
                     The V5 Inertial Sensor port number from 1-21
    \return The Inertial Sensor's status code, or PROS_ERR if the operation
    failed, setting errno.
    */
    pub fn imu_get_status(port: u8) -> imu_status_e_t;
    /**
    Resets the current reading of the Inertial Sensor's heading to zero

    This function uses the following values of errno when an error state is
    reached:
    ENXIO - The given value is not within the range of V5 ports (1-21).
    ENODEV - The port cannot be configured as an Inertial Sensor
    EAGAIN - The sensor is still calibrating

    \param  port
                     The V5 Inertial Sensor port number from 1-21
    \return 1 if the operation was successful or PROS_ERR if the operation
    failed, setting errno.
    */
    pub fn imu_tare_heading(port: u8) -> i32;
    /**
    Resets the current reading of the Inertial Sensor's rotation to zero

    This function uses the following values of errno when an error state is
    reached:
    ENXIO - The given value is not within the range of V5 ports (1-21).
    ENODEV - The port cannot be configured as an Inertial Sensor
    EAGAIN - The sensor is still calibrating

    \param  port
                     The V5 Inertial Sensor port number from 1-21
    \return 1 if the operation was successful or PROS_ERR if the operation
    failed, setting errno.
    */
    pub fn imu_tare_rotation(port: u8) -> i32;
    /**
    Resets the current reading of the Inertial Sensor's pitch to zero

    This function uses the following values of errno when an error state is
    reached:
    ENXIO - The given value is not within the range of V5 ports (1-21).
    ENODEV - The port cannot be configured as an Inertial Sensor
    EAGAIN - The sensor is still calibrating

    \param  port
                     The V5 Inertial Sensor port number from 1-21
    \return 1 if the operation was successful or PROS_ERR if the operation
    failed, setting errno.
    */
    pub fn imu_tare_pitch(port: u8) -> i32;
    /**
    Resets the current reading of the Inertial Sensor's roll to zero

    This function uses the following values of errno when an error state is
    reached:
    ENXIO - The given value is not within the range of V5 ports (1-21).
    ENODEV - The port cannot be configured as an Inertial Sensor
    EAGAIN - The sensor is still calibrating

    \param  port
                     The V5 Inertial Sensor port number from 1-21
    \return 1 if the operation was successful or PROS_ERR if the operation
    failed, setting errno.
    */
    pub fn imu_tare_roll(port: u8) -> i32;
    /**
    Resets the current reading of the Inertial Sensor's yaw to zero

    This function uses the following values of errno when an error state is
    reached:
    ENXIO - The given value is not within the range of V5 ports (1-21).
    ENODEV - The port cannot be configured as an Inertial Sensor
    EAGAIN - The sensor is still calibrating

    \param  port
                     The V5 Inertial Sensor port number from 1-21
    \return 1 if the operation was successful or PROS_ERR if the operation
    failed, setting errno.
    */
    pub fn imu_tare_yaw(port: u8) -> i32;
    /**
    Reset all 3 euler values of the Inertial Sensor to 0.

    This function uses the following values of errno when an error state is
    reached:
    ENXIO - The given value is not within the range of V5 ports (1-21).
    ENODEV - The port cannot be configured as an Inertial Sensor
    EAGAIN - The sensor is still calibrating

    \param  port
                     The V5 Inertial Sensor port number from 1-21
    \return 1 if the operation was successful or PROS_ERR if the operation
    failed, setting errno.
    */
    pub fn imu_tare_euler(port: u8) -> i32;
    /**
    Resets all 5 values of the Inertial Sensor to 0.

    This function uses the following values of errno when an error state is
    reached:
    ENXIO - The given value is not within the range of V5 ports (1-21).
    ENODEV - The port cannot be configured as an Inertial Sensor
    EAGAIN - The sensor is still calibrating

    \param  port
                     The V5 Inertial Sensor port number from 1-21
    \return 1 if the operation was successful or PROS_ERR if the operation
    failed, setting errno.
    */
    pub fn imu_tare(port: u8) -> i32;
    /**
    Sets the current reading of the Inertial Sensor's euler values to
    target euler values. Will default to +/- 180 if target exceeds +/- 180.

    This function uses the following values of errno when an error state is
    reached:
    ENXIO - The given value is not within the range of V5 ports (1-21).
    ENODEV - The port cannot be configured as an Inertial Sensor
    EAGAIN - The sensor is still calibrating

    \param  port
                    The V5 Inertial Sensor port number from 1-21
    \param  target
                    Target euler values for the euler values to be set to
    \return 1 if the operation was successful or PROS_ERR if the operation
    failed, setting errno.
    */
    pub fn imu_set_euler(port: u8, target: euler_s_t) -> i32;
    /**
    Sets the current reading of the Inertial Sensor's rotation to target value

    This function uses the following values of errno when an error state is
    reached:
    ENXIO - The given value is not within the range of V5 ports (1-21).
    ENODEV - The port cannot be configured as an Inertial Sensor
    EAGAIN - The sensor is still calibrating

    \param  port
                     The V5 Inertial Sensor port number from 1-21
    \param  target
                     Target value for the rotation value to be set to
    \return 1 if the operation was successful or PROS_ERR if the operation
    failed, setting errno.
    */
    pub fn imu_set_rotation(port: u8, target: f64) -> i32;
    /**
    Sets the current reading of the Inertial Sensor's heading to target value
    Target will default to 360 if above 360 and default to 0 if below 0.

    This function uses the following values of errno when an error state is
    reached:
    ENXIO - The given value is not within the range of V5 ports (1-21).
    ENODEV - The port cannot be configured as an Inertial Sensor
    EAGAIN - The sensor is still calibrating

    \param  port
                     The V5 Inertial Sensor port number from 1-21
    \param  target
                     Target value for the heading value to be set to
    \return 1 if the operation was successful or PROS_ERR if the operation
    failed, setting errno.
    */
    pub fn imu_set_heading(port: u8, target: f64) -> i32;
    /**
    Sets the current reading of the Inertial Sensor's pitch to target value
    Will default to +/- 180 if target exceeds +/- 180.

    This function uses the following values of errno when an error state is
    reached:
    ENXIO - The given value is not within the range of V5 ports (1-21).
    ENODEV - The port cannot be configured as an Inertial Sensor
    EAGAIN - The sensor is still calibrating

    \param  port
                     The V5 Inertial Sensor port number from 1-21
    \param  target
                     Target value for the pitch value to be set to
    \return 1 if the operation was successful or PROS_ERR if the operation
    failed, setting errno.
    */
    pub fn imu_set_pitch(port: u8, target: f64) -> i32;
    /**
    Sets the current reading of the Inertial Sensor's roll to target value
    Will default to +/- 180 if target exceeds +/- 180.

    This function uses the following values of errno when an error state is
    reached:
    ENXIO - The given value is not within the range of V5 ports (1-21).
    ENODEV - The port cannot be configured as an Inertial Sensor
    EAGAIN - The sensor is still calibrating

    \param  port
                     The V5 Inertial Sensor port number from 1-21
    \param  target
                     Target value for the roll value to be set to
    \return 1 if the operation was successful or PROS_ERR if the operation
    failed, setting errno.
    */
    pub fn imu_set_roll(port: u8, target: f64) -> i32;
    /**
    Sets the current reading of the Inertial Sensor's yaw to target value
    Will default to +/- 180 if target exceeds +/- 180.

    This function uses the following values of errno when an error state is
    reached:
    ENXIO - The given value is not within the range of V5 ports (1-21).
    ENODEV - The port cannot be configured as an Inertial Sensor
    EAGAIN - The sensor is still calibrating

    \param  port
                     The V5 Inertial Sensor port number from 1-21
    \param  target
                     Target value for the yaw value to be set to
    \return 1 if the operation was successful or PROS_ERR if the operation
    failed, setting errno.
    */
    pub fn imu_set_yaw(port: u8, target: f64) -> i32;
}