LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

State Machine Between Three Cases

Hi,

 

I'm currently making a vi that allows one to move stages using sliders or adding input values (if known). The only problem I have though is creating a program that is able to switch between three cases rather than 2 (I currently have the vi set up to select between 2 controls, a speed and motion adjustor. I'd like to add one more). I wasn't sure if this included arrays of some sort which I am not too familiar with. Any help on this would be greatly appreciated. Just let me know if you need more info. I'm currently using LabView 8.5. 

0 Kudos
Message 1 of 12
(4,438 Views)

All you need to do is right click on the enumumerated value for the states and edit items. Then when you have done this right click on the case structure and add a case for eveyvalue See snippit.

 

19307iFC57559B36BF4E09

Tim
GHSP
0 Kudos
Message 2 of 12
(4,416 Views)

Perhaps I'm not giving a good basis for things, for I'm not really sure if you are answering my question. I've fixed up the code a bit, and I think it shows what I need. What I'd like is for a user to be able to switch between functions (currently there are 3) without switching the program on and off. For instance, I'd like to move a stage, then change it's speed, and then move back without having to stop.

0 Kudos
Message 3 of 12
(4,407 Views)

can you post your new code?

 

Tim
GHSP
0 Kudos
Message 4 of 12
(4,405 Views)

You need to make your default state do nothing. I would put an event structure in it so that it waits until you have changed a control or slider.

Tim
GHSP
0 Kudos
Message 5 of 12
(4,403 Views)

Ok I figured it out. Thought i'd post it just in case anybody had something remotely similar to this.

0 Kudos
Message 6 of 12
(4,387 Views)

Get rid of the stacked sequence structure and use a state machine.  This would make the code much easier to read, and would also result in making any changes much easier to do.  You need an event structure to capture Value Change events for your enum.  When the user selects a different enum value, the Value Change event could put the next state on the queue or shift register, depends on which type of state machine you use.  The states can be built to handle any code that is in the stacked sequence.  To add another enum selection, like you are trying to do, you would simply edit the enum to add another item,  add cases to handle the new code, and edit the event case to point to the first new case added for this function.

 

When coding the state machine, you may be able to combine frames from your stacked sequence into one state.  See the attached example.  Fill it in with your own code.  Hopefully you will get the idea.  This will make it so much easier to add more selections in the future.

 

- tbob

Inventor of the WORM Global
0 Kudos
Message 7 of 12
(4,372 Views)

@AsianChef wrote:

Ok I figured it out. Thought i'd post it just in case anybody had something remotely similar to this.


You should put a delay (Wait(mS)) inside your loop or your program will hog the CPU using 1005 of the CPU time (unless you have a multi core, but still it hogs the CPU).  Putting a small delay prevents CPU hogging and won't affect your code.  Your front panel has duplicate controls, making it more difficult to use.  I suggest using tabs.  One tab for each enum item.  You put the pertinent controls on each tab page.  The user selects the tab he wants to use, and all of its controls are on that tab.  No confusion as to which controls belong to which function.

 

I would still look into the state machine idea I showed in my last post.

 

- tbob

Inventor of the WORM Global
Message 8 of 12
(4,365 Views)

Hey tbob,

 

Thanks for the pointers. I try to stay away from sequences, but in this case, I find it easier for what I'm trying to do. I've actually already changed a lot to what I had popsted before since I'm not the type to wait for answers on here.

 

By chance would you be able to convert the file you posted for LabView 8.5? I would still like to see what you did since I'm still learning as much as I can about Labview.

 

Thanks also for the wait time comment; I tend to forget about those 😕

 

And I'll definitely use tabs. This is actually just a part of grander scheme.

 

 

 

0 Kudos
Message 9 of 12
(4,338 Views)

This is really wierd.  Whenever I try to save for previous version, Labview crashes.  Save my VI, and post it to the Downconvert VI Request thread.  maybe someone there will have better luck than me.  Sorry.

 

- tbob

Inventor of the WORM Global
0 Kudos
Message 10 of 12
(4,324 Views)