LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Event Structure for Events that Require Iteration

Solved!
Go to solution

Hello all, 

 

I am controlling a motor and wanted to have the option to (1) home, (2) move it to a specified position, and (3) to scan, that is, the motor goes to specified positions and stays there for a certain time while measurements are made. 

 

Because what the motor is doing is determined by the user, my intuition was to use an event structure. However, by having the scan functionality, I would need a while loop inside the event structure to iterate through the motor's different positions. So, I thought of having the "start scan" event trigger the start of an external while loop or something of the sort. 

 

I'm trying to improve my LabVIEW skills, so is there a better, more elegant solution to my problem? What is the general rule of thumb when an event requires iteration?

 

I'm attaching the VI in question.

 

Thank you!  

0 Kudos
Message 1 of 5
(1,122 Views)
Solution
Accepted by topic author enricomc

One option is to use the Timeout case of your Event Structure.  Use a Shift Register to state what the timeout should be (-1 = wait forever).  Use another Shift Register to state what case inside of the Timeout case should be ran.  This is a form of the State Machine but the Event Structure on the outside of the state case structure.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 2 of 5
(1,093 Views)

One common solution is to have some State on the motor that the event sets. That way it doesn't need to lock the event structure with a wait. In This case Would e.g. set Move and End position in a cluster (keep all important data in a cluster that's wired through a shift register). Then you can scan position in the timeout to stop it, or even better use HW timing/pos.

(It's basically what Crossrulz said) 🙂

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
Message 3 of 5
(1,058 Views)

Look at a queued message handler or queued state machine architecture.

Message 4 of 5
(1,046 Views)

You want a queued message handler. A queued state machine, though commonly recommended, is not a good architecture long-term. Telling the system to execute a specific "state" next is better accomplished by just making that task a subVI.

 

Keep the state internal to the loop, and have it process a command.

Message 5 of 5
(1,024 Views)