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 Class Reference

Detailed Description

Class used to create linear models from FGFDMExec instances.

Definition at line 39 of file FGLinearization.h.

#include <FGLinearization.h>

Public Member Functions

 FGLinearization (FGFDMExec *fdmPtr)
 
const Vector2D< double > & GetFeedforwardMatrix () const
 
const std::vector< double > & GetInitialInput () const
 
const std::vector< double > & GetInitialOutput () const
 
const std::vector< double > & GetInitialState () const
 
const Vector2D< double > & GetInputMatrix () const
 
const std::vector< std::string > & GetInputNames () const
 
const std::vector< std::string > & GetInputUnits () const
 
const Vector2D< double > & GetOutputMatrix () const
 
const std::vector< std::string > & GetOutputNames () const
 
const std::vector< std::string > & GetOutputUnits () const
 
const std::vector< std::string > & GetStateNames () const
 
const std::vector< std::string > & GetStateUnits () const
 
const Vector2D< double > & GetSystemMatrix () const
 Get the state space model matrices.
 
void WriteScicoslab () const
 Write Scicoslab source file with the state space model to a file in the current working directory.
 
void WriteScicoslab (std::string &path) const
 Write Scicoslab source file with the state space model to the given path.
 

Constructor & Destructor Documentation

◆ FGLinearization()

FGLinearization ( FGFDMExec fdmPtr)
Parameters
fdmPtrAlready configured FGFDMExec instance used to create the new linear model.

Definition at line 26 of file FGLinearization.cpp.

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}
+ Here is the call graph for this function:

Member Function Documentation

◆ GetFeedforwardMatrix()

const Vector2D< double > & GetFeedforwardMatrix ( ) const
inline

Definition at line 75 of file FGLinearization.h.

75{ return D; };

◆ GetInitialInput()

const std::vector< double > & GetInitialInput ( ) const
inline

Definition at line 78 of file FGLinearization.h.

78{ return u0; };

◆ GetInitialOutput()

const std::vector< double > & GetInitialOutput ( ) const
inline

Definition at line 79 of file FGLinearization.h.

79{ return y0; };

◆ GetInitialState()

const std::vector< double > & GetInitialState ( ) const
inline

Definition at line 77 of file FGLinearization.h.

77{ return x0; };

◆ GetInputMatrix()

const Vector2D< double > & GetInputMatrix ( ) const
inline

Definition at line 73 of file FGLinearization.h.

73{ return B; };

◆ GetInputNames()

const std::vector< std::string > & GetInputNames ( ) const
inline

Definition at line 82 of file FGLinearization.h.

82{ return u_names; };

◆ GetInputUnits()

const std::vector< std::string > & GetInputUnits ( ) const
inline

Definition at line 86 of file FGLinearization.h.

86{ return u_units; };

◆ GetOutputMatrix()

const Vector2D< double > & GetOutputMatrix ( ) const
inline

Definition at line 74 of file FGLinearization.h.

74{ return C; };

◆ GetOutputNames()

const std::vector< std::string > & GetOutputNames ( ) const
inline

Definition at line 83 of file FGLinearization.h.

83{ return y_names; };

◆ GetOutputUnits()

const std::vector< std::string > & GetOutputUnits ( ) const
inline

Definition at line 87 of file FGLinearization.h.

87{ return y_units; };

◆ GetStateNames()

const std::vector< std::string > & GetStateNames ( ) const
inline

Definition at line 81 of file FGLinearization.h.

81{ return x_names; };

◆ GetStateUnits()

const std::vector< std::string > & GetStateUnits ( ) const
inline

Definition at line 85 of file FGLinearization.h.

85{ return x_units; };

◆ GetSystemMatrix()

const Vector2D< double > & GetSystemMatrix ( ) const
inline

Get the state space model matrices.

Parameters
A_System matrix
B_Input matrix
C_Output matrix
D_Feedforward matrix

Definition at line 72 of file FGLinearization.h.

72{ return A; };

◆ WriteScicoslab() [1/2]

void WriteScicoslab ( ) const

Write Scicoslab source file with the state space model to a file in the current working directory.

Definition at line 86 of file FGLinearization.cpp.

86 {
87 auto path = std::string(aircraft_name+"_lin.sce");
88 WriteScicoslab(path);
89}
void WriteScicoslab() const
Write Scicoslab source file with the state space model to a file in the current working directory.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ WriteScicoslab() [2/2]

void WriteScicoslab ( std::string &  path) const

Write Scicoslab source file with the state space model to the given path.

Parameters
path

Definition at line 91 of file FGLinearization.cpp.

91 {
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}

The documentation for this class was generated from the following files: