Holarch
Kurskapitel

Schulung · Reihe 9. SysML-v2-Grundlagen · Kapitel 9.4 von 8

9.4 Zustände und Übergänge 3:51

Eine State Machine mit Auslösern, Guards und Zustandsaktionen schreiben und einen zeitgesteuerten Übergang zeichnen.

Zeigt Holarch 2.22.

← 9.3 Aktionen und Flüsse · Alle Kapitel · 9.5 Anforderungen →

Das lernen Sie

  • Signale und eine State-Definition mit einem Anfangszustand definieren
  • Übergänge mit Auslöser, Guard und Ziel schreiben, in der Kurzform und als benannte Übergänge
  • Einem Zustand entry-, do- und exit-Actions geben
  • Einen Übergang in einer Zustandsübergangs-Ansicht zeichnen und Name und Auslöser festlegen
  • Einen Part eine State-Definition aufweisen lassen (exhibit)

Schreiben Sie eine SysML-v2-State-Machine in Holarch, nach dem SysML-v2-Tutorial „States and Transitions“ an einem kleinen Hybrid-Car-Projekt: Signale als Definitionen, eine State-Definition mit Anfangszustand, Übergänge mit Auslösern und Guards, entry-, do- und exit-Actions, benannte Übergänge, eine Zustandsübergangs-Ansicht mit einem darauf gezeichneten zeitgesteuerten Übergang und ein Auto, das die Zustände aufweist. SysML ist eine eingetragene Marke der Object Management Group, Inc.

Projektdateien

  • Fertiges Projekt (.holarch.json; Projekte verwalten → Projektdateien ▾ → Projekt importieren (.json)…)

Das Video wird von holarch.app abgespielt; siehe Datenschutzerklärung.

Übung

Führen Sie dies selbst in Holarch durch, am Demoprojekt Hybrid Car (SysML v2).

  1. Öffnen Sie Ihr Demoprojekt Hybrid Car (erstellen Sie es bei Bedarf: Projekte verwalten → Projektdateien ▾ → Neues Demoprojekt → Hybridauto (SysML v2)), öffnen Sie Modell → Editor und das Package VehicleBehavior.
  2. Fügen Sie nach attribute def Unplug; attribute def FaultDetected; hinzu.
  3. Fügen Sie vor der schließenden Klammer von state def PowertrainStates state limpHome { entry action warnDriver; do action driveLimited; } und transition limpStop first limpHome accept StopRequest then off; hinzu.
  4. Öffnen Sie Verhalten → State Machines, klicken Sie auf + Neues Diagramm, wählen Sie unter Zeigt PowertrainStates und klicken Sie auf Erstellen.
  5. Wählen Sie electric aus und ziehen Sie von seinem Griff zu limpHome; legen Sie auf Übergang ab. Geben Sie im Übergangsbereich den Name electricFault und den Auslöser FaultDetected ein und klicken Sie dann auf Im Text anzeigen.

Sie sind fertig, wenn PowertrainStates limpHome, limpStop und den Übergang electricFault enthält, der FaultDetected akzeptiert, und der Status unter dem Editor keine Probleme meldet.

Selbsttest

  1. Was macht off zum Anfangszustand von PowertrainStates?
  2. Nach state off; folgt accept StartRequest if charge > 20 then electric;. Nennen Sie Auslöser, Guard, Quelle und Ziel.
  3. Wann laufen die entry-, do- und exit-Actions eines Zustands?
  4. Was sagt exhibit state powertrainStates : PowertrainStates; in DrivenCar aus?
Antworten anzeigen
  1. Was macht off zum Anfangszustand von PowertrainStates?

    entry; then off;: Auf den Eintritt folgt eine Succession zu off, daher startet die State Machine dort. Die Ansicht zeichnet ihn als Punkt.

  2. Nach state off; folgt accept StartRequest if charge > 20 then electric;. Nennen Sie Auslöser, Guard, Quelle und Ziel.

    Auslöser: das Signal StartRequest. Guard: charge > 20. Ziel: electric. Die Kurzform beginnt bei dem Zustand, dem sie folgt, off.

  3. Wann laufen die entry-, do- und exit-Actions eines Zustands?

    Die entry-Action läuft beim Betreten des Zustands, die do-Action, solange der Zustand aktiv ist, und die exit-Action beim Verlassen des Zustands.

  4. Was sagt exhibit state powertrainStates : PowertrainStates; in DrivenCar aus?

    Dass das Auto diese State Machine aufweist: Das Auto besitzt eine Usage von PowertrainStates, daher sind ihre Zustände die Zustände des Autos.

Weiterlesen

Transkript

Transkript anzeigen (Erzählung und Bildschirminhalt)

Introduction

Chapter four: states and transitions. A state machine says how a system reacts to events, and what it does in each state.

In this chapter you write signals and a state machine with triggers, guards and state actions, draw a timed transition in a view, and let the car exhibit the states.

Start the tutorial

Start the tutorial States and Transitions from Project Files, Start a Tutorial. Its starter project holds the powertrain package with the car, and nothing else yet.

On screen: Project Files ▾ → Start a Tutorial… → SysML v2: States and Transitions → Start; Model → Editor.

The state machine

A state machine reacts to signals, and in SysML v2 they are plain definitions. After the imports, define four: start request, stop request, plug in and unplug.

On screen: After the imports: four attribute defs.

Below the signals, write the state definition. Charge is an input that the transitions read. Entry, then off, makes off the initial state.

On screen: Below Unplug: state def PowertrainStates with three states.

Transitions and state actions

A transition has a trigger, a guard and a target. After the off state, a start request goes to electric when the charge is above twenty, and to hybrid otherwise. This short form starts at the state it follows.

On screen: After state off;: accept StartRequest if charge > 20 then electric; accept StartRequest then hybrid;

Now give the electric state its actions. Replace its line with a body: the entry action runs when the state is entered, the do action while it is active, and the exit action when it is left.

On screen: Select state electric; and type its body.

After the electric state, the powertrain switches to hybrid when the charge drops below fifteen, and turns off on a stop request. The hybrid state turns off on a stop request too.

On screen: After electric's closing brace: if charge < 15 then hybrid; accept StopRequest then off; after state hybrid;: accept StopRequest then off;

Before the closing brace of the state definition, add the charging state and two named transitions. A named transition says where it starts, with first.

On screen: After hybrid's stop transition: state charging; transition plugIn; transition unplugged.

The State Transition View

Open Behavior, then State Machines, and click New Diagram. Keep State Transition View, choose the powertrain states under Shows, and click Create.

On screen: Behavior → State Machines → + New Diagram; Shows: PowertrainBehavior::PowertrainStates; Create.

States show their entry, do and exit actions, and the dot marks the initial state. Each transition reads its trigger, the guard in square brackets, then a slash and the effect.

On screen: The view.

Draw a timed transition

A full charge takes half an hour, then the car switches off. Select the charging state, and drag from its handle to the off state. The drop makes a transition.

On screen: Select charging; drag its handle onto off.

In the transition panel, name it charged, and set its trigger to after thirty minutes.

On screen: Transition panel: Name charged; Trigger after 30 [min].

Open the Editor. The new transition is in the state definition: named charged, it accepts after thirty minutes, and goes to off.

On screen: Model → Editor: the transition charged.

Exhibit

Last, let the car exhibit the states. Inside the car, after its doc line, add an exhibit state usage. The state machine now belongs to the car.

On screen: In part def Car after doc: exhibit state powertrainStates : PowertrainStates;

Recap

Every step is ticked off. Click Mark as Done.

On screen: Step panel → Mark as Done.

Let's recap. You defined signals, wrote a state definition with an initial state, transitions with triggers and guards, and state actions, drew a timed transition that Holarch wrote into the text, and let the car exhibit the states.

Next, requirements say what the car must do, in a form the model can check.