40 #include "FGKinemat.h" 41 #include "input_output/FGXMLElement.h" 42 #include "models/FGFCS.h" 50 IDENT(IdSrc,
"$Id: FGKinemat.cpp,v 1.16 2016/06/12 14:47:46 bcoconni Exp $");
51 IDENT(IdHdr,ID_FLAPS);
59 Element *traverse_element, *setting_element;
64 TransitionTimes.clear();
69 if (element->
FindElement(
"noscale")) DoScale =
false;
71 traverse_element = element->
FindElement(
"traverse");
72 setting_element = traverse_element->
FindElement(
"setting");
73 while (setting_element) {
76 Detents.push_back(tmpDetent);
77 TransitionTimes.push_back(tmpTime);
81 if (Detents.size() <= 1) {
82 cerr <<
"Kinematic component " << Name
83 <<
" must have more than 1 setting element" << endl;
87 FGFCSComponent::bind();
105 Input = InputNodes[0]->getDoubleValue() * InputSigns[0];
107 if (DoScale) Input *= Detents.back();
109 if (IsOutput) Output = OutputNodes[0]->getDoubleValue();
111 Input =
Constrain(Detents.front(), Input, Detents.back());
113 if (fcs->GetTrimStatus())
123 for (ind = 1; (Input < Output) ? Detents[ind] < Output : Detents[ind] <= Output ; ++ind)
124 if (ind >= Detents.size())
129 if (TransitionTimes[ind] <= 0.0) {
134 double Rate = (Detents[ind] - Detents[ind-1])/TransitionTimes[ind];
136 double ThisInput =
Constrain(Detents[ind-1], Input, Detents[ind]);
138 double ThisDt = fabs((ThisInput-Output)/Rate);
144 Output += ThisDt*Rate;
146 Output -= ThisDt*Rate;
158 if (IsOutput) SetOutput();
182 void FGKinemat::Debug(
int from)
184 if (debug_lvl <= 0)
return;
188 cout <<
" INPUT: " << InputNodes[0]->GetName() << endl;
189 cout <<
" DETENTS: " << Detents.size() << endl;
190 for (
unsigned int i=0;i<Detents.size();i++) {
191 cout <<
" " << Detents[i] <<
" " << TransitionTimes[i] << endl;
194 for (
unsigned int i=0; i<OutputNodes.size(); i++)
195 cout <<
" OUTPUT: " << OutputNodes[i]->getName() << endl;
197 if (!DoScale) cout <<
" NOSCALE" << endl;
200 if (debug_lvl & 2 ) {
201 if (from == 0) cout <<
"Instantiated: FGKinemat" << endl;
202 if (from == 1) cout <<
"Destroyed: FGKinemat" << endl;
204 if (debug_lvl & 4 ) {
206 if (debug_lvl & 8 ) {
208 if (debug_lvl & 16) {
210 if (debug_lvl & 64) {
212 cout << IdSrc << endl;
213 cout << IdHdr << endl;
static double Constrain(double min, double value, double max)
Constrain a value between a minimum and a maximum value.
Element * FindElement(const std::string &el="")
Searches for a specified element.
double FindElementValueAsNumber(const std::string &el="")
Searches for the named element and returns the data belonging to it as a number.
static bool EqualToRoundoff(double a, double b)
Finite precision comparison.
Encapsulates the Flight Control System (FCS) functionality.
Element * FindNextElement(const std::string &el="")
Searches for the next element as specified.
bool Run(void)
Run method, overrides FGModel::Run().
Base class for JSBSim Flight Control System Components.