forked from Openvario/variod
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstf.c
97 lines (78 loc) · 2.16 KB
/
stf.c
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
#include "stf.h"
#include <stdio.h>
float mc_val;
t_polar polar, ideal_polar;
// remember if we have received the Real Polar from XCSoar, yet.
bool real_polar_valid = false;
float ballast;
float degradation;
float getSTF(float v_sink){
float stfsq, speed;
stfsq = (polar.c+mc_val+v_sink)/polar.a;
speed=(stfsq > 0)? sqrt(stfsq):0;
return speed/3.6;
}
float getPlaneSink(float ias){
return polar.a*ias*ias+polar.b*ias+polar.c;
}
float getNet(float v_sink, float ias){
//printf("polar: %f,%f,%f, mcc: %f\n", polar.a, polar.b, polar.c, mc_val);
ias*=3.6;
return v_sink-getPlaneSink(ias);
}
float getIAS(float q){
return sqrt(2*q / RHO);
}
void setMC(float mc){
mc_val=mc;
}
/***********************************************
* formulas for calculating real polar from ideal polar
* are various places, for instance:
*
* Streckensegelflug, Helmut Reichmann, ISBN 3-613-02479-9
* Page 188 ff
*
* Idaflieg.de various papers
*
* In XCSoar:
* GlidePolar::Update() in XCSoar/src/Engine/GlideSolvers/GlidePolar.cpp
*********************************************/
static void updateRealPolar(){
// we don't use Ideal Polar and degradation and ballast
// if we have the Real Polar from XCSoar
if (real_polar_valid) return;
// TODO: this formula for loading_factor is incorrect
// it should be loading_factor = sqrt(total_mass/reference_mass)
// with total_mass = dry_mass + ballast
// reference_mass is the mass at which the polar was measured.
float loading_factor= (ideal_polar.w >0)? sqrt((ideal_polar.w + ballast) / ideal_polar.w) : 1;
float deg_inv = (degradation>0)? 1.0/degradation : 1;
polar.a= deg_inv * ideal_polar.a / loading_factor;
polar.b= deg_inv * ideal_polar.b;
polar.c= deg_inv * ideal_polar.c * loading_factor;
}
void setPolar(float a, float b, float c, float w){
ideal_polar.a=a;
ideal_polar.b=b;
ideal_polar.c=c;
ideal_polar.w=w;
updateRealPolar();
}
void setRealPolar(float a, float b, float c){
polar.a=a;
polar.b=b;
polar.c=c;
real_polar_valid = true;
}
void setBallast(float b){
ballast=b;
updateRealPolar();
}
void setDegradation(float d){
degradation=d;
updateRealPolar();
}
void initSTF(){
setPolar(POL_A,POL_B,POL_C,POL_W);
}