]> git.mxchange.org Git - flightgear.git/commitdiff
Added a <solve-weight> subtag of the approach/cruise parameters that can
authorandy <andy>
Wed, 18 Feb 2004 15:36:35 +0000 (15:36 +0000)
committerandy <andy>
Wed, 18 Feb 2004 15:36:35 +0000 (15:36 +0000)
be used to set the variable weights to specific values for the solution.

src/FDM/YASim/Airplane.cpp
src/FDM/YASim/Airplane.hpp
src/FDM/YASim/FGFDM.cpp

index bb95ae9bada26178b5d591789988e679551cec43..ba1674b0cc7d926452d26c99f2939ec5921d060f 100644 (file)
@@ -66,6 +66,8 @@ Airplane::~Airplane()
        delete (Surface*)_surfs.get(i);    
     for(i=0; i<_contacts.size(); i++)
         delete[] (float*)_contacts.get(i);
+    for(i=0; i<_solveWeights.size(); i++)
+        delete[] (SolveWeight*)_solveWeights.get(i);
 }
 
 void Airplane::iterate(float dt)
@@ -212,6 +214,15 @@ void Airplane::addCruiseControl(int control, float val)
     _cruiseControls.add(c);
 }
 
+void Airplane::addSolutionWeight(bool approach, int idx, float wgt)
+{
+    SolveWeight* w = new SolveWeight();
+    w->approach = approach;
+    w->idx = idx;
+    w->wgt = wgt;
+    _solveWeights.add(w);
+}
+
 int Airplane::numTanks()
 {
     return _tanks.size();
@@ -755,6 +766,18 @@ void Airplane::stabilizeThrust()
        _model.getThruster(i)->stabilize();
 }
 
+void Airplane::setupWeights(bool isApproach)
+{
+    int i;
+    for(i=0; i<_weights.size(); i++)
+        setWeight(i, 0);
+    for(i=0; i<_solveWeights.size(); i++) {
+        SolveWeight* w = (SolveWeight*)_solveWeights.get(i);
+        if(w->approach == isApproach)
+            setWeight(w->idx, w->wgt);
+    }
+}
+
 void Airplane::runCruise()
 {
     setupState(_cruiseAoA, _cruiseSpeed, &_cruiseState);
@@ -777,6 +800,7 @@ void Airplane::runCruise()
     Math::vmul33(_cruiseState.orient, wind, wind);
  
     setFuelFraction(_cruiseFuel);
+    setupWeights(false);
    
     // Set up the thruster parameters and iterate until the thrust
     // stabilizes.
@@ -818,9 +842,10 @@ void Airplane::runApproach()
     Math::mul3(-1, _approachState.v, wind);
     Math::vmul33(_approachState.orient, wind, wind);
     
-    // Approach is by convention at 20% tank capacity
     setFuelFraction(_approachFuel);
 
+    setupWeights(true);
+
     // Run the thrusters until they get to a stable setting.  FIXME:
     // this is lots of wasted work.
     for(i=0; i<_thrusters.size(); i++) {
index bc35a9b30b939a5dcf3d1b1935bfe2030a7cdcd9..763e8d5ead84e82a81694713a191cc09b6ef2736 100644 (file)
@@ -55,6 +55,8 @@ public:
     void addApproachControl(int control, float val);
     void addCruiseControl(int control, float val);
 
+    void addSolutionWeight(bool approach, int idx, float wgt);
+
     int numGear();
     Gear* getGear(int g);
 
@@ -86,6 +88,7 @@ private:
                       int handle; float cg[3]; float mass; };
     struct Control { int control; float val; };
     struct WeightRec { int handle; Surface* surf; };
+    struct SolveWeight { bool approach; int idx; float wgt; };
 
     void runCruise();
     void runApproach();
@@ -104,6 +107,7 @@ private:
     void compileContactPoints();
     float normFactor(float f);
     void updateGearState();
+    void setupWeights(bool isApproach);
 
     Model _model;
     ControlMap _controls;
@@ -127,6 +131,8 @@ private:
 
     Vector _rotors;
 
+    Vector _solveWeights;
+
     Vector _cruiseControls;
     State _cruiseState;
     float _cruiseP;
index f1d489708fad02ab07130e577935cf7179e9e3af..234a25c1afecc43f9bae3b15ed6743c511243956 100644 (file)
@@ -125,6 +125,10 @@ void FGFDM::startElement(const char* name, const XMLAttributes &atts)
        float alt = attrf(a, "alt") * FT2M;
        _airplane.setCruise(spd, alt, attrf(a, "fuel", 0.5));
        _cruiseCurr = true;
+    } else if(eq(name, "solve-weight")) {
+        int idx = attri(a, "idx");
+        float wgt = attrf(a, "weight") * LBS2KG;
+        _airplane.addSolutionWeight(!_cruiseCurr, idx, wgt);
     } else if(eq(name, "cockpit")) {
        v[0] = attrf(a, "x");
        v[1] = attrf(a, "y");