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
--- /dev/null
+// 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 <simgear/math/interpolater.hxx>
+
+#include "altimeter.hxx"
+#include <Main/fg_props.hxx>
+
+
+// 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
--- /dev/null
+// 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 <simgear/misc/props.hxx>
+#include <Main/fgfs.hxx>
+
+
+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
//
// This file is in the Public Domain and comes with no warranty.
+// TODO:
+// - tumble
+// - better spin-up
+
#include "attitude_indicator.hxx"
#include <Main/fg_props.hxx>
#include "instrument_mgr.hxx"
+#include "altimeter.hxx"
#include "attitude_indicator.hxx"
FGInstrumentMgr::init ()
{
// TODO: replace with XML configuration
+ _instruments.push_back(new Altimeter);
_instruments.push_back(new AttitudeIndicator);
// Initialize the individual instruments
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
--- /dev/null
+// 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 <Main/fg_props.hxx>
+
+
+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
--- /dev/null
+// 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 <simgear/misc/props.hxx>
+#include <Main/fgfs.hxx>
+
+
+/**
+ * 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
#include "system_mgr.hxx"
#include "electrical.hxx"
+#include "static.hxx"
#include "vacuum.hxx"
{
// TODO: replace with XML configuration
_systems.push_back(new FGElectricalSystem);
+ _systems.push_back(new StaticSystem);
_systems.push_back(new VacuumSystem);
// Initialize the individual systems