diff --git a/scripts/737_cruise_steady_turn_linearize.xml b/scripts/737_cruise_steady_turn_linearize.xml new file mode 100644 index 0000000000..cc06c4bfc3 --- /dev/null +++ b/scripts/737_cruise_steady_turn_linearize.xml @@ -0,0 +1,65 @@ + + + + + + This is a very simple script that trims the aircraft with running + engines, exports linearized equations, and runs out to 10 seconds. + + + + + + + simulation/notify-time-trigger + + + simulation/sim-time-sec le 0.1 + + + + + + + + + + simulation/sim-time-sec gt 0.1 + + + + + + + Output message at 5 second intervals + + propulsion/engine[0]/n2 + propulsion/engine[1]/n2 + propulsion/engine[0]/thrust-lbs + propulsion/engine[1]/thrust-lbs + position/h-agl-ft + velocities/vc-kts + velocities/vc-fps + velocities/vt-fps + attitude/phi-rad + attitude/theta-rad + attitude/psi-rad + + simulation/sim-time-sec >= simulation/notify-time-trigger + + + + + + diff --git a/src/FGFDMExec.cpp b/src/FGFDMExec.cpp index 60bfb17c1d..c2eb8e3c8d 100644 --- a/src/FGFDMExec.cpp +++ b/src/FGFDMExec.cpp @@ -60,6 +60,7 @@ INCLUDES #include "models/FGAuxiliary.h" #include "models/FGInput.h" #include "initialization/FGTrim.h" +#include "initialization/FGLinearization.h" #include "input_output/FGScript.h" #include "input_output/FGXMLFileRead.h" #include "initialization/FGInitialCondition.h" @@ -158,6 +159,7 @@ FGFDMExec::FGFDMExec(FGPropertyManager* root, std::shared_ptr fdmc Constructing = true; typedef int (FGFDMExec::*iPMF)(void) const; instance->Tie("simulation/do_simple_trim", this, (iPMF)0, &FGFDMExec::DoTrim); + instance->Tie("simulation/do_linearization", this, (iPMF)0, &FGFDMExec::DoLinearization); instance->Tie("simulation/reset", this, (iPMF)0, &FGFDMExec::ResetToInitialConditions); instance->Tie("simulation/disperse", this, &FGFDMExec::GetDisperse); instance->Tie("simulation/randomseed", this, (iPMF)&FGFDMExec::SRand, &FGFDMExec::SRand); @@ -1315,6 +1317,16 @@ void FGFDMExec::DoTrim(int mode) //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +void FGFDMExec::DoLinearization(int) +{ + double dt0 = this->GetDeltaT(); + FGLinearization lin(this); + lin.WriteScicoslab(); + this->Setdt(dt0); +} + +//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + void FGFDMExec::SRand(int sr) { RandomSeed = sr; diff --git a/src/FGFDMExec.h b/src/FGFDMExec.h index 98fad407b5..92fcdf16d4 100644 --- a/src/FGFDMExec.h +++ b/src/FGFDMExec.h @@ -475,6 +475,11 @@ class JSBSIM_API FGFDMExec : public FGJSBBase * - tNone */ void DoTrim(int mode); + /** Executes linearization with state-space output + * You must trim first to get an accurate state-space model + */ + void DoLinearization(int); + /// Disables data logging to all outputs. void DisableOutput(void) { Output->Disable(); } /// Enables data logging to all outputs. diff --git a/src/initialization/FGLinearization.cpp b/src/initialization/FGLinearization.cpp index 58562e7828..b8ac6fa78b 100644 --- a/src/initialization/FGLinearization.cpp +++ b/src/initialization/FGLinearization.cpp @@ -87,9 +87,10 @@ void FGLinearization::WriteScicoslab() const { } void FGLinearization::WriteScicoslab(std::string& path) const { - int width=10; + int width=20; + int precision=10; std::ofstream scicos(path.c_str()); - scicos.precision(10); + scicos.precision(precision); width=20; scicos << std::scientific << aircraft_name << ".x0=..\n" << std::setw(width) << x0 << ";\n" @@ -101,6 +102,8 @@ void FGLinearization::WriteScicoslab(std::string& path) const { << std::setw(width) << D << ");\n" << aircraft_name << ".tfm = ss2tf(" << aircraft_name << ".sys);\n" << std::endl; + scicos.close(); + } } // JSBSim