Behavioral Modeling - Power Window
- Feature modeling
- Component and statemachine modeling
- Variability in behavior using inheritance
- Variability in behaviour using strategy pattern
- Scenarios and properties
- Checking the properties
- It must be impossible for the user to request opening and the window remains closed
- It
must be impossible for the window to be
closedand continue sendingmotorUpcommand - The
window must never continue
movingUpafter an object was detected - An example positive scenario
- It must be possible to go from closed to open via partiallyOpen state
This example demonstrates modeling both structure and behaviour with variability.
Feature modeling
We model features as final, that is, we do not allow dynamic reconfiguration. Feature configuration from the first snapshot remains unchanged for the entire trace.
Metamodel
Model
The optional feature express indicates the functionality
of automatically closing the window. The feature
pinchProtection indicates the functionality of detecting
obstacles and stopping the window.
Component and statemachine modeling
Metamodel
Simple component modeling. Nesting the Port under
Component ensures that all ports are always children of
components. The components are final because we do not allow dynamic
reconfiguration; however, the ports are not final: a port instance can
appear to point to a value, disappear, and a new instance can appear to
point to a different value.
Inside the components, we will embed statemachines modeling their behavior. The states are not final because we want to allow state changes.
Model
Commands received by the window motor.
Window motor. The port cmd is mandatory, meaning that
the motor must always be given a command.
Requests from the user. Observe, that the request
expressUp is optional.
The user request expressUp is only available when the
feature express is present (alphabet variability).
The component pinchDetector of each
WinController is only required if the feature
pinchProtection is present.
Instances of the ports endOfTravel and
objectDetected appear when the corresponding binary signal
is received. On the other hand, instances of the port req
point to a specific user request. No instance of the port
req indicates no user request. Finally, we allow at most
one of req, endOfTravel, and
objectDetected in order to remove non-determinism. After an
expressUp, the user does not need to hold the button: the
window keeps moving up on its own.
We model state actions by fixing the motor command. E.g., in state
movingDown, motor command is fixed to
motorDown.
State transitions are modeled using “next transitions”:
-->. In the state movingUp we demonstrate
“guarded next transition”:
movingUpX -[objectDetected]-> stopped.partlyOpen.
A transition lasts as long as the parent of the state it is in. A
transition that leaves its parent state is therefore a constraint of
that parent: e.g.,
closed && req=down --> movingDown is a
constraint of stopped, not of closed. Written
in closed, it would lapse together with
stopped, and it would only force the window to leave
stopped, to any state.
A transition only says what happens when its trigger occurs; it does
not keep the state from changing otherwise. Therefore, each state also
says that it lasts when none of its triggers occurs, e.g.,
!(req=up || endOfTravel || req=stop) --> movingDown. The
substates last as long as their parent: this --> closed
lapses when the window leaves stopped.
Disabling
objectDetected port
Without the feature pinchProtection, the port
objectDetected should be inactive. Having the feature will
allow receiving the signal objectDetected.
Variability in behavior using inheritance
Two kinds of window controllers. They are abstract: a concrete
controller is one of them, e.g., wc : WinCtrWithChime
instead of wc : WinController below. A model with several
concrete controllers is solved for all of them together, which takes
much longer.
With continuous chime
With intermittent chime
Variability in behaviour using strategy pattern
We first define an abstract chiming strategy: chiming can be
audible but only if active (expressed by
nesting).
Concrete strategies:
Now we can parametrize the controller with a chiming strategy. Chiming should be active when moving up in express mode. The chime should be emitted only when the chiming is audible.
A concrete controller chooses its chiming strategy with a constraint, e.g.:
wc : WinControllerStrategies
[ strategy = Intermittent ]
Scenarios and properties
We define a concrete window controller wc. A property is
an assertion: it must hold in every trace of wc, and the
command check looks for a counterexample within the scopes
and the maximum trace length. A scenario is a constraint on the trace of
wc, anchored to the start of the trace with
initially: it is possible when the model has a trace with
it.
Checking the properties
A counterexample is found quickly, but a property that holds must be
checked on every trace up to the maximum trace length, which takes long.
The window reaches each of its states within two steps from the start,
and each property below is about a state and the next one. Therefore,
check them with a shorter trace: the command tl 4 and then
check. The times of check in claferIG for each
property, one after another:
| Property | tl 3 |
tl 4 |
tl 5 |
tl 10 (default) |
|---|---|---|---|---|
The request down leaves closed |
holds, 19 s | holds, 42 s | holds, 81 s | holds, 7 min |
No motorUp when closed |
holds, 4 s | holds, 8 s | holds, 13 s | holds, 68 s |
| Stops moving up after an object | counterexample, 2 s | counterexample, 1 s | counterexample, 1 s | counterexample, 1 s |
| Stops moving up in express mode after an object | holds, 6 s | holds, 14 s | holds, 28 s | holds, 141 s |
All four (check) |
31 s | 65 s | 123 s | 10.5 min |
The results are the same for all the trace lengths. With
tl 10, the counterexample still comes in a second, but
proving the three properties that hold takes ten minutes, most of it for
the first one. A property that holds is proven only for the traces up to
the maximum trace length and within the scopes.
It must be impossible for the user to request opening and the window remains closed
A transition holds trivially in a state where its source does not, so
never (wc.req = down --> wc.WinStates.stopped.closed)
would not say this. Instead, the request in the state
closed leads to another state.
It
must be impossible for the window to be closed and continue
sending motorUp command
It is a safety property to prevent burning the motor.
The
window must never continue movingUp after an object was
detected
It is a safety property to prevent injury.
This property has a counterexample: the window keeps moving up in
basic, while the user holds the button, with an object
detected. Only the express mode movingUpX is protected,
which the following property states. It has no counterexample.
An example positive scenario
All the Clafer code on a page forms one model. Therefore, the
scenarios are not part of the model of this page. To try one, open the
model in the IDE and add it under wc.
The window opens, the user reverses it, moves it up in express mode, and an object stops it. The scenario states its first state, since a chain is an implication from its first state, which holds trivially when the trace starts elsewhere.
[ initially (WinStates.stopped.closed && req=down) ]
[ initially (WinStates.stopped.closed && req=down --> WinStates.movingDown -->> req=up
--> WinStates.movingUp.basic && req=expressUp --> WinStates.movingUp.movingUpX -->> objectDetected
--> WinStates.stopped.partlyOpen) ]
It must be possible to go from closed to open via partiallyOpen state
The window moves down between the states in which it is stopped.
[ initially WinStates.stopped.closed ]
[ initially (WinStates.stopped.closed -->> WinStates.movingDown -->> WinStates.stopped.partlyOpen
-->> WinStates.movingDown -->> WinStates.stopped.open) ]
