Howto:Implement copilot announcements

From FlightGear wiki
Jump to navigation Jump to search

On all airliners and most slightly larger-than the C172P-like aircraft, workload during a flight is shared between the two pilots (and sometimes even an engineer). During takeoff and landing for example, the copilot usually reads out the checklists and V-speeds. Being a flightsimmer usually makes you a solo-pilot on all flights (unless you share your cockpit through Dual Control). As an aircraft developer, you can create a simple Nasal script to implement copilot announcements.

Please note that the codes at this page are not 'the' way to go. They just show you one out of many ways and may not necessarily be the best solution.

The "talking" copilot

During takeoff, the copilot monitors the aircraft's speed and calls out when it reaches so called V-speeds. See Howto: Calculate V-speeds for a script that calculates the Vspeeds that we will be using in our copilot script. Copy&pasting the script below without calculating V-speeds will result in an error.

To print the callouts from the copilot on the screen, we create a .nas file with the following content. You can leave the text preceeded by # symbols out of your script, altough it might be nice to keep it, so you can easily see what the script does and where it does that.

 setlistener("/sim/signals/fdm-initialized", func {
    copilot.init();
 });
 
 # Copilot announcements
 var copilot = {
    init : func { 
        me.UPDATE_INTERVAL = 1.73; 
        me.loopid = 0;
        # Initialize state variables.
        me.V1announced = 0;
        me.VRannounced = 0;
        me.V2announced = 0;
        me.reset(); 
        print("Copilot ready"); 
    }, 
    update : func {
        var airspeed = getprop("velocities/airspeed-kt");
        var V1 = getprop("/instrumentation/fmc/vspeeds/V1");
        var V2 = getprop("/instrumentation/fmc/vspeeds/V2");
        var VR = getprop("/instrumentation/fmc/vspeeds/VR");
 
        #Check if the V1, VR and V2 callouts should occur and if so, add to the announce function
        if ((airspeed != nil) and (V1 != nil) and (airspeed > V1) and (me.V1announced == 0)) {
            me.announce("V1!");
                me.V1announced = 1;
 
        } elsif ((airspeed != nil) and (VR != nil) and (airspeed > VR) and (me.VRannounced == 0)) {
            me.announce("VR!");
                me.VRannounced = 1;
 
        } elsif ((airspeed != nil) and (V2 != nil) and (airspeed > V2) and (me.V2announced == 0)) {
            me.announce("V2!");
                me.V2announced = 1;
        }
    },
 
    # Print the announcement on the screen
    announce : func(msg) {
        setprop("/sim/messages/copilot", msg);
    },
    reset : func {
        me.loopid += 1;
        me._loop_(me.loopid);
    },
    _loop_ : func(id) {
        id == me.loopid or return;
        me.update();
        settimer(func { me._loop_(id); }, me.UPDATE_INTERVAL);
    }
 };

Save the .nas file in your aircraft's Nasal/ directory. Now, reference to the file in your -set.xml file:

 <nasal>
  ...
  <file>Aircraft/.../Nasal/copilot.nas</file>
  ...
 </nasal>