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

Detailed Description

Base class for JSBSim Flight Control System Components.

The Flight Control System (FCS) for JSBSim consists of the FCS container class (see FGFCS), the FGFCSComponent base class, and the component classes from which can be constructed a string, or channel. See:

Author
Jon S. Berndt
See also
Documentation for the FGFCS class, and for the configuration file class

Definition at line 84 of file FGFCSComponent.h.

#include <FGFCSComponent.h>

+ Inheritance diagram for FGFCSComponent:
+ Collaboration diagram for FGFCSComponent:

Public Member Functions

 FGFCSComponent (FGFCS *fcs, Element *el)
 Constructor.
 
virtual ~FGFCSComponent ()
 Destructor.
 
std::string GetName (void) const
 
double GetOutput (void) const
 
virtual double GetOutputPct (void) const
 
std::string GetType (void) const
 
virtual void ResetPastStates (void)
 
virtual bool Run (void)
 
virtual void SetOutput (void)
 
- Public Member Functions inherited from FGJSBBase
 FGJSBBase ()
 Constructor for FGJSBBase.
 
virtual ~FGJSBBase ()
 Destructor for FGJSBBase.
 
void disableHighLighting (void)
 Disables highlighting in the console output.
 

Protected Member Functions

virtual void bind (Element *el, FGPropertyManager *pm)
 
void CheckInputNodes (size_t MinNodes, size_t MaxNodes, Element *el)
 
void Clip (void)
 
virtual void Debug (int from)
 
void Delay (void)
 

Protected Attributes

bool clip
 
FGParameter_ptr ClipMax
 
FGParameter_ptr ClipMin
 
bool cyclic_clip
 
unsigned int delay
 
double delay_time
 
double dt
 
FGFCSfcs
 
int index
 
std::vector< FGPropertyValue_ptr > InitNodes
 
double Input
 
std::vector< FGPropertyValue_ptr > InputNodes
 
std::string Name
 
double Output
 
std::vector< double > output_array
 
std::vector< SGPropertyNode_ptr > OutputNodes
 
std::string Type
 

Additional Inherited Members

- Public Types inherited from FGJSBBase
enum  { eL = 1 , eM , eN }
 Moments L, M, N. More...
 
enum  { eP = 1 , eQ , eR }
 Rates P, Q, R. More...
 
enum  { eU = 1 , eV , eW }
 Velocities U, V, W. More...
 
enum  { eX = 1 , eY , eZ }
 Positions X, Y, Z. More...
 
enum  { ePhi = 1 , eTht , ePsi }
 Euler angles Phi, Theta, Psi. More...
 
enum  { eDrag = 1 , eSide , eLift }
 Stability axis forces, Drag, Side force, Lift. More...
 
enum  { eRoll = 1 , ePitch , eYaw }
 Local frame orientation Roll, Pitch, Yaw. More...
 
enum  { eNorth = 1 , eEast , eDown }
 Local frame position North, East, Down. More...
 
enum  { eLat = 1 , eLong , eRad }
 Locations Radius, Latitude, Longitude. More...
 
enum  {
  inNone = 0 , inDegrees , inRadians , inMeters ,
  inFeet
}
 Conversion specifiers. More...
 
- Static Public Member Functions inherited from FGJSBBase
static const std::string & GetVersion (void)
 Returns the version number of JSBSim.
 
static constexpr double KelvinToFahrenheit (double kelvin)
 Converts from degrees Kelvin to degrees Fahrenheit.
 
static constexpr double CelsiusToRankine (double celsius)
 Converts from degrees Celsius to degrees Rankine.
 
static constexpr double RankineToCelsius (double rankine)
 Converts from degrees Rankine to degrees Celsius.
 
static constexpr double KelvinToRankine (double kelvin)
 Converts from degrees Kelvin to degrees Rankine.
 
static constexpr double RankineToKelvin (double rankine)
 Converts from degrees Rankine to degrees Kelvin.
 
static constexpr double FahrenheitToCelsius (double fahrenheit)
 Converts from degrees Fahrenheit to degrees Celsius.
 
static constexpr double CelsiusToFahrenheit (double celsius)
 Converts from degrees Celsius to degrees Fahrenheit.
 
static constexpr double CelsiusToKelvin (double celsius)
 Converts from degrees Celsius to degrees Kelvin.
 
static constexpr double KelvinToCelsius (double kelvin)
 Converts from degrees Kelvin to degrees Celsius.
 
static constexpr double FeetToMeters (double measure)
 Converts from feet to meters.
 
static bool EqualToRoundoff (double a, double b)
 Finite precision comparison.
 
static bool EqualToRoundoff (float a, float b)
 Finite precision comparison.
 
static bool EqualToRoundoff (float a, double b)
 Finite precision comparison.
 
static bool EqualToRoundoff (double a, float b)
 Finite precision comparison.
 
static constexpr double Constrain (double min, double value, double max)
 Constrain a value between a minimum and a maximum value.
 
static constexpr double sign (double num)
 
- Static Public Attributes inherited from FGJSBBase
static char highint [5] = {27, '[', '1', 'm', '\0' }
 highlights text
 
static char halfint [5] = {27, '[', '2', 'm', '\0' }
 low intensity text
 
static char normint [6] = {27, '[', '2', '2', 'm', '\0' }
 normal intensity text
 
static char reset [5] = {27, '[', '0', 'm', '\0' }
 resets text properties
 
static char underon [5] = {27, '[', '4', 'm', '\0' }
 underlines text
 
static char underoff [6] = {27, '[', '2', '4', 'm', '\0' }
 underline off
 
static char fgblue [6] = {27, '[', '3', '4', 'm', '\0' }
 blue text
 
static char fgcyan [6] = {27, '[', '3', '6', 'm', '\0' }
 cyan text
 
static char fgred [6] = {27, '[', '3', '1', 'm', '\0' }
 red text
 
static char fggreen [6] = {27, '[', '3', '2', 'm', '\0' }
 green text
 
static char fgdef [6] = {27, '[', '3', '9', 'm', '\0' }
 default text
 
static short debug_lvl = 1
 
- Static Protected Member Functions inherited from FGJSBBase
static std::string CreateIndexedPropertyName (const std::string &Property, int index)
 
- Static Protected Attributes inherited from FGJSBBase
static constexpr double radtodeg = 180. / M_PI
 
static constexpr double degtorad = M_PI / 180.
 
static constexpr double hptoftlbssec = 550.0
 
static constexpr double psftoinhg = 0.014138
 
static constexpr double psftopa = 47.88
 
static constexpr double fttom = 0.3048
 
static constexpr double ktstofps = 1852./(3600*fttom)
 
static constexpr double fpstokts = 1.0 / ktstofps
 
static constexpr double inchtoft = 1.0/12.0
 
static constexpr double m3toft3 = 1.0/(fttom*fttom*fttom)
 
static constexpr double in3tom3 = inchtoft*inchtoft*inchtoft/m3toft3
 
static constexpr double inhgtopa = 3386.38
 
static constexpr double slugtolb = 32.174049
 Note that definition of lbtoslug by the inverse of slugtolb and not to a different constant you can also get from some tables will make lbtoslug*slugtolb == 1 up to the magnitude of roundoff.
 
static constexpr double lbtoslug = 1.0/slugtolb
 
static constexpr double kgtolb = 2.20462
 
static constexpr double kgtoslug = 0.06852168
 
static const std::string needed_cfg_version = "2.0"
 
static const std::string JSBSim_version = JSBSIM_VERSION " " __DATE__ " " __TIME__
 

Constructor & Destructor Documentation

◆ FGFCSComponent()

FGFCSComponent ( FGFCS fcs,
Element el 
)

Constructor.

Definition at line 53 of file FGFCSComponent.cpp.

53 : fcs(_fcs)
54{
55 Input = Output = delay_time = 0.0;
56 delay = index = 0;
57 ClipMin = ClipMax = new FGRealValue(0.0);
58 clip = cyclic_clip = false;
59 dt = fcs->GetChannelDeltaT();
60
61 auto PropertyManager = fcs->GetPropertyManager();
62 if (element->GetName() == string("lag_filter")) {
63 Type = "LAG_FILTER";
64 } else if (element->GetName() == string("lead_lag_filter")) {
65 Type = "LEAD_LAG_FILTER";
66 } else if (element->GetName() == string("washout_filter")) {
67 Type = "WASHOUT_FILTER";
68 } else if (element->GetName() == string("second_order_filter")) {
69 Type = "SECOND_ORDER_FILTER";
70 } else if (element->GetName() == string("integrator")) {
71 Type = "INTEGRATOR";
72 } else if (element->GetName() == string("summer")) {
73 Type = "SUMMER";
74 } else if (element->GetName() == string("pure_gain")) {
75 Type = "PURE_GAIN";
76 } else if (element->GetName() == string("scheduled_gain")) {
77 Type = "SCHEDULED_GAIN";
78 } else if (element->GetName() == string("aerosurface_scale")) {
79 Type = "AEROSURFACE_SCALE";
80 } else if (element->GetName() == string("switch")) {
81 Type = "SWITCH";
82 } else if (element->GetName() == string("kinematic")) {
83 Type = "KINEMATIC";
84 } else if (element->GetName() == string("deadband")) {
85 Type = "DEADBAND";
86 } else if (element->GetName() == string("fcs_function")) {
87 Type = "FCS_FUNCTION";
88 } else if (element->GetName() == string("pid")) {
89 Type = "PID";
90 } else if (element->GetName() == string("sensor")) {
91 Type = "SENSOR";
92 } else if (element->GetName() == string("accelerometer")) {
93 Type = "ACCELEROMETER";
94 } else if (element->GetName() == string("magnetometer")) {
95 Type = "MAGNETOMETER";
96 } else if (element->GetName() == string("gyro")) {
97 Type = "GYRO";
98 } else if (element->GetName() == string("actuator")) {
99 Type = "ACTUATOR";
100 } else if (element->GetName() == string("waypoint_heading")) {
101 Type = "WAYPOINT_HEADING";
102 } else if (element->GetName() == string("waypoint_distance")) {
103 Type = "WAYPOINT_DISTANCE";
104 } else if (element->GetName() == string("angle")) {
105 Type = "ANGLE";
106 } else if (element->GetName() == string("distributor")) {
107 Type = "DISTRIBUTOR";
108 } else { // illegal component in this channel
109 Type = "UNKNOWN";
110 }
111
112 Name = element->GetAttributeValue("name");
113
114 Element *init_element = element->FindElement("init");
115 while (init_element) {
116 InitNodes.push_back(new FGPropertyValue(init_element->GetDataLine(),
117 PropertyManager, init_element));
118 init_element = element->FindNextElement("init");
119 }
120
121 Element *input_element = element->FindElement("input");
122 while (input_element) {
123 InputNodes.push_back(new FGPropertyValue(input_element->GetDataLine(),
124 PropertyManager, input_element));
125
126 input_element = element->FindNextElement("input");
127 }
128
129 Element *out_elem = element->FindElement("output");
130 while (out_elem) {
131 string output_node_name = out_elem->GetDataLine();
132 bool node_exists = PropertyManager->HasNode(output_node_name);
133 SGPropertyNode* OutputNode = PropertyManager->GetNode( output_node_name, true );
134 if (!OutputNode) {
135 XMLLogException err(out_elem);
136 err << " Unable to process property: " << output_node_name << "\n";
137 throw err;
138 }
139 OutputNodes.push_back(OutputNode);
140 // If the node has just been created then it must be initialized to a
141 // sensible value since FGPropertyNode::GetNode() does not take care of
142 // that. If the node was already existing, its current value is kept
143 // unchanged.
144 if (!node_exists)
145 OutputNode->setDoubleValue(Output);
146 out_elem = element->FindNextElement("output");
147 }
148
149 Element* delay_elem = element->FindElement("delay");
150 if ( delay_elem ) {
151 string delay_str = delay_elem->GetDataLine();
152 FGParameterValue delayParam(delay_str, PropertyManager, delay_elem);
153 delay_time = delayParam.GetValue();
154 string delayType = delay_elem->GetAttributeValue("type");
155 if (delayType.length() > 0) {
156 if (delayType == "time") {
157 delay = (unsigned int)(delay_time / dt);
158 } else if (delayType == "frames") {
159 delay = (unsigned int)delay_time;
160 } else {
161 FGXMLLogging log(delay_elem, LogLevel::ERROR);
162 log << "Unallowed delay type\n";
163 }
164 } else {
165 delay = (unsigned int)(delay_time / dt);
166 }
167 output_array.resize(delay);
168 for (unsigned int i=0; i<delay; i++) output_array[i] = 0.0;
169 }
170
171 Element *clip_el = element->FindElement("clipto");
172 if (clip_el) {
173 Element* el = clip_el->FindElement("min");
174 if (!el) {
175 FGXMLLogging log(clip_el, LogLevel::ERROR);
176 log << "Element <min> is missing, <clipto> is ignored.\n";
177 return;
178 }
179
180 ClipMin = new FGParameterValue(el, PropertyManager);
181
182 el = clip_el->FindElement("max");
183 if (!el) {
184 FGXMLLogging log(clip_el, LogLevel::ERROR);
185 log << "Element <max> is missing, <clipto> is ignored.\n";
186 ClipMin = nullptr;
187 return;
188 }
189
190 ClipMax = new FGParameterValue(el, PropertyManager);
191
192 if (clip_el->GetAttributeValue("type") == "cyclic")
193 cyclic_clip = true;
194
195 clip = true;
196 }
197
198 Debug(0);
199}
A node in a property tree.
Definition props.hxx:747
bool setDoubleValue(double value)
Set a double value for this node.
+ Here is the call graph for this function:

◆ ~FGFCSComponent()

~FGFCSComponent ( )
virtual

Destructor.

Definition at line 203 of file FGFCSComponent.cpp.

204{
205 Debug(1);
206}

Member Function Documentation

◆ bind()

void bind ( Element el,
FGPropertyManager *  pm 
)
protectedvirtual

Definition at line 303 of file FGFCSComponent.cpp.

304{
305 string tmp;
306 if (Name.find("/") == string::npos)
307 tmp = "fcs/" + PropertyManager->mkPropertyName(Name, true);
308 else
309 tmp = Name;
310
311 bool node_exists = PropertyManager->HasNode(tmp);
312 SGPropertyNode* node = PropertyManager->GetNode(tmp, true);
313
314 if (node) {
315 OutputNodes.push_back(node);
316 // If the node has just been created then it must be initialized to a
317 // sensible value since FGPropertyNode::GetNode() does not take care of
318 // that. If the node was already existing, its current value is kept
319 // unchanged.
320 if (!node_exists)
321 node->setDoubleValue(Output);
322 }
323 else {
324 FGXMLLogging log(el, LogLevel::ERROR);
325 log << "Could not get or create property " << tmp << "\n";
326 }
327}

◆ CheckInputNodes()

void CheckInputNodes ( size_t  MinNodes,
size_t  MaxNodes,
Element el 
)
protected

Definition at line 219 of file FGFCSComponent.cpp.

220{
221 size_t num = InputNodes.size();
222
223 if (num < MinNodes) {
224 XMLLogException err(el);
225 err << " Not enough <input> nodes are provided\n"
226 << " Expecting " << MinNodes << " while " << num
227 << " are provided.\n";
228 throw err;
229 }
230
231 if (num > MaxNodes) {
232 FGXMLLogging log(el, LogLevel::ERROR);
233 log << " Too many <input> nodes are provided\n"
234 << " Expecting " << MaxNodes << " while " << num
235 << " are provided.\n"
236 << " The last " << num-MaxNodes << " input nodes will be ignored.\n";
237 }
238}

◆ Clip()

void Clip ( void  )
protected

Definition at line 267 of file FGFCSComponent.cpp.

268{
269 if (clip) {
270 double vmin = ClipMin->GetValue();
271 double vmax = ClipMax->GetValue();
272 double range = vmax - vmin;
273
274 if (range < 0.0) {
275 FGLogging log(LogLevel::ERROR);
276 log << "Trying to clip with a max value (" << fixed << vmax << ") from "
277 << ClipMax->GetName() << " lower than the min value (" << vmin
278 << ") from " << ClipMin->GetName() << ".\n"
279 << "Clipping is ignored.\n";
280 return;
281 }
282
283 if (cyclic_clip && range != 0.0) {
284 double value = Output - vmin;
285 Output = fmod(value, range) + vmin;
286 if (Output < vmin)
287 Output += range;
288 }
289 else
290 Output = Constrain(vmin, Output, vmax);
291 }
292}
static constexpr double Constrain(double min, double value, double max)
Constrain a value between a minimum and a maximum value.
Definition FGJSBBase.h:289

◆ Debug()

void Debug ( int  from)
protectedvirtual

Definition at line 348 of file FGFCSComponent.cpp.

349{
350 if (debug_lvl <= 0) return;
351
352 if (debug_lvl & 1) { // Standard console startup message output
353 if (from == 0) {
354 FGLogging log(LogLevel::DEBUG);
355 log << "\n Loading Component \"" << Name << fixed
356 << "\" of type: " << Type << "\n";
357
358 if (clip) {
359 log << " Minimum limit: " << ClipMin->GetName() << "\n";
360 log << " Maximum limit: " << ClipMax->GetName() << "\n";
361 }
362 if (delay > 0) log <<" Frame delay: " << delay << fixed
363 << setprecision(4) << " frames (" << delay*dt << " sec)\n";
364 }
365 }
366 if (debug_lvl & 2 ) { // Instantiation/Destruction notification
367 FGLogging log(LogLevel::DEBUG);
368 if (from == 0) log << "Instantiated: FGFCSComponent\n";
369 if (from == 1) log << "Destroyed: FGFCSComponent\n";
370 }
371 if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
372 }
373 if (debug_lvl & 8 ) { // Runtime state variables
374 }
375 if (debug_lvl & 16) { // Sanity checking
376 }
377 if (debug_lvl & 64) {
378 if (from == 0) { // Constructor
379 }
380 }
381}

◆ Delay()

void Delay ( void  )
protected

Definition at line 250 of file FGFCSComponent.cpp.

251{
252 if (fcs->GetTrimStatus()) {
253 // Update the whole history while trim routines are executing.
254 // Don't want to model delays while calculating a trim solution.
255 std::fill(output_array.begin(), output_array.end(), Output);
256 }
257 else {
258 output_array[index] = Output;
259 if ((unsigned int)index == delay-1) index = 0;
260 else index++;
261 Output = output_array[index];
262 }
263}

◆ GetName()

std::string GetName ( void  ) const
inline

Definition at line 95 of file FGFCSComponent.h.

95{return Name;}

◆ GetOutput()

double GetOutput ( void  ) const
inline

Definition at line 94 of file FGFCSComponent.h.

94{return Output;}

◆ GetOutputPct()

virtual double GetOutputPct ( void  ) const
inlinevirtual

Reimplemented in FGKinemat.

Definition at line 97 of file FGFCSComponent.h.

97{ return 0; }

◆ GetType()

std::string GetType ( void  ) const
inline

Definition at line 96 of file FGFCSComponent.h.

96{ return Type; }

◆ ResetPastStates()

void ResetPastStates ( void  )
virtual

Definition at line 210 of file FGFCSComponent.cpp.

211{
212 index = 0;
213 for (auto &elm: output_array)
214 elm = 0.0;
215}

◆ Run()

virtual bool Run ( void  )
inlinevirtual

Reimplemented in FGActuator, FGDistributor, FGKinemat, FGLinearActuator, FGSummer, and FGSwitch.

Definition at line 92 of file FGFCSComponent.h.

92{ return true; }

◆ SetOutput()

void SetOutput ( void  )
virtual

Definition at line 242 of file FGFCSComponent.cpp.

243{
244 for (auto node: OutputNodes)
245 node->setDoubleValue(Output);
246}

Member Data Documentation

◆ clip

bool clip
protected

Definition at line 115 of file FGFCSComponent.h.

◆ ClipMax

FGParameter_ptr ClipMax
protected

Definition at line 103 of file FGFCSComponent.h.

◆ ClipMin

FGParameter_ptr ClipMin
protected

Definition at line 103 of file FGFCSComponent.h.

◆ cyclic_clip

bool cyclic_clip
protected

Definition at line 115 of file FGFCSComponent.h.

◆ delay

unsigned int delay
protected

Definition at line 112 of file FGFCSComponent.h.

◆ delay_time

double delay_time
protected

Definition at line 111 of file FGFCSComponent.h.

◆ dt

double dt
protected

Definition at line 114 of file FGFCSComponent.h.

◆ fcs

FGFCS* fcs
protected

Definition at line 101 of file FGFCSComponent.h.

◆ index

int index
protected

Definition at line 113 of file FGFCSComponent.h.

◆ InitNodes

std::vector<FGPropertyValue_ptr> InitNodes
protected

Definition at line 104 of file FGFCSComponent.h.

◆ Input

double Input
protected

Definition at line 109 of file FGFCSComponent.h.

◆ InputNodes

std::vector<FGPropertyValue_ptr> InputNodes
protected

Definition at line 105 of file FGFCSComponent.h.

◆ Name

std::string Name
protected

Definition at line 108 of file FGFCSComponent.h.

◆ Output

double Output
protected

Definition at line 110 of file FGFCSComponent.h.

◆ output_array

std::vector<double> output_array
protected

Definition at line 106 of file FGFCSComponent.h.

◆ OutputNodes

std::vector<SGPropertyNode_ptr> OutputNodes
protected

Definition at line 102 of file FGFCSComponent.h.

◆ Type

std::string Type
protected

Definition at line 107 of file FGFCSComponent.h.


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