zkv1000 / Nasal / afcs.nas /
Newer Older
298 lines | 13.995kb
adds AFCS
Sébastien MARQUE authored on 2020-05-06
1
var APClass = {
2
    new : func {
3
        var m = { parents: [ APClass ] };
4

            
5
        m.system = 'none';
6
        var ap_systems = { # described AP systems to search, if it returns true system is set
autopilot S-TEC 55X integrat...
Sébastien MARQUE authored on 2020-05-06
7
            STEC55X: func contains(stec55x, 'ITAF'),
creates entry point for GFC7...
Sébastien MARQUE authored on 2020-05-16
8
            GFC700: func props.globals.getNode('/autopilot/GFC700/FSM/lateral').getPath(),
adds AFCS
Sébastien MARQUE authored on 2020-05-06
9
        };
10
        foreach (var s; sort(keys(ap_systems), func(a,b) cmp(a,b))) {
11
            call(ap_systems[s], [], nil, nil, var errors = []);
12
            if (!size(errors)) {
13
                msg('found autopilot system: ' ~ s);
14
                m.system = s;
15
                break;
16
            }
17
        }
18

            
19
        m.engaged = 0;
20

            
21
        if (! contains(data.timers, 'updateAP')) {
22
            data.timers.updateAP = maketimer(1, m, m.systems[m.system].updateDisplay);
23
            data.timers.updateAP.start();
24
        }
25

            
autopilot status with separa...
Sébastien MARQUE authored on 2020-05-08
26
        var ap_annun = [
27
            'LATMOD-Armed-text',  'LATMOD-Active-text',
28
            'AP-Status-text',     'YD-Status-text',
29
            'VERMOD-Active-text', 'VERMOD-Reference-text', 'VERMOD-Armed-text'
30
        ];
31
        foreach (var elem; ap_annun) {
32
            var color = (elem == 'LATMOD-Armed-text' or elem == 'VERMOD-Armed-text') ? 'white' : 'green';
33
            flightdeck.PFD.display.screenElements[elem]
34
                .setColor(flightdeck.PFD.display.colors[color])
35
                .setVisible(0);
36
        }
37
        foreach (var ap; [ 'AP', 'YD' ])
38
            flightdeck.PFD.display.screenElements[ap ~ '-Status-text']
afcs improvements
Sébastien MARQUE authored on 2020-05-17
39
                .setDrawMode(canvas.Text.TEXT + canvas.Text.FILLEDBOUNDINGBOX)
40
                .setColorFill(flightdeck.PFD.display.colors.black)
autopilot status with separa...
Sébastien MARQUE authored on 2020-05-08
41
                .setText(ap);
42

            
43
        ap_annun = nil;
44
        ap_systems = nil;
delete unused afcs systems
Sébastien MARQUE authored on 2020-05-16
45
        # delete unused systems
46
        foreach (var e; keys(m.systems))
47
            if (e != m.system)
48
                delete(m.systems, e);
autopilot status with separa...
Sébastien MARQUE authored on 2020-05-08
49

            
adds AFCS
Sébastien MARQUE authored on 2020-05-06
50
        if (contains(m.systems[m.system], 'hook') and typeof(m.systems[m.system].hook) == 'func')
51
                m.systems[m.system].hook();
52

            
53
        return m;
54
    },
55
    softkey: func (side, row, a) {
little fixes
Sébastien MARQUE authored on 2020-05-11
56
        if (a)
adds AFCS
Sébastien MARQUE authored on 2020-05-06
57
            return;
afcs improvements
Sébastien MARQUE authored on 2020-05-17
58
        call(me.systems[me.system][side][row], [], autopilot.parents[0].systems[me.system]);
adds AFCS
Sébastien MARQUE authored on 2020-05-06
59
    },
60
    systems : {
61
        # L: AP FD  NAV ALT VS FLC
62
        # R: YD HDG APR VNV UP DN
63
        none: {
64
            updateDisplay: func,
65
            hook: func,
66
            L: [ func, func, func, func, func, func ],
67
            R: [ func, func, func, func, func, func ],
68
        },
creates entry point for GFC7...
Sébastien MARQUE authored on 2020-05-16
69
        GFC700: {
integration of GFC700 capabi...
Sébastien MARQUE authored on 2020-05-17
70
# Many thanks to the great work on the FG1000
71
            _blink_count: 0,
72
            updateDisplay: func {
73
                var se = flightdeck.PFD.display.screenElements;
74
                var annunciator = props.globals.getNode('/autopilot/annunciator');
75
                var ap_enabled  = annunciator.getValue('autopilot-enabled');
76

            
77
                var latmod         = annunciator.getValue('lateral-mode');
78
                var latmod_armed   = annunciator.getValue('lateral-mode-armed');
79
                var vertmod        = annunciator.getValue('vertical-mode');
80
                var vertmod_armed  = annunciator.getValue('vertical-mode-armed');
81
                var vertmod_target = annunciator.getValue('vertical-mode-target');
82
                if (vertmod_target != nil) {
83
                    vertmod_target = string.replace(vertmod_target, '+', utf8.chstr(9650));
84
                    vertmod_target = string.replace(vertmod_target, '-', utf8.chstr(9660));
85
                }
86

            
87
                se['LATMOD-Active-text'].setVisible(latmod != nil and ap_enabled).setText(latmod);
88
                se['LATMOD-Armed-text'].setVisible(latmod_armed != nil and ap_enabled).setText(latmod_armed);
89
                se['VERMOD-Active-text'].setVisible(vertmod != nil and ap_enabled).setText(vertmod);
90
                se['VERMOD-Reference-text'].setVisible(vertmod_target != nil and ap_enabled).setText(vertmod_target);
91
                se['VERMOD-Armed-text'].setVisible(vertmod_armed != nil and ap_enabled).setText(vertmod_armed);
92

            
93
                if (se['AP-Status-text'].getVisible() and !ap_enabled) {
94
                    if (math.mod(me._blink_count,2))
95
                        se['AP-Status-text']
96
                            .setDrawMode(canvas.Text.TEXT + canvas.Text.FILLEDBOUNDINGBOX)
97
                            .setColorFill(flightdeck.PFD.display.colors.yellow)
98
                            .setColor(flightdeck.PFD.display.colors.black);
99
                    else
100
                        se['AP-Status-text']
101
                            .setDrawMode(canvas.Text.TEXT + canvas.Text.FILLEDBOUNDINGBOX)
102
                            .setColorFill(flightdeck.PFD.display.colors.black)
103
                            .setColor(flightdeck.PFD.display.colors.yellow);
104
                    me._blink_count += 1;
105
                    if (me._blink_count == 5) {
106
                        se['AP-Status-text']
107
                            .setColor(flightdeck.PFD.display.colors.green)
108
                            .setVisible(0);
109
                        me._blink_count = 0;
110
                    }
111
                    return;
112
                }
113
                else {
114
                    se['AP-Status-text'].setVisible(ap_enabled);
115
                    me._blink_count = 0;
116
                }
117
            },
118
            hook: func {
119
                me._vertical_mode = globals.props.getNode("/autopilot/annunciator/vertical-mode", 1);
120
                me._pitch_setting = globals.props.getNode("/autopilot/settings/target-pitch-deg", 1);
121
                me._climb_setting = globals.props.getNode("/autopilot/settings/vertical-speed-fpm", 1);
122
                me._speed_setting = globals.props.getNode("/autopilot/settings/target-speed-kt", 1);
123
                me._vertical_mode_button = globals.props.getNode("/autopilot/vertical-mode-button", 1);
124
                me._lateral_mode_button = globals.props.getNode("/autopilot/lateral-mode-button", 1);
125
                me._ap_mode_button = globals.props.getNode("/autopilot/AP-mode-button", 1);
126
                me._ap_enabled = globals.props.getNode("/autopilot/annunciator/autopilot-enabled", 1);;
127
                me._fd_enabled = globals.props.getNode("/autopilot/annunciator/flight-director-enabled", 1);;
128

            
129
            },
130
            sendModeChange: func (value) {
131
                me._vertical_mode_button.setValue(value);
132
                me._lateral_mode_button.setValue(value);
133
                if (value == "AP") {
134
                    me._ap_mode_button.setValue(value);
135
                }
136
            },
137
            handleNoseUpDown : func(value) {
138
                var vertical_mode = me._vertical_mode.getValue();
139

            
140
                if (vertical_mode == "PIT")
141
                    me._pitch_setting.setValue(me._pitch_setting.getValue() + (value * 1));
142

            
143
                if (vertical_mode == "VS") {
144
                    me._climb_setting.setValue(me._climb_setting.getValue() + (value * 100));
145
                    setprop("/autopilot/annunciator/vertical-mode-target",
146
                        sprintf("%+ifpm", me._climb_setting.getValue())
147
                    );
148
                }
149

            
150
                if (vertical_mode == "FLC") {
151
                    me._speed_setting.setValue(me._speed_setting.getValue() - (value * 1));
152
                    setprop("/autopilot/annunciator/vertical-mode-target",
153
                        sprintf("%i kt", me._speed_setting.getValue())
154
                    );
155
                }
156
            },
nothing interesting
Sébastien MARQUE authored on 2020-05-17
157
            L: [
integration of GFC700 capabi...
Sébastien MARQUE authored on 2020-05-17
158
               func { me.sendModeChange('AP');  },
159
               func { me.sendModeChange('FD');  },
160
               func { me.sendModeChange('NAV'); },
161
               func { me.sendModeChange('ALT'); },
162
               func { me.sendModeChange('VS');  },
163
               func { me.sendModeChange('FLC'); },
164
            ],
nothing interesting
Sébastien MARQUE authored on 2020-05-17
165
            R: [
integration of GFC700 capabi...
Sébastien MARQUE authored on 2020-05-17
166
               func { me.sendModeChange('YD');  },
167
               func { me.sendModeChange('HDG'); },
168
               func { me.sendModeChange('APR'); },
169
               func { me.sendModeChange('VNV'); },
170
               func { me.handleNoseUpDown(1);   },
171
               func { me.handleNoseUpDown(-1);  },
172
            ],
creates entry point for GFC7...
Sébastien MARQUE authored on 2020-05-16
173
        },
autopilot S-TEC 55X integrat...
Sébastien MARQUE authored on 2020-05-06
174
        STEC55X: {
code more clear
Sébastien MARQUE authored on 2020-05-16
175
            _aliases: {
176
                hdg:          afcs.getNode('heading-bug-deg'),
177
                alt:          afcs.getNode('selected-alt-ft'),
178
                NAVCourse:    cdi.getNode('course'),
179
                OBSNAVNeedle: cdi.getNode('course-deflection'),
180
            },
autopilot status with separa...
Sébastien MARQUE authored on 2020-05-08
181
            hook : func {
182
                me.trimTarget = 0;
code more clear
Sébastien MARQUE authored on 2020-05-16
183
                foreach (var a; keys(me._aliases)) stec55x[a].alias(me._aliases[a]);
stec55x integration (suite)
Sébastien MARQUE authored on 2020-05-11
184
                setprop('/it-stec55x/input/ap-master-sw', 1);
autopilot status with separa...
Sébastien MARQUE authored on 2020-05-08
185
            },
autopilot S-TEC 55X integrat...
Sébastien MARQUE authored on 2020-05-06
186
            updateDisplay: func {
autopilot status with separa...
Sébastien MARQUE authored on 2020-05-08
187
                var se = flightdeck.PFD.display.screenElements;
188
                se['AP-Status-text'].setVisible(stec55x.rollMode  != -1 or stec55x.pitchMode != -1);
189
                se['YD-Status-text'].setVisible(stec55x.yaw.getValue() != -1);
190
                if (stec55x.rollMode  != -1) {
191
                    se['LATMOD-Active-text'].setVisible(1).setText('ROL');
192
                    var armed = '';
193
                    foreach (var m; [ 'NAV', 'CNAV', 'REV', 'CREV' ])
194
                        if (stec55x[m]) armed = m;
fix roll mode determination
Sébastien MARQUE authored on 2020-05-11
195
                    if (stec55x.roll.getValue() == 0) armed = 'HDG';
196
                    elsif (stec55x.roll.getValue() == 2) armed = 'GPS';
197
                    elsif (stec55x.APR_annun.getValue()) armed = 'APR';
autopilot status with separa...
Sébastien MARQUE authored on 2020-05-08
198
                    se['LATMOD-Armed-text']
199
                        .setVisible(size(armed))
200
                        .setText(armed);
201
                }
202
                else {
203
                    se['LATMOD-Active-text'].setVisible(0);
204
                    se['LATMOD-Armed-text'].setVisible(0);
autopilot S-TEC 55X integrat...
Sébastien MARQUE authored on 2020-05-06
205
                }
206

            
autopilot status with separa...
Sébastien MARQUE authored on 2020-05-08
207
                if (stec55x.pitchMode != 1) {
208
                    var armed     = '';
209
                    var active    = '';
210
                    var reference = '';
211
                    if (stec55x.ALT_annun.getBoolValue()) {
212
                        if (abs(data.alt - afcs.getValue('selected-alt-ft')) < 150) {
213
                            active    = 'ALT';
214
                            reference = sprintf('%5d ft', afcs.getValue('selected-alt-ft'));
215
                            armed     = 'ALTS'
216
                        }
217
                        else {
218
                            active    = 'ALT';
219
                            reference = sprintf('%5d ft', math.round(data.alt, 10));
220
                            armed     = 'ALT';
221
                        }
222
                    }
223
                    elsif (stec55x.VS_annun.getBoolValue()) {
224
                        active    = 'VS';
225
                        reference = sprintf('%s%4d fpm',
autopilot S-TEC 55X integrat...
Sébastien MARQUE authored on 2020-05-06
226
                                        utf8.chstr(stec55x.vs.getValue() > 0 ? 9650 : 9660),
227
                                        math.abs(math.round(stec55x.vs.getValue(), 10)));
autopilot status with separa...
Sébastien MARQUE authored on 2020-05-08
228
                    }
229
                    elsif (stec55x.GSArmed.getBoolValue()) {
230
                        armed  = 'VPATH';
231
                        active = 'GS';
232
                    }
233
# TODO: ask Octal450 which prop or variable can be used here
234
#                    elsif (stec55x.???) {
235
#                        armed  = 'PIT';
236
#                        active = 'ALT';
237
#                        reference = sprintf("%d°", autopilot.systems.STEC55X.trim);
238
#                    }
239
                    se['VERMOD-Active-text'].setVisible(size(active)).setText(active);
240
                    se['VERMOD-Armed-text'].setVisible(size(armed)).setText(armed);
241
                    se['VERMOD-Reference-text'].setVisible(size(reference)).setText(reference);
242
                }
autopilot S-TEC 55X integrat...
Sébastien MARQUE authored on 2020-05-06
243
            },
244
            L: [
only HDG roll mode is availa...
Sébastien MARQUE authored on 2020-05-11
245
                func,
autopilot S-TEC 55X integrat...
Sébastien MARQUE authored on 2020-05-06
246
                func {
only HDG roll mode is availa...
Sébastien MARQUE authored on 2020-05-11
247
#                    var apfd_master_sw = '/it-stec55x/input/apfd-master-sw';
248
#                    setprop(apfd_master_sw, !getprop(apfd_master_sw));
autopilot S-TEC 55X integrat...
Sébastien MARQUE authored on 2020-05-06
249
                },
250
                func {
add STEC55X GPS roll mode
Sébastien MARQUE authored on 2020-05-11
251
                    var _roll = stec55x.roll.getValue();
252
                    if (_roll == 1 or _roll == 2 or _roll == 4)
253
                        stec55x.roll.setValue(-1);
254
                    else {
255
                        stec55x.roll.setValue(1);
256
                        call(stec55x.button.NAV, [], nil, stec55x);
257
                    }
autopilot S-TEC 55X integrat...
Sébastien MARQUE authored on 2020-05-06
258
                },
259
                func {
only HDG roll mode is availa...
Sébastien MARQUE authored on 2020-05-11
260
#                    call(stec55x.button.ALT, [], nil, stec55x);
autopilot S-TEC 55X integrat...
Sébastien MARQUE authored on 2020-05-06
261
                },
262
                func {
only HDG roll mode is availa...
Sébastien MARQUE authored on 2020-05-11
263
#                    stec55x.vs.setValue(math.round(data.vsi, 100));
264
#                    call(stec55x.button.VS, [], nil, stec55x);
autopilot S-TEC 55X integrat...
Sébastien MARQUE authored on 2020-05-06
265
                },
266
                func,
267
            ],
268
            R: [
269
                func {
only HDG roll mode is availa...
Sébastien MARQUE authored on 2020-05-11
270
#                    var yaw_dumper_sw = '/it-stec55x/input/yaw-damper-sw';
271
#                    setprop(yaw_dumper_sw, !getprop(yaw_dumper_sw));
autopilot S-TEC 55X integrat...
Sébastien MARQUE authored on 2020-05-06
272
                },
273
                func {
only HDG roll mode is availa...
Sébastien MARQUE authored on 2020-05-11
274
                    if (stec55x.roll.getValue() == 0)
275
                        stec55x.roll.setValue(-1);
276
                    else
277
                        call(stec55x.button.HDG, [], nil, stec55x);
autopilot S-TEC 55X integrat...
Sébastien MARQUE authored on 2020-05-06
278
                },
279
                func {
only HDG roll mode is availa...
Sébastien MARQUE authored on 2020-05-11
280
#                    call(stec55x.button.APR, [], nil, stec55x);
autopilot S-TEC 55X integrat...
Sébastien MARQUE authored on 2020-05-06
281
                },
282
                func,
283
                func { # UP (trim)
only HDG roll mode is availa...
Sébastien MARQUE authored on 2020-05-11
284
#                    if (autopilot.systems.STEC55X.trimTarget > -15)
285
#                        autopilot.systems.STEC55X.trimTarget -= 1;
286
#                    fgcommand('property-assign', {property: '/it-stec55x/input/man-trim', value: -1});
287
#                    fgcommand('property-assign', {property: '/it-stec55x/input/man-trim', value:  0});
autopilot S-TEC 55X integrat...
Sébastien MARQUE authored on 2020-05-06
288
                },
289
                func { # DN (trim)
only HDG roll mode is availa...
Sébastien MARQUE authored on 2020-05-11
290
#                    if (autopilot.systems.STEC55X.trimTarget < 20)
291
#                        autopilot.systems.STEC55X.trimTarget += 1;
292
#                    fgcommand('property-assign', {property: '/it-stec55x/input/man-trim', value: 1});
293
#                    fgcommand('property-assign', {property: '/it-stec55x/input/man-trim', value: 0});
autopilot S-TEC 55X integrat...
Sébastien MARQUE authored on 2020-05-06
294
                },
295
            ],
296
        }
adds AFCS
Sébastien MARQUE authored on 2020-05-06
297
    }
298
};