]> git.mxchange.org Git - flightgear.git/blob - src/Instrumentation/attitude_indicator.cxx
9b6626e8785c6ab6ca3554cab605938dc6699eda
[flightgear.git] / src / Instrumentation / attitude_indicator.cxx
1 // attitude_indicator.cxx - a vacuum-powered attitude indicator.
2 // Written by David Megginson, started 2002.
3 //
4 // This file is in the Public Domain and comes with no warranty.
5
6 // TODO:
7 // - tumble
8 // - better spin-up
9
10 #include "attitude_indicator.hxx"
11 #include <Main/fg_props.hxx>
12
13
14 AttitudeIndicator::AttitudeIndicator ()
15 {
16 }
17
18 AttitudeIndicator::~AttitudeIndicator ()
19 {
20 }
21
22 void
23 AttitudeIndicator::init ()
24 {
25                                 // TODO: allow index of pump and AI
26                                 // to be configured.
27     _serviceable_node =
28         fgGetNode("/instrumentation/attitude-indicator/serviceable", true);
29     _pitch_in_node = fgGetNode("/orientation/pitch-deg", true);
30     _roll_in_node = fgGetNode("/orientation/roll-deg", true);
31     _suction_node = fgGetNode("/systems/vacuum[0]/suction-inhg", true);
32     _pitch_out_node =
33         fgGetNode("/instrumentation/attitude-indicator/indicated-pitch-deg",
34                   true);
35     _roll_out_node =
36         fgGetNode("/instrumentation/attitude-indicator/indicated-roll-deg",
37                   true);
38 }
39
40 void
41 AttitudeIndicator::bind ()
42 {
43 }
44
45 void
46 AttitudeIndicator::unbind ()
47 {
48 }
49
50 void
51 AttitudeIndicator::update (double dt)
52 {
53                                 // First, calculate the bogo-spin from 0 to 1.
54                                 // All numbers are made up.
55
56     _spin -= 0.005 * dt;         // spin decays every 0.5% every second.
57
58                                 // spin increases up to 25% every second
59                                 // if suction is available and the gauge
60                                 // is serviceable.
61     if (_serviceable_node->getBoolValue()) {
62         double suction = _suction_node->getDoubleValue();
63         double step = 0.25 * (suction / 5.0) * dt;
64         if ((_spin + step) <= (suction / 5.0))
65             _spin += step;
66     }
67     if (_spin > 1.0)
68         _spin = 1.0;
69     else if (_spin < 0.0)
70         _spin = 0.0;
71
72                                 // Next, calculate the indicated roll
73                                 // and pitch, introducing errors.
74     double factor = 1.0 - ((1.0 - _spin) * (1.0 - _spin));
75     double roll = _roll_in_node->getDoubleValue();
76     double pitch = _pitch_in_node->getDoubleValue();
77     roll = 35 + (factor * (roll - 35));
78     pitch = 15 + (factor * (pitch - 15));
79
80     _roll_out_node->setDoubleValue(roll);
81     _pitch_out_node->setDoubleValue(pitch);
82 }
83
84 // end of attitude_indicator.cxx