1
0
Fork 0

YASIM refactoring of Wing class

This commit is contained in:
Henning Stahlke 2017-06-13 21:15:46 +02:00
parent 3ac90ee866
commit 95ee37c9b9
3 changed files with 77 additions and 89 deletions

View file

@ -308,7 +308,8 @@ void FGFDM::startElement(const char* name, const XMLAttributes &atts)
#undef p2
r->setInUse();
} else if(eq(name, "wing")) {
_airplane.setWing(parseWing(a, name, &_airplane));
Wing *wing = parseWing(a, name, &_airplane);
_airplane.setWing(wing);
} else if(eq(name, "hstab")) {
_airplane.setTail(parseWing(a, name, &_airplane));
} else if(eq(name, "vstab") || eq(name, "mstab")) {
@ -537,23 +538,30 @@ void FGFDM::startElement(const char* name, const XMLAttributes &atts)
w->setStall(attrf(a, "aoa") * DEG2RAD);
w->setStallWidth(attrf(a, "width", 2) * DEG2RAD);
w->setStallPeak(attrf(a, "peak", 1.5));
} else if(eq(name, "flap0")) {
((Wing*)_currObj)->setFlap0Params(attrf(a, "start"), attrf(a, "end"),
attrf(a, "lift"), attrf(a, "drag"));
} else if(eq(name, "flap1")) {
((Wing*)_currObj)->setFlap1Params(attrf(a, "start"), attrf(a, "end"),
attrf(a, "lift"), attrf(a, "drag"));
} else if(eq(name, "slat")) {
((Wing*)_currObj)->setSlatParams(attrf(a, "start"), attrf(a, "end"),
attrf(a, "aoa"), attrf(a, "drag"));
} else if(eq(name, "spoiler")) {
((Wing*)_currObj)->setSpoilerParams(attrf(a, "start"), attrf(a, "end"),
attrf(a, "lift"), attrf(a, "drag"));
/* } else if(eq(name, "collective")) {
((Rotor*)_currObj)->setcollective(attrf(a, "min"), attrf(a, "max"));
} else if(eq(name, "cyclic")) {
((Rotor*)_currObj)->setcyclic(attrf(a, "ail"), attrf(a, "ele"));
*/
} else if(eq(name, "flap0") || eq(name, "flap1") || eq(name, "spoiler") || eq(name, "slat")) {
FlapParams fp;
fp.start = attrf(a, "start");
fp.end = attrf(a, "end");
if (eq(name, "slat")) {
fp.aoa = attrf(a, "aoa");
}
else {
fp.lift = attrf(a, "lift");
}
fp.drag = attrf(a, "drag");
if (eq(name, "flap0")) {
((Wing*)_currObj)->setFlapParams(WING_FLAP0, fp);
}
if (eq(name, "flap1")) {
((Wing*)_currObj)->setFlapParams(WING_FLAP1, fp);
}
if (eq(name, "spoiler")) {
((Wing*)_currObj)->setFlapParams(WING_SPOILER, fp);
}
if (eq(name, "slat")) {
((Wing*)_currObj)->setFlapParams(WING_SLAT, fp);
}
} else if(eq(name, "actionpt")) {
v[0] = attrf(a, "x");
v[1] = attrf(a, "y");
@ -807,14 +815,19 @@ Wing* FGFDM::parseWing(XMLAttributes* a, const char* type, Version * version)
defDihed = 90;
mirror = false;
}
float base[3];
base[0] = attrf(a, "x");
base[1] = attrf(a, "y");
base[2] = attrf(a, "z");
float isSection = attrb(a, "section");
float base[3] {0,0,0};
float chord {0};
if (!isSection) {
base[0] = attrf(a, "x");
base[1] = attrf(a, "y");
base[2] = attrf(a, "z");
chord = attrf(a, "chord");
}
float length = attrf(a, "length");
float chord = attrf(a, "chord");
// optional attributes (with defaults)
float sweep = attrf(a, "sweep", 0) * DEG2RAD;
float taper = attrf(a, "taper", 1);
float dihedral = attrf(a, "dihedral", defDihed) * DEG2RAD;
@ -831,7 +844,7 @@ Wing* FGFDM::parseWing(XMLAttributes* a, const char* type, Version * version)
}
Wing* w = new Wing(version, mirror, base, chord, length,
taper, sweep, dihedral, twist);
taper, sweep, dihedral, twist);
w->setIncidence(incidence);
w->setCamber(camber);

View file

@ -39,36 +39,9 @@ void Wing::setIncidence(float incidence)
((SurfRec*)_surfs.get(i))->surface->setIncidence(incidence);
}
void Wing::setFlap0Params(float start, float end, float lift, float drag)
void Wing::setFlapParams(WingFlaps i, FlapParams fp)
{
_flap0Start = start;
_flap0End = end;
_flap0Lift = lift;
_flap0Drag = drag;
}
void Wing::setFlap1Params(float start, float end, float lift, float drag)
{
_flap1Start = start;
_flap1End = end;
_flap1Lift = lift;
_flap1Drag = drag;
}
void Wing::setSlatParams(float start, float end, float aoa, float drag)
{
_slatStart = start;
_slatEnd = end;
_slatAoA = aoa;
_slatDrag = drag;
}
void Wing::setSpoilerParams(float start, float end, float lift, float drag)
{
_spoilerStart = start;
_spoilerEnd = end;
_spoilerLift = lift;
_spoilerDrag = drag;
_flapParams[i] = fp;
}
void Wing::setFlap0Pos(float lval, float rval)
@ -201,10 +174,14 @@ void Wing::compile()
// segments.
const int NUM_BOUNDS {10};
float bounds[NUM_BOUNDS];
bounds[0] = _flap0Start; bounds[1] = _flap0End;
bounds[2] = _flap1Start; bounds[3] = _flap1End;
bounds[4] = _spoilerStart; bounds[5] = _spoilerEnd;
bounds[6] = _slatStart; bounds[7] = _slatEnd;
bounds[0] = _flapParams[WING_FLAP0].start;
bounds[1] = _flapParams[WING_FLAP0].end;
bounds[2] = _flapParams[WING_FLAP1].start;
bounds[3] = _flapParams[WING_FLAP1].end;
bounds[4] = _flapParams[WING_SPOILER].start;
bounds[5] = _flapParams[WING_SPOILER].end;
bounds[6] = _flapParams[WING_SLAT].start;
bounds[7] = _flapParams[WING_SLAT].end;
//and don't forget the root and the tip of the wing itself
bounds[8] = 0; bounds[9] = 1;
@ -243,10 +220,10 @@ void Wing::compile()
float mid = (start+end)/2;
bool hasFlap0=0, hasFlap1=0, hasSlat=0, hasSpoiler=0;
if(_flap0Start < mid && mid < _flap0End) hasFlap0 = 1;
if(_flap1Start < mid && mid < _flap1End) hasFlap1 = 1;
if(_slatStart < mid && mid < _slatEnd) hasSlat = 1;
if(_spoilerStart < mid && mid < _spoilerEnd) hasSpoiler = 1;
if(_flapParams[WING_FLAP0].start < mid && mid < _flapParams[WING_FLAP0].end) hasFlap0 = 1;
if(_flapParams[WING_FLAP1].start < mid && mid < _flapParams[WING_FLAP1].end) hasFlap1 = 1;
if(_flapParams[WING_SLAT].start < mid && mid < _flapParams[WING_SLAT].end) hasSlat = 1;
if(_flapParams[WING_SPOILER].start < mid && mid < _flapParams[WING_SPOILER].end) hasSpoiler = 1;
// FIXME: Should probably detect an error here if both flap0
// and flap1 are set. Right now flap1 overrides.
@ -353,10 +330,10 @@ Surface* Wing::newSurface(float* pos, float* orient, float chord,
s->setStallWidth(i, 0.01);
}
if(hasFlap0) s->setFlapParams(_flap0Lift, _flap0Drag);
if(hasFlap1) s->setFlapParams(_flap1Lift, _flap1Drag);
if(hasSlat) s->setSlatParams(_slatAoA, _slatDrag);
if(hasSpoiler) s->setSpoilerParams(_spoilerLift, _spoilerDrag);
if(hasFlap0) s->setFlapParams(_flapParams[WING_FLAP0].lift, _flapParams[WING_FLAP0].drag);
if(hasFlap1) s->setFlapParams(_flapParams[WING_FLAP1].lift, _flapParams[WING_FLAP1].drag);
if(hasSlat) s->setSlatParams(_flapParams[WING_SLAT].aoa, _flapParams[WING_SLAT].drag);
if(hasSpoiler) s->setSpoilerParams(_flapParams[WING_SPOILER].lift, _flapParams[WING_SPOILER].drag);
if(hasFlap0) _flap0Surfs.add(s);
if(hasFlap1) _flap1Surfs.add(s);

View file

@ -9,8 +9,24 @@ namespace yasim {
class Surface;
struct FlapParams {
float start {0};
float end {0};
float lift {0};
float drag {0};
float aoa {0};
};
enum WingFlaps {
WING_FLAP0,
WING_FLAP1,
WING_SLAT,
WING_SPOILER
};
// FIXME: need to handle "inverted" controls for mirrored wings.
class Wing {
public:
Wing(Version *ver, bool mirror, float* base, float chord, float length,
float taper = 1, float sweep = 0, float dihedral = 0, float twist = 0);
@ -47,10 +63,7 @@ public:
void setInducedDrag(float drag) { _inducedDrag = drag; }
void setFlap0Params(float start, float end, float lift, float drag);
void setFlap1Params(float start, float end, float lift, float drag);
void setSpoilerParams(float start, float end, float lift, float drag);
void setSlatParams(float start, float end, float aoa, float drag);
void setFlapParams(WingFlaps i, FlapParams fp);
// Set the control axes for the sub-surfaces
void setFlap0Pos(float lval, float rval);
@ -88,6 +101,7 @@ public:
void setLiftRatio(float ratio);
float getLiftRatio() const { return _liftRatio; }
private:
void interp(const float* v1, const float* v2, const float frac, float* out);
Surface* newSurface(float* pos, float* orient, float chord,
@ -97,6 +111,7 @@ private:
void calculateSpan();
void calculateMAC();
float calculateSweepAngleLeadingEdge();
void addSurface(Surface* s, float weight, float twist);
struct SurfRec { Surface * surface; float weight; };
@ -141,25 +156,8 @@ private:
float _dragScale {1};
float _liftRatio {1};
float _flap0Start {0};
float _flap0End {0};
float _flap0Lift {0};
float _flap0Drag {0};
FlapParams _flapParams[sizeof(WingFlaps)];
float _flap1Start {0};
float _flap1End {0};
float _flap1Lift {0};
float _flap1Drag {0};
float _spoilerStart {0};
float _spoilerEnd {0};
float _spoilerLift {0};
float _spoilerDrag {0};
float _slatStart {0};
float _slatEnd {0};
float _slatAoA {0};
float _slatDrag {0};
};
}; // namespace yasim