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 "attitude_indicator.hxx"
10 #include <Main/fg_props.hxx>
11 #include <Main/util.hxx>
14 AttitudeIndicator::AttitudeIndicator ()
19 AttitudeIndicator::~AttitudeIndicator ()
24 AttitudeIndicator::init ()
26 // TODO: allow index of pump and AI
28 _pitch_in_node = fgGetNode("/orientation/pitch-deg", true);
29 _roll_in_node = fgGetNode("/orientation/roll-deg", true);
30 _suction_node = fgGetNode("/systems/vacuum[0]/suction-inhg", true);
32 fgGetNode("/instrumentation/attitude-indicator/config/tumble-flag",
35 fgGetNode("/instrumentation/attitude-indicator/indicated-pitch-deg",
38 fgGetNode("/instrumentation/attitude-indicator/indicated-roll-deg",
43 AttitudeIndicator::bind ()
45 fgTie("/instrumentation/attitude-indicator/serviceable",
46 &_gyro, &Gyro::is_serviceable, &Gyro::set_serviceable);
47 fgTie("/instrumentation/attitude-indicator/spin",
48 &_gyro, &Gyro::get_spin_norm, &Gyro::set_spin_norm);
52 AttitudeIndicator::unbind ()
54 fgUntie("/instrumentation/attitude-indicator/serviceable");
55 fgUntie("/instrumentation/attitude-indicator/spin");
59 AttitudeIndicator::update (double dt)
61 // Get the spin from the gyro
62 _gyro.set_power_norm(_suction_node->getDoubleValue()/5.0);
64 double spin = _gyro.get_spin_norm();
66 // Calculate the responsiveness
67 double responsiveness = spin * spin * spin * spin * spin * spin;
69 // Get the indicated roll and pitch
70 double roll = _roll_in_node->getDoubleValue();
71 double pitch = _pitch_in_node->getDoubleValue();
73 // Calculate the tumble for the
75 if (_tumble_flag_node->getBoolValue()) {
77 if (fabs(roll) > 45.0) {
78 double target = (fabs(roll) - 45.0) / 45.0;
82 if (fabs(pitch) > 45.0) {
83 double target = (fabs(pitch) - 45.0) / 45.0;
91 // Reerect in 5 minutes
96 responsiveness *= ((1.0 - _tumble) * (1.0 - _tumble) *
97 (1.0 - _tumble) * (1.0 - _tumble));
101 roll = fgGetLowPass(_roll_out_node->getDoubleValue(), roll,
103 pitch = fgGetLowPass(_pitch_out_node->getDoubleValue(), pitch,
106 // Assign the new values
107 _roll_out_node->setDoubleValue(roll);
108 _pitch_out_node->setDoubleValue(pitch);
111 // end of attitude_indicator.cxx