Holarch
과정의 장

교육 · 트랙 9. SysML v2 기초 · 9.4장 (전체 8장)

9.4 상태와 전이 3:51

트리거, 가드, 상태 액션이 있는 상태 기계를 작성하고, 시간 전이를 그립니다.

Holarch 2.22 화면입니다.

학습 내용

  • 신호와 초기 상태가 있는 상태 정의 정의하기
  • 트리거, 가드, 도착 상태가 있는 전이를 짧은 형식과 이름 있는 전이로 작성하기
  • 상태에 entry, do, exit 액션 지정하기
  • 상태 전이 뷰에서 전이를 그리고 이름과 트리거 설정하기
  • 파트가 상태 정의를 나타내도록 하기

Hybrid Car라는 작은 프로젝트에서 SysML v2 튜토리얼 States and Transitions를 따라 Holarch에서 SysML v2 상태 기계를 작성합니다. 정의로서의 신호, 초기 상태가 있는 상태 정의, 트리거와 가드가 있는 전이, entry, do, exit 액션, 이름 있는 전이, 시간 전이를 그린 상태 전이 뷰, 그리고 상태를 나타내는 자동차를 다룹니다. SysML은 Object Management Group, Inc.의 등록 상표입니다.

프로젝트 파일

  • 완성 프로젝트 (.holarch.json; 프로젝트 관리 → 프로젝트 파일 ▾ → 프로젝트 가져오기 (.json)…)

동영상은 holarch.app에서 재생됩니다. 개인정보 처리방침을 참조하십시오.

실습

Hybrid Car 데모 프로젝트(SysML v2)에서 Holarch로 직접 해 보십시오.

  1. Hybrid Car 데모 프로젝트를 열고(필요하면 만드십시오: 프로젝트 관리 → 프로젝트 파일 ▾ → 새 데모 프로젝트 → Hybrid Car (SysML v2)), 모델 → 편집기와 패키지 VehicleBehavior를 엽니다.
  2. attribute def Unplug; 뒤에 attribute def FaultDetected;를 추가합니다.
  3. state def PowertrainStates의 닫는 중괄호 앞에 state limpHome { entry action warnDriver; do action driveLimited; }와 transition limpStop first limpHome accept StopRequest then off;를 추가합니다.
  4. 동작 → 상태 기계를 열고 + 새 다이어그램을 클릭한 다음, 표시 대상에서 PowertrainStates를 선택하고 만들기를 클릭합니다.
  5. electric을 선택하고 핸들에서 limpHome으로 끌어 전이에 놓습니다. 전이 패널에서 이름 electricFault와 트리거 FaultDetected를 입력한 다음 텍스트에 표시를 클릭합니다.

PowertrainStates에 limpHome, limpStop, 그리고 FaultDetected를 수락하는 전이 electricFault가 있고, 편집기 아래의 상태에 문제가 없다고 표시되면 완료입니다.

스스로 확인

  1. 무엇이 off를 PowertrainStates의 초기 상태로 만듭니까?
  2. state off; 다음에 accept StartRequest if charge > 20 then electric;이 옵니다. 트리거, 가드, 출발 상태, 도착 상태를 말해 보십시오.
  3. 상태의 entry, do, exit 액션은 언제 실행됩니까?
  4. DrivenCar의 exhibit state powertrainStates : PowertrainStates;는 무엇을 말합니까?
답 보기
  1. 무엇이 off를 PowertrainStates의 초기 상태로 만듭니까?

    entry; then off;입니다. entry 뒤에 off로 가는 succession이 오므로 상태 기계가 그곳에서 시작합니다. 뷰는 이를 점으로 그립니다.

  2. state off; 다음에 accept StartRequest if charge > 20 then electric;이 옵니다. 트리거, 가드, 출발 상태, 도착 상태를 말해 보십시오.

    트리거: 신호 StartRequest. 가드: charge > 20. 도착 상태: electric. 짧은 형식은 앞에 오는 상태인 off에서 시작합니다.

  3. 상태의 entry, do, exit 액션은 언제 실행됩니까?

    entry 액션은 상태에 들어갈 때, do 액션은 상태가 활성인 동안, exit 액션은 상태를 떠날 때 실행됩니다.

  4. DrivenCar의 exhibit state powertrainStates : PowertrainStates;는 무엇을 말합니까?

    자동차가 이 상태 기계를 나타낸다는 것입니다. 자동차가 PowertrainStates의 사용을 소유하므로, 그 상태가 곧 자동차의 상태입니다.

더 읽어 보기

대본

대본 보기 (내레이션과 화면 내용)

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.