Using listeners and signals with Nasal: Difference between revisions

Jump to navigation Jump to search
m
m (→‎Nasal code coupled to the autopilot system: https://code.google.com/p/flightgear-bugs/issues/detail?id=421#c13)
Line 217: Line 217:
There's just one (minor) problem at the moment. There's no generic FDM update() function where one could put a sig.setDoubleValue(dt).This would have to be done in all FDMs.
There's just one (minor) problem at the moment. There's no generic FDM update() function where one could put a sig.setDoubleValue(dt).This would have to be done in all FDMs.


There are several options, such as 1) Run a second events system and add an additional parameter to Nasal's settimer allowing you to use this new events system. 2) Add in a signal that is fired each simulation step, probably right before the Autopilot system is run:
Another possibility is to extend the declarative expression logic, which is already supported by the autopilot components, to allow a Nasal expression. Then you mix the declarative components (which you're going to want for most autopilot laws) with some scripted ones.
Since the expression evaluation would be driven by the autopilot subsystem, it would run at whatever frame-rate that itself runs at - which is currently in lock-step with the FDM [http://flightgear.org/forums/viewtopic.php?f=46&t=17069&hilit=nasal+fdm+autopilot&start=15#p165596].
 
There are several other options, such as 1) Run a second events system and add an additional parameter to Nasal's settimer allowing you to use this new events system. 2) Add in a signal that is fired each simulation step, probably right before the Autopilot system is run:


<syntaxhighlight lang="php">
<syntaxhighlight lang="php">
Line 238: Line 241:
is the way that JSBSim has approached the solution.
is the way that JSBSim has approached the solution.


Some benefits to such an approach include (IMHO) better testability, more predictability, and easier interface (someday) with a GUI tool, should one
Some benefits to such an approach include better testability, more predictability, and easier interface (someday) with a GUI tool, should one
materialize. The downside is that XML can be verbose.
materialize. The downside is that XML can be verbose.


All that being said, it is definitely possible to run Nasal in the FDM update loop, so to make up your own mind, you could try this:
All that being said, it is definitely possible to run Nasal in the FDM update loop, so to make up your own mind, you could try this:

Navigation menu