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
27 _pitch_in_node = fgGetNode("/orientation/pitch-deg", true);
28 _roll_in_node = fgGetNode("/orientation/roll-deg", true);
29 _suction_node = fgGetNode("/systems/vacuum[0]/suction-inhg", true);
31 fgGetNode("/instrumentation/attitude-indicator/indicated-pitch-deg",
34 fgGetNode("/instrumentation/attitude-indicator/indicated-roll-deg",
39 AttitudeIndicator::bind ()
41 fgTie("/instrumentation/attitude-indicator/serviceable",
42 &_gyro, &Gyro::is_serviceable, &Gyro::set_serviceable);
43 fgTie("/instrumentation/attitude-indicator/spin",
44 &_gyro, &Gyro::get_spin_norm, &Gyro::set_spin_norm);
48 AttitudeIndicator::unbind ()
50 fgUntie("/instrumentation/attitude-indicator/serviceable");
51 fgUntie("/instrumentation/attitude-indicator/spin");
55 AttitudeIndicator::update (double dt)
57 // Get the spin from the gyro
58 _gyro.set_power_norm(_suction_node->getDoubleValue()/5.0);
60 double spin = _gyro.get_spin_norm();
62 // Next, calculate the indicated roll
63 // and pitch, introducing errors.
64 double factor = 1.0 - ((1.0 - spin) * (1.0 - spin) * (1.0 - spin));
65 double roll = _roll_in_node->getDoubleValue();
66 double pitch = _pitch_in_node->getDoubleValue();
67 roll = 35 + (factor * (roll - 35));
68 pitch = 15 + (factor * (pitch - 15));
70 _roll_out_node->setDoubleValue(roll);
71 _pitch_out_node->setDoubleValue(pitch);
74 // end of attitude_indicator.cxx