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

Detailed Description

Definition at line 38 of file FGStateSpace.h.

+ Collaboration diagram for FGStateSpace:

Classes

class  AccelX
 
class  AccelY
 
class  AccelZ
 
class  Alpha
 
class  Alt
 
class  Beta
 
class  COG
 
class  Component
 
class  ComponentVector
 
class  DaCmd
 
class  DaPos
 
class  DeCmd
 
class  DePos
 
class  DrCmd
 
class  DrPos
 
class  Latitude
 
class  Longitude
 
class  P
 
class  Phi
 
class  Pi
 
class  PropPitch
 
class  Psi
 
class  Q
 
class  Qi
 
class  R
 
class  Ri
 
class  Rpm0
 
class  Rpm1
 
class  Rpm2
 
class  Rpm3
 
class  Theta
 
class  ThrottleCmd
 
class  ThrottlePos
 
class  Vd
 
class  Ve
 
class  VGround
 
class  Vn
 
class  Vt
 

Public Member Functions

 FGStateSpace (FGFDMExec *fdm)
 
void clear ()
 
void linearize (std::vector< double > x0, std::vector< double > u0, std::vector< double > y0, std::vector< std::vector< double > > &A, std::vector< std::vector< double > > &B, std::vector< std::vector< double > > &C, std::vector< std::vector< double > > &D)
 
void run ()
 
void setFdm (FGFDMExec *fdm)
 
double stateSum ()
 

Public Attributes

ComponentVector u
 
ComponentVector x
 
ComponentVector y
 

Constructor & Destructor Documentation

◆ FGStateSpace()

FGStateSpace ( FGFDMExec fdm)
inline

Definition at line 219 of file FGStateSpace.h.

219: x(fdm,this), u(fdm,this), y(fdm,this), m_fdm(fdm) {};

◆ ~FGStateSpace()

virtual ~FGStateSpace ( )
inlinevirtual

Definition at line 278 of file FGStateSpace.h.

278{};

Member Function Documentation

◆ clear()

void clear ( )
inline

Definition at line 271 of file FGStateSpace.h.

271 {
272 x.clear();
273 u.clear();
274 y.clear();
275 }

◆ linearize()

void linearize ( std::vector< double >  x0,
std::vector< double >  u0,
std::vector< double >  y0,
std::vector< std::vector< double > > &  A,
std::vector< std::vector< double > > &  B,
std::vector< std::vector< double > > &  C,
std::vector< std::vector< double > > &  D 
)

Definition at line 28 of file FGStateSpace.cpp.

36{
37 double h = 1e-4;
38
39 // A, d(x)/dx
40 numericalJacobian(A,x,x,x0,x0,h,true);
41 // B, d(x)/du
42 numericalJacobian(B,x,u,x0,u0,h,true);
43 // C, d(y)/dx
44 numericalJacobian(C,y,x,y0,x0,h);
45 // D, d(y)/du
46 numericalJacobian(D,y,u,y0,u0,h);
47
48}

◆ run()

void run ( )
inline

Definition at line 223 of file FGStateSpace.h.

223 {
224 // initialize
225 m_fdm->Initialize(m_fdm->GetIC().get());
226
227 for (unsigned int i=0; i<m_fdm->GetPropulsion()->GetNumEngines(); i++) {
228 m_fdm->GetPropulsion()->GetEngine(i)->InitRunning();
229 }
230
231 // wait for stable state
232 double cost = stateSum();
233 for(int i=0;i<1000;i++) {
234 m_fdm->GetPropulsion()->GetSteadyState();
235 m_fdm->SetTrimStatus(true);
236 m_fdm->DisableOutput();
237 m_fdm->SuspendIntegration();
238 m_fdm->Run();
239 m_fdm->SetTrimStatus(false);
240 m_fdm->EnableOutput();
241 m_fdm->ResumeIntegration();
242
243 double costNew = stateSum();
244 double dcost = fabs(costNew - cost);
245 if (dcost < std::numeric_limits<double>::epsilon()) {
246 if(m_fdm->GetDebugLevel() > 1) {
247 FGLogging log(LogLevel::DEBUG);
248 log << "cost convergd, i: " << i << "\n";
249 }
250 break;
251 }
252 if (i > 1000) {
253 if(m_fdm->GetDebugLevel() > 1) {
254 FGLogging log(LogLevel::DEBUG);
255 log << "cost failed to converge, dcost: "
256 << std::scientific
257 << dcost << "\n";
258 }
259 break;
260 }
261 cost = costNew;
262 }
263 }
void EnableOutput(void)
Enables data logging to all outputs.
Definition FGFDMExec.h:487
std::shared_ptr< FGInitialCondition > GetIC(void) const
Returns a pointer to the FGInitialCondition object.
Definition FGFDMExec.h:390
int GetDebugLevel(void) const
Retrieves the current debug level setting.
Definition FGFDMExec.h:602
bool Run(void)
This function executes each scheduled model in succession.
void DisableOutput(void)
Disables data logging to all outputs.
Definition FGFDMExec.h:485
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 Initialize(const FGInitialCondition *FGIC)
Initializes the simulation with initial conditions.
void ResumeIntegration(void)
Resumes the simulation by resetting delta T to the correct value.
Definition FGFDMExec.h:559

◆ setFdm()

void setFdm ( FGFDMExec fdm)
inline

Definition at line 221 of file FGStateSpace.h.

221{ m_fdm = fdm; }

◆ stateSum()

double stateSum ( )
inline

Definition at line 265 of file FGStateSpace.h.

265 {
266 double sum = 0;
267 for (unsigned int i=0;i<x.getSize();i++) sum += x.get(i);
268 return sum;
269 }

Member Data Documentation

◆ u

Definition at line 216 of file FGStateSpace.h.

◆ x

Definition at line 216 of file FGStateSpace.h.

◆ y

Definition at line 216 of file FGStateSpace.h.


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