2002-09-27 22:03:48 +00:00
|
|
|
// heading_indicator.cxx - a vacuum-powered heading indicator.
|
|
|
|
// Written by David Megginson, started 2002.
|
|
|
|
//
|
|
|
|
// This file is in the Public Domain and comes with no warranty.
|
|
|
|
|
2004-11-19 23:01:34 +00:00
|
|
|
#include <simgear/compiler.h>
|
2009-03-15 19:18:14 +00:00
|
|
|
#include <simgear/sg_inlines.h>
|
2008-07-25 18:38:29 +00:00
|
|
|
#include <iostream>
|
|
|
|
#include <string>
|
2004-11-19 23:01:34 +00:00
|
|
|
#include <sstream>
|
|
|
|
|
2002-09-27 22:03:48 +00:00
|
|
|
#include "heading_indicator.hxx"
|
|
|
|
#include <Main/fg_props.hxx>
|
|
|
|
#include <Main/util.hxx>
|
|
|
|
|
|
|
|
|
2004-10-16 12:37:39 +00:00
|
|
|
HeadingIndicator::HeadingIndicator ( SGPropertyNode *node )
|
|
|
|
:
|
2006-12-06 22:11:43 +00:00
|
|
|
_name(node->getStringValue("name", "heading-indicator")),
|
|
|
|
_num(node->getIntValue("number", 0)),
|
|
|
|
_suction(node->getStringValue("suction", "/systems/vacuum/suction-inhg"))
|
2002-09-27 22:03:48 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
HeadingIndicator::~HeadingIndicator ()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
HeadingIndicator::init ()
|
|
|
|
{
|
2004-10-16 12:37:39 +00:00
|
|
|
string branch;
|
2006-12-06 22:11:43 +00:00
|
|
|
branch = "/instrumentation/" + _name;
|
2004-10-16 12:37:39 +00:00
|
|
|
|
2006-12-06 22:11:43 +00:00
|
|
|
SGPropertyNode *node = fgGetNode(branch.c_str(), _num, true );
|
2004-10-16 12:37:39 +00:00
|
|
|
_offset_node = node->getChild("offset-deg", 0, true);
|
2002-09-27 22:03:48 +00:00
|
|
|
_heading_in_node = fgGetNode("/orientation/heading-deg", true);
|
2006-12-06 22:11:43 +00:00
|
|
|
_suction_node = fgGetNode(_suction.c_str(), true);
|
2004-10-16 12:37:39 +00:00
|
|
|
_heading_out_node = node->getChild("indicated-heading-deg", 0, true);
|
2009-03-15 19:18:14 +00:00
|
|
|
_heading_bug_error_node = node->getChild("heading-bug-error-deg", 0, true);
|
|
|
|
_heading_bug_node = node->getChild("heading-bug-deg", 0, true);
|
2002-09-27 22:03:48 +00:00
|
|
|
_last_heading_deg = (_heading_in_node->getDoubleValue() +
|
|
|
|
_offset_node->getDoubleValue());
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
HeadingIndicator::bind ()
|
|
|
|
{
|
2004-11-19 23:01:34 +00:00
|
|
|
std::ostringstream temp;
|
2004-10-16 12:37:39 +00:00
|
|
|
string branch;
|
2006-12-06 22:11:43 +00:00
|
|
|
temp << _num;
|
|
|
|
branch = "/instrumentation/" + _name + "[" + temp.str() + "]";
|
2004-11-19 23:01:34 +00:00
|
|
|
|
|
|
|
fgTie((branch + "/serviceable").c_str(),
|
2003-01-26 20:20:15 +00:00
|
|
|
&_gyro, &Gyro::is_serviceable, &Gyro::set_serviceable);
|
2004-11-19 23:01:34 +00:00
|
|
|
fgTie((branch + "/spin").c_str(),
|
2003-01-25 19:49:27 +00:00
|
|
|
&_gyro, &Gyro::get_spin_norm, &Gyro::set_spin_norm);
|
2002-09-27 22:03:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
HeadingIndicator::unbind ()
|
|
|
|
{
|
2004-11-19 23:01:34 +00:00
|
|
|
std::ostringstream temp;
|
2004-10-16 12:37:39 +00:00
|
|
|
string branch;
|
2006-12-06 22:11:43 +00:00
|
|
|
temp << _num;
|
|
|
|
branch = "/instrumentation/" + _name + "[" + temp.str() + "]";
|
2004-11-19 23:01:34 +00:00
|
|
|
|
|
|
|
fgUntie((branch + "/serviceable").c_str());
|
|
|
|
fgUntie((branch + "/spin").c_str());
|
2002-09-27 22:03:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
HeadingIndicator::update (double dt)
|
|
|
|
{
|
2003-01-25 19:49:27 +00:00
|
|
|
// Get the spin from the gyro
|
|
|
|
_gyro.set_power_norm(_suction_node->getDoubleValue()/5.0);
|
|
|
|
_gyro.update(dt);
|
|
|
|
double spin = _gyro.get_spin_norm();
|
2002-09-27 22:03:48 +00:00
|
|
|
|
|
|
|
// Next, calculate time-based precession
|
|
|
|
double offset = _offset_node->getDoubleValue();
|
|
|
|
offset -= dt * (0.25 / 60.0); // 360deg/day
|
2009-03-15 19:18:14 +00:00
|
|
|
SG_NORMALIZE_RANGE(offset, -360.0, 360.0);
|
2002-09-27 22:03:48 +00:00
|
|
|
|
|
|
|
// TODO: movement-induced error
|
|
|
|
|
|
|
|
// Next, calculate the indicated heading,
|
|
|
|
// introducing errors.
|
2009-01-08 07:57:04 +00:00
|
|
|
double factor = 100 * (spin * spin * spin * spin * spin * spin);
|
2002-09-27 22:03:48 +00:00
|
|
|
double heading = _heading_in_node->getDoubleValue();
|
2002-10-27 20:32:34 +00:00
|
|
|
|
|
|
|
// Now, we have to get the current
|
|
|
|
// heading and the last heading into
|
|
|
|
// the same range.
|
|
|
|
while ((heading - _last_heading_deg) > 180)
|
|
|
|
_last_heading_deg += 360;
|
|
|
|
while ((heading - _last_heading_deg) < -180)
|
|
|
|
_last_heading_deg -= 360;
|
|
|
|
|
2009-01-08 07:57:04 +00:00
|
|
|
heading = fgGetLowPass(_last_heading_deg, heading, dt * factor);
|
2002-09-27 22:03:48 +00:00
|
|
|
_last_heading_deg = heading;
|
|
|
|
|
|
|
|
heading += offset;
|
2009-03-15 19:18:14 +00:00
|
|
|
SG_NORMALIZE_RANGE(heading, 0.0, 360.0);
|
2002-09-27 22:03:48 +00:00
|
|
|
|
|
|
|
_heading_out_node->setDoubleValue(heading);
|
2009-03-15 19:18:14 +00:00
|
|
|
|
|
|
|
// Calculate heading bug error normalized to +/- 180.0
|
|
|
|
double heading_bug = _heading_bug_node->getDoubleValue();
|
|
|
|
double diff = heading_bug - heading;
|
|
|
|
|
|
|
|
SG_NORMALIZE_RANGE(diff, -180.0, 180.0);
|
|
|
|
_heading_bug_error_node->setDoubleValue( diff );
|
2002-09-27 22:03:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// end of heading_indicator.cxx
|