create changelog entry
[debian/openrocket] / core / doc / techdoc / chapter-software.tex
1
2
3 \chapter{The OpenRocket simulation software}
4 \label{chap-software}
5
6 The flight simulation described in the previous chapters was
7 implemented in the {\it OpenRocket} simulation
8 software~\cite{openrocket}.  The software was written entirely in Java
9 for maximum portability between different operating systems.  A
10 significant amount of effort was put into making the graphical user
11 interface (UI) robust, intuitive and easy to use.  As of the first
12 public release the source code contained over 300 classes and over
13 47\s000 lines of code (including comments and blank lines).
14
15 The software was released under the copyleft GNU General Public
16 License (GPL)~\cite{gnu-gpl}, allowing everybody access to the source code
17 and permitting use and modification for any purposes.  The only major
18 restriction placed is that if a modified version is distributed, the
19 source code for the modifications must also be available under the GNU
20 GPL.  This ensures that the program stays free and Open Source; a
21 company cannot simply take the code, enhance it and start selling it
22 as their own without contributing anything back to the community.
23
24 In this section the basic architectural designs are discussed and the
25 main features of the UI are explained.
26
27
28
29 \section{Architectural design}
30
31 The software has been split into various components within their own
32 Java packages.  This enables use of the components without needing the
33 other components.  For example, all of the UI code is within the
34 \code{gui} package, and the simulation system can be used
35 independently of it.
36
37
38 The rocket structure is composed of components, each with their
39 own class defined within the package \code{rocketcomponent}.  This
40 provides the base for defining a rocket.  The components are described
41 in more detail in Section~\ref{sec-rocket-components}.  The simulation
42 code is separated from the aerodynamic calculation code in the
43 \code{simulation} and \code{aerodynamics} packages, respectively;
44 these are discussed in Section~\ref{sec-simulator-calculator}.
45
46 The package naming convention recommended in the Java Language
47 Specification is followed~\cite{java-packages}.  Therefore all package
48 names discussed herein are relative to the package
49 \url{net.sf.openrocket}.  For example, the rocket components are
50 defined in the package \url{net.sf.openrocket.rocketcomponent}.
51
52
53
54
55 \subsection{Rocket components}
56 \label{sec-rocket-components}
57
58 The structure of the rocket is split up into {\it components}, for
59 example nose cones, body tubes and components within the rocket body.
60 Each component type is defined as a subclass of the abstract
61 \code{RocketComponent} class.  Each component can contain zero or more
62 components attached to it, which creates a tree structure containing
63 the entire rocket design.  The base component of every design is a
64 \code{Rocket} object, which holds one or more \code{Stage} objects.
65 These represent the stages of the rocket and hold all of the physical
66 components.
67
68 Inheritance has been highly used in the class hierarchy of the
69 components in order to combine common features of various components.
70 There are also some abstract classes, such as \code{BodyComponent},
71 whose sole purpose currently is to allow future extensions.  The
72 complete component class hierarchy is presented as a UML diagram in
73 Figure~\ref{fig-rocketcomponent-uml}, and a more detailed description
74 of each class is presented in Table~\ref{table-rocketcomponents}.
75
76 \begin{sidewaysfigure}
77 \centering
78 \hspace{-1cm}
79 \epsfig{file=figures/software/rocketcomponents,width=20cm}
80 \caption{A UML diagram of the rocket component classes.  Abstract
81   classes are shown in italics.}
82 \label{fig-rocketcomponent-uml}
83 \end{sidewaysfigure}
84
85
86 \begin{table}
87 \caption{Descriptions of the rocket component classes and their
88   functionality.  Abstract classes are shown in italics.}
89 \label{table-rocketcomponents}
90 \sloppy\footnotesize
91 \vspace{\baselineskip}
92 \hspace{-5mm}\begin{tabular}{lp{80mm}}
93 Component class & Description \\
94 \hline
95 \code{\textit{RocketComponent}}: &
96   The base class of all components,
97   including common features such as child component handling. \\
98
99 \hspace{3mm}\code{Rocket}: &
100   The base component of a
101   rocket design, provides change event notifications. \\
102
103 \hspace{3mm}\code{\textit{ComponentAssembly}}: &
104   A base component for an assembly of external components.  This could
105   in the future be extended to allow multiple rocket bodies next to
106   each other. \\
107
108 \hspace{6mm}\code{Stage}: &
109   A separable stage of the rocket. \\
110
111 \hspace{3mm}\code{\textit{ExternalComponent}}: &
112   An external component that has an effect on the aerodynamics of the
113   rocket. \\
114
115 \hspace{6mm}\code{\textit{BodyComponent}}: &
116   A portion of the main rocket body, defined in cylindrical coordinates
117   by $r = f(x, \theta)$. \\
118
119 \hspace{9mm}\code{\textit{SymmetricComponent}}: &
120   An axisymmetrical body component. \\
121
122 \hspace{12mm}\code{Transition}: &
123   A symmetrical transition (shoulder or boattail). \\
124
125 \hspace{15mm}\code{NoseCone}: &
126   A transition with the initial radius zero. \\
127
128 \hspace{12mm}\code{BodyTube}: &
129   A cylindrical body tube.  Can be used as a motor mount. \\
130
131 \hspace{6mm}\code{\textit{FinSet}}: &
132   A set of one or more fins. \\
133
134 \hspace{9mm}\code{TrapezoidalFinSet}: &
135   A set of trapezoidal fins. \\
136
137 \hspace{9mm}\code{EllipticalFinSet}: &
138   A set of elliptical fins. \\
139
140 \hspace{9mm}\code{FreeformFinSet}: &
141   A set of free-form fins. \\
142
143 \hspace{6mm}\code{LaunchLug}: &
144   A launch lug or rail pin. \\
145
146 \hspace{3mm}\code{\textit{InternalComponent}}: &
147   An internal component that may affect the mass of the rocket but not
148   its aerodynamics. \\
149
150 \hspace{6mm}\code{\textit{StructuralComponent}}: &
151   A structural internal component, with specific shape and density. \\
152
153 \hspace{9mm}\code{\textit{RingComponent}}: &
154   A hollow cylindrical component. \\
155
156 \hspace{12mm}\code{\textit{ThicknessRingComponent}}: &
157   A component defined by an outer radius and shell thickness. \\
158
159 \hspace{15mm}\code{InnerTube}: &
160   An inner tube.  Can be used as a motor mount and can be clustered. \\
161
162 \hspace{15mm}\code{TubeCoupler}: &
163   A coupler tube. \\
164
165 \hspace{15mm}\code{EngineBlock}: &
166   An engine block. \\
167
168 \hspace{12mm}\code{\textit{RadiusRingComponent}}: &
169   A component defined by an inner and outer radius. \\
170
171 \hspace{15mm}\code{CenteringRing}: &
172   A ring for centering components. \\
173
174 \hspace{15mm}\code{Bulkhead}: &
175   A solid bulkhead (inner radius zero). \\
176
177 \hspace{6mm}\code{\textit{MassObject}}: &
178   An internal component shaped approximately like a solid cylinder and
179   with a specific mass. \\
180
181 \hspace{9mm}\code{MassComponent}: &
182   A generic component with specific mass, for example payload. \\
183
184 \hspace{9mm}\code{\textit{RecoveryDevice}}: &
185   A recovery device. \\
186
187 \hspace{12mm}\code{Parachute}: &
188   A parachute. \\
189
190 \hspace{12mm}\code{Streamer}: &
191   A streamer. \\
192
193 \hspace{9mm}\code{ShockCord}: &
194   A shock cord with a specified material and length. \\
195
196 \hline
197 \end{tabular}
198 \end{table}
199
200
201 Additionally four interfaces are defined for the components,
202 \code{MotorMount}, \code{Clusterable}, \code{Radial\-Parent} and
203 \code{Coaxial}.  Components implementing the \code{Motor\-Mount}
204 interface, currently \code{Body\-Tube} and \code{Inner\-Tube}, can
205 function as motor mounts and have motors loaded in them.  The
206 \code{Clusterable} interface signifies that the component can be
207 clustered in various configurations.  Currently only the
208 \code{Inner\-Tube} component can be clustered.  Components and motors
209 that are attached to a clustered inner tube are automatically
210 replicated to all tubes within the cluster.  The \code{Radial\-Parent}
211 interface allows inner components to automatically identify their
212 correct inner and outer radii based on their parent and sibling
213 components.  For example, a coupler tube can automatically detect its
214 radius based on the inner radius of the parent body tube.
215 \code{Coaxial} on the other hand provides a generic interface for
216 accessing and modifying properties of fixed-radius components. 
217
218
219 Since the software functionality is divided into different packages,
220 all component similarities cannot be directly be exploited through
221 inheritance.  For example, the method of drawing a nose cone shape
222 belongs to the \url{gui.rocketfigure} package, however, it can share
223 the same code that draws a transition.  For these purposes, reflective
224 programming is used extensively.  The code for drawing both nose cones
225 and transitions is provided in the class
226 \code{gui.rocketfigure.SymmetricComponentShapes}, while the simpler
227 body tube is drawn by the class \code{BodyTubeShapes}.  The correct
228 class is derived and instantiated dynamically based on the component
229 class.  This allows easily sharing functionality common to different
230 components while still having loose coupling between the rocket
231 structure, presentation, computation and storage methods.
232
233
234
235
236 \subsection{Aerodynamic calculators and simulators}
237 \label{sec-simulator-calculator}
238
239 One of the key aspects in the design of the simulation implementation
240 was extensibility.  Therefore all aerodynamic calculation code is
241 separated in the package \code{aerodynamics} and all simulation code
242 is in the package \code{simulator}.  This allows adding new
243 implementations of the aerodynamic calculators and simulators
244 independently.  For example, a simulator using Euler integration was
245 written in the early stages of development, and later replaced by the
246 Runge-Kutta~4 simulator.  Similarly, a different method of calculating
247 the aerodynamic forces, such as CFD, could be implemented and used by
248 the existing simulators.
249
250 The basis for all aerodynamic calculations is the interface
251 \code{Aerodynamic\-Calculator}.  The current implementation, based on
252 the Barrowman methods, is implemented in the class
253 \code{Barrowman\-Calculator}.  This implementation caches mid-results
254 for performance reasons.
255
256 Flight simulation is split into the
257 interfaces \code{Simulation\-Engine}, which is responsible for
258 maintaining the flow of the simulation and handling events (such as
259 motor ignition), and \code{Simulation\-Stepper}, which is responsible
260 for taking individual time steps while simulating (using {\it e.g.}
261 RK4 iteration).
262
263 Similar abstraction has been performed for the atmospheric temperature
264 and pressure model with the \code{Atmospheric\-Model} interface, the
265 gravity model with \code{Gravity\-Model}, the wind modelling with
266 \code{Wind\-Model} and different rocket motor types by the
267 \code{Motor} class, among others.
268
269
270
271
272
273 \subsection{Simulation listeners}
274 \label{sec-listeners}
275
276 Simulation listeners are pieces of code that can dynamically be
277 configured to listen to and interact with a simulation while it is
278 running.  The listeners are called before and after each simulation
279 step, each simulation event and any calculations performed during
280 flight simulation.  The listeners may simply gather flight data for
281 use outside the simulation or modify the rocket or simulation during
282 the flight.  This allows great potential for extensibility both
283 internally and externally.
284
285 Listeners are used internally for various purposes such as retrieving
286 flight progress information when the user is running simulations and
287 cancelling the simulations when necessary.  Implementing such
288 functionality otherwise would have required a lot of special case
289 handling directly within the simulation code.
290
291 Listeners can also be used to modify the simulation or the rocket
292 during its flight.  The successor project of Haisunäätä included
293 an active roll stabilization system, where a flight computer 
294 measured the roll rate using two magnetometers and used a PID controller
295 to adjust two auxiliary fins to cancel out any roll produced by
296 inevitable imperfections in the main fins.  A simulation listener was
297 written that initially simulated the PID controller purely in Java, which
298 modified the cant angle of the auxiliary fins during the simulation.
299 Later a similar listener interfaced the external flight computer
300 directly using a serial data link.  The listener fed the simulated
301 flight data to the controller which computed and reported the control
302 actions back to the simulator.  This system helped identify and fix
303 numerous bugs in the flight computer software, which would have
304 otherwise been nearly impossible to fully test.  It is expected that
305 the simulation listeners will be an invaluable tool for more ambitious
306 model rocket enthusiasts.
307
308 A listener is produced by implementing the \code{Simulation\-Listener}
309 and optionally \code{Simulation\-Event\-Listener} and
310 \code{Simulation\-Computation\-Listener} interfaces, or by extending
311 the \code{Abstract\-Simulation\-Listener} class.  The UI includes the
312 option of defining custom simulation listeners to be utilized during
313 flight simulation.
314
315
316 \subsection{Warnings}
317 \label{sec-warnings}
318
319 The aerodynamic calculations and simulations are based on certain
320 assumptions and simplifications, such as a low angle of attack and a
321 smooth, continuous rocket body.  The rocket component architecture
322 makes it possible to create designs that break these assumptions.
323 Instead of limiting the options of the design, the aerodynamic
324 calculator and simulator can produce warnings about such issues.
325 These warnings are presented to the user during the design of the
326 rocket or after simulations.  It is then left up to the user to judge
327 whether such violations are significant enough to cast doubt to the
328 validity of the results.
329
330
331 \subsection{File format}
332
333 An XML-based file format was devised for storing the rocket designs
334 and simulations.  The use of XML allows using many existing tools for
335 reading and writing the files, allows easy extensibility and makes the
336 files human-readable.  The user has the option of including all
337 simulated data in the file, storing the data at specific time
338 intervals or storing only the simulation launch conditions.  To reduce
339 the file size, the files can additionally be compressed using the
340 standard GZIP compression algorithm~\cite{GZIP}.  The files are
341 compressed and uncompressed automatically by the software.  The file
342 extension .ORK was chosen for the design files, an abbreviation of the
343 software name that at the same time had no previous uses as a file
344 extension.
345
346
347
348
349
350 \section{User interface design}
351
352 The user interface was designed with the intent of being robust but
353 yet easy to use even for inexperienced users.  The main window,
354 depicted in Figure~\ref{fig-main-window}(a) with the design of the
355 original Haisunäätä rocket, consists of a schematic drawing of the
356 rocket, the tree structure of the rocket components and
357 buttons for adding new components to the structure. Components can
358 be selected or edited by clicking and double-clicking either the tree
359 view or the component in the schematic diagram.  The selected
360 components are drawn in bold to give a visual clue to the position
361 of the component.
362
363 The schematic drawing can be viewed either from the side or from the
364 rear, can be zoomed in and out and rotated along the centerline.  The
365 schematic diagram view also presents basic information about the
366 rocket, such as the design name, length, maximum diameter, mass and
367 possible warnings about the design. It also calculates the CG and CP
368 positions continuously during design and shows them both numerically
369 and on the diagram.  Additionally, a simulation is automatically run
370 in the background after each modification and the main results are
371 presented in the lower left corner of the diagram.  Many users are
372 interested in the maximum altitude or velocity of the rocket, and this
373 allows an immediate feedback on the effect of the changes they are
374 making to the design.  The flight information typically takes less
375 than a second to update.
376
377 The upper part of the main window can also be changed to view
378 simulation results, Figure~\ref{fig-main-window}(b).  Many simulations
379 can be added with different launch conditions and motor configurations
380 to investigate their effects.  Each simulation has a row which
381 presents the basic information about the simulation.  The first column
382 gives an immediate visual clue to the status of the simulation; a gray
383 ball indicates that the simulation has not been run yet, green
384 indicates an up-to-date simulation, red indicates that the design has
385 been changed after the simulation was run and yellow indicates that
386 the simulation information was loaded from a file, but that the file
387 states it to be up-to-date.  The simulations can be run one or several
388 at a time.  The software automatically utilizes several threads when
389 running multiple simulations on a multi-CPU computer to utilize the
390 full processing capacity.
391
392 Figure~\ref{fig-various-dialogs} shows two dialogs that are used
393 to modify and analyze the designs.  The components are edited using a
394 small dialog window that allows the user to either fill in the exact
395 numerical values specifying the shape of the component or use sliders
396 to modify them.  The user can change the units by clicking on them, or
397 set default values from the preferences.  Different tabs allow control
398 over the mass and CG override settings, figure color options, motor
399 mount and cluster options and more.  The Component analysis dialog
400 shown in the figure can be used to analyze the effect of individual
401 components on the total stability, drag and roll characteristics of
402 the rocket.
403
404 Similarly, the launch conditions and simulator options can be edited
405 in the corresponding dialog.  The simulator options also allow the
406 user to define custom simulation listeners to use during the
407 simulations.  The simulation edit dialog is also used for later data
408 analysis.  The simulated data can be plotted in a variety of ways as
409 shown in Figure~\ref{fig-plotting}.  The user can use predefined plot
410 settings or define their own.  Up to 15 different variables out of the
411 47 quantities computed can be plotted at a time.  The variable on the
412 horizontal axis can be freely selected, and the other variables can be
413 plotted on one of two vertical axis, on either side of the plot.  The
414 user can either specify whether a variable should plot on the left or
415 right axis or let the software decide the most suitable axis.  Typical
416 plots include the altitude, vertical velocity and acceleration of the
417 rocket with time or the drag coefficient as a function of the Mach
418 number.
419
420
421 \begin{figure}
422 \hspace{-7mm}
423 \begin{tabular}{m{1mm}m{10cm}}
424 \hspace{-5mm}(a) &
425 \epsfig{file=figures/pix/openrocket-main-haisunaata,scale=0.5} \\
426 \hspace{-5mm}(b) &
427 \epsfig{file=figures/pix/openrocket-simulations-haisunaata,scale=0.5}
428
429 \end{tabular}
430 \caption{The main design window of OpenRocket; (a) the design
431   view and (b) the simulation view.}
432 \label{fig-main-window}
433 \end{figure}
434
435 \begin{figure}
436 \centering
437 \epsfig{file=figures/pix/openrocket-dialog-edit,scale=0.5}
438 \vspace{2cm} \\
439 \epsfig{file=figures/pix/openrocket-dialog-analysis,scale=0.5}
440 \vspace{1cm} \\
441 \caption{Dialog windows for editing the properties of a nose cone
442   and for analyzing the influence of individual components on
443   the stability, drag and roll characteristics of the rocket.}
444 \label{fig-various-dialogs}
445 \end{figure}
446
447 \begin{figure}
448 \centering
449 \epsfig{file=figures/pix/openrocket-dialog-plot-options,scale=0.5}
450 \vspace{2cm} \\
451 \epsfig{file=figures/pix/openrocket-dialog-plot,scale=0.5}
452 \vspace{1cm} \\
453 \caption{Dialog window for changing the simulation plot options and a
454   plot of the simulated flight of the Haisunäätä hybrid rocket.}
455 \label{fig-plotting}
456 \end{figure}
457
458 Advanced users may also export the flight data in CSV format for
459 further analysis using other tools.
460
461 %
462 %\section{Future enhancements}
463 %
464 %Numerous features have been planned and taken into account during the
465 %design of the software.  Below are listed a few of the planned
466 %features and how they have been taken into account:
467 %
468 %{\it Alternative aerodynamic calculators.}  For example CFD could be
469 %used to calculate the aerodynamic properties, allowing even better
470 %simulation accuracy.  The calculators have been abstracted by the
471 %\code{AerodynamicCalculator} interface so they can easily be
472 %interchanged.
473 %
474 %{\it Alternative simulators.}  These could take into account for
475 %example the curvature of the Earth and include the Coriolis effect.
476 %New simulators can be created by implementing the
477 %\code{Simulation\-Stepper} interface.
478 %
479 %{\it Export and import of flight data.}  The simulated data could be
480 %exported for further analysis as comma separated values (CSV).
481 %Similarly, experimental data could be imported either from files or
482 %directly from altimeters.  Support for imported data already exists in
483 %the core functionalities.
484 %
485 %{\it Importing database files.}  The motor database is easily
486 %extendable to read external thrust curves.  Also data of commercially
487 %available rocket components could be imported and available in the
488 %component edit dialog.
489 %
490 %{\it Further UI enhancements.}  These could include for example a 3D
491 %view of the rocket, an animation of the rocket flight, a ``wizard''
492 %dialog for easily creating new designs, {\it etc.}
493 %