JSBSim Flight Dynamics Model  1.0 (02 March 2017)
An Open Source Flight Dynamics and Control Software Library in C++
FGScript Class Reference

Encapsulates the JSBSim scripting capability. More...

#include <FGScript.h>

+ Inheritance diagram for FGScript:
+ Collaboration diagram for FGScript:

Public Member Functions

 FGScript (FGFDMExec *exec)
 Default constructor.
 
 ~FGScript ()
 Default destructor.
 
bool LoadScript (const SGPath &script, double default_dT, const SGPath &initfile)
 Loads a script to drive JSBSim (usually in standalone mode). More...
 
void ResetEvents (void)
 
bool RunScript (void)
 This function is called each pass through the executive Run() method IF scripting is enabled. More...
 
- Public Member Functions inherited from FGJSBBase
 FGJSBBase ()
 Constructor for FGJSBBase.
 
virtual ~FGJSBBase ()
 Destructor for FGJSBBase.
 
void disableHighLighting (void)
 Disables highlighting in the console output.
 
std::string GetVersion (void)
 Returns the version number of JSBSim. More...
 
void PutMessage (const Message &msg)
 Places a Message structure on the Message queue. More...
 
void PutMessage (const std::string &text)
 Creates a message with the given text and places it on the queue. More...
 
void PutMessage (const std::string &text, bool bVal)
 Creates a message with the given text and boolean value and places it on the queue. More...
 
void PutMessage (const std::string &text, int iVal)
 Creates a message with the given text and integer value and places it on the queue. More...
 
void PutMessage (const std::string &text, double dVal)
 Creates a message with the given text and double value and places it on the queue. More...
 
int SomeMessages (void)
 Reads the message on the queue (but does not delete it). More...
 
void ProcessMessage (void)
 Reads the message on the queue and removes it from the queue. More...
 
MessageProcessNextMessage (void)
 Reads the next message on the queue and removes it from the queue. More...
 

Additional Inherited Members

- Public Types inherited from FGJSBBase
enum  { eL = 1, eM, eN }
 Moments L, M, N.
 
enum  { eP = 1, eQ, eR }
 Rates P, Q, R.
 
enum  { eU = 1, eV, eW }
 Velocities U, V, W.
 
enum  { eX = 1, eY, eZ }
 Positions X, Y, Z.
 
enum  { ePhi = 1, eTht, ePsi }
 Euler angles Phi, Theta, Psi.
 
enum  { eDrag = 1, eSide, eLift }
 Stability axis forces, Drag, Side force, Lift.
 
enum  { eRoll = 1, ePitch, eYaw }
 Local frame orientation Roll, Pitch, Yaw.
 
enum  { eNorth = 1, eEast, eDown }
 Local frame position North, East, Down.
 
enum  { eLat = 1, eLong, eRad }
 Locations Radius, Latitude, Longitude.
 
enum  {
  inNone = 0, inDegrees, inRadians, inMeters,
  inFeet
}
 Conversion specifiers.
 
- Static Public Member Functions inherited from FGJSBBase
static double CelsiusToFahrenheit (double celsius)
 Converts from degrees Celsius to degrees Fahrenheit. More...
 
static double CelsiusToKelvin (double celsius)
 Converts from degrees Celsius to degrees Kelvin. More...
 
static double CelsiusToRankine (double celsius)
 Converts from degrees Celsius to degrees Rankine. More...
 
static double Constrain (double min, double value, double max)
 Constrain a value between a minimum and a maximum value.
 
static bool EqualToRoundoff (double a, double b)
 Finite precision comparison. More...
 
static bool EqualToRoundoff (float a, float b)
 Finite precision comparison. More...
 
static bool EqualToRoundoff (float a, double b)
 Finite precision comparison. More...
 
static bool EqualToRoundoff (double a, float b)
 Finite precision comparison. More...
 
static double FahrenheitToCelsius (double fahrenheit)
 Converts from degrees Fahrenheit to degrees Celsius. More...
 
static double FeetToMeters (double measure)
 Converts from feet to meters. More...
 
static double GaussianRandomNumber (void)
 
static double KelvinToCelsius (double kelvin)
 Converts from degrees Kelvin to degrees Celsius. More...
 
static double KelvinToFahrenheit (double kelvin)
 Converts from degrees Kelvin to degrees Fahrenheit. More...
 
static double KelvinToRankine (double kelvin)
 Converts from degrees Kelvin to degrees Rankine. More...
 
static double MachFromVcalibrated (double vcas, double p, double psl, double rhosl)
 Calculate the Mach number from the calibrated airspeed. More...
 
static double PitotTotalPressure (double mach, double p)
 Compute the total pressure in front of the Pitot tube. More...
 
static double RankineToCelsius (double rankine)
 Converts from degrees Rankine to degrees Celsius. More...
 
static double RankineToKelvin (double rankine)
 Converts from degrees Rankine to degrees Kelvin. More...
 
static double sign (double num)
 
static double VcalibratedFromMach (double mach, double p, double psl, double rhosl)
 Calculate the calibrated airspeed from the Mach number. More...
 
- Static Public Attributes inherited from FGJSBBase
static short debug_lvl = 1
 
static char highint [5] = {27, '[', '1', 'm', '\0' }
 highlights text
 
static char halfint [5] = {27, '[', '2', 'm', '\0' }
 low intensity text
 
static char normint [6] = {27, '[', '2', '2', 'm', '\0' }
 normal intensity text
 
static char reset [5] = {27, '[', '0', 'm', '\0' }
 resets text properties
 
static char underon [5] = {27, '[', '4', 'm', '\0' }
 underlines text
 
static char underoff [6] = {27, '[', '2', '4', 'm', '\0' }
 underline off
 
static char fgblue [6] = {27, '[', '3', '4', 'm', '\0' }
 blue text
 
static char fgcyan [6] = {27, '[', '3', '6', 'm', '\0' }
 cyan text
 
static char fgred [6] = {27, '[', '3', '1', 'm', '\0' }
 red text
 
static char fggreen [6] = {27, '[', '3', '2', 'm', '\0' }
 green text
 
static char fgdef [6] = {27, '[', '3', '9', 'm', '\0' }
 default text
 
- Protected Member Functions inherited from FGJSBBase
void Debug (int)
 
- Static Protected Member Functions inherited from FGJSBBase
static std::string CreateIndexedPropertyName (const std::string &Property, int index)
 
- Static Protected Attributes inherited from FGJSBBase
static const double degtorad = 0.017453292519943295769236907684886
 
static const double fpstokts = 1.0/ktstofps
 
static const double fttom = 0.3048
 
static int gaussian_random_number_phase = 0
 
static const double hptoftlbssec = 550.0
 
static const double in3tom3 = 1.638706E-5
 
static const double inchtoft = 0.08333333
 
static const double inhgtopa = 3386.38
 
static const std::string JSBSim_version = "1.0 " __DATE__ " " __TIME__
 
static const double kgtolb = 2.20462
 
static const double kgtoslug = 0.06852168
 
static const double ktstofps = 1.68781
 
static const double lbtoslug = 1.0/slugtolb
 
static Message localMsg
 
static const double m3toft3 = 1.0/(fttom*fttom*fttom)
 
static double Mair = 28.9645
 
static unsigned int messageId = 0
 
static std::queue< MessageMessages
 
static const std::string needed_cfg_version = "2.0"
 
static const double psftoinhg = 0.014138
 
static const double psftopa = 47.88
 
static const double radtodeg = 57.295779513082320876798154814105
 
static double Reng = 1716.56
 
static double Rstar = 1545.348
 
static const double SHRatio = 1.40
 
static const double slugtolb = 32.174049
 

Detailed Description

Encapsulates the JSBSim scripting capability.

Scripting support provided via FGScript.

There is support for scripting provided in the FGScript class. Commands are specified using the Scripting Directives for JSBSim. The script file is in XML format. A test condition (or conditions) can be set up in an event in a script and when the condition evaluates to true, the specified action[s] is/are taken. An event can be persistent, meaning that at every time the test condition first evaluates to true (toggling from false to true) then the specified set actions take place. An event can also be defined to execute or evaluate continuously while the condition is true. When the set of tests evaluates to true for a given condition, an item may be set to another value. This value may be a value, or a delta value, and the change from the current value to the new value can be either via a step action, a ramp, or an exponential approach. The speed of a ramp or exponential approach is specified via the time constant. Here is an example illustrating the format of the script file:

<?xml version="1.0"?>
<runscript name="C172-01A takeoff run">
<!--
This run is for testing the C172 altitude hold autopilot
-->
<use aircraft="c172x"/>
<use initialize="reset00"/>
<run start="0.0" end="3000" dt="0.0083333">
<event name="engine start">
<notify/>
<condition>
sim-time-sec >= 0.25
</condition>
<set name="fcs/throttle-cmd-norm" value="1.0" action="FG_RAMP" tc ="0.5"/>
<set name="fcs/mixture-cmd-norm" value="0.87" action="FG_RAMP" tc ="0.5"/>
<set name="propulsion/magneto_cmd" value="3"/>
<set name="propulsion/starter_cmd" value="1"/>
</event>
<event name="set heading hold">
<!-- Set Heading when reach 5 ft -->
<notify/>
<condition>
position/h-agl-ft >= 5
</condition>
<set name="ap/heading_setpoint" value="200"/>
<set name="ap/attitude_hold" value="0"/>
<set name="ap/heading_hold" value="1"/>
</event>
<event name="set autopilot">
<!-- Set Autopilot for 20 ft -->
<notify/>
<condition>
aero/qbar-psf >= 4
</condition>
<set name="ap/altitude_setpoint" value="100.0" action="FG_EXP" tc ="2.0"/>
<set name="ap/altitude_hold" value="1"/>
<set name="fcs/flap-cmd-norm" value=".33"/>
</event>
<event name="set autopilot 2" persistent="true">
<!-- Set Autopilot for 6000 ft -->
<notify/>
<condition>
aero/qbar-psf > 5
</condition>
<set name="ap/altitude_setpoint" value="6000.0"/>
</event>
<event name="Time Notify">
<notify/>
<condition> sim-time-sec >= 500 </condition>
</event>
<event name="Time Notify">
<notify/>
<condition> sim-time-sec >= 1000 </condition>
</event>
</run>
</runscript>

The first line must always be present - it identifies the file as an XML format file. The second line identifies this file as a script file, and gives a descriptive name to the script file. Comments are next, delineated by the <!– and –> symbols. The aircraft and initialization files to be used are specified in the "use" lines. Next, comes the "run" section, where the conditions are described in "event" clauses.

Author
Jon S. Berndt
Version
"$Id: FGScript.h,v 1.31 2017/02/25 14:23:18 bcoconni Exp $"

Definition at line 172 of file FGScript.h.

Member Function Documentation

◆ LoadScript()

bool LoadScript ( const SGPath &  script,
double  default_dT,
const SGPath &  initfile 
)

Loads a script to drive JSBSim (usually in standalone mode).

The language is the Script Directives for JSBSim. If a simulation step size has been supplied on the command line, it will override the script specified simulation step size.

Parameters
scriptthe filename (including path name, if any) for the script.
default_dTthe default simulation step size if no value is specified in the script
initfileAn optional initialization file name passed in, empty by default. If a file name is passed in, it will override the one present in the script.
Returns
true if successful

Definition at line 99 of file FGScript.cpp.

101 {
102  SGPath initialize;
103  string aircraft="", prop_name="";
104  string notifyPropertyName="";
105  Element *element=0, *run_element=0, *event_element=0;
106  Element *set_element=0;
107  Element *notify_element = 0L, *notify_property_element = 0L;
108  double dt = 0.0, value = 0.0;
109  FGCondition *newCondition;
110 
111  FGXMLFileRead XMLFileRead;
112  Element* document = XMLFileRead.LoadXMLDocument(script);
113 
114  if (!document) {
115  cerr << "File: " << script << " could not be loaded." << endl;
116  return false;
117  }
118 
119  if (document->GetName() != string("runscript")) {
120  cerr << "File: " << script << " is not a script file" << endl;
121  return false;
122  }
123 
124  ScriptName = document->GetAttributeValue("name");
125 
126  // First, find "run" element and set delta T
127 
128  run_element = document->FindElement("run");
129 
130  if (!run_element) {
131  cerr << "No \"run\" element found in script." << endl;
132  return false;
133  }
134 
135  // Set sim timing
136 
137  if (run_element->HasAttribute("start"))
138  StartTime = run_element->GetAttributeValueAsNumber("start");
139  else
140  StartTime = 0.0;
141  FDMExec->Setsim_time(StartTime);
142  if (run_element->HasAttribute("end")) {
143  EndTime = run_element->GetAttributeValueAsNumber("end");
144  } else {
145  cerr << "An end time (duration) for the script must be specified in the script <run> element." << endl;
146  return false;
147  }
148 
149  // Make sure that the desired time is reached and executed.
150  EndTime += 0.99*FDMExec->GetDeltaT();
151 
152  if (default_dT == 0.0)
153  dt = run_element->GetAttributeValueAsNumber("dt");
154  else {
155  dt = default_dT;
156  cout << endl << "Overriding simulation step size from the command line. New step size is: "
157  << default_dT << " seconds (" << 1/default_dT << " Hz)" << endl << endl;
158  }
159 
160  FDMExec->Setdt(dt);
161 
162  // read aircraft and initialization files
163 
164  element = document->FindElement("use");
165  if (element) {
166  aircraft = element->GetAttributeValue("aircraft");
167  if (!aircraft.empty()) {
168  if (!FDMExec->LoadModel(aircraft))
169  return false;
170  } else {
171  cerr << "Aircraft must be specified in use element." << endl;
172  return false;
173  }
174 
175  initialize = SGPath::fromLocal8Bit(element->GetAttributeValue("initialize").c_str());
176  if (initfile.isNull()) {
177  if (initialize.isNull()) {
178  cerr << "Initialization file must be specified in use element." << endl;
179  return false;
180  }
181  } else {
182  cout << endl << "The initialization file specified in the script file (" << initialize
183  << ") has been overridden with a specified file (" << initfile << ")." << endl;
184  initialize = initfile;
185  }
186 
187  } else {
188  cerr << "No \"use\" directives in the script file." << endl;
189  return false;
190  }
191 
192  FGInitialCondition *IC=FDMExec->GetIC();
193  if ( ! IC->Load( initialize )) {
194  cerr << "Initialization unsuccessful" << endl;
195  return false;
196  }
197 
198  // Now, read input spec if given.
199  element = document->FindElement("input");
200  while (element) {
201  if (!FDMExec->GetInput()->Load(element))
202  return false;
203 
204  element = document->FindNextElement("input");
205  }
206 
207  // Now, read output spec if given.
208  element = document->FindElement("output");
209  while (element) {
210  if (!FDMExec->GetOutput()->Load(element))
211  return false;
212 
213  element = document->FindNextElement("output");
214  }
215 
216  // Read local property/value declarations
217  int saved_debug_lvl = debug_lvl;
218  debug_lvl = 0; // Disable messages
219  LocalProperties.Load(run_element, PropertyManager, true);
220  debug_lvl = saved_debug_lvl;
221 
222  // Read "events" from script
223 
224  event_element = run_element->FindElement("event");
225  while (event_element) { // event processing
226 
227  // Create the event structure
228  struct event *newEvent = new struct event();
229 
230  // Retrieve the event name if given
231  newEvent->Name = event_element->GetAttributeValue("name");
232 
233  // Is this event persistent? That is, does it execute every time the
234  // condition triggers to true, or does it execute as a one-shot event, only?
235  if (event_element->GetAttributeValue("persistent") == string("true")) {
236  newEvent->Persistent = true;
237  }
238 
239  // Does this event execute continuously when triggered to true?
240  if (event_element->GetAttributeValue("continuous") == string("true")) {
241  newEvent->Continuous = true;
242  }
243 
244  // Process the conditions
245  Element* condition_element = event_element->FindElement("condition");
246  if (condition_element != 0) {
247  try {
248  newCondition = new FGCondition(condition_element, PropertyManager);
249  } catch(string& str) {
250  cout << endl << fgred << str << reset << endl << endl;
251  delete newEvent;
252  return false;
253  }
254  newEvent->Condition = newCondition;
255  } else {
256  cerr << "No condition specified in script event " << newEvent->Name << endl;
257  delete newEvent;
258  return false;
259  }
260 
261  // Is there a delay between the time this event is triggered, and when the event
262  // actions are executed?
263 
264  Element* delay_element = event_element->FindElement("delay");
265  if (delay_element)
266  newEvent->Delay = event_element->FindElementValueAsNumber("delay");
267  else
268  newEvent->Delay = 0.0;
269 
270  // Notify about when this event is triggered?
271  if ((notify_element = event_element->FindElement("notify")) != 0) {
272  if (notify_element->HasAttribute("format")) {
273  if (notify_element->GetAttributeValue("format") == "kml") newEvent->NotifyKML = true;
274  }
275  newEvent->Notify = true;
276  // Check here for new <description> tag that gets echoed
277  string notify_description = notify_element->FindElementValue("description");
278  if (!notify_description.empty()) {
279  newEvent->Description = notify_description;
280  }
281  notify_property_element = notify_element->FindElement("property");
282  while (notify_property_element) {
283  notifyPropertyName = notify_property_element->GetDataLine();
284 
285  newEvent->NotifyPropertyNames.push_back(notifyPropertyName);
286  newEvent->NotifyProperties.push_back(0);
287  string caption_attribute = notify_property_element->GetAttributeValue("caption");
288  if (caption_attribute.empty()) {
289  newEvent->DisplayString.push_back(notifyPropertyName);
290  } else {
291  newEvent->DisplayString.push_back(caption_attribute);
292  }
293 
294  notify_property_element = notify_element->FindNextElement("property");
295  }
296  }
297 
298  // Read set definitions (these define the actions to be taken when the event is triggered).
299  set_element = event_element->FindElement("set");
300  while (set_element) {
301  prop_name = set_element->GetAttributeValue("name");
302  if (PropertyManager->HasNode(prop_name)) {
303  newEvent->SetParam.push_back( PropertyManager->GetNode(prop_name) );
304  } else {
305  newEvent->SetParam.push_back( 0L );
306  }
307  newEvent->SetParamName.push_back( prop_name );
308 
309  //Todo - should probably do some safety checking here to make sure one or the other
310  //of value or function is specified.
311  if (!set_element->GetAttributeValue("value").empty()) {
312  value = set_element->GetAttributeValueAsNumber("value");
313  newEvent->Functions.push_back((FGFunction*)0L);
314  } else if (set_element->FindElement("function")) {
315  value = 0.0;
316  newEvent->Functions.push_back(new FGFunction(PropertyManager, set_element->FindElement("function")));
317  }
318  newEvent->SetValue.push_back(value);
319  newEvent->OriginalValue.push_back(0.0);
320  newEvent->newValue.push_back(0.0);
321  newEvent->ValueSpan.push_back(0.0);
322  string tempCompare = set_element->GetAttributeValue("type");
323  if (to_lower(tempCompare).find("delta") != string::npos) newEvent->Type.push_back(FG_DELTA);
324  else if (to_lower(tempCompare).find("bool") != string::npos) newEvent->Type.push_back(FG_BOOL);
325  else if (to_lower(tempCompare).find("value") != string::npos) newEvent->Type.push_back(FG_VALUE);
326  else newEvent->Type.push_back(FG_VALUE); // DEFAULT
327  tempCompare = set_element->GetAttributeValue("action");
328  if (to_lower(tempCompare).find("ramp") != string::npos) newEvent->Action.push_back(FG_RAMP);
329  else if (to_lower(tempCompare).find("step") != string::npos) newEvent->Action.push_back(FG_STEP);
330  else if (to_lower(tempCompare).find("exp") != string::npos) newEvent->Action.push_back(FG_EXP);
331  else newEvent->Action.push_back(FG_STEP); // DEFAULT
332 
333  if (!set_element->GetAttributeValue("tc").empty())
334  newEvent->TC.push_back(set_element->GetAttributeValueAsNumber("tc"));
335  else
336  newEvent->TC.push_back(1.0); // DEFAULT
337 
338  newEvent->Transiting.push_back(false);
339 
340  set_element = event_element->FindNextElement("set");
341  }
342  Events.push_back(*newEvent);
343  delete newEvent;
344 
345  event_element = run_element->FindNextElement("event");
346  }
347 
348  Debug(4);
349 
350  return true;
351 }
FGInitialCondition * GetIC(void)
Returns a pointer to the FGInitialCondition object.
Definition: FGFDMExec.h:385
FGOutput * GetOutput(void)
Returns the FGOutput pointer.
Definition: FGFDMExec.h:375
static char reset[5]
resets text properties
Definition: FGJSBBase.h:131
FGInput * GetInput(void)
Returns the FGInput pointer.
Definition: FGFDMExec.h:373
static char fgred[6]
red text
Definition: FGJSBBase.h:141
double Setsim_time(double cur_time)
Sets the current sim time.
Definition: FGFDMExec.h:551
void Setdt(double delta_t)
Sets the integration time step for the simulation executive.
Definition: FGFDMExec.h:559
bool Load(Element *el)
Load the output directives and adds a new output instance to the Output Manager list.
Definition: FGOutput.cpp:249
bool Load(Element *el)
Load the input directives and adds a new input instance to the Input Manager list.
Definition: FGInput.cpp:81
double GetDeltaT(void) const
Returns the simulation delta T.
Definition: FGFDMExec.h:536
bool LoadModel(const SGPath &AircraftPath, const SGPath &EnginePath, const SGPath &SystemsPath, const std::string &model, bool addModelToPath=true)
Loads an aircraft model.
Definition: FGFDMExec.cpp:666
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ RunScript()

bool RunScript ( void  )

This function is called each pass through the executive Run() method IF scripting is enabled.

Returns
false if script should exit (i.e. if time limits are violated

Definition at line 366 of file FGScript.cpp.

367 {
368  unsigned i, j;
369  unsigned event_ctr = 0;
370 
371  double currentTime = FDMExec->GetSimTime();
372  double newSetValue = 0;
373 
374  if (currentTime > EndTime) return false;
375 
376  // Iterate over all events.
377  for (unsigned int ev_ctr=0; ev_ctr < Events.size(); ev_ctr++) {
378 
379  struct event &thisEvent = Events[ev_ctr];
380 
381  // Determine whether the set of conditional tests for this condition equate
382  // to true and should cause the event to execute. If the conditions evaluate
383  // to true, then the event is triggered. If the event is not persistent,
384  // then this trigger will remain set true. If the event is persistent,
385  // the trigger will reset to false when the condition evaluates to false.
386  if (thisEvent.Condition->Evaluate()) {
387  if (!thisEvent.Triggered) {
388 
389  // The conditions are true, do the setting of the desired Event parameters
390  for (i=0; i<thisEvent.SetValue.size(); i++) {
391  if (thisEvent.SetParam[i] == 0L) { // Late bind property if necessary
392  if (PropertyManager->HasNode(thisEvent.SetParamName[i])) {
393  thisEvent.SetParam[i] = PropertyManager->GetNode(thisEvent.SetParamName[i]);
394  } else {
395  throw("No property, \""+thisEvent.SetParamName[i]+"\" is defined.");
396  }
397  }
398  thisEvent.OriginalValue[i] = thisEvent.SetParam[i]->getDoubleValue();
399  if (thisEvent.Functions[i] != 0) { // Parameter should be set to a function value
400  try {
401  thisEvent.SetValue[i] = thisEvent.Functions[i]->GetValue();
402  } catch (string& msg) {
403  std::cerr << std::endl << "A problem occurred in the execution of the script. " << msg << endl;
404  throw;
405  }
406  }
407  switch (thisEvent.Type[i]) {
408  case FG_VALUE:
409  case FG_BOOL:
410  thisEvent.newValue[i] = thisEvent.SetValue[i];
411  break;
412  case FG_DELTA:
413  thisEvent.newValue[i] = thisEvent.OriginalValue[i] + thisEvent.SetValue[i];
414  break;
415  default:
416  cerr << "Invalid Type specified" << endl;
417  break;
418  }
419  thisEvent.StartTime = currentTime + thisEvent.Delay;
420  thisEvent.ValueSpan[i] = thisEvent.newValue[i] - thisEvent.OriginalValue[i];
421  thisEvent.Transiting[i] = true;
422  }
423  }
424  thisEvent.Triggered = true;
425 
426  } else if (thisEvent.Persistent) { // If the event is persistent, reset the trigger.
427  thisEvent.Triggered = false; // Reset the trigger for persistent events
428  thisEvent.Notified = false; // Also reset the notification flag
429  } else if (thisEvent.Continuous) { // If the event is continuous, reset the trigger.
430  thisEvent.Triggered = false; // Reset the trigger for persistent events
431  thisEvent.Notified = false; // Also reset the notification flag
432  }
433 
434  if ((currentTime >= thisEvent.StartTime) && thisEvent.Triggered) {
435 
436  for (i=0; i<thisEvent.SetValue.size(); i++) {
437  if (thisEvent.Transiting[i]) {
438  thisEvent.TimeSpan = currentTime - thisEvent.StartTime;
439  switch (thisEvent.Action[i]) {
440  case FG_RAMP:
441  if (thisEvent.TimeSpan <= thisEvent.TC[i]) {
442  newSetValue = thisEvent.TimeSpan/thisEvent.TC[i] * thisEvent.ValueSpan[i] + thisEvent.OriginalValue[i];
443  } else {
444  newSetValue = thisEvent.newValue[i];
445  if (thisEvent.Continuous != true) thisEvent.Transiting[i] = false;
446  }
447  break;
448  case FG_STEP:
449  newSetValue = thisEvent.newValue[i];
450 
451  // If this is not a continuous event, reset the transiting flag.
452  // Otherwise, it is known that the event is a continuous event.
453  // Furthermore, if the event is to be determined by a function,
454  // then the function will be continuously calculated.
455  if (thisEvent.Continuous != true)
456  thisEvent.Transiting[i] = false;
457  else if (thisEvent.Functions[i] != 0)
458  newSetValue = thisEvent.Functions[i]->GetValue();
459 
460  break;
461  case FG_EXP:
462  newSetValue = (1 - exp( -thisEvent.TimeSpan/thisEvent.TC[i] )) * thisEvent.ValueSpan[i] + thisEvent.OriginalValue[i];
463  break;
464  default:
465  cerr << "Invalid Action specified" << endl;
466  break;
467  }
468  thisEvent.SetParam[i]->setDoubleValue(newSetValue);
469  }
470  }
471 
472  // Print notification values after setting them
473  if (thisEvent.Notify && !thisEvent.Notified) {
474  if (thisEvent.NotifyKML) {
475  cout << endl << "<Placemark>" << endl;
476  cout << " <name> " << currentTime << " seconds" << " </name>" << endl;
477  cout << " <description>" << endl;
478  cout << " <![CDATA[" << endl;
479  cout << " <b>" << thisEvent.Name << " (Event " << event_ctr << ")" << " executed at time: " << currentTime << "</b><br/>" << endl;
480  } else {
481  cout << endl << underon
482  << highint << thisEvent.Name << normint << underoff
483  << " (Event " << event_ctr << ")"
484  << " executed at time: " << highint << currentTime << normint << endl;
485  }
486  if (!thisEvent.Description.empty()) {
487  cout << " " << thisEvent.Description << endl;
488  }
489  for (j=0; j<thisEvent.NotifyProperties.size();j++) {
490  if (thisEvent.NotifyProperties[j] == 0) {
491  if (PropertyManager->HasNode(thisEvent.NotifyPropertyNames[j])) {
492  thisEvent.NotifyProperties[j] = PropertyManager->GetNode(thisEvent.NotifyPropertyNames[j]);
493  } else {
494  throw("Could not find property named "+thisEvent.NotifyPropertyNames[j]+" in script.");
495  }
496  }
497  cout << " " << thisEvent.DisplayString[j] << " = " << thisEvent.NotifyProperties[j]->getDoubleValue();
498  if (thisEvent.NotifyKML) cout << " <br/>";
499  cout << endl;
500  }
501  if (thisEvent.NotifyKML) {
502  cout << " ]]>" << endl;
503  cout << " </description>" << endl;
504  cout << " <Point>" << endl;
505  cout << " <altitudeMode> absolute </altitudeMode>" << endl;
506  cout << " <extrude> 1 </extrude>" << endl;
507  cout << " <coordinates>" << FDMExec->GetPropagate()->GetLongitudeDeg()
508  << "," << FDMExec->GetPropagate()->GetGeodLatitudeDeg()
509  << "," << FDMExec->GetPropagate()->GetAltitudeASLmeters() << "</coordinates>" << endl;
510  cout << " </Point>" << endl;
511  cout << "</Placemark>" << endl;
512  }
513  cout << endl;
514  thisEvent.Notified = true;
515  }
516 
517  }
518 
519  event_ctr++;
520  }
521  return true;
522 }
double GetAltitudeASLmeters(void) const
Returns the current altitude above sea level.
Definition: FGPropagate.h:344
static char normint[6]
normal intensity text
Definition: FGJSBBase.h:129
static char underoff[6]
underline off
Definition: FGJSBBase.h:135
double GetSimTime(void) const
Returns the cumulative simulation time in seconds.
Definition: FGFDMExec.h:533
static char highint[5]
highlights text
Definition: FGJSBBase.h:125
static char underon[5]
underlines text
Definition: FGJSBBase.h:133
FGPropagate * GetPropagate(void)
Returns the FGPropagate pointer.
Definition: FGFDMExec.h:369
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

The documentation for this class was generated from the following files: