11-29-2020 03:23 PM
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!
Solved! Go to Solution.
11-29-2020 06:03 PM
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.
11-30-2020 06:14 AM
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) 🙂
11-30-2020 06:33 AM
Look at a queued message handler or queued state machine architecture.
11-30-2020 11:38 AM
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.