]> git.mxchange.org Git - flightgear.git/blob - src/FDM/UIUCModel/uiuc_aerodeflections.cpp
d87f608b82812ad9991f00ac37dd123240706843
[flightgear.git] / src / FDM / UIUCModel / uiuc_aerodeflections.cpp
1 /**********************************************************************
2
3  FILENAME:     uiuc_aerodeflections.cpp
4
5 ----------------------------------------------------------------------
6
7  DESCRIPTION:  determine the aero control surface deflections
8                elevator [rad]
9                aileron [rad]
10                rudder [rad]
11                
12 ----------------------------------------------------------------------
13
14  STATUS:       alpha version
15
16 ----------------------------------------------------------------------
17
18  REFERENCES:   based on deflection portions of c172_aero.c and 
19                uiuc_aero.c
20
21 ----------------------------------------------------------------------
22
23  HISTORY:      01/30/2000   initial release
24                04/05/2000   (JS) added zero_Long_trim command
25                07/05/2001   (RD) removed elevator_tab addidtion to
26                             elevator calculation
27                11/12/2001   (RD) added new flap routine.  Needed for
28                             Twin Otter non-linear model
29
30 ----------------------------------------------------------------------
31
32  AUTHOR(S):    Jeff Scott         <jscott@mail.com>
33                Robert Deters      <rdeters@uiuc.edu>
34                Michael Selig      <m-selig@uiuc.edu>
35
36 ----------------------------------------------------------------------
37
38  VARIABLES:
39
40 ----------------------------------------------------------------------
41
42  INPUTS:       *
43
44 ----------------------------------------------------------------------
45
46  OUTPUTS:      *
47
48 ----------------------------------------------------------------------
49
50  CALLED BY:    *
51
52 ----------------------------------------------------------------------
53
54  CALLS TO:     *
55
56 ----------------------------------------------------------------------
57
58  COPYRIGHT:    (C) 2000 by Michael Selig
59
60  This program is free software; you can redistribute it and/or
61  modify it under the terms of the GNU General Public License
62  as published by the Free Software Foundation.
63
64  This program is distributed in the hope that it will be useful,
65  but WITHOUT ANY WARRANTY; without even the implied warranty of
66  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
67  GNU General Public License for more details.
68
69  You should have received a copy of the GNU General Public License
70  along with this program; if not, write to the Free Software
71  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
72  USA or view http://www.gnu.org/copyleft/gpl.html.
73
74 **********************************************************************/
75
76 #include <math.h>
77
78 #include "uiuc_aerodeflections.h"
79
80 void uiuc_aerodeflections( double dt )
81 {
82   double prevFlapHandle = 0.0f;
83   double flap_transit_rate;
84   bool flaps_in_transit = false;
85
86   if (zero_Long_trim)
87     {
88       Long_trim = 0;
89       //elevator_tab = 0;
90     }
91
92   if (Lat_control <= 0)
93     aileron = - Lat_control * damin * DEG_TO_RAD;
94   else
95     aileron = - Lat_control * damax * DEG_TO_RAD;
96
97   if ((Long_control+Long_trim) <= 0)
98     elevator = (Long_control + Long_trim) * demax * DEG_TO_RAD;
99   else
100     elevator = (Long_control + Long_trim) * demin * DEG_TO_RAD;
101
102   if (Rudder_pedal <= 0)
103     rudder = - Rudder_pedal * drmin * DEG_TO_RAD;
104   else
105     rudder = - Rudder_pedal * drmax * DEG_TO_RAD;
106
107
108   // new flap routine
109   // designed for the twin otter non-linear model
110   flap_percent     = Flap_handle / 30.0;       // percent of flaps desired
111   if (flap_percent>=0.31 && flap_percent<=0.35)
112     flap_percent = 1.0 / 3.0;
113   if (flap_percent>=0.65 && flap_percent<=0.69)
114     flap_percent = 2.0 / 3.0;
115   flap_goal        = flap_percent * flap_max;  // angle of flaps desired
116   flap_moving_rate = flap_rate * dt;           // amount flaps move per time step
117   
118   // determine flap position with respect to the flap goal
119   if (flap_pos < flap_goal)
120     {
121       flap_pos += flap_moving_rate;
122       if (flap_pos > flap_goal)
123         flap_pos = flap_goal;
124     }
125   else if (flap_pos > flap_goal)
126     {
127       flap_pos -= flap_moving_rate;
128       if (flap_pos < flap_goal)
129         flap_pos = flap_goal;
130     }
131
132
133   // old flap routine
134   // check for lowest flap setting
135   if (Flap_handle < dfArray[1])
136     {
137       Flap_handle    = dfArray[1];
138       prevFlapHandle = Flap_handle;
139       flap           = Flap_handle;
140     }
141   // check for highest flap setting
142   else if (Flap_handle > dfArray[ndf])
143     {
144       Flap_handle      = dfArray[ndf];
145       prevFlapHandle   = Flap_handle;
146       flap             = Flap_handle;
147     }
148   // otherwise in between
149   else          
150     {
151       if(Flap_handle != prevFlapHandle)
152         {
153           flaps_in_transit = true;
154         }
155       if(flaps_in_transit)
156         {
157           int iflap = 0;
158           while (dfArray[iflap] < Flap_handle)
159             {
160               iflap++;
161             }
162           if (flap < Flap_handle)
163             {
164               if (TimeArray[iflap] > 0)
165                 flap_transit_rate = (dfArray[iflap] - dfArray[iflap-1]) / TimeArray[iflap+1];
166               else
167                 flap_transit_rate = (dfArray[iflap] - dfArray[iflap-1]) / 5;
168             }
169           else 
170             {
171               if (TimeArray[iflap+1] > 0)
172                 flap_transit_rate = (dfArray[iflap] - dfArray[iflap+1]) / TimeArray[iflap+1];
173               else
174                 flap_transit_rate = (dfArray[iflap] - dfArray[iflap+1]) / 5;
175             }
176           if(fabs (flap - Flap_handle) > dt * flap_transit_rate)
177             flap += flap_transit_rate * dt;
178           else
179             {
180               flaps_in_transit = false;
181               flap = Flap_handle;
182             }
183         }
184     }
185   prevFlapHandle = Flap_handle;
186
187   return;
188 }
189
190 // end uiuc_aerodeflections.cpp