Hi James,

thank you very much for your changes, here is the very first step of a vor-to-vor flightplan builder. Let me improve it for more functions and capacities.

best regards,
seb

James Turner a ecrit :
On 9 Dec 2009, at 13:47, Scott Hamilton wrote:

   Something I was playing around with a few months back I thought, if only I 
could find the nearest VOR/NDB/FIX/APT to
   some point that I am not at but will be in the near future, unfortunately 
I've forgotten what it was I was trying to do,
but I'm sure it was a good idea.... ;)

Yep, agreed, it's an obvious thing to support. And easy to do, as well!

 Off-topic is there anyway in Nasal to find the ILS frequencies and optionally 
the name, for a particular airport and runway?

Yes, the airportinfo function returns you a Nasal hash with all this and more.

Also, although it's not exposed in the current GPS GUI dialog, when you search 
for an airport, the GPS scratch data contains the runways, including ILS 
frequencies, headings and names. You can see them in the property browser.

James


------------------------------------------------------------------------------
Return on Information:
Google Enterprise Search pays you back
Get the facts.
http://p.sf.net/sfu/google-dev2dev
_______________________________________________
Flightgear-devel mailing list
Flightgear-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/flightgear-devel

var gps = props.globals.getNode("/instrumentation/gps/", 1);
var cmd = gps.getNode("command", 1);
var scratch = gps.getNode("scratch");
var flightplan = gps.getNode("flightplan", 1);

scratch.getNode("exact", 1).setBoolValue(0);
var searchType = scratch.getNode("type", 1);
var searchQuery = scratch.getNode("query", 1);
var searchMax = scratch.getNode("max-results", 1);

var flightplan_vector = [];

var copy_wp_infos = func (orig, dest) {
    var nodelist = ["latitude-deg", "longitude-deg", "name", "ident", 
"altitude-ft", "frequency-mhz"]; #TODO frequency for NDB in kHz
        foreach (var n; nodelist) {
            var o = orig.getNode(n);
            o != nil or continue;
            dest[n] = o.getValue();
        }
}

var build = func (from, to) {
    var target_lat = from["latitude-deg"] + ((to["latitude-deg"] - 
from["latitude-deg"])/2);
    var target_lon = from["longitude-deg"] + ((to["longitude-deg"] - 
from["longitude-deg"])/2);

    scratch.getNode("latitude-deg").setDoubleValue(target_lat);
    scratch.getNode("longitude-deg").setDoubleValue(target_lon);
    searchType.setValue("vor");
    searchMax.setIntValue(1);
    cmd.setValue("nearest");
    
    var wp = {};
    copy_wp_infos(scratch, wp);

    var wpcoords   = geo.Coord.new().set_latlon(wp["latitude-deg"], 
wp["longitude-deg"]);
    var fromcoords = geo.Coord.new().set_latlon(from["latitude-deg"], 
from["longitude-deg"]);
    var tocoords   = geo.Coord.new().set_latlon(to["latitude-deg"], 
to["longitude-deg"]);
    #var dist_to = wpcoords.distance_to(tocoords);
    #printf("%s -> %s dist_to %s", wp["ident"], to["ident"], dist_to);
    #dist_to > 18520 or return;
    wpcoords.distance_to(tocoords) > 18520 or return;
    #var dist_from = wpcoords.distance_to(fromcoords);
    #printf("%s -> %s dist_from %s", from["ident"], wp["ident"], dist_to);
    #dist_from > 18520 or return;
    wpcoords.distance_to(fromcoords) > 18520 or return;

    build(from, wp);
    append(flightplan_vector, wp);
    build(wp, to);
}

var new_flightplan = func {
    flightplan_vector = [];
    print("LFBT->LFPT");
    searchType.setValue("airport");
    searchQuery.setValue("lfbt");
    cmd.setValue("search");
    var departure = {};
    copy_wp_infos(scratch, departure);

    searchType.setValue("airport");
    searchQuery.setValue("lfpt");
    cmd.setValue("search");
    var destination = {};
    copy_wp_infos(scratch, destination);

    print("building flightplan");
    if (departure["latitude-deg"] < -9990.0 or destination["latitude-deg"] < 
-9990.0) {
        print("I need some yoga exercices...");
        return;
    }

    append(flightplan_vector, departure);

    build(departure, destination);

    append(flightplan_vector, destination);

    for (var i = 0; i < size(flightplan_vector); i += 1) {
        foreach (var k; keys(flightplan_vector[i])) {
            var content = flightplan_vector[i][k];
            var n = flightplan.getNode("wp[" ~ i ~ "]/" ~ k, 1);
            if (k == "name" or k == "ident")
                n.setValue(content);
            else
                n.setDoubleValue(content);
        }
    }
    
    print("flightplan complete");
}
------------------------------------------------------------------------------
Return on Information:
Google Enterprise Search pays you back
Get the facts.
http://p.sf.net/sfu/google-dev2dev
_______________________________________________
Flightgear-devel mailing list
Flightgear-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/flightgear-devel

Reply via email to