03-11-2010 05:01 PM
Hi all,
I have a state machine, and one particular state is pretty busy. I want to loop that state a few times. I thought of the following, but I don't like them. Let me know if you have a better idea.
1. Add a shift register as a counter for the state. The state will keep looping to itself, while decrementing the counter. If the counter is zero, it will go to the next state. If not, it will keep looping. I don't like this, because I will have to add a shift register. If I have a few more state that need different number of iteration, I will have to add a counter for such state. My main VI will have way too many shift registers.
2. Add a for loop around the code in my case for iteration. I don't like it, since too many wires will be going in and out of the loop. I don't want to make cluster either.
Yik
Solved! Go to Solution.
03-11-2010 05:10 PM
03-11-2010 06:24 PM
One feedback node per counter that I need?
Yik
03-11-2010 07:10 PM
jyang72211 wrote:One feedback node per counter that I need?
Yik
Precisely. See this example, each state loops 5 times before moving on. Beats having 5 shift registers and all of those wires passing through the other cases.
03-11-2010 08:24 PM
03-12-2010 04:09 AM
Yik,
this depends a lot on the question:
Do you want to split the state into several iterations because you want to have a chance to interact inbetween?
If yes, the logic to determine the next state has to take into account:
Iterations finished? || Stop Iterations?
If the Iterations finished?-criteria depends on pure "amount of iterations", a loopcounter using a shift register or feedback node should work out. If you do not plan to "resume the iterations anytime", a single shiftregister/feedback node will work for any amount of split states.
If i would have to implement something like this, i would consider to "hide" that counting mechanism in an action engine. This will remove SR/FN from the state machine iteself but will provide the desired functionality.
If the Iterations finished?- criteria depends on some other stuff....well, it could get arbitrarily complicated (is this really an english expression???). But even in this case, moving the logic into an action engine could be a good idea....
hope this helps,
Norbert
03-12-2010 08:46 AM
Hi Darin,
I really like the counter that you attached. I like the fact that it reset itself when it is done. I also learned an interesting fact about the FB node from you code. It seems like when it is uninitialized, the initial value is assumed to be zero? I am right?
Yik
03-12-2010 11:35 AM
Hey jyang,
The default initialized value of a feedback node is 0. However, you can change this by initializing the feedback node yourself. To do this, just wire a constant to the Initialization Terminal of the feedback node. This is the node coming out of the "DOT" on the feedback node.
Cheers
Logan