LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Need Help

Solved!
Go to solution

Dear Labview Community, 

I am constatly facing two issues with my Labvew code  -

 

1. My q_dot matrix in the code is not giving result, though it should give. (I checked multiple times)

2. I wanted to increment the dt value from 0 to T at a particular time instant using let say 0.02 sec.

3. I wanted to execute the loop at frequency of 200 Hz.

 

Looking froward help from community. 

Download All
0 Kudos
Message 1 of 12
(924 Views)

Since you're using lots of Local variables it screams Race Condition.

Race condition - Wikipedia

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 2 of 12
(896 Views)

what shall I do to avoid the Race codition ? 

0 Kudos
Message 3 of 12
(883 Views)

Connect data with the wires so you know what state it's in.

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 4 of 12
(879 Views)

I am only using local variables for some parameters which is need for other calculation. You are asking me to connect each and every parameters from the source instead of using the local varible.

0 Kudos
Message 5 of 12
(866 Views)

@rishab_kr wrote:

I am only using local variables for some parameters which is need for other calculation. You are asking me to connect each and every parameters from the source instead of using the local varible.


Yes.

As you've done it, there are lots of race conditions.  I wouldn't expect it to work.  Learn how to code using dataflow.

Also, your block diagram is way too big (and you've got a superfluous sequence).

"If you weren't supposed to push it, it wouldn't be a button."
Message 6 of 12
(855 Views)
Solution
Accepted by topic author rishab_kr

You will greatly benefit by applying some basic "Good LabVIEW Style" guidelines to your Block Diagrams.  Here are a few important starters:

  • Keep your Block Diagram small enough to fit on a Laptop Screen (formerly 640 x 480, now 1920 x 1080, about 8 times the area).
  • Make your wires run left-to-right, with as few bends as possible.
  • Use the Error Line to "serialize" your code.  Most functions and almost all VIs should "sit" on the Error Line (lower left/lower right of 4-2-2-4 connector pane).
  • Use Sub-VIs to "hide the messy details".  Give the sub-VIs "meaningful names" and an Icon (even a Rectangle with 2-4 short words).

For what you are trying to accomplish, I would recommend something like a State Machine (perhaps something as simple as a While Loop surrounding a Case Statement, with the Loop Index, "i", wired to the Case Selector and the "Cases" being "0", "1", "2", ..., <last case #>, "Default", where the "Default" "catches" all the numbers you don't specify.  Note that when this runs, it automatically does the "steps" from 0 to <last case #>.

 

As for your variables, put a bunch of Shift Registers up at the top and use them to "hold" the Variables.  Wire them "through" the Case Statements.  Because they are on Shift Registers, they will all hold "the latest values" of these variables, there are no "race" conditions, all the Variables are in one place and easily visible to any Case, and if you want to do an operation (say, add A to B and put the result back in A, leaving B intact), you put in "Add" in the appropriate "Case", drop a wire from the "A Wire" and "B Wire" to the input of the Add, delete the wire going to the Case output tunnel for A, and wire the output of the Add to that tunnel.  Of course, you can do multiple arithmetic operations in each Case, and you can also organize it so you do, for example, all your "Build Matrices" in one Case, your "Use Matrices" in another, etc.  

 

Note that there are more "elegant" ways to do this, but this should get you started thinking about Data Flow programming, on which LabVIEW is based, with (for LabVIEW) the data "flowing" in the wires.

 

A Clean Block Diagram is so much easier to create/build/use/debug/understand than a chaotic mess.  Data Flow Is Your Friend!

 

Bob Schoe

Message 7 of 12
(846 Views)

Thanks Bob, For your time and letting me know about the mistakes I should take care of. I am bigginer to Labview, as I have shared my labview code can you point out the mistakes that I am doing. I understand a bit in above replay.

Thanks Again.

0 Kudos
Message 8 of 12
(828 Views)

Hello Ni Community,

 

I need your help, In the attached VI finally I am calculating the q_dot matrix by multiplying the x_dot matrix by the pseudo inverse matrix. Ideally It should give an output of 2*1 matrix but, it is not giving any result. 

 

It would be a great help if anyone let me know where I am making the mistake. 

0 Kudos
Message 9 of 12
(735 Views)

Hi rishab,

 

you forgot to attach the subVIs to your VI. And I guess your last question is related to your other thread, so I merged them…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 10 of 12
(699 Views)