Editing
Simulation Listeners
(section)
Jump to navigation
Jump to search
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
=== Simulation listener actions === The simulation listeners can take action and modify the rocket state at any of the following (method names included in parenthesis): * before and after the simulation (<tt style="color: #006">startSimulation</tt>, <tt style="color: #006">endSimulation</tt>) * before and after a single step of the simulation (<tt style="color: #006">preStep</tt>, <tt style="color: #006">postStep</tt>) * before adding a flight event to the event queue (<tt style="color: #006">addFlightEvent</tt>) * before handling a flight event (<tt style="color: #006">handleFlightEvent</tt>) * before any motor ignition (<tt style="color: #006">motorIgnition</tt>) or recovery device deployment (<tt style="color: #006">recoveryDeviceDeployment</tt>) * before and after any computation (<tt style="color: #006">pre<em>Xyz</em></tt>, <tt style="color: #006">post<em>Xyz</em></tt>) All simulation listeners must implement the <tt style="color: #006">[http://openrocket.svn.sourceforge.net/viewvc/openrocket/trunk/src/net/sf/openrocket/simulation/listeners/SimulationListener.java?view=markup SimulationListener]</tt> interface. This defines a few basic hooks for the simulation startup and steps. For additional hooks the class can additionally implement the <tt style="color: #006">[http://openrocket.svn.sourceforge.net/viewvc/openrocket/trunk/src/net/sf/openrocket/simulation/listeners/SimulationEventListener.java?view=markup SimulationEventListener]</tt> and <tt style="color: #006">[http://openrocket.svn.sourceforge.net/viewvc/openrocket/trunk/src/net/sf/openrocket/simulation/listeners/SimulationComputationListener.java?view=markup SimulationComputationListener]</tt> interfaces. The recommended way of implementing simulation listeners is by extending the <tt style="color: #006">AbstractSimulationListener</tt> class. This implements all of the hook methods with abstract implementations that do nothing. During future development the interfaces may be augmented or change slightly, but the abstract class will contain backward-compatible callbacks. The hook methods come in three varieties depending on the return value. * The <tt style="color: #006">startSimulation</tt>, <tt style="color: #006">endSimulation</tt> and <tt style="color: #006">postStep</tt> are hooks that are called at a specific point of the simulation. They are void methods and do not return any value. * The <tt style="color: #006">preStep</tt> and event-related hooks return a boolean value indicating whether the action should be taken or not. A return value of <tt style="color: #006">true</tt> indicates that the action should be taken as normally would be (default), <tt style="color: #006">false</tt> will inhibit the action. * The pre- and post-computation methods may return the computed value, either as an object or a double value. The pre-computation methods allow pre-empting the entire computation, while the post-computation methods allow augmenting the computed values. These methods may return <tt style="color: #006">null</tt> or <tt style="color: #006">Double.NaN</tt> to use the original values (default), or return an overriding value. Every method receives a <tt style="color: #006">SimulationStatus</tt> object as the first argument, and may have additional arguments. The <tt style="color: #006">SimulationStatus</tt> object contains information about the rocket's current position, orientation, velocity and simulation state. It also contains a reference to a copy of the rocket design and its configuration. Any simulation listener method may modify the state of the rocket by changing the properties of the state object. Each listener method may also throw a <tt style="color: #006">SimulationException</tt>. This is considered an error during simulation, and an error dialog is displayed to the user with the exception message. The simulation data thus far is not stored in the simulation. Throwing a <tt style="color: #006">RuntimeException</tt> is considered a bug in the software and will result in a bug report dialog. If a simulation listener wants to stop a simulation prematurely without an error condition, it needs to add a flight event of type <tt style="color: #006">SIMULATION_END</tt> to the simulation event queue: status.getEventQueue().add(new FlightEvent(FlightEvent.Type.SIMULATION_END, status.getSimulationTime(), null)); This will cause the simulation to be terminated normally. ---- <div style="text-align: center;"> <div style="float: left;">[[Custom Expressions|← Custom Expressions]]</div> <div style="float: right;">[[FAQ|Frequently Asked Questions (Appendix A) →]]</div> [[Main Page|↑ Back to Contents]] </div>
Summary:
Please note that all contributions to OpenRocket wiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
OpenRocket:Copyrights
for details).
Do not submit copyrighted work without permission!
⧼questycaptcha-edit⧽
What is the name of the software this site is describing?
Cancel
Editing help
(opens in new window)
Navigation menu
Personal tools
Not logged in
Talk
Contributions
Create account
Log in
Namespaces
Page
Discussion
English
Views
Read
Edit
View history
More
Search
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
Tools
What links here
Related changes
Special pages
Page information