zkv1000 / Nasal / afcs.nas /
Newer Older
179 lines | 7.58kb
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'),
adds AFCS
Sébastien MARQUE authored on 2020-05-06
8
        };
9
        foreach (var s; sort(keys(ap_systems), func(a,b) cmp(a,b))) {
10
            call(ap_systems[s], [], nil, nil, var errors = []);
11
            if (!size(errors)) {
12
                msg('found autopilot system: ' ~ s);
13
                m.system = s;
14
                break;
15
            }
16
        }
17

            
18
        m.engaged = 0;
19

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

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

            
40
        ap_annun = nil;
41
        ap_systems = nil;
42

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

            
46
        return m;
47
    },
48
    softkey: func (side, row, a) {
little fixes
Sébastien MARQUE authored on 2020-05-11
49
        if (a)
adds AFCS
Sébastien MARQUE authored on 2020-05-06
50
            return;
51
        var _system = me.systems[me.system];
52
        var _side = _system[side];
53
        _side[row]();
54
    },
55
    systems : {
56
        # L: AP FD  NAV ALT VS FLC
57
        # R: YD HDG APR VNV UP DN
58
        none: {
59
            updateDisplay: func,
60
            hook: func,
61
            L: [ func, func, func, func, func, func ],
62
            R: [ func, func, func, func, func, func ],
63
        },
autopilot S-TEC 55X integrat...
Sébastien MARQUE authored on 2020-05-06
64
        STEC55X: {
autopilot status with separa...
Sébastien MARQUE authored on 2020-05-08
65
            hook : func {
66
                me.trimTarget = 0;
stec55x integration (suite)
Sébastien MARQUE authored on 2020-05-11
67
                afcs.getNode('heading-bug-deg').unalias();
68
                stec55x.hdg.alias(afcs.getNode('heading-bug-deg'));
69
                afcs.getNode('selected-alt-ft').unalias();
70
                stec55x.alt.alias(afcs.getNode('selected-alt-ft'));
71
                setprop('/it-stec55x/input/ap-master-sw', 1);
autopilot status with separa...
Sébastien MARQUE authored on 2020-05-08
72
            },
autopilot S-TEC 55X integrat...
Sébastien MARQUE authored on 2020-05-06
73
            updateDisplay: func {
autopilot status with separa...
Sébastien MARQUE authored on 2020-05-08
74
                var se = flightdeck.PFD.display.screenElements;
75
                se['AP-Status-text'].setVisible(stec55x.rollMode  != -1 or stec55x.pitchMode != -1);
76
                se['YD-Status-text'].setVisible(stec55x.yaw.getValue() != -1);
77
                if (stec55x.rollMode  != -1) {
78
                    se['LATMOD-Active-text'].setVisible(1).setText('ROL');
79
                    var armed = '';
80
                    foreach (var m; [ 'NAV', 'CNAV', 'REV', 'CREV' ])
81
                        if (stec55x[m]) armed = m;
82
                    if (stec55x.roll.getValue() == 4) armed = 'GPS';
83
                    if (stec55x.APR_annun.getValue()) armed = 'APR';
84
                    if (stec55x.HDG_annun.getValue()) armed = 'HDG';
85
                    se['LATMOD-Armed-text']
86
                        .setVisible(size(armed))
87
                        .setText(armed);
88
                }
89
                else {
90
                    se['LATMOD-Active-text'].setVisible(0);
91
                    se['LATMOD-Armed-text'].setVisible(0);
autopilot S-TEC 55X integrat...
Sébastien MARQUE authored on 2020-05-06
92
                }
93

            
autopilot status with separa...
Sébastien MARQUE authored on 2020-05-08
94
                if (stec55x.pitchMode != 1) {
95
                    var armed     = '';
96
                    var active    = '';
97
                    var reference = '';
98
                    if (stec55x.ALT_annun.getBoolValue()) {
99
                        if (abs(data.alt - afcs.getValue('selected-alt-ft')) < 150) {
100
                            active    = 'ALT';
101
                            reference = sprintf('%5d ft', afcs.getValue('selected-alt-ft'));
102
                            armed     = 'ALTS'
103
                        }
104
                        else {
105
                            active    = 'ALT';
106
                            reference = sprintf('%5d ft', math.round(data.alt, 10));
107
                            armed     = 'ALT';
108
                        }
109
                    }
110
                    elsif (stec55x.VS_annun.getBoolValue()) {
111
                        active    = 'VS';
112
                        reference = sprintf('%s%4d fpm',
autopilot S-TEC 55X integrat...
Sébastien MARQUE authored on 2020-05-06
113
                                        utf8.chstr(stec55x.vs.getValue() > 0 ? 9650 : 9660),
114
                                        math.abs(math.round(stec55x.vs.getValue(), 10)));
autopilot status with separa...
Sébastien MARQUE authored on 2020-05-08
115
                    }
116
                    elsif (stec55x.GSArmed.getBoolValue()) {
117
                        armed  = 'VPATH';
118
                        active = 'GS';
119
                    }
120
# TODO: ask Octal450 which prop or variable can be used here
121
#                    elsif (stec55x.???) {
122
#                        armed  = 'PIT';
123
#                        active = 'ALT';
124
#                        reference = sprintf("%d°", autopilot.systems.STEC55X.trim);
125
#                    }
126
                    se['VERMOD-Active-text'].setVisible(size(active)).setText(active);
127
                    se['VERMOD-Armed-text'].setVisible(size(armed)).setText(armed);
128
                    se['VERMOD-Reference-text'].setVisible(size(reference)).setText(reference);
129
                }
autopilot S-TEC 55X integrat...
Sébastien MARQUE authored on 2020-05-06
130
            },
131
            L: [
only HDG roll mode is availa...
Sébastien MARQUE authored on 2020-05-11
132
                func,
autopilot S-TEC 55X integrat...
Sébastien MARQUE authored on 2020-05-06
133
                func {
only HDG roll mode is availa...
Sébastien MARQUE authored on 2020-05-11
134
#                    var apfd_master_sw = '/it-stec55x/input/apfd-master-sw';
135
#                    setprop(apfd_master_sw, !getprop(apfd_master_sw));
autopilot S-TEC 55X integrat...
Sébastien MARQUE authored on 2020-05-06
136
                },
137
                func {
only HDG roll mode is availa...
Sébastien MARQUE authored on 2020-05-11
138
#                    call(stec55x.button.NAV, [], nil, stec55x);
autopilot S-TEC 55X integrat...
Sébastien MARQUE authored on 2020-05-06
139
                },
140
                func {
only HDG roll mode is availa...
Sébastien MARQUE authored on 2020-05-11
141
#                    call(stec55x.button.ALT, [], nil, stec55x);
autopilot S-TEC 55X integrat...
Sébastien MARQUE authored on 2020-05-06
142
                },
143
                func {
only HDG roll mode is availa...
Sébastien MARQUE authored on 2020-05-11
144
#                    stec55x.vs.setValue(math.round(data.vsi, 100));
145
#                    call(stec55x.button.VS, [], nil, stec55x);
autopilot S-TEC 55X integrat...
Sébastien MARQUE authored on 2020-05-06
146
                },
147
                func,
148
            ],
149
            R: [
150
                func {
only HDG roll mode is availa...
Sébastien MARQUE authored on 2020-05-11
151
#                    var yaw_dumper_sw = '/it-stec55x/input/yaw-damper-sw';
152
#                    setprop(yaw_dumper_sw, !getprop(yaw_dumper_sw));
autopilot S-TEC 55X integrat...
Sébastien MARQUE authored on 2020-05-06
153
                },
154
                func {
only HDG roll mode is availa...
Sébastien MARQUE authored on 2020-05-11
155
                    if (stec55x.roll.getValue() == 0)
156
                        stec55x.roll.setValue(-1);
157
                    else
158
                        call(stec55x.button.HDG, [], nil, stec55x);
autopilot S-TEC 55X integrat...
Sébastien MARQUE authored on 2020-05-06
159
                },
160
                func {
only HDG roll mode is availa...
Sébastien MARQUE authored on 2020-05-11
161
#                    call(stec55x.button.APR, [], nil, stec55x);
autopilot S-TEC 55X integrat...
Sébastien MARQUE authored on 2020-05-06
162
                },
163
                func,
164
                func { # UP (trim)
only HDG roll mode is availa...
Sébastien MARQUE authored on 2020-05-11
165
#                    if (autopilot.systems.STEC55X.trimTarget > -15)
166
#                        autopilot.systems.STEC55X.trimTarget -= 1;
167
#                    fgcommand('property-assign', {property: '/it-stec55x/input/man-trim', value: -1});
168
#                    fgcommand('property-assign', {property: '/it-stec55x/input/man-trim', value:  0});
autopilot S-TEC 55X integrat...
Sébastien MARQUE authored on 2020-05-06
169
                },
170
                func { # DN (trim)
only HDG roll mode is availa...
Sébastien MARQUE authored on 2020-05-11
171
#                    if (autopilot.systems.STEC55X.trimTarget < 20)
172
#                        autopilot.systems.STEC55X.trimTarget += 1;
173
#                    fgcommand('property-assign', {property: '/it-stec55x/input/man-trim', value: 1});
174
#                    fgcommand('property-assign', {property: '/it-stec55x/input/man-trim', value: 0});
autopilot S-TEC 55X integrat...
Sébastien MARQUE authored on 2020-05-06
175
                },
176
            ],
177
        }
adds AFCS
Sébastien MARQUE authored on 2020-05-06
178
    }
179
};