-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsac2020_imu.h
More file actions
124 lines (108 loc) · 3.2 KB
/
sac2020_imu.h
File metadata and controls
124 lines (108 loc) · 3.2 KB
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
/**
* [ANOTHER FINE PRODUCT FROM THE NONSENSE FACTORY]
*
* Flight software for the Longhorn Rocketry Association's Spaceport America
* Cup 2020 rocket. Built for the LRA Generation 2 flight computer, which also
* flies in LRA's NASA Student Launch 2020 rocket. The configurability of the
* software--combined with modularity and all-in-one-package style of the
* Generation 2 flight computer--means the software can be easily adapted to run
* in any high-power rocket.
*
* @file sac2020_imu.h
* @purpose Device wrapper for the flight computer's inertial measurement
* unit.
* @author Stefan deBruyn
* @updated 2/22/2020
*/
#ifndef SAC2020_IMU_H
#define SAC2020_IMU_H
#include <Adafruit_BNO055.h>
#include <Adafruit_Sensor.h>
#include "photic.h"
#include "utility/imumaths.h"
class Sac2020Imu final : public photic::Imu
{
public:
/**
* Initializes the BNO055.
*
* @ret True if successful, false otherwise.
*/
bool init()
{
bool success = m_bno055.begin();
if (success)
{
m_bno055.setExtCrystalUse(true);
}
return success;
}
/**
* Updates orientation and acceleration data with the BNO055's Euler angle
* and linear accleration readings. Magnetometer data is disregarded.
*
* @ret Always returns true.
*/
bool update()
{
// Read in sensor events from device.
sensors_event_t orient, accel;
m_bno055.getEvent(&orient, Adafruit_BNO055::VECTOR_EULER);
m_bno055.getEvent(&accel, Adafruit_BNO055::VECTOR_LINEARACCEL);
// Populate orientation data. Currently this maps x, y, z to roll,
// pitch, yaw, but I have no idea if this is correct.
m_data.gyro_x = orient.orientation.x;
m_data.gyro_y = orient.orientation.y;
m_data.gyro_z = orient.orientation.z;
// Populate acceleration data.
m_data.accel_x = accel.acceleration.x;
m_data.accel_y = accel.acceleration.y;
m_data.accel_z = accel.acceleration.z;
// Populate quaternion orientation. This does not go into the data
// struct because it uses a proprietary class. Access with
// Sac2020Imu::quat().
m_quat = m_bno055.getQuat();
return true;
}
/**
* Gets quaternion orientation.
*
* @ret Quaternion orientation relative to startup orientation.
*/
imu::Quaternion quat()
{
return m_quat;
}
/**
* Gets the calibration level of IMU components.
*
* @param k_sys System.
* @param k_gyro Gyroscope.
* @param k_accel Accelerometer.
* @param k_mag Magnetometer.
*/
void get_calib(uint8_t* k_sys, uint8_t* k_gyro, uint8_t* k_accel,
uint8_t* k_mag)
{
m_bno055.getCalibration(k_sys, k_gyro, k_accel, k_mag);
}
/**
* Gets the current temperature read by the IMU.
*
* @ret Temperature in C.
*/
int8_t get_temp()
{
return m_bno055.getTemp();
}
private:
/**
* BNO055 driver.
*/
Adafruit_BNO055 m_bno055;
/**
* Last sensed quaternion orientation.
*/
imu::Quaternion m_quat;
};
#endif