-
Notifications
You must be signed in to change notification settings - Fork 0
/
InclinometerModel.h
121 lines (102 loc) · 3.07 KB
/
InclinometerModel.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
/**
* @file InclinometerModel.h
* @author Ryan Johnson ([email protected])
* @brief Mathematical Model of the Inclinometer
* @version 0.1
* @date 2020-05-26
*
* @copyright Copyright (c) 2020
*
*/
#ifndef INCLINOMETER_MODEL_H
#define INCLINOMETER_MODEL_H
#include "MovingAverage.h"
#include <stlport.h>
#include <Eigen30.h>
#include <Eigen/Core>
#include <Eigen/Geometry>
using namespace Eigen;
namespace Inclinometer {
/**
* @brief The flattened version of a eigen matrix3d, which represents a
* rotation. This "frame" can be stored to represent the zero pose of an
* inclinometer.
*
* This model uses Roll-Pitch-Yaw euler rotations (Left-To-Right), or
* Yaw-Pitch-Roll (Right-to-Left)
*/
typedef struct {
double m00;
double m01;
double m02;
double m10;
double m11;
double m12;
double m20;
double m21;
double m22;
} ModelZeropoint;
/**
* @brief The Inclinometer Model
*
* This model allows a pitch-roll inclinometer to have a yaw offset and a
* programmable zero pose.
*/
class Model {
public:
/**
* @brief Construct a new Model object
*/
Model()
: baseFrame(AngleAxisd(0, Vector3d::UnitX()) *
AngleAxisd(0, Vector3d::UnitY()) *
AngleAxisd(0, Vector3d::UnitZ())),
zeroFrame(AngleAxisd(0, Vector3d::UnitX()) *
AngleAxisd(0, Vector3d::UnitY()) *
AngleAxisd(0, Vector3d::UnitZ())),
rollVelocity(0, 0.1), pitchVelocity(0, 0.1){};
/**
* @brief Imports a ModelZeropoint and updates the model
*
* @param data the zero point to import
*/
void importZero(ModelZeropoint data);
/**
* @brief Zeroes the model based on the passed in measurement, and returns
* the ModelZeropoint that can be used to come back to this zero point.
*
* @param angleMeasures angle measures (inclinometer pitch/roll)
* @return ModelZeropoint
*/
ModelZeropoint setMeasurementAsZero(Vector2d angleMeasures);
/**
* @brief Set the base frame (static rotation offsets) from three euler
* angles (roll, pitch, and yaw)
*
* @param angles roll, pitch, yaw
*/
void setBaseFrameAnglesRadians(Vector3d angles);
/**
* @brief Apply zero and base frame to get new coordinates.
*
* @param angleMeasures input (measured) angles (roll, pitch)
* @return Vector2d output (calculated) angles (roll, pitch)
*/
Vector2d calculate(Vector2d angleMeasures);
/**
* @brief Returns the cumulative exponentially-weighted moving average of
* the displacements of previous calculations
*
* @return Vector2d roll, pitch
*/
Vector2d getAngularAveragedVelocities();
private:
Matrix3d baseFrame;
Matrix3d zeroFrame;
Vector2d lastAngles;
::MovingAverage pitchVelocity;
::MovingAverage rollVelocity;
Matrix3d convertAnglesToFrame(Vector2d angleMeasures);
};
}; // namespace Inclinometer
#endif