10-01-2017 10:44 AM
Hey, guys, I need some advice.
I've got a state machine which will run on a real-time system. In it, there is a case that should decide what the next state is. The decision should be based on a couple of int values, some boolean values, and a string. The output should be a string of the states which should follow.
I'm still relatively new to LV but it seems rather complex to create multiple multi conditional if statements using the graphical blocks.
That is why I'm not sure whether to use the formula block or use an external DLL or maybe there is an even better way to solve my problem.
But I think I would have a hard time with the formula block and the strings. So I'm tending towards implementing my function in some C code.
Any suggestions?
Thanks for the help.
Daniel
10-01-2017 11:10 AM
Hi schpongo,
but it seems rather complex to create multiple multi conditional if statements using the graphical blocks.
Why should it be more "complex" than using textual programming?
Hint: There is the CompoundArithmetic being able to do also boolean arithmetic on multiple inputs…
10-01-2017 11:47 AM
schpongo wrote:The decision should be based on a couple of int values, some boolean values, and a string. The output should be a string of the states which should follow.
I'm still relatively new to LV but it seems rather complex to create multiple multi conditional if statements using the graphical blocks.
That is why I'm not sure whether to use the formula block or use an external DLL or maybe there is an even better way to solve my problem.
But I think I would have a hard time with the formula block and the strings. So I'm tending towards implementing my function in some C code.
I guess the question is "How many states do you actually have". Once you have a couple of booleans, integers, and strings, you get a combinatorial explosion of possible outcomes. I doubt you want a case structure with millions of cases. 😮
Can you give an actual example of the calculations involved?
And yes, I agree with Gerd that if the complexity is in the task itself, the programming language is irrelevant to the complexity. Most contributors here are LabVIEW programmers and my guess is that a pure G implementation is probably the best. I definitely would go with LabVIEW. Explain the problem and we will show you how.
10-02-2017 02:00 AM
Here are the variables and a brief description of them:
I only have 6 states and have mapped out a couple of scenarios on paper.
Here is an example:
if( Last_case== update && move_complete==true) { next_case="sart_contour","Read"}
else
if( Last_case== update && move_complete==false) {next_state= "Read"}
else if( Last_case==compare && #Elements_fifo===99 && Parameter_Const==true){next_state=''add'',''create poly'',}
and I've got quite a few more depending on which case I'm coming from.
I hope I've managed to clarify my problem at hand and not make it too confusing.
Even though in my opinion it is not elegant to use a DLL as it is more difficult to read and edit, but I feel like many if conditions are very easy to implement in a written language.
But I might be wrong. If someone could maybe point me to an example of how this could be handled, I would be very thankful.
10-02-2017 02:40 AM - edited 10-02-2017 02:43 AM
Hi schpongo,
the "LastCase==" comparison reduces to a case structure with LastCase wired to the selector input. I hope you have created an enum type definition for this data type...
In the "update" case you only have to check your MoveComplete condition once to handle both first and second IF statement...
10-02-2017 07:58 AM
Uh good input there.
I didn't think of replacing my strings with an enum, as my state machine is base on strings. But if I convert the
But if I convert the strings to an enum and the booleans to 0 and 1 I might be able to the formula block.
For multiple output strings, I could store the enum in an array and convert that back into strings.
10-02-2017 10:38 AM
I personally like string-based state machines. They can be harder to debug if, for example, you make a typo when selecting a state. But there is a lot more you can do with a string based, IMO. I recommend that you have a gander at the JKI state machine. When you open it up, it may be a little intimidating at first but just throw the VI into highlight mode and watch it go. And then mess with it a bit to see how it operates. Make it go to a state that doesn't exist and see how it handles a typo.
10-02-2017 11:01 AM
Hi schpongo,
I don't like to convert booleans to 0/1 just for "cosmetic" reasons…
Your statement
if( Last_case== update && move_complete==true) { next_case="sart_contour","Read"}
else
if( Last_case== update && move_complete==false) {next_state= "Read"}
could be reduced to
switch Last_case "update": IF move_complete THEN next := [sart_contour, Read] ELSE next := [Read] ENDIF "other cases":
… end_switch