-
Notifications
You must be signed in to change notification settings - Fork 3
/
sensor.cpp
52 lines (44 loc) · 1.27 KB
/
sensor.cpp
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
/**
* This file contains the implementation for the sensor class,
* which determines the launch vehicle state based on raw
* sensor data.
*/
#include "sensor.h"
sensor::sensor()
{
offset = 0;
}
void sensor::zero_altimeters(double a1, double a2, double a3, double a4)
{
offset = (a1 + a2 + a3 + a4)/N_ALTIMETERS;
}
double sensor::get_vertical_speed(state_t X_tm1, double a1, double a2,
double a3, double a4){
/**
* We use a simple calculation of finite differences to calculate the
* average velocity over the last sampling period
*/
return (get_altitude(X_tm1, a1,a2,a3,a4)-X_tm1->altitude)/SAMPLE_T;
}
double sensor::get_altitude(state_t X_tm1, double a1, double a2, double a3, double a4)
{
/**
* We take the average of the altimeter readings and
* convert to an altitude AGL
*/
return ((a1 + a2 + a3 + a4)/N_ALTIMETERS - offset);
}
double sensor::get_polar_angle(double th_y, double th_z)
{
th_y = th_y * M_PI/180;
th_z = th_z * M_PI/180;
/**
* this function combines the Euler angles in y and z
* to form the polar angle in radians
*/
return atan( sqrt(tan(th_y)*tan(th_y) + tan(th_z)*tan(th_z)) );
}
double sensor::get_polar_angle(double th)
{
return th;
}