Howto:Calculate V-speeds

From FlightGear wiki
Jump to: navigation, search

With a bit of Nasal you can calculate V-speeds in FlightGear. This is especially useful on airliners, in cooperation with a Flight Management System (FMS).

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 script

To calculate the V-speeds, we create a .nas file with the following content. You can leave the lines preceded by # symbols out of your script, although it might be nice to keep them, so you can easily see what the script does and where it does that.

For JSBSim

 # Create initial announced variables at startup of the sim
 V1 = "";
 VR = "";
 V2 = "";
 
 # The actual function
 var vspeeds = func {
 
        # Create/populate variables at each function cycle
        # Retrieve total aircraft weight and convert to kg.
 	WT = getprop("/fdm/jsbsim/inertia/weight-lbs")*0.00045359237;
 	flaps = getprop("/instrumentation/fmc/to-flap");
 
        # Calculate V-speeds with flaps 10
 	if (flaps == 10) {
 		V1 = (0.3*(WT-200))+100;
 		VR = (0.3*(WT-200))+115;
 		V2 = (0.3*(WT-200))+135;
 	}
 
        # Calculate V-speeds with flaps 20
 	elsif (flaps == 20) {
 		V1 = (0.3*(WT-200))+95;
 		VR = (0.3*(WT-200))+110;
 		V2 = (0.3*(WT-200))+130;
 	}
 
        # Export the calculated V-speeds to the property-tree, for further use
 	setprop("/instrumentation/fmc/vspeeds/V1",V1);
 	setprop("/instrumentation/fmc/vspeeds/VR",VR);
 	setprop("/instrumentation/fmc/vspeeds/V2",V2);
 
        # Repeat the function each second
 	settimer(vspeeds, 1);
 }
 
 # Only start the function when the FDM is initialized, to prevent the problem of not-yet-created properties.
 _setlistener("/sim/signals/fdm-initialized", vspeeds);

For YASim

 # Create initial announced variables at startup of the sim
 V1 = "";
 VR = "";
 V2 = "";
 
 # The actual function
 var vspeeds = func {
 
        # Create/populate variables at each function cycle
        # Retrieve total aircraft weight and convert to kg.
 	WT = getprop("/yasim/gross-weight-lbs")*0.00045359237;
 	flaps = getprop("/instrumentation/fmc/to-flap");
 
        # Calculate V-speeds with flaps 10
 	if (flaps == 10) {
 		V1 = (0.3*(WT-200))+100;
 		VR = (0.3*(WT-200))+115;
 		V2 = (0.3*(WT-200))+135;
 	}
 
        # Calculate V-speeds with flaps 20
 	elsif (flaps == 20) {
 		V1 = (0.3*(WT-200))+95;
 		VR = (0.3*(WT-200))+110;
 		V2 = (0.3*(WT-200))+130;
 	}
 
        # Export the calculated V-speeds to the property-tree, for further use
 	setprop("/instrumentation/fmc/vspeeds/V1",V1);
 	setprop("/instrumentation/fmc/vspeeds/VR",VR);
 	setprop("/instrumentation/fmc/vspeeds/V2",V2);
 
        # Repeat the function each second
 	settimer(vspeeds, 1);
 }
 
 # Only start the function when the FDM is initialized, to prevent the problem of not-yet-created properties.
 _setlistener("/sim/signals/fdm-initialized", vspeeds);

Each aircraft has different formulas for calculating V-speeds. This script is based on a Boeing 747-400. For calculating the V-speeds used in this script, the FMC must know the takeoff flap setting. Since it is not sure that the pilot checks the V-speeds with the flaps in takeoff configuration, this setting must be set in a special property: /instrumentation/fmc/to-flap. If you don't need such "complicated" calculations, you can use /controls/flight/flaps instead. Do note that the values in the latter property are in a range from 0 to 1!!

Related content