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);
|
|
|
|
_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-24 16:37:28 +00:00
|
|
|
_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-24 14:51:37 +00:00
|
|
|
if ((_spin + step) <= (suction / 5.0))
|
|
|
|
_spin += step;
|
|
|
|
}
|
2002-09-24 16:37:28 +00:00
|
|
|
if (_spin > 1.0)
|
|
|
|
_spin = 1.0;
|
|
|
|
else if (_spin < 0.0)
|
|
|
|
_spin = 0.0;
|
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.
|
|
|
|
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
|