19 #include "FGInitialCondition.h" 20 #include "FGLinearization.h" 27 FGLinearization::FGLinearization(FGFDMExec * fdm,
int mode)
29 std::cout <<
"\nlinearization: " << std::endl;
30 std::clock_t time_start=clock(), time_linDone;
33 ss.x.add(
new FGStateSpace::Vt);
34 ss.x.add(
new FGStateSpace::Alpha);
35 ss.x.add(
new FGStateSpace::Theta);
36 ss.x.add(
new FGStateSpace::Q);
39 FGEngine * engine0 = fdm->GetPropulsion()->GetEngine(0);
40 FGThruster * thruster0 = engine0->GetThruster();
42 if (thruster0->GetType()==FGThruster::ttPropeller)
44 ss.x.add(
new FGStateSpace::Rpm0);
47 int numEngines = fdm->GetPropulsion()->GetNumEngines();
48 if (numEngines>1) ss.x.add(
new FGStateSpace::Rpm1);
49 if (numEngines>2) ss.x.add(
new FGStateSpace::Rpm2);
50 if (numEngines>3) ss.x.add(
new FGStateSpace::Rpm3);
52 std::cerr <<
"more than 4 engines not currently handled" << std::endl;
55 ss.x.add(
new FGStateSpace::Beta);
56 ss.x.add(
new FGStateSpace::Phi);
57 ss.x.add(
new FGStateSpace::P);
58 ss.x.add(
new FGStateSpace::Psi);
59 ss.x.add(
new FGStateSpace::R);
60 ss.x.add(
new FGStateSpace::Latitude);
61 ss.x.add(
new FGStateSpace::Longitude);
62 ss.x.add(
new FGStateSpace::Alt);
64 ss.u.add(
new FGStateSpace::ThrottleCmd);
65 ss.u.add(
new FGStateSpace::DaCmd);
66 ss.u.add(
new FGStateSpace::DeCmd);
67 ss.u.add(
new FGStateSpace::DrCmd);
72 std::vector< std::vector<double> > A,B,C,D;
73 std::vector<double> x0 = ss.x.get(), u0 = ss.u.get();
74 std::vector<double> y0 = x0;
75 std::cout << ss << std::endl;
77 ss.linearize(x0,u0,y0,A,B,C,D);
80 std::cout.precision(3);
84 <<
"\nA=\n" << std::setw(width) << A
85 <<
"\nB=\n" << std::setw(width) << B
86 <<
"\nC=\n" << std::setw(width) << C
87 <<
"\n* note: C should be identity, if not, indicates problem with model" 88 <<
"\nD=\n" << std::setw(width) << D
92 std::string aircraft = fdm->GetAircraft()->GetAircraftName();
93 std::ofstream scicos(std::string(aircraft+
"_lin.sce").c_str());
98 << aircraft <<
".x0=..\n" << std::setw(width) << x0 <<
";\n" 99 << aircraft <<
".u0=..\n" << std::setw(width) << u0 <<
";\n" 100 << aircraft <<
".sys = syslin('c',..\n" 101 << std::setw(width) << A <<
",..\n" 102 << std::setw(width) << B <<
",..\n" 103 << std::setw(width) << C <<
",..\n" 104 << std::setw(width) << D <<
");\n" 105 << aircraft <<
".tfm = ss2tf(" << aircraft <<
".sys);\n" 108 time_linDone = std::clock();
109 std::cout <<
"\nlinearization computation time: " << (time_linDone - time_start)/
double(CLOCKS_PER_SEC) <<
" s\n" << std::endl;