]> git.mxchange.org Git - flightgear.git/blob - scripts/perl/autopilot/flyplan.pl
Updated license statement.
[flightgear.git] / scripts / perl / autopilot / flyplan.pl
1 #!/usr/bin/perl
2 #
3 # Written by Curtis L. Olson, started January 2003
4 #
5 # This file is in the Public Domain and comes with no warranty.
6
7 use strict;
8
9 require "telnet.pl";
10
11 my( $server ) = "localhost";
12 my( $port ) = 5401;
13 my( $timeout ) = 10;
14
15 my( %Route );
16 $Route{0} = "OAK:116.80:020";
17 $Route{1} = "OAK:116.80:019:27";
18 $Route{2} = "SAC:115.20:020";
19 $Route{3} = "SAC:115.20:080:43";
20 $Route{4} = "ECA:116.0:209";
21
22 my( $i );
23
24 foreach $i ( keys(%Route) ) {
25     &fly_to( $Route{$i} );
26 }
27
28
29 sub fly_to() {
30     my( $waypoint ) = shift;
31
32     # decode waypoint
33     my( $id, $freq, $radial, $dist ) = split( /:/, $waypoint );
34
35     print "Next way point is $id - $freq\n";
36     print "  Target radial is $radial\n";
37     if ( $dist ne "" ) {
38         print "  Flying outbound for $dist nm\n";
39     } else {
40         print "  Flying inbound to station\n";
41     }
42
43     # tune radio and set autopilot
44     my( $fgfs );
45     if ( !( $fgfs = &connect($server, $port, $timeout) ) ) {
46         print "Error: can't open socket\n";
47         return;
48     }
49     &send( $fgfs, "data" );     # switch to raw data mode
50     set_prop( $fgfs, "/radios/nav[0]/frequencies/selected-mhz", $freq );
51     set_prop( $fgfs, "/radios/nav[0]/radials/selected-deg", $radial );
52     set_prop( $fgfs, "/radios/dme/switch-position", "1" );
53     set_prop( $fgfs, "/autopilot/locks/nav", "true" );
54
55     # monitor progress until goal is achieved
56     my( $done ) = 0;
57     my( $last_range ) = 9999.0;
58     while ( !$done ) {
59         my( $inrange ) = get_prop( $fgfs, "/radios/nav[0]/in-range" );
60         if ( $inrange eq "false" ) {
61             print "Warning, VOR not in range, we are lost!\n";
62         }
63         my( $cur_range ) = get_prop( $fgfs, "/radios/dme/distance-nm" );
64         print "  range = $cur_range\n";
65         if ( $dist ne "" ) {
66             # a target dist is specified so assume we are flying outbound
67             if ( $cur_range > $dist ) {
68                 $done = 1;
69             }
70         } else {
71             # no target dist is specified, assume we are flying
72             # inbound to the station
73             if ( $cur_range < 0.25 && $cur_range > 0.0 ) {
74                 $done = 1;
75             } elsif ( $last_range < $cur_range ) {
76                 $done = 1;
77             }
78         }
79         $last_range = $cur_range;
80
81         # loop once per second
82         sleep(1);
83     }
84
85     &send( $fgfs, "quit");
86     close $fgfs;
87 }