pros_sys/
imu.rs

1use core::ffi::c_uint;
2
3pub const IMU_MINIMUM_DATA_RATE: c_uint = 5;
4
5pub const E_IMU_STATUS_CALIBRATING: c_uint = 0x01;
6pub const E_IMU_STATUS_ERROR: c_uint = 0xFF;
7pub type imu_status_e_t = c_uint;
8
9#[repr(packed, C)]
10pub struct quaternion_s_t {
11    pub x: f64,
12    pub y: f64,
13    pub z: f64,
14    pub w: f64,
15}
16
17#[repr(C)]
18pub struct imu_raw_s {
19    pub x: f64,
20    pub y: f64,
21    pub z: f64,
22    pub w: f64,
23}
24
25pub type imu_gyro_s_t = imu_raw_s;
26pub type imu_accel_s_t = imu_raw_s;
27
28#[repr(packed, C)]
29pub struct euler_s_t {
30    pub pitch: f64,
31    pub roll: f64,
32    pub yaw: f64,
33}
34
35extern "C" {
36    /**
37    Calibrate IMU
38
39    Calibration takes approximately 2 seconds, but this function only blocks
40    until the IMU status flag is set properly to E_IMU_STATUS_CALIBRATING,
41    with a minimum blocking time of 5ms.
42
43    This function uses the following values of errno when an error state is
44    reached:
45    ENXIO - The given value is not within the range of V5 ports (1-21).
46    ENODEV - The port cannot be configured as an Inertial Sensor
47    EAGAIN - The sensor is already calibrating, or time out setting the status flag.
48
49    \param port
50           The V5 Inertial Sensor port number from 1-21
51    \return 1 if the operation was successful or PROS_ERR if the operation
52    failed setting errno.
53    */
54    pub fn imu_reset(port: u8) -> i32;
55    /**
56    Calibrate IMU and Blocks while Calibrating
57
58    Calibration takes approximately 2 seconds and blocks during this period,
59    with a timeout for this operation being set a 3 seconds as a safety margin.
60    Like the other reset function, this function also blocks until the IMU
61    status flag is set properly to E_IMU_STATUS_CALIBRATING, with a minimum
62    blocking time of 5ms and a timeout of 1 second if it's never set.
63
64    This function uses the following values of errno when an error state is
65    reached:
66    ENXIO - The given value is not within the range of V5 ports (1-21).
67    ENODEV - The port cannot be configured as an Inertial Sensor
68    EAGAIN - The sensor is already calibrating, or time out setting the status flag.
69
70    \param port
71           The V5 Inertial Sensor port number from 1-21
72    \return 1 if the operation was successful or PROS_ERR if the operation
73    failed (timing out or port claim failure), setting errno.
74    */
75    pub fn imu_reset_blocking(port: u8) -> i32;
76    /**
77    Set the Inertial Sensor's refresh interval in milliseconds.
78
79    The rate may be specified in increments of 5ms, and will be rounded down to
80    the nearest increment. The minimum allowable refresh rate is 5ms. The default
81    rate is 10ms.
82
83    As values are copied into the shared memory buffer only at 10ms intervals,
84    setting this value to less than 10ms does not mean that you can poll the
85    sensor's values any faster. However, it will guarantee that the data is as
86    recent as possible.
87
88    This function uses the following values of errno when an error state is
89    reached:
90    ENXIO - The given value is not within the range of V5 ports (1-21).
91    ENODEV - The port cannot be configured as an Inertial Sensor
92    EAGAIN - The sensor is still calibrating
93
94    \param port
95             The V5 Inertial Sensor port number from 1-21
96    \param rate The data refresh interval in milliseconds
97    \return 1 if the operation was successful or PROS_ERR if the operation
98    failed, setting errno.
99    */
100    pub fn imu_set_data_rate(port: u8, rate: u32) -> i32;
101    /**
102    Get the total number of degrees the Inertial Sensor has spun about the z-axis
103
104    This value is theoretically unbounded. Clockwise rotations are represented
105    with positive degree values, while counterclockwise rotations are represented
106    with negative ones.
107
108    This function uses the following values of errno when an error state is
109    reached:
110    ENXIO - The given value is not within the range of V5 ports (1-21).
111    ENODEV - The port cannot be configured as an Inertial Sensor
112    EAGAIN - The sensor is still calibrating
113
114    \param  port
115                     The V5 Inertial Sensor port number from 1-21
116    \return The degree value or PROS_ERR_F if the operation failed, setting
117    errno.
118    */
119    pub fn imu_get_rotation(port: u8) -> f64;
120    /**
121    Get the Inertial Sensor's heading relative to the initial direction of its
122    x-axis
123
124    This value is bounded by [0,360). Clockwise rotations are represented with
125    positive degree values, while counterclockwise rotations are represented with
126    negative ones.
127
128    This function uses the following values of errno when an error state is
129    reached:
130    ENXIO - The given value is not within the range of V5 ports (1-21).
131    ENODEV - The port cannot be configured as an Inertial Sensor
132    EAGAIN - The sensor is still calibrating
133
134    \param  port
135                     The V5 Inertial Sensor port number from 1-21
136    \return The degree value or PROS_ERR_F if the operation failed, setting
137    errno.
138    */
139    pub fn imu_get_heading(port: u8) -> f64;
140    /**
141    Get a quaternion representing the Inertial Sensor's orientation
142
143    This function uses the following values of errno when an error state is
144    reached:
145    ENXIO - The given value is not within the range of V5 ports (1-21).
146    ENODEV - The port cannot be configured as an Inertial Sensor
147    EAGAIN - The sensor is still calibrating
148
149    \param  port
150                     The V5 Inertial Sensor port number from 1-21
151    \return The quaternion representing the sensor's orientation. If the
152    operation failed, all the quaternion's members are filled with PROS_ERR_F and
153    errno is set.
154    */
155    pub fn imu_get_quaternion(port: u8) -> quaternion_s_t;
156    /**
157    Get the Euler angles representing the Inertial Sensor's orientation
158
159    This function uses the following values of errno when an error state is
160    reached:
161    ENXIO - The given value is not within the range of V5 ports (1-21).
162    ENODEV - The port cannot be configured as an Inertial Sensor
163    EAGAIN - The sensor is still calibrating
164
165    \param  port
166                     The V5 Inertial Sensor port number from 1-21
167    \return The Euler angles representing the sensor's orientation. If the
168    operation failed, all the structure's members are filled with PROS_ERR_F and
169    errno is set.
170    */
171    pub fn imu_get_euler(port: u8) -> euler_s_t;
172    /**
173    Get the Inertial Sensor's pitch angle bounded by (-180,180)
174
175    This function uses the following values of errno when an error state is
176    reached:
177    ENXIO - The given value is not within the range of V5 ports (1-21).
178    ENODEV - The port cannot be configured as an Inertial Sensor
179    EAGAIN - The sensor is still calibrating
180
181    \param  port
182                     The V5 Inertial Sensor port number from 1-21
183    \return The pitch angle, or PROS_ERR_F if the operation failed, setting
184    errno.
185    */
186    pub fn imu_get_pitch(port: u8) -> f64;
187    /**
188    Get the Inertial Sensor's roll angle bounded by (-180,180)
189
190    This function uses the following values of errno when an error state is
191    reached:
192    ENXIO - The given value is not within the range of V5 ports (1-21).
193    ENODEV - The port cannot be configured as an Inertial Sensor
194    EAGAIN - The sensor is still calibrating
195
196    \param  port
197                     The V5 Inertial Sensor port number from 1-21
198    \return The roll angle, or PROS_ERR_F if the operation failed, setting errno.
199    */
200    pub fn imu_get_roll(port: u8) -> f64;
201    /**
202    Get the Inertial Sensor's roll angle bounded by (-180,180)
203
204    This function uses the following values of errno when an error state is
205    reached:
206    ENXIO - The given value is not within the range of V5 ports (1-21).
207    ENODEV - The port cannot be configured as an Inertial Sensor
208    EAGAIN - The sensor is still calibrating
209
210    \param  port
211                     The V5 Inertial Sensor port number from 1-21
212    \return The roll angle, or PROS_ERR_F if the operation failed, setting errno.
213    */
214    pub fn imu_get_yaw(port: u8) -> f64;
215    /**
216    Get the Inertial Sensor's raw gyroscope values
217
218    This function uses the following values of errno when an error state is
219    reached:
220    ENXIO - The given value is not within the range of V5 ports (1-21).
221    ENODEV - The port cannot be configured as an Inertial Sensor
222    EAGAIN - The sensor is still calibrating
223
224    \param  port
225                     The V5 Inertial Sensor port number from 1-21
226    \return The raw gyroscope values. If the operation failed, all the
227    structure's members are filled with PROS_ERR_F and errno is set.
228    */
229    pub fn imu_get_gyro_rate(port: u8) -> imu_gyro_s_t;
230    /**
231    Get the Inertial Sensor's raw accelerometer values
232
233    This function uses the following values of errno when an error state is
234    reached:
235    ENXIO - The given value is not within the range of V5 ports (1-21).
236    ENODEV - The port cannot be configured as an Inertial Sensor
237    EAGAIN - The sensor is still calibrating
238
239    \param  port
240                     The V5 Inertial Sensor port number from 1-21
241    \return The raw accelerometer values. If the operation failed, all the
242    structure's members are filled with PROS_ERR_F and errno is set.
243    */
244    pub fn imu_get_accel(port: u8) -> imu_accel_s_t;
245    /**
246    Get the Inertial Sensor's status
247
248    This function uses the following values of errno when an error state is
249    reached:
250    ENXIO - The given value is not within the range of V5 ports (1-21).
251    ENODEV - The port cannot be configured as an Inertial Sensor
252    EAGAIN - The sensor is still calibrating
253
254    \param  port
255                     The V5 Inertial Sensor port number from 1-21
256    \return The Inertial Sensor's status code, or PROS_ERR if the operation
257    failed, setting errno.
258    */
259    pub fn imu_get_status(port: u8) -> imu_status_e_t;
260    /**
261    Resets the current reading of the Inertial Sensor's heading to zero
262
263    This function uses the following values of errno when an error state is
264    reached:
265    ENXIO - The given value is not within the range of V5 ports (1-21).
266    ENODEV - The port cannot be configured as an Inertial Sensor
267    EAGAIN - The sensor is still calibrating
268
269    \param  port
270                     The V5 Inertial Sensor port number from 1-21
271    \return 1 if the operation was successful or PROS_ERR if the operation
272    failed, setting errno.
273    */
274    pub fn imu_tare_heading(port: u8) -> i32;
275    /**
276    Resets the current reading of the Inertial Sensor's rotation to zero
277
278    This function uses the following values of errno when an error state is
279    reached:
280    ENXIO - The given value is not within the range of V5 ports (1-21).
281    ENODEV - The port cannot be configured as an Inertial Sensor
282    EAGAIN - The sensor is still calibrating
283
284    \param  port
285                     The V5 Inertial Sensor port number from 1-21
286    \return 1 if the operation was successful or PROS_ERR if the operation
287    failed, setting errno.
288    */
289    pub fn imu_tare_rotation(port: u8) -> i32;
290    /**
291    Resets the current reading of the Inertial Sensor's pitch to zero
292
293    This function uses the following values of errno when an error state is
294    reached:
295    ENXIO - The given value is not within the range of V5 ports (1-21).
296    ENODEV - The port cannot be configured as an Inertial Sensor
297    EAGAIN - The sensor is still calibrating
298
299    \param  port
300                     The V5 Inertial Sensor port number from 1-21
301    \return 1 if the operation was successful or PROS_ERR if the operation
302    failed, setting errno.
303    */
304    pub fn imu_tare_pitch(port: u8) -> i32;
305    /**
306    Resets the current reading of the Inertial Sensor's roll to zero
307
308    This function uses the following values of errno when an error state is
309    reached:
310    ENXIO - The given value is not within the range of V5 ports (1-21).
311    ENODEV - The port cannot be configured as an Inertial Sensor
312    EAGAIN - The sensor is still calibrating
313
314    \param  port
315                     The V5 Inertial Sensor port number from 1-21
316    \return 1 if the operation was successful or PROS_ERR if the operation
317    failed, setting errno.
318    */
319    pub fn imu_tare_roll(port: u8) -> i32;
320    /**
321    Resets the current reading of the Inertial Sensor's yaw to zero
322
323    This function uses the following values of errno when an error state is
324    reached:
325    ENXIO - The given value is not within the range of V5 ports (1-21).
326    ENODEV - The port cannot be configured as an Inertial Sensor
327    EAGAIN - The sensor is still calibrating
328
329    \param  port
330                     The V5 Inertial Sensor port number from 1-21
331    \return 1 if the operation was successful or PROS_ERR if the operation
332    failed, setting errno.
333    */
334    pub fn imu_tare_yaw(port: u8) -> i32;
335    /**
336    Reset all 3 euler values of the Inertial Sensor to 0.
337
338    This function uses the following values of errno when an error state is
339    reached:
340    ENXIO - The given value is not within the range of V5 ports (1-21).
341    ENODEV - The port cannot be configured as an Inertial Sensor
342    EAGAIN - The sensor is still calibrating
343
344    \param  port
345                     The V5 Inertial Sensor port number from 1-21
346    \return 1 if the operation was successful or PROS_ERR if the operation
347    failed, setting errno.
348    */
349    pub fn imu_tare_euler(port: u8) -> i32;
350    /**
351    Resets all 5 values of the Inertial Sensor to 0.
352
353    This function uses the following values of errno when an error state is
354    reached:
355    ENXIO - The given value is not within the range of V5 ports (1-21).
356    ENODEV - The port cannot be configured as an Inertial Sensor
357    EAGAIN - The sensor is still calibrating
358
359    \param  port
360                     The V5 Inertial Sensor port number from 1-21
361    \return 1 if the operation was successful or PROS_ERR if the operation
362    failed, setting errno.
363    */
364    pub fn imu_tare(port: u8) -> i32;
365    /**
366    Sets the current reading of the Inertial Sensor's euler values to
367    target euler values. Will default to +/- 180 if target exceeds +/- 180.
368
369    This function uses the following values of errno when an error state is
370    reached:
371    ENXIO - The given value is not within the range of V5 ports (1-21).
372    ENODEV - The port cannot be configured as an Inertial Sensor
373    EAGAIN - The sensor is still calibrating
374
375    \param  port
376                    The V5 Inertial Sensor port number from 1-21
377    \param  target
378                    Target euler values for the euler values to be set to
379    \return 1 if the operation was successful or PROS_ERR if the operation
380    failed, setting errno.
381    */
382    pub fn imu_set_euler(port: u8, target: euler_s_t) -> i32;
383    /**
384    Sets the current reading of the Inertial Sensor's rotation to target value
385
386    This function uses the following values of errno when an error state is
387    reached:
388    ENXIO - The given value is not within the range of V5 ports (1-21).
389    ENODEV - The port cannot be configured as an Inertial Sensor
390    EAGAIN - The sensor is still calibrating
391
392    \param  port
393                     The V5 Inertial Sensor port number from 1-21
394    \param  target
395                     Target value for the rotation value to be set to
396    \return 1 if the operation was successful or PROS_ERR if the operation
397    failed, setting errno.
398    */
399    pub fn imu_set_rotation(port: u8, target: f64) -> i32;
400    /**
401    Sets the current reading of the Inertial Sensor's heading to target value
402    Target will default to 360 if above 360 and default to 0 if below 0.
403
404    This function uses the following values of errno when an error state is
405    reached:
406    ENXIO - The given value is not within the range of V5 ports (1-21).
407    ENODEV - The port cannot be configured as an Inertial Sensor
408    EAGAIN - The sensor is still calibrating
409
410    \param  port
411                     The V5 Inertial Sensor port number from 1-21
412    \param  target
413                     Target value for the heading value to be set to
414    \return 1 if the operation was successful or PROS_ERR if the operation
415    failed, setting errno.
416    */
417    pub fn imu_set_heading(port: u8, target: f64) -> i32;
418    /**
419    Sets the current reading of the Inertial Sensor's pitch to target value
420    Will default to +/- 180 if target exceeds +/- 180.
421
422    This function uses the following values of errno when an error state is
423    reached:
424    ENXIO - The given value is not within the range of V5 ports (1-21).
425    ENODEV - The port cannot be configured as an Inertial Sensor
426    EAGAIN - The sensor is still calibrating
427
428    \param  port
429                     The V5 Inertial Sensor port number from 1-21
430    \param  target
431                     Target value for the pitch value to be set to
432    \return 1 if the operation was successful or PROS_ERR if the operation
433    failed, setting errno.
434    */
435    pub fn imu_set_pitch(port: u8, target: f64) -> i32;
436    /**
437    Sets the current reading of the Inertial Sensor's roll to target value
438    Will default to +/- 180 if target exceeds +/- 180.
439
440    This function uses the following values of errno when an error state is
441    reached:
442    ENXIO - The given value is not within the range of V5 ports (1-21).
443    ENODEV - The port cannot be configured as an Inertial Sensor
444    EAGAIN - The sensor is still calibrating
445
446    \param  port
447                     The V5 Inertial Sensor port number from 1-21
448    \param  target
449                     Target value for the roll value to be set to
450    \return 1 if the operation was successful or PROS_ERR if the operation
451    failed, setting errno.
452    */
453    pub fn imu_set_roll(port: u8, target: f64) -> i32;
454    /**
455    Sets the current reading of the Inertial Sensor's yaw to target value
456    Will default to +/- 180 if target exceeds +/- 180.
457
458    This function uses the following values of errno when an error state is
459    reached:
460    ENXIO - The given value is not within the range of V5 ports (1-21).
461    ENODEV - The port cannot be configured as an Inertial Sensor
462    EAGAIN - The sensor is still calibrating
463
464    \param  port
465                     The V5 Inertial Sensor port number from 1-21
466    \param  target
467                     Target value for the yaw value to be set to
468    \return 1 if the operation was successful or PROS_ERR if the operation
469    failed, setting errno.
470    */
471    pub fn imu_set_yaw(port: u8, target: f64) -> i32;
472}