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
/* 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;
46
                /* CIF NEXTSTATE (2810, 438), (74, 35) */
Maxime Perrotin's avatar
Maxime Perrotin committed
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
                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):
63
                        /* CIF task (3138, 410), (161, 120) */
Maxime Perrotin's avatar
Maxime Perrotin committed
64
65
66
67
68
69
70
71
72
73
74
75
                        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;
76
    /* CIF state (1717, 76), (74, 35) */
Maxime Perrotin's avatar
Maxime Perrotin committed
77
    state Stopped;
78
        /* CIF input (1277, 131), (196, 35) */
Maxime Perrotin's avatar
Maxime Perrotin committed
79
80
81
        input Floor_Command (floor_cmd)
        /* CIF comment (1495, 131), (270, 32) */
        comment 'Someone at floor F pressed UP or DOWN';
82
            /* CIF decision (1208, 186), (336, 56) */
Maxime Perrotin's avatar
Maxime Perrotin committed
83
84
85
86
            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';
87
                /* CIF ANSWER (1139, 262), (70, 24) */
Maxime Perrotin's avatar
Maxime Perrotin committed
88
                (true):
89
                    /* CIF NEXTSTATE (1137, 306), (74, 35) */
Maxime Perrotin's avatar
Maxime Perrotin committed
90
91
92
                    NEXTSTATE Stopped;
                /* CIF ANSWER (1547, 262), (70, 24) */
                (false):
93
94
                    /* CIF task (1443, 306), (276, 35) */
                    task target_pos := float (num(floor_cmd.floor));
Maxime Perrotin's avatar
Maxime Perrotin committed
95
96
                    /* CIF decision (1506, 356), (151, 50) */
                    decision round(sensors.pos_x);
97
98
99
                        /* CIF ANSWER (1221, 426), (201, 24) */
                        (= float(num(floor_cmd.floor))):
                            /* CIF task (1240, 470), (163, 24) */
Maxime Perrotin's avatar
Maxime Perrotin committed
100
101
102
103
                            task cmd.door := door_open
                            /* CIF comment (1425, 464), (138, 40) */
                            comment 'Lift is there
Just open the door';
104
                            /* CIF task (1254, 514), (134, 35) */
Maxime Perrotin's avatar
Maxime Perrotin committed
105
                            task door := door_open;
106
                            /* CIF NEXTSTATE (1284, 564), (74, 35) */
Maxime Perrotin's avatar
Maxime Perrotin committed
107
                            NEXTSTATE Stopped;
108
                        /* CIF ANSWER (1675, 426), (54, 40) */
Maxime Perrotin's avatar
Maxime Perrotin committed
109
                        ELSE:
110
                            /* CIF task (1635, 486), (134, 35) */
Maxime Perrotin's avatar
Maxime Perrotin committed
111
                            task door := door_close;
112
                            /* CIF join (1685, 541), (35, 35) */
Maxime Perrotin's avatar
Maxime Perrotin committed
113
114
115
                            join move;
                    enddecision;
            enddecision;
116
        /* CIF input (2006, 132), (200, 35) */
Maxime Perrotin's avatar
Maxime Perrotin committed
117
118
119
120
121
        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';
122
            /* CIF decision (2034, 187), (145, 50) */
Maxime Perrotin's avatar
Maxime Perrotin committed
123
124
125
126
127
            decision present(cabin_cmd);
                /* CIF ANSWER (1975, 257), (70, 24) */
                (floor):
                    /* CIF decision (1896, 301), (227, 71) */
                    decision round(sensors.pos_x)
128
 = float(num(cabin_cmd.floor));
Maxime Perrotin's avatar
Maxime Perrotin committed
129
130
131
132
133
134
135
136
137
                        /* 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;
138
                            /* CIF NEXTSTATE (1866, 534), (74, 35) */
Maxime Perrotin's avatar
Maxime Perrotin committed
139
140
141
142
143
                            NEXTSTATE Stopped;
                        /* CIF ANSWER (2267, 396), (70, 24) */
                        (false):
                            /* CIF task (2234, 440), (134, 35) */
                            task door := door_close;
144
145
                            /* CIF task (2162, 490), (279, 35) */
                            task target_pos := float (num(cabin_cmd.floor));
Maxime Perrotin's avatar
Maxime Perrotin committed
146
147
148
                            /* CIF join (2284, 545), (35, 35) */
                            join move;
                    enddecision;
149
                /* CIF ANSWER (2454, 257), (123, 24) */
Maxime Perrotin's avatar
Maxime Perrotin committed
150
                (emergency_stop):
151
                    /* CIF task (2451, 301), (129, 43) */
Maxime Perrotin's avatar
Maxime Perrotin committed
152
153
                    task cmd .motor := off,
cmd.brake   := on;
154
                    /* CIF NEXTSTATE (2479, 364), (74, 35) */
Maxime Perrotin's avatar
Maxime Perrotin committed
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
                    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;
176
                /* CIF ANSWER (921, 426), (94, 24) */
Maxime Perrotin's avatar
Maxime Perrotin committed
177
                (nb_of_cycle):
178
                    /* CIF task (881, 470), (175, 40) */
Maxime Perrotin's avatar
Maxime Perrotin committed
179
180
                    task counter := nb_of_cycle :
counter.nb_of_cycle - 1;
181
                    /* CIF decision (886, 530), (165, 50) */
Maxime Perrotin's avatar
Maxime Perrotin committed
182
183
184
185
186
187
188
189
190
191
192
193
                    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;
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
    /* CIF state (3593, 92), (70, 35) */
    state Moving;
        /* CIF input (3594, 147), (67, 35) */
        input Pulse;
            /* CIF PROCEDURECALL (3572, 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 (3559, 317), (135, 40) */
            output Housekeeping (hk);
            /* CIF decision (3533, 377), (189, 50) */
            decision present(counter);
                /* CIF ANSWER (3500, 447), (68, 24) */
                (forever):
                    /* CIF join (3517, 491), (35, 35) */
                    join move;
                /* CIF ANSWER (3668, 447), (94, 24) */
                (nb_of_cycle):
                    /* CIF task (3628, 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 (3650, 665), (35, 35) */
                            join move;
                        /* CIF ANSWER (3723, 621), (70, 24) */
                        (false):
                            /* CIF NEXTSTATE (3712, 665), (90, 35) */
                            NEXTSTATE Power_Off;
                    enddecision;
            enddecision;
    endstate;
    /* CIF state (316, 394), (91, 56) */
Maxime Perrotin's avatar
Maxime Perrotin committed
233
234
235
    state Power_Off,
Stopped,
Moving;
236
        /* CIF input (151, 470), (122, 40) */
Maxime Perrotin's avatar
Maxime Perrotin committed
237
238
        input Start_Controller
(counter);
239
            /* CIF decision (148, 530), (128, 50) */
Maxime Perrotin's avatar
Maxime Perrotin committed
240
241
242
            decision present(counter);
                /* CIF ANSWER (98, 600), (73, 24) */
                (forever):
243
                    /* CIF decision (75, 644), (118, 50) */
Maxime Perrotin's avatar
Maxime Perrotin committed
244
245
246
247
248
249
250
251
252
253
254
                    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):
255
                                    /* CIF NEXTSTATE (98, 872), (74, 35) */
Maxime Perrotin's avatar
Maxime Perrotin committed
256
257
258
259
                                    NEXTSTATE Stopped;
                            enddecision;
                        /* CIF ANSWER (191, 714), (70, 24) */
                        (false):
260
                            /* CIF NEXTSTATE (180, 758), (90, 35) */
Maxime Perrotin's avatar
Maxime Perrotin committed
261
262
                            NEXTSTATE Power_Off;
                    enddecision;
263
                /* CIF ANSWER (311, 600), (94, 24) */
Maxime Perrotin's avatar
Maxime Perrotin committed
264
                (nb_of_cycle):
265
                    /* CIF decision (313, 644), (90, 50) */
Maxime Perrotin's avatar
Maxime Perrotin committed
266
267
268
269
270
271
272
                    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):
273
                            /* CIF NEXTSTATE (368, 758), (74, 35) */
Maxime Perrotin's avatar
Maxime Perrotin committed
274
275
276
                            NEXTSTATE Stopped;
                    enddecision;
            enddecision;
277
        /* CIF input (452, 470), (119, 40) */
Maxime Perrotin's avatar
Maxime Perrotin committed
278
279
        input Manual_Control
(cmd);
280
            /* CIF NEXTSTATE (477, 530), (70, 35) */
Maxime Perrotin's avatar
Maxime Perrotin committed
281
282
283
            NEXTSTATE -;
    endstate;
endprocess Controller;