]> git.mxchange.org Git - flightgear.git/commitdiff
Added static port system and a new altimeter model connected to it.
authordavid <david>
Fri, 27 Sep 2002 18:27:58 +0000 (18:27 +0000)
committerdavid <david>
Fri, 27 Sep 2002 18:27:58 +0000 (18:27 +0000)
The static port uses the

  /systems/static/

property subtree, and the altimeter uses the

  /instrumentation/altimeter/

property subtree.

src/Instrumentation/Makefile.am
src/Instrumentation/altimeter.cxx [new file with mode: 0644]
src/Instrumentation/altimeter.hxx [new file with mode: 0644]
src/Instrumentation/attitude_indicator.cxx
src/Instrumentation/instrument_mgr.cxx
src/Systems/Makefile.am
src/Systems/static.cxx [new file with mode: 0644]
src/Systems/static.hxx [new file with mode: 0644]
src/Systems/system_mgr.cxx

index e66685e746716129d67b86c1d6f6af2938653bff..02707bb5727f2d9a441aa166173221051b199db0 100644 (file)
@@ -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 (file)
index 0000000..b545055
--- /dev/null
@@ -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 <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
diff --git a/src/Instrumentation/altimeter.hxx b/src/Instrumentation/altimeter.hxx
new file mode 100644 (file)
index 0000000..b653a4c
--- /dev/null
@@ -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 <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
index 87bd0f19145db288eaa8b02e9642ada3f43d2a65..9b6626e8785c6ab6ca3554cab605938dc6699eda 100644 (file)
@@ -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 <Main/fg_props.hxx>
 
index f330856e9d7cce7962086ac974bf17f89a678c50..8025a853079a0e2fe24fb81a8f6f4b97fd1ae602 100644 (file)
@@ -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
index d254cde857bf74c9bb12570cf7f19abd2c80b853..a4de5c996dc3f3e92ee04addbb036f0a029a9b4c 100644 (file)
@@ -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 (file)
index 0000000..9e2b6af
--- /dev/null
@@ -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 <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
diff --git a/src/Systems/static.hxx b/src/Systems/static.hxx
new file mode 100644 (file)
index 0000000..0ed4058
--- /dev/null
@@ -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 <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
index 364eb983655d5af4cd18132689cc7b8ac693416f..f30f88f711941eccea1f851d6c2e943e9ac58f60 100644 (file)
@@ -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