| 1 |
# SPDX-License-Identifier: GPL-2.0-or-later |
| 2 |
# |
| 3 |
# NOTE! This copyright does *not* cover user models that use these Nasal |
| 4 |
# services by normal function calls - this is merely considered normal use |
| 5 |
# of the code, and does *not* fall under the heading of "derived work." |
| 6 |
# |
| 7 |
# Copyright (C) 2010 by Vivian Meazza |
| 8 |
# Copyright (C) 2013 by Philosopher |
| 9 |
# Copyright (C) 2020 by Henning Stahlke |
| 10 |
|
| 11 |
######### |
| 12 |
# contrail calculator. Based on an approxmation to the "Appleman Chart" |
| 13 |
# y = -0.077x2 + 2.7188x - 64.36 |
| 14 |
######## |
| 15 |
|
| 16 |
var pressure_Node = props.globals.initNode("environment/pressure-inhg", 1, "DOUBLE"); |
| 17 |
var temperature_Node = props.globals.initNode("environment/temperature-degc", 1, "DOUBLE"); |
| 18 |
var contrail_Node = props.globals.initNode("environment/contrail", 1, "BOOL"); |
| 19 |
var contrail_temp_Node = props.globals.initNode("environment/contrail-temperature-degc", 1, "DOUBLE"); |
| 20 |
var static_contrail_node = props.globals.getNode("sim/ai/aircraft/contrail", 1); |
| 21 |
var time_node = props.globals.getNode("sim/time/elapsed-sec", 1); |
| 22 |
|
| 23 |
updateContrail = func { |
| 24 |
var x = pressure_Node.getValue(); |
| 25 |
var y = temperature_Node.getValue(); |
| 26 |
var con_temp = -0.077 * x * x + 2.7188 * x - 64.36; |
| 27 |
contrail_temp_Node.setValue(con_temp); |
| 28 |
|
| 29 |
if (y < con_temp and y < -40) { |
| 30 |
contrail_Node.setValue(1); |
| 31 |
} else { |
| 32 |
contrail_Node.setValue(0); |
| 33 |
} |
| 34 |
} |
| 35 |
|
| 36 |
updateContrail(); # avoid 30 second delay on startup https://sourceforge.net/p/flightgear/codetickets/2077/ |
| 37 |
|
| 38 |
contrailTimer = maketimer(30, updateContrail); |
| 39 |
contrailTimer.simulatedTime = 1; |
| 40 |
contrailTimer.restart(30); |