From ac93c22545863e58eb2b4f5dad0e2c5313758d5f Mon Sep 17 00:00:00 2001 From: andy Date: Wed, 11 Dec 2002 22:58:47 +0000 Subject: [PATCH] Put in some (currently compile-time) tuning for the solver threshold. A recent change resulted in the Piper Cub oscillating about its correct solution. --- src/FDM/YASim/Airplane.cpp | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/src/FDM/YASim/Airplane.cpp b/src/FDM/YASim/Airplane.cpp index 04d1b87ef..05c64df31 100644 --- a/src/FDM/YASim/Airplane.cpp +++ b/src/FDM/YASim/Airplane.cpp @@ -929,9 +929,16 @@ void Airplane::solve() applyDragFactor(dragFactor); applyLiftRatio(liftFactor); + // Solver threshold. How close to the solution are we trying + // to get? Trying too hard can result in oscillations about + // the correct solution, which is bad. Stick this in as a + // compile time constant for now, and consider making it + // settable per-model. + float STHRESH = 1.6; + // DON'T do the following until the above are sane - if(normFactor(dragFactor) > 1.0001 - || normFactor(liftFactor) > 1.0001) + if(normFactor(dragFactor) > STHRESH*1.0001 + || normFactor(liftFactor) > STHRESH*1.0001) { continue; } @@ -943,13 +950,13 @@ void Airplane::solve() _cruiseAoA = clamp(_cruiseAoA, -0.175f, 0.175f); _tailIncidence = clamp(_tailIncidence, -0.175f, 0.175f); - if(abs(xforce/_cruiseWeight) < 0.0001 && - abs(alift/_approachWeight) < 0.0001 && - abs(aoaDelta) < .000017 && - abs(tailDelta) < .000017) + if(abs(xforce/_cruiseWeight) < STHRESH*0.0001 && + abs(alift/_approachWeight) < STHRESH*0.0001 && + abs(aoaDelta) < STHRESH*.000017 && + abs(tailDelta) < STHRESH*.000017) { // If this finaly value is OK, then we're all done - if(abs(elevDelta) < 0.0001) + if(abs(elevDelta) < STHRESH*0.0001) break; // Otherwise, adjust and do the next iteration -- 2.39.5