Library globals

Namespace globals . aircraft

View source

This module provide basic functions and classes for use in aircraft specific
Nasal context.

Classes

HUD

HUD control class to handle both HUD implementations ==============================================================================

angular_lowpass

angular lowpass ============================================================================== same as above, but for angles. Filters sin/cos separately and calculates the angle again from them. This avoids unexpected jumps from 179.99 to -180 degree.

autotrim

autotrim ============================================================================= Singleton class that supports quick trimming and compensates for the lack of resistance/force feedback in most joysticks. Normally the pilot trims such that no real or artificially generated (by means of servo motors and spring preloading) forces act on the stick/yoke and it is in a comfortable position. This doesn't work well on computer joysticks. SYNOPSIS: autotrim.start(); # on key/button press autotrim.stop(); # on key/button release (mod-up) USAGE: (1) move the stick such that the aircraft is in an orientation that you want to trim for (forward flight, hover, ...) (2) press autotrim button and keep it pressed (3) move stick/yoke to neutral position (center) (4) release autotrim button

crossfeed_valve

crossfeed_valve ============================================================================= class that creates a fuel tank cross-feed valve. Designed for YASim aircraft; JSBSim aircraft can simply use systems code within the FDM (see 747-400 for an example). WARNING: this class requires the tank properties to be ready, so call new() after the FDM is initialized. SYNOPSIS: crossfeed_valve.new(<max_flow_rate>, <property>, <tank>, <tank>, ... ); crossfeed_valve.open(<update>); crossfeed_valve.close(<update>); <max_flow_rate> ... maximum transfer rate between the tanks in lbs/sec <property> ... property path to use as switch - pass nil to use no such switch <tank> ... number of a tank to connect - can have unlimited number of tanks connected <update> ... update switch property when opening/closing valve via Nasal - 0 or 1; by default, 1 EXAMPLES: aircraft.crossfeed_valve.new(0.5, "/controls/fuel/x-feed", 0, 1, 2); ------- var xfeed = aircraft.crossfeed_valve.new(1, nil, 0, 1); xfeed.open();

data

data ============================================================================== class that loads and saves properties to aircraft-specific data files in ~/.fgfs/aircraft-data/ (Unix) or %APPDATA%\flightgear.org\aircraft-data\. There's no public constructor, as the only needed instance gets created by the system. SYNOPSIS: data.add(<properties>); data.save([<interval>]) properties ... about any combination of property nodes (props.Node) or path name strings, or lists or hashes of them, lists of lists of them, etc. interval ... save in <interval> minutes intervals, or only once if 'nil' or empty (and again at reinit/exit) SIGNALS: /sim/signals/save ... set to 'true' right before saving. Can be used to update values that are to be saved EXAMPLE: var p = props.globals.getNode("/sim/model", 1); var vec = [p, p]; var hash = {"foo": p, "bar": p}; # add properties aircraft.data.add("/sim/fg-root", p, "/sim/fg-home"); aircraft.data.add(p, vec, hash, "/sim/fg-root"); # now save only once (and at exit/reinit, which is automatically done) aircraft.data.save(); # or save now and every 30 sec (and at exit/reinit) aircraft.data.save(0.5);

door

door ============================================================================== class for objects moving at constant speed, with the ability to reverse moving direction at any point. Appropriate for doors, canopies, etc. SYNOPSIS: door.new(<property>, <swingtime> [, <startpos>]); property ... door node: property path or node swingtime ... time in seconds for full movement (0 -> 1) startpos ... initial position (default: 0) PROPERTIES: ./position-norm (double) (default: <startpos>) ./enabled (bool) (default: 1) EXAMPLE: var canopy = aircraft.door.new("sim/model/foo/canopy", 5); canopy.open();

light

light ============================================================================== class for generation of pulsing values. Appropriate for controlling beacons, strobes, etc. SYNOPSIS: light.new(<property>, <pattern> [, <switch>]); light.new(<property>, <stretch>, <pattern> [, <switch>]); property ... light node: property path or node stretch ... multiplicator for all pattern values pattern ... array of on/off time intervals (in seconds) switch ... property path or node to use as switch (default: ./enabled) instead of ./enabled PROPERTIES: ./state (bool) (default: 0) ./enabled (bool) (default: 0) except if <switch> given) EXAMPLES: aircraft.light.new("sim/model/foo/beacon", [0.4, 0.4]); # anonymous light ------- var strobe = aircraft.light.new("sim/model/foo/strobe", [0.05, 0.05, 0.05, 1], "controls/lighting/strobe"); strobe.switch(1); ------- var switch = props.globals.getNode("controls/lighting/strobe", 1); var pattern = [0.02, 0.03, 0.02, 1]; aircraft.light.new("sim/model/foo/strobe-top", 1.001, pattern, switch); aircraft.light.new("sim/model/foo/strobe-bot", 1.005, pattern, switch);

livery

livery ============================================================================= Class that maintains livery XML files (see English Electric Lightning for an example). The last used livery is saved on exit and restored next time. Livery files are regular PropertyList XML files whose properties are copied to the main tree. SYNOPSIS: livery.init(<livery-dir> [, <name-path> [, <sort-path>]]); <livery-dir> ... directory with livery XML files, relative to $FG_ROOT <name-path> ... property path to the livery name in the livery files and the property tree (default: sim/model/livery/name) <sort-path> ... property path to the sort criterion (default: same as <name-path> -- that is: alphabetic sorting) EXAMPLE: aircraft.livery.init("Aircraft/Lightning/Models/Liveries", "sim/model/livery/variant", "sim/model/livery/index"); # optional aircraft.livery.dialog.toggle(); aircraft.livery.select("OEBH"); aircraft.livery.next();

livery_update

livery_update ============================================================================= Class for maintaining liveries in MP aircraft. It is used in Nasal code that's embedded in aircraft animation XML files, and checks in intervals whether the parent aircraft has changed livery, in which case it changes the livery in the remote aircraft accordingly. This class is a wrapper for overlay_update. SYNOPSIS: livery_update.new(<livery-dir> [, <interval:10> [, <func>]]); <livery-dir> ... directory with livery files, relative to $FG_ROOT <interval> ... checking interval in seconds (default: 10) <func> ... callback function that's called with the ./sim/model/livery/file contents as argument whenever the livery has changed. This can be used for post-processing. EXAMPLE: <nasal> <load> var livery_update = aircraft.livery_update.new( "Aircraft/R22/Models/Liveries", 30, func print("R22 livery update")); </load> <unload> livery_update.stop(); </unload> </nasal>

lowpass

lowpass ============================================================================== class that implements a variable-interval EWMA (Exponentially Weighted Moving Average) lowpass filter with characteristics independent of the frame rate. SYNOPSIS: lowpass.new(<coefficient>); EXAMPLE: var lp = aircraft.lowpass.new(1.5); print(lp.filter(10)); # prints 10 print(lp.filter(0));

overlay_update

overlay_update ============================================================================= Class for maintaining overlays in MP aircraft. It is used in Nasal code that's embedded in aircraft animation XML files, and checks in intervals whether the parent aircraft has changed an overlay, in which case it copies the respective overlay to the aircraft's root directory. SYNOPSIS: livery_update.new(); livery_update.add(<overlay-dir>, <property> [, <callback>]); <overlay-dir> ... directory with overlay files, relative to $FG_ROOT <property> ... MP property where the overlay file name can be found (usually one of the sim/multiplay/generic/string properties) <callback> ... callback function that's called with two arguments: the file name (without extension) and the overlay directory EXAMPLE: <nasal> <load> var update = aircraft.overlay_update.new(); update.add("Aircraft/F4U/Models/Logos", "sim/multiplay/generic/string"); </load> <unload> update.stop(); </unload> </nasal>

rain

rain ============================================================================= Provides a property which can be used to control rain. Can be used to turn off rain in internal views, and or used with a texture on canopies etc. The output is co-ordinated with system precipitation: /sim/model/rain/raining-norm rain intensity /sim/model/rain/flow-mps drop flow speed [m/s] See Hawker Seahawk for an example. SYNOPSIS: aircraft.rain.init(); aircraft.rain.update();

steering

steering ============================================================================= Class that implements differential braking depending on rudder position. Note that this overrides the controls.applyBrakes() wrapper. If you need your own version, then override it again after the steering.init() call. SYNOPSIS: steering.init([<property> [, <threshold>]]); <property> ... property path or props.Node hash that enables/disables brake steering (usually bound to the js trigger button) <threshold> ... defines range (+- threshold) around neutral rudder position in which both brakes are applied EXAMPLES: aircraft.steering.init("/controls/gear/steering", 0.2); aircraft.steering.init();

timer

timer ============================================================================== class that implements timer that can be started, stopped, reset, and can have its value saved to the aircraft specific data file. Saving the value is done automatically by the aircraft.Data class. SYNOPSIS: timer.new(<property> [, <resolution:double> [, <save:bool>]]) <property> ... property path or props.Node hash that holds the timer value <resolution> ... timer update resolution -- interval in seconds in which the timer property is updated while running (default: 1 s) <save> ... bool that defines whether the timer value should be saved and restored next time, as needed for Hobbs meters (default: 1) EXAMPLES: var hobbs_turbine = aircraft.timer.new("/sim/time/hobbs/turbine[0]", 60); hobbs_turbine.start(); aircraft.timer.new("/sim/time/hobbs/battery", 60).start(); # anonymous timer

tyresmoke

tyresmoke_system

Functions

kias_to_ktas

returns true airspeed for given indicated airspeed [kt] and altitude [m]

makeNode

creates (if necessary) and returns a property node from arg[0], which can be a property node already, or a property path

optarg

returns args[index] if available and non-nil, or default otherwise

teleport

teleport ============================================================================= Usage: aircraft.teleport(lat:48.3, lon:32.4, alt:5000);

wind_speed_from

returns wind speed [kt] from given direction [deg]; useful for head-wind

Variables

ac

temporary hack to provide backward compatibility for /sim/auto-coordination remove this code when all references to /sim/auto-coordination are gone