]> git.mxchange.org Git - flightgear.git/blob - src/FDM/UIUCModel/uiuc_aerodeflections.cpp
Updated Cameron's entry.
[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
26 ----------------------------------------------------------------------
27
28  AUTHOR(S):    Jeff Scott         <jscott@mail.com>
29                Michael Selig      <m-selig@uiuc.edu>
30
31 ----------------------------------------------------------------------
32
33  VARIABLES:
34
35 ----------------------------------------------------------------------
36
37  INPUTS:       *
38
39 ----------------------------------------------------------------------
40
41  OUTPUTS:      *
42
43 ----------------------------------------------------------------------
44
45  CALLED BY:    *
46
47 ----------------------------------------------------------------------
48
49  CALLS TO:     *
50
51 ----------------------------------------------------------------------
52
53  COPYRIGHT:    (C) 2000 by Michael Selig
54
55  This program is free software; you can redistribute it and/or
56  modify it under the terms of the GNU General Public License
57  as published by the Free Software Foundation.
58
59  This program is distributed in the hope that it will be useful,
60  but WITHOUT ANY WARRANTY; without even the implied warranty of
61  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
62  GNU General Public License for more details.
63
64  You should have received a copy of the GNU General Public License
65  along with this program; if not, write to the Free Software
66  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
67  USA or view http://www.gnu.org/copyleft/gpl.html.
68
69 **********************************************************************/
70
71 #include <math.h>
72
73 #include "uiuc_aerodeflections.h"
74
75 void uiuc_aerodeflections( double dt )
76 {
77   double prevFlapHandle = 0.0f;
78   double flap_transit_rate;
79   bool flaps_in_transit = false;
80
81   if (zero_Long_trim)
82     {
83       Long_trim = 0;
84       //elevator_tab = 0;
85     }
86
87   if (Lat_control <= 0)
88     aileron = - Lat_control * damin * DEG_TO_RAD;
89   else
90     aileron = - Lat_control * damax * DEG_TO_RAD;
91
92   if ((Long_control+Long_trim) <= 0)
93     elevator = (Long_control + Long_trim) * demax * DEG_TO_RAD + elevator_tab;
94   else
95     elevator = (Long_control + Long_trim) * demin * DEG_TO_RAD + elevator_tab;
96
97   if (Rudder_pedal <= 0)
98     rudder = - Rudder_pedal * drmin * DEG_TO_RAD;
99   else
100     rudder = - Rudder_pedal * drmax * DEG_TO_RAD;
101
102   // flap routine
103   // check for lowest flap setting
104   if (Flap_handle < dfArray[1])
105     {
106       Flap_handle    = dfArray[1];
107       prevFlapHandle = Flap_handle;
108       flap           = Flap_handle;
109     }
110   // check for highest flap setting
111   else if (Flap_handle > dfArray[ndf])
112     {
113       Flap_handle      = dfArray[ndf];
114       prevFlapHandle   = Flap_handle;
115       flap             = Flap_handle;
116     }
117   // otherwise in between
118   else          
119     {
120       if(Flap_handle != prevFlapHandle)
121         {
122           flaps_in_transit = true;
123         }
124       if(flaps_in_transit)
125         {
126           int iflap = 0;
127           while (dfArray[iflap] < Flap_handle)
128             {
129               iflap++;
130             }
131           if (flap < Flap_handle)
132             {
133               if (TimeArray[iflap] > 0)
134                 flap_transit_rate = (dfArray[iflap] - dfArray[iflap-1]) / TimeArray[iflap+1];
135               else
136                 flap_transit_rate = (dfArray[iflap] - dfArray[iflap-1]) / 5;
137             }
138           else 
139             {
140               if (TimeArray[iflap+1] > 0)
141                 flap_transit_rate = (dfArray[iflap] - dfArray[iflap+1]) / TimeArray[iflap+1];
142               else
143                 flap_transit_rate = (dfArray[iflap] - dfArray[iflap+1]) / 5;
144             }
145           if(fabs (flap - Flap_handle) > dt * flap_transit_rate)
146             flap += flap_transit_rate * dt;
147           else
148             {
149               flaps_in_transit = false;
150               flap = Flap_handle;
151             }
152         }
153     }
154   prevFlapHandle = Flap_handle;
155
156   return;
157 }
158
159 // end uiuc_aerodeflections.cpp