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 *******************************************************************************/
42 /*******************************************************************************
43 ************************************ CODE **************************************
44 *******************************************************************************/
46 // *****************************************************************************
47 // Function: Constructor
52 FGFlaps::FGFlaps(FGFCS* fcs, FGConfigFile* AC_cfg) : FGFCSComponent(fcs),
59 TransitionTimes.clear();
61 Type = AC_cfg->GetValue("TYPE");
62 Name = AC_cfg->GetValue("NAME");
63 AC_cfg->GetNextConfigLine();
65 while ((token = AC_cfg->GetValue()) != "/COMPONENT") {
69 cout << " ID: " << ID << endl;
70 } else if (token == "INPUT") {
71 token = AC_cfg->GetValue("INPUT");
72 cout << " INPUT: " << token << endl;
73 if (token.find("FG_") != token.npos) {
75 InputIdx = fcs->GetState()->GetParameterIndex(token);
76 InputType = itPilotAC;
78 } else if ( token == "DETENTS" ) {
79 *AC_cfg >> NumDetents;
80 cout << " DETENTS: " << NumDetents << endl;
81 for(int i=0;i<NumDetents;i++) {
84 Detents.push_back(tmpDetent);
85 TransitionTimes.push_back(tmpTime);
86 cout << " " << Detents[i] << " " << TransitionTimes[i] << endl;
88 } else if (token == "OUTPUT") {
91 *AC_cfg >> sOutputIdx;
92 cout << " OUTPUT: " <<sOutputIdx << endl;
93 OutputIdx = fcs->GetState()->GetParameterIndex(sOutputIdx);
98 // *****************************************************************************
104 bool FGFlaps::Run(void ) {
105 float dt=fcs->GetState()->Getdt();
106 float flap_transit_rate=0;
108 FGFCSComponent::Run(); // call the base class for initialization of Input
109 Flap_Handle=Input*Detents[NumDetents-1];
110 Flap_Position=fcs->GetState()->GetParameter(OutputIdx);
112 if(Flap_Handle < Detents[0]) {
114 Flap_Handle=Detents[0];
115 lastFlapHandle=Flap_Handle;
116 Flap_Position=Detents[0];
117 Output=Flap_Position;
118 } else if(Flap_Handle > Detents[NumDetents-1]) {
120 Flap_Handle=Detents[fi];
121 lastFlapHandle=Flap_Handle;
122 Flap_Position=Detents[fi];
123 Output=Flap_Position;
125 //cout << "FGFlaps::Run Handle: " << Flap_Handle << " Position: " << Flap_Position << endl;
127 Flap_Position=Flap_Handle;
129 if(Flap_Handle != lastFlapHandle) {
133 if(Flaps_In_Transit) {
135 //fprintf(stderr,"Flap_Handle: %g, Flap_Position: %g\n",Flap_Handle,Flap_Position);
137 while(Detents[fi] < Flap_Handle) {
140 if(Flap_Position < Flap_Handle) {
141 if(TransitionTimes[fi] > 0)
142 flap_transit_rate=(Detents[fi] - Detents[fi-1])/TransitionTimes[fi];
144 flap_transit_rate=(Detents[fi] - Detents[fi-1])/5;
146 if(TransitionTimes[fi+1] > 0)
147 flap_transit_rate=(Detents[fi] - Detents[fi+1])/TransitionTimes[fi+1];
149 flap_transit_rate=(Detents[fi] - Detents[fi+1])/5;
151 if(fabs(Flap_Position - Flap_Handle) > dt*flap_transit_rate)
152 Flap_Position+=flap_transit_rate*dt;
155 Flap_Position=Flap_Handle;
159 lastFlapHandle=Flap_Handle;
160 Output=Flap_Position;
162 //cout << "FGFlaps::Run Handle: " << Flap_Handle << " Position: " << Flap_Position << " Output: " << Output << endl;
164 //cout << "Calling SetOutput()" << endl;
167 //cout << "Out FGFlap::Run" << endl;