| 1 |
# c172p state manager |
| 2 |
# by Wayne Bragg 2018 |
| 3 |
|
| 4 |
var state_manager = func { |
| 5 |
|
| 6 |
if (!getprop("/sim/presets/airspeed-kt")) { |
| 7 |
setprop("/velocities/airspeed-kt", 100); |
| 8 |
setprop("/velocities/uBody-fps", 163); |
| 9 |
setprop("/orientation/pitch-deg", 0); |
| 10 |
} |
| 11 |
|
| 12 |
# Reset battery charge and circuit breakers |
| 13 |
electrical.reset_battery_and_circuit_breakers(); |
| 14 |
|
| 15 |
var integral_tanks = getprop("/fdm/jsbsim/fuel/tank"); |
| 16 |
if (integral_tanks) { |
| 17 |
setprop("/consumables/fuel/tank[2]/selected", 1); |
| 18 |
setprop("/consumables/fuel/tank[3]/selected", 1); |
| 19 |
setprop("/consumables/fuel/tank[0]/selected", 0); |
| 20 |
setprop("/consumables/fuel/tank[1]/selected", 0); |
| 21 |
} else { |
| 22 |
setprop("/consumables/fuel/tank[0]/selected", 1); |
| 23 |
setprop("/consumables/fuel/tank[1]/selected", 1); |
| 24 |
setprop("/consumables/fuel/tank[2]/selected", 0); |
| 25 |
setprop("/consumables/fuel/tank[3]/selected", 0); |
| 26 |
} |
| 27 |
|
| 28 |
var auto_mixture = getprop("/fdm/jsbsim/engine/auto-mixture"); |
| 29 |
setprop("/controls/engines/current-engine/mixture", auto_mixture); |
| 30 |
|
| 31 |
# removing any ice from the carburetor |
| 32 |
setprop("/engines/active-engine/carb_ice", 0.0); |
| 33 |
setprop("/engines/active-engine/carb_icing_rate", 0.0); |
| 34 |
setprop("/controls/engines/current-engine/carb-heat", 1); |
| 35 |
|
| 36 |
setprop("/engines/active-engine/running", 1); |
| 37 |
setprop("/engines/active-engine/auto-start", 1); |
| 38 |
setprop("/engines/active-engine/cranking", 1); |
| 39 |
|
| 40 |
|
| 41 |
setprop("/controls/engines/engine[0]/primer", 3); |
| 42 |
setprop("/controls/engines/engine[0]/primer-lever", 0); |
| 43 |
#setprop("/controls/engines/current-engine/throttle", 0.2); |
| 44 |
setprop("/controls/engines/engine[0]/throttle", 0.2); |
| 45 |
setprop("/controls/engines/engine[1]/throttle", 0.2); |
| 46 |
setprop("/controls/flight/elevator-trim", -0.03); |
| 47 |
|
| 48 |
setprop("/controls/switches/dome-red", 0); |
| 49 |
setprop("/controls/switches/dome-white", 0); |
| 50 |
setprop("/controls/switches/magnetos", 3); |
| 51 |
setprop("/controls/switches/master-bat", 1); |
| 52 |
setprop("/controls/switches/master-alt", 1); |
| 53 |
setprop("/controls/switches/master-avionics", 1); |
| 54 |
setprop("/controls/switches/starter", 1); |
| 55 |
|
| 56 |
setprop("/controls/lighting/beacon", 1); |
| 57 |
setprop("/controls/lighting/taxi-light", 0); |
| 58 |
|
| 59 |
setprop("/fdm/jsbsim/running", 0); |
| 60 |
setprop("/fdm/jsbsim/inertia/pointmass-weight-lbs[0]", 170); |
| 61 |
setprop("/fdm/jsbsim/inertia/pointmass-weight-lbs[1]", 0); |
| 62 |
|
| 63 |
setprop("/sim/model/c172p/securing/tiedownL-visible", 0); |
| 64 |
setprop("/sim/model/c172p/securing/tiedownR-visible", 0); |
| 65 |
setprop("/sim/model/c172p/securing/tiedownT-visible", 0); |
| 66 |
setprop("/sim/model/c172p/securing/pitot-cover-visible", 0); |
| 67 |
setprop("/sim/model/c172p/securing/chock", 0); |
| 68 |
setprop("/sim/model/c172p/securing/cowl-plugs-visible", 0); |
| 69 |
setprop("/sim/model/c172p/cockpit/control-lock-placed", 0); |
| 70 |
|
| 71 |
if (getprop("/fdm/jsbsim/bushkit") == 4) { |
| 72 |
setprop("/controls/gear/gear-down-command", 1); |
| 73 |
} |
| 74 |
|
| 75 |
setprop("/controls/gear/brake-parking", 0); |
| 76 |
|
| 77 |
var distance_nm = getprop("/sim/presets/offset-distance-nm") or 0; |
| 78 |
|
| 79 |
var engine_running_check_delay = 5.0; |
| 80 |
settimer(func { |
| 81 |
if (!getprop("/engines/active-engine/running")) { |
| 82 |
gui.popupTip("The autostart failed to start the engine. You may have to adjust the mixture and start the engine manually.", 5); |
| 83 |
} |
| 84 |
setprop("/controls/switches/starter", 0); |
| 85 |
setprop("/engines/active-engine/auto-start", 0); |
| 86 |
|
| 87 |
if (distance_nm > 5) { |
| 88 |
#setprop("/controls/engines/current-engine/throttle", 0.85); |
| 89 |
setprop("/controls/engines/engine[0]/throttle", 0.85); |
| 90 |
setprop("/controls/engines/engine[1]/throttle", 0.85); |
| 91 |
setprop("/controls/flight/flaps", .33); |
| 92 |
} else if (distance_nm > 1) { |
| 93 |
#setprop("/controls/engines/current-engine/throttle", 0.80); |
| 94 |
setprop("/controls/engines/engine[0]/throttle", 0.80); |
| 95 |
setprop("/controls/engines/engine[1]/throttle", 0.80); |
| 96 |
setprop("/controls/flight/flaps", .66); |
| 97 |
} else { |
| 98 |
#setprop("/controls/engines/current-engine/throttle", 0.785); |
| 99 |
setprop("/controls/engines/engine[0]/throttle", 0.75); |
| 100 |
setprop("/controls/engines/engine[1]/throttle", 0.75); |
| 101 |
setprop("/controls/flight/flaps", 1); |
| 102 |
} |
| 103 |
|
| 104 |
# Set the altimeter |
| 105 |
var pressure_sea_level = getprop("/environment/pressure-sea-level-inhg"); |
| 106 |
setprop("/instrumentation/altimeter/setting-inhg", pressure_sea_level); |
| 107 |
|
| 108 |
# Set heading offset |
| 109 |
var magnetic_variation = getprop("/environment/magnetic-variation-deg"); |
| 110 |
setprop("/instrumentation/heading-indicator/offset-deg", -magnetic_variation); |
| 111 |
|
| 112 |
# Setting instrument lights if needed |
| 113 |
var light_level = 1.0-getprop("/rendering/scene/diffuse/red"); |
| 114 |
|
| 115 |
if (light_level > .6) { |
| 116 |
if (getprop("/controls/lighting/instruments-norm") == 0) { |
| 117 |
if (light_level > .6) light_level = .6; |
| 118 |
setprop("/controls/lighting/instruments-norm", light_level); |
| 119 |
} |
| 120 |
if (getprop("/controls/lighting/nav-lights") == 0) { |
| 121 |
setprop("/controls/lighting/nav-lights", 1); |
| 122 |
} |
| 123 |
if (getprop("/controls/lighting/strobe") == 0) { |
| 124 |
setprop("/controls/lighting/strobe", 1); |
| 125 |
} |
| 126 |
if (getprop("/controls/lighting/landing-lights") == 0) { |
| 127 |
setprop("/controls/lighting/landing-lights", 1); |
| 128 |
} |
| 129 |
} |
| 130 |
|
| 131 |
}, engine_running_check_delay); |
| 132 |
|
| 133 |
}; |