- A-6E: Moved the instrument model definition in a cockpit dedicated model file....
[fg:toms-fgdata.git] / Aircraft / A-6E / Nasal / A-6E.nas
1
2
3
4 var UPDATE_PERIOD = 0.1;
5
6 var ticker      = props.globals.getNode("sim/model/A-6E/instrumentation/ticker", 1);
7 var ikts        = props.globals.getNode("velocities/airspeed-kt");
8 var aft_ballast = props.globals.getNode("sim/model/A-6E/controls/flight/CG-trim-aft", 1);
9 var fwd_ballast = props.globals.getNode("sim/model/A-6E/controls/flight/CG-trim-fwd", 1);
10 var Vx          = props.globals.getNode("velocities/uBody-fps", 1);
11 var Vy          = props.globals.getNode("velocities/vBody-fps", 1);
12 var Vz          = props.globals.getNode("velocities/wBody-fps", 1);
13 var vdi_vel_y   = props.globals.getNode("sim/model/A-6E/instrumentation/vdi/velocity_marker_y", 1);
14 var vdi_vel_z   = props.globals.getNode("sim/model/A-6E/instrumentation/vdi/velocity_marker_z", 1);
15 #var wind_deg   = props.globals.getNode("environment/wind-from-heading-deg");
16 #var wind_kts   = props.globals.getNode("environment/wind-speed-kt");
17 var ac_hdg      = props.globals.getNode("/orientation/heading-deg", 1);
18 var g_curr              = props.globals.getNode("accelerations/pilot-g");
19 var g_max               = props.globals.getNode("sim/model/A-6E/instrumentation/g-meter/g-max", 1);
20 var g_min               = props.globals.getNode("sim/model/A-6E/instrumentation/g-meter/g-min", 1);
21 var TrueHdg          = props.globals.getNode("orientation/heading-deg");
22 var Hsd              = props.globals.getNode("sim/model/A-6E/instrumentation/hsd", 1);
23 var MagHdg           = props.globals.getNode("orientation/heading-magnetic-deg");
24 var MagDev           = props.globals.getNode("orientation/local-mag-dev", 1);
25 var Tc               = props.globals.getNode("instrumentation/tacan");
26 var Vtc              = props.globals.getNode("instrumentation/nav[1]");
27 var TcFreqs          = Tc.getNode("frequencies");
28 var TcTrueHdg        = Tc.getNode("indicated-bearing-true-deg");
29 var TcMagHdg         = Tc.getNode("indicated-mag-bearing-deg", 1);
30 var TcIdent          = Tc.getNode("ident");
31 var TcServ           = Tc.getNode("serviceable");
32 var TcXY             = Tc.getNode("frequencies/selected-channel[4]");
33
34 var mag_dev = 0;
35 var tc_mode = 0;
36
37
38 # Main loop ###############
39 var cnt = 0;
40
41 update_loop = func {
42         A6Echronograph.update_chrono();
43         tacan_update();
44         inc_ticker();
45         g_min_max();
46         auto_trim();
47         vdi_vel_marker();
48         vdi_drift_angle();
49         if ( cnt == 10 ) {
50                 # done each 1 sec.
51                 local_mag_deviation();
52                 cnt = 0;
53         } else {
54                 cnt += 1;
55         }
56         settimer(update_loop, UPDATE_PERIOD);
57 }
58
59
60
61 # functions ###############
62
63 inc_ticker = func {
64         # used for VDI background continuous translation animation
65         var tick = ticker.getValue();
66         tick += 1 ;
67         ticker.setDoubleValue(tick);
68 }
69
70 g_min_max = func {
71         # records g min and max values
72         var curr = g_curr.getValue();
73         var max = g_max.getValue();
74         var min = g_min.getValue();
75         if ( curr >= max ) {
76                 g_max.setDoubleValue(curr);
77         } elsif ( curr <= min ) {
78                 g_min.setDoubleValue(curr);
79         }
80 }
81
82
83 auto_trim = func {
84         # Move a ballast from one Yasim weight point to another
85         # depending on the airspeed of the a/c. 
86         var kts = ikts.getValue();
87         var new_fwd = 0;
88         if (kts > 150) { new_fwd = 30*(kts-150); }
89         if (new_fwd > 7000) { new_fwd = 7000 }
90         var new_aft = 7000 - new_fwd;
91         
92         aft_ballast.setDoubleValue(new_aft);
93         fwd_ballast.setDoubleValue(new_fwd);
94 }
95
96
97 # Compute local magnetic deviation.
98 var local_mag_deviation = func {
99         var true = TrueHdg.getValue();
100         var mag = MagHdg.getValue();
101         mag_dev = geo.normdeg( mag - true );
102         if ( mag_dev > 180 ) mag_dev -= 360;
103         MagDev.setValue(mag_dev); 
104 }
105
106
107 var tacan_update = func {
108         #var tc_mode = TcModeSwitch.getValue();
109         var tc_mode = 1;
110         if ( tc_mode != 0 and tc_mode != 4 ) {
111
112                 # Get magnetic tacan bearing.
113                 var true_bearing = TcTrueHdg.getValue();
114                 var mag_bearing = geo.normdeg( true_bearing + mag_dev );
115                 if ( true_bearing != 0 ) {
116                         TcMagHdg.setDoubleValue( mag_bearing );
117                 } else {
118                         TcMagHdg.setDoubleValue(0);
119                 }
120
121                 # Get TACAN radials on HSD's Course Deviation Indicator.
122                 # CDI works with ils OR tacan OR vortac (which freq is tuned from the tacan panel).
123                 #var tcnid = TcIdent.getValue();
124                 #var vtcid = VtcIdent.getValue();
125                 #if ( tcnid == vtcid ) {
126                         # We have a VORTAC.
127                         #HsdFromFlag.setBoolValue(VtcFromFlag.getBoolValue());
128                         #HsdToFlag.setBoolValue(VtcToFlag.getBoolValue());
129                         #HsdCdiDeflection.setValue(VtcHdgDeflection.getValue());
130                 #} else {
131                         # We have a legacy TACAN.
132                         #var tcn_toflag = 1;
133                         #var tcn_fromflag = 0;
134                         #var tcn_bearing = TcMagHdg.getValue();
135                         #var radial = VtcRadialDeg.getValue();
136                         #var d = tcn_bearing - radial;
137                         #if ( d > 180 ) { d -= 360 } elsif ( d < -180 ) { d += 360 }
138                         #if ( d > 90 ) {
139                                 #d -= 180;
140                                 #tcn_toflag = 0;
141                                 #tcn_fromflag = 1;
142                         #} elsif ( d < - 90 ) {
143                                 #d += 180;
144                                 #tcn_toflag = 0;
145                                 #tcn_fromflag = 1;
146                         #}
147                         #if ( d > 10 ) d = 10 ;
148                         #if ( d < -10 ) d = -10 ;
149                         #HsdFromFlag.setBoolValue(tcn_fromflag);
150                         #HsdToFlag.setBoolValue(tcn_toflag);
151                         #HsdCdiDeflection.setValue(d);
152                 #}
153         } else {
154                 TcMagHdg.setDoubleValue(0);
155         }
156 }
157
158 vdi_vel_marker = func {
159         # displays impact point on the VDI display
160         var vx = Vx.getValue();
161         var vy = Vy.getValue();
162         var vz = Vz.getValue();
163         if (vx > 0.1 ) {
164                 var vely = vy/vx;
165                 var velz = vz/vx;
166                 vdi_vel_y.setDoubleValue(vely);
167                 vdi_vel_z.setDoubleValue(velz);
168         }
169 }
170
171 vdi_drift_angle = func {
172         #var wdeg = wind-deg.getValue();
173         #var wkt = wind_kt.getValue();
174         var achdg = ac_hdg.getValue();
175 }
176
177 # init #################
178
179 print("Initializing A-6 Intruder systems");
180 ticker.setDoubleValue(0);
181 vdi_vel_y.setDoubleValue(0);
182 vdi_vel_z.setDoubleValue(0);
183
184 # Remember Radar Altimeter and lighting settings.
185 aircraft.data.add(
186         "sim/model/A-6E/instrumentation/radar-altimeter/limit-bug",
187         "controls/lighting/beacon",
188         "controls/lighting/taxi-light",
189         "sim/model/A-6E/controls/lighting/pylons-lts",
190         "controls/lighting/instruments-norm",
191         "controls/lighting/panel-norm",
192         "sim/model/A-6E/controls/lighting/index-norm",
193         "sim/model/A-6E/controls/lighting/tail-lt",
194         "sim/model/A-6E/controls/lighting/wings-lts",
195         "sim/model/A-6E/controls/lighting/formation-lts",
196         "sim/model/A-6E/controls/lighting/flood-lts"
197 );
198
199 #setlistener("/sim/signals/fdm-initialized", update_loop);
200 settimer(update_loop, 10);