]> git.mxchange.org Git - flightgear.git/blob - src/Instrumentation/attitude_indicator.cxx
5378e15ed8fd29630ef362355c5fe5ea4f3a71c0
[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     _spin_node = fgGetNode("/instrumentation/attitude-indicator/spin", true);
30     _pitch_in_node = fgGetNode("/orientation/pitch-deg", true);
31     _roll_in_node = fgGetNode("/orientation/roll-deg", true);
32     _suction_node = fgGetNode("/systems/vacuum[0]/suction-inhg", true);
33     _pitch_out_node =
34         fgGetNode("/instrumentation/attitude-indicator/indicated-pitch-deg",
35                   true);
36     _roll_out_node =
37         fgGetNode("/instrumentation/attitude-indicator/indicated-roll-deg",
38                   true);
39 }
40
41 void
42 AttitudeIndicator::bind ()
43 {
44 }
45
46 void
47 AttitudeIndicator::unbind ()
48 {
49 }
50
51 void
52 AttitudeIndicator::update (double dt)
53 {
54                                 // First, calculate the bogo-spin from 0 to 1.
55                                 // All numbers are made up.
56
57     double spin = _spin_node->getDoubleValue();
58     spin -= 0.005 * dt;         // spin decays every 0.5% every second.
59
60                                 // spin increases up to 25% every second
61                                 // if suction is available and the gauge
62                                 // is serviceable.
63     if (_serviceable_node->getBoolValue()) {
64         double suction = _suction_node->getDoubleValue();
65         double step = 0.25 * (suction / 5.0) * dt;
66         if ((spin + step) <= (suction / 5.0))
67             spin += step;
68     }
69     if (spin > 1.0)
70         spin = 1.0;
71     else if (spin < 0.0)
72         spin = 0.0;
73     _spin_node->setDoubleValue(spin);
74
75                                 // Next, calculate the indicated roll
76                                 // and pitch, introducing errors.
77     double factor = 1.0 - ((1.0 - spin) * (1.0 - spin) * (1.0 - spin));
78     double roll = _roll_in_node->getDoubleValue();
79     double pitch = _pitch_in_node->getDoubleValue();
80     roll = 35 + (factor * (roll - 35));
81     pitch = 15 + (factor * (pitch - 15));
82
83     _roll_out_node->setDoubleValue(roll);
84     _pitch_out_node->setDoubleValue(pitch);
85 }
86
87 // end of attitude_indicator.cxx