f66a98cadcb6517e614b8a5ea5c2a1594d8d3780
[debian/openrocket] / 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 three interfaces are defined for the components,
202 \code{MotorMount}, \code{Clusterable} and \code{RadialParent}.
203 Components implementing the \code{Motor\-Mount} interface, currently
204 \code{BodyTube} and \code{InnerTube}, can function as motor mounts and
205 have motors loaded in them.  The \code{Clusterable} interface
206 signifies that the component can be clustered in various
207 configurations.  Currently only the \code{InnerTube} component can be
208 clustered.  Components and motors that are attached to a clustered
209 inner tube are automatically replicated to all tubes within the
210 cluster.  The \code{RadialParent} interface allows inner components to
211 automatically identify their correct inner and outer radii based on
212 their parent and sibling components.  For example, a coupler tube can
213 automatically detect its radius based on the inner radius of
214 the parent body tube.
215
216
217 Since the software functionality is divided into different packages,
218 all component similarities cannot be directly be exploited through
219 inheritance.  For example, the method of drawing a nose cone shape
220 belongs to the \url{gui.rocketfigure} package, however, it can share
221 the same code that draws a transition.  For these purposes, reflective
222 programming is used extensively.  The code for drawing both nose cones
223 and transitions is provided in the class
224 \code{gui.rocketfigure.SymmetricComponentShapes}, while the simpler
225 body tube is drawn by the class \code{BodyTubeShapes}.  The correct
226 class is derived and instantiated dynamically based on the component
227 class.  This allows easily sharing functionality common to different
228 components while still having loose coupling between the rocket
229 structure, presentation, computation and storage methods.
230
231
232
233
234 \subsection{Aerodynamic calculators and simulators}
235 \label{sec-simulator-calculator}
236
237 One of the key aspects in the design of the simulation implementation
238 was extensibility.  Therefore all aerodynamic calculation code is
239 separated in the package \code{aerodynamics} and all simulation code
240 is in the package \code{simulator}.  
241
242 The basis for aerodynamic calculations is the abstract class
243 \code{Aerodynamic\-Calculator}, while the simulators are subclasses of
244 the \code{Flight\-Simulator} class.  This allows adding new
245 implementations of the aerodynamic calculators and simulators
246 independently.  For example, a simulator using Euler integration was
247 written in the early stages of development, and later replaced by the
248 Runge-Kutta~4 simulator.  Similarly, a different method of calculating
249 the aerodynamic forces, such as CFD, could be implemented and used by
250 the existing simulators.
251
252 Similar abstraction has been performed for the atmospheric temperature
253 and pressure model by the abstract class \code{AtmosphericModel} and
254 different rocket motor types by the \code{Motor} class, among others.
255
256
257
258
259
260 \subsection{Simulation listeners}
261 \label{sec-listeners}
262
263 Simulation listeners are pieces of code that can dynamically be
264 configured to listen to and interact with a simulation while it is
265 running.  The listeners are called after each simulation step, at each
266 simulation event and both when the flight conditions and aerodynamic
267 forces have been calculated.  The listeners may simply gather flight
268 data for use outside the simulation or modify the rocket or simulation
269 during the flight.  This allows great potential for extensibility both
270 internally and externally.
271
272 Listeners are used internally for various purposes such as retrieving
273 flight progress information when the user is running simulations and
274 cancelling the simulations when necessary.  Implementing such
275 functionality otherwise would have required a lot of special case
276 handling directly within the simulation code.
277
278 Listeners can also be used to modify the simulation or the rocket
279 during its flight.  The successor project of Haisunäätä will include
280 an active roll stabilization system, where a flight computer will
281 measure the roll rate using two magnetometers and use a PID controller
282 to adjust two auxiliary fins to cancel out the roll inevitably
283 produced by imperfections in the main fins.  A simulation listener was
284 written that first simulated the PID controller purely in Java, which
285 modified the cant angle of the auxiliary fins during the simulation.
286 Later a similar listener interfaced the external flight computer
287 directly using a serial data link.  The listener fed the flight data
288 to the controller which computed and reported the control actions back
289 to the simulator.  This system helped identify and fix numerous bugs
290 in the flight computer software, which would have otherwise been
291 nearly impossible to fully test.  It is expected that the simulation
292 listeners will be an invaluable tool for more ambitious model rocket
293 enthusiasts.
294
295 A listener is produced by implementing the \code{SimulationListener}
296 interface or by extending the \code{AbstractSimulationListener}
297 class.  The UI includes the option of defining custom simulation
298 listeners to be utilized during flight simulation.
299
300
301 \subsection{Warnings}
302 \label{sec-warnings}
303
304 The aerodynamic calculations and simulations are based on certain
305 assumptions and simplifications, such as a low angle of attack and a
306 smooth, continuous rocket body.  The rocket component architecture
307 makes it possible to create designs that break these assumptions.
308 Instead of limiting the options of the design, the aerodynamic
309 calculator and simulator can produce warnings about such issues.
310 These warnings are presented to the user during the design of the
311 rocket or after simulations.  It is then left up to the user to judge
312 whether such violations are significant enough to cast doubt to the
313 validity of the results.
314
315
316 \subsection{File format}
317
318 An XML-based file format was devised for storing the rocket designs
319 and simulations.  The use of XML allows using many existing tools for
320 reading and writing the files, allows easy extensibility and makes the
321 files human-readable.  The user has the option of including all
322 simulated data in the file, storing the data at specific time
323 intervals or storing only the simulation launch conditions.  To reduce
324 the file size, the files can additionally be compressed using the
325 standard GZIP compression algorithm~\cite{GZIP}.  The files are
326 compressed and uncompressed automatically by the software.  The file
327 extension .ORK was chosen for the design files, an abbreviation of the
328 software name that at the same time had no previous uses as a file
329 extension.
330
331
332
333
334
335 \section{User interface design}
336
337 The user interface was designed with the intent of being robust but
338 yet easy to use even for inexperienced users.  The main window,
339 depicted in Figure~\ref{fig-main-window}(a) with the design of the
340 original Haisunäätä rocket, consists of a schematic drawing of the
341 rocket, the tree structure of the rocket components and
342 buttons for adding new components to the structure. Components can
343 be selected or edited by clicking and double-clicking either the tree
344 view or the component in the schematic diagram.  The selected
345 components are drawn in bold to give a visual clue to the position
346 of the component.
347
348 The schematic drawing can be viewed either from the side or from the
349 rear, can be zoomed in and out and rotated along the centerline.  The
350 schematic diagram view also presents basic information about the
351 rocket, such as the design name, length, maximum diameter, mass and
352 possible warnings about the design. It also calculates the CG and CP
353 positions continuously during design and shows them both numerically
354 and on the diagram.  Additionally, a simulation is automatically run
355 in the background after each modification and the main results are
356 presented in the lower left corner of the diagram.  Many users are
357 interested in the maximum altitude or velocity of the rocket, and this
358 allows an immediate feedback on the effect of the changes they are
359 making to the design.  The flight information typically takes less
360 than a second to update.
361
362 The upper part of the main window can also be changed to view
363 simulation results, Figure~\ref{fig-main-window}(b).  Many simulations
364 can be added with different launch conditions and motor configurations
365 to investigate their effects.  Each simulation has a row which
366 presents the basic information about the simulation.  The first column
367 gives an immediate visual clue to the status of the simulation; a gray
368 ball indicates that the simulation has not been run yet, green
369 indicates an up-to-date simulation, red indicates that the design has
370 been changed after the simulation was run and yellow indicates that
371 the simulation information was loaded from a file, but that the file
372 states it to be up-to-date.  The simulations can be run one or several
373 at a time.  The software automatically utilizes several threads when
374 running multiple simulations on a multi-CPU computer to utilize the
375 full processing capacity.
376
377 Figure~\ref{fig-various-dialogs} shows two dialogs that are used
378 to modify and analyze the designs.  The components are edited using a
379 small dialog window that allows the user to either fill in the exact
380 numerical values specifying the shape of the component or use sliders
381 to modify them.  The user can change the units by clicking on them, or
382 set default values from the preferences.  Different tabs allow control
383 over the mass and CG override settings, figure color options, motor
384 mount and cluster options and more.  The Component analysis dialog
385 shown in the figure can be used to analyze the effect of individual
386 components on the total stability, drag and roll characteristics of
387 the rocket.
388
389 Similarly, the launch conditions and simulator options can be edited
390 in the corresponding dialog.  The simulator options also allow the
391 user to define custom simulation listeners to use during the
392 simulations.  The simulation edit dialog is also used for later data
393 analysis.  The simulated data can be plotted in a variety of ways as
394 shown in Figure~\ref{fig-plotting}.  The user can use predefined plot
395 settings or define their own.  Up to 15 different variables out of the
396 47 quantities computed can be plotted at a time.  The variable on the
397 horizontal axis can be freely selected, and the other variables can be
398 plotted on one of two vertical axis, on either side of the plot.  The
399 user can either specify whether a variable should plot on the left or
400 right axis or let the software decide the most suitable axis.  Typical
401 plots include the altitude, vertical velocity and acceleration of the
402 rocket with time or the drag coefficient as a function of the Mach
403 number.
404
405
406 \begin{figure}
407 \hspace{-7mm}
408 \begin{tabular}{m{1mm}m{10cm}}
409 \hspace{-5mm}(a) &
410 \epsfig{file=figures/pix/openrocket-main-haisunaata,scale=0.5} \\
411 \hspace{-5mm}(b) &
412 \epsfig{file=figures/pix/openrocket-simulations-haisunaata,scale=0.5}
413
414 \end{tabular}
415 \caption{The main design window of OpenRocket; (a) the design
416   view and (b) the simulation view.}
417 \label{fig-main-window}
418 \end{figure}
419
420 \begin{figure}
421 \centering
422 \epsfig{file=figures/pix/openrocket-dialog-edit,scale=0.5}
423 \vspace{2cm} \\
424 \epsfig{file=figures/pix/openrocket-dialog-analysis,scale=0.5}
425 \vspace{1cm} \\
426 \caption{Dialog windows for editing the properties of a nose cone
427   and for analyzing the influence of individual components on
428   the stability, drag and roll characteristics of the rocket.}
429 \label{fig-various-dialogs}
430 \end{figure}
431
432 \begin{figure}
433 \centering
434 \epsfig{file=figures/pix/openrocket-dialog-plot-options,scale=0.5}
435 \vspace{2cm} \\
436 \epsfig{file=figures/pix/openrocket-dialog-plot,scale=0.5}
437 \vspace{1cm} \\
438 \caption{Dialog window for changing the simulation plot options and a
439   plot of the simulated flight of the Haisunäätä hybrid rocket.}
440 \label{fig-plotting}
441 \end{figure}
442
443
444 \section{Future enhancements}
445
446 Numerous features have been planned and taken into account during the
447 design of the software.  Below are listed a few of the planned
448 features and how they have been taken into account:
449
450 {\it Alternative aerodynamic calculators.}  For example CFD could be
451 used to calculate the aerodynamic properties, allowing even better
452 simulation accuracy.  The calculators have been abstracted by the
453 \code{AerodynamicCalculator} class so they can easily be
454 interchanged.
455
456 {\it Alternative simulators.}  These could take into account for
457 example the curvature of the Earth and include the Coriolis effect.
458 New simulators can be created by extending the abstract
459 \code{FlightSimulator} class.
460
461 {\it Export and import of flight data.}  The simulated data could be
462 exported for further analysis as comma separated values (CSV).
463 Similarly, experimental data could be imported either from files or
464 directly from altimeters.  Support for imported data already exists in
465 the core functionalities.
466
467 {\it Importing database files.}  The motor database is easily
468 extendable to read external thrust curves.  Also data of commercially
469 available rocket components could be imported and available in the
470 component edit dialog.
471
472 {\it Further UI enhancements.}  These could include for example a 3D
473 view of the rocket, an animation of the rocket flight, a ``wizard''
474 dialog for easily creating new designs, {\it etc.}
475