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