LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Creating an "Abort" state in a state machine (used for a state machine sending digital output signals in sequence)

Solved!
Go to solution

Hi,

 

I'm making a VI used for data acquisition and it needs to be able to send out digital output signals to certain valves in a timed sequence, as well as send signals from manually pressing switches. I set up a state machine to accomplish this and it works for the most part, but it also needs to have an abort state that the state machine immediately goes to upon pressing the abort button. The problem is, I'm not sure how to interrupt the sequence (especially during any of the wait x milliseconds frames) and immediately proceed to the abort state without having to wait for either the current state to end or for the sequence to end. Any help on how to do so is appreciated.

 

I have attached a model VI of the situation as well the relevant portion of the full VI I'm making.

Download All
0 Kudos
Message 1 of 8
(4,734 Views)

Hi joey,

 

I set up a state machine to accomplish this and it works for the most part,

Please make that enum a type definition! (For clusters and enums you should immediatly start with typedefinitions!)

Right now you already use different kinds of enums as can be seen by those coercion dots!

And you surely don't need all those local variables…

 

but it also needs to have an abort state

You already created such a state, that's fine.

 

that the state machine immediately goes to upon pressing the abort button. The problem is, I'm not sure how to interrupt the sequence (especially during any of the wait x milliseconds frames) and immediately proceed to the abort state without having to wait for either the current state to end or for the sequence to end.

There is NO way to "break" a wait function. NO WAY!

Possible solutions:

- Don't use wait functions with high wait times. You may use a dedicated "wait state" with a small delay of 10ms to be able to react "immediately" on your "Abort" button…

- Use a different approach than a (simple) state machine. A QMH (queued message handler) might be suited better here…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 8
(4,695 Views)
Solution
Accepted by topic author joeyjackson97

Hi Joey

 

A simple way to achieve this is to have a for loop inside each case that currently has a delay. Replace the delay with the loop monitoring your abort button on a much smaller timeout. Not sure how quickly you need to abort but I've chosen 10ms.

See attached VI.

 

0 Kudos
Message 3 of 8
(4,693 Views)

I'm relatively inexperienced with LabVIEW, could you explain the reason for making the enum(s) a type definition?

 

Yes there were a lot of local variables but I just quickly threw that model VI together to get the job done I guess.

 

I'll look into possibly making a QMH

0 Kudos
Message 4 of 8
(4,683 Views)

Thank you! I'll try that out when I get the chance.

0 Kudos
Message 5 of 8
(4,682 Views)

I'm relatively inexperienced with LabVIEW, could you explain the reason for making the enum(s) a type definition?

Type-defs

Basically all changes to all instances of the type-def are synced. Smiley Happy

 

0 Kudos
Message 6 of 8
(4,675 Views)

Hi Joey,

 

could you explain the reason for making the enum(s) a type definition?

With a typedefinition you only need to change the definition (like adding a new state/item to your enum) and all instances of this typedefinition automatically adapt to the changes!

 

Just count how many enum constants you use in your simple VI: when adding new items you would need to change them all - or just one typedefinition…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 7 of 8
(4,671 Views)

If you have a need for a long "wait state with abort" do something like this:

waitCapture.PNG

My "Stop" button will abort the timer. (after 10mS)

 

Also notice the time I leave the loop becomes my acquisition time stamp.  Using a shift register is fed to my acquisition state then fed back to the timer state to make up for acquisition time, keeping the acquisition intervales exact. 

========================
=== Engineer Ambiguously ===
========================
0 Kudos
Message 8 of 8
(4,638 Views)