LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to Create an Array from Formula Node Output Values

Solved!
Go to solution

Well, those are formulas, alright.  What I was hoping for was some Math, including matrices, that would lead to what almost could be called an "understanding" of what you are doing.

 

For example, the matrix R (made up of 9 Rxx components) seems to be a 3D Rotation Matrix, but uses a slightly-non-conventional ordering of either axes or rotation order (trust me -- there are too many ways to specify rotations in 3D).  The vector X has a "spatial" part (the first three components) and a rotation part (the last three) -- instead of treating it as a 6-element "vector", with separate formulas for X1, X2, X3 not involving trig functions, and X4, X5, X6 involving trig functions (hence being rotations), it would simplify the logic to have a cluster of "offset" (first three) and "orientation" (last three).

 

Similarly, I found it interesting that you have a P vector and a B vector where you define 6 components, but do so in such a way that the B components go 1, 2, 3, 4, 5, 6, while the P components go 6, 1, 2, 3, 4, 5.  Really, would it have been such a problem to number them similarly?  Maybe by making the P offset of 60° go in the other direction?

 

I think I'm giving up ...

 

Bob Schor

0 Kudos
Message 21 of 33
(1,927 Views)
Solution
Accepted by topic author OzanGungor

I made a little bit of progress. First, I just made the inputs and outputs into arrays. Notice that this reduces the indices of the variables by 1.... so what you referred to as J11 is now J[0][0], etc.

 

This makes everything look a little cleaner, and it also makes it easier to notice small stuff... such as the fact that one of the BY values is different than the others. Maybe this is a typo?

 

The next thing I did is group the equations by their last index, rather than their first index. This makes it easy to see which equations are of the same form. For example, looking at the J[][2] family of equations:

 

J[0][2]=(2*X[2]+2*(R[2][0]*PX[0]+R[2][1]*PY[0]))*(1/(2*L_SON[0]));
J[1][2]=(2*X[2]+2*(R[2][0]*PX[1]+R[2][1]*PY[1]))*(1/(2*L_SON[1]));
J[2][2]=(2*X[2]+2*(R[2][0]*PX[2]+R[2][1]*PY[2]))*(1/(2*L_SON[2]));
J[3][2]=(2*X[2]+2*(R[2][0]*PX[3]+R[2][1]*PY[3]))*(1/(2*L_SON[3]));
J[4][2]=(2*X[2]+2*(R[2][0]*PX[4]+R[2][1]*PY[4]))*(1/(2*L_SON[4]));
J[5][2]=(2*X[2]+2*(R[2][0]*PX[5]+R[2][1]*PY[5]))*(1/(2*L_SON[5]));

 

These are so similar that they really should not be six separate equations. They should be one equation, solved six times (in a loop), with different PX, PY and L_SON values for each iteration of the loop. If we did that for all the equations, this whole thing would be a lot simpler and easier to maintain... and we might even gain some understanding of the underlying meaning of it all.

 

But, right now, I haven't the energy to tackle that. I hope this helps.

 

Array In and Outs.png

 

 

 

0 Kudos
Message 22 of 33
(1,918 Views)

Thanks a lot LandJBelenky,

 

It already looks like what I wanted to do in the beginning, with arrays as inputs and outputs. Looks much more simple and efficient indeed. Since I don't have much of an experience with Labview, can you tell me how did you defined the inputs ? Did you just create 6x1 arrays in the front panel and wired them as inputs?

 

Thanks a lot again!

0 Kudos
Message 23 of 33
(1,898 Views)

To make the inputs, you go to the block diagram, right click, and select 'Array' -> 'Array Constant.' This gives you an empty array.

 

An array can be an array of just about anything (number, boolean, string, path, picture, cluster, etc...) So you have to tell it that you want this to be an array of number.  To do that, add a numeric constant to the block diagram (Right click, Numeric, Dbl Numeric Constant.) Drop that on the block diagram and then drag and drop it into the empty array. You can then resize the array and fill in the numbers you want.

 

In the new version of LabVIEW, you can just place the numeric constant and then right-click it and pick 'Change to Array.' That saves a step.

 

 

0 Kudos
Message 24 of 33
(1,885 Views)
Dear LandJBelenky,
One more question, I would like to do the following calculation.
The output  values F and J will be multiplied and then will be subtracted from the input X value; and the result will be X again. "X = X - J*F" I have converted my J and F outputs to matrix with Array2Matrix block and did the equation but how to equalise it to X again? I've tried feedback block but couldn't sort it out. It will be inside a loop as I guess.
Thanks, 
0 Kudos
Message 25 of 33
(1,862 Views)

Hocam eşitliğin diğer ucuna X dediğin kontrolün üstüne sağ tıklayıp, create-Local Variable-Yapacaksın. Böylelikle işlem sonundaki değer X' tekrar atanmış olacak.

Add 273 on whatever Celcius said.
-Kelvin
0 Kudos
Message 26 of 33
(1,848 Views)

Merhaba, fotoğraf ya da basit bir VI koyabilir misin lütfen tam anlayamadım? 

Teşekkürler.

 

Bu şekilde mi?

0 Kudos
Message 27 of 33
(1,841 Views)

Aynen öyle hocam. 

Add 273 on whatever Celcius said.
-Kelvin
0 Kudos
Message 28 of 33
(1,833 Views)

In general, people try to steer away from local variables. A local variable will change the value of an existing control or indicator, so you can use it to alter the value of an input, but it doesn't turn that input into an output. Also, if you're not careful about when and how that value gets changed, you can end up with what's known as a 'race condition' in which you can't really predict which value will be there at any given time.

 

In this case, it sounds like you want to have X as an input, and then a modified X as an output. The standard way to do this is to have "X in" as a control and "X out" as an indicator. That way, if this is a sub-vi, the data flows in, through, and then out, of the VI.

 

Generally, this is very easy to do, and it's the standard approach.  The only thing that is giving me trouble now is that I want to make sure I'm doing the matrix math correctly. Check my work: J is a 6x6 matrix and F is a 6 element vector. So multiplying these together yields a 6-element vector.  X is a 6-element vector, so when you say you want X-J*F, you want a 6-element vector of X[0]-(J*F)[0], X[1]-(J*F)[1], X[2]-(J*F)[2]... etc?

 

You don't need a loop because you can perform basic math functions (+,-,*,/), directly on arrays.

 

The attached should do this.

 

 

0 Kudos
Message 29 of 33
(1,831 Views)

Well yes, the calculation nodes seems as I want to do (X=X-J*F), however, I don't want a different output such as Xout, I want the result of my calculation (x out as you referred in your VI) to be my new X values and take place inside the formula node values X[0],X[1]....X[6]. 

 

So I give the equations  6 initial X values and it solves the equations according to Formula Node, then from outputs it calculates the nex X values and put it to equations again and calculates the new J,R values.

 

Of course, there will be a loop covering all, to tell how many times I want this run through.

0 Kudos
Message 30 of 33
(1,828 Views)