-
Notifications
You must be signed in to change notification settings - Fork 53
/
Copy pathdevicefilter.h
174 lines (134 loc) · 4.19 KB
/
devicefilter.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
#ifndef DEVICEFILTER_H
#define DEVICEFILTER_H
#include <QThread>
#include <QTimer>
#include "usbcan.h"
#include "IMUfilter.h"
#include "macrodefs.h"
using namespace std;
class deviceFilter : public QObject
{
Q_OBJECT
public:
deviceFilter();
~deviceFilter();
signals:
void postGyroAndAccelData(double gyroRateX, double gyroRateY, double gyroRateZ, double accelRateX, double accelRateY, double accelRateZ);
void postFilterOrientationData(double pitch, double yaw, double roll);
public slots:
void filterUpdateAndCalc();
void sampleGyroAndAccel();
public slots:
void testSampleTimer();
void testFilterTimer();
void naiveIntegrationFilter();
private:
QTimer* _sampleTimer;
QTimer* _filterTimer;
USBCAN* _usbCANDevice;
IMUfilter* _imuFilter;
public:
void attachUsbCANDevice(USBCAN* usbCANDevice);
void attachImuFilter(IMUfilter *imuFilter);
void setBiasForGyroAndAccel(double gyroXBias, double gyroYBias, double gyroZBias, double accelXBias, double accelYBias, double accelZBias);
public:
//Offsets for the gyroscope.
//The readings we take when the gyroscope is stationary won't be 0, so we'll
//average a set of readings we do get when the gyroscope is stationary and
//take those away from subsequent readings to ensure the gyroscope is offset
//or "biased" to 0.
double w_xBias;
double w_yBias;
double w_zBias;
//Offsets for the accelerometer.
//Same as with the gyroscope.
double a_xBias;
double a_yBias;
double a_zBias;
//Accumulators used for oversampling and then averaging.
volatile double a_xAccumulator;
volatile double a_yAccumulator;
volatile double a_zAccumulator;
volatile double w_xAccumulator;
volatile double w_yAccumulator;
volatile double w_zAccumulator;
//Accelerometer and gyroscope readings for x, y, z axes.
volatile double a_x;
volatile double a_y;
volatile double a_z;
volatile double w_x;
volatile double w_y;
volatile double w_z;
// Last reading
volatile double a_x_last;
volatile double a_y_last;
volatile double a_z_last;
volatile double w_x_last;
volatile double w_y_last;
volatile double w_z_last;
volatile double a_x_m_ss;
volatile double a_y_m_ss;
volatile double a_z_m_ss;
volatile double w_x_rad_s;
volatile double w_y_rad_s;
volatile double w_z_rad_s;
//Buffer for accelerometer readings.
int readings[3];
//Number of accelerometer samples we're on.
int accelerometerSamples;
//Number of gyroscope samples we're on.
int gyroscopeSamples;
// Orientation for X, Y, Z(Pitch, Yaw and Roll)
double gyroOrientationX;
double gyroOrientationY;
double gyroOrientationZ;
/**
* Prototypes
*/
//Set up the ADXL345 appropriately.
void initializeAcceleromter(void);
//Calculate the null bias.
void calibrateAccelerometer(void);
//Take a set of samples and average them.
void sampleAccelerometer(void);
//Set up the ITG3200 appropriately.
void initializeGyroscope(void);
//Calculate the null bias.
void calibrateGyroscope(void);
//Take a set of samples and average them.
void sampleGyroscope(void);
// Calculate the null bias for both Gyro and Accel
void calibrateGyroAndAccel(void);
// Take a set of samples both for Gyro and Accel
//void sampleGyroAndAccel(void);
//Update the filter and calculate the Euler angles.
//void filterUpdateAndCalc(void);
public:
// Variables for calculating IMU-F100A5 angles
unsigned long totalReceivedFrames;
unsigned long totalReceivedID66;
unsigned long totalReceivedID67;
unsigned long totalReceivedID69;
int iterateTimes;
signed long gyroXLong;
signed long gyroYLong;
signed long gyroZLong;
signed long tempOfIMULong;
signed short accelXLong;
signed short accelYLong;
signed short accelZLong;
double gyroRateX;
double gyroRateY;
double gyroRateZ;
double accelRateX;
double accelRateY;
double accelRateZ;
double tempIMU;
public:
VCI_CAN_OBJ vco[1000];
DWORD recNumber;
DWORD receivedFrames;
public:
bool showVerboseInfo;
};
#endif // DEVICEFILTER_H