Using listeners and signals with Nasal: Difference between revisions

Jump to navigation Jump to search
m
→‎Nasal code coupled to the autopilot system: http://www.mail-archive.com/flightgear-devel@lists.sourceforge.net/msg13025.html
(→‎Nasal code coupled to the autopilot system: http://flightgear.org/forums/viewtopic.php?f=46&t=17069&hilit=nasal+fdm+autopilot&start=15#p165551)
m (→‎Nasal code coupled to the autopilot system: http://www.mail-archive.com/flightgear-devel@lists.sourceforge.net/msg13025.html)
Line 193: Line 193:


=== Nasal code coupled to the autopilot system ===
=== Nasal code coupled to the autopilot system ===
The FDM doesn't run at a fixed rate, either. It runs 120 times per second (if so configured), but it runs all iterations for a frame one after the other, then waits until the next frame.
Some people have a need to run Nasal code at the same rate as the simulation. Currently, without modifying the source code for FlightGear, the only way
Some people have a need to run Nasal code at the same rate as the simulation. Currently, without modifying the source code for FlightGear, the only way
to do this is to find a property updated at the right time in the simulation cycle and set a listener on it. From a code quality standpoint, this is less than ideal.
to do this is to find a property updated at the right time in the simulation cycle and set a listener on it. From a code quality standpoint, this is less than ideal.
Line 209: Line 211:
</syntaxhighlight>
</syntaxhighlight>


Unfortunately, some core developers are opposed to the idea, i.e. avoid *any* Nasal in the fast simulation loop of the FDM, because Nasal execution is slow and non-deterministic. Running it in the fast simulation loop is the last thing we want[http://www.mail-archive.com/flightgear-devel@lists.sourceforge.net/msg38172.html].
Some core developers are fairly opposed to the whole idea, i.e. want to avoid *any* Nasal in the fast simulation loop of the FDM, because Nasal execution is slow and non-deterministic because of its GC issue. Running it in the fast simulation loop is the last thing they want[http://www.mail-archive.com/flightgear-devel@lists.sourceforge.net/msg38172.html].


You can then use Nasal for the high level stuff, and enable/disable/switch the individual controller elements (e.g. in order to automatically switch the autopilot mode when capturing the ILS). There are some nice examples with fgdata/Git aircraft. You could look at the 777.
You can then use Nasal for the high level stuff, and enable/disable/switch the individual controller elements (e.g. in order to automatically switch the autopilot mode when capturing the ILS). There are some nice examples with fgdata/Git aircraft. You could look at the 777.
Line 223: Line 225:
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 (IMHO) 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