ā12-03-2010 11:00 AM
Hi,
I'm trying to implement a state machine to control input and output analog signals.
To reduce the wires, I think used two clusters, one to control the analog output, and another to control the analog input.
When I try that, a problem surged, how can I separate the elements of the cluster in the front panel?
I used the manner see in the picture, but I don't know if it's a good manner! And I notice also that I can't modified the value in another point of the program, because it's out of the while.
Some of the controls are just used in one state of the machine, but some of them should be used in more then one state, should I use one cluster without sift register, and another with that?
I hope you can understand my english, and can help me.
Thanks,
Silvia
ā12-03-2010 11:07 AM
Code looks fine.
If you properly design the clusters, you can possibly use a cluster indicator on the front panel directly. No separations needed. Else unbundle for indicators and bundle for controls. Use a value change event on the control, then bundle in that event case.
Everything needs to happen in the toplevel while loop, so make sure it contains the shift register. You can modify any element using "bundle by name".
ā12-03-2010 11:22 AM
Here is an example state machine that I often use as a starting point. It has a cluster or variables that can be used in any state. One of the states shows how to unbundle an element, change its value, then bundle it back so its new value gets passed along to future states. Hope this helps.
ā12-03-2010 11:45 AM
Hi,
Thanks for your quick reply, you are amazing.
But another doubt surged! What's "value change event", how can I do that?
Tbob, can you attach the vi in version 9?I think that will help allot.
Thanks,
Silvia
ā12-03-2010 12:13 PM
Attached as version 9.
Value change is an event. Look at the event structure. If you right click on the border, you can select Add Event Case. In the window that pops up, in the second column, select the control you wish to have an event for and then select Value Change in the third column. When that control's value gets changed by the user, the code in that case will execute. As you can see, there are many events, like Mouse Down, Mouse Up, etc....
The value change event will only fire if the user changes the value with mouse or keyboard. If the program changes the value (writing to a local variable), the value change event will not happen. If you want it to happen, you have to wire a new value to the Value(signal) Property Node for that control. Right click on the control to create a property node, and select Value(sgnl). Then wire a value to it. When that part of the code executes, the Value Change event will fire just as if the user changed it with mouse or keyboard.
ā12-14-2010 11:06 AM
Hi,
I try to make a simple example to understand the use of the queues, event structure and state machine. But this is a mess!
I looked somewhere else that queue state machine are not good. How can I stop the state machine?
What is wrong with the queue? The data don't pass through it!
Thanks for all your help
SĆlvia
ā12-14-2010 12:16 PM
Why do you have two different queues?
The consumer loop will need to get an element in both queues before the case structure runs. As it is right now, you only enqueue an element for data in one event, and only enqueue an element for Stopping in another event. Your consumer loop should only have a queue to work off of. Create a command enum that is part of your cluster. That includes the command and the data. One command would be Stop. Another command might be UpdateData. The appropriate case can then dequeue the data as necessary.
Look at this thread. queued state machine question
ā12-14-2010 12:17 PM
@sreis wrote:
Hi,
I try to make a simple example to understand the use of the queues, event structure and state machine. But this is a mess!
I looked somewhere else that queue state machine are not good. How can I stop the state machine?
What is wrong with the queue? The data don't pass through it!
Thanks for all your help
SĆlvia
First of all, there is nothing wrong with using a queued state machine. They work quite well. In your vi, the top loop, you have all terminals on the right set to Use Default if Unwired. Don't do this. Right click on each terminal and uncheck this box. Then wire something to each terminal. If not used, just wire the corresponding terminal on the left to the one on the right.
Next, add a timeouot value to the hourglass (top left corner).
Next, Use Error In and Error out to indicate any errors. Error wires should go through shift registers on any loops to propogate errors from one loop iteration to the next. In fact, put the error ins and outs before you change the Use Default if unwired terminals and you will see the errors.
In the bottom loop, in the stop case, wire a True constant to the terminal, not the dequeue element.
Your use of queues is improper. The bottom loop must see a dequeue output from each queue in order to execute the case structure. Yet you do not enqueue both queues in all cases. The bottom loop gets stuck and never stops.
Instead of using two queues, put a stop boolean in the data cluster and use it to stop the bottom loop.
ā12-14-2010 01:36 PM
Hi,
I try to modify the vi like you said, but I don't know if I understand everything.
The program seems work better, but not everything is good.
Now I use only a queue, because I put the stop in the cluster, but if in the front panel the data and the stop are separated?
I receive always an error when I stop the program, how can I eliminate that error?
Thanks for all your help
SĆlvia
ā12-14-2010 01:43 PM
Your queue is being released before the Consumer loop dequeues the 'Stop' command. You could simply wire the error terminal somewhere and ignore the error (yuk), but I would consider adding some dataflow (ie. error wires and merge errors) so that the release queue happens after the consumer loop has finished.