1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4 Author: Tony Peden, for flight control system authored by Jon S. Berndt
7 ------------- Copyright (C) 2000 Anthony K. Peden -------------
9 This program is free software; you can redistribute it and/or modify it under
10 the terms of the GNU General Public License as published by the Free Software
11 Foundation; either version 2 of the License, or (at your option) any later
14 This program is distributed in the hope that it will be useful, but WITHOUT
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16 FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
19 You should have received a copy of the GNU General Public License along with
20 this program; if not, write to the Free Software Foundation, Inc., 59 Temple
21 Place - Suite 330, Boston, MA 02111-1307, USA.
23 Further information about the GNU General Public License can also be found on
24 the world wide web at http://www.gnu.org.
26 FUNCTIONAL DESCRIPTION
27 --------------------------------------------------------------------------------
30 --------------------------------------------------------------------------------
32 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
33 COMMENTS, REFERENCES, and NOTES
34 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
36 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
38 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
40 #include "FGKinemat.h"
42 static const char *IdSrc = "$Id$";
43 static const char *IdHdr = ID_FLAPS;
45 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
47 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
49 FGKinemat::FGKinemat(FGFCS* fcs, FGConfigFile* AC_cfg) : FGFCSComponent(fcs),
56 TransitionTimes.clear();
58 Type = AC_cfg->GetValue("TYPE");
59 Name = AC_cfg->GetValue("NAME");
60 AC_cfg->GetNextConfigLine();
62 while ((token = AC_cfg->GetValue()) != string("/COMPONENT")) {
66 } else if (token == "INPUT") {
67 token = AC_cfg->GetValue("INPUT");
68 if (token.find("FG_") != token.npos) {
70 InputIdx = fcs->GetState()->GetParameterIndex(token);
71 InputType = itPilotAC;
73 } else if ( token == "DETENTS" ) {
74 *AC_cfg >> NumDetents;
75 for(int i=0;i<NumDetents;i++) {
78 Detents.push_back(tmpDetent);
79 TransitionTimes.push_back(tmpTime);
81 } else if (token == "OUTPUT") {
84 *AC_cfg >> sOutputIdx;
85 OutputIdx = fcs->GetState()->GetParameterIndex(sOutputIdx);
90 cout << " ID: " << ID << endl;
91 cout << " INPUT: " << InputIdx << endl;
92 cout << " DETENTS: " << NumDetents << endl;
93 for(int i=0;i<NumDetents;i++) {
94 cout << " " << Detents[i] << " " << TransitionTimes[i] << endl;
96 if (IsOutput) cout << " OUTPUT: " <<sOutputIdx << endl;
99 if (debug_lvl & 2) cout << "Instantiated: FGKinemat" << endl;
102 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
104 FGKinemat::~FGKinemat()
106 if (debug_lvl & 2) cout << "Destroyed: FGKinemat" << endl;
109 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
111 bool FGKinemat::Run(void ) {
112 double dt=fcs->GetState()->Getdt();
113 double output_transit_rate=0;
115 FGFCSComponent::Run(); // call the base class for initialization of Input
116 InputCmd = Input*Detents[NumDetents-1];
117 OutputPos = fcs->GetState()->GetParameter(OutputIdx);
119 if(InputCmd < Detents[0]) {
122 lastInputCmd=InputCmd;
123 OutputPos=Detents[0];
125 } else if(InputCmd > Detents[NumDetents-1]) {
127 InputCmd=Detents[fi];
128 lastInputCmd=InputCmd;
129 OutputPos=Detents[fi];
132 //cout << "FGKinemat::Run Handle: " << InputCmd << " Position: " << OutputPos << endl;
136 if(InputCmd != lastInputCmd) {
142 //fprintf(stderr,"InputCmd: %g, OutputPos: %g\n",InputCmd,OutputPos);
144 while(Detents[fi] < InputCmd) {
147 if(OutputPos < InputCmd) {
148 if(TransitionTimes[fi] > 0)
149 output_transit_rate=(Detents[fi] - Detents[fi-1])/TransitionTimes[fi];
151 output_transit_rate=(Detents[fi] - Detents[fi-1])/5;
153 if(TransitionTimes[fi+1] > 0)
154 output_transit_rate=(Detents[fi] - Detents[fi+1])/TransitionTimes[fi+1];
156 output_transit_rate=(Detents[fi] - Detents[fi+1])/5;
158 if(fabs(OutputPos - InputCmd) > dt*output_transit_rate)
159 OutputPos+=output_transit_rate*dt;
166 lastInputCmd=InputCmd;
169 //cout << "FGKinemat::Run Handle: " << InputCmd << " Position: " << OutputPos << " Output: " << Output << endl;
171 //cout << "Calling SetOutput()" << endl;
174 //cout << "Out FGKinemat::Run" << endl;
178 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
180 void FGKinemat::Debug(void)
182 //TODO: Add your source code here