LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Selecting state machine architecture to enable user input

Hello!

 

I have recently started developing an application and currently I am stuck in the architecturing stage. I want the state machine to have the following states.

 

Capture.PNG

The state machine will start in the first state and will move into the idle state.

 

What I want to do (but I havent figured how to do it yet) is to force the SM to run in the Idle state until the user sends a command (in this case either run or shutdown). I would like to have the same behaviour in the Run state. The "problem" is that these states would have several while loops running inside, and this is what is driving me mad 🙂 

 

So I was thinking about what would be the best architecture but I couldn't think about the best design. This is what I have thought so far:

a) SM with 4 states (init, idle, run & shutdown)

 

b) SM with 2 states (init & other)

Event structure (idle, run & shutdown)

 

c) Queued SM

 

The problem I find and dont know how to solve is how can I stop all the while loops inside one state and force to move to the next one. Maybe should I use dynamic user events with one of the previous architectures?

 

What would be your suggestion?

 

Thanks,

0 Kudos
Message 1 of 8
(3,073 Views)

Depending on your requirements, a simple Global variable could solve it. Else you can use User events, Occurance or similar.

 

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

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 2 of 8
(3,056 Views)

It's hard to say without seeing your code. Typically you would not have any while loops running inside your states. If you look at what is going on in those loops you will likely find that you have additional states for your state machine since the states that you have defined so far a very high level.

 

If you need to have different loops running in parallel then a queued message handler is often a nice option. You could then just send a message to each loop to shut down. 

0 Kudos
Message 3 of 8
(3,041 Views)

@Kalandrak wrote:

The "problem" is that these states would have several while loops running inside, and this is what is driving me mad 🙂 


This almost makes me think you should be using the Actor Framework.  I am not personally a fan of it since it feels like too much OOP, but what you describe here is what it was designed for.



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
0 Kudos
Message 4 of 8
(3,037 Views)

I would attach my code, but at this moment, I am thinking in the architecture and havent done any coding yet (as I am not sure which solution could I implement).

 

It is true that if I put a while loop then is not a real state machine, but it is the only way I have found to suit my application.

 

I will add some more information about my application, maybe it would lead to a change in the overall architecture. This application would be deployed to a target, hence the initialization and shutdown states to correctly operate the device.

 

The state machine is in idle, until it receives a signal to start the test.

Then the test runs and after a certain time stops and gets back to idle state.

Here the key point is that during the test, I would like that the user is capable of aborting the test and returning back to idle.

 

And then in idle, select to run another test or shutdown safely.

 

Would you advise using a queued message handler inside the idle and run states? (or maybe is not good practice?)

-----------------------------------

 

At this moment, I am exploring user events and notifiers in order to be able to force to stop the while loops.

 

I will also explore the Actor Framework (although I have never heard of it). Thanks!

 

0 Kudos
Message 5 of 8
(3,020 Views)

@Kalandrak wrote:

It is true that if I put a while loop then is not a real state machine, but it is the only way I have found to suit my application.


You put the code inside of the loop as a state.  You can repeat a state until the right parameter is reached.



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
0 Kudos
Message 6 of 8
(3,016 Views)

@crossrulz wrote:

@Kalandrak wrote:

It is true that if I put a while loop then is not a real state machine, but it is the only way I have found to suit my application.


You put the code inside of the loop as a state.  You can repeat a state until the right parameter is reached.


Yes, you already have a while loop. You do not need another.

0 Kudos
Message 7 of 8
(2,999 Views)

If you want a good architecture, i would suggest that you can use a SM principle like JKI SM.

 

This SM is just a reference for your design. This SM is well suitable for host apps, but for RTOS apps you can design in your own way like how they are doing with Enum Data Types.

 

0 Kudos
Message 8 of 8
(2,984 Views)