03-21-2013 04:52 AM
Hello everyone, I am a new in labview, and here are some simple questions related with structure and loop, hoping you would please do me a favor to give me some instructions, and that will be very nice of you all!
1. May I just put a while loop inside an event structure so that when a button called 'calculate' is pressed, the while loop will be executed until a condition is acheived, then the output will be shown on the array controller on the front panel? Coz after reading different related post, I am now getting confused whether I am able to do it.
2. If I have different controllers, ex. controller c1,c2,c3,c4 and different buttons B1, B2, B3 on the front panel. For example, for ALL controllers, ex. c1 and c2, I would like to use it sometimes as a input when I press B1, and then the calculated output will be shown in c3, and then press B2, the further output will be shown in c4 and c1, and c2 and c3 will return to zero. By pressing B3, the current value of c3 and c4 will be used to generate and show the new value of c2, and then press B2 again, the further output will be shown in c4 and c1, and c2 and c3 will return to zero.
I hope it will not be too complex to understand, anyway, in that case, should I put all the elements (case structure, formula node.....) inside a while loop the block diagram, and also create a stop button to control the loop even though I do not need to use the stop button?
3. When I use the formula node, I would like to create a array inside, and then output it to a array indicator shown in the front panel, however, when I add the output on the boundary of the node, sometimes it is orange but sometimes it is blue. When it is blue, it is quite ok; but when it is orange, it always shows the error that I can not link my calculated output array to the array indicator:
These cannot be wired together because their data types (numeric, string, array, cluster, etc.) do not match. Show the Context Help window to see what data type is required.
The type of the source is double [64-bit real (~15 digit precision)].
The type of the sink is 1-D array of double [64-bit real (~15 digit precision)].
So I wonder does it mean that I can not use formula node to create the array without input any already built array? But if yes, how to solve the problem since the element number of the output array is really large and it is not good to output them separately one by one?
4. I wonder whether there is any operations on how to generate a Jacobian matrix containing the partial derivatives of nonlinear multi-variable (9) equations (9) in a formula type and then I can eval it with input variable values? Or any recommendation or solution?
Looking forwards to hearing from you soon!
Have a nice day and best regards!
03-21-2013 07:50 AM
1. No, a while loop inside the event structure is probably not a good idea. No other events will fire until the loop completes. You might need parallel loops or put the while loop in a state machine with so way to break the loop (e.g. the user wants to stop the program)
2. Hmm.. not sure what you're talking about. Can you post some code?
3. The node color is based on the data type. If the data type is wrong, then you probably have a syntax issue with your formula node. Again, post your code, we'll take a look at it.
4. Do you have the LabVIEW Control Design and Simulation Module? You may need it.
03-21-2013 09:54 AM
thanks vt92~
Just the first question, if I understand correctly, do you mean that the reason that we can not put while loop inside a event structure is only that every other action will stop until while loop completes? Since in my case, since there are different events in the structure, but they do not run in parellel, which means I will use the event structure just to start the while loop until I get the output shown in the controller in the front panel. Like what is shown in the attachement.
Therefore, if there is no action that the user will do when the while loop calculates, may I still use the while loop in event structure?
03-21-2013 10:13 AM
Yes, from a technical stand point there is no issue with a while loop inside an event structure. The issue basically is that event structures are generally used to handle the UI of an application. Any processig that occurs within the event structure will impact the responsiveness of the UI. If the processing takes less than 100ms to 150ms the user generally does not notice any lag in the UI. Longer processing starts to impact the UI and the user will see a lag in responsiveness.
03-21-2013 10:25 AM
Also for the 3rd question, but there will be no error shown when I firstly link the output array to the function 'build array' and then to the array shown on the front panel. Pls check the jpg attached.
For the 4th question, I am sorry that my version installed does not have that module. So does it mean that I hve to create the jacobian elements one by one?
03-21-2013 10:29 AM
As long as your calculations converge, I don't see any issues with putting that code in the event structure. Here are a couple of things you might want to concider to make life easier on you:
1. Put the while loop code into a subVI. It'll take up a lot less space and you can reuse it elsewhere.
2. Put in a limit on how many times the loop can iterate. Actually, turn it into a FOR loop, make the termination terminal visible and terminate as you currently do. But wire in something like 10 to the N so that the loop doesn't just run forever.
03-21-2013 10:41 AM
In your formula nodes declare the array as floats, not int32.
03-21-2013 10:44 AM
@sophiey wrote:
Also for the 3rd question, but there will be no error shown when I firstly link the output array to the function 'build array' and then to the array shown on the front panel. Pls check the jpg attached.
For the 4th question, I am sorry that my version installed does not have that module. So does it mean that I hve to create the jacobian elements one by one?
I think you want your declaration to be
float64 Ax[6];
You will need to figure out the formulas for the Jacobians.
03-21-2013 10:50 AM - edited 03-21-2013 10:58 AM
(1) You can put any kind of code inside an event structure with the limitation that it should be able to complete quickly and without user interaction. For example a while loop for a newton-raphson method is fine, but an interactive while loop where the stop condition depends on user iteraction is not recommended. By default, event structures lock the front panel until the event completes, so you would not even be able to stop it.
(2) Yes, you can do all that. LabVIEW has no limitation as a programming language. Use shift registers to hold data and state information, the manipulate the contents as needed.
(3) I would recommend to use plain LabVIEW primitives instead of formula nodes. Show us your code so we can better see what it's all about. Obviously you have a mismatch betweeen scalars and arrays. It is impossible from the given information where the problem is.
(4) Yes, look inside the nonlinear curve fit VI (you can open it an inspect the code!). One of the subVIs does exactly that. Just supply your model VI.
03-21-2013 10:58 AM - edited 03-21-2013 11:05 AM
sophiey wrote:Therefore, if there is no action that the user will do when the while loop calculates, may I still use the while loop in event structure?
Please attach your actual VI, or at least clean up the diagram before posting a code image. Many of your wires overlap or are hidden underneath structure boundarries and it is impossible to tell where they go.