1 /**********************************************************************
3 FILENAME: uiuc_aerodeflections.cpp
5 ----------------------------------------------------------------------
7 DESCRIPTION: determine the aero control surface deflections
12 ----------------------------------------------------------------------
16 ----------------------------------------------------------------------
18 REFERENCES: based on deflection portions of c172_aero.c and
21 ----------------------------------------------------------------------
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
27 11/12/2001 (RD) added new flap routine. Needed for
28 Twin Otter non-linear model
30 ----------------------------------------------------------------------
32 AUTHOR(S): Jeff Scott <jscott@mail.com>
33 Robert Deters <rdeters@uiuc.edu>
34 Michael Selig <m-selig@uiuc.edu>
36 ----------------------------------------------------------------------
40 ----------------------------------------------------------------------
44 ----------------------------------------------------------------------
48 ----------------------------------------------------------------------
52 ----------------------------------------------------------------------
56 ----------------------------------------------------------------------
58 COPYRIGHT: (C) 2000 by Michael Selig
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.
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.
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.
74 **********************************************************************/
78 #include "uiuc_aerodeflections.h"
80 void uiuc_aerodeflections( double dt )
82 double prevFlapHandle = 0.0f;
83 double flap_transit_rate;
84 bool flaps_in_transit = false;
93 aileron = - Lat_control * damin * DEG_TO_RAD;
95 aileron = - Lat_control * damax * DEG_TO_RAD;
97 if ((Long_control+Long_trim) <= 0)
98 elevator = (Long_control + Long_trim) * demax * DEG_TO_RAD;
100 elevator = (Long_control + Long_trim) * demin * DEG_TO_RAD;
102 if (Rudder_pedal <= 0)
103 rudder = - Rudder_pedal * drmin * DEG_TO_RAD;
105 rudder = - Rudder_pedal * drmax * DEG_TO_RAD;
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
118 // determine flap position with respect to the flap goal
119 if (flap_pos < flap_goal)
121 flap_pos += flap_moving_rate;
122 if (flap_pos > flap_goal)
123 flap_pos = flap_goal;
125 else if (flap_pos > flap_goal)
127 flap_pos -= flap_moving_rate;
128 if (flap_pos < flap_goal)
129 flap_pos = flap_goal;
134 // check for lowest flap setting
135 if (Flap_handle < dfArray[1])
137 Flap_handle = dfArray[1];
138 prevFlapHandle = Flap_handle;
141 // check for highest flap setting
142 else if (Flap_handle > dfArray[ndf])
144 Flap_handle = dfArray[ndf];
145 prevFlapHandle = Flap_handle;
148 // otherwise in between
151 if(Flap_handle != prevFlapHandle)
153 flaps_in_transit = true;
158 while (dfArray[iflap] < Flap_handle)
162 if (flap < Flap_handle)
164 if (TimeArray[iflap] > 0)
165 flap_transit_rate = (dfArray[iflap] - dfArray[iflap-1]) / TimeArray[iflap+1];
167 flap_transit_rate = (dfArray[iflap] - dfArray[iflap-1]) / 5;
171 if (TimeArray[iflap+1] > 0)
172 flap_transit_rate = (dfArray[iflap] - dfArray[iflap+1]) / TimeArray[iflap+1];
174 flap_transit_rate = (dfArray[iflap] - dfArray[iflap+1]) / 5;
176 if(fabs (flap - Flap_handle) > dt * flap_transit_rate)
177 flap += flap_transit_rate * dt;
180 flaps_in_transit = false;
185 prevFlapHandle = Flap_handle;
190 // end uiuc_aerodeflections.cpp