From: david Date: Fri, 27 Sep 2002 18:27:58 +0000 (+0000) Subject: Added static port system and a new altimeter model connected to it. X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=8d5714084e76ab923c08aae431dbdb9e516aaf96;p=flightgear.git Added static port system and a new altimeter model connected to it. The static port uses the /systems/static/ property subtree, and the altimeter uses the /instrumentation/altimeter/ property subtree. --- diff --git a/src/Instrumentation/Makefile.am b/src/Instrumentation/Makefile.am index e66685e74..02707bb57 100644 --- a/src/Instrumentation/Makefile.am +++ b/src/Instrumentation/Makefile.am @@ -1,6 +1,7 @@ noinst_LIBRARIES = libInstrumentation.a libInstrumentation_a_SOURCES = instrument_mgr.cxx instrument_mgr.hxx \ + altimeter.cxx altimeter.hxx \ attitude_indicator.cxx attitude_indicator.hxx INCLUDES = -I$(top_srcdir) -I$(top_srcdir)/src diff --git a/src/Instrumentation/altimeter.cxx b/src/Instrumentation/altimeter.cxx new file mode 100644 index 000000000..b5450551e --- /dev/null +++ b/src/Instrumentation/altimeter.cxx @@ -0,0 +1,90 @@ +// altimeter.cxx - an altimeter tied to the static port. +// Written by David Megginson, started 2002. +// +// This file is in the Public Domain and comes with no warranty. + +#include + +#include "altimeter.hxx" +#include
+ + +// Altitude based on pressure difference from sea level. +// pressure difference inHG, altitude ft +static double altitude_data[][2] = { + -8.41, -8858.27, + 0.00, 0.00, + 3.05, 2952.76, + 5.86, 5905.51, + 8.41, 8858.27, + 10.74, 11811.02, + 12.87, 14763.78, + 14.78, 17716.54, + 16.55, 20669.29, + 18.13, 23622.05, + 19.62, 26574.80, + 20.82, 29527.56, + 21.96, 32480.31, + 23.01, 35433.07, + 23.91, 38385.83, + 24.71, 41338.58, + 25.40, 44291.34, + 26.00, 47244.09, + 26.51, 50196.85, + 26.96, 53149.61, + 27.35, 56102.36, + 27.68, 59055.12, + 27.98, 62007.87, + 29.62, 100000.00 // just to fill it in + -1, -1, +}; + + +Altimeter::Altimeter () + : _altitude_table(new SGInterpTable) +{ + + for (int i = 0; altitude_data[i][0] != -1; i++) + _altitude_table->addEntry(altitude_data[i][0], altitude_data[i][1]); +} + +Altimeter::~Altimeter () +{ + delete _altitude_table; +} + +void +Altimeter::init () +{ + _serviceable_node = + fgGetNode("/instrumentation/altimeter/serviceable", true); + _setting_node = + fgGetNode("/instrumentation/altimeter/setting-inhg", true); + _pressure_node = + fgGetNode("/systems/static/pressure-inhg", true); + _altitude_node = + fgGetNode("/instrumentation/altimeter/indicated-altitude-ft", true); +} + +void +Altimeter::bind () +{ +} + +void +Altimeter::unbind () +{ +} + +void +Altimeter::update (double dt) +{ + if (_serviceable_node->getBoolValue()) { + double pressure = _pressure_node->getDoubleValue(); + double setting = _setting_node->getDoubleValue(); + _altitude_node + ->setDoubleValue(_altitude_table->interpolate(setting-pressure)); + } +} + +// end of altimeter.cxx diff --git a/src/Instrumentation/altimeter.hxx b/src/Instrumentation/altimeter.hxx new file mode 100644 index 000000000..b653a4c13 --- /dev/null +++ b/src/Instrumentation/altimeter.hxx @@ -0,0 +1,60 @@ +// altimeter.hxx - an altimeter 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_ALTIMETER_HXX +#define __INSTRUMENTS_ALTIMETER_HXX 1 + +#ifndef __cplusplus +# error This library requires C++ +#endif + +#include +#include
+ + +class SGInterpTable; + + +/** + * Model a barometric altimeter tied to the static port. + * + * Input properties: + * + * /instrumentation/altimeter/serviceable + * /instrumentation/altimeter/setting-inhg + * /systems/static[0]/pressure-inhg + * + * Output properties: + * + * /instrumentation/altimeter/indicated-altitude-ft + */ +class Altimeter : public FGSubsystem +{ + +public: + + Altimeter (); + virtual ~Altimeter (); + + virtual void init (); + virtual void bind (); + virtual void unbind (); + virtual void update (double dt); + +private: + + double _spin; + + SGPropertyNode_ptr _serviceable_node; + SGPropertyNode_ptr _setting_node; + SGPropertyNode_ptr _pressure_node; + SGPropertyNode_ptr _altitude_node; + + SGInterpTable * _altitude_table; + +}; + +#endif // __INSTRUMENTS_ALTIMETER_HXX diff --git a/src/Instrumentation/attitude_indicator.cxx b/src/Instrumentation/attitude_indicator.cxx index 87bd0f191..9b6626e87 100644 --- a/src/Instrumentation/attitude_indicator.cxx +++ b/src/Instrumentation/attitude_indicator.cxx @@ -3,6 +3,10 @@ // // This file is in the Public Domain and comes with no warranty. +// TODO: +// - tumble +// - better spin-up + #include "attitude_indicator.hxx" #include
diff --git a/src/Instrumentation/instrument_mgr.cxx b/src/Instrumentation/instrument_mgr.cxx index f330856e9..8025a8530 100644 --- a/src/Instrumentation/instrument_mgr.cxx +++ b/src/Instrumentation/instrument_mgr.cxx @@ -5,6 +5,7 @@ #include "instrument_mgr.hxx" +#include "altimeter.hxx" #include "attitude_indicator.hxx" @@ -25,6 +26,7 @@ void FGInstrumentMgr::init () { // TODO: replace with XML configuration + _instruments.push_back(new Altimeter); _instruments.push_back(new AttitudeIndicator); // Initialize the individual instruments diff --git a/src/Systems/Makefile.am b/src/Systems/Makefile.am index d254cde85..a4de5c996 100644 --- a/src/Systems/Makefile.am +++ b/src/Systems/Makefile.am @@ -1,8 +1,9 @@ noinst_LIBRARIES = libSystems.a libSystems_a_SOURCES = \ - system_mgr.cxx system_mgr.hxx \ - electrical.cxx electrical.hxx \ - vacuum.cxx vacuum.hxx + system_mgr.cxx system_mgr.hxx \ + electrical.cxx electrical.hxx \ + static.cxx static.hxx \ + vacuum.cxx vacuum.hxx INCLUDES = -I$(top_srcdir) -I$(top_srcdir)/src diff --git a/src/Systems/static.cxx b/src/Systems/static.cxx new file mode 100644 index 000000000..9e2b6aff1 --- /dev/null +++ b/src/Systems/static.cxx @@ -0,0 +1,48 @@ +// static.cxx - the static air system. +// Written by David Megginson, started 2002. +// +// This file is in the Public Domain and comes with no warranty. + +#include "static.hxx" +#include
+ + +StaticSystem::StaticSystem () +{ +} + +StaticSystem::~StaticSystem () +{ +} + +void +StaticSystem::init () +{ + _serviceable_node = fgGetNode("/systems/static[0]/serviceable", true); + _pressure_in_node = fgGetNode("/environment/pressure-inhg", true); + _pressure_out_node = fgGetNode("/systems/static[0]/pressure-inhg", true); +} + +void +StaticSystem::bind () +{ +} + +void +StaticSystem::unbind () +{ +} + +void +StaticSystem::update (double dt) +{ + if (_serviceable_node->getBoolValue()) { + double target = _pressure_in_node->getDoubleValue(); + double current = _pressure_out_node->getDoubleValue(); + double delta = target - current; + current += delta * dt; + _pressure_out_node->setDoubleValue(current); + } +} + +// end of static.cxx diff --git a/src/Systems/static.hxx b/src/Systems/static.hxx new file mode 100644 index 000000000..0ed405801 --- /dev/null +++ b/src/Systems/static.hxx @@ -0,0 +1,54 @@ +// static.hxx - the static air system. +// Written by David Megginson, started 2002. +// +// This file is in the Public Domain and comes with no warranty. + + +#ifndef __SYSTEMS_STATIC_HXX +#define __SYSTEMS_STATIC_HXX 1 + +#ifndef __cplusplus +# error This library requires C++ +#endif + +#include +#include
+ + +/** + * Model a static air system. + * + * Input properties: + * + * /environment/pressure-inhg + * /systems/static[0]/serviceable + * + * Output properties: + * + * /systems/static[0]/pressure-inhg + * + * TODO: support multiple static ports and specific locations + * TODO: support alternate air with errors + */ +class StaticSystem : public FGSubsystem +{ + +public: + + StaticSystem (); + virtual ~StaticSystem (); + + virtual void init (); + virtual void bind (); + virtual void unbind (); + virtual void update (double dt); + +private: + + SGPropertyNode_ptr _serviceable_node; + SGPropertyNode_ptr _pressure_in_node; + SGPropertyNode_ptr _pressure_out_node; + +}; + +#endif // __SYSTEMS_STATIC_HXX diff --git a/src/Systems/system_mgr.cxx b/src/Systems/system_mgr.cxx index 364eb9836..f30f88f71 100644 --- a/src/Systems/system_mgr.cxx +++ b/src/Systems/system_mgr.cxx @@ -6,6 +6,7 @@ #include "system_mgr.hxx" #include "electrical.hxx" +#include "static.hxx" #include "vacuum.hxx" @@ -27,6 +28,7 @@ FGSystemMgr::init () { // TODO: replace with XML configuration _systems.push_back(new FGElectricalSystem); + _systems.push_back(new StaticSystem); _systems.push_back(new VacuumSystem); // Initialize the individual systems