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;
87 static double elev_trim;
89 //if (use_uiuc_network)
95 // if (pitch_trim_down)
97 // if (elev_trim > 1.0)
99 // if (elev_trim < -1.0)
101 // if (outside_control)
103 // pilot_elev_no = true;
104 // pilot_ail_no = true;
105 // pilot_rud_no = true;
106 // pilot_throttle_no = true;
107 // Long_trim = elev_trim;
117 if (Lat_control <= 0)
118 aileron = - Lat_control * damin * DEG_TO_RAD;
120 aileron = - Lat_control * damax * DEG_TO_RAD;
126 elevator = Long_trim * demax * DEG_TO_RAD;
127 demax_remain = demax + Long_trim * demax;
128 demin_remain = -1*Long_trim * demax + demin;
129 if (Long_control <= 0)
130 elevator += Long_control * demax_remain * DEG_TO_RAD;
132 elevator += Long_control * demin_remain * DEG_TO_RAD;
136 elevator = Long_trim * demin * DEG_TO_RAD;
137 demin_remain = demin - Long_trim * demin;
138 demax_remain = Long_trim * demin + demax;
139 if (Long_control >=0)
140 elevator += Long_control * demin_remain * DEG_TO_RAD;
142 elevator += Long_control * demax_remain * DEG_TO_RAD;
147 if ((Long_control+Long_trim) <= 0)
148 elevator = (Long_control + Long_trim) * demax * DEG_TO_RAD;
150 elevator = (Long_control + Long_trim) * demin * DEG_TO_RAD;
153 if (Rudder_pedal <= 0)
154 rudder = - Rudder_pedal * drmin * DEG_TO_RAD;
156 rudder = - Rudder_pedal * drmax * DEG_TO_RAD;
159 if (old_flap_routine)
162 // check for lowest flap setting
163 if (Flap_handle < dfArray[1])
165 Flap_handle = dfArray[1];
166 prevFlapHandle = Flap_handle;
169 // check for highest flap setting
170 else if (Flap_handle > dfArray[ndf])
172 Flap_handle = dfArray[ndf];
173 prevFlapHandle = Flap_handle;
176 // otherwise in between
179 if(Flap_handle != prevFlapHandle)
181 flaps_in_transit = true;
186 while (dfArray[iflap] < Flap_handle)
190 if (flap < Flap_handle)
192 if (TimeArray[iflap] > 0)
193 flap_transit_rate = (dfArray[iflap] - dfArray[iflap-1]) / TimeArray[iflap+1];
195 flap_transit_rate = (dfArray[iflap] - dfArray[iflap-1]) / 5;
199 if (TimeArray[iflap+1] > 0)
200 flap_transit_rate = (dfArray[iflap] - dfArray[iflap+1]) / TimeArray[iflap+1];
202 flap_transit_rate = (dfArray[iflap] - dfArray[iflap+1]) / 5;
204 if(fabs (flap - Flap_handle) > dt * flap_transit_rate)
205 flap += flap_transit_rate * dt;
208 flaps_in_transit = false;
213 prevFlapHandle = Flap_handle;
218 // designed for the twin otter non-linear model
219 if (outside_control == false)
221 flap_percent = Flap_handle / 30.0; // percent of flaps desired
222 if (flap_percent>=0.31 && flap_percent<=0.35)
223 flap_percent = 1.0 / 3.0;
224 if (flap_percent>=0.65 && flap_percent<=0.69)
225 flap_percent = 2.0 / 3.0;
227 flap_goal = flap_percent * flap_max; // angle of flaps desired
228 flap_moving_rate = flap_rate * dt; // amount flaps move per time step
230 // determine flap position with respect to the flap goal
231 if (flap_pos < flap_goal)
233 flap_pos += flap_moving_rate;
234 if (flap_pos > flap_goal)
235 flap_pos = flap_goal;
237 else if (flap_pos > flap_goal)
239 flap_pos -= flap_moving_rate;
240 if (flap_pos < flap_goal)
241 flap_pos = flap_goal;
248 // end uiuc_aerodeflections.cpp