1 // attitude_indicator.cxx - a vacuum-powered attitude indicator.
2 // Written by David Megginson, started 2002.
4 // This file is in the Public Domain and comes with no warranty.
10 #include "attitude_indicator.hxx"
11 #include <Main/fg_props.hxx>
14 AttitudeIndicator::AttitudeIndicator ()
18 AttitudeIndicator::~AttitudeIndicator ()
23 AttitudeIndicator::init ()
25 // TODO: allow index of pump and AI
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);
34 fgGetNode("/instrumentation/attitude-indicator/indicated-pitch-deg",
37 fgGetNode("/instrumentation/attitude-indicator/indicated-roll-deg",
42 AttitudeIndicator::bind ()
47 AttitudeIndicator::unbind ()
52 AttitudeIndicator::update (double dt)
54 // First, calculate the bogo-spin from 0 to 1.
55 // All numbers are made up.
57 double spin = _spin_node->getDoubleValue();
58 spin -= 0.005 * dt; // spin decays every 0.5% every second.
60 // spin increases up to 25% every second
61 // if suction is available and the gauge
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))
73 _spin_node->setDoubleValue(spin);
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));
83 _roll_out_node->setDoubleValue(roll);
84 _pitch_out_node->setDoubleValue(pitch);
87 // end of attitude_indicator.cxx