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.
6 #include "attitude_indicator.hxx"
7 #include <Main/fg_props.hxx>
10 AttitudeIndicator::AttitudeIndicator ()
14 AttitudeIndicator::~AttitudeIndicator ()
19 AttitudeIndicator::init ()
21 // TODO: allow index of pump and AI
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);
29 fgGetNode("/instrumentation/attitude-indicator/indicated-pitch-deg",
32 fgGetNode("/instrumentation/attitude-indicator/indicated-roll-deg",
37 AttitudeIndicator::bind ()
42 AttitudeIndicator::unbind ()
47 AttitudeIndicator::update (double dt)
49 // First, calculate the bogo-spin from 0 to 1.
50 // All numbers are made up.
52 _spin -= 0.005 * dt; // spin decays every 0.5% every second.
54 // spin increases up to 25% every second
55 // if suction is available and the gauge
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))
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));
76 _roll_out_node->setDoubleValue(roll);
77 _pitch_out_node->setDoubleValue(pitch);
80 // end of attitude_indicator.cxx