-
Notifications
You must be signed in to change notification settings - Fork 73
/
imu.h
256 lines (234 loc) · 7.87 KB
/
imu.h
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
/**
* \file pros/imu.h
*
* Contains prototypes for functions related to the VEX Inertial sensor.
*
* Visit https://pros.cs.purdue.edu/v5/tutorials/topical/imu.html to learn
* more.
*
* This file should not be modified by users, since it gets replaced whenever
* a kernel upgrade occurs.
*
* Copyright (c) 2017-2020, Purdue University ACM SIGBots.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#ifndef _PROS_IMU_H_
#define _PROS_IMU_H_
#include <stdbool.h>
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
namespace pros {
namespace c {
#endif
typedef enum imu_status_e {
E_IMU_STATUS_CALIBRATING = 0x01,
E_IMU_STATUS_ERROR = 0xFF, // NOTE: used for returning an error from the get_status function, not that the IMU is
// necessarily in an error state
} imu_status_e_t;
typedef struct __attribute__((__packed__)) quaternion_s {
double x;
double y;
double z;
double w;
} quaternion_s_t;
struct imu_raw_s {
double x;
double y;
double z;
};
typedef struct imu_raw_s imu_gyro_s_t;
typedef struct imu_raw_s imu_accel_s_t;
typedef struct __attribute__((__packed__)) euler_s {
double pitch;
double roll;
double yaw;
} euler_s_t;
/**
* Calibrate IMU
*
* This takes approximately 2 seconds, and is a non-blocking operation.
*
* 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
*
* \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.
*/
int32_t imu_reset(uint8_t port);
/**
* 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.
*/
double imu_get_rotation(uint8_t port);
/**
* Get the Inertial Sensor's heading relative to the initial direction of its
* x-axis
*
* This value is bounded by (-360,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.
*/
double imu_get_heading(uint8_t port);
/**
* 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.
*/
quaternion_s_t imu_get_quaternion(uint8_t port);
/**
* 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.
*/
euler_s_t imu_get_euler(uint8_t port);
/**
* Get the Inertial Sensor's pitch angle
*
* 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.
*/
double imu_get_pitch(uint8_t port);
/**
* Get the Inertial Sensor's roll angle
*
* 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.
*/
double imu_get_roll(uint8_t port);
/**
* Get the Inertial Sensor's yaw angle
*
* 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 yaw angle, or PROS_ERR_F if the operation failed, setting errno.
*/
double imu_get_yaw(uint8_t port);
/**
* 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.
*/
imu_gyro_s_t imu_get_gyro_rate(uint8_t port);
/**
* Get the Inertial Sensor's raw acceleroneter 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.
*/
imu_accel_s_t imu_get_accel(uint8_t port);
/**
* 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.
*/
imu_status_e_t imu_get_status(uint8_t port);
// NOTE: not used
// void imu_set_mode(uint8_t port, uint32_t mode);
// uint32_t imu_get_mode(uint8_t port);
#ifdef __cplusplus
}
}
}
#endif
#endif