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
28namespace Boardcore
29{
30
37enum SensorErrors : uint8_t
38{
42 NOT_INIT = 3, // if some method called before init()
43 ALREADY_INIT = 4, // if init() called multiple times
46 NO_NEW_DATA = 7, // no new data available from the sensor
50 END_OF_BASE_ERRORS = 11 // used to extend this enum
51};
52
54{
55 uint64_t timestamp;
56
57 static std::string header() { return "timestamp\n"; }
58
59 void print(std::ostream& os) const { os << timestamp << "\n"; }
60};
61
63{
64 uint64_t loadTimestamp = 0;
65 float load = 0;
66
67 static std::string header() { return "loadTimestamp,load\n"; }
68
69 void print(std::ostream& os) const
70 {
71 os << loadTimestamp << "," << load << "\n";
72 }
73};
74
76{
78 float temperature = 0;
79
80 static std::string header() { return "timestamp,temperature\n"; }
81
82 void print(std::ostream& os) const
83 {
84 os << temperatureTimestamp << "," << temperature << "\n";
85 }
86};
87
89{
90 uint64_t pressureTimestamp = 0;
91 float pressure = 0;
92
93 static std::string header() { return "timestamp,pressure\n"; }
94
95 void print(std::ostream& os) const
96 {
97 os << pressureTimestamp << "," << pressure << "\n";
98 }
99};
100
105{
106 uint64_t humidityTimestamp = 0;
107 float humidity = 0;
108
109 static std::string header() { return "timestamp,humidity\n"; }
110
111 void print(std::ostream& os) const
112 {
113 os << humidityTimestamp << "," << humidity << "\n";
114 }
115};
116
121{
123 float accelerationX = 0;
124 float accelerationY = 0;
125 float accelerationZ = 0;
126
128
129 AccelerometerData(uint64_t timestamp, float x, float y, float z)
132 {
133 }
134
135 AccelerometerData(const AccelerometerData& data) = default;
136
137 explicit AccelerometerData(const Eigen::Vector3f& acc)
138 : accelerationX(acc(0)), accelerationY(acc(1)), accelerationZ(acc(2))
139 {
140 }
141
142 static std::string header()
143 {
144 return "timestamp,accelerationX,accelerationY,accelerationZ\n";
145 }
146
147 void print(std::ostream& os) const
148 {
149 os << accelerationTimestamp << "," << accelerationX << ","
150 << accelerationY << "," << accelerationZ << "\n";
151 }
152
153 operator Eigen::Vector3f() const
154 {
156 }
157};
158
163{
165 float quaternionX = 0;
166 float quaternionY = 0;
167 float quaternionZ = 0;
168 float quaternionW = 0;
169
171
172 QuaternionData(uint64_t timestamp, float x, float y, float z, float w)
173 : quaternionTimestamp(timestamp), quaternionX(x), quaternionY(y),
175 {
176 }
177
178 QuaternionData(const QuaternionData& data) = default;
179
180 explicit QuaternionData(const Eigen::Vector4f& quat)
181 : quaternionX(quat(0)), quaternionY(quat(1)), quaternionZ(quat(2)),
182 quaternionW(quat(3))
183 {
184 }
185
186 static std::string header()
187 {
188 return "timestamp,quaternionX,quaternionY,quaternionZ,quaterionW\n";
189 }
190
191 void print(std::ostream& os) const
192 {
193 os << quaternionTimestamp << "," << quaternionX << "," << quaternionY
194 << "," << quaternionZ << "," << quaternionW << "\n";
195 }
196
197 operator Eigen::Vector4f() const
198 {
200 }
201};
202
207{
209 float angularSpeedX = 0;
210 float angularSpeedY = 0;
211 float angularSpeedZ = 0;
212
214
215 GyroscopeData(uint64_t timestamp, float x, float y, float z)
218 {
219 }
220
221 GyroscopeData(const GyroscopeData& data) = default;
222
223 explicit GyroscopeData(const Eigen::Vector3f& vel)
224 : angularSpeedX(vel(0)), angularSpeedY(vel(1)), angularSpeedZ(vel(2))
225 {
226 }
227
228 static std::string header()
229 {
230 return "timestamp,angularSpeedX,angularSpeedY,angularSpeedZ\n";
231 }
232
233 void print(std::ostream& os) const
234 {
235 os << angularSpeedTimestamp << "," << angularSpeedX << ","
236 << angularSpeedY << "," << angularSpeedZ << "\n";
237 }
238
239 operator Eigen::Vector3f() const
240 {
242 }
243};
244
249{
251 float magneticFieldX = 0;
252 float magneticFieldY = 0;
253 float magneticFieldZ = 0;
254
256
257 MagnetometerData(uint64_t timestamp, float x, float y, float z)
258 : magneticFieldTimestamp(timestamp), magneticFieldX(x),
260 {
261 }
262
263 MagnetometerData(const MagnetometerData& data) = default;
264
265 explicit MagnetometerData(const Eigen::Vector3f& mag)
266 : magneticFieldX(mag(0)), magneticFieldY(mag(1)), magneticFieldZ(mag(2))
267 {
268 }
269
270 static std::string header()
271 {
272 return "timestamp,magneticFieldX,magneticFieldY,magneticFieldZ\n";
273 }
274
275 void print(std::ostream& os) const
276 {
277 os << magneticFieldTimestamp << "," << magneticFieldX << ","
278 << magneticFieldY << "," << magneticFieldZ << "\n";
279 }
280
281 operator Eigen::Vector3f() const
282 {
284 }
285};
286
291{
292 uint64_t gpsTimestamp = 0;
293 float latitude = 0; // [deg]
294 float longitude = 0; // [deg]
295 float height = 0; // [m]
296 float velocityNorth = 0; // [m/s]
297 float velocityEast = 0; // [m/s]
298 float velocityDown = 0; // [m/s]w
299 float speed = 0; // [m/s]
300 float track = 0; // [deg]
301 float positionDOP = 0; // [?]
302 uint8_t satellites = 0; // [1]
303 uint8_t fix = 0; // 0 = no fix
304
305 static std::string header()
306 {
307 return "timestamp,latitude,longitude,height,velocityNorth,velocityEast,"
308 "velocityDown,speed,track,positionDOP,satellites,fix\n";
309 }
310
311 void print(std::ostream& os) const
312 {
313 os << gpsTimestamp << "," << latitude << "," << longitude << ","
314 << height << "," << velocityNorth << "," << velocityEast << ","
315 << velocityDown << "," << speed << "," << track << "," << positionDOP
316 << "," << (int)satellites << "," << (int)fix << "\n";
317 }
318};
319
324{
325 uint64_t currentTimestamp = 0;
326 float current = 0;
327
328 static std::string header() { return "timestamp,current\n"; }
329
330 void print(std::ostream& os) const
331 {
332 os << currentTimestamp << "," << current << "\n";
333 }
334};
335
340{
341 uint64_t voltageTimestamp = 0;
342 float voltage = 0;
343
344 static std::string header() { return "timestamp,voltage\n"; }
345
346 void print(std::ostream& os) const
347 {
348 os << voltageTimestamp << "," << voltage << "\n";
349 }
350};
351
356{
357 uint64_t voltageTimestamp = 0;
358 uint8_t channelId = 0;
359 float voltage = 0;
360
361 static std::string header() { return "timestamp,channelId,voltage\n"; }
362
363 void print(std::ostream& os) const
364 {
365 os << voltageTimestamp << "," << (int)channelId << "," << voltage
366 << "\n";
367 }
368
372 operator VoltageData() const
373 {
374 return VoltageData{
376 .voltage = voltage,
377 };
378 }
379};
380
381} // namespace Boardcore
This file includes all the types the logdecoder script will decode.
SensorErrors
Generic error codes that a sensor can generate.
Definition SensorData.h:38
@ SELF_TEST_FAIL
Definition SensorData.h:44
@ INVALID_FIFO_INDEX
Definition SensorData.h:47
@ END_OF_BASE_ERRORS
Definition SensorData.h:50
@ INVALID_WHOAMI
Definition SensorData.h:40
@ COMMAND_FAILED
Definition SensorData.h:49
Structure to handle ADC data.
Definition SensorData.h:356
void print(std::ostream &os) const
Definition SensorData.h:363
static std::string header()
Definition SensorData.h:361
uint64_t voltageTimestamp
Definition SensorData.h:357
Structure to handle accelerometer data.
Definition SensorData.h:121
AccelerometerData(const Eigen::Vector3f &acc)
Definition SensorData.h:137
AccelerometerData(const AccelerometerData &data)=default
static std::string header()
Definition SensorData.h:142
AccelerometerData(uint64_t timestamp, float x, float y, float z)
Definition SensorData.h:129
void print(std::ostream &os) const
Definition SensorData.h:147
Structure to handle current data.
Definition SensorData.h:324
static std::string header()
Definition SensorData.h:328
void print(std::ostream &os) const
Definition SensorData.h:330
Structure to handle GPS data.
Definition SensorData.h:291
uint64_t gpsTimestamp
Definition SensorData.h:292
void print(std::ostream &os) const
Definition SensorData.h:311
static std::string header()
Definition SensorData.h:305
Structure to handle gyroscope data.
Definition SensorData.h:207
GyroscopeData(uint64_t timestamp, float x, float y, float z)
Definition SensorData.h:215
GyroscopeData(const Eigen::Vector3f &vel)
Definition SensorData.h:223
GyroscopeData(const GyroscopeData &data)=default
void print(std::ostream &os) const
Definition SensorData.h:233
static std::string header()
Definition SensorData.h:228
Structure to handle humidity data.
Definition SensorData.h:105
static std::string header()
Definition SensorData.h:109
void print(std::ostream &os) const
Definition SensorData.h:111
void print(std::ostream &os) const
Definition SensorData.h:69
static std::string header()
Definition SensorData.h:67
Structure to handle magnetometer data.
Definition SensorData.h:249
MagnetometerData(const MagnetometerData &data)=default
void print(std::ostream &os) const
Definition SensorData.h:275
static std::string header()
Definition SensorData.h:270
MagnetometerData(uint64_t timestamp, float x, float y, float z)
Definition SensorData.h:257
MagnetometerData(const Eigen::Vector3f &mag)
Definition SensorData.h:265
void print(std::ostream &os) const
Definition SensorData.h:95
static std::string header()
Definition SensorData.h:93
Structure to handle quaternion data.
Definition SensorData.h:163
QuaternionData(const Eigen::Vector4f &quat)
Definition SensorData.h:180
static std::string header()
Definition SensorData.h:186
void print(std::ostream &os) const
Definition SensorData.h:191
QuaternionData(const QuaternionData &data)=default
QuaternionData(uint64_t timestamp, float x, float y, float z, float w)
Definition SensorData.h:172
static std::string header()
Definition SensorData.h:80
void print(std::ostream &os) const
Definition SensorData.h:82
void print(std::ostream &os) const
Definition SensorData.h:59
static std::string header()
Definition SensorData.h:57
Structure to handle voltage data.
Definition SensorData.h:340
static std::string header()
Definition SensorData.h:344
void print(std::ostream &os) const
Definition SensorData.h:346