Kurs bölümleri
Eğitim · Kurs 9. SysML v2 temelleri · Bölüm 9.4 / 8
9.4 Durumlar ve geçişler 3:51
Tetikleyiciler, koşullar ve durum eylemleri içeren bir durum makinesi yazın ve zamanlı bir geçiş çizin.
Holarch 2.22 sürümünü gösterir.
Neler öğreneceksiniz
- Sinyalleri ve başlangıç durumu olan bir durum tanımını tanımlayın
- Bir tetikleyici, bir koşul ve bir hedefle geçişleri kısa biçimde ve adlandırılmış geçişler olarak yazın
- Bir duruma entry, do ve exit eylemleri verin
- Bir Durum geçişi görünümünde bir geçiş çizin ve adını ve tetikleyicisini ayarlayın
- Bir parçanın bir durum tanımını sergilemesini sağlayın
Küçük bir Hybrid Car projesi üzerinde SysML v2 öğreticisi States and Transitions'ı izleyerek Holarch'ta bir SysML v2 durum makinesi yazın: tanım olarak sinyaller, başlangıç durumu olan bir durum tanımı, tetikleyicili ve koşullu geçişler, entry, do ve exit eylemleri, adlandırılmış geçişler, üzerine zamanlı bir geçiş çizilmiş bir Durum geçişi görünümü ve durumları sergileyen bir otomobil. SysML, Object Management Group, Inc.'in tescilli ticari markasıdır.
Proje dosyaları
- Bitmiş proje (.holarch.json; Projeleri yönet → Proje dosyaları ▾ → Proje içe aktar (.json)…)
Video holarch.app'ten oynatılır; bkz. Gizlilik Politikası.
Alıştırma
Bunu Holarch'ta, Hybrid Car demo projesinde (SysML v2) kendiniz yapın.
- Hybrid Car demo projenizi açın (gerekirse oluşturun: Projeleri yönet → Proje dosyaları ▾ → Yeni demo proje → Hybrid Car (SysML v2)), Model → Düzenleyici'yi ve
VehicleBehaviorpaketini açın. attribute def Unplug;'dan sonraattribute def FaultDetected;ekleyin.state def PowertrainStates'in kapanış ayracından öncestate limpHome { entry action warnDriver; do action driveLimited; }vetransition limpStop first limpHome accept StopRequest then off;ekleyin.- Davranış → Durum makineleri'ni açın, + Yeni diyagram'a tıklayın, Gösterir altında
PowertrainStates'i seçin ve Oluştur'a tıklayın. electric'i seçin ve tutamacındanlimpHome'a sürükleyin; Geçiş üzerine bırakın. Geçiş panelinde Ad olarakelectricFault, Tetikleyici olarakFaultDetectedgirin, ardından Metinde göster'e tıklayın.
PowertrainStates, limpHome'u, limpStop'u ve FaultDetected'ı kabul eden electricFault geçişini içerdiğinde ve düzenleyicinin altındaki durum hiçbir sorun bildirmediğinde işiniz bitmiştir.
Kendinizi sınayın
off'uPowertrainStates'in başlangıç durumu yapan nedir?state off;'dan sonraaccept StartRequest if charge > 20 then electric;gelir. Tetikleyicisini, koşulunu, kaynağını ve hedefini söyleyin.- Bir durumun entry, do ve exit eylemleri ne zaman çalışır?
DrivenCariçindekiexhibit state powertrainStates : PowertrainStates;ne söyler?
Yanıtları göster
off'uPowertrainStates'in başlangıç durumu yapan nedir?entry; then off;: entry'yioff'a bir ardışıklık izler, bu yüzden durum makinesi orada başlar. Görünüm bunu nokta olarak çizer.state off;'dan sonraaccept StartRequest if charge > 20 then electric;gelir. Tetikleyicisini, koşulunu, kaynağını ve hedefini söyleyin.Tetikleyici: StartRequest sinyali. Koşul:
charge > 20. Hedef:electric. Kısa biçim, izlediği durumda, yanioff'ta başlar.Bir durumun entry, do ve exit eylemleri ne zaman çalışır?
entry eylemi duruma girildiğinde, do eylemi durum etkinken, exit eylemi de durumdan çıkıldığında çalışır.
DrivenCariçindekiexhibit state powertrainStates : PowertrainStates;ne söyler?Otomobilin bu durum makinesini sergilediğini: otomobil bir PowertrainStates kullanımına sahiptir, bu yüzden onun durumları otomobilin durumlarıdır.
Daha fazla bilgi
Döküm
Dökümü göster (anlatım ve ekranda görünenler)
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.