Project

General

Profile

Download (8.86 KB) Statistics
| Branch: | Tag: | Revision:
1

    
2
--==================
3
-- Simple Elevator 
4
--==================
5

    
6
(*
7
Acknowledgements: This example is inspired by a similar one first made 
8
by Prover Technology AB, then adapted at Chalmers University 
9
by Carl Johan Lillieroth, K.V.S. Prasad, Mary Sheeran, Angela Wallenburg, 
10
and Jan-Willem Roorda. 
11

    
12
-------
13
Setting
14
-------
15

    
16
It models a simple elevator, moving people between two floors. 
17
In the elevator, there are three buttons: 
18
- a button 1 to go to the first floor, 
19
- a button 2 to go to the first floor, and 
20
- a stop switch to stop the elevator. 
21
On each floor, there is a button to call the elevator. 
22

    
23
The elevator has three sensors, 
24
- the first indicating if the elevator is on the first floor or not, 
25
- the second doing the same for the second floor, and 
26
- the third indicating if the elevator's door is closed or not.
27

    
28
The stop switch is located within the elevator and can be pressed to 
29
block the elevator. While the switch is on the elevator stops immediately 
30
if it was moving and ignores any other input. Turning the switch back off 
31
makes the elevator to be responsive again to other inputs.
32

    
33
The elevator is moved up and down by a motor that is on the roof of the 
34
building. The motor is controlled by two signals, 
35
- one for moving the elevator up and 
36
- one for moving it down.
37

    
38
The control system looks at the buttons that are being pressed and the sensors 
39
that say where the elevator is and if the door is open, and then decides if 
40
the motor should move the elevator up or down, or do nothing.
41

    
42
For simplicity, we do not distinguish between the case of someone on floor 1 
43
(resp., 2) pressing the call button and someone in the elevator pressing 
44
the button 1 (resp., 2). 
45

    
46
-------------------
47
Safety Requirements
48
-------------------
49

    
50
The controller is supposed to satisfy the following safety requirements:
51

    
52
R1  The elevator moves only when the door is closed and the stop switch 
53
    is not on.
54
R2  The elevator may not pass the end positions, that is, go through 
55
    the roof or the floor.
56
R3  A moving elevator halts only if the stop switch is on, or the door 
57
    is opened, or the elevator has arrived at the destination floor.
58
R4  The elevator halts before changing direction.
59
R5  The signals sent to the motor are not contradictory.
60
R6  The elevator starts moving when it should. 
61
R7  The elevator stays on a floor indefinitely as long as
62
    there is no call the other floor
63
*)
64

    
65
-------------------------
66
-- Auxiliary operators --
67
-------------------------
68

    
69
node Happened(X : bool) returns (Y : bool);
70
let
71
  Y = X or (false -> pre Y) ;
72
tel
73

    
74
node Since( X, Y : bool ) returns ( Z : bool );
75
let
76
  Z =  X or (Y and (false -> pre Z));
77
tel
78

    
79
node SinceIncl( X, Y : bool ) returns ( Z : bool );
80
let
81
  Z =  Y and (X or (false -> pre Z));
82
tel
83

    
84
node ToInt(X: bool) returns (N: int);
85
let
86
  N = if X then 1 else 0;
87
tel
88

    
89
node MutuallyExcl_4(X1, X2, X3, X4: bool) returns (Y: bool);
90
let
91
  Y = ToInt(X1) + ToInt(X2) + ToInt(X3) + ToInt(X4) < 2 ;
92
tel
93

    
94

    
95
---------------------------------
96
-- Controller high-level specs --
97
---------------------------------
98

    
99
contract ControlReq( Floor_1, Floor_2, DoorOpen, Call_1, Call_2, Stop : bool )
100
returns ( MotorUp, MotorDown : bool);
101
let
102
 
103
  -------------------------------
104
  -- Environmental assumptions --
105
  -------------------------------
106
  -- the elevator starts on the first floor
107
  assume Floor_1 -> true; 
108

    
109
  -- if the elevator was on the first (second) floor and did not move up (down)
110
  -- then it is still on that floor
111
  assume true -> pre (Floor_1 and not MotorUp and not MotorDown) => Floor_1 ; 
112
  assume true -> pre (Floor_2 and not MotorUp and not MotorDown) => Floor_2 ;
113
 (*
114
  -- if the elevator was on the first (second) floor and moved up (down)
115
  -- then it has left that floor
116
  assume true -> pre (Floor_1 and MotorUp) => not Floor_1 ;
117
  assume true -> pre (Floor_2 and MotorDown) => not Floor_2 ;
118
 *)
119
 
120
  -----------
121
  -- Modes --
122
  -----------
123
  mode blocked (
124
    require Stop or DoorOpen ;
125
    ensure not MotorUp ;
126
    ensure not MotorDown ;
127
  );
128
  
129
  mode servicing1 (
130
    require SinceIncl(Call_1, not ::blocked and not Floor_1  
131
                              and not (false -> pre MotorUp) 
132
                              ) ;
133
    ensure MotorDown ;
134
    ensure not MotorUp ;
135
  ) ;
136
  
137
  mode servicing2 (
138
    require SinceIncl(Call_2, not ::servicing1  
139
                              and not ::blocked and not Floor_2  
140
                              and not (false -> pre MotorDown) 
141
                              ) ;
142
    ensure MotorUp ;
143
    ensure not MotorDown ;
144
  ) ;
145

    
146
 mode waiting (
147
    require not ::blocked ;
148
    require not ::servicing1 ;
149
    require not ::servicing2 ;
150
    ensure not MotorUp ;
151
    ensure not MotorDown ;
152
  ) ;
153

    
154

    
155
  -------------------------
156
  -- Auxiliary variables --
157
  -------------------------
158
  
159
  -- Moving is true iff the elevator is moving now
160
  var Moving: bool = MotorUp or MotorDown ;
161
  
162
  -- Halts is true iff the elevator has come to a stop
163
  var Halts: bool = not Moving and (false -> pre Moving);
164

    
165
  -- The elevator can move now iff 
166
  --   the Stop button is not pressed and
167
  --   the door is not closed
168
  var CanMove: bool = not Stop and not DoorOpen;
169
  
170
  -- The elevator should start moving iff 
171
  --   it was not moving before
172
  --   it can move,
173
  --   there is a call to go to a floor, and
174
  --   the elevator is not a that floor
175
    var ShouldMove: bool = (true -> not pre Moving) 
176
                           and CanMove
177
                           and ((Call_1 and not Floor_1) or
178
                                (Call_2 and not Floor_2)) ;
179

    
180
  ----------------
181
  -- Guarantees --
182
  ----------------
183
  -- the execution modes are mutually exclusive  
184
  guarantee MutuallyExcl_4(::blocked, ::servicing1, ::servicing2, ::waiting) ;
185

    
186
  -- R1: The elevator moves only when the door is closed and
187
  --     the Stop button is not pressed
188
  guarantee Moving => not DoorOpen and not Stop;
189

    
190
  -- R2: The elevator will not pass the end positions, that is,
191
  --     go through the roof or the floor.
192
  guarantee (Floor_1 => not MotorDown) ; 
193
  guarantee (Floor_2 => not MotorUp) ;
194

    
195
  -- R3: A moving elevator halts only if
196
  --     the Stop button is pressed, or the door is open, or
197
  --     the elevator has arrived at the destination floor
198
  guarantee Halts => ( Stop 
199
                       or DoorOpen
200
                       or ((true -> pre MotorDown) and Floor_1)
201
                       or ((true -> pre MotorUp) and Floor_2)
202
                       ) ;
203

    
204
  -- R4: he elevator halts before changing direction
205
  guarantee true -> (     not (pre MotorDown and MotorUp)  
206
                      and not (pre MotorUp and MotorDown)
207
                      ) ;
208

    
209
  -- R5: The signals sent to the motor are not contradictory
210
  guarantee not (MotorUp and MotorDown) ;
211

    
212
  -- R6: The elevator starts moving when it should
213
  guarantee ShouldMove => Moving ;
214
 
215
  -- R7: The elevator stays on a floor indefinitely as long as
216
  --     there is no call the other floor
217
  guarantee Since(Floor_1, not Happened(Call_2)) => Floor_1 ;
218
  guarantee Since(Floor_2, not Happened(Call_1)) => Floor_2 ;
219
  
220
 tel
221

    
222

    
223
--------------------------------
224
-- Controller low-level specs --
225
--------------------------------
226

    
227
node Control( Floor_1, Floor_2, DoorOpen, Call_1, Call_2, Stop : bool )
228
returns ( MotorUp, MotorDown : bool) ;
229
(*@ contract import
230
  ControlReq( Floor_1, Floor_2, DoorOpen, Call_1, Call_2, Stop )
231
  returns ( MotorUp, MotorDown ) ;
232
*)
233
var CanMove : bool ;
234
let
235
  CanMove =  not Stop and not DoorOpen ;
236

    
237
(*
238
  The elevator goes down iff all the following hold:
239
  1) there is a call to the first floor or it was already going down
240
  2) it can move
241
  3) it is not on the first floor already
242
  4) it was not going up
243
*)
244
  MotorDown =  (Call_1 or (false -> pre MotorDown)) 
245
               and CanMove 
246
               and not Floor_1
247
               and not (false -> pre MotorUp) ;
248

    
249
(*
250
  The elevator goes up iff all the following hold:
251
  0) it is not going down (i.e., going down takes precedence over going up)
252
  1) there is a call to the second floor or it was already going up
253
  2) it can move
254
  3) it is not on the second floor already
255
  4) it was not going down
256
*)
257
  MotorUp =  not MotorDown 
258
             and (Call_2 or (false -> pre MotorUp))
259
             and CanMove 
260
             and not Floor_2
261
             and not (false -> pre MotorDown) ;
262

    
263
  --%MAIN;
264
tel
265

    
266

    
267

    
268
-- To simulate the elevator system make this the main file first
269

    
270
-- The simulator assumes (for brevity) that it takes 5 execution steps 
271
-- to go from one floor to the other, each corresponding to an intermediate
272
-- "level". Level 0 corresponds to the first floor, level 4 to the second 
273
node Simulator( Call_1, Call_2, Stop, DoorOpen : bool )
274
returns ( Floor_1, Floor_2 : bool ) ;
275
var MotorUp, MotorDown: bool ;
276
    L: int ;
277
let
278
  L = 0 -> if pre MotorUp then pre L + 1
279
           else if pre MotorDown then pre L - 1
280
           else pre L ;
281
  Floor_1 =  L = 0 ;
282
  Floor_2 =  L = 4 ;
283
  
284
  (MotorUp, MotorDown) = Control(Floor_1, Floor_2, DoorOpen, Call_1, Call_2, Stop) ;
285
  -- %MAIN;
286
 tel
287

    
288

    
289

    
290

    
(1-1/6)