Top Banner
Workshop 4 of 7 Welcome!
54

Workshop 4 of 7

Feb 24, 2016

Download

Documents

Hayes

Welcome!. Workshop 4 of 7. Today's Topics. Review of Workshop 3 Sequence Structure Timing State Machine . Review Question 1. How many times must a For Loop iterate? A While Loop? 0,0 1,0 0,1 1,1. Review Question 1. How many times must a For Loop iterate? A While Loop? 0,0 1,0 - PowerPoint PPT Presentation
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Workshop  4 of 7

Workshop 4 of 7

Welcome!

Page 2: Workshop  4 of 7

Today's Topics

Review of Workshop 3

Sequence Structure Timing State Machine

Page 3: Workshop  4 of 7

Review Question 1

How many times must a For Loop iterate? A While Loop?

a) 0,0

b) 1,0

c) 0,1

d) 1,1

Page 4: Workshop  4 of 7

Review Question 1

How many times must a For Loop iterate? A While Loop?

a) 0,0

b) 1,0

c) 0,1d) 1,1

Page 5: Workshop  4 of 7

Review Question 2

True or False?The value passed to the case selector terminal determines which case will execute.

Page 6: Workshop  4 of 7

Review Question 2

True or False?The value passed to the case selector terminal determines which case will execute.

TRUE

Page 7: Workshop  4 of 7

Review Question 3

A “hollow” output tunnel will appear on the edge of a case structure because…?

a) the wrong data type is wired to it

b) there is not a wire leading away from it

c) one or more cases do not have a wire leading to it

Page 8: Workshop  4 of 7

Review Question 3

A “hollow” output tunnel will appear on the edge of a case structure because…?

a) the wrong data type is wired to it

b) there is not a wire leading away from it

c) one or more cases do not have a wire leading to it

Page 9: Workshop  4 of 7

Review Question 4

Which of the following statements about Auto-indexing are true? (multiple answers possible)

a) When auto-indexing is enabled on an output tunnel, only one element can be passed out of the tunnel.

b) When auto-indexing is enabled on an input tunnel, only one element can be passed out of the tunnel

c) When auto-indexing is enabled on an output tunnel, the entire array is passed out of the tunnel

d) When auto-indexing is enabled on an input tunnel, the entire array is passed out of the tunnel

Page 10: Workshop  4 of 7

Review Question 4

Which of the following statements about Auto-indexing are true? (multiple answers possible)

a) When auto-indexing is enabled on an output tunnel, only one element can be passed out of the tunnel.

b) When auto-indexing is enabled on an input tunnel, only one element can be passed out of the tunnel

c) When auto-indexing is enabled on an output tunnel, the entire array is passed out of the tunnel

d) When auto-indexing is enabled on an input tunnel, the entire array is passed out of the tunnel

Page 11: Workshop  4 of 7

Review Question 5

The value of Result when the VI below finishes will be:

a) 15

b) 18

c) 22

d) 28

Page 12: Workshop  4 of 7

Review Question 5

The value of Result when the VI below finishes will be:

a) 15

b) 18c) 22

d) 28

Page 13: Workshop  4 of 7

Review Question 1

True or False?

You must have at least one case in a Disable Diagram that is enabled.

Page 14: Workshop  4 of 7

Review Question 1

True or False?

You must have at least one case in a Disable Diagram that is enabled.

TRUE

Page 15: Workshop  4 of 7

Review Question 2Match the following:

a) Event Filter Node

b) Notify Event

c) Filter Event

d) Event Data Node

• attached to the inside left border of each event case; identifies the data LabVIEW provides when an event occurs.

• attached to the inside right border of filter event cases; identifies the subset of data available that the event case can modify

• an indication that a user action has already occurred, such as when the user has changed the value of a control

• inform you that the user has performed an action before LabVIEW processes it, which allows you to customize how the program responds to interactions with the user interface

Page 16: Workshop  4 of 7

Review Question 2

Match the following:

a) Event Filter Node

b) Notify Event

c) Filter Event

d) Event Data Node

• attached to the inside left border of each event case; identifies the data LabVIEW provides when an event occurs.

• attached to the inside right border of filter event cases; identifies the subset of data available that the event case can modify

• an indication that a user action has already occurred, such as when the user has changed the value of a control

• Informs you that the user has performed an action before LabVIEW processes it, which allows you to customize how the program responds to interactions with the user interface

Page 17: Workshop  4 of 7

Review Question 3

Which of the following is true about the Event Structure?

a) An event structure will sleep while waiting for an event to occur

b) An even structure can process multiple events simultaneously

c) It is a good idea multiple event structures within a block diagram

d) Event structures are often used within a while loop

Page 18: Workshop  4 of 7

Review Question 3

Which of the following is true about the Event Structure?

a) An event structure will sleep while waiting for an event to occur TRUE

b) An even structure can process multiple events simultaneously FALSE

c) It is a good idea multiple event structures within a block diagram FALSE

d) Event structures are often used within a while loop TRUE

Page 19: Workshop  4 of 7

Flat Sequence Structure Executes each frame beginning with the left-most frame

and ending with the right-most frame The previous frame must complete before the next frame

executes Data can be passed out of or between frames using tunnels Once the sequence begins, it cannot be stopped

1st 2nd 3rd

Page 20: Workshop  4 of 7

Stacked Sequence Structure

Stacks each frame so you see only one frame at a time Executes frame 0, then frame 1, etc. until the last frame

executes Returns data only after the

last frame executes To transfer data from frame

to frame, a Sequence Local must be created (right-click » Add Sequence Local)

• Once the sequence begins, it cannot be stopped

Sequence Local

Page 21: Workshop  4 of 7

Timing Functions

• Control or measure the frequency at which a loop executes• Provide the processor with time to complete other tasks,

such as processing the user interface• Uses the operating system millisecond clock

Page 22: Workshop  4 of 7

Wait Function

• Waits the specified number of milliseconds.• If 0 is wired to it, the current thread is forced to yield

control of the CPU • Uses the operating system millisecond clock

Page 23: Workshop  4 of 7

Wait Function- example cases

10 ms 20 ms 30 ms

Wait

Other code (running in parallel with Wait VI)

• Loop would go on to next iteration after 10 ms, because the only thing that happens in each iteration is wait 10 ms

• Loop would go to next iteration after 10 ms or more depending on amount of time the subVI takes.

• If subVI takes >10 ms, loop goes as soon as subVI is done

• If subVI takes <10 ms , loop goes at 10 ms mark.

Moment next loop iteration can begin

Page 24: Workshop  4 of 7

Wait Until Next Millisecond Multiple Function

• Waits until a multiple of the millisecond value wired in• Provide the processor with time to complete other

tasks, such as processing the user interface• Uses the operating system millisecond clock

Page 25: Workshop  4 of 7

Wait Until Next Millisecond Multiple Function

10 ms 20 ms 30 ms

• Loop would go on to next iteration after 10 ms, because the only thing that happens in each iteration is wait 10 ms and 10ms is the first multiple of 10

• Loop would go to next iteration after 10 , 20, 30, or a greater multiple of 10 ms depending on amount of time the subVI takes.

• If subVI takes <10 ms , loop goes at 10 ms mark.

• If subVI takes 16 ms, then the loop goes at 20 ms.

• If subVI takes 22 ms, then the subVI goes at 30 ms.

Wait

Other code (subVI)

Page 26: Workshop  4 of 7

Comparison of Timing Functions

10 ms 20 ms 30 ms

Other code (running in

parallel with waits)

Moment next loop iteration can begin

Red represents times when Wait functions are NOT restricting

Page 27: Workshop  4 of 7

Demonstration: Comparing the Timing Functions

Page 28: Workshop  4 of 7

VI Timing Types• Execution Timing

• Provides the design pattern with a function that specifically allows the processor time to complete other tasks

• In some cases, a Wait function is not necessary

• Use of Timeout inputs can provide execution timing

• Software Control Timing

• Timing (pauses, waits, time checks) you put in place to make the code execute after a certain amount of time.

• Example:• If you must acquire data for 5 minutes, you could remain in the acquisition state until

the 5 minutes elapses. However, during that time you cannot process any user interface actions such as stopping the VI. To process user interface actions, you must implement timing (checking if 5 min has passed since the start of acquisition) so that the VI continually executes for the specified time

Page 29: Workshop  4 of 7

29

Software Control Timing

Execution TimingVI Timing

Page 30: Workshop  4 of 7

State Machine Intro: Scenario

Want to create a program that does the following:

1. Reads a voltage

2. Tells user to turn on power supply

3. Read the voltage again now that power is on

4. Tell the user to turn off the power.

Page 31: Workshop  4 of 7

Programming Designs: Sequential

Page 32: Workshop  4 of 7

Sequential Programming

Page 33: Workshop  4 of 7

Sequential Programming

Page 34: Workshop  4 of 7

Sequential Programming

Page 35: Workshop  4 of 7

Sequential Programming

• What if you need to change the order of the sequence?

• What if you need to repeat one item in the sequence more often than the other items?

• What if some items in the sequence execute only when certain conditions are met?

• What if you need to stop the program immediately, rather than waiting until the end of the sequence?

Page 36: Workshop  4 of 7

State Machines

• Implements a state diagram.

• Programmatically determine which state is next- Different action if a

quarter was inserted compared to return change requested

Page 37: Workshop  4 of 7

• A state machine consists of a set of states and a transition function that maps to the next state

• Each state can lead to one or multiple states or end the process flow

While Loop

Case StructureShift Register

State Machine

Enum

Page 38: Workshop  4 of 7

• State Functionality Code: • this state was entered to perform

what function?

• Transition Code: • which state is next?

State Machine: Transition Code

Page 39: Workshop  4 of 7

Demonstration: Execution of a State Machine

Page 40: Workshop  4 of 7

General VI Three phases: Start-up, Main Application, and Shut-

down

40

Design Patterns: Single Loop

Page 41: Workshop  4 of 7

General VI

41

Single Loop Design Pattern: in LabVIEW

Page 42: Workshop  4 of 7

Single Loop Design Pattern

State MachineUsually has a start-up and shut-down state, but also

contains other states

42

Page 43: Workshop  4 of 7

Single Loop Design Pattern

State Machine

43

Page 44: Workshop  4 of 7

Parallelism Parallelism: executing multiple tasks at the same time

Use case:• Need to acquire data very quickly, process it and save it to file.• If you do each step in a linear fashion and try to acquire all the data

before processing, then you may run out of memory before processing begins.

• If you do “sets” of steps (acquire, process, save, repeat), then you are missing the data points when the processing and saving are going on.

• If only you could acquire, process, and save in parallel….good news, you can!

44

Page 45: Workshop  4 of 7

Multiple Loop Design Pattern

Parallel Loop

45

Page 46: Workshop  4 of 7

Multiple Loop Design PatternProducer/Consumer

46

Page 47: Workshop  4 of 7

Multiple Loop Design PatternMaster/Slave: a type of Producer/Consumer

47

• uses notifiers to allow loops to run at different rates

Page 48: Workshop  4 of 7

NotifiersPros:

• Both loops are synchronized to the master loop—the slave loop only executes when the master loop sends a notification

• You can use notifiers to create globally available data, making it possible to send data with a notification

• Using notifiers creates efficient code—there is no need to poll to determine when data is available from the master loop

Cons:• Notifiers do not buffer data.

• If the master loop sends another piece of data before the first piece of data has been read by the slave loops, that data is overwritten and lost.

48

Page 49: Workshop  4 of 7

Queues

• Queues are similar to notifiers, except that a queue can store multiple pieces of data

• By default, queues work in a FIFO (first in, first out) manner

• Use a queue when you want to process all data placed in the queue

• Use a notifier if you only want to process the current data

• Use the Queue Operations functions to create a queue for communicating data between sections of a block diagram or from another VI.

49

Page 50: Workshop  4 of 7

50

Producer/Consumer with Queues

Data type here determines the data type that can be placed in the queue

Page 51: Workshop  4 of 7

Demonstration: Queues in Action

Page 52: Workshop  4 of 7

52

Producer/Consumer with Queues and Events

• Efficiently responds asynchronously to the user interface

Page 53: Workshop  4 of 7

Notifier vs. Queue Review

Tool Function When to use

Notifier - sends alert to helps control timing of parallel loops- can transfer data between loops- data NOT buffered (lossy)

- have a parallel loops that are running at different rates and 1+ loop is dependent on another- want to transfer data from one loop to another

Queue - helps control timing of parallel loops - transfers data between loops - buffers data to be transferred (FIFO)

- have a parallel loops that are running at different rates and 1+ loop is dependent on another- want to transfer ALL data from one loop to another

Page 54: Workshop  4 of 7

Work on a Game!

Complete Homework 4

CLAD Questions 4

Email to [email protected]

Homework