Skyward boardcore
Loading...
Searching...
No Matches
SensorData.h
Go to the documentation of this file.
1/* Copyright (c) 2020-2022 Skyward Experimental Rocketry
2 * Authors: Luca Conterio, Alberto Nidasio
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 * THE SOFTWARE.
21 */
22
23#pragma once
24
25#include <Eigen/Core>
26#include <ostream>
27#include <reflect.hpp>
28
29namespace Boardcore
30{
31
38enum SensorErrors : uint8_t
39{
43 NOT_INIT = 3, // if some method called before init()
44 ALREADY_INIT = 4, // if init() called multiple times
47 NO_NEW_DATA = 7, // no new data available from the sensor
51 END_OF_BASE_ERRORS = 11 // used to extend this enum
52};
53
55{
56 uint64_t timestamp;
57
58 static constexpr auto reflect()
59 {
60 return STRUCT_DEF(TimestampData, FIELD_DEF(timestamp));
61 }
62};
63
65{
66 uint64_t loadTimestamp = 0;
67 float load = 0;
68
69 static constexpr auto reflect()
70 {
71 return STRUCT_DEF(LoadCellData,
72 FIELD_DEF(loadTimestamp) FIELD_DEF(load));
73 }
74};
75
77{
79 float temperature = 0;
80
81 static constexpr auto reflect()
82 {
83 return STRUCT_DEF(TemperatureData, FIELD_DEF(temperatureTimestamp)
84 FIELD_DEF(temperature));
85 }
86};
87
89{
90 uint64_t pressureTimestamp = 0;
91 float pressure = 0;
92
93 static constexpr auto reflect()
94 {
95 return STRUCT_DEF(PressureData,
96 FIELD_DEF(pressureTimestamp) FIELD_DEF(pressure));
97 }
98};
99
104{
105 uint64_t humidityTimestamp = 0;
106 float humidity = 0;
107
108 static constexpr auto reflect()
109 {
110 return STRUCT_DEF(HumidityData,
111 FIELD_DEF(humidityTimestamp) FIELD_DEF(humidity));
112 }
113};
114
119{
121 float accelerationX = 0;
122 float accelerationY = 0;
123 float accelerationZ = 0;
124
126
127 AccelerometerData(uint64_t timestamp, float x, float y, float z)
130 {
131 }
132
133 AccelerometerData(const AccelerometerData& data) = default;
134
135 explicit AccelerometerData(const Eigen::Vector3f& acc)
136 : accelerationX(acc(0)), accelerationY(acc(1)), accelerationZ(acc(2))
137 {
138 }
139
140 operator Eigen::Vector3f() const
141 {
143 }
144
145 static constexpr auto reflect()
146 {
147 return STRUCT_DEF(AccelerometerData,
148 FIELD_DEF(accelerationTimestamp)
149 FIELD_DEF(accelerationX) FIELD_DEF(accelerationY)
150 FIELD_DEF(accelerationZ));
151 }
152};
153
158{
160 float quaternionX = 0;
161 float quaternionY = 0;
162 float quaternionZ = 0;
163 float quaternionW = 0;
164
166
167 QuaternionData(uint64_t timestamp, float x, float y, float z, float w)
168 : quaternionTimestamp(timestamp), quaternionX(x), quaternionY(y),
170 {
171 }
172
173 QuaternionData(const QuaternionData& data) = default;
174
175 explicit QuaternionData(const Eigen::Vector4f& quat)
176 : quaternionX(quat(0)), quaternionY(quat(1)), quaternionZ(quat(2)),
177 quaternionW(quat(3))
178 {
179 }
180
181 operator Eigen::Vector4f() const
182 {
184 }
185
186 static constexpr auto reflect()
187 {
188 return STRUCT_DEF(QuaternionData,
189 FIELD_DEF(quaternionTimestamp) FIELD_DEF(quaternionX)
190 FIELD_DEF(quaternionY) FIELD_DEF(quaternionZ)
191 FIELD_DEF(quaternionW));
192 }
193};
194
199{
201 float angularSpeedX = 0;
202 float angularSpeedY = 0;
203 float angularSpeedZ = 0;
204
206
207 GyroscopeData(uint64_t timestamp, float x, float y, float z)
210 {
211 }
212
213 GyroscopeData(const GyroscopeData& data) = default;
214
215 explicit GyroscopeData(const Eigen::Vector3f& vel)
216 : angularSpeedX(vel(0)), angularSpeedY(vel(1)), angularSpeedZ(vel(2))
217 {
218 }
219
220 operator Eigen::Vector3f() const
221 {
223 }
224
225 static constexpr auto reflect()
226 {
227 return STRUCT_DEF(GyroscopeData,
228 FIELD_DEF(angularSpeedTimestamp)
229 FIELD_DEF(angularSpeedX) FIELD_DEF(angularSpeedY)
230 FIELD_DEF(angularSpeedZ));
231 }
232};
233
238{
240 float magneticFieldX = 0;
241 float magneticFieldY = 0;
242 float magneticFieldZ = 0;
243
245
246 MagnetometerData(uint64_t timestamp, float x, float y, float z)
247 : magneticFieldTimestamp(timestamp), magneticFieldX(x),
249 {
250 }
251
252 MagnetometerData(const MagnetometerData& data) = default;
253
254 explicit MagnetometerData(const Eigen::Vector3f& mag)
255 : magneticFieldX(mag(0)), magneticFieldY(mag(1)), magneticFieldZ(mag(2))
256 {
257 }
258
259 operator Eigen::Vector3f() const
260 {
262 }
263
264 static constexpr auto reflect()
265 {
266 return STRUCT_DEF(
268 FIELD_DEF(magneticFieldTimestamp) FIELD_DEF(magneticFieldX)
269 FIELD_DEF(magneticFieldY) FIELD_DEF(magneticFieldZ));
270 }
271};
272
277{
278 uint64_t gpsTimestamp = 0;
279 float latitude = 0; // [deg]
280 float longitude = 0; // [deg]
281 float height = 0; // [m]
282 float velocityNorth = 0; // [m/s]
283 float velocityEast = 0; // [m/s]
284 float velocityDown = 0; // [m/s]w
285 float speed = 0; // [m/s]
286 float track = 0; // [deg]
287 float positionDOP = 0; // [?]
288 uint8_t satellites = 0; // [1]
289 uint8_t fix = 0; // 0 = no fix
290
291 static constexpr auto reflect()
292 {
293 return STRUCT_DEF(
294 GPSData,
295 FIELD_DEF(gpsTimestamp) FIELD_DEF(latitude) FIELD_DEF(longitude)
296 FIELD_DEF(height) FIELD_DEF(velocityNorth)
297 FIELD_DEF(velocityEast) FIELD_DEF(velocityDown)
298 FIELD_DEF(speed) FIELD_DEF(track) FIELD_DEF(positionDOP)
299 FIELD_DEF(satellites) FIELD_DEF(fix));
300 }
301};
302
307{
308 uint64_t currentTimestamp = 0;
309 float current = 0;
310
311 static constexpr auto reflect()
312 {
313 return STRUCT_DEF(CurrentData,
314 FIELD_DEF(currentTimestamp) FIELD_DEF(current));
315 }
316};
317
322{
323 uint64_t voltageTimestamp = 0;
324 float voltage = 0;
325
326 static constexpr auto reflect()
327 {
328 return STRUCT_DEF(VoltageData,
329 FIELD_DEF(voltageTimestamp) FIELD_DEF(voltage));
330 }
331};
332
337{
338 uint64_t voltageTimestamp = 0;
339 uint8_t channelId = 0;
340 float voltage = 0;
341
345 operator VoltageData() const
346 {
347 return VoltageData{
349 .voltage = voltage,
350 };
351 }
352
353 static constexpr auto reflect()
354 {
355 return STRUCT_DEF(ADCData, FIELD_DEF(voltageTimestamp)
356 FIELD_DEF(channelId) FIELD_DEF(voltage));
357 }
358};
359
360} // namespace Boardcore
Driver for the VN100S IMU.
SensorErrors
Generic error codes that a sensor can generate.
Definition SensorData.h:39
@ SELF_TEST_FAIL
Definition SensorData.h:45
@ INVALID_FIFO_INDEX
Definition SensorData.h:48
@ END_OF_BASE_ERRORS
Definition SensorData.h:51
@ INVALID_WHOAMI
Definition SensorData.h:41
@ COMMAND_FAILED
Definition SensorData.h:50
Structure to handle ADC data.
Definition SensorData.h:337
static constexpr auto reflect()
Definition SensorData.h:353
uint64_t voltageTimestamp
Definition SensorData.h:338
Structure to handle accelerometer data.
Definition SensorData.h:119
static constexpr auto reflect()
Definition SensorData.h:145
AccelerometerData(const Eigen::Vector3f &acc)
Definition SensorData.h:135
AccelerometerData(const AccelerometerData &data)=default
AccelerometerData(uint64_t timestamp, float x, float y, float z)
Definition SensorData.h:127
Structure to handle current data.
Definition SensorData.h:307
static constexpr auto reflect()
Definition SensorData.h:311
Structure to handle GPS data.
Definition SensorData.h:277
uint64_t gpsTimestamp
Definition SensorData.h:278
static constexpr auto reflect()
Definition SensorData.h:291
Structure to handle gyroscope data.
Definition SensorData.h:199
GyroscopeData(uint64_t timestamp, float x, float y, float z)
Definition SensorData.h:207
static constexpr auto reflect()
Definition SensorData.h:225
GyroscopeData(const Eigen::Vector3f &vel)
Definition SensorData.h:215
GyroscopeData(const GyroscopeData &data)=default
Structure to handle humidity data.
Definition SensorData.h:104
static constexpr auto reflect()
Definition SensorData.h:108
static constexpr auto reflect()
Definition SensorData.h:69
Structure to handle magnetometer data.
Definition SensorData.h:238
MagnetometerData(const MagnetometerData &data)=default
MagnetometerData(uint64_t timestamp, float x, float y, float z)
Definition SensorData.h:246
MagnetometerData(const Eigen::Vector3f &mag)
Definition SensorData.h:254
static constexpr auto reflect()
Definition SensorData.h:264
static constexpr auto reflect()
Definition SensorData.h:93
Structure to handle quaternion data.
Definition SensorData.h:158
QuaternionData(const Eigen::Vector4f &quat)
Definition SensorData.h:175
static constexpr auto reflect()
Definition SensorData.h:186
QuaternionData(const QuaternionData &data)=default
QuaternionData(uint64_t timestamp, float x, float y, float z, float w)
Definition SensorData.h:167
static constexpr auto reflect()
Definition SensorData.h:81
static constexpr auto reflect()
Definition SensorData.h:58
Structure to handle voltage data.
Definition SensorData.h:322
static constexpr auto reflect()
Definition SensorData.h:326