17 Commits

Author SHA1 Message Date
PlayeRom
1d5bd7c7f5 Update version to 1.8.0 2022-09-09 19:04:05 +02:00
PlayeRom
c60097c8cd Update readme 2022-09-09 03:58:51 +02:00
PlayeRom
f3d50cc815 The plane returns to the airport from which it took off
There is one problem, that on touch down the plane is going underground on the short while.
2022-09-09 03:48:20 +02:00
PlayeRom
cbc1888425 Update version to 1.7.0 2022-08-26 20:59:48 +02:00
PlayeRom
ea72151d48 Add possibility to set max altitude in route dialog 2022-08-26 20:57:41 +02:00
PlayeRom
bcd7d3cca8 Update version to 1.6.0 2022-08-23 12:28:21 +02:00
PlayeRom
6cd64a486a Correction for comment and indents as spaces 2022-08-23 12:19:22 +02:00
PlayeRom
93a0d6f46d Merge pull request #3 from wlbragg/Sound-configuration-change
Remove unused sounds, interior and exterior sound
2022-08-23 12:14:37 +02:00
wlbragg
f4356c079f Remove unused sounds, interior and exterior sound 2022-08-22 15:32:06 -05:00
PlayeRom
9ed54d98b6 Add true and false global variables as aliases for boolean types to distinguish the use of "int" from "bool". 2022-08-22 16:29:31 +02:00
PlayeRom
b12e139b2c Update version to 1.5.0 2022-08-22 00:43:45 +02:00
PlayeRom
b1403b3066 Add Towrope Configuration dialog 2022-08-21 21:38:19 +02:00
PlayeRom
3376a6f35d Use towrope length for initial distance of AI plane 2022-08-21 21:35:15 +02:00
PlayeRom
1d22597d3f Update comments 2022-08-21 13:20:13 +02:00
PlayeRom
467336590b Add Timer class for simplify use maketimer() function with single shot 2022-08-21 13:10:42 +02:00
PlayeRom
5ce9a0a299 Update version to 1.4.1 2022-08-20 22:15:25 +02:00
PlayeRom
dff16702d4 Fix crash by missing parameter 2022-08-20 22:14:24 +02:00
23 changed files with 1063 additions and 233 deletions

View File

@@ -1,11 +1,31 @@
# CHANGELOG
## v.1.8.0
- The tow plane, after completing its route, returns to the runway from which it took off. For a bush take-off it does not land.
## v.1.7.0
- Add possibility to set max altitude in route dialog
## v.1.6.0
- Add sound support from internal and external view for C-74 aircraft (thanks to wlbragg)
## v.1.5.0
- Add Towrope Configuration dialog
## v.1.4.1
- Fix crash by missing parameter
## v.1.4.0
- Add Douglas C-47 as a tow plane
- Add Douglas C-47 as a tow plane (thanks to wlbragg)
- Add possibility to take off in the bush
- Add a separate engine sound for the DR400
- Add French translation of meta data
- Add French translation of meta data (thanks to Florent)
- Add possibility to save/load route waypoints with description
## v.1.3.0

View File

@@ -2,11 +2,39 @@
<PropertyList>
<fx>
<engine>
<name>engine</name>
<name>engineINT</name>
<mode>looped</mode>
<path>Croisiere_int_2.wav</path>
<condition>
<and>
<property>/addons/by-id/org.flightgear.addons.Aerotow/addon-devel/sound/enable</property>
<property>/sim/current-view/internal</property>
</and>
</condition>
<volume>
<offset>-0.80</offset>
</volume>
<pitch>
<property>velocities/true-airspeed-kt</property>
<factor>0.012</factor>
<offset>0.3</offset>
<min>0.3</min>
<max>1.0</max>
</pitch>
<reference-dist>150.0</reference-dist>
<max-dist>5000.0</max-dist>
</engine>
<engine>
<name>engineEXT</name>
<mode>looped</mode>
<path>Croisiere_ext_2.wav</path>
<condition>
<property>/addons/by-id/org.flightgear.addons.Aerotow/addon-devel/sound/enable</property>
<and>
<property>/addons/by-id/org.flightgear.addons.Aerotow/addon-devel/sound/enable</property>
<not>
<property>/sim/current-view/internal</property>
</not>
</and>
</condition>
<volume>
<offset>-0.80</offset>

View File

@@ -28,7 +28,7 @@ You can also take off in the bush. Then the tow plane will position itself in fr
## How does the AI tow aircraft fly by default?
The tow plane always takes off in front of your runway and flies along the runway for 5 km, then turns back and flies downwind for 6 km, then turns back again and flies another 6 km. During this flight it is constantly gaining altitude. Then when it has completed the entire set route it turns to unknown direction and flies at a constant altitude.
The tow plane always takes off in front of your runway and flies along the runway for 5 km, then turns back and flies downwind for 6 km, then turns back again and flies another 6 km. During this flight it is constantly gaining altitude. Then, after having flown the entire given route, it lands at the airport from which it took off or when start in the bush turns in an unknown direction and flies at a constant altitude. If the aircraft lands at the airport, the scenario starts again, i.e. the aircraft respawn to take-off again.
You can disconnect from the aircraft at any time, most often by pressing the `o` key (check help of your glider).
@@ -38,20 +38,20 @@ Default route
1 - 1st waypoint
2 - 2nd waypoint, etc.
2 . . 1 7
. . .
. . .
3 . .
2 . . 1 5
. . .
. . .
. . .
. . .
. . .
. . .
. ^ 6
. . .
. . .
. . .
. ^ .
. .
. .
4 . . . . 5
3 . . . . 4
```
## Menu of add-on
@@ -59,13 +59,15 @@ Default route
This add-on add a new item to main menu named `Aerotow Everywhere` with following items:
1. `Aerotow Route` - display the dialog for change aerotow route.
2. `Call for Piper J3 Cub aircraft` - load AI tow sceneraio with Piper J3 Cub.
3. `Call for Robin DR400 aircraft` - load AI tow sceneraio with Robin DR400. This aircraft has better performance and can take you higher then Piper Cub.
4. `Call for Cessna 182 aircraft` - load AI tow sceneraio with Cessna 182. This aircraft has little bit better performance than Robin.
5. `Disable tow aircraft` - unload AI tow sceneraio.
6. `Add thermal` - display the dialog for configuring and adding thermal.
7. `Help` - display help dialog.
8. `About` - display about dialog with add-on information.
2. `Towrope Configuration` - display the dialog for change towrope parameters.
3. `Call for Piper J3 Cub aircraft` - load AI tow sceneraio with Piper J3 Cub.
4. `Call for Robin DR400 aircraft` - load AI tow sceneraio with Robin DR400. This aircraft has better performance and can take you higher then Piper Cub.
5. `Call for Cessna 182 aircraft` - load AI tow sceneraio with Cessna 182. This aircraft has little bit better performance than Robin.
6. `Call for Douglas C-47 aircraft` - load AI tow sceneraio with Douglas C-47.
7. `Disable tow aircraft` - unload AI tow sceneraio.
8. `Add thermal` - display the dialog for configuring and adding thermal.
9. `Help` - display help dialog.
10. `About` - display about dialog with add-on information.
## Aerotow Route
@@ -75,6 +77,10 @@ You can change the AI aircraft's default route, for this go to menu `Aerotow Eve
On the top of the "Aerotow Route" dialog you have selector to change aircraft type. It's only for calculate performance and display how the altitude will change.
### Max alt (AGL)
Here you can set limit of AGL altitude. 0 means without limits - the plane will always increase its altitude during its flight. AGL is always in terms of the place you are starting from.
### Route
Next you have initial heading, distance and altitude change. "Initial heading" depend of the runway where you are located. The aircraft will always take-off along the runway, a distance of 100 m, where it will gain 20 ft in altitude above the terrain. These parameters you cannot change unless you change the airport/runway.
@@ -83,7 +89,7 @@ Next you can see a table with fields where you can change values. Each row repre
1. `Heading change (deg)` - information on how the heading of the aircraft should change in relation to the previous one. A value of `0` means no change, so continue with the same heading. And e.g. `-90` means a left turn of 90 degrees, `60` means a right turn of 60 degrees, etc.
2. `Distance (m)` - distance in meters from the previous waypoint to the present one.
3. `Alt change (AGL ft)` - information on how much the altitude on this leg of the route will increase (in feet above ground.) This information depend of selected airplane.
3. `Alt change (AGL ft)` - information on how much the altitude on this leg of the route will increase (in feet above ground.) This information depend of selected airplane. AGL is always in terms of the place you are starting from (not the waypoint place).
If you enter a value less than or equal to `0` for `Distance (m)` field this means that here the route is end and the next rows will not be included to the flight plan.

View File

@@ -44,6 +44,10 @@
<distance-m type="double">0</distance-m>
<alt-change-agl-ft type="double">0</alt-change-agl-ft>
</init-wpt>
<wpts>
<description type="string">Default route around the start location</description>
<max-alt-agl type="double"></max-alt-agl>
</wpts>
<total>
<distance>0</distance>
<alt>0</alt>

View File

@@ -30,7 +30,7 @@ var main = func(addon) {
loadExtraNasalFiles(addon);
createDirectories();
createDirectories(addon);
aerotow.init(addon);
}
@@ -42,12 +42,14 @@ var main = func(addon) {
#
var loadExtraNasalFiles = func (addon) {
var modules = [
"nasal/timer",
"nasal/aircraft",
"nasal/message",
"nasal/dialogs/route",
"nasal/dialogs/thermal",
"nasal/flight-plan",
"nasal/scenario",
"nasal/io/waypoint",
"nasal/io/flight-plan-writer",
"nasal/aerotow",
"aerotow",

View File

@@ -36,6 +36,13 @@
<dialog-name>route-aerotow</dialog-name>
</binding>
</item>
<item>
<label>Towrope Configuration</label>
<binding>
<command>dialog-show</command>
<dialog-name>towrope-config</dialog-name>
</binding>
</item>
<item>
<label>Call for Piper J3 Cub aircraft</label>
<binding>
@@ -79,11 +86,9 @@
<command>nasal</command>
<script><![CDATA[
# Run stopAerotow() with a delay to ensure that the engine sound turns off
var timer = maketimer(1, func () {
aerotow.Timer.new().singleShot(1, aerotow.g_Aerotow, func () {
aerotow.g_Aerotow.stopAerotow();
});
timer.singleShot = 1;
timer.start();
]]></script>
</binding>
</item>

View File

@@ -21,7 +21,7 @@
<addon>
<identifier type="string">org.flightgear.addons.Aerotow</identifier>
<name type="string">Aerotow Everywhere</name>
<version type="string">1.4.0</version>
<version type="string">1.8.0</version>
<authors>
<author>

View File

@@ -9,6 +9,16 @@
# under the GNU Public License v3 (GPLv3)
#
#
# Global aliases for boolean types to distinguish the use of "int" from "bool".
# NOTE: unfortunately, it doesn't work as an assignment of a default value for a function parameter!
#
var true = 1;
var false = 0;
#
# Global object of Aerotow
#
var g_Aerotow = nil;
#

View File

@@ -45,7 +45,7 @@
<hrule/>
<text>
<label>Aerotow Everywhere version 1.4.0 - 20th August 2022</label>
<label>Aerotow Everywhere version 1.8.0 - 9th September 2022</label>
</text>
<text>

View File

@@ -75,14 +75,14 @@
<row>0</row>
<col>0</col>
<halign>right</halign>
<label>Aerotow</label>
<label>Aerotow:</label>
</text>
<combo>
<row>0</row>
<col>1</col>
<halign>left</halign>
<pref-width>150</pref-width>
<pref-width>120</pref-width>
<live>true</live>
<property>/addons/by-id/org.flightgear.addons.Aerotow/addon-devel/route/ai-model</property>
<value>Piper J3 Cub</value>
@@ -93,6 +93,24 @@
<command>dialog-apply</command>
</binding>
</combo>
<text>
<row>0</row>
<col>2</col>
<halign>right</halign>
<label>Max alt (AGL):</label>
</text>
<input>
<row>0</row>
<col>3</col>
<halign>left</halign>
<property>/addons/by-id/org.flightgear.addons.Aerotow/addon-devel/route/wpts/max-alt-agl</property>
<live>true</live>
<binding>
<command>dialog-apply</command>
</binding>
</input>
</group>
<hrule/>
@@ -501,7 +519,7 @@
<input>
<halign>fill</halign>
<halign>left</halign>
<!-- <halign>left</halign> -->
<property>/addons/by-id/org.flightgear.addons.Aerotow/addon-devel/route/wpts/description</property>
<live>true</live>
<binding>

View File

@@ -0,0 +1,342 @@
<?xml version="1.0"?>
<PropertyList>
<name>towrope-config</name>
<layout>vbox</layout>
<default-padding>5</default-padding>
<modal>false</modal>
<width>680</width>
<!-- title bar -->
<group>
<layout>hbox</layout>
<empty>
<stretch>true</stretch>
</empty>
<text>
<label>Towrope Configuration</label>
</text>
<empty>
<stretch>true</stretch>
</empty>
<button>
<legend/>
<key>Esc</key>
<pref-width>16</pref-width>
<pref-height>16</pref-height>
<border>2</border>
<binding>
<command>dialog-close</command>
</binding>
</button>
</group>
<hrule/>
<!-- aerotow parameters -->
<group>
<layout>hbox</layout>
<group>
<layout>table</layout>
<!-- tow length -->
<text>
<row>0</row>
<col>0</col>
<halign>right</halign>
<label>Towrope Length</label>
</text>
<text>
<row>0</row>
<col>1</col>
<halign>right</halign>
<label></label>
<live>true</live>
<format>%.0f m </format>
<property>/sim/hitches/aerotow/tow/length</property>
<color>
<red>0.2</red>
<green>0.9</green>
<blue>0.2</blue>
</color>
</text>
<!-- break force -->
<text>
<row>1</row>
<col>0</col>
<halign>right</halign>
<label>Weak Link Break Force</label>
</text>
<text>
<row>1</row>
<col>1</col>
<halign>right</halign>
<label></label>
<live>true</live>
<format>%.0f N </format>
<property>/sim/hitches/aerotow/tow/brake-force</property>
<color>
<red>0.2</red>
<green>0.9</green>
<blue>0.2</blue>
</color>
</text>
<!-- tow characteristic -->
<text>
<row>2</row>
<col>0</col>
<halign>right</halign>
<label>Towrope Elastic Constant</label>
</text>
<text>
<row>2</row>
<col>1</col>
<halign>right</halign>
<label></label>
<live>true</live>
<format>%.0f N</format>
<property>/sim/hitches/aerotow/tow/elastic-constant</property>
<color>
<red>0.2</red>
<green>0.9</green>
<blue>0.2</blue>
</color>
</text>
<!-- tow thickness -->
<text>
<row>3</row>
<col>0</col>
<halign>right</halign>
<label>Towrope Diameter</label>
</text>
<text>
<row>3</row>
<col>1</col>
<halign>right</halign>
<label></label>
<live>true</live>
<format>%.0f mm</format>
<property>/sim/hitches/aerotow/rope/rope-diameter-mm</property>
<color>
<red>0.2</red>
<green>0.9</green>
<blue>0.2</blue>
</color>
</text>
<!-- tow weight -->
<text>
<row>4</row>
<col>0</col>
<halign>right</halign>
<label>Towrope Weight per Meter</label>
</text>
<text>
<row>4</row>
<col>1</col>
<halign>right</halign>
<label></label>
<live>true</live>
<format>%.3f kg/m</format>
<property>/sim/hitches/aerotow/tow/weight-per-m-kg-m</property>
<color>
<red>0.2</red>
<green>0.9</green>
<blue>0.2</blue>
</color>
</text>
</group>
<empty>
<stretch>true</stretch>
</empty>
<vrule/>
<group>
<layout>table</layout>
<!-- tow length -->
<text>
<row>0</row>
<col>1</col>
<halign>right</halign>
<label>20 m</label>
</text>
<slider>
<row>0</row>
<col>2</col>
<live>true</live>
<halign>fill</halign>
<pref-width>300</pref-width>
<name>tow_length</name>
<property>/sim/hitches/aerotow/tow/length</property>
<min>20</min>
<max>200</max>
<step>5</step>
<binding>
<command>dialog-apply</command>
</binding>
</slider>
<text>
<row>0</row>
<col>3</col>
<halign>left</halign>
<label>200 m</label>
</text>
<!-- break force -->
<text>
<row>1</row>
<col>1</col>
<halign>right</halign>
<label>100 N</label>
</text>
<slider>
<row>1</row>
<col>2</col>
<live>true</live>
<halign>fill</halign>
<pref-width>300</pref-width>
<name>break_force</name>
<property>/sim/hitches/aerotow/tow/brake-force</property>
<min>100</min>
<max>100000</max>
<step>100</step>
<binding>
<command>dialog-apply</command>
</binding>
</slider>
<text>
<row>1</row>
<col>3</col>
<halign>left</halign>
<label>100,000 N</label>
</text>
<!-- tow characteristic -->
<text>
<row>2</row>
<col>1</col>
<halign>right</halign>
<label>0 N</label>
</text>
<slider>
<row>2</row>
<col>2</col>
<live>true</live>
<halign>fill</halign>
<pref-width>300</pref-width>
<name>elastic_constant</name>
<property>/sim/hitches/aerotow/tow/elastic-constant</property>
<min>0</min>
<max>1500000</max>
<step>200</step>
<binding>
<command>dialog-apply</command>
</binding>
</slider>
<text>
<row>2</row>
<col>3</col>
<halign>left</halign>
<label>1,500,000 N</label>
</text>
<!-- tow thickness -->
<text>
<row>3</row>
<col>1</col>
<halign>right</halign>
<label>0 mm</label>
</text>
<slider>
<row>3</row>
<col>2</col>
<live>true</live>
<halign>fill</halign>
<pref-width>300</pref-width>
<name>rope_diameter</name>
<property>/sim/hitches/aerotow/rope/rope-diameter-mm</property>
<min>0</min>
<max>50</max>
<step>1</step>
<binding>
<command>dialog-apply</command>
</binding>
</slider>
<text>
<row>3</row>
<col>3</col>
<halign>left</halign>
<label>50 mm</label>
</text>
<!-- tow weight -->
<text>
<row>4</row>
<col>1</col>
<halign>right</halign>
<label>0 kg/m</label>
</text>
<slider>
<row>4</row>
<col>2</col>
<live>true</live>
<halign>fill</halign>
<pref-width>300</pref-width>
<name>weight_per_m</name>
<property>/sim/hitches/aerotow/tow/weight-per-m-kg-m</property>
<min>0</min>
<max>1</max>
<step>0.001</step>
<binding>
<command>dialog-apply</command>
</binding>
</slider>
<text>
<row>4</row>
<col>3</col>
<halign>left</halign>
<label>1 kg/m</label>
</text>
</group>
</group>
<hrule/>
<!-- bottom line -->
<group>
<layout>hbox</layout>
<empty>
<stretch>true</stretch>
</empty>
<button>
<legend>Close</legend>
<equal>true</equal>
<binding>
<command>dialog-close</command>
</binding>
</button>
<button>
<legend>Default</legend>
<equal>true</equal>
<binding>
<command>nasal</command>
<script><![CDATA[
setprop("/sim/hitches/aerotow/tow/length", 60.0); # hitch.nas 60.0
setprop("/sim/hitches/aerotow/tow/brake-force", 100000.0); # hitch.nas 12345.0
setprop("/sim/hitches/aerotow/tow/elastic-constant", 10000.0); # hitch.nas 9111.0
setprop("/sim/hitches/aerotow/rope/rope-diameter-mm", 20); # hitch.nas 20
setprop("/sim/hitches/aerotow/tow/weight-per-m-kg-m", 0.35); # hitch.nas 0.35
]]></script>
</binding>
</button>
<empty>
<stretch>true</stretch>
</empty>
</group>
</PropertyList>

View File

@@ -10,7 +10,7 @@
#
#
# Aerotow object
# Class Aerotow for enable and disable scenario with aerotow aircraft.
#
var Aerotow = {
#
@@ -51,20 +51,16 @@ var Aerotow = {
#
# Function for restart AI scenario with delay when the sound has to stop.
#
# Return 1 on successful, otherwise 0.
#
restartAerotow: func () {
me.message.success("Aerotow on the way");
# Stop playing engine sound
setprop(me.addonNodePath ~ "/addon-devel/sound/enable", 0);
setprop(me.addonNodePath ~ "/addon-devel/sound/enable", false);
# Wait a second for the engine sound to turn off
var timer = maketimer(1, func () {
Timer.new().singleShot(1, me, func () {
me.unloadScenario();
});
timer.singleShot = 1;
timer.start();
},
#
@@ -76,25 +72,23 @@ var Aerotow = {
}
# Start aerotow with delay to avoid duplicate engine sound playing
var timer = maketimer(1, func () {
Timer.new().singleShot(1, me, func () {
me.startAerotow();
});
timer.singleShot = 1;
timer.start();
},
#
# Main function to prepare AI scenario and run it.
#
# Return 1 on successful, otherwise 0.
# Return true on successful, otherwise false.
#
startAerotow: func () {
if (!me.scenario.unload()) {
return 0;
return false;
}
if (!me.scenario.generateXml()) {
return 0;
return false;
}
return me.scenario.load();
@@ -103,10 +97,10 @@ var Aerotow = {
#
# Function for unload our AI scenario.
#
# Return 1 on successful, otherwise 0.
# Return true on successful, otherwise false.
#
stopAerotow: func () {
var withMessages = 1;
var withMessages = true;
return me.scenario.unload(withMessages);
},
};

View File

@@ -10,7 +10,7 @@
#
#
# Parent object of Aircraft
# Parent class of Aircraft
#
var Aircraft = {
#
@@ -50,7 +50,7 @@ var Aircraft = {
#
# name - Name of aircraft to check.
#
# Return 1 when match, otherwise 0.
# Return true when match, otherwise false.
#
isModelName: func (name) {
return name == me.name or name == me.nameMenuCall;
@@ -69,8 +69,8 @@ var Aircraft = {
# Return selected Aircraft object
#
# addon - Addon object
# isRouteMode - Use 1 to get the plane for the "Aerotow Route" dialog,
# use 0 (default) for call the airplane for towing.
# isRouteMode - Use true to get the plane for the "Aerotow Route" dialog,
# use false (default) for call the airplane for towing.
#
getSelected: func (addon, isRouteMode = 0) {
var name = Aircraft.getSelectedAircraftName(addon, isRouteMode);
@@ -89,10 +89,10 @@ var Aircraft = {
#
#
# addon - Addon object
# isRouteMode - Use 1 to get the plane for the "Aerotow Route" dialog,
# use 0 (default) for call the airplane for towing.
# isRouteMode - Use true to get the plane for the "Aerotow Route" dialog,
# use false (default) for call the airplane for towing.
#
getSelectedAircraftName: func (addon, isRouteMode = 0) {
getSelectedAircraftName: func (addon, isRouteMode) {
if (isRouteMode) {
return getprop(addon.node.getPath() ~ "/addon-devel/route/ai-model") or g_Aircrafts[0].name;
}

View File

@@ -10,7 +10,7 @@
#
#
# Object for hande Route Dialog
# Class for hande Route Dialog
#
var RouteDialog = {
#
@@ -39,6 +39,11 @@ var RouteDialog = {
obj.calculateAltChangeAndTotals();
}));
# Set listener for Max altitude AGL value in route dialog for recalculate altitude change
append(obj.listeners, setlistener(obj.addonNodePath ~ "/addon-devel/route/wpts/max-alt-agl", func () {
obj.calculateAltChangeAndTotals();
}));
# Set listeners for distance fields for calculate altitude change
for (var i = 0; i < obj.maxRouteWaypoints; i += 1) {
append(obj.listeners, setlistener(obj.addonNodePath ~ "/addon-devel/route/wpts/wpt[" ~ i ~ "]/distance-m", func () {
@@ -64,18 +69,27 @@ var RouteDialog = {
calculateAltChangeAndTotals: func () {
var totalDistance = 0.0;
var totalAlt = 0.0;
var isEnd = 0;
var isEnd = false;
var isAltLimit = false;
var isRouteMode = 1;
var isRouteMode = true;
var aircraft = Aircraft.getSelected(me.addon, isRouteMode);
# 0 means without altitude limits
var maxAltAgl = getprop(me.addonNodePath ~ "/addon-devel/route/wpts/max-alt-agl") or 0;
for (var i = 0; i < me.maxRouteWaypoints; i += 1) {
var distance = getprop(me.addonNodePath ~ "/addon-devel/route/wpts/wpt[" ~ i ~ "]/distance-m");
if (distance == nil) {
break;
var distance = getprop(me.addonNodePath ~ "/addon-devel/route/wpts/wpt[" ~ i ~ "]/distance-m") or 0;
# 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;
}
var altChange = aircraft.getAltChange(distance);
setprop(me.addonNodePath ~ "/addon-devel/route/wpts/wpt[" ~ i ~ "]/alt-change-agl-ft", altChange);
if (!isEnd) {
@@ -84,7 +98,7 @@ var RouteDialog = {
totalAlt += altChange;
}
else {
isEnd = 1;
isEnd = true;
}
}
}

View File

@@ -9,6 +9,9 @@
# under the GNU Public License v3 (GPLv3)
#
#
# Class Thermal for handle add new thermal.
#
var Thermal = {
#
# Constructor
@@ -59,7 +62,7 @@ var Thermal = {
#
# Add thermal 300 m before glider position.
#
# Return 1 on successful, otherwise 0.
# Return true on successful, otherwise false.
#
add: func () {
var heading = getprop("/orientation/heading-deg") or 0;
@@ -84,10 +87,10 @@ var Thermal = {
if (fgcommand("add-aiobject", args)) {
me.message.success("The thermal has been added");
return 1;
return true;
}
me.message.error("Adding thermal failed");
return 0;
return false;
},
};

View File

@@ -10,7 +10,7 @@
#
#
# Flight Plan object
# Class FlightPlan for crate and save as XML file the flight plan for AI scenario.
#
var FlightPlan = {
#
@@ -36,7 +36,6 @@ var FlightPlan = {
obj.addonNodePath = addon.node.getPath();
obj.wptCount = 0;
obj.coord = nil; # Coordinates for flight plan
obj.heading = nil; # AI plane heading
obj.altitude = nil; # AI plane altitude
@@ -47,7 +46,7 @@ var FlightPlan = {
#
# Get inital location of glider.
#
# Return object with "lat", "lon" and 'heading".
# Return object with "lat", "lon" and "heading".
#
getLocation: func () {
var icao = getprop("/sim/airport/closest-airport-id");
@@ -70,10 +69,11 @@ var FlightPlan = {
if (rwyResult.distance > FlightPlan.MAX_RUNWAY_DISTANCE) {
# The runway is too far away, we assume a bush start
return {
"type" : "bush",
"lat" : gliderCoord.lat(),
"lon" : gliderCoord.lon(),
"heading" : getprop("/orientation/heading-deg"),
"type" : "bush",
"lat" : gliderCoord.lat(),
"lon" : gliderCoord.lon(),
"heading" : getprop("/orientation/heading-deg"),
"elevation": me.getEleveationInFt(gliderCoord),
};
}
@@ -89,11 +89,15 @@ var FlightPlan = {
}
return {
"type" : "runway",
"lat" : rwyResult.runway.lat,
"lon" : rwyResult.runway.lon,
"heading" : rwyResult.runway.heading,
}
"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,
};
},
#
@@ -124,19 +128,22 @@ var FlightPlan = {
#
# Initialize flight plan and set it to property tree
#
# Return 1 on successful, otherwise 0.
# Return true on successful, otherwise false.
#
initial: func () {
var location = me.getLocation();
if (location == nil) {
return 0;
return false;
}
var aircraft = Aircraft.getSelected(me.addon);
var isGliderPos = 0;
var isGliderPos = false;
me.initAircraftVariable(location, isGliderPos);
# Max altitude without limits
setprop(me.addonNodePath ~ "/addon-devel/route/wpts/max-alt-agl", 0);
# 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);
@@ -146,11 +153,11 @@ var FlightPlan = {
var wptData = [
{"hdgChange": 0, "dist": 5000, "altChange": aircraft.vs * 5},
{"hdgChange": -90, "dist": 1000, "altChange": aircraft.vs},
{"hdgChange": -90, "dist": 1000, "altChange": aircraft.vs},
{"hdgChange": 0, "dist": 5000, "altChange": aircraft.vs * 5},
{"hdgChange": -90, "dist": 6000, "altChange": aircraft.vs * 6},
{"hdgChange": -90, "dist": 1500, "altChange": aircraft.vs * 1.5},
{"hdgChange": -90, "dist": 1000, "altChange": aircraft.vs},
{"hdgChange": 0, "dist": 5000, "altChange": aircraft.vs * 5},
{"hdgChange": -90, "dist": 6000, "altChange": aircraft.vs * 6},
{"hdgChange": 0, "dist": 0, "altChange": 0},
{"hdgChange": 0, "dist": 0, "altChange": 0},
{"hdgChange": 0, "dist": 0, "altChange": 0},
{"hdgChange": 0, "dist": 0, "altChange": 0},
{"hdgChange": 0, "dist": 0, "altChange": 0},
@@ -161,20 +168,20 @@ var FlightPlan = {
# 1 - 1st waypoint
# 2 - 2nd waypoint, etc.
#
# 2 . . 1 7
# . . .
# . . .
# 3 . .
# 2 . . 1 5
# . . .
# . . .
# . . .
# . . .
# . . .
# . . .
# . ^ 6
# . . .
# . . .
# . . .
# . ^ .
# . .
# . .
# 4 . . . . 5
# 3 . . . . 4
var index = 0;
foreach (var wpt; wptData) {
@@ -189,95 +196,197 @@ var FlightPlan = {
setprop(me.addonNodePath ~ "/addon-devel/route/wpts/description", "Default route around the start location");
return 1;
return true;
},
#
# Generate the XML file with the flight plane for our plane for AI scenario.
# The file will be stored to $Fobj.HOME/Export/aerotown-addon-flightplan.xml.
# The file will be stored to $FG_HOME/Export/Addons/org.flightgear.addons.Aerotow/AI/FlightPlans/aerotown-addon-flightplan.xml.
#
# Return 1 on successful, otherwise 0.
# Return true on successful, otherwise false.
#
generateXml: func () {
me.wptCount = 0;
var location = me.getLocation();
if (location == nil) {
return 0;
return false;
}
me.flightPlanWriter.open();
var aircraft = Aircraft.getSelected(me.addon);
var isGliderPos = 1;
var isGliderPos = true;
me.initAircraftVariable(location, isGliderPos);
# Start at 2 o'clock from the glider...
# Inital ktas must be >= 1.0
me.addWptGround({"hdgChange": 60, "dist": 25}, {"altChange": 0, "ktas": 5});
me.addWptGround({"shift": {"hdgChange": 60, "dist": 25, "altChange": 0}, "ktas": 5}); # 1
# Reset coord and heading
isGliderPos = 0;
isGliderPos = false;
me.initAircraftVariable(location, isGliderPos);
var gliderOffsetM = me.getGliderOffsetFromRunwayThreshold(location);
# ... and line up with the runway
me.addWptGround({"hdgChange": 0, "dist": 30 + gliderOffsetM}, {"altChange": 0, "ktas": 2.5});
me.addWptGround({"shift": {"hdgChange": 0, "dist": me.getInitialDistance() + gliderOffsetM, "altChange": 0}, "ktas": 2.5}); # 2
# Rolling
me.addWptGround({"hdgChange": 0, "dist": 10}, {"altChange": 0, "ktas": 5});
me.addWptGround({"hdgChange": 0, "dist": 20}, {"altChange": 0, "ktas": 5});
me.addWptGround({"hdgChange": 0, "dist": 20}, {"altChange": 0, "ktas": aircraft.speed / 6});
me.addWptGround({"hdgChange": 0, "dist": 10}, {"altChange": 0, "ktas": aircraft.speed / 5});
me.addWptGround({"hdgChange": 0, "dist": 10 * aircraft.rolling}, {"altChange": 0, "ktas": aircraft.speed / 4});
me.addWptGround({"hdgChange": 0, "dist": 10 * aircraft.rolling}, {"altChange": 0, "ktas": aircraft.speed / 3.5});
me.addWptGround({"hdgChange": 0, "dist": 10 * aircraft.rolling}, {"altChange": 0, "ktas": aircraft.speed / 3});
me.addWptGround({"hdgChange": 0, "dist": 10 * aircraft.rolling}, {"altChange": 0, "ktas": aircraft.speed / 2.5});
me.addWptGround({"hdgChange": 0, "dist": 10 * aircraft.rolling}, {"altChange": 0, "ktas": aircraft.speed / 2});
me.addWptGround({"hdgChange": 0, "dist": 10 * aircraft.rolling}, {"altChange": 0, "ktas": aircraft.speed / 1.75});
me.addWptGround({"hdgChange": 0, "dist": 10 * aircraft.rolling}, {"altChange": 0, "ktas": aircraft.speed / 1.5});
me.addWptGround({"hdgChange": 0, "dist": 10 * aircraft.rolling}, {"altChange": 0, "ktas": aircraft.speed / 1.25});
me.addWptGround({"hdgChange": 0, "dist": 10 * aircraft.rolling}, {"altChange": 0, "ktas": aircraft.speed});
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
# Take-off
me.addWptAir({"hdgChange": 0, "dist": 100 * aircraft.rolling}, {"elevationPlus": 3, "ktas": aircraft.speed * 1.05});
me.addWptAir({"hdgChange": 0, "dist": 100}, {"altChange": aircraft.vs / 10, "ktas": aircraft.speed * 1.025});
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
# 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
var speedInc = 1.0;
foreach (var wptNode; props.globals.getNode(me.addonNodePath ~ "/addon-devel/route/wpts").getChildren("wpt")) {
var dist = wptNode.getChild("distance-m").getValue();
if (dist <= 0.0) {
var distance = wptNode.getChild("distance-m").getValue();
if (distance <= 0.0) {
break;
}
var hdgChange = wptNode.getChild("heading-change").getValue();
var altChange = aircraft.getAltChange(dist);
speedInc += ((dist / Aircraft.DISTANCE_DETERMINANT) * 0.025);
# 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);
var ktas = aircraft.speed * speedInc;
if (ktas > aircraft.speedLimit) {
ktas = aircraft.speedLimit;
}
me.addWptAir({"hdgChange": hdgChange, "dist": dist}, {"altChange": altChange, "ktas": ktas});
totalAlt += altChange;
me.addWptAir({"shift": {"hdgChange": hdgChange, "dist": distance, "altChange": altChange}, "ktas": ktas});
}
me.addWptEnd();
# 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();
}
me.flightPlanWriter.close();
return 1;
return true;
},
#
# 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;
},
#
# Initialize AI aircraft variable
#
# location - Object of location from which the glider start.
# isGliderPos - Pass 1 for set AI aircraft's coordinates as glider position, 0 set coordinates as runway threshold.
# isGliderPos - Pass true for set AI aircraft's coordinates as glider position, false set coordinates as runway threshold.
#
initAircraftVariable: func (location, isGliderPos = 1) {
initAircraftVariable: func (location, isGliderPos) {
var gliderCoord = geo.aircraft_position();
# Set coordinates as glider position or runway threshold
@@ -307,33 +416,31 @@ var FlightPlan = {
return rwyThreshold.distance_to(gliderCoord);
}
# We are not on runway
# We are not on the runway, return 0 distance
return 0;
},
#
# Add new waypoint on ground
#
# coordOffset - Hash for calculate next coordinates (lat, lon), with following fields:
# {
# hdgChange - How the aircraft's heading supposed to change? 0 - keep the same heading.
# dis - Distance in meters to calculate next waypoint coordinates.
# }
# performance - Hash with following fields:
# {
# altChange - How the aircraft's altitude is supposed to change? 0 - keep the same altitude.
# ktas - True air speed of AI plane at the waypoint.
# }
# wptData - hash object with waypoint data
#
addWptGround: func (coordOffset, performance) {
me.wrireWpt(nil, coordOffset, performance, "ground");
addWptGround: func (wptData) {
wptData.onGround = true;
me.addWpt(wptData);
},
#
# Add new waypoint in air
#
addWptAir: func (coordOffset, performance) {
me.wrireWpt(nil, coordOffset, performance, "air");
# wptData - hash object wtih waypoint data
#
addWptAir: func (wptData) {
if (contains(wptData, "onGround")) {
wptData.onGround = nil;
}
me.addWpt(wptData);
},
#
@@ -342,70 +449,115 @@ var FlightPlan = {
# sec - Number of seconds for wait
#
addWptWait: func (sec) {
me.wrireWpt("WAIT", {}, {}, nil, sec);
me.addWpt({"waitSec": sec});
},
#
# Add "END" waypoint
# Add "END" waypoint with optional waypoint data
#
addWptEnd: func () {
me.wrireWpt("END", {}, {});
addWptEnd: func (wptData = nil) {
if (wptData == nil) {
wptData = {};
}
wptData.name = "END";
me.addWpt(wptData);
},
#
# Write waypoint to flight plan file
# Add new waypoint with given waypoint data
#
# name - The name of waypoint
# coordOffset.hdgChange - How the aircraft's heading supposed to change?
# coordOffset.dist - Distance in meters to calculate next waypoint coordinates
# performance.altChange - How the aircraft's altitude is supposed to change?
# performance.elevationPlus - 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
# performance.ktas - True air speed of AI plane at the waypoint
# groundAir - Allowed value: "ground or "air". The "ground" means that AI plane is on the ground, "air" - in air
# sec - Number of seconds for "WAIT" waypoint
# 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
# }
#
wrireWpt: func (
name,
coordOffset,
performance,
groundAir = nil,
sec = nil
) {
var coord = nil;
if (contains(coordOffset, "hdgChange") and contains(coordOffset, "dist")) {
me.heading += coordOffset.hdgChange;
if (me.heading < 0) {
me.heading += 360;
}
addWpt: func (wptData) {
if (contains(wptData, "shift")) {
me.shiftWpt(wptData.shift);
if (me.heading > 360) {
me.heading -= 360;
}
me.coord.apply_course_distance(me.heading, coordOffset.dist);
coord = me.coord;
# Set coord and crossAt updated by shiftWpt()
wptData.coord = me.coord;
wptData.crossAt = me.altitude;
}
var alt = nil;
if (coord != nil and contains(performance, "elevationPlus")) {
var elevation = geo.elevation(coord.lat(), coord.lon());
me.altitude = elevation == nil
? me.altitude + performance.elevationPlus
: elevation * globals.M2FT + performance.elevationPlus;
alt = me.altitude;
}
else if (contains(performance, "altChange")) {
me.altitude += performance.altChange;
alt = 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");
}
var ktas = contains(performance, "ktas") ? performance.ktas : nil;
if (!contains(wptShift, "dist")) {
die("ERROR aerotow add-on: missing 'dist' for computeWptShift");
}
name = name == nil ? me.wptCount : name;
me.flightPlanWriter.write(name, coord, alt, ktas, groundAir, sec);
# Shift heading and coordinates
me.heading = me.correctHeading(me.heading + wptShift.hdgChange);
me.coord.apply_course_distance(me.heading, wptShift.dist);
me.wptCount += 1;
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;
}
if (heading > 360) {
heading -= 360;
}
return heading;
},
#
# Get elevation of given coordinates in feet
#
# coord - geo.Coord object
#
getEleveationInFt: func (coord) {
if (coord == nil) {
return nil;
}
return geo.elevation(coord.lat(), coord.lon()) * globals.M2FT;
},
};

View File

@@ -10,7 +10,7 @@
#
#
# Object for write flight plan to the XML file
# Class FlightPlanWriter for write flight plan to the XML file
#
var FlightPlanWriter = {
#
@@ -23,6 +23,7 @@ var FlightPlanWriter = {
obj.fpFileHandler = nil; # Handler for wrire flight plan to file
obj.flightPlanPath = addon.storagePath ~ "/AI/FlightPlans/" ~ FlightPlan.FILENAME_FLIGHTPLAN;
obj.wptCount = 1;
return obj;
},
@@ -31,6 +32,8 @@ var FlightPlanWriter = {
# Open XML file to wrire flight plan
#
open: func () {
me.wptCount = 1;
me.fpFileHandler = io.open(me.flightPlanPath, "w");
if (me.fpFileHandler) {
@@ -47,50 +50,61 @@ var FlightPlanWriter = {
#
# Write single waypoint to XML file with flight plan
#
# name - Name of waypoint. Special names are: "WAIT", "END".
# coord - The Coord object
# alt - Altitude AMSL of AI plane
# ktas - True air speed of AI plane
# groundAir - Allowe value: "ground or "air". The "ground" means that AI plane is on the ground, "air" - in air
# sec - Number of seconds for "WAIT" waypoint
# wpt - Waypoint object
#
write: func (name, coord = nil, alt = nil, ktas = nil, groundAir = nil, sec = nil) {
write: func (wpt) {
if (!me.fpFileHandler) {
return;
}
var str = " <wpt>\n"
~ " <name>" ~ name ~ "</name>\n";
if (wpt.name == nil) {
wpt.setName(me.wptCount);
}
if (coord != nil) {
str ~= " <lat>" ~ coord.lat() ~ "</lat>\n";
str ~= " <lon>" ~ coord.lon() ~ "</lon>\n";
var str = " <wpt>\n"
~ " <name>" ~ wpt.name ~ "</name>\n";
if (wpt.coord != nil) {
str ~= " <lat>" ~ wpt.coord.lat() ~ "</lat>\n";
str ~= " <lon>" ~ wpt.coord.lon() ~ "</lon>\n";
str ~= " <!--\n"
~ " " ~ coord.lat() ~ "," ~ coord.lon() ~ "\n"
~ " " ~ wpt.coord.lat() ~ "," ~ wpt.coord.lon() ~ "\n"
~ " -->\n";
}
if (alt != nil) {
# str ~= " <alt>" ~ alt ~ "</alt>\n";
str ~= " <crossat>" ~ alt ~ "</crossat>\n";
if (wpt.alt != nil) {
str ~= " <alt>" ~ wpt.alt ~ "</alt>\n";
}
if (ktas != nil) {
str ~= " <ktas>" ~ ktas ~ "</ktas>\n";
if (wpt.crossAt != nil) {
str ~= " <crossat>" ~ wpt.crossAt ~ "</crossat>\n";
}
if (groundAir != nil) {
var onGround = groundAir == "ground" ? "true" : "false";
str ~= " <on-ground>" ~ onGround ~ "</on-ground>\n";
if (wpt.ktas != nil) {
str ~= " <ktas>" ~ wpt.ktas ~ "</ktas>\n";
}
if (sec != nil) {
str ~= " <time-sec>" ~ sec ~ "</time-sec>\n";
if (wpt.onGround != nil) {
str ~= " <on-ground>" ~ (wpt.onGround ? "true" : "false") ~ "</on-ground>\n";
}
if (wpt.waitSec != nil) {
str ~= " <time-sec>" ~ wpt.waitSec ~ "</time-sec>\n";
}
if (wpt.flapsDown != nil) {
str ~= " <flaps-down>" ~ (wpt.flapsDown ? "true" : "false") ~ "</flaps-down>\n";
}
if (wpt.gearDown != nil) {
str ~= " <gear-down>" ~ (wpt.gearDown ? "true" : "false") ~ "</gear-down>\n";
}
str ~= " </wpt>\n";
io.write(me.fpFileHandler, str);
me.wptCount += 1;
},
#

175
nasal/io/waypoint.nas Normal file
View File

@@ -0,0 +1,175 @@
#
# 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)
#
#
# Class Waypoint represent the data of waypoint in the flight plan.
#
var Waypoint = {
#
# Constructor
#
new: func () {
var obj = { parents: [Waypoint] };
obj.name = nil; # Name of waypoint. Special names are: "WAIT", "END".
obj.coord = nil; # geo.Coord object
obj.alt = nil; # Altitude AMSL in feet
obj.crossAt = nil; # Altitude AMSL in feet
obj.ktas = nil; # True airspeed in knots
obj.onGround = nil; # If true then on the ground, otherwise in air
obj.flapsDown = nil; # If true then flaps down, otherwise up
obj.gearDown = nil; # If true then gear down, otherwise up
obj.waitSec = nil; # Number of seconds for "WAIT" waypoint
return obj;
},
#
# Set name of waypoint
#
# name - Name of waypoint
#
setName: func (name) {
me.name = name;
return me;
},
#
# Set coordinates of waypoint
#
# coord - geo.Coord object
#
setCoord: func (coord) {
me.coord = coord;
return me;
},
#
# Set altitude in feet of waypoint
#
# alt - altitude in feet
#
setAlt: func (alt) {
me.alt = alt;
return me;
},
#
# Set altitude in feet of waypoint as cross at
#
# alt - altitude in feet
#
setCrossAt: func (crossAt) {
me.crossAt = crossAt;
return me;
},
#
# Set true airspeed in knots for waypoint
#
# ktas - true airspeed in knots
#
setKtas: func (ktas) {
me.ktas = ktas;
return me;
},
#
# Set waypoint on the ground
#
setOnGround: func () {
me.onGround = 1;
return me;
},
#
# Set flaps down
#
setFlapsDown: func () {
me.flapsDown = 1;
return me;
},
#
# Set gear down
#
setGearDown: func () {
me.gearDown = 1;
return me;
},
#
# Set number of seconds for WAIT waypoint. This force to use "WAIT" name.
#
# waitSec - Number of seconds
#
setWaitSec: func (waitSec) {
me.setName("WAIT"); # force WAIT name
me.waitSec = waitSec;
return me;
},
#
# Set all waypoint data from given hash object
#
setHashData: func (wptData) {
if (wptData == nil) {
return me;
}
if (contains(wptData, "name")) {
me.setName(wptData.name);
}
if (contains(wptData, "coord")) {
me.setCoord(wptData.coord);
}
if (contains(wptData, "crossAt")) {
me.setCrossAt(wptData.crossAt);
}
if (contains(wptData, "alt")) {
me.setAlt(wptData.alt);
}
if (contains(wptData, "ktas")) {
me.setKtas(wptData.ktas);
}
if (contains(wptData, "onGround") and wptData.onGround) {
me.setOnGround();
}
if (contains(wptData, "flapsDown") and wptData.flapsDown) {
me.setFlapsDown();
}
if (contains(wptData, "gearDown") and wptData.gearDown) {
me.setGearDown();
}
if (contains(wptData, "waitSec")) {
me.setWaitSec(wptData.waitSec);
}
return me;
}
};

View File

@@ -10,7 +10,7 @@
#
#
# Object for display messages
# Class Message for display messages on the screen with read by speech synthesizer.
#
var Message = {
#

View File

@@ -10,16 +10,16 @@
#
#
# Scenario object
# Class Scenario for create AI scenario XML file and attach it to scenario property list for load it.
#
var Scenario = {
#
# Constants
#
SCENARIO_ID: "aerotow_addon",
SCENARIO_NAME: "Aerotow Add-on",
SCENARIO_DESC: "This scenario starts the towing plane at the airport where the pilot with the glider is located. Use Ctrl-o to hook the plane.",
FILENAME_SCENARIO: "aerotown-addon.xml",
SCENARIO_ID: "aerotow_addon",
SCENARIO_NAME: "Aerotow Add-on",
SCENARIO_DESC: "This scenario starts the towing plane at the airport where the pilot with the glider is located. Use Ctrl-o to hook the plane.",
FILENAME_SCENARIO: "aerotown-addon.xml",
#
# Constructor
@@ -38,7 +38,7 @@ var Scenario = {
obj.listeners = [];
obj.routeDialog = RouteDialog.new(addon, message);
obj.flightPlan = FlightPlan.new(addon, message, obj.routeDialog);
obj.isScenarioLoaded = 0;
obj.isScenarioLoaded = false;
obj.scenarioPath = addon.storagePath ~ "/" ~ Scenario.FILENAME_SCENARIO;
obj.flightPlan.initial();
@@ -64,11 +64,13 @@ var Scenario = {
#
# Generate the XML file with the AI scenario.
# The file will be stored to $FG_HOME/Export/aerotown-addon.xml.
# The file will be stored to $FG_HOME/Export/Addons/org.flightgear.addons.Aerotow/aerotown-addon.xml.
#
# Return true on successful, otherwise false
#
generateXml: func () {
if (!me.flightPlan.generateXml()) {
return 0;
return false;
}
var scenarioXml = {
@@ -82,7 +84,7 @@ var Scenario = {
"class": "aerotow-dragger",
"model": Aircraft.getSelected(me.addon).modelPath,
"flightplan": FlightPlan.FILENAME_FLIGHTPLAN,
"repeat": 1,
"repeat": true, # start again indefinitely, it will work if the aircraft stops on the ground
}
}
}
@@ -93,7 +95,7 @@ var Scenario = {
me.addScenarioToPropertyList();
return 1;
return true;
},
#
@@ -114,67 +116,67 @@ var Scenario = {
},
#
# Return 1 if scenario is already added to "/sim/ai/scenarios" property list, otherwise return 0.
# Return true if scenario is already added to "/sim/ai/scenarios" property list, otherwise return false.
#
isAlreadyAdded: func () {
foreach (var scenario; props.globals.getNode("/sim/ai/scenarios").getChildren("scenario")) {
var id = scenario.getChild("id");
if (id != nil and id.getValue() == Scenario.SCENARIO_ID) {
return 1;
return true;
}
}
return 0;
return false;
},
#
# Load scenario
#
# Return 1 on successful, otherwise 0.
# Return true on successful, otherwise false.
#
load: func () {
var args = props.Node.new({ "name": Scenario.SCENARIO_ID });
if (fgcommand("load-scenario", args)) {
me.isScenarioLoaded = 1;
me.isScenarioLoaded = true;
me.message.success("Let's fly!");
# Enable engine sound
setprop(me.addonNodePath ~ "/addon-devel/sound/enable", 1);
return 1;
setprop(me.addonNodePath ~ "/addon-devel/sound/enable", true);
return true;
}
me.message.error("Tow failed!");
return 0;
return false;
},
#
# Unload scenario
#
# withMessages - Set 1 to display messages.
# withMessages - Set true to display messages.
#
# Return 1 on successful, otherwise 0.
# Return true on successful, otherwise false.
#
unload: func (withMessages = 0) {
if (me.isScenarioLoaded) {
var args = props.Node.new({ "name": Scenario.SCENARIO_ID });
if (fgcommand("unload-scenario", args)) {
me.isScenarioLoaded = 0;
me.isScenarioLoaded = false;
if (withMessages) {
me.message.success("Aerotown disabled");
}
return 1;
return true;
}
if (withMessages) {
me.message.error("Aerotown disable failed");
}
return 0;
return false;
}
if (withMessages) {
me.message.success("Aerotown already disabled");
}
return 1;
return true;
},
};

41
nasal/timer.nas Normal file
View File

@@ -0,0 +1,41 @@
#
# 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)
#
#
# Class Timer for wrapping maketimer() function.
#
var Timer = {
#
# Constructor
#
new: func () {
return { parents: [Timer] };
},
#
# Run timer as single shot
#
# delaySec - Delay in seconds for execute timer's callback.
# self - Specifying what any "me" references in the function being called will refer to.
# callback - Function to be called after given delay.
#
# Return timer handler object
#
singleShot: func (delaySec, self, callback) {
var timer = maketimer(delaySec, self, func () {
callback();
});
timer.singleShot = true;
timer.start();
return timer;
},
};