2022-08-19 08:36:36 +08:00
|
|
|
#
|
|
|
|
# Aerotow Everywhere - Add-on for FlightGear
|
|
|
|
#
|
|
|
|
# Written and developer by Roman Ludwicki (PlayeRom, SP-ROM)
|
|
|
|
#
|
|
|
|
# Copyright (C) 2022 Roman Ludwicki
|
|
|
|
#
|
|
|
|
# Aerotow Everywhere is an Open Source project and it is licensed
|
|
|
|
# under the GNU Public License v3 (GPLv3)
|
|
|
|
#
|
|
|
|
|
|
|
|
#
|
2022-08-21 19:20:13 +08:00
|
|
|
# Class FlightPlan for crate and save as XML file the flight plan for AI scenario.
|
2022-08-19 08:36:36 +08:00
|
|
|
#
|
|
|
|
var FlightPlan = {
|
|
|
|
#
|
|
|
|
# Constants
|
|
|
|
#
|
|
|
|
FILENAME_FLIGHTPLAN: "aerotown-addon-flightplan.xml",
|
2022-08-20 09:53:42 +08:00
|
|
|
MAX_RUNWAY_DISTANCE: 100, # meters
|
2022-08-19 08:36:36 +08:00
|
|
|
|
|
|
|
#
|
|
|
|
# Constructor
|
|
|
|
#
|
|
|
|
# addon - Addon object
|
|
|
|
# message - Message object
|
|
|
|
# routeDialog - RouteDialog object
|
|
|
|
#
|
|
|
|
new: func (addon, message, routeDialog) {
|
|
|
|
var obj = { parents: [FlightPlan] };
|
|
|
|
|
2022-08-19 09:39:09 +08:00
|
|
|
obj.addon = addon;
|
|
|
|
obj.message = message;
|
|
|
|
obj.routeDialog = routeDialog;
|
|
|
|
obj.flightPlanWriter = FlightPlanWriter.new(addon);
|
2022-08-19 08:36:36 +08:00
|
|
|
|
|
|
|
obj.addonNodePath = addon.node.getPath();
|
|
|
|
|
|
|
|
obj.coord = nil; # Coordinates for flight plan
|
|
|
|
obj.heading = nil; # AI plane heading
|
|
|
|
obj.altitude = nil; # AI plane altitude
|
|
|
|
|
|
|
|
return obj;
|
|
|
|
},
|
|
|
|
|
|
|
|
#
|
2022-08-20 07:25:12 +08:00
|
|
|
# Get inital location of glider.
|
2022-08-19 08:36:36 +08:00
|
|
|
#
|
2022-08-27 02:57:41 +08:00
|
|
|
# Return object with "lat", "lon" and "heading".
|
2022-08-19 08:36:36 +08:00
|
|
|
#
|
2022-08-20 07:25:12 +08:00
|
|
|
getLocation: func () {
|
2022-08-19 08:36:36 +08:00
|
|
|
var icao = getprop("/sim/airport/closest-airport-id");
|
2022-08-20 07:25:12 +08:00
|
|
|
if (icao == nil or icao == "") {
|
2022-08-19 08:36:36 +08:00
|
|
|
me.message.error("Airport code cannot be obtained.");
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
2022-08-20 07:25:12 +08:00
|
|
|
# Find nearest runway threshold
|
|
|
|
var airport = airportinfo(icao);
|
|
|
|
if (airport == nil) {
|
|
|
|
me.message.error("An airport with the code " ~ icao ~ " cannot be found.");
|
2022-08-19 08:36:36 +08:00
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
2022-08-20 07:25:12 +08:00
|
|
|
var gliderCoord = geo.aircraft_position();
|
2022-08-19 08:36:36 +08:00
|
|
|
|
2022-08-20 07:25:12 +08:00
|
|
|
var rwyResult = me.findRunway(airport, gliderCoord);
|
|
|
|
|
2022-08-20 09:53:42 +08:00
|
|
|
if (rwyResult.distance > FlightPlan.MAX_RUNWAY_DISTANCE) {
|
2022-08-20 07:25:12 +08:00
|
|
|
# The runway is too far away, we assume a bush start
|
|
|
|
return {
|
2022-09-09 09:48:20 +08:00
|
|
|
"type" : "bush",
|
|
|
|
"lat" : gliderCoord.lat(),
|
|
|
|
"lon" : gliderCoord.lon(),
|
|
|
|
"heading" : getprop("/orientation/heading-deg"),
|
|
|
|
"elevation": me.getEleveationInFt(gliderCoord),
|
2022-08-20 07:25:12 +08:00
|
|
|
};
|
2022-08-19 08:36:36 +08:00
|
|
|
}
|
|
|
|
|
2022-08-20 07:25:12 +08:00
|
|
|
# We have a runway
|
2022-08-19 08:36:36 +08:00
|
|
|
|
|
|
|
var minRwyLength = Aircraft.getSelected(me.addon).minRwyLength;
|
2022-08-20 07:25:12 +08:00
|
|
|
if (rwyResult.runway.length < minRwyLength) {
|
2022-08-19 08:36:36 +08:00
|
|
|
me.message.error(
|
|
|
|
"This runway is too short. Please choose a longer one than " ~ minRwyLength ~ " m "
|
|
|
|
~ "(" ~ math.round(minRwyLength * globals.M2FT) ~ " ft)."
|
|
|
|
);
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
2022-09-09 09:48:20 +08:00
|
|
|
"type" : "runway",
|
|
|
|
"lat" : rwyResult.runway.lat,
|
|
|
|
"lon" : rwyResult.runway.lon,
|
|
|
|
"heading" : rwyResult.runway.heading,
|
|
|
|
"elevation": me.getEleveationInFt(
|
|
|
|
geo.Coord.new().set_latlon(rwyResult.runway.lat, rwyResult.runway.lon)
|
|
|
|
),
|
|
|
|
"length" : rwyResult.runway.length,
|
2022-08-21 19:20:13 +08:00
|
|
|
};
|
2022-08-20 07:25:12 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
#
|
|
|
|
# Find nearest runway for given airport
|
|
|
|
#
|
|
|
|
# Return hash with distance to nearest runway threshold and runway object itself.
|
|
|
|
#
|
|
|
|
findRunway: func (airport, gliderCoord) {
|
|
|
|
var result = {
|
|
|
|
"runway" : nil,
|
|
|
|
"distance" : 999999999,
|
2022-08-19 08:36:36 +08:00
|
|
|
};
|
2022-08-20 07:25:12 +08:00
|
|
|
|
|
|
|
foreach (var runwayName; keys(airport.runways)) {
|
|
|
|
var runway = airport.runways[runwayName];
|
|
|
|
var rwyThreshold = geo.Coord.new().set_latlon(runway.lat, runway.lon);
|
|
|
|
|
|
|
|
var distanceToThreshold = rwyThreshold.distance_to(gliderCoord);
|
|
|
|
if (distanceToThreshold < result.distance) {
|
|
|
|
result.runway = runway;
|
|
|
|
result.distance = distanceToThreshold;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
2022-08-19 08:36:36 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
#
|
|
|
|
# Initialize flight plan and set it to property tree
|
|
|
|
#
|
2022-08-22 22:29:31 +08:00
|
|
|
# Return true on successful, otherwise false.
|
2022-08-19 08:36:36 +08:00
|
|
|
#
|
|
|
|
initial: func () {
|
2022-08-20 07:25:12 +08:00
|
|
|
var location = me.getLocation();
|
2022-08-19 08:36:36 +08:00
|
|
|
if (location == nil) {
|
2022-08-22 22:29:31 +08:00
|
|
|
return false;
|
2022-08-19 08:36:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
var aircraft = Aircraft.getSelected(me.addon);
|
|
|
|
|
2022-08-22 22:29:31 +08:00
|
|
|
var isGliderPos = false;
|
2022-08-20 07:25:12 +08:00
|
|
|
me.initAircraftVariable(location, isGliderPos);
|
2022-08-19 08:36:36 +08:00
|
|
|
|
2022-08-27 02:57:41 +08:00
|
|
|
# Max altitude without limits
|
|
|
|
setprop(me.addonNodePath ~ "/addon-devel/route/wpts/max-alt-agl", 0);
|
|
|
|
|
2022-08-19 08:36:36 +08:00
|
|
|
# inittial readonly waypoint
|
|
|
|
setprop(me.addonNodePath ~ "/addon-devel/route/init-wpt/heading-change", me.heading);
|
|
|
|
setprop(me.addonNodePath ~ "/addon-devel/route/init-wpt/distance-m", 100);
|
|
|
|
setprop(me.addonNodePath ~ "/addon-devel/route/init-wpt/alt-change-agl-ft", aircraft.vs / 10);
|
|
|
|
|
|
|
|
# in air
|
|
|
|
var wptData = [
|
|
|
|
{"hdgChange": 0, "dist": 5000, "altChange": aircraft.vs * 5},
|
|
|
|
{"hdgChange": -90, "dist": 1000, "altChange": aircraft.vs},
|
2022-09-09 09:48:20 +08:00
|
|
|
{"hdgChange": -90, "dist": 6000, "altChange": aircraft.vs * 6},
|
2022-08-19 08:36:36 +08:00
|
|
|
{"hdgChange": -90, "dist": 1500, "altChange": aircraft.vs * 1.5},
|
2022-09-09 09:48:20 +08:00
|
|
|
{"hdgChange": -90, "dist": 6000, "altChange": aircraft.vs * 6},
|
|
|
|
{"hdgChange": 0, "dist": 0, "altChange": 0},
|
|
|
|
{"hdgChange": 0, "dist": 0, "altChange": 0},
|
2022-08-19 08:36:36 +08:00
|
|
|
{"hdgChange": 0, "dist": 0, "altChange": 0},
|
|
|
|
{"hdgChange": 0, "dist": 0, "altChange": 0},
|
|
|
|
{"hdgChange": 0, "dist": 0, "altChange": 0},
|
|
|
|
];
|
|
|
|
|
|
|
|
# Default route
|
|
|
|
# ^ - airport with heading direction to north
|
|
|
|
# 1 - 1st waypoint
|
|
|
|
# 2 - 2nd waypoint, etc.
|
|
|
|
#
|
2022-09-09 09:48:20 +08:00
|
|
|
# 2 . . 1 5
|
|
|
|
# . . .
|
2022-08-19 08:36:36 +08:00
|
|
|
# . . .
|
|
|
|
# . . .
|
|
|
|
# . . .
|
|
|
|
# . . .
|
|
|
|
# . . .
|
|
|
|
# . . .
|
|
|
|
# . . .
|
|
|
|
# . . .
|
2022-09-09 09:48:20 +08:00
|
|
|
# . ^ .
|
2022-08-19 08:36:36 +08:00
|
|
|
# . .
|
|
|
|
# . .
|
2022-09-09 09:48:20 +08:00
|
|
|
# 3 . . . . 4
|
2022-08-19 08:36:36 +08:00
|
|
|
|
|
|
|
var index = 0;
|
|
|
|
foreach (var wpt; wptData) {
|
2022-08-21 03:49:31 +08:00
|
|
|
setprop(me.addonNodePath ~ "/addon-devel/route/wpts/wpt[" ~ index ~ "]/heading-change", wpt.hdgChange);
|
|
|
|
setprop(me.addonNodePath ~ "/addon-devel/route/wpts/wpt[" ~ index ~ "]/distance-m", wpt.dist);
|
|
|
|
setprop(me.addonNodePath ~ "/addon-devel/route/wpts/wpt[" ~ index ~ "]/alt-change-agl-ft", wpt.altChange);
|
2022-08-19 08:36:36 +08:00
|
|
|
|
2022-08-20 09:53:42 +08:00
|
|
|
index += 1;
|
2022-08-19 08:36:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
me.routeDialog.calculateAltChangeAndTotals();
|
|
|
|
|
2022-08-21 03:49:31 +08:00
|
|
|
setprop(me.addonNodePath ~ "/addon-devel/route/wpts/description", "Default route around the start location");
|
|
|
|
|
2022-08-22 22:29:31 +08:00
|
|
|
return true;
|
2022-08-19 08:36:36 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
#
|
|
|
|
# Generate the XML file with the flight plane for our plane for AI scenario.
|
2022-08-23 18:19:22 +08:00
|
|
|
# The file will be stored to $FG_HOME/Export/Addons/org.flightgear.addons.Aerotow/AI/FlightPlans/aerotown-addon-flightplan.xml.
|
2022-08-19 08:36:36 +08:00
|
|
|
#
|
2022-08-22 22:29:31 +08:00
|
|
|
# Return true on successful, otherwise false.
|
2022-08-19 08:36:36 +08:00
|
|
|
#
|
|
|
|
generateXml: func () {
|
2022-08-20 07:25:12 +08:00
|
|
|
var location = me.getLocation();
|
2022-08-19 08:36:36 +08:00
|
|
|
if (location == nil) {
|
2022-08-22 22:29:31 +08:00
|
|
|
return false;
|
2022-08-19 08:36:36 +08:00
|
|
|
}
|
|
|
|
|
2022-08-19 09:39:09 +08:00
|
|
|
me.flightPlanWriter.open();
|
2022-08-19 08:36:36 +08:00
|
|
|
|
|
|
|
var aircraft = Aircraft.getSelected(me.addon);
|
|
|
|
|
2022-08-22 22:29:31 +08:00
|
|
|
var isGliderPos = true;
|
2022-08-20 07:25:12 +08:00
|
|
|
me.initAircraftVariable(location, isGliderPos);
|
2022-08-19 08:36:36 +08:00
|
|
|
|
|
|
|
# Start at 2 o'clock from the glider...
|
|
|
|
# Inital ktas must be >= 1.0
|
2022-09-09 09:48:20 +08:00
|
|
|
me.addWptGround({"shift": {"hdgChange": 60, "dist": 25, "altChange": 0}, "ktas": 5}); # 1
|
2022-08-19 08:36:36 +08:00
|
|
|
|
|
|
|
# Reset coord and heading
|
2022-08-22 22:29:31 +08:00
|
|
|
isGliderPos = false;
|
2022-08-20 07:25:12 +08:00
|
|
|
me.initAircraftVariable(location, isGliderPos);
|
2022-08-19 08:36:36 +08:00
|
|
|
|
2022-08-20 07:25:12 +08:00
|
|
|
var gliderOffsetM = me.getGliderOffsetFromRunwayThreshold(location);
|
2022-08-19 08:36:36 +08:00
|
|
|
|
|
|
|
# ... and line up with the runway
|
2022-09-09 09:48:20 +08:00
|
|
|
me.addWptGround({"shift": {"hdgChange": 0, "dist": me.getInitialDistance() + gliderOffsetM, "altChange": 0}, "ktas": 2.5}); # 2
|
2022-08-19 08:36:36 +08:00
|
|
|
|
|
|
|
# Rolling
|
2022-09-09 09:48:20 +08:00
|
|
|
me.addWptGround({"shift": {"hdgChange": 0, "dist": 10, "altChange": 0}, "ktas": 5}); # 3
|
|
|
|
me.addWptGround({"shift": {"hdgChange": 0, "dist": 20, "altChange": 0}, "ktas": 5}); # 4
|
|
|
|
me.addWptGround({"shift": {"hdgChange": 0, "dist": 20, "altChange": 0}, "ktas": aircraft.speed / 6}); # 5
|
|
|
|
me.addWptGround({"shift": {"hdgChange": 0, "dist": 10, "altChange": 0}, "ktas": aircraft.speed / 5}); # 6
|
|
|
|
me.addWptGround({"shift": {"hdgChange": 0, "dist": 10 * aircraft.rolling, "altChange": 0}, "ktas": aircraft.speed / 4}); # 7
|
|
|
|
me.addWptGround({"shift": {"hdgChange": 0, "dist": 10 * aircraft.rolling, "altChange": 0}, "ktas": aircraft.speed / 3.5}); # 8
|
|
|
|
me.addWptGround({"shift": {"hdgChange": 0, "dist": 10 * aircraft.rolling, "altChange": 0}, "ktas": aircraft.speed / 3}); # 9
|
|
|
|
me.addWptGround({"shift": {"hdgChange": 0, "dist": 10 * aircraft.rolling, "altChange": 0}, "ktas": aircraft.speed / 2.5}); # 10
|
|
|
|
me.addWptGround({"shift": {"hdgChange": 0, "dist": 10 * aircraft.rolling, "altChange": 0}, "ktas": aircraft.speed / 2}); # 11
|
|
|
|
me.addWptGround({"shift": {"hdgChange": 0, "dist": 10 * aircraft.rolling, "altChange": 0}, "ktas": aircraft.speed / 1.75}); # 12
|
|
|
|
me.addWptGround({"shift": {"hdgChange": 0, "dist": 10 * aircraft.rolling, "altChange": 0}, "ktas": aircraft.speed / 1.5}); # 13
|
|
|
|
me.addWptGround({"shift": {"hdgChange": 0, "dist": 10 * aircraft.rolling, "altChange": 0}, "ktas": aircraft.speed / 1.25}); # 14
|
|
|
|
me.addWptGround({"shift": {"hdgChange": 0, "dist": 10 * aircraft.rolling, "altChange": 0}, "ktas": aircraft.speed}); # 15
|
2022-08-19 08:36:36 +08:00
|
|
|
|
2022-08-20 07:25:12 +08:00
|
|
|
# Take-off
|
2022-09-09 09:48:20 +08:00
|
|
|
me.addWptAir({ "shift": {"hdgChange": 0, "dist": 100 * aircraft.rolling, "elevation": 3}, "ktas": aircraft.speed * 1.05}); # 16
|
|
|
|
me.addWptAir({ "shift": {"hdgChange": 0, "dist": 100, "altChange": aircraft.vs / 10}, "ktas": aircraft.speed * 1.025}); # 17
|
2022-08-19 08:36:36 +08:00
|
|
|
|
2022-08-27 02:57:41 +08:00
|
|
|
|
|
|
|
# 0 means without altitude limits
|
|
|
|
var maxAltAgl = getprop(me.addonNodePath ~ "/addon-devel/route/wpts/max-alt-agl") or 0;
|
|
|
|
var totalAlt = 0.0;
|
|
|
|
var isAltLimit = false;
|
|
|
|
|
|
|
|
# Add waypoints according to user settings
|
2022-08-19 08:36:36 +08:00
|
|
|
var speedInc = 1.0;
|
2022-08-21 03:49:31 +08:00
|
|
|
foreach (var wptNode; props.globals.getNode(me.addonNodePath ~ "/addon-devel/route/wpts").getChildren("wpt")) {
|
2022-08-27 02:57:41 +08:00
|
|
|
var distance = wptNode.getChild("distance-m").getValue();
|
|
|
|
if (distance <= 0.0) {
|
2022-08-19 08:36:36 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
var hdgChange = wptNode.getChild("heading-change").getValue();
|
|
|
|
|
2022-08-27 02:57:41 +08:00
|
|
|
# If we have reached the altitude limit, the altitude no longer changes (0)
|
|
|
|
var altChange = isAltLimit ? 0 : aircraft.getAltChange(distance);
|
|
|
|
if (maxAltAgl > 0 and altChange > 0 and totalAlt + altChange > maxAltAgl) {
|
|
|
|
# We will exceed the altitude limit, so set the altChange to the altitude limit
|
|
|
|
# and set isAltLimit flag that the limit is reached.
|
|
|
|
altChange = maxAltAgl - totalAlt;
|
|
|
|
isAltLimit = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
speedInc += ((distance / Aircraft.DISTANCE_DETERMINANT) * 0.025);
|
2022-08-19 08:36:36 +08:00
|
|
|
var ktas = aircraft.speed * speedInc;
|
|
|
|
if (ktas > aircraft.speedLimit) {
|
|
|
|
ktas = aircraft.speedLimit;
|
|
|
|
}
|
|
|
|
|
2022-08-27 02:57:41 +08:00
|
|
|
totalAlt += altChange;
|
|
|
|
|
2022-09-09 09:48:20 +08:00
|
|
|
me.addWptAir({"shift": {"hdgChange": hdgChange, "dist": distance, "altChange": altChange}, "ktas": ktas});
|
2022-08-19 08:36:36 +08:00
|
|
|
}
|
|
|
|
|
2022-09-09 09:48:20 +08:00
|
|
|
# Back to airport if possible
|
|
|
|
if (location.type == "runway") {
|
|
|
|
# Add extra near waypoint to keep plane in whole designed track
|
|
|
|
me.addWptAir({"shift": {"hdgChange": hdgChange, "dist": 100, "altChange": altChange}, "ktas": ktas});
|
|
|
|
|
|
|
|
var coordRwyThreshold = geo.Coord.new().set_latlon(location.lat, location.lon);;
|
|
|
|
|
|
|
|
# Check distance to runway threshold
|
|
|
|
var dostanceToThreshold = me.coord.distance_to(coordRwyThreshold);
|
|
|
|
|
|
|
|
# Reset variables
|
|
|
|
me.heading = location.heading; # runway heading
|
|
|
|
me.coord = coordRwyThreshold;
|
|
|
|
|
|
|
|
# Move o the left of the runway threshold
|
|
|
|
me.heading = me.correctHeading(me.heading - 90);
|
|
|
|
me.coord.apply_course_distance(me.heading, 1000);
|
|
|
|
|
|
|
|
# Add a waypoint to the left of the runway + 3000 m to the middle of length
|
|
|
|
# Descend as far as you can to max elevation + 3000 ft
|
|
|
|
var halfRwyLenght = location.length / 2;
|
|
|
|
var altAgl = me.altitude - location.elevation;
|
|
|
|
var elevation = altAgl - (aircraft.getAltChange(dostanceToThreshold) * 2);
|
|
|
|
if (elevation < 3000) {
|
|
|
|
elevation = 3000;
|
|
|
|
}
|
|
|
|
me.addWptAir({"shift": {"hdgChange": 90, "dist": halfRwyLenght, "elevation": elevation}, "ktas": aircraft.speed});
|
|
|
|
|
|
|
|
# Fly downwind away of threshold, how far depend of the altitude
|
|
|
|
var desiredElevation = 2000;
|
|
|
|
var distance = (((elevation - desiredElevation) / (aircraft.vs * 3)) * 1000);
|
|
|
|
if (distance < 3000) {
|
|
|
|
distance = 3000;
|
|
|
|
}
|
|
|
|
me.addWptAir({"shift": {"hdgChange": -180, "dist": halfRwyLenght + distance, "elevation": desiredElevation}, "ktas": aircraft.speed});
|
|
|
|
|
|
|
|
# Turn to base leg
|
|
|
|
me.addWptAir({"shift": {"hdgChange": -90, "dist": 1000, "elevation": 1000}, "ktas": aircraft.speed, "flapsDown": true});
|
|
|
|
|
|
|
|
# Reset variables
|
|
|
|
me.coord = geo.Coord.new().set_latlon(location.lat, location.lon); # runway threshold
|
|
|
|
|
|
|
|
# Turn on final
|
|
|
|
me.addWptAir({
|
|
|
|
"coord" : me.coord,
|
|
|
|
"crossAt" : location.elevation + 10,
|
|
|
|
"ktas" : aircraft.speed * 0.75,
|
|
|
|
"flapsDown": true,
|
|
|
|
"gearDown" : true,
|
|
|
|
});
|
|
|
|
|
|
|
|
# Reset variables
|
|
|
|
me.heading = location.heading;
|
|
|
|
|
|
|
|
# Flare
|
|
|
|
me.addWptAir({
|
|
|
|
"shift" : {"hdgChange": 0, "dist": 100, "elevation": 10},
|
|
|
|
"ktas" : aircraft.speed * 0.7,
|
|
|
|
"flapsDown": true,
|
|
|
|
"gearDown" : true,
|
|
|
|
});
|
|
|
|
|
|
|
|
# Touchdown
|
|
|
|
me.addWptGround({"shift": {"hdgChange": 0, "dist": 200, "elevation": 0}, "ktas": aircraft.speed * 0.6});
|
|
|
|
|
|
|
|
# Break
|
|
|
|
me.addWptGround({"shift": {"hdgChange": 0, "dist": 200, "elevation": 0}, "ktas": aircraft.speed * 0.4});
|
|
|
|
|
|
|
|
# Slow down to 5 kt
|
|
|
|
me.addWptGround({"shift": {"hdgChange": 0, "dist": 50, "elevation": 0}, "ktas": 5});
|
|
|
|
|
|
|
|
# Turn right out of runway and full stop
|
|
|
|
me.addWptEnd({"shift": {"hdgChange": 90, "dist": 100, "elevation": 0}, "ktas": 0, "onGround": true});
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
me.addWptEnd();
|
|
|
|
}
|
2022-08-19 08:36:36 +08:00
|
|
|
|
2022-08-19 09:39:09 +08:00
|
|
|
me.flightPlanWriter.close();
|
2022-08-19 08:36:36 +08:00
|
|
|
|
2022-08-22 22:29:31 +08:00
|
|
|
return true;
|
2022-08-19 08:36:36 +08:00
|
|
|
},
|
|
|
|
|
2022-08-22 03:35:15 +08:00
|
|
|
#
|
|
|
|
# Get initial distance AI plane from the glider that the tow is nearly tautened.
|
|
|
|
#
|
|
|
|
# Return distance in meters.
|
|
|
|
#
|
|
|
|
getInitialDistance: func () {
|
|
|
|
var ropeLengthM = getprop("/sim/hitches/aerotow/tow/length") or 60;
|
|
|
|
var tautenRelative = 0.68;
|
|
|
|
return ropeLengthM * tautenRelative;
|
|
|
|
},
|
|
|
|
|
2022-08-19 08:36:36 +08:00
|
|
|
#
|
|
|
|
# Initialize AI aircraft variable
|
|
|
|
#
|
2022-08-20 07:25:12 +08:00
|
|
|
# location - Object of location from which the glider start.
|
2022-08-22 22:29:31 +08:00
|
|
|
# isGliderPos - Pass true for set AI aircraft's coordinates as glider position, false set coordinates as runway threshold.
|
2022-08-19 08:36:36 +08:00
|
|
|
#
|
2022-08-22 22:29:31 +08:00
|
|
|
initAircraftVariable: func (location, isGliderPos) {
|
2022-08-19 08:36:36 +08:00
|
|
|
var gliderCoord = geo.aircraft_position();
|
|
|
|
|
|
|
|
# Set coordinates as glider position or runway threshold
|
|
|
|
me.coord = isGliderPos
|
|
|
|
? gliderCoord
|
2022-08-20 07:25:12 +08:00
|
|
|
: geo.Coord.new().set_latlon(location.lat, location.lon);
|
2022-08-19 08:36:36 +08:00
|
|
|
|
2022-08-20 07:25:12 +08:00
|
|
|
# Set airplane heading as runway or glider heading
|
|
|
|
me.heading = location.heading;
|
2022-08-19 08:36:36 +08:00
|
|
|
|
|
|
|
# Set AI airplane altitude as glider altitude (assumed it's on the ground).
|
|
|
|
# It is more accurate than airport.elevation.
|
|
|
|
me.altitude = gliderCoord.alt() * globals.M2FT;
|
|
|
|
},
|
|
|
|
|
|
|
|
#
|
|
|
|
# Get distance from glider to runway threshold e.g. in case that the user taxi from the runway threshold
|
|
|
|
#
|
2022-08-20 07:25:12 +08:00
|
|
|
# location - Object of location from which the glider start.
|
2022-08-19 08:36:36 +08:00
|
|
|
# Return the distance in metres, of the glider's displacement from the runway threshold.
|
|
|
|
#
|
2022-08-20 07:25:12 +08:00
|
|
|
getGliderOffsetFromRunwayThreshold: func (location) {
|
|
|
|
if (location.type == "runway") {
|
|
|
|
var gliderCoord = geo.aircraft_position();
|
|
|
|
var rwyThreshold = geo.Coord.new().set_latlon(location.lat, location.lon);
|
|
|
|
|
|
|
|
return rwyThreshold.distance_to(gliderCoord);
|
|
|
|
}
|
2022-08-19 08:36:36 +08:00
|
|
|
|
2022-08-22 22:29:31 +08:00
|
|
|
# We are not on the runway, return 0 distance
|
2022-08-20 07:25:12 +08:00
|
|
|
return 0;
|
2022-08-19 08:36:36 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
#
|
|
|
|
# Add new waypoint on ground
|
|
|
|
#
|
2022-09-09 09:48:20 +08:00
|
|
|
# wptData - hash object with waypoint data
|
2022-08-19 08:36:36 +08:00
|
|
|
#
|
2022-09-09 09:48:20 +08:00
|
|
|
addWptGround: func (wptData) {
|
|
|
|
wptData.onGround = true;
|
|
|
|
me.addWpt(wptData);
|
2022-08-19 08:36:36 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
#
|
|
|
|
# Add new waypoint in air
|
|
|
|
#
|
2022-09-09 09:48:20 +08:00
|
|
|
# wptData - hash object wtih waypoint data
|
|
|
|
#
|
|
|
|
addWptAir: func (wptData) {
|
|
|
|
if (contains(wptData, "onGround")) {
|
|
|
|
wptData.onGround = nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
me.addWpt(wptData);
|
2022-08-19 08:36:36 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
#
|
|
|
|
# Add "WAIT" waypoint
|
|
|
|
#
|
|
|
|
# sec - Number of seconds for wait
|
|
|
|
#
|
|
|
|
addWptWait: func (sec) {
|
2022-09-09 09:48:20 +08:00
|
|
|
me.addWpt({"waitSec": sec});
|
2022-08-19 08:36:36 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
#
|
2022-09-09 09:48:20 +08:00
|
|
|
# Add "END" waypoint with optional waypoint data
|
2022-08-19 08:36:36 +08:00
|
|
|
#
|
2022-09-09 09:48:20 +08:00
|
|
|
addWptEnd: func (wptData = nil) {
|
|
|
|
if (wptData == nil) {
|
|
|
|
wptData = {};
|
|
|
|
}
|
|
|
|
|
|
|
|
wptData.name = "END";
|
|
|
|
|
|
|
|
me.addWpt(wptData);
|
2022-08-19 08:36:36 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
#
|
2022-09-09 09:48:20 +08:00
|
|
|
# Add new waypoint with given waypoint data
|
|
|
|
#
|
|
|
|
# wptData = {
|
|
|
|
# shift: { - Optionally hash with data to calculate next coordinates (lat, lon) and altitude of waypoint
|
|
|
|
# hdgChange - How the aircraft's heading supposed to change? 0 - keep the same heading.
|
|
|
|
# dist - Distance in meters to calculate next waypoint coordinates.
|
|
|
|
# altChange - How the aircraft's altitude is supposed to change? 0 - keep the same altitude.
|
|
|
|
# elevation - Set aircraft altitude as current terrain elevation + given value in feets.
|
|
|
|
# It's best to use for the first point in the air to avoid the plane collapsing into
|
|
|
|
# the ground in a bumpy airport.
|
|
|
|
# },
|
|
|
|
# coord - The geo.Coord object, required if shift is not given
|
|
|
|
# crossAt - Altitude in feet, required if shift is not given
|
|
|
|
# ktas - True airspeed in knots, required
|
|
|
|
# onGround - If true then set on ground, otherwise set in air
|
|
|
|
# flapsDown - If true then set flaps down, otherwise set flaps up
|
|
|
|
# gearDown - If true then set gear down, otherwise set gear up
|
|
|
|
# waitSec - Number of seconds for WIAT waypoint
|
|
|
|
# }
|
|
|
|
#
|
|
|
|
addWpt: func (wptData) {
|
|
|
|
if (contains(wptData, "shift")) {
|
|
|
|
me.shiftWpt(wptData.shift);
|
2022-08-19 08:36:36 +08:00
|
|
|
|
2022-09-09 09:48:20 +08:00
|
|
|
# Set coord and crossAt updated by shiftWpt()
|
|
|
|
wptData.coord = me.coord;
|
|
|
|
wptData.crossAt = me.altitude;
|
|
|
|
}
|
|
|
|
|
|
|
|
var wpt = Waypoint.new().setHashData(wptData);
|
|
|
|
|
|
|
|
me.flightPlanWriter.write(wpt);
|
|
|
|
},
|
|
|
|
|
|
|
|
#
|
|
|
|
# Calculate heading, coordinates and altitude from data in wptShift hash
|
|
|
|
#
|
|
|
|
# wptShift - hash object with data
|
|
|
|
#
|
|
|
|
shiftWpt: func (wptShift) {
|
|
|
|
if (!contains(wptShift, "hdgChange")) {
|
|
|
|
die("ERROR aerotow add-on: missing 'hdgChange' for computeWptShift");
|
|
|
|
}
|
2022-08-19 08:36:36 +08:00
|
|
|
|
2022-09-09 09:48:20 +08:00
|
|
|
if (!contains(wptShift, "dist")) {
|
|
|
|
die("ERROR aerotow add-on: missing 'dist' for computeWptShift");
|
2022-08-19 08:36:36 +08:00
|
|
|
}
|
|
|
|
|
2022-09-09 09:48:20 +08:00
|
|
|
# Shift heading and coordinates
|
|
|
|
me.heading = me.correctHeading(me.heading + wptShift.hdgChange);
|
|
|
|
me.coord.apply_course_distance(me.heading, wptShift.dist);
|
|
|
|
|
|
|
|
if (contains(wptShift, "elevation")) {
|
|
|
|
# Set the altitude as the elevation for coordinates of the point plus the given elevation
|
|
|
|
me.altitude = me.getEleveationInFt(me.coord) + wptShift.elevation;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (contains(wptShift, "altChange")) {
|
|
|
|
# Change altitude by given altChange
|
|
|
|
me.altitude += wptShift.altChange;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
#
|
|
|
|
# Correct the heading value that to be from 0 to 360
|
|
|
|
#
|
|
|
|
# heading - heading for correction
|
|
|
|
# Return heading in range from 0 to 360.
|
|
|
|
#
|
|
|
|
correctHeading: func (heading) {
|
|
|
|
if (heading < 0) {
|
|
|
|
heading += 360;
|
2022-08-19 08:36:36 +08:00
|
|
|
}
|
2022-09-09 09:48:20 +08:00
|
|
|
|
|
|
|
if (heading > 360) {
|
|
|
|
heading -= 360;
|
2022-08-19 08:36:36 +08:00
|
|
|
}
|
|
|
|
|
2022-09-09 09:48:20 +08:00
|
|
|
return heading;
|
|
|
|
},
|
2022-08-19 08:36:36 +08:00
|
|
|
|
2022-09-09 09:48:20 +08:00
|
|
|
#
|
|
|
|
# Get elevation of given coordinates in feet
|
|
|
|
#
|
|
|
|
# coord - geo.Coord object
|
|
|
|
#
|
|
|
|
getEleveationInFt: func (coord) {
|
|
|
|
if (coord == nil) {
|
|
|
|
return nil;
|
|
|
|
}
|
2022-08-19 08:36:36 +08:00
|
|
|
|
2022-09-09 09:48:20 +08:00
|
|
|
return geo.elevation(coord.lat(), coord.lon()) * globals.M2FT;
|
2022-08-19 08:36:36 +08:00
|
|
|
},
|
|
|
|
};
|