]> git.mxchange.org Git - flightgear.git/commitdiff
Refactoring in preparation to add a turbine engine to YASim. The
authorandy <andy>
Fri, 30 Apr 2004 19:06:29 +0000 (19:06 +0000)
committerandy <andy>
Fri, 30 Apr 2004 19:06:29 +0000 (19:06 +0000)
PistonEngine class has grown an "Engine" superclass.  Some other stuff
moved around too, and I cleaned up some property naming while I was in
there.  This hasn't been tested very thorougly, hopefully I didn't
break anything.

src/FDM/YASim/ControlMap.cpp
src/FDM/YASim/Engine.hpp [new file with mode: 0644]
src/FDM/YASim/FGFDM.cpp
src/FDM/YASim/PistonEngine.cpp
src/FDM/YASim/PistonEngine.hpp
src/FDM/YASim/PropEngine.cpp
src/FDM/YASim/PropEngine.hpp
src/FDM/YASim/Thruster.hpp
src/FDM/YASim/YASim.cxx
src/FDM/YASim/yasim-test.cpp

index 9854cac28dc3a2dc2d37071d58416e42872e2f29..51f5275941fa0e1af4b0e7d601e9b5eecad091e6 100644 (file)
@@ -206,7 +206,7 @@ void ControlMap::applyControls(float dt)
         case ROTORENGINEON: ((Rotor*)obj)->setEngineOn((int)lval); break;
        case REVERSE_THRUST: ((Jet*)obj)->setReverse(lval != 0);   break;
        case BOOST:
-           ((Thruster*)obj)->getPistonEngine()->setBoost(lval);
+           ((PistonEngine*)((Thruster*)obj)->getEngine())->setBoost(lval);
            break;
        }
     }
diff --git a/src/FDM/YASim/Engine.hpp b/src/FDM/YASim/Engine.hpp
new file mode 100644 (file)
index 0000000..edbe15d
--- /dev/null
@@ -0,0 +1,45 @@
+#ifndef _ENGINE_HPP
+#define _ENGINE_HPP
+
+namespace yasim {
+
+class PistonEngine;
+
+//
+// Interface for the "Engine" part of a PropEngine object.  This is a
+// virtual class, intended to be implemented by stuff like
+// PistonEngine and TurbineEngine, and maybe exotics like
+// SolarElectricEngine, etc...
+//
+
+class Engine {
+public:
+    virtual PistonEngine* isPistonEngine() { return 0; }
+
+    void setThrottle(float throttle) { _throttle = throttle; }
+    void setStarter(bool starter) { _starter = starter; }
+    void setMagnetos(int magnetos) { _magnetos = magnetos; }
+    void setMixture(float mixture) { _mixture = mixture; }
+    void setBoost(float boost) { _boost = boost; }
+    void setFuelState(bool hasFuel) { _fuel = hasFuel; }
+    void setRunning(bool r) { _running = r; }
+
+    bool isRunning() { return _running; }
+    virtual bool isCranking() { return false; }
+
+    virtual void calc(float pressure, float temp, float speed) = 0;
+    virtual float getTorque() = 0;
+    virtual float getFuelFlow() = 0;
+
+protected:
+    float _throttle;
+    bool _starter; // true=engaged, false=disengaged
+    int _magnetos; // 0=off, 1=right, 2=left, 3=both
+    float _mixture;
+    float _boost;
+    bool _fuel;
+    bool _running;
+};
+
+}; // namespace yasim
+#endif // _ENGINE_HPP
index 4524c35b49733b16d86ea7353afcdfd9a4e612ab..6454f848e5f2d6695046ec4cf29d0e5bd01c6156 100644 (file)
@@ -3,6 +3,7 @@
 
 #include <Main/fg_props.hxx>
 
+#include "Math.hpp"
 #include "Jet.hpp"
 #include "SimpleJet.hpp"
 #include "Gear.hpp"
@@ -436,41 +437,43 @@ void FGFDM::setOutputProperties()
     for(i=0; i<_thrusters.size(); i++) {
        EngRec* er = (EngRec*)_thrusters.get(i);
         Thruster* t = er->eng;
+        SGPropertyNode * node = fgGetNode("engines/engine", i, true);
 
-       sprintf(buf, "%s/fuel-flow-gph", er->prefix);
-        fgSetFloat(buf, (t->getFuelFlow()/fuelDensity) * 3600 * CM2GALS);
+        // Set: running, cranking, prop-thrust, max-hp, power-pct
+       node->setBoolValue("running", t->isRunning());
+       node->setBoolValue("cranking", t->isCranking());
 
-       if(t->getPropEngine()) {
-            PropEngine* p = t->getPropEngine();
-
-            sprintf(buf, "%s/rpm", er->prefix);
-            fgSetFloat(buf, p->getOmega() / RPM2RAD);
-        }
+        float tmp[3];
+        t->getThrust(tmp);
+        float lbs = Math::mag3(tmp) * (KG2LBS/9.8);
+       node->setFloatValue("prop-thrust", lbs); // Deprecated name
+       node->setFloatValue("thrust-lbs", lbs);
 
-        if(t->getPistonEngine()) {
-            PistonEngine* p = t->getPistonEngine();
-           
-            sprintf(buf, "%s/mp-osi", er->prefix);
-           fgSetFloat(buf, p->getMP() * (1/INHG2PA));
+        node->setFloatValue("fuel-flow-gph",
+                            (t->getFuelFlow()/fuelDensity) * 3600 * CM2GALS);
 
-           sprintf(buf, "%s/egt-degf", er->prefix);
-           fgSetFloat(buf, p->getEGT() * K2DEGF + K2DEGFOFFSET);
+       if(t->getPropEngine()) {
+            PropEngine* p = t->getPropEngine();
+            node->setFloatValue("rpm", p->getOmega() * (1/RPM2RAD));
+            
+            if(p->getEngine()->isPistonEngine()) {
+                PistonEngine* pe = p->getEngine()->isPistonEngine();
+                node->setFloatValue("mp-osi", pe->getMP() * (1/INHG2PA));
+                node->setFloatValue("mp-inhg", pe->getMP() * (1/INHG2PA));
+                node->setFloatValue("egt-degf",
+                                    pe->getEGT() * K2DEGF + K2DEGFOFFSET);
+//             } else if(p->isTurbineEngine()) {
+//                 TurbineEngine* te = p->isTurbineEngine();
+            }
         }
 
         if(t->getJet()) {
             Jet* j = t->getJet();
-
-            sprintf(buf, "%s/n1", er->prefix);
-            fgSetFloat(buf, j->getN1());
-
-            sprintf(buf, "%s/n2", er->prefix);
-            fgSetFloat(buf, j->getN2());
-
-            sprintf(buf, "%s/epr", er->prefix);
-            fgSetFloat(buf, j->getEPR());
-
-            sprintf(buf, "%s/egt-degf", er->prefix);
-            fgSetFloat(buf, j->getEGT() * K2DEGF + K2DEGFOFFSET);
+            node->setFloatValue("n1", j->getN1());
+            node->setFloatValue("n2", j->getN2());
+            node->setFloatValue("epr", j->getEPR());
+            node->setFloatValue("egr-degf",
+                                j->getEGT() * K2DEGF + K2DEGFOFFSET);
         }
     }
 }
index e88178fb20c0568ade2e4a18c60a6cb880ae16ff..938909c62725cfa220f5e2568b5ed127f474bde7 100644 (file)
@@ -68,41 +68,6 @@ float PistonEngine::getMaxPower()
     return _power0;
 }
 
-void PistonEngine::setThrottle(float t)
-{
-    _throttle = t;
-}
-
-void PistonEngine::setRunning(bool r)
-{
-    _running = r;
-}
-
-void PistonEngine::setStarter(bool s)
-{
-    _cranking = s;
-}
-
-void PistonEngine::setMagnetos(int m)
-{
-    _magnetos = m;
-}
-
-void PistonEngine::setMixture(float m)
-{
-    _mixture = m;
-}
-
-void PistonEngine::setBoost(float boost)
-{
-    _boost = boost;
-}
-
-bool PistonEngine::isRunning()
-{
-    return _running;
-}
-
 bool PistonEngine::isCranking()
 {
     return _cranking;
index bd7ffb3629cd5699db761a465de11a7dcd0b3f5d..96aac119041489ab44841420cdb2e63aeaf24fc6 100644 (file)
@@ -1,35 +1,28 @@
 #ifndef _PISTONENGINE_HPP
 #define _PISTONENGINE_HPP
 
+#include "Engine.hpp"
+
 namespace yasim {
 
-class PistonEngine {
+class PistonEngine : public Engine {
 public:
+    virtual PistonEngine* isPistonEngine() { return this; }
+
     // Initializes an engine from known "takeoff" parameters.
     PistonEngine(float power, float spd);
     void setTurboParams(float mul, float maxMP);
     void setDisplacement(float d);
     void setCompression(float c);
 
-    void setThrottle(float throttle);
-    void setStarter(bool starter);
-    void setMagnetos(int magnetos);
-    void setMixture(float mixture);
-    void setBoost(float boost); // fraction of turbo-mul used
-    void setFuelState(bool hasFuel) { _fuel = hasFuel; }
-
-    // For solver use
-    void setRunning(bool r);
-
-    float getMaxPower(); // max sea-level power
-
-    void calc(float pressure, float temp, float speed);
-    bool isRunning();
     bool isCranking();
-    float getTorque();
-    float getFuelFlow();
     float getMP();
     float getEGT();
+    float getMaxPower(); // max sea-level power
+
+    virtual void calc(float pressure, float temp, float speed);
+    virtual float getTorque();
+    virtual float getFuelFlow();
 
 private:
     // Static configuration:
@@ -43,16 +36,7 @@ private:
     float _displacement; // piston stroke volume
     float _compression;  // compression ratio (>1)
 
-    // Runtime settables:
-    float _throttle;
-    bool _starter; // true=engaged, false=disengaged
-    int _magnetos; // 0=off, 1=right, 2=left, 3=both
-    float _mixture;
-    float _boost;
-    bool _fuel;
-
     // Runtime state/output:
-    bool _running;
     bool _cranking;
     float _mp;
     float _torque;
index f5f90236a1c28fc0d58bce2b39d7b77b07dbb620..9b7afdc67dc7d9fcc143eb87087cb79db7a2bdba 100644 (file)
@@ -1,10 +1,10 @@
 #include "Math.hpp"
 #include "Propeller.hpp"
-#include "PistonEngine.hpp"
+#include "Engine.hpp"
 #include "PropEngine.hpp"
 namespace yasim {
 
-PropEngine::PropEngine(Propeller* prop, PistonEngine* eng, float moment)
+PropEngine::PropEngine(Propeller* prop, Engine* eng, float moment)
 {
     // Start off at 500rpm, because the start code doesn't exist yet
     _omega = 52.3f;
index 603dee1629c91512ea2a02a008666ac56a0dc8a3..92ad8549ec545be06a1be32902bb64d26a0cac6b 100644 (file)
@@ -6,11 +6,11 @@
 namespace yasim {
 
 class Propeller;
-class PistonEngine;
+class Engine;
 
 class PropEngine : public Thruster {
 public:
-    PropEngine(Propeller* prop, PistonEngine* eng, float moment);
+    PropEngine(Propeller* prop, Engine* eng, float moment);
     virtual ~PropEngine();
 
     void setMagnetos(int magnetos);
@@ -20,7 +20,7 @@ public:
     void setGearRatio(float ratio) { _gearRatio = ratio; }
 
     virtual PropEngine* getPropEngine() { return this; }
-    virtual PistonEngine* getPistonEngine() { return _eng; }
+    virtual Engine* getEngine() { return _eng; }
     virtual Propeller* getPropeller() { return _prop; }
 
     // Dynamic output
@@ -42,7 +42,7 @@ public:
 private:
     float _moment;
     Propeller* _prop;
-    PistonEngine* _eng;
+    Engine* _eng;
 
     bool _variable;
     int _magnetos;  // 0=off, 1=right, 2=left, 3=both
index 7d6e0c9cdd65d05e31913021ff4ce06b7ed1aece..c022ebaa424b563d8839c25b4aee884c01c1f6be 100644 (file)
@@ -6,7 +6,7 @@ namespace yasim {
 class Jet;
 class PropEngine;
 class Propeller;
-class PistonEngine;
+class Engine;
 
 class Thruster {
 public:
@@ -19,7 +19,7 @@ public:
     virtual Jet* getJet() { return 0; }
     virtual PropEngine* getPropEngine() { return 0; }
     virtual Propeller* getPropeller() { return 0; }
-    virtual PistonEngine* getPistonEngine() { return 0; }
+    virtual Engine* getEngine() { return 0; }
     
     // Static data
     void getPosition(float* out);
index 8e1e1e96b59634bcf8e2f72ae52ccca8be6881d3..9f7594b2e7c3b2cb34af00b70ad975157f16b6c1 100644 (file)
@@ -443,28 +443,4 @@ void YASim::copyFromYASim()
        node->setBoolValue("wow", g->getCompressFraction() != 0);
        node->setFloatValue("compression-norm", g->getCompressFraction());
     }
-
-    for(i=0; i<model->numThrusters(); i++) {
-        SGPropertyNode * node = fgGetNode("engines/engine", i, true);
-        Thruster* t = model->getThruster(i);
-
-       node->setBoolValue("running", t->isRunning());
-       node->setBoolValue("cranking", t->isCranking());
-
-        float tmp[3];
-        t->getThrust(tmp);
-       node->setDoubleValue("prop-thrust", Math::mag3(tmp) * KG2LBS / 9.8);
-
-        PropEngine* pe = t->getPropEngine();
-        if(pe) {
-           node->setDoubleValue("rpm", pe->getOmega() * RAD2RPM);
-
-            pe->getTorque(tmp);
-            float power = Math::mag3(tmp) * pe->getOmega();
-            float maxPower = pe->getPistonEngine()->getMaxPower();
-
-           node->setDoubleValue("max-hp", maxPower * W2HP);
-           node->setDoubleValue("power-pct", 100 * power/maxPower);
-        }
-    }
 }
index faf7520e49086f1a534c0b77ecdc85697391a636..7f578b6a9665063f4320bbb9009e15b454398db1 100644 (file)
@@ -13,6 +13,7 @@ bool fgSetFloat (const char * name, float val) { return false; }
 bool fgSetBool(char const * name, bool val) { return false; }
 bool fgGetBool(char const * name, bool def) { return false; }
 SGPropertyNode* fgGetNode (const char * path, bool create) { return 0; }
+SGPropertyNode* fgGetNode (const char * path, int i, bool create) { return 0; }
 float fgGetFloat (const char * name, float defaultValue) { return 0; }
 float fgGetDouble (const char * name, double defaultValue) { return 0; }
 float fgSetDouble (const char * name, double defaultValue) { return 0; }