Nasal Flightplan: Difference between revisions

From FlightGear wiki
Jump to navigation Jump to search
m (→‎Related content: more pointers to help fill in some gaps)
Line 129: Line 129:
* [[Nasal library#Extension functions|Nasal library § Extension functions]]
* [[Nasal library#Extension functions|Nasal library § Extension functions]]
* [[Navdata cache#Accessing via Nasal|Navdata cache § Accessing via Nasal]]
* [[Navdata cache#Accessing via Nasal|Navdata cache § Accessing via Nasal]]
* [[Route Manager]]
* [[Route Manager internals]]


=== Documentation ===
=== Documentation ===
Line 135: Line 137:
* [http://api-docs.freeflightsim.org/flightgear/NasalPositioned_8cxx_source.html#l02485 initNasalPositioned] — ''Contains a list of functions that can be called on airport, flight plan, waypoint, procedure, or flight plan leg objects.''
* [http://api-docs.freeflightsim.org/flightgear/NasalPositioned_8cxx_source.html#l02485 initNasalPositioned] — ''Contains a list of functions that can be called on airport, flight plan, waypoint, procedure, or flight plan leg objects.''
* [http://api-docs.freeflightsim.org/flightgear/route__mgr_8cxx_source.html#l00220 FGRouteMgr::FGRouteMgr] — ''List of [[fgcommands]] relating to the route manager.''
* [http://api-docs.freeflightsim.org/flightgear/route__mgr_8cxx_source.html#l00220 FGRouteMgr::FGRouteMgr] — ''List of [[fgcommands]] relating to the route manager.''
=== Misc ===
* https://sourceforge.net/p/flightgear/mailman/message/34688624/
* https://sourceforge.net/p/flightgear/mailman/message/35164289/
* https://sourceforge.net/p/flightgear/mailman/flightgear-devel/thread/BB67C9F3-028B-40E5-94E4-246CD1E0B2CC%40mac.com/#msg23708827
* https://sourceforge.net/p/flightgear/mailman/message/33699574/
* https://sourceforge.net/p/flightgear/mailman/message/21010010/
* https://sourceforge.net/p/flightgear/mailman/message/23678747/


=== Search Queries ===
=== Search Queries ===

Revision as of 18:06, 26 August 2017

Note  Whenever possible, please refrain from modeling complex systems, like an FDM, autopilot or Route Manager with Nasal. This is primarily to help reduce Nasal overhead (especially GC overhead). It will also help to unify duplicated code. The FlightGear/SimGear code base already contains fairly generic and efficient systems and helpers, implemented in C++, that merely need to be better generalized and exposed to Nasal so that they can be used elsewhere. For example, this would enable Scripted AI Objects to use full FDM implementations and/or built-in route manager systems.

Technically, this is also the correct approach, as it allows us to easily reuse existing code that is known to be stable and working correctly, .

For details on exposing these C++ systems to Nasal, please refer to Nasal/CppBind. If in doubt, please get in touch via the mailing list or the forum first.


Because FlightGear's route manager flight plan system is exposed to Nasal, Nasal can be used to interact with flight plans. Obviously, this is very useful, especially for aircraft like airliners, which have complex route managers systems. This article shows how this can be done.

Background

The Nasal functions relating to the route manager system include:

Flight plans are based on waypoints, which, in C++, inherit from the FGPositioned (doxygen) class.

Waypoint hashes

The following are members of a waypoint ghost, as generated by, for example, airwaysRoute() :

wp_name
Name of the waypoint, returned as string.
wp_type
Waypoint type, returned as string. One of "basic," "navaid," "offset-navaid," "runway," "hdgToAlt," "dmeIntercept," "radialIntercept," or "vectors."
wp_role
Role of waypoint.
wp_lat or lat
Latitude of waypoint.
wp_lon or lon
Longitude of waypoint.
wp_parent_name
Name of waypoint's parent.
wp_parent
Waypoint's parent.
fly_type
How to waypoint should be flown over or reacted to. One of "Hold," "flyOver," or "flyBy."
heading_course
Heading of runway.

Flightplan methods and variables

getWP()
currentWP()
nextWP()
getPlanSize()
Returns number of waypoints
numWaypoints()
appendWP()
insertWP(wp, index)
Pass a waypoint object and its position.
deleteWP()
insertWPAfter()
insertWaypoints(vector, index)
Pass a vector of waypoint objects, and the position to insert.
cleanPlan()
clearWPType()
clone()
Return a copy of the fligthplan.
pathGeod()
finish()
indexOfWP()
destination
airport object as destination.
destination_runway
rwy object as destination and its runway
departure
airport object as departure.
departure_runway
rwy object as departure and its runway
id
sid
star
sid_trans
star_trans
approach
current
aircraftCategory
followLegTrackToFix
activate()

Examples

# get the active flight plan (the one being used by the route manager)
var fp = flightplan();

# or create one an XML file
fp = flightplan('/path/to/xml');

# save the active flight plan
fgcommand("save-flightplan", props.Node.new({"path": 'path/to/xml'}));

# duplicate a flight-plan
var secondary = fp.clone();

var dest = airportinfo('KSFO');
var rwy = dest.runway('19L');
# the the arrival runway (and airport, automatically)
fp.destination_runway = rwy;

# or if no runway is known/specified
fp.destination = dest;

Building procedures and transitions. As mentioned above there's a couple of different ways to handle this, the examples below assume the C++ code automatically deletes and re-inserts waypoints for procedures, but that's only one possible design.

var apt = airportinfo('KSFO');
# example for SIDs, STARs are the same, approaches too
var allSids = apt.sids();

# SIDs for a specific runway - note these return SID IDs as string, for compatibility with existing code
var rwySids = apt.sids('28L');

Inserting and deleting waypoints (possibly in batches)

var fp = flightplan();
# waypoint created from lat, lon, or a navaid, or anything else?
var pos = geo.aircraft_position().apply_course_distance(getprop("/orientation/heading-deg"), 100000);
var wp = createWP(pos.lat(), pos.lon(), "EPICA");

# manually insert a waypoint at the end of the plan
fp.insertWP(wp, fp.getPlanSize());

# manually insert a waypoint at a defined position (n) into the plan
fp.insertWP(wp, n);

# route along airways, and insert a whole bunch of waypoints
# this is needed for the route-manager dialog, maybe not for a
# real FMS interface....
var segment = [<waypoint object>, <waypoint object>, <waypoint object>];
# segment is a vector of waypoints now
fp.insertWaypoints(segment, fp.getPlanSize());

aircraft.history() (3.2+)

Function to expose flight history as aircraft.history()

var hist = aircraft.history();

# get history of aircraft position/orientation collapsing
# nodes with a distance smaller than the given minimum
# edge length
debug.dump( hist.pathForHistory(<minimum-edge-length-meter>) );

Related content

Wiki articles

Documentation

Misc

Search Queries

Commits

Threads

References