From 5289055776b645f25234f1f1f012727baa31e863 Mon Sep 17 00:00:00 2001 From: david Date: Fri, 27 Sep 2002 22:03:48 +0000 Subject: [PATCH] Added a heading-indicator connected to the vacuum pump and a vertical-speed indicator connected to the static port. --- src/Instrumentation/Makefile.am | 4 +- src/Instrumentation/heading_indicator.cxx | 94 +++++++++++++++++++ src/Instrumentation/heading_indicator.hxx | 60 ++++++++++++ src/Instrumentation/instrument_mgr.cxx | 4 + .../vertical_speed_indicator.cxx | 61 ++++++++++++ .../vertical_speed_indicator.hxx | 53 +++++++++++ 6 files changed, 275 insertions(+), 1 deletion(-) create mode 100644 src/Instrumentation/heading_indicator.cxx create mode 100644 src/Instrumentation/heading_indicator.hxx create mode 100644 src/Instrumentation/vertical_speed_indicator.cxx create mode 100644 src/Instrumentation/vertical_speed_indicator.hxx diff --git a/src/Instrumentation/Makefile.am b/src/Instrumentation/Makefile.am index 02707bb57..7553264cf 100644 --- a/src/Instrumentation/Makefile.am +++ b/src/Instrumentation/Makefile.am @@ -2,6 +2,8 @@ noinst_LIBRARIES = libInstrumentation.a libInstrumentation_a_SOURCES = instrument_mgr.cxx instrument_mgr.hxx \ altimeter.cxx altimeter.hxx \ - attitude_indicator.cxx attitude_indicator.hxx + attitude_indicator.cxx attitude_indicator.hxx \ + heading_indicator.cxx heading_indicator.hxx \ + vertical_speed_indicator.cxx vertical_speed_indicator.hxx INCLUDES = -I$(top_srcdir) -I$(top_srcdir)/src diff --git a/src/Instrumentation/heading_indicator.cxx b/src/Instrumentation/heading_indicator.cxx new file mode 100644 index 000000000..a5040f95d --- /dev/null +++ b/src/Instrumentation/heading_indicator.cxx @@ -0,0 +1,94 @@ +// 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. + +#include "heading_indicator.hxx" +#include
+#include
+ + +HeadingIndicator::HeadingIndicator () +{ +} + +HeadingIndicator::~HeadingIndicator () +{ +} + +void +HeadingIndicator::init () +{ + _serviceable_node = + fgGetNode("/instrumentation/heading-indicator/serviceable", true); + _offset_node = + fgGetNode("/instrumentation/heading-indicator/offset-deg", true); + _heading_in_node = fgGetNode("/orientation/heading-deg", true); + _suction_node = fgGetNode("/systems/vacuum[0]/suction-inhg", true); + _heading_out_node = + fgGetNode("/instrumentation/heading-indicator/indicated-heading-deg", + true); + _last_heading_deg = (_heading_in_node->getDoubleValue() + + _offset_node->getDoubleValue()); +} + +void +HeadingIndicator::bind () +{ +} + +void +HeadingIndicator::unbind () +{ +} + +void +HeadingIndicator::update (double dt) +{ + // First, calculate the bogo-spin from 0 to 1. + // All numbers are made up. + + _spin -= 0.005 * dt; // spin decays every 0.5% every second. + + // spin increases up to 25% every second + // if suction is available and the gauge + // is serviceable. + if (_serviceable_node->getBoolValue()) { + double suction = _suction_node->getDoubleValue(); + double step = 0.25 * (suction / 5.0) * dt; + if ((_spin + step) <= (suction / 5.0)) + _spin += step; + } + if (_spin > 1.0) + _spin = 1.0; + else if (_spin < 0.0) + _spin = 0.0; + + // Next, calculate time-based precession + double offset = _offset_node->getDoubleValue(); + offset -= dt * (0.25 / 60.0); // 360deg/day + while (offset < -360) + offset += 360; + while (offset > 360) + offset -= 360; + _offset_node->setDoubleValue(offset); + + // TODO: movement-induced error + + // Next, calculate the indicated heading, + // introducing errors. + double factor = 0.01 / (_spin * _spin * _spin * _spin * _spin * _spin); + double heading = _heading_in_node->getDoubleValue(); + heading = fgGetLowPass(_last_heading_deg, heading, dt/factor); + _last_heading_deg = heading; + + heading += offset; + while (heading < 0) + heading += 360; + while (heading > 360) + heading -= 360; + + _heading_out_node->setDoubleValue(heading); +} + +// end of heading_indicator.cxx diff --git a/src/Instrumentation/heading_indicator.hxx b/src/Instrumentation/heading_indicator.hxx new file mode 100644 index 000000000..6e414c9c4 --- /dev/null +++ b/src/Instrumentation/heading_indicator.hxx @@ -0,0 +1,60 @@ +// heading_indicator.hxx - a vacuum-powered heading indicator. +// Written by David Megginson, started 2002. +// +// This file is in the Public Domain and comes with no warranty. + + +#ifndef __INSTRUMENTS_HEADING_INDICATOR_HXX +#define __INSTRUMENTS_HEADING_INDICATOR_HXX 1 + +#ifndef __cplusplus +# error This library requires C++ +#endif + +#include +#include
+ + +/** + * Model a vacuum-powered heading indicator. + * + * This first, simple draft is hard-wired to vacuum pump #1. + * + * Input properties: + * + * /instrumentation/heading-indicator/serviceable + * /instrumentation/heading-indicator/offset-deg + * /orientation/heading-deg + * /systems/vacuum[0]/suction-inhg + * + * Output properties: + * + * /instrumentation/heading-indicator/indicated-heading-deg + */ +class HeadingIndicator : public FGSubsystem +{ + +public: + + HeadingIndicator (); + virtual ~HeadingIndicator (); + + virtual void init (); + virtual void bind (); + virtual void unbind (); + virtual void update (double dt); + +private: + + double _spin; + double _last_heading_deg; + + SGPropertyNode_ptr _serviceable_node; + SGPropertyNode_ptr _offset_node; + SGPropertyNode_ptr _heading_in_node; + SGPropertyNode_ptr _suction_node; + SGPropertyNode_ptr _heading_out_node; + +}; + +#endif // __INSTRUMENTS_HEADING_INDICATOR_HXX diff --git a/src/Instrumentation/instrument_mgr.cxx b/src/Instrumentation/instrument_mgr.cxx index 8025a8530..765c48715 100644 --- a/src/Instrumentation/instrument_mgr.cxx +++ b/src/Instrumentation/instrument_mgr.cxx @@ -7,6 +7,8 @@ #include "instrument_mgr.hxx" #include "altimeter.hxx" #include "attitude_indicator.hxx" +#include "heading_indicator.hxx" +#include "vertical_speed_indicator.hxx" FGInstrumentMgr::FGInstrumentMgr () @@ -28,6 +30,8 @@ FGInstrumentMgr::init () // TODO: replace with XML configuration _instruments.push_back(new Altimeter); _instruments.push_back(new AttitudeIndicator); + _instruments.push_back(new HeadingIndicator); + _instruments.push_back(new VerticalSpeedIndicator); // Initialize the individual instruments for (unsigned int i = 0; i < _instruments.size(); i++) diff --git a/src/Instrumentation/vertical_speed_indicator.cxx b/src/Instrumentation/vertical_speed_indicator.cxx new file mode 100644 index 000000000..295346691 --- /dev/null +++ b/src/Instrumentation/vertical_speed_indicator.cxx @@ -0,0 +1,61 @@ +// vertical_speed_indicator.cxx - a regular VSI. +// Written by David Megginson, started 2002. +// +// This file is in the Public Domain and comes with no warranty. + +#include + +#include "vertical_speed_indicator.hxx" +#include
+#include
+ + +VerticalSpeedIndicator::VerticalSpeedIndicator () + : _internal_pressure_inhg(29.92) +{ +} + +VerticalSpeedIndicator::~VerticalSpeedIndicator () +{ +} + +void +VerticalSpeedIndicator::init () +{ + _serviceable_node = + fgGetNode("/instrumentation/vertical-speed-indicator/serviceable", + true); + _pressure_node = + fgGetNode("/systems/static/pressure-inhg", true); + _speed_node = + fgGetNode("/instrumentation/vertical-speed-indicator/indicated-speed-fpm", + true); +} + +void +VerticalSpeedIndicator::bind () +{ +} + +void +VerticalSpeedIndicator::unbind () +{ +} + +void +VerticalSpeedIndicator::update (double dt) +{ + // model take from steam.cxx, with change + // from 10000 to 10500 for manual factor + if (_serviceable_node->getBoolValue()) { + double pressure = _pressure_node->getDoubleValue(); + _speed_node + ->setDoubleValue((_internal_pressure_inhg - pressure) * 10500); + _internal_pressure_inhg = + fgGetLowPass(_internal_pressure_inhg, + _pressure_node->getDoubleValue(), + dt/6.0); + } +} + +// end of vertical_speed_indicator.cxx diff --git a/src/Instrumentation/vertical_speed_indicator.hxx b/src/Instrumentation/vertical_speed_indicator.hxx new file mode 100644 index 000000000..b7d775531 --- /dev/null +++ b/src/Instrumentation/vertical_speed_indicator.hxx @@ -0,0 +1,53 @@ +// vertical_speed_indicator.hxx - a regular VSI tied to the static port. +// Written by David Megginson, started 2002. +// +// This file is in the Public Domain and comes with no warranty. + + +#ifndef __INSTRUMENTS_VERTICAL_SPEED_INDICATOR_HXX +#define __INSTRUMENTS_VERTICAL_SPEED_INDICATOR_HXX 1 + +#ifndef __cplusplus +# error This library requires C++ +#endif + +#include +#include
+ + +/** + * Model a non-instantaneous VSI tied to the static port. + * + * Input properties: + * + * /instrumentation/vertical-speed-indicator/serviceable + * /systems/static[0]/pressure-inhg + * + * Output properties: + * + * /instrumentation/vertical-speed-indicator/indicated-speed-fpm + */ +class VerticalSpeedIndicator : public FGSubsystem +{ + +public: + + VerticalSpeedIndicator (); + virtual ~VerticalSpeedIndicator (); + + virtual void init (); + virtual void bind (); + virtual void unbind (); + virtual void update (double dt); + +private: + + double _internal_pressure_inhg; + + SGPropertyNode_ptr _serviceable_node; + SGPropertyNode_ptr _pressure_node; + SGPropertyNode_ptr _speed_node; + +}; + +#endif // __INSTRUMENTS_VERTICAL_SPEED_INDICATOR_HXX -- 2.39.5