1
0
Fork 0

Added a <solve-weight> subtag of the approach/cruise parameters that can

be used to set the variable weights to specific values for the solution.
This commit is contained in:
andy 2004-02-18 15:36:35 +00:00
parent 7de581bf8f
commit 8d1698d21a
3 changed files with 36 additions and 1 deletions

View 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++) {

View 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;

View 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");