JSBSim Flight Dynamics Model 1.3.0 (09 Apr 2026)
An Open Source Flight Dynamics and Control Software Library in C++
Loading...
Searching...
No Matches
FGLinearization.cpp
1/*
2 * FGLinearization.cpp
3 * Copyright (C) James Goppert 2011 <james.goppert@gmail.com>
4 *
5 * FGLinearization.h is free software: you can redistribute it and/or modify it
6 * under the terms of the GNU Lesser General Public License as published by the
7 * Free Software Foundation, either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * FGLinearization.h is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 * See the GNU Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public License along
16 * with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19#include "FGInitialCondition.h"
20#include "FGLinearization.h"
21#include "input_output/FGLog.h"
22
23
24namespace JSBSim {
25
27 : aircraft_name(fdm->GetAircraft()->GetAircraftName())
28{
29 FGStateSpace ss(fdm);
30 ss.x.add(new FGStateSpace::Vt);
31 ss.x.add(new FGStateSpace::Alpha);
32 ss.x.add(new FGStateSpace::Theta);
33 ss.x.add(new FGStateSpace::Q);
34
35 // get propulsion pointer to determine type/ etc.
36 auto engine0 = fdm->GetPropulsion()->GetEngine(0);
37 FGThruster * thruster0 = engine0->GetThruster();
38
39 if (thruster0->GetType()==FGThruster::ttPropeller)
40 {
41 ss.x.add(new FGStateSpace::Rpm0);
42 // TODO add variable prop pitch property
43 // if (variablePropPitch) ss.x.add(new FGStateSpace::PropPitch);
44 int numEngines = fdm->GetPropulsion()->GetNumEngines();
45 if (numEngines>1) ss.x.add(new FGStateSpace::Rpm1);
46 if (numEngines>2) ss.x.add(new FGStateSpace::Rpm2);
47 if (numEngines>3) ss.x.add(new FGStateSpace::Rpm3);
48 if (numEngines>4) {
49 FGLogging log(LogLevel::ERROR);
50 log << "More than 4 engines not currently handled\n";
51 }
52 }
53 ss.x.add(new FGStateSpace::Beta);
54 ss.x.add(new FGStateSpace::Phi);
55 ss.x.add(new FGStateSpace::P);
56 ss.x.add(new FGStateSpace::Psi);
57 ss.x.add(new FGStateSpace::R);
58 ss.x.add(new FGStateSpace::Latitude);
59 ss.x.add(new FGStateSpace::Longitude);
60 ss.x.add(new FGStateSpace::Alt);
61
62 ss.u.add(new FGStateSpace::ThrottleCmd);
63 ss.u.add(new FGStateSpace::DaCmd);
64 ss.u.add(new FGStateSpace::DeCmd);
65 ss.u.add(new FGStateSpace::DrCmd);
66
67 // state feedback
68 ss.y = ss.x;
69
70 x0 = ss.x.get();
71 u0 = ss.u.get();
72 y0 = x0; // state feedback
73
74 fdm->SuspendIntegration();
75 ss.linearize(x0, u0, y0, A, B, C, D);
76 fdm->ResumeIntegration();
77
78 x_names = ss.x.getName();
79 u_names = ss.u.getName();
80 y_names = ss.y.getName();
81 x_units = ss.x.getUnit();
82 u_units = ss.u.getUnit();
83 y_units = ss.y.getUnit();
84}
85
87 auto path = std::string(aircraft_name+"_lin.sce");
88 WriteScicoslab(path);
89}
90
91void FGLinearization::WriteScicoslab(std::string& path) const {
92 int width=20;
93 int precision=10;
94 std::ofstream scicos(path.c_str());
95 scicos.precision(precision);
96 width=20;
97 scicos << std::scientific
98 << aircraft_name << ".x0=..\n" << std::setw(width) << x0 << ";\n"
99 << aircraft_name << ".u0=..\n" << std::setw(width) << u0 << ";\n"
100 << aircraft_name << ".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_name << ".tfm = ss2tf(" << aircraft_name << ".sys);\n"
106 << std::endl;
107 scicos.close();
108
109}
110
111} // JSBSim
112
113// vim:ts=4:sw=4
Encapsulates the JSBSim simulation executive.
Definition FGFDMExec.h:185
std::shared_ptr< FGPropulsion > GetPropulsion(void) const
Returns the FGPropulsion pointer.
void SuspendIntegration(void)
Suspends the simulation and sets the delta T to zero.
Definition FGFDMExec.h:556
void ResumeIntegration(void)
Resumes the simulation by resetting delta T to the correct value.
Definition FGFDMExec.h:559
void WriteScicoslab() const
Write Scicoslab source file with the state space model to a file in the current working directory.
FGLinearization(FGFDMExec *fdmPtr)
Base class for specific thrusting devices such as propellers, nozzles, etc.
Definition FGThruster.h:77
Main namespace for the JSBSim Flight Dynamics Model.
Definition FGFDMExec.cpp:71