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