From: Bertrand <bco...@us...> - 2016-06-12 14:47:49
|
Update of /cvsroot/jsbsim/JSBSim/src/models/flight_control In directory sfp-cvs-1.v30.ch3.sourceforge.com:/tmp/cvs-serv15283/src/models/flight_control Modified Files: FGKinemat.h FGKinemat.cpp Log Message: Avoid the lag while trimming and code cleanup. Index: FGKinemat.h =================================================================== RCS file: /cvsroot/jsbsim/JSBSim/src/models/flight_control/FGKinemat.h,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -r1.11 -r1.12 *** FGKinemat.h 28 Mar 2015 14:49:02 -0000 1.11 --- FGKinemat.h 12 Jun 2016 14:47:46 -0000 1.12 *************** *** 122,126 **** /** Kinematic component output value. @return the current output of the kinematic object on the range of [0,1]. */ ! double GetOutputPct() const { return OutputPct; } /** Run method, overrides FGModel::Run(). --- 122,127 ---- /** Kinematic component output value. @return the current output of the kinematic object on the range of [0,1]. */ ! double GetOutputPct() const ! { return (Output-Detents[0])/(Detents.back()-Detents[0]); } /** Run method, overrides FGModel::Run(). *************** *** 132,137 **** std::vector<double> Detents; std::vector<double> TransitionTimes; - size_t NumDetents; - double OutputPct; bool DoScale; --- 133,136 ---- Index: FGKinemat.cpp =================================================================== RCS file: /cvsroot/jsbsim/JSBSim/src/models/flight_control/FGKinemat.cpp,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -r1.15 -r1.16 *** FGKinemat.cpp 2 Apr 2015 17:39:28 -0000 1.15 --- FGKinemat.cpp 12 Jun 2016 14:47:46 -0000 1.16 *************** *** 40,43 **** --- 40,44 ---- #include "FGKinemat.h" #include "input_output/FGXMLElement.h" + #include "models/FGFCS.h" #include <iostream> #include <cstdlib> *************** *** 63,67 **** TransitionTimes.clear(); ! Output = OutputPct = 0; DoScale = true; --- 64,68 ---- TransitionTimes.clear(); ! Output = 0; DoScale = true; *************** *** 77,83 **** setting_element = traverse_element->FindNextElement("setting"); } - NumDetents = Detents.size(); ! if (NumDetents <= 1) { cerr << "Kinematic component " << Name << " must have more than 1 setting element" << endl; --- 78,83 ---- setting_element = traverse_element->FindNextElement("setting"); } ! if (Detents.size() <= 1) { cerr << "Kinematic component " << Name << " must have more than 1 setting element" << endl; *************** *** 86,90 **** FGFCSComponent::bind(); - // treenode->Tie("output-norm", this, &FGKinemat::GetOutputPct ); Debug(0); --- 86,89 ---- *************** *** 106,161 **** Input = InputNodes[0]->getDoubleValue() * InputSigns[0]; ! if (DoScale) Input *= Detents[NumDetents-1]; if (IsOutput) Output = OutputNodes[0]->getDoubleValue(); ! if (Input < Detents[0]) ! Input = Detents[0]; ! else if (Detents[NumDetents-1] < Input) ! Input = Detents[NumDetents-1]; ! ! // Process all detent intervals the movement traverses until either the ! // final value is reached or the time interval has finished. ! while ( dt0 > 0.0 && !EqualToRoundoff(Input, Output) ) { ! ! // Find the area where Output is in ! unsigned int ind; ! for (ind = 1; (Input < Output) ? Detents[ind] < Output : Detents[ind] <= Output ; ++ind) ! if (NumDetents <= ind) ! break; ! // A transition time of 0.0 means an infinite rate. ! // The output is reached in one step ! if (TransitionTimes[ind] <= 0.0) { ! Output = Input; ! break; ! } else { ! // Compute the rate in this area ! double Rate = (Detents[ind] - Detents[ind-1])/TransitionTimes[ind]; ! // Compute the maximum input value inside this area ! double ThisInput = Input; ! if (ThisInput < Detents[ind-1]) ThisInput = Detents[ind-1]; ! if (Detents[ind] < ThisInput) ThisInput = Detents[ind]; ! // Compute the time to reach the value in ThisInput ! double ThisDt = fabs((ThisInput-Output)/Rate); ! ! // and clip to the timestep size ! if (dt0 < ThisDt) { ! ThisDt = dt0; ! if (Output < Input) ! Output += ThisDt*Rate; ! else ! Output -= ThisDt*Rate; ! } else ! // Handle this case separate to make shure the termination condition ! // is met even in inexact arithmetics ... ! Output = ThisInput; ! dt0 -= ThisDt; } } - OutputPct = (Output-Detents[0])/(Detents[NumDetents-1]-Detents[0]); - Clip(); if (IsOutput) SetOutput(); --- 105,158 ---- Input = InputNodes[0]->getDoubleValue() * InputSigns[0]; ! if (DoScale) Input *= Detents.back(); if (IsOutput) Output = OutputNodes[0]->getDoubleValue(); ! Input = Constrain(Detents.front(), Input, Detents.back()); ! if (fcs->GetTrimStatus()) ! // When trimming the output must be reached in one step ! Output = Input; ! else { ! // Process all detent intervals the movement traverses until either the ! // final value is reached or the time interval has finished. ! while ( dt0 > 0.0 && !EqualToRoundoff(Input, Output) ) { ! ! // Find the area where Output is in ! unsigned int ind; ! for (ind = 1; (Input < Output) ? Detents[ind] < Output : Detents[ind] <= Output ; ++ind) ! if (ind >= Detents.size()) ! break; ! ! // A transition time of 0.0 means an infinite rate. ! // The output is reached in one step ! if (TransitionTimes[ind] <= 0.0) { ! Output = Input; ! break; ! } else { ! // Compute the rate in this area ! double Rate = (Detents[ind] - Detents[ind-1])/TransitionTimes[ind]; ! // Compute the maximum input value inside this area ! double ThisInput = Constrain(Detents[ind-1], Input, Detents[ind]); ! // Compute the time to reach the value in ThisInput ! double ThisDt = fabs((ThisInput-Output)/Rate); ! ! // and clip to the timestep size ! if (dt0 < ThisDt) { ! ThisDt = dt0; ! if (Output < Input) ! Output += ThisDt*Rate; ! else ! Output -= ThisDt*Rate; ! } else ! // Handle this case separate to make shure the termination condition ! // is met even in inexact arithmetics ... ! Output = ThisInput; ! dt0 -= ThisDt; ! } } } Clip(); if (IsOutput) SetOutput(); *************** *** 190,195 **** if (from == 0) { // Constructor cout << " INPUT: " << InputNodes[0]->GetName() << endl; ! cout << " DETENTS: " << NumDetents << endl; ! for (unsigned int i=0;i<NumDetents;i++) { cout << " " << Detents[i] << " " << TransitionTimes[i] << endl; } --- 187,192 ---- if (from == 0) { // Constructor cout << " INPUT: " << InputNodes[0]->GetName() << endl; ! cout << " DETENTS: " << Detents.size() << endl; ! for (unsigned int i=0;i<Detents.size();i++) { cout << " " << Detents[i] << " " << TransitionTimes[i] << endl; } |