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.
9 #include <math.h> // fabs()
11 #include "attitude_indicator.hxx"
12 #include <Main/fg_props.hxx>
13 #include <Main/util.hxx>
16 AttitudeIndicator::AttitudeIndicator ()
21 AttitudeIndicator::~AttitudeIndicator ()
26 AttitudeIndicator::init ()
28 // TODO: allow index of pump and AI
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/config/tumble-flag",
37 fgGetNode("/instrumentation/attitude-indicator/indicated-pitch-deg",
40 fgGetNode("/instrumentation/attitude-indicator/indicated-roll-deg",
45 AttitudeIndicator::bind ()
47 fgTie("/instrumentation/attitude-indicator/serviceable",
48 &_gyro, &Gyro::is_serviceable, &Gyro::set_serviceable);
49 fgTie("/instrumentation/attitude-indicator/spin",
50 &_gyro, &Gyro::get_spin_norm, &Gyro::set_spin_norm);
54 AttitudeIndicator::unbind ()
56 fgUntie("/instrumentation/attitude-indicator/serviceable");
57 fgUntie("/instrumentation/attitude-indicator/spin");
61 AttitudeIndicator::update (double dt)
63 // Get the spin from the gyro
64 _gyro.set_power_norm(_suction_node->getDoubleValue()/5.0);
66 double spin = _gyro.get_spin_norm();
68 // Calculate the responsiveness
69 double responsiveness = spin * spin * spin * spin * spin * spin;
71 // Get the indicated roll and pitch
72 double roll = _roll_in_node->getDoubleValue();
73 double pitch = _pitch_in_node->getDoubleValue();
75 // Calculate the tumble for the
77 if (_tumble_flag_node->getBoolValue()) {
79 if (fabs(roll) > 45.0) {
80 double target = (fabs(roll) - 45.0) / 45.0;
84 if (fabs(pitch) > 45.0) {
85 double target = (fabs(pitch) - 45.0) / 45.0;
93 // Reerect in 5 minutes
98 responsiveness *= ((1.0 - _tumble) * (1.0 - _tumble) *
99 (1.0 - _tumble) * (1.0 - _tumble));
103 roll = fgGetLowPass(_roll_out_node->getDoubleValue(), roll,
105 pitch = fgGetLowPass(_pitch_out_node->getDoubleValue(), pitch,
108 // Assign the new values
109 _roll_out_node->setDoubleValue(roll);
110 _pitch_out_node->setDoubleValue(pitch);
113 // end of attitude_indicator.cxx