create changelog entry
[debian/openrocket] / core / doc / techdoc / chapter-flight-simulation.tex
1
2
3 \chapter{Flight simulation}
4 \label{chap-simulation}
5
6 In this chapter the actual flight simulation is analyzed.  First in
7 Section~\ref{sec-atmospheric-properties} methods for simulating
8 atmospheric conditions and wind are presented.  Then in
9 Section~\ref{sec-flight-modeling} the actual simulation procedure is
10 developed.
11
12
13
14 \section{Atmospheric properties}
15 \label{sec-atmospheric-properties}
16
17 In order to calculate the aerodynamic forces acting on the rocket it
18 is necessary to know the prevailing atmospheric conditions.  Since the
19 atmosphere is not constant with altitude, a model must be developed to
20 account for the changes.  Wind also plays an important role in the
21 flight of a rocket, and therefore it is important to have a realistic
22 wind model in use during the simulation.
23
24
25 \subsection{Atmospheric model}
26
27 The atmospheric model is responsible to estimating the atmospheric
28 conditions at varying altitudes.  The properties that are of most
29 interest are the density of air $\rho$ (which is a scaling parameter
30 to the aerodynamic coefficients via the dynamic pressure
31 $\frac{1}{2}\rho v^2$) and the speed of sound $c$ (which affects the
32 Mach number of the rocket, which in turn affects its aerodynamic
33 properties).  These may in turn be calculated from the air pressure
34 $p$ and temperature $T$.
35
36 Several models exist that define standard atmospheric conditions as a
37 function of altitude, including the Internaltional Standard
38 Atmosphere (ISA)~\cite{international-standard-atmosphere} and the
39 U.S. Standard Atmosphere~\cite{US-standard-atmosphere}.  These two
40 models yield identical temperature and pressure profiles for altitudes
41 up to 32~km.
42
43 The models are based on the assumption that air follows the ideal gas
44 law
45 %
46 \begin{equation}
47 \rho = \frac{Mp}{RT}
48 \end{equation}
49 %
50 where $M$ is the molecular mass of air and $R$ is the ideal gas
51 constant.  From the equilibrium of hydrostatic forces the differential
52 equation for pressure as a function of altitude $z$ can be found as
53 %
54 \begin{equation}
55 \dif p = -g_0 \rho \dif z = -g_0 \frac{Mp}{RT} \dif z
56 \label{eq-pressure-altitude}
57 \end{equation}
58 %
59 where $g_0$ is the gravitational acceleration.  If the temperature of
60 air were to be assumed to be constant, this would yield an exponential
61 diminishing of air pressure.
62
63 The ISA and U.S. Standard Atmospheres further specity a standard
64 temperature and pressure at sea level and a temperature profile for
65 the atmosphere.  The temperature profile is given as eight
66 temperatures for different altitudes, which are then linearly
67 interpolated.  The temperature profile and base pressures for the ISA
68 model are presented in Table~\ref{table-ISA-model}.  These values
69 along with equation~(\ref{eq-pressure-altitude}) define the
70 temperature/pressure profile as a function of altitude.
71
72 \begin{table}
73 \caption{Layers defined in the International Standard
74   Atmosphere~\cite{wiki-ISA-layers}}
75 \label{table-ISA-model}
76 \begin{center}
77 \begin{tabular}{ccccl}
78 \hline
79 Layer & Altitude$^\dagger$ & Temperature & Lapse rate &
80                                                 \multicolumn{1}{c}{Pressure} \\
81       &  m       &  $^\circ$C  & $^\circ$C/km & \multicolumn{1}{c}{Pa} \\
82 \hline
83 0     & 0        & $+15.0$     & $-6.5$       & 101\s325 \\
84 1     & 11\s000  & $-56.5$     & $+0.0$       & \num22\s632 \\
85 2     & 20\s000  & $-56.5$     & $+1.0$       & \num\num5\s474.9 \\
86 3     & 32\s000  & $-44.5$     & $+2.8$       & \num\num\num\s868.02 \\
87 4     & 47\s000  & \num$-2.5$  & $+0.0$       & \num\num\num\s110.91 \\
88 5     & 51\s000  & \num$-2.5$  & $-2.8$       & \num\num\num\s\num66.939 \\
89 6     & 71\s000  & $-58.5$     & $-2.0$       & \num\num\num\s\num\num3.9564 \\
90 7     & 84\s852  & $-86.2$     &              & \num\num\num\s\num\num0.3734 \\
91 \hline
92 \end{tabular}
93 \end{center}
94 \vspace{-3mm}
95 {\footnotesize $^\dagger$ Altitude is the geopotential height which
96   does not account for the diminution of gravity at high altitudes.}
97 \vspace{3mm}
98 \end{table}
99
100 These models are totally static and do not take into account any local
101 flight conditions.  Many rocketeers may be interested in flight
102 differences during summer and winter and what kind of effect air pressure
103 has on the flight.  These are also parameters that can easily be
104 measured on site when launching rockets.  On the other hand, it is
105 generally hard to know a specific temperature profile for a specific
106 day.  Therefore the atmospheric model was extended to allow the user
107 to specify the base conditions either at mean sea level or at the
108 altitude of the launch site.  These values are simply assigned to the
109 first layer of the atmospheric model.  Most model rockets do not
110 exceed altitudes of a few kilometers, and therefore the flight
111 conditions at the launch site will dominate the flight.
112
113 One parameter that also has an effect on air density and the speed of
114 sound is humidity.  The standard models do not include any definition
115 of humidity as a function of altitude.  Furthermore, the effect of
116 humidity on air density and the speed of sound is marginal.  The
117 difference in air density and the speed of sound between completely dry
118 air and saturated air at standard conditions are both less than 1\%.
119 Therefore the effect of humidity has been ignored.
120
121
122
123
124 \subsection{Wind modeling}
125
126 Wind plays a critical role in the flight of model rockets.  As has
127 been seen, large angles of attack may cause rockets to lose a
128 significant amount of stability and even go unstable.  Over-stable
129 rockets may weathercock and turn into the wind.  In a perfectly static
130 atmosphere a rocket would, in principle, fly its entire flight
131 directly upwards at zero angle of attack.  Therefore, the effect of
132 wind must be taken into account in a full rocket simulation.
133
134 Most model rocketeers, however, do not have access to a full wind
135 profile of the area they are launching in.  Different layers of air
136 may have different wind velocities and directions.  Modeling such
137 complex patterns is beyond the scope of this project. Therefore, the
138 goal is to produce a realistic wind model that can be specified with
139 only a few parameters understandable to the user and that covers
140 altitudes of most rocket flights.  Extensions to allow for multiple
141 air layers may be added in the future.
142
143 In addition to a constant average velocity, wind always has some
144 degree of turbulence in it.  The effect of turbulence can be modeled
145 by summing the steady flow of air and a random, zero-mean turbulence
146 velocity.  Two central aspects of the turbulence velocity are the
147 amplitude of the variation and the frequencies at which they occur.
148 Therefore a reasonable turbulence model is achieved by a random
149 process that produces a sequence with a similar distribution and
150 frequency spectrum as that of real wind.
151
152 Several models of the spectrum of wind turbulence at specific
153 altitudes exist.  Two commonly used such spectra are the {\it Kaimal}
154 and {\it von Kármán} wind turbulence
155 spectra~\cite[p.~23]{wind-energy-handbook}:
156 %
157 \begin{eqnarray}
158 \mbox{Kaimal:} & & \frac{S_u(f)}{\sigma_u^2} =
159     \frac{4 L_{1u} / U}{(1 + 6fL_{1u}/U)^{5/3}} \label{eq-kaimal-wind} \\
160 %
161 \mbox{von Kármán:} & & \frac{S_u(f)}{\sigma_u^2} =
162     \frac{4 L_{2u} / U}{(1 + 70.8(fL_{2u}/U)^2)^{5/6}} \label{eq-karman-wind}
163 \end{eqnarray}
164
165 Here $S_u(f)$ is the spectral density function of the turbulence
166 velocity and $f$ the turbulence frequency, $\sigma_u$ the standard
167 deviation of the turbulence velocity, $L_{1u}$ and $L_{2u}$ length
168 parameters and $U$ the average wind speed.
169
170 Both models approach the asymptotic limit 
171 $S_u(f)/\sigma_u^2 \sim f^{-5/3}$ quite fast.  Above frequencies of
172 0.5~Hz the difference between equation~(\ref{eq-kaimal-wind}) and the
173 same equation without the term 1 in the denominator is less than 4\%.
174 Since the time scale of a model rocket's flight is quite short, the
175 effect of extremely low frequencies can be ignored.  Therefore
176 turbulence may reasonably well be modelled by utilizing 
177 {\it pink noise} that has a spectrum of $1/f^\alpha$ with $\alpha=5/3$.
178 True pink noise has the additional useful property of being
179 scale-invariant.  This means that a stream of pink noise samples may
180 be generated and assumed to be at any sampling rate while maintaining
181 their spectral properties.
182
183 Discerete samples of pink noise with spectrum $1/f^\alpha$ can be
184 generated by applying a suitable digital filter to {\it white noise},
185 which is simply uncorrelated pseudorandom numbers.  One such filter is
186 the infinite impulse response (IIR) filter presented by
187 Kasdin~\cite{pink-filter}:
188 %
189 \begin{equation}
190 x_n = w_n - a_1 x_{n-1} - a_2 x_{n-2} - a_3 x_{n-3} - \ldots
191 \label{eq-pink-generator}
192 \end{equation}
193 %
194 where $x_i$ are the generated samples, $w_n$ is a generated white
195 random number and the coefficients are computed using
196 %
197 \begin{equation}
198 \begin{array}{rl}
199 a_0 & = 1 \\
200 a_k & = \del{k-1-\frac{\alpha}{2}} \frac{a_{k-1}}{k}.
201 \end{array}
202 \label{eq-pink-coefficients}
203 \end{equation}
204 %
205 The infinite sum may be truncated with a suitable number of terms.
206 In the context of IIR filters these terms are calles {\it poles}.
207 Experimentation showed that already 1--3 poles provides a reasonably
208 accurate frequency spectrum in the high frequency range.
209
210 One problem in using pink noise as a turbulence velocity
211 model is that the power spectrum of pure pink noise goes to
212 infinity at very low frequencies.  This means that a long sequence
213 of random values may deviate significantly from zero.  However, when
214 using the truncated IIR filter of equation~(\ref{eq-pink-generator}),
215 the spectrum density becomes constant below a certain limiting
216 frequency, dependent on the number of poles used.  By adjusting the
217 number of poles used, the limiting frequency can be adjusted to a value
218 suitable for model rocket flight.  Specifically, the number of poles
219 must be selected such that the limiting frequency is suitable at the
220 chosen sampling rate.  
221
222 It is also desirable that the simulation resolution does not affect
223 the wind conditions.  For example, a simulation with a time step of
224 10~ms should experience the same wind conditions as a simulation with
225 a time step of 5~ms.  This is achieved by selecting a constant
226 turbulence generation frequency and interpolating between the
227 generated points when necessary.  The fixed frequency was chosen at
228 20~Hz, which can still simulate fluctuations at a time scale of 0.1
229 seconds.
230
231 \begin{figure}[p]
232 \centering
233 \epsfig{file=figures/wind/pinktime, width=105mm}
234 \caption{The effect of the number of IIR filter poles on two 20 second
235   samples of generated turbulence, normalized so that the two-pole
236   sequence has standard deviation one.}
237 \label{fig-pink-poles}
238 \end{figure}
239
240 \begin{figure}[p]
241 \centering
242 \epsfig{file=figures/wind/pinkfreq, width=95mm}
243 \caption{The average power spectrum of 100 turbulence
244   simulations using a two-pole IIR filter (solid) and the Kaimal
245   turbulence spectrum (dashed); vertical axis arbitrary.}
246 \label{fig-pink-spectrum}
247 \end{figure}
248
249
250
251 The effect of the number of poles is depicted in
252 Figure~\ref{fig-pink-poles}, where two pink noise sequences were
253 generated from the same random number source with two-pole and
254 ten-pole IIR filters.  A small number of poles generates values strongly
255 centered on zero, while a larger number of poles introduces more low
256 frequency variability.  Since the free-flight time of a typical model
257 rocket is of the order of 5--30 seconds, it is desireable that the
258 maximum gust length during the flight is substantially shorter than
259 this.  Therefore the pink noise generator used by the wind model was
260 chosen to contain only two poles, which has a limiting frequency of
261 approximately 0.3~Hz when sampled at 20~Hz.  This means that gusts of
262 wind longer than 3--5 seconds will be rare in the simulted turbulence,
263 which is a suitable gust length for modeling typical model rocket
264 flight. Figure~\ref{fig-pink-spectrum} depicts the resulting pink
265 noise spectrum of the two-pole IIR filter and the Kaimal spectrum of
266 equation~(\ref{eq-kaimal-wind}) scaled to match each other.
267
268
269 %, which causes frequency
270 %components below approximately 0.3~Hz to be subdued.  Therefore, gusts
271 %of wind longer than 3--5 seconds will be rare in the simulated wind, a
272 %suitable time scale for the flight of a model rocket.
273 %Figure~\ref{fig-turbulence}(a) shows a 20 second sample of the
274 %generated turbulence, normalized to have a standard deviation of one.
275 %Figure~\ref{fig-turbulence}(b) depicts the actual frequency spectrum
276 %of the generated turbulence and the Kaimal spectrum of
277 %equation~(\ref{eq-kaimal-wind}) scaled to match each other.
278
279
280
281 To simplify the model, the average wind speed is assumed to be
282 constant with altitude and in a constant direction.  This allows
283 specifying the model parameters using just the average wind speed and
284 its standard deviation.  An alternative parameter for specifying the
285 turbulence amplitude is the {\it turbulence intensity}, which is the
286 percentage that the standard deviation is of the average wind
287 velocity,
288 %
289 \begin{equation}
290 I_u = \frac{\sigma_u}{U}.
291 \end{equation}
292 %
293 Wind farm load design standards typically specify turbulence
294 intensities around 10\ldots20\%~\cite[p.~22]{wind-energy-handbook}.
295 It is assumed that these intensities are at the top of the range of
296 conditions in which model rockets are typically flown.
297
298 Overall, the process to generate the wind velocity as a function of
299 time from the average wind velocity $U$ and standard deviation
300 $\sigma_u$ can be summarized in the following steps:
301 %
302 \begin{enumerate}
303 %\item[Input:]  Average wind velocity $U$ and standard deviation
304 %  $\sigma_u$.
305 %
306 \item Generate a pink noise sample $x_n$ from a Gaussian white noise
307   sample $w_n$ using equations~(\ref{eq-pink-generator}) and
308   (\ref{eq-pink-coefficients}) with two memory terms included.
309
310 \item Scale the sample to a standard deviation one.  This is performed
311   by dividing the value by a previously calculated standard deviation
312   of a long, unscaled pink noise sequence (2.252 for the two-pole IIR
313   filter).
314
315 \item The wind velocity at time $n\cdot\Delta t$ ($\Delta t = 0.05\rm~s$)
316   is $U_n = U + \sigma_u x_n$.  Velocities in between are interpolated.
317 \end{enumerate}
318
319
320
321
322 \section{Modeling rocket flight}
323 \label{sec-flight-modeling}
324
325
326 Modeling of rocket flight is based on Newton's laws.  The basic forces
327 acting upon a rocket are gravity, thrust from the motors and
328 aerodynamic forces and moments.  These forces and moments are
329 calculated and integrated numerically to yield a simulation over a
330 full flight.
331
332 Since most model rockets fly at a maximum a few kilometers high, the
333 curvature of the Earth is not taken into account.  Assuming a flat
334 Earth allows us to use simple Cartesian coordinates to represent the
335 position and altitude of the rocket.  As a consequence, the coriolis
336 effect when flying long distances north or south is not simulated
337 either.
338
339
340
341 \subsection{Coordinates and orientation}
342
343 During a rocket's flight many quantities, such as the aerodynamical
344 forces and thrust from the motors, are relative to the rocket itself,
345 while others, such as the position and gravitational force, are more
346 naturally described relative to the launch site.  Therefore two sets
347 of coordinates are defined, the {\it rocket coordinates}, which are
348 the same as used in Chapter~\ref{chap-aerodynamics}, and 
349 {\it world coordinates}, which is a fixed coordinate system with the
350 origin at the position of launch.
351
352 The position and velocity of a rocket are most naturally maintained as
353 Cartesian world coordinates.  Following normal convensions, the
354 $xy$-plane is selected to be parallel to the ground and the $z$-axis
355 is chosen to point upwards.  In flight dynamics of aircraft the
356 $z$-axis often points towards the earth, but in the case of rockets it
357 is natural to have the rocket's altitude as the $z$-coordinate.
358
359 Since the wind is assumed to be unidirectional and the Coriolis effect
360 is ignored, it may be assumed that the wind is directed along the
361 $x$-axis.  The angle of the launch rod may then be positioned relative
362 to the direction of the wind without any loss of generality.
363
364 Determining the orientation of a rocket is more complicated.  A
365 natural choise for defining the orientation would be to use the
366 spherical coordinate zenith and azimuth angles $(\theta, \phi)$ and an
367 additional roll angle parameter.  Another choise common in aviation is
368 to use {\it Euler angles}~\cite{wiki-euler-angles}.  However, both of
369 these systems have notable shortcomings.  Both systems have
370 singularity points, in which the value of some parameter is
371 ambiguous.  With spherical coordinates, this is the direction of the
372 $z$-axis, in which case the azimuth angle $\phi$ has no effect on the
373 position.  Rotations that occur near these points must often be
374 handled as special cases.  Furthermore, rotations in spherical
375 coordinate systems contain complex trigonometric formulae which are
376 prone to programming errors.
377
378 The solution to the singularity problem is to introduce an extra
379 parameter and an additional constraint to the system.  For example,
380 the direction of a rocket could be defined by a three-dimensional unit
381 vector $(x,y,z)$ instead of just the zenith and azimuth angles.  The
382 additional constraint is that the vector must be of unit length.  This
383 kind of representation has no singularity points which would require
384 special consideration.
385
386 Furthermore, Euler's rotation theorem states that a rigid body can be
387 rotated from any orientation to any other orientation by a single
388 rotation around a specific axis~\cite{wiki-euler-rotation-theorem}.
389 Therefore instead of defining quantities that define the orientation
390 of the rocket we can define a three-dimensional rotation that rotates
391 the rocket from a known reference orientation to the current
392 orientation. This has the additional advantage that the same rotation
393 and its inverse can be used to transform any vector between world
394 coordinates and rocket coordinates.
395
396 A simple and efficient way of descibing the 3D rotation is by using
397 {\it unit quaternions}.  Each unit quaternion corresponds to a unique
398 3D rotation, and they are remarkably simple to combine and use.  The
399 following section will present a brief overview of the properties of
400 quaternions.
401
402 The fixed reference orientation of the rocket defines the rocket
403 pointing towards the positive $z$-axis in world coordinates and an
404 arbitrary but fixed roll angle.  The orientation of the rocket is then
405 stored as a unit quaternion that rotates the rocket from this
406 reference orientation to its current orientation.  
407 This rotation can also be used to transform vectors from world
408 coordinates to rocket coordinates and its inverse from rocket
409 coordinates to world coordinates.  (Note that the rocket's initial
410 orientation on the launch pad may already be different than its
411 reference orientation if the launch rod is not completely vertical.)
412
413
414
415
416 \subsection{Quaternions}
417
418 {\it Quaternions} are an extension of complex numbers into four
419 dimensions.  The usefulness of quaternions arises from their use in
420 spatial rotations.  Similar to the way multiplication with a complex
421 number of unit length $e^{i\phi}$ corresponds to a rotation of angle
422 $\phi$ around the origin on the complex plane, multiplication with
423 unit quaternions correspond to specific 3D rotations around an axis.
424 A more thorough review of quaternions and their use in spatial
425 rotations is available in Wikipedia~\cite{wiki-quaternion-rotations}.
426
427 The typical notation of quaternions resembles the addition of a scalar
428 and a vector:
429 %
430 \begin{equation}
431 q = w + x\vi + y\vj + z\vk = w + \vect v
432 \end{equation}
433 %
434 Addition of quaternions and multiplication with a scalar operate as
435 expected.  However, the multiplication of two quaternions is
436 non-commutative (in general $ab \neq ba$) and follows the rules
437 %
438 \begin{equation}
439 \vi^2 = \vj^2 = \vk^2 = \vi\vj\vk = -1.
440 \end{equation}
441 %
442 As a corollary, the following equations hold:
443 %
444 \begin{equation}
445 \begin{array}{rl}
446 \vi\vj = \vk  \hspace{15mm}& \vj\vi = -\vk \\
447 \vj\vk = \vi  \hspace{15mm}& \vk\vj = -\vi \\
448 \vk\vi = \vj  \hspace{15mm}& \vi\vk = -\vj 
449 \end{array}
450 \end{equation}
451 %
452 The general multiplication of two quaternions becomes
453 %
454 \begin{equation}
455 \begin{array}{rl}
456 (a + b\vi + c\vj + d\vk)(w + x\vi + y\vj + z\vk)\;\; =
457  &   (aw-bx-cy-dz) \\
458  & + (ax+bw+cz-dy)\;\vi \\
459  & + (ay-bz+cw+dx)\;\vj \\
460  & + (az+by-cx+dw)\;\vk
461 \end{array}
462 \end{equation}
463 %
464 while the norm of a quaternion is defined in the normal manner
465 %
466 \begin{equation}
467 |q| = \sqrt{w^2+x^2+y^2+z^2}.
468 \end{equation}
469
470 The usefulness of quaternions becomes evident when we consider a
471 rotation around a vector $\vect u$, $|\vect u|=1$ by an angle $\phi$.
472 Let
473 %
474 \begin{equation}
475 q = \cos\frac{\phi}{2} + \vect u \sin\frac{\phi}{2}.
476 \label{eq-rotation-quaternion}
477 \end{equation}
478 %
479 Now the previously mentioned rotation of a three-dimensional vector
480 $\vect v$ defined by $\vi$, $\vj$ and $\vk$ is equivalent to the
481 quaternion product
482 %
483 \begin{equation}
484 \vect v \mapsto q\vect v q^{-1}.
485 \end{equation}
486 %
487 Similarly, the inverse rotation is equivalent to the transformation
488 %
489 \begin{equation}
490 \vect v \mapsto q^{-1} \vect v q.
491 \end{equation}
492 %
493 The problem simplifies even further, since for unit quaternions
494 %
495 \begin{equation}
496 q^{-1} = (w + x\vi + y\vj + z\vk)^{-1} = w - x\vi - y\vj - z\vk.
497 \end{equation}
498 %
499 Vectors can therefore be considered quaternions with no scalar
500 component and their rotation is equivalent to the left- and right-sided
501 multiplication with unit quaternions, requiring a total of 24
502 floating-point multiplications.  Even if this does not make the
503 rotations more efficient, it simplifies the trigonometry considerably
504 and therefore helps reduce programming errors.
505
506
507 \subsection{Mass and moment of inertia calculations}
508 \label{sec-mass-inertia}
509
510 Converting the forces and moments into linear and angluar acceleration
511 requires knowledge of the rocket's mass and moments of inertia.  The
512 mass of a component can be easily calculated from its volume and
513 density.  Due to the highly symmetrical nature of rockets, the rocket
514 centerline is commonly a principal axis for the moments of inertia.
515 Furthermore, the moments of inertia around the in the $y$- and
516 $z$-axes are very close to one another.  Therefore as a simplification
517 only two moments of inertia are calculated, the longitudal and
518 rotational moment of inertia.  These can be easily calculated for each
519 component using standard formulae~\cite{wiki-moments-of-inertia} and
520 combined to yield the moments of the entire rocket.
521
522 This is a good way of calculating the mass, CG and inertia of a rocket
523 during the design phase.  However, actual rocket components often have
524 a slightly different density or additional sources of mass such as
525 glue attached to them.  These cannot be effectively modeled by the
526 simulator, since it would be extremely tedious to define all these
527 properties.  Instead, some properties of the components can be
528 overridden to utilize measured values.
529
530 Two properties that can very easily be measured are the mass and
531 CG position of a component.  Measuring the moments of inertia is a
532 much harder task.  Therefore the moments of inertia are still computed
533 automatically, but are scaled by the overridden measurement values.
534
535 If the mass of a component is overridden by a measured value, the
536 moments of inertia are scaled linearly according to the mass.  This
537 assumes that the extra weight is distributed evenly along the
538 component.  If the CG position is overridden, there is no knowledge
539 where the extra weight is at.  Therefore as a best guess the moments
540 of inertia are updated by shifting the moment axis according to the
541 parallel axis theorem.
542
543 As the components are computed individually and then combined, the
544 overriding can take place either for individual components or larger
545 combinations.  It is especially useful is to override the mass and/or CG
546 position of the entire rocket.  This allows constructing a rocket from
547 components whose masses are not precisely known and afterwards scaling
548 the moments of inertia to closely match true values.
549
550
551
552 \subsection{Flight simulation}
553
554 The process of simulating rocket flight can be broken down into the
555 following steps:
556
557 \begin{enumerate}
558 \setcounter{enumi}{-1}
559 \item Initialize the rocket in a known position and orientation at
560   time $t=0$.
561 \item Compute the local wind velocity and other atmospheric conditions.
562 \item Compute the current airspeed, angle of attack, lateral wind
563   direction and other flight parameters.
564 \item Compute the aerodynamic forces and moments affecting the rocket.
565 \item Compute the effect of motor thrust and gravity.
566 \item Compute the mass and moments of inertia of the rocket and from
567   these the linear and rotational acceleration of the rocket.
568 \item Numerically integrate the acceleration to the rocket's position
569   and orientation during a time step $\Delta t$ and update the current
570   time $t \mapsto t+\Delta t$.
571 \end{enumerate}
572
573 Steps 1--6 are repeated until an end criteria is met, typically until
574 the rocket has landed.
575
576 The computation of the atmospheric properties and instantaneous wind
577 velocity were discussed in Section~\ref{sec-atmospheric-properties}.
578 The local wind velocity is added to the rocket velocity to get the
579 airspeed velocity of the rocket.  By inverse rotation this quantity is
580 obtained in rocket coordinates, from which the angle of attack and
581 other flight parameters can be computed.
582
583 After the instantaneous flight parameters are known, the aerodynamic
584 forces can be computed as discussed in
585 Chapter~\ref{chap-aerodynamics}.  The computed forces are in the
586 rocket coordinates, and can be converted to world coordinates by
587 applying the orientation rotation.  The thrust from the motors is
588 similarly calculated from the thrust curves and converted to world
589 coordinates, while the direction of gravity is already in world
590 coordinates.  When all of the the forces and moments acting upon the
591 rocket are known, the linear and rotational accelerations can be
592 calculated using the mass and moments of inertia discussed in
593 Section~\ref{sec-mass-inertia}.
594
595 The numerical integration is performed using the Runge-Kutta~4 (RK4)
596 integration method.  In order to simulate the differential equations
597 %
598 \begin{equation}
599 \begin{split}
600 x''(t) &= a(t) \\
601 \phi''(t) &= \alpha(t)
602 \end{split}
603 \end{equation}
604 %
605 the equation is first divided into first-order equations using the
606 substitutions $v(t)=x'(t)$ and $\omega(t)=\phi'(t)$:
607 %
608 \begin{equation}
609 \begin{split}
610 v'(t) &= a(t) \\
611 x'(t) &= v(t) \\
612 \omega'(t) &= \alpha(t) \\
613 \phi'(t)   &= \omega(t)
614 \end{split}
615 \end{equation}
616 %
617 For brevity, this is presented in the first order representation
618 %
619 \begin{equation}
620 y' = f(y,\; t)
621 \end{equation}
622 %
623 where $y$ is a vector function containing the position and orientation
624 of the rocket.
625
626 Next the right-hand side is evaluated at four positions, dependent on
627 the previous evaluations:
628 %
629 \begin{equation}
630 \begin{split}
631 k_1 &= f(y_0,\; t_0) \\
632 k_2 &= f(y_0 + k_1\:\mbox{$\frac{\Delta t}{2}$},\; 
633        t_0 + \mbox{$\frac{\Delta t}{2}$}) \\
634 k_3 &= f(y_0 + k_2\:\mbox{$\frac{\Delta t}{2}$},\; 
635        t_0 + \mbox{$\frac{\Delta t}{2}$}) \\
636 k_4 &= f(y_0 + k_3\:\Delta t,\; t_0 + \Delta t)
637 \end{split}
638 \end{equation}
639 %
640 Finally, the result is a weighted sum of these values:
641 %
642 \begin{align}
643 y_1 &= y_0 + \frac{1}{6}\left(k_1+2k_2+2k_3+k_4\right)\,\Delta t \\
644 t_1 &= t_0 + \Delta t
645 \end{align}
646
647 Computing the values $k_1\ldots k_4$ involves performing steps~1--5
648 four times per simulation iteration, but results in significantly
649 better simulation precision.  The method is a fourth-order integration
650 method, meaning that the error incurred during one simulation step is
651 of the order  $O(\Delta t^5)$ and of the total simulation 
652 $O(\Delta t^4)$.  This is a considerable improvement
653 over, for example, simple Euler integration, which has a total error
654 of the order $O(\Delta t)$.  Halving the time step in an Euler
655 integration only halves the total error, but reduces the error of a
656 RK4 simulation 16-fold.
657
658 The example above used a total rotation vector $\phi$ to contain the
659 orientation of the rocket.  Instead, this is replaced by the rotation
660 quaternion, which can be utilized directly as a transformation between
661 world and rocket coordinates.  Instead of updating the total rotation
662 vector,
663 %
664 \begin{equation}
665 \phi_1 = \phi_0 + \omega\,\Delta t,
666 \end{equation}
667 %
668 the orientation quaternion $o$ is updated by the same amount by
669 %
670 \begin{equation}
671 o_1 = \del{\cos\del{|\omega|\,\Delta t} +
672 \hat\omega\sin\del{|\omega|\,\Delta t}} \cdot o_0.
673 \end{equation}
674 %
675 The first term is simply the unit quaternion corresponding to the
676 3D rotation $\omega\,\Delta t$ as in
677 equation~(\ref{eq-rotation-quaternion}).  It is applied to the
678 previous value $o_0$ by multiplying the quaternion from the left.
679 This update is performed both during the calculation of 
680 $k_2\ldots k_4$ and when computing the final step result.  Finally, in
681 order to improve numerical stability, the quaternion is normalized to
682 unit length.
683
684 Since most of a rocket's flight occurs in a straight line, rather
685 large time steps can be utilized.  However, the rocket may encounter
686 occasional oscillation, which may affect its flight notably.
687 Therefore the time step utilized is dynamically reduced in cases where
688 the angular velocity or angular acceleration exceeds a predefined
689 limit.  This allows utilizing reasonably large time steps for most of
690 the flight, while maintaining the accuracy during oscillation.
691
692
693 \subsection{Recovery simulation}
694
695 All model rockets must have some recovery system for safe landing.
696 This is typically done either using a parachute or a streamer.  When a
697 parachute is deployed the rocket typically splits in half, and it is
698 no longer practical to compute the orientation of the rocket.
699 Therefore at this point the simulation changes to a simpler, three
700 degree of freedom simulation, where only the position of the rocket is
701 computed.
702
703 The entire drag coefficient of the rocket is assumed to come from the
704 deployed recovery devices.  For parachutes the drag coefficient is
705 by default 0.8~\cite[p.~13-23]{hoerner} with the reference area being the
706 area of the parachute.  The user can also define their own drag
707 coefficient.
708
709 The drag coefficient of streamers depend on the material, width and
710 length of the streamer.  The drag coefficient and optimization of
711 streamers has been an item of much intrest within the rocketry
712 community, with competitions being held on streamer descent time
713 durations~\cite{streamer-optimization}.  In order to estimate the drag
714 coefficient of streamers, a series of experiments were perfomed using
715 the $40\times40\times120$~cm wind tunnel of
716 Pollux~\cite{pollux-wind-tunnel}.  The experiments were performed
717 using various materials, widths and lengths of streamers and at
718 different wind speeds.  From these results an empirical formula was
719 devised that estimates the drag coefficient of streamers.  The
720 experimental results and the derivation of the empirical formula are
721 presented in Appendix~\ref{app-streamers}.  Validation performed with
722 an independent set of measurements indicates that the drag coefficient
723 is estimated with an accuracy of about 20\%, which translates to a
724 descent velocity accuracy within 15\% of the true value.
725
726
727
728
729 \subsection{Simulation events}
730
731 Numerous different events may cause actions to be taken during a
732 rocket's flight.  For example in high-power rockets the burnout or
733 ignition charge of the first stage's motor may trigger the ignition of
734 a second stage motor.  Similarly a flight computer may deploy a small
735 drogue parachute when apogee is detected and the main parachute is
736 deployed later at a predefined lower altitude.  To accomodate
737 different configurations a simulation event system is used, where
738 events may cause other events to be triggered.
739
740 Table~\ref{tab-simulation-events} lists the available simulation
741 events and which of them can be used to trigger motor ignition or recovery
742 device deployment.  Each trigger event may additionally include a
743 delay time.  For example, one motor may be configured to ignite at
744 launch and a second motor to ignite using a timer at 5 seconds after
745 launch.  Alternatively, a short delay of 0.5--1 seconds may be used to
746 simulate the delay of an ejection charge igniting the upper stage
747 motors.
748
749 The flight events are also stored along with the simulated flight data
750 for later analysis.  They are also available to the simulation
751 listeners, described in Section~\ref{sec-listeners}, to act upon
752 specific conditions.
753
754 \begin{table}
755 \caption{Simulation events and the actions they may trigger (motor
756   ignition or recovery device deployment).}
757 \label{tab-simulation-events}
758 %
759 \begin{center}
760 \begin{tabular}{ll}
761 Event description & Triggers \\
762 \hline
763 Rocket launch at $t=0$          & Ignition, recovery \\
764 Motor ignition                  & None \\
765 Motor burnout                   & Ignition \\
766 Motor ejection charge           & Ignition, recovery \\
767 Launch rod cleared              & None \\
768 Apogee detected                 & Recovery \\
769 Change in altitude              & Recovery \\
770 Touchdown after flight          & None \\
771 Deployment of a recovery device & None \\
772 End of simulation               & None \\
773 \hline
774 \end{tabular}
775 \end{center}
776 \end{table}
777
778
779
780
781