Exercise 1 of 10
What stands after accept in this transition?
item def PowerOn;
state def MachineStates {
state off;
state heatingUp;
transition first off accept PowerOn then heatingUp;
}Learn how SysML v2 describes how a system reacts to events: state def and state, transitions with transition, accept and then, the initial state with entry, and entry, do and exit on a state. With exercises, for beginners and SysML v1 users.
The actions from lesson 6 describe a flow that runs once from start to end. A coffee machine does not always do the same, though: it is off, heats up, is ready or brews, and what it does next depends on what happens. For that SysML v2 has states and transitions. The example is the state machine of the invented coffee machine.
A state def defines a state machine, just as part def defines a kind of part. The states stand inside it as state. The machine has four: off, heating up, ready, brewing.
At first they are only names. What connects them comes in the next section.
// Excerpt of the coffee machine model
state def MachineStates {
state off;
state heatingUp;
state ready;
state brewing;
}A transition changes from one state to another. transition first off accept PowerOn then heatingUp; means: in the state off the machine changes to heatingUp as soon as PowerOn arrives. The accept names the triggering event by its type. PowerOn is an ordinary definition, here an item def, like the items from lesson 4.
Without accept, the transition has no trigger from outside: it fires as soon as the actions of its source state are done. brewed in the model below is an example; it fires when pour ends. You can give a transition a name, like powerOn here, between transition and first.
entry; then off; sets the start: the machine begins in the state off.
// Excerpt of the coffee machine model
item def PowerOn;
item def TemperatureReached;
state def MachineStates {
entry; then off;
state off;
state heatingUp;
state ready;
transition powerOn first off accept PowerOn then heatingUp;
transition warmedUp first heatingUp accept TemperatureReached then ready;
}Actions that you know from lesson 6 can hang on a state. With entry an action runs when the state is entered, with exit when it is left, with do while the machine is in the state.
The machine heats as long as it is in the state heatingUp. entry switches the heating on, exit switches it off again. While brewing, the action pour runs the whole time.
// Excerpt of the coffee machine model
state def MachineStates {
state heatingUp {
entry action heat : HeatWater;
exit action stop : StopHeating;
}
state brewing {
do action pour : Pour;
}
}The state def is a definition. For a machine to have it, a part takes it in with exhibit state. The model then says that exactly this machine goes through this state machine.
// Excerpt of the coffee machine model
part def CoffeeMachine {
exhibit state machineStates : MachineStates;
}The complete state machine of the machine. The download also contains the structure from lessons 4 and 5, in which CoffeeMachine takes in the state machine. One gap remains: when the boiler gets too hot, the machine has nowhere to go. Adding a fault state is your task below.
// Excerpt: the state machine of this lesson
item def PowerOn;
item def TemperatureReached;
item def BrewCommand;
item def PowerOffCommand;
action def HeatWater;
action def StopHeating;
action def Pour;
state def MachineStates {
entry; then off;
state off;
state heatingUp {
entry action heat : HeatWater;
exit action stop : StopHeating;
}
state ready;
state brewing {
do action pour : Pour;
}
transition powerOn first off accept PowerOn then heatingUp;
transition warmedUp first heatingUp accept TemperatureReached then ready;
transition startBrew first ready accept BrewCommand then brewing;
transition brewed first brewing then ready;
transition powerOff first ready accept PowerOffCommand then off;
}Statements follow the OMG SysML v2 specification, Part 1 (Language Specification), in the clause on states (state definitions and usages, transitions, entry, do and exit actions, exhibit state). PRISM reads these constructs and checks that the names resolve, but does not draw a diagram for state machines yet. The states of this lesson are therefore visible in the text and in the task’s checklist, not in the diagram.
This is the coffee machine model of the lesson: the structure from the earlier lessons plus the machine's state machine, which is in the textual notation (Off, HeatingUp, Ready, Brewing). PRISM has no diagram for state machines yet. What is drawn is therefore the structure of the machine; the states are checked by the task's checklist. Edit the text; the diagram redraws while you type. Everything runs in your browser, nothing is sent anywhere. At the end of the page you can download the file and open it in any tool that reads SysML v2 textual notation.
The editor contains open-source components. Third-party notices · Source offer
10 short exercises. Every answer gets feedback right away. Exercises you get wrong come back at the end. Your progress stays in this browser.
What stands after accept in this transition?
item def PowerOn;
state def MachineStates {
state off;
state heatingUp;
transition first off accept PowerOn then heatingUp;
}Match each SysML v1 term with its counterpart in SysML v2.
SysML v1SysML v2
Which word names the event that triggers the transition?
state def MachineStates {
state off;
state heatingUp;
transition first off ___ PowerOn then heatingUp;
}Tap the line that is not valid SysML v2.
state def MachineStates {
state off;
state heatingUp;
transition first off accept PowerOn to heatingUp;
}Tap a line, or move to it with the Tab key and press Enter.
Put the pieces in the order of the line that changes from off to heatingUp as soon as PowerOn arrives.
Drag the pieces, or use the arrow buttons.
thenPowerOntransition;offheatingUpacceptfirstType the keyword that makes the action run when the state is left.
state heatingUp {
entry action heat : HeatWater;
___ action stop : StopHeating;
}In which state does the machine begin?
state def MachineStates {
entry; then ready;
state off;
state ready;
}What does exhibit state machineStates : MachineStates; do in CoffeeMachine?
part def CoffeeMachine {
exhibit state machineStates : MachineStates;
}Tap the line that is not valid SysML v2.
package CoffeeMachine {
state machine MachineStates {
state off;
}
}Tap a line, or move to it with the Tab key and press Enter.
Which line makes the machine change from ready to brewing as soon as BrewCommand arrives?
state def MachineStates {
state ready;
state brewing;
}The coffee machine model as a SysML v2 text file.
Download coffee-machine.sysmlPRISM turns SysML v2 text like this into diagrams and views. Try it on the sample model.
Try it nowWhat the machine has to achieve: writing requirements, making them checkable and assigning them to the part that satisfies them.