zkv1000 / Nasal / afcs.nas /
Newer Older
199 lines | 8.402kb
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']
39
                .setText(ap);
40

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

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

            
51
        return m;
52
    },
53
    softkey: func (side, row, a) {
little fixes
Sébastien MARQUE authored on 2020-05-11
54
        if (a)
adds AFCS
Sébastien MARQUE authored on 2020-05-06
55
            return;
56
        var _system = me.systems[me.system];
57
        var _side = _system[side];
58
        _side[row]();
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: {
70
            updateDisplay: func,
71
            hook: func,
72
            L: [ func, func, func, func, func, func ],
73
            R: [ func, func, func, func, func, func ],
74
        },
autopilot S-TEC 55X integrat...
Sébastien MARQUE authored on 2020-05-06
75
        STEC55X: {
code more clear
Sébastien MARQUE authored on 2020-05-16
76
            _aliases: {
77
                hdg:          afcs.getNode('heading-bug-deg'),
78
                alt:          afcs.getNode('selected-alt-ft'),
79
                NAVCourse:    cdi.getNode('course'),
80
                OBSNAVNeedle: cdi.getNode('course-deflection'),
81
            },
autopilot status with separa...
Sébastien MARQUE authored on 2020-05-08
82
            hook : func {
83
                me.trimTarget = 0;
code more clear
Sébastien MARQUE authored on 2020-05-16
84
                foreach (var a; keys(me._aliases)) stec55x[a].alias(me._aliases[a]);
stec55x integration (suite)
Sébastien MARQUE authored on 2020-05-11
85
                setprop('/it-stec55x/input/ap-master-sw', 1);
autopilot status with separa...
Sébastien MARQUE authored on 2020-05-08
86
            },
autopilot S-TEC 55X integrat...
Sébastien MARQUE authored on 2020-05-06
87
            updateDisplay: func {
autopilot status with separa...
Sébastien MARQUE authored on 2020-05-08
88
                var se = flightdeck.PFD.display.screenElements;
89
                se['AP-Status-text'].setVisible(stec55x.rollMode  != -1 or stec55x.pitchMode != -1);
90
                se['YD-Status-text'].setVisible(stec55x.yaw.getValue() != -1);
91
                if (stec55x.rollMode  != -1) {
92
                    se['LATMOD-Active-text'].setVisible(1).setText('ROL');
93
                    var armed = '';
94
                    foreach (var m; [ 'NAV', 'CNAV', 'REV', 'CREV' ])
95
                        if (stec55x[m]) armed = m;
fix roll mode determination
Sébastien MARQUE authored on 2020-05-11
96
                    if (stec55x.roll.getValue() == 0) armed = 'HDG';
97
                    elsif (stec55x.roll.getValue() == 2) armed = 'GPS';
98
                    elsif (stec55x.APR_annun.getValue()) armed = 'APR';
autopilot status with separa...
Sébastien MARQUE authored on 2020-05-08
99
                    se['LATMOD-Armed-text']
100
                        .setVisible(size(armed))
101
                        .setText(armed);
102
                }
103
                else {
104
                    se['LATMOD-Active-text'].setVisible(0);
105
                    se['LATMOD-Armed-text'].setVisible(0);
autopilot S-TEC 55X integrat...
Sébastien MARQUE authored on 2020-05-06
106
                }
107

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