Debian Codegraph @

Aircraft/Generic/wingflexer.nas

raw
1 # wingflexer.nas - A simple wing flex model.
2 #
3 # Copyright (C) 2014 Thomas Albrecht
4 #
5 # This program is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU General Public License as
7 # published by the Free Software Foundation; either version 2 of the
8 # License, or (at your option) any later version.
9 #
10 # This program is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 # General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18
19 #
20 # -->
21 # g
22 # +-----+ +-----+
23 # <--- | m_w |---/\/\/\---| |
24 # +-----+ +-----+
25 # Lift wing spring fuselage
26 # force mass
27 #
28 # We integrate
29 #
30 # .. k d . 0.5*F_L ..
31 # 0 = -z + --- z + ---- z - ------- - g - z_f
32 # m_w m_w m_w
33 #
34 # where
35 #
36 # z : deflection
37 # k : wing stiffness
38 # d : damping
39 # m_w = m_dw + fuel_frac * m_fuel
40 # Total wing mass. Because the fuel is distributed over the wing, we use
41 # a fraction of the fuel mass in the calculation.
42 # 0.5*F_L : lift force/2 (we look at one wing only)
43 # ..
44 # z_f : acceleration of the frame of reference (fuselage)
45 #
46 # and write the deflection (z + z_ofs) in meters to /sim/model/wing-flex/z-m.
47 # The offset z_ofs is calculated automatically and ensures that the dry wing
48 # (which still has a non-zero mass) creates neutral deflection.
49 #
50 # Discretisation by first order finite differences:
51 #
52 # z_0 - 2 z_1 + z_2 k d (z_0 - z_1) 1/2 F_L ..
53 # ----------------- + --- z_1 + --- ----------- - ------- - g - z_f = 0
54 # dt^2 m_w m_w dt m_w
55 #
56 # It is convenient to divide k and d by a (constant) reference mass:
57 #
58 # K = k / m_dw
59 # D = d / m_dw
60 #
61 # To adapt this to your aircraft, you need m_w, K, D.
62 # How to estimate these?
63 #
64 # 1. Assume a dry wing mass m_dw. Research the wing fuel mass m_fuel.
65 #
66 # 2. Obtain estimates of
67 # - the deflection z_flight in level flight, e.g by comparing photos
68 # of the real aircraft on ground and in air,
69 # - the wing's eigenfrequency, perhaps from videos of the wing's oscillation in
70 # turbulence,
71 # - the deflection with full and empty tanks while sitting on the ground.
72 #
73 # 3. Compute K to match in flight deflection with full tanks:
74 # K = g * (m_ac / 2 - (fuel_frac * m_fuel)) / (z_in_flight / z_fac) / m_dw
75 #
76 # where
77 # m_ac : aircraft mass
78 # g : 9.81 m/s^2
79 # z_fac: scaling factor for the deflection, start with 1.
80 #
81 # 4. Compute the eigenfrequency of this system for full and empty wing tanks:
82 # f_full = sqrt(K * m_dw / (m_dw + fuel_frac * m_fuel)) / (2 pi)
83 # f_empty = sqrt(K) / (2 pi)
84 #
85 # Ideally we want our model to match the eigenfrequency, the deflection
86 # while sitting on the ground with full or empty tanks, and the deflection
87 # during a hard landing. Getting real-world data for the latter is difficult.
88 #
89 # There's a python script wingflexer.py which assists you in tuning the parameters.
90 #
91 # Here are some relations:
92 # - a lower wing mass increases the eigenfrequency, and weakens the touchdown bounce
93 # - a higher stiffness K reduces the deflection and increases the eigenfrequency
94 #
95 # The 787 is known for its very flexible wings; the deflection in
96 # unaccelerated flight is quoted as z = 3 m. One wing tank of FG's 787-8 holds
97 # 23,000 kg of fuel. Because the fuel is distributed over the wing, we use a
98 # fraction of the fuel mass in the calculation: fuel_frac = 0.75. For the same reason
99 # we don't use the true wing mass, but rather something that makes our model look
100 # plausible.
101 #
102 # So assuming a wing mass of 12000 kg, we get K=25.9 and f_empty = 0.5 Hz.
103 # That frequency might be a bit low, videos of a 777 wing in turbulence show about
104 # 2-3 Hz. (I didn't research 787 videos).
105 #
106 # To increase it, we could either reduce m_dw or increase K. A lower m_dw results
107 # in a rather weak bounce on touchdown which might look odd. A higher K reduces
108 # the deflection z_flight, but we can simply scale the animation to account for
109 # that. We'll multiply the deflection z by a factor z_fac to get an angle for the
110 # <rotate> animation later on anyway. So repeat 3. and 4. using e.g. z_fac = 10.
111 # Now K = 259 and f_empty=2.6 Hz. While our model spring now only deflects
112 # to 0.3 m instead of 3 m, the animation scale factor will make sure the wing
113 # bends to 3 m. This way, we can match both eigenfrequency and observed deflection,
114 # and still get a realistic bounce on touch down. Finally, adjust D such that an
115 # impulse is damped out after about one or two oscillations; D = 12 seems to work
116 # OK in our example.
117 #
118 # It's difficult to get real-world data on the deflection during touchdown.
119 # Touchdown at more than 10 ft/s is considered a hard landing. There's a video of
120 # a hard landing of an A346 (http://avherald.com/h?article=471e70e9), showing the
121 # wings bend perhaps 1 m. But I couldn't find any data for the acceleration over
122 # time during a hard landing.
123 #
124 # To assist you in tuning parameters for the touchdown bounce we can give our
125 # wing mass the touchdown vertical speed via /sim/model/wing-flex/sink-rate_fps.
126 #
127 # Our model outputs the deflection in meters, but the <rotate> animation expects an
128 # angle. It is up to you calculate an appropriate factor, depending on your wing
129 # span and number of segments in the animation. Also don't forget to include z_fac.
130 #
131 # To use this with your JSBSim aircraft, use
132 #
133 # io.include("Aircraft/Generic/wingflexer.nas");
134 # WingFlexer.new(1, K, D, mass_dry_wing_kg,
135 # fuel_fraction, fuel_node_left, fuel_node_right);
136 #
137 # with apropriate parameters.
138 #
139 # Yasim does not write the lift to the property tree. But you can create a helper
140 # function which computes the lift as
141 # lift_force_lbs = aircraft_weight_lbs * load_factor - total_weight_on_wheels_lbs
142 # and write lift_force_lbs to /fdm/jsbsim/forces/fbz-aero-lbs (or another location
143 # passed to WingFlexer.new() as lift_node).
144 #
145 # TODO
146 # - write Yasim helper
147 # - perhaps use analytical solution of ODE
148 # - input for fuselage acceleration should rather be acceleration at CG -- find property
149
150 io.include("Aircraft/Generic/updateloop.nas");
151
152 var WingFlexer = {
153 parents: [Updatable],
154
155 # FIXME: these defaults make the 787-8 wing flex look realistic, which is certainly not
156 # the most generic airliner wing. Once someone obtains a set of parameters for e.g.
157 # the 777, use them here.
158
159 new: func(enable = 1, K=259., D=12., mass_dry_wing_kg = 12000., fuel_fraction = 0.75,
160 fuel_node_left = "consumables/fuel/tank/level-kg",
161 fuel_node_right = "consumables/fuel/tank[1]/level-kg",
162 node = "sim/model/wing-flex/", lift_node = "fdm/jsbsim/forces/fbz-aero-lbs") {
163 var m = { parents: [WingFlexer] };
164 m.node = node;
165 m.m_dw = mass_dry_wing_kg;
166 m.k = K * m.m_dw;
167 m.d = D * m.m_dw;
168 m.fuel_frac_on_2 = fuel_fraction / 2.; # so we don't have to divide each frame
169 m.fuel_node_left = fuel_node_left;
170 m.fuel_node_right = fuel_node_right;
171 m.lift_node = lift_node;
172 m.loop = UpdateLoop.new(components: [m], enable: enable);
173 return m;
174 },
175
176 reset: func {
177
178 me.z = 0.;
179 me.z1 = 0.;
180 me.z2 = 0.;
181
182 setprop(me.node ~ "z-m", 0.);
183 setprop(me.node ~ "mass-wing-kg", me.m_dw);
184 setprop(me.node ~ "K", me.k/me.m_dw);
185 setprop(me.node ~ "D", me.d/me.m_dw);
186 setprop(me.node ~ "fuel-fac", me.fuel_frac_on_2 * 2);
187 setprop(me.node ~ "sink-rate_fps", 0.);
188 me.g_on_2_times_LB2KG = getprop("/environment/gravitational-acceleration-mps2") / 2. * globals.LB2KG;
189 me.calc_z_ofs();
190
191 setlistener(me.node ~ "mass-wing-kg", func(the_node) {
192 me.m_dw = the_node.getValue();
193 me.calc_z_ofs();
194 }, 0, 0);
195 setlistener(me.node ~ "K", func(the_node) {
196 me.k = the_node.getValue() * me.m_dw;
197 me.calc_z_ofs();
198 }, 0, 0);
199 setlistener(me.node ~ "D", func(the_node) { me.d = the_node.getValue() * me.m_dw; }, 0, 0);
200 setlistener(me.node ~ "fuel-fac", func(the_node) { me.fuel_frac_on_2 = the_node.getValue() / 2.; }, 0, 0);
201
202 # The following helped me getting wing flex look OK. It's no longer
203 # needed once you get the parameters right, so it's disabled by default.
204 # Look for DEV to re-enable.
205 # Include z-fac here, so you don't have to adjust the animation .xml
206 # setprop(me.node ~ "z-fac", 3.);
207 # me.last_dt = 1/30.;
208 # me.max_z = 0.;
209 # setlistener(me.node ~ "sink-rate_fps", func(the_node) {
210 # var dz = me.last_dt * the_node.getValue() * globals.FT2M;
211 # me.z0 = me.z1 - dz;
212 # me.z2 = me.z1 + dz;
213 # me.max_z = 0.;
214 # }, 1, 0);
215 },
216
217 calc_z_ofs: func() {
218 print ("wingflex: calc z_ofs");
219 me.z_ofs = getprop("/environment/gravitational-acceleration-mps2") * me.m_dw / me.k;
220 },
221
222 update: func(dt) {
223 # limit time step to avoid numerical instability
224 if (dt > 0.2) dt = 0.2;
225
226 # DEV:
227 # me.last_dt = dt;
228
229 # fuselage z (up) acceleration in m/s^2
230 # we get -g in unaccelerated flight, and large negative numbers on touchdown
231 var a_f = getprop("accelerations/pilot/z-accel-fps_sec") * globals.FT2M;
232
233 # lift force. Convert to N and use 1/2 (one wing only)
234 var F_l = getprop(me.lift_node) * me.g_on_2_times_LB2KG;
235
236 # compute total mass of one wing, using the average fuel mass in both wing tanks.
237 # The averaging factor 0.5 is lumped into fuel_frac_on_2
238 me.m = me.m_dw + me.fuel_frac_on_2 * (getprop(me.fuel_node_left) + getprop(me.fuel_node_right));
239
240 # integrate discretised equation of motion
241 # reverse sign of F_l because z in JSBsim body coordinate system points down
242 me.z = (2.*me.z1 - me.z2 + dt * ((me.d * me.z1 + dt * (-F_l - me.k * me.z1))/me.m + dt *
243 a_f)) / (1. + me.d * dt / me.m);
244 me.z2 = me.z1;
245 me.z1 = me.z;
246
247 me.z += me.z_ofs;
248
249 # output to property
250 setprop(me.node ~ "z-m", me.z);
251
252 # DEV: scale output and log max deflection
253 # var z_fac = getprop(me.node ~ "z-fac");
254 # if (me.z * z_fac < me.max_z) me.max_z = me.z * z_fac;
255 # print (sprintf(" z %4.2f max %4.2f m %7.1f", me.z * z_fac, me.max_z, me.m));
256 # setprop(me.node ~ "z-m", me.z * z_fac);
257 },
258
259 enable: func { me.loop.enable() },
260 disable: func { me.loop.disable() },
261 };
262
263
264