zkv1000 / Nasal / afcs.nas /
Newer Older
192 lines | 8.115kb
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;
delete unused afcs systems
Sébastien MARQUE authored on 2020-05-16
42
        # delete unused systems
43
        foreach (var e; keys(m.systems))
44
            if (e != m.system)
45
                delete(m.systems, e);
autopilot status with separa...
Sébastien MARQUE authored on 2020-05-08
46

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

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

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