]> git.mxchange.org Git - flightgear.git/blob - src/FDM/UIUCModel/uiuc_aerodeflections.cpp
Code clean ups relating to FGOptions ... and moved it into globals-> space.
[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, flap_transit_rate;
78   bool flaps_in_transit;
79
80   if (zero_Long_trim)
81     {
82       Long_trim = 0;
83       //elevator_tab = 0;
84     }
85
86   if (Lat_control <= 0)
87     aileron = - Lat_control * damin * DEG_TO_RAD;
88   else
89     aileron = - Lat_control * damax * DEG_TO_RAD;
90
91   if ((Long_control+Long_trim) <= 0)
92     elevator = (Long_control + Long_trim) * demax * DEG_TO_RAD + elevator_tab;
93   else
94     elevator = (Long_control + Long_trim) * demin * DEG_TO_RAD + elevator_tab;
95
96   if (Rudder_pedal <= 0)
97     rudder = - Rudder_pedal * drmin * DEG_TO_RAD;
98   else
99     rudder = - Rudder_pedal * drmax * DEG_TO_RAD;
100
101   // flap routine
102   // check for lowest flap setting
103   if (Flap_handle < dfArray[1])
104     {
105       Flap_handle    = dfArray[1];
106       prevFlapHandle = Flap_handle;
107       flap           = Flap_handle;
108     }
109   // check for highest flap setting
110   else if (Flap_handle > dfArray[ndf])
111     {
112       Flap_handle      = dfArray[ndf];
113       prevFlapHandle   = Flap_handle;
114       flap             = Flap_handle;
115     }
116   // otherwise in between
117   else          
118     {
119       if(Flap_handle != prevFlapHandle)
120         {
121           flaps_in_transit = true;
122         }
123       if(flaps_in_transit)
124         {
125           int iflap = 0;
126           while (dfArray[iflap] < Flap_handle)
127             {
128               iflap++;
129             }
130           if (flap < Flap_handle)
131             {
132               if (TimeArray[iflap] > 0)
133                 flap_transit_rate = (dfArray[iflap] - dfArray[iflap-1]) / TimeArray[iflap+1];
134               else
135                 flap_transit_rate = (dfArray[iflap] - dfArray[iflap-1]) / 5;
136             }
137           else 
138             {
139               if (TimeArray[iflap+1] > 0)
140                 flap_transit_rate = (dfArray[iflap] - dfArray[iflap+1]) / TimeArray[iflap+1];
141               else
142                 flap_transit_rate = (dfArray[iflap] - dfArray[iflap+1]) / 5;
143             }
144           if(fabs (flap - Flap_handle) > dt * flap_transit_rate)
145             flap += flap_transit_rate * dt;
146           else
147             {
148               flaps_in_transit = false;
149               flap = Flap_handle;
150             }
151         }
152     }
153   prevFlapHandle = Flap_handle;
154
155   return;
156 }
157
158 // end uiuc_aerodeflections.cpp