controller.pr 11.5 KB
Newer Older
Maxime Perrotin's avatar
Maxime Perrotin committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
/* CIF PROCESS (250, 150), (150, 75) */
process Controller;
    /* CIF TEXT (0, 100), (278, 184) */
    dcl cmd                  Lift_control,
           counter           Start_condition,
           sensors            Lift_sensor,
           door                 OpenClose := door_close,
           floor_cmd       Floor_button,
           cabin_cmd      Cabin_button,
           target_pos      Position;
    
    dcl hk Status;
    /* CIF ENDTEXT */
    /* CIF START (456, 71), (70, 35) */
    START;
        /* CIF task (385, 126), (212, 184) */
        task sensors.pos_x  := 60.0,

cmd := {
   direction down,
   motor       off,
   door          door_close,
   brake        on
},

counter             := forever : false
        /* CIF comment (617, 200), (145, 35) */
        comment 'Set initial conditions';
        /* CIF NEXTSTATE (445, 341), (90, 35) */
        NEXTSTATE Power_Off;
    /* CIF label (2921, 85), (102, 57) */
    connection move:
        /* CIF decision (2859, 159), (226, 75) */
        decision target_pos =
 round (sensors.pos_x);
            /* CIF ANSWER (2813, 254), (70, 24) */
            (true):
                /* CIF task (2767, 298), (161, 120) */
                task cmd := {
   direction up,
   motor       off,
   door          door_open,
   brake        on
},
door := door_open;
                /* CIF NEXTSTATE (2811, 438), (74, 35) */
                NEXTSTATE Stopped;
            /* CIF ANSWER (3104, 254), (70, 24) */
            (false):
                /* CIF decision (3045, 298), (186, 48) */
                decision target_pos > sensors.pos_x;
                    /* CIF ANSWER (3013, 366), (70, 24) */
                    (true):
                        /* CIF task (2967, 410), (161, 120) */
                        task cmd := {
   direction up,
   motor       on,
   door          door_close,
   brake        off
};
                    /* CIF ANSWER (3184, 366), (70, 24) */
                    (false):
                        /* CIF task (3139, 410), (161, 120) */
                        task cmd := {
   direction down,
   motor       on,
   door          door_close,
   brake        off
};
                enddecision;
                /* CIF NEXTSTATE (3104, 545), (70, 35) */
                NEXTSTATE Moving;
        enddecision;
    /* CIF End Label */
    endconnection;
    /* CIF state (1718, 76), (74, 35) */
    state Stopped;
        /* CIF input (1278, 131), (196, 35) */
        input Floor_Command (floor_cmd)
        /* CIF comment (1495, 131), (270, 32) */
        comment 'Someone at floor F pressed UP or DOWN';
            /* CIF decision (1209, 186), (336, 56) */
            decision floor_cmd = { direction up, floor floor_5 }
or floor_cmd = { direction down, floor floor_0 }
            /* CIF comment (1565, 196), (204, 35) */
            comment 'Discard impossible commands';
                /* CIF ANSWER (1157, 262), (70, 24) */
                (true):
                    /* CIF NEXTSTATE (1155, 306), (74, 35) */
                    NEXTSTATE Stopped;
                /* CIF ANSWER (1547, 262), (70, 24) */
                (false):
                    /* CIF task (1461, 306), (241, 35) */
                    task target_pos := float (floor_cmd.floor);
                    /* CIF decision (1506, 356), (151, 50) */
                    decision round(sensors.pos_x);
                        /* CIF ANSWER (1239, 426), (166, 24) */
                        (= float(floor_cmd.floor)):
                            /* CIF task (1241, 470), (163, 24) */
                            task cmd.door := door_open
                            /* CIF comment (1425, 464), (138, 40) */
                            comment 'Lift is there
Just open the door';
                            /* CIF task (1255, 514), (134, 35) */
                            task door := door_open;
                            /* CIF NEXTSTATE (1285, 564), (74, 35) */
                            NEXTSTATE Stopped;
                        /* CIF ANSWER (1676, 426), (54, 40) */
                        ELSE:
                            /* CIF task (1636, 486), (134, 35) */
                            task door := door_close;
                            /* CIF join (1686, 541), (35, 35) */
                            join move;
                    enddecision;
            enddecision;
        /* CIF input (2007, 132), (200, 35) */
        input Cabin_Command (cabin_cmd)
        /* CIF comment (2230, 132), (239, 56) */
        comment 'Someone selected a target floor
from inside the cabin, or someone
pressed the emergency stop button';
            /* CIF decision (2035, 187), (145, 50) */
            decision present(cabin_cmd);
                /* CIF ANSWER (1975, 257), (70, 24) */
                (floor):
                    /* CIF decision (1896, 301), (227, 71) */
                    decision round(sensors.pos_x)
 = float(cabin_cmd.floor);
                        /* CIF ANSWER (1869, 396), (70, 24) */
                        (true):
                            /* CIF task (1822, 435), (163, 24) */
                            task cmd.door := door_open
                            /* CIF comment (1999, 429), (138, 40) */
                            comment 'Lift is there
Just open the door';
                            /* CIF task (1836, 479), (134, 35) */
                            task door := door_open;
                            /* CIF NEXTSTATE (1867, 534), (74, 35) */
                            NEXTSTATE Stopped;
                        /* CIF ANSWER (2267, 396), (70, 24) */
                        (false):
                            /* CIF task (2234, 440), (134, 35) */
                            task door := door_close;
                            /* CIF task (2180, 490), (243, 35) */
                            task target_pos := float (cabin_cmd.floor);
                            /* CIF join (2284, 545), (35, 35) */
                            join move;
                    enddecision;
                /* CIF ANSWER (2437, 257), (123, 24) */
                (emergency_stop):
                    /* CIF task (2434, 301), (129, 43) */
                    task cmd .motor := off,
cmd.brake   := on;
                    /* CIF NEXTSTATE (2461, 364), (74, 35) */
                    NEXTSTATE Stopped;
            enddecision;
        /* CIF input (846, 131), (70, 35) */
        input Pulse;
            /* CIF PROCEDURECALL (826, 186), (109, 40) */
            call Operate_Lift
(cmd, sensors)
            /* CIF comment (943, 182), (166, 56) */
            comment 'Call the Simulink
 model with the current
command';
            /* CIF task (782, 246), (197, 35) */
            task hk := {lift sensors, door door};
            /* CIF output (813, 296), (135, 40) */
            output Housekeeping (hk);
            /* CIF decision (786, 356), (189, 50) */
            decision present(counter);
                /* CIF ANSWER (753, 426), (70, 24) */
                (forever):
                    /* CIF NEXTSTATE (750, 470), (74, 35) */
                    NEXTSTATE Stopped;
                /* CIF ANSWER (922, 426), (94, 24) */
                (nb_of_cycle):
                    /* CIF task (882, 470), (175, 40) */
                    task counter := nb_of_cycle :
counter.nb_of_cycle - 1;
                    /* CIF decision (887, 530), (165, 50) */
                    decision counter.nb_of_cycle > 0;
                        /* CIF ANSWER (891, 600), (70, 24) */
                        (true):
                            /* CIF NEXTSTATE (888, 644), (74, 35) */
                            NEXTSTATE Stopped;
                        /* CIF ANSWER (981, 600), (70, 24) */
                        (false):
                            /* CIF NEXTSTATE (970, 644), (90, 35) */
                            NEXTSTATE Power_Off;
                    enddecision;
            enddecision;
    endstate;
    /* CIF state (317, 394), (91, 56) */
    state Power_Off,
Stopped,
Moving;
        /* CIF input (152, 470), (122, 40) */
        input Start_Controller
(counter);
            /* CIF decision (149, 530), (128, 50) */
            decision present(counter);
                /* CIF ANSWER (98, 600), (73, 24) */
                (forever):
                    /* CIF decision (76, 644), (118, 50) */
                    decision counter.forever;
                        /* CIF ANSWER (56, 714), (70, 24) */
                        (true):
                            /* CIF decision (45, 758), (90, 50) */
                            decision cmd.motor;
                                /* CIF ANSWER (11, 828), (70, 24) */
                                (on):
                                    /* CIF NEXTSTATE (11, 872), (70, 35) */
                                    NEXTSTATE Moving;
                                /* CIF ANSWER (101, 828), (70, 24) */
                                (off):
                                    /* CIF NEXTSTATE (99, 872), (74, 35) */
                                    NEXTSTATE Stopped;
                            enddecision;
                        /* CIF ANSWER (191, 714), (70, 24) */
                        (false):
                            /* CIF NEXTSTATE (181, 758), (90, 35) */
                            NEXTSTATE Power_Off;
                    enddecision;
                /* CIF ANSWER (312, 600), (94, 24) */
                (nb_of_cycle):
                    /* CIF decision (314, 644), (90, 50) */
                    decision cmd.motor;
                        /* CIF ANSWER (281, 714), (70, 24) */
                        (on):
                            /* CIF NEXTSTATE (281, 758), (70, 35) */
                            NEXTSTATE Moving;
                        /* CIF ANSWER (371, 714), (70, 24) */
                        (off):
                            /* CIF NEXTSTATE (369, 758), (74, 35) */
                            NEXTSTATE Stopped;
                    enddecision;
            enddecision;
        /* CIF input (453, 470), (119, 40) */
        input Manual_Control
(cmd);
            /* CIF NEXTSTATE (478, 530), (70, 35) */
            NEXTSTATE -;
    endstate;
    /* CIF state (3593, 92), (70, 35) */
    state Moving;
        /* CIF input (3594, 147), (67, 35) */
        input Pulse;
            /* CIF PROCEDURECALL (3573, 202), (109, 40) */
            call Operate_Lift
(cmd, sensors)
            /* CIF comment (3691, 198), (123, 40) */
            comment 'Call the Simulink
 model';
            /* CIF task (3529, 262), (197, 35) */
            task hk := {lift sensors, door door};
            /* CIF output (3560, 317), (135, 40) */
            output Housekeeping (hk);
            /* CIF decision (3533, 377), (189, 50) */
            decision present(counter);
                /* CIF ANSWER (3501, 447), (68, 24) */
                (forever):
                    /* CIF join (3518, 491), (35, 35) */
                    join move;
                /* CIF ANSWER (3669, 447), (94, 24) */
                (nb_of_cycle):
                    /* CIF task (3629, 491), (175, 40) */
                    task counter := nb_of_cycle :
counter.nb_of_cycle - 1;
                    /* CIF decision (3633, 551), (165, 50) */
                    decision counter.nb_of_cycle > 0;
                        /* CIF ANSWER (3633, 621), (70, 24) */
                        (true):
                            /* CIF join (3651, 665), (35, 35) */
                            join move;
                        /* CIF ANSWER (3723, 621), (70, 24) */
                        (false):
                            /* CIF NEXTSTATE (3713, 665), (90, 35) */
                            NEXTSTATE Power_Off;
                    enddecision;
            enddecision;
    endstate;
endprocess Controller;