21
CSCI1600: Embedded and Real Time Software Lecture 7: Modeling II: Discrete Systems Steven Reiss, Fall 2015

CSCI1600: Embedded and Real Time Software Lecture 7: Modeling II: Discrete Systems Steven Reiss, Fall 2015

Embed Size (px)

Citation preview

Page 1: CSCI1600: Embedded and Real Time Software Lecture 7: Modeling II: Discrete Systems Steven Reiss, Fall 2015

CSCI1600: Embedded and Real Time SoftwareLecture 7: Modeling II: Discrete Systems

Steven Reiss, Fall 2015

Page 2: CSCI1600: Embedded and Real Time Software Lecture 7: Modeling II: Discrete Systems Steven Reiss, Fall 2015

Embedded Systems

Are sets of tasks The task is the primary abstraction to be used

If we want to understand the system We want to model it

Should we model the whole system Or should we just model the individual tasks

Page 3: CSCI1600: Embedded and Real Time Software Lecture 7: Modeling II: Discrete Systems Steven Reiss, Fall 2015

How to Model a Task English description

Typically used first

Imprecise, hard to check, incomplete

Formal mathematics

Very precise

Difficult to understand

Hard to express external events

Formal diagrams

Combine formal math with understanding

Diagrams make it easier to comprehend what is there

Provide a framework for the math and understanding

Page 4: CSCI1600: Embedded and Real Time Software Lecture 7: Modeling II: Discrete Systems Steven Reiss, Fall 2015

Modeling Control Systems

Control oriented systems Typically respond to external stimuli

Reaction based on previous interactions These determine the state of the system

Stimulus moves system to a new state Control is state-oriented

Natural model is finite state automata

Page 5: CSCI1600: Embedded and Real Time Software Lecture 7: Modeling II: Discrete Systems Steven Reiss, Fall 2015

Basic Finite State Automata

Page 6: CSCI1600: Embedded and Real Time Software Lecture 7: Modeling II: Discrete Systems Steven Reiss, Fall 2015

Problem

Want to automatically trigger switch When train goes from R to L

What does sensing look like

What does train look like

When should you trigger the switch

C

D

A B

Page 7: CSCI1600: Embedded and Real Time Software Lecture 7: Modeling II: Discrete Systems Steven Reiss, Fall 2015

Problem

Can only trigger one switch at a time Switch trigger

Should be momentary (>100ms, <500ms)

What does this task do?

How many tasks should it be?

Is it a FSA?

Page 8: CSCI1600: Embedded and Real Time Software Lecture 7: Modeling II: Discrete Systems Steven Reiss, Fall 2015

Problem

Problem: when is the train on which block When is train completely on A/C or B or D side of switch

Handling initial conditions

Handling reversing directions

C

D

A B

Page 9: CSCI1600: Embedded and Real Time Software Lecture 7: Modeling II: Discrete Systems Steven Reiss, Fall 2015

Issues with Basic FSA

Need to specify actions

Semi-external events: timers

Internal events from other automata

Conditional events

Multiple FSA’s in parallel

Counters and other variables

State space blowup

Page 10: CSCI1600: Embedded and Real Time Software Lecture 7: Modeling II: Discrete Systems Steven Reiss, Fall 2015

Actions: Moore vs Mealy Machine

Page 11: CSCI1600: Embedded and Real Time Software Lecture 7: Modeling II: Discrete Systems Steven Reiss, Fall 2015

Moore vs. Mealy

Which is more useful?

Are they equivalent?

Page 12: CSCI1600: Embedded and Real Time Software Lecture 7: Modeling II: Discrete Systems Steven Reiss, Fall 2015

Extended State Machines Each arc has condition/action

To traverse arc, condition must hold

When traversing arc, action is taken

There are a finite set of (bounded) variables Conditions can reference these

Condition can be

Event

Time out

Expression over variables

Combination of the two

Page 13: CSCI1600: Embedded and Real Time Software Lecture 7: Modeling II: Discrete Systems Steven Reiss, Fall 2015

Extended State Machines Actions

Can access and change variables

Can be { var = expression; … }

Can do something external

When no condition is true Stay in same state

When multiple conditions are true What should be done

Nondeterminism,

Allow priority specification

Page 14: CSCI1600: Embedded and Real Time Software Lecture 7: Modeling II: Discrete Systems Steven Reiss, Fall 2015

Digital Watch

Four buttons

Chimes, alarms, time, stopwatch, light

How does it work?

Number of states?

Lots of tasks Specifying each

Specifying their interaction

Page 15: CSCI1600: Embedded and Real Time Software Lecture 7: Modeling II: Discrete Systems Steven Reiss, Fall 2015

Statecharts

David Harel (80’s)

Part of UML

Extended FSM notation

Page 16: CSCI1600: Embedded and Real Time Software Lecture 7: Modeling II: Discrete Systems Steven Reiss, Fall 2015

Concurrency

Concurrent FSMs Same box, dashed line

State of overall is cross-product of states

Can have array (n copies)

Page 17: CSCI1600: Embedded and Real Time Software Lecture 7: Modeling II: Discrete Systems Steven Reiss, Fall 2015

Hierarchical Automata

Allow abstraction

Can be used to generalize groups of states

Can be used for clustering

Can have multiple levels

What state to goto inside?

Page 18: CSCI1600: Embedded and Real Time Software Lecture 7: Modeling II: Discrete Systems Steven Reiss, Fall 2015

Start and Stop States

Start states are large dots

Stop states are encircled dots

Hierarchal elements can have internal start states

Page 19: CSCI1600: Embedded and Real Time Software Lecture 7: Modeling II: Discrete Systems Steven Reiss, Fall 2015

History Mechanism

Keep track of state in nested automata

Circled-H is entry point Default entry

Can point to start state

Page 20: CSCI1600: Embedded and Real Time Software Lecture 7: Modeling II: Discrete Systems Steven Reiss, Fall 2015

Delays and Timeouts

Delays cause a state to hold until time has expired time< in state

Timeouts are automatic events <time in state

Separate timeout event

Page 21: CSCI1600: Embedded and Real Time Software Lecture 7: Modeling II: Discrete Systems Steven Reiss, Fall 2015

Homework

Read Chapter 4