2002-09-24 14:51:37 +00:00
|
|
|
// attitude_indicator.cxx - a vacuum-powered attitude indicator.
|
|
|
|
// Written by David Megginson, started 2002.
|
|
|
|
//
|
|
|
|
// This file is in the Public Domain and comes with no warranty.
|
|
|
|
|
2002-09-27 18:27:58 +00:00
|
|
|
// TODO:
|
|
|
|
// - tumble
|
|
|
|
// - better spin-up
|
|
|
|
|
2002-09-24 14:51:37 +00:00
|
|
|
#include "attitude_indicator.hxx"
|
|
|
|
#include <Main/fg_props.hxx>
|
|
|
|
|
|
|
|
|
|
|
|
AttitudeIndicator::AttitudeIndicator ()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
AttitudeIndicator::~AttitudeIndicator ()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
AttitudeIndicator::init ()
|
|
|
|
{
|
|
|
|
// TODO: allow index of pump and AI
|
|
|
|
// to be configured.
|
|
|
|
_serviceable_node =
|
|
|
|
fgGetNode("/instrumentation/attitude-indicator/serviceable", true);
|
2002-09-29 18:26:24 +00:00
|
|
|
_spin_node = fgGetNode("/instrumentation/attitude-indicator/spin", true);
|
2002-09-24 14:51:37 +00:00
|
|
|
_pitch_in_node = fgGetNode("/orientation/pitch-deg", true);
|
|
|
|
_roll_in_node = fgGetNode("/orientation/roll-deg", true);
|
|
|
|
_suction_node = fgGetNode("/systems/vacuum[0]/suction-inhg", true);
|
|
|
|
_pitch_out_node =
|
|
|
|
fgGetNode("/instrumentation/attitude-indicator/indicated-pitch-deg",
|
|
|
|
true);
|
|
|
|
_roll_out_node =
|
|
|
|
fgGetNode("/instrumentation/attitude-indicator/indicated-roll-deg",
|
|
|
|
true);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
AttitudeIndicator::bind ()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
AttitudeIndicator::unbind ()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
AttitudeIndicator::update (double dt)
|
|
|
|
{
|
|
|
|
// First, calculate the bogo-spin from 0 to 1.
|
|
|
|
// All numbers are made up.
|
|
|
|
|
2002-09-29 18:26:24 +00:00
|
|
|
double spin = _spin_node->getDoubleValue();
|
|
|
|
spin -= 0.005 * dt; // spin decays every 0.5% every second.
|
2002-09-24 14:51:37 +00:00
|
|
|
|
2002-09-24 16:37:28 +00:00
|
|
|
// spin increases up to 25% every second
|
2002-09-24 14:51:37 +00:00
|
|
|
// if suction is available and the gauge
|
|
|
|
// is serviceable.
|
|
|
|
if (_serviceable_node->getBoolValue()) {
|
|
|
|
double suction = _suction_node->getDoubleValue();
|
2002-09-24 16:37:28 +00:00
|
|
|
double step = 0.25 * (suction / 5.0) * dt;
|
2002-09-29 18:26:24 +00:00
|
|
|
if ((spin + step) <= (suction / 5.0))
|
|
|
|
spin += step;
|
2002-09-24 14:51:37 +00:00
|
|
|
}
|
2002-09-29 18:26:24 +00:00
|
|
|
if (spin > 1.0)
|
|
|
|
spin = 1.0;
|
|
|
|
else if (spin < 0.0)
|
|
|
|
spin = 0.0;
|
|
|
|
_spin_node->setDoubleValue(spin);
|
2002-09-24 14:51:37 +00:00
|
|
|
|
|
|
|
// Next, calculate the indicated roll
|
2002-09-24 16:37:28 +00:00
|
|
|
// and pitch, introducing errors.
|
2002-09-29 18:26:24 +00:00
|
|
|
double factor = 1.0 - ((1.0 - spin) * (1.0 - spin));
|
2002-09-24 14:51:37 +00:00
|
|
|
double roll = _roll_in_node->getDoubleValue();
|
|
|
|
double pitch = _pitch_in_node->getDoubleValue();
|
2002-09-24 16:37:28 +00:00
|
|
|
roll = 35 + (factor * (roll - 35));
|
|
|
|
pitch = 15 + (factor * (pitch - 15));
|
|
|
|
|
2002-09-24 14:51:37 +00:00
|
|
|
_roll_out_node->setDoubleValue(roll);
|
|
|
|
_pitch_out_node->setDoubleValue(pitch);
|
|
|
|
}
|
|
|
|
|
|
|
|
// end of attitude_indicator.cxx
|