LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

problem with double for loop

Hello i'm pretty new to Labview and i'm trying making a block scheme that makes speed profile by using 2 arrays.
So i made this project and i'm having problems with for loops (probably is trivial :D).

Basically when i start the code the first 2 couples of values of speed-time are bypassed and the codes procedes calculating the ramp of the speed with the third couple of values, then the fourth couple of values is bypassed to.

Where am i doing wrong?

zeta1928_0-1721395417930.png

 

0 Kudos
Message 1 of 10
(387 Views)

First, I'd recommend saving your attached VI in a previous version of LabVIEW so that more people will be able to view it.  LV 2024 is not something that many will have at this point.  That, or, save your code as a .png snippet and post.

 

If I had to guess as to why your first set of values are being skipped: if you are multiplying your values by one of the for loop iteration terminals, it may be returning 0 as a result since the increment starts at 0 and not 1.

0 Kudos
Message 2 of 10
(380 Views)
  • Please don't maximize the front panel to the screen,
  • Please explain the term "bypassed". that's very ambiguous.
  • Please make sure that all controls have typical default values before attaching so we can test. Currently all controls are zero or empty arrays. ( do you know how to do that?)
  • You have way too many local variables while terminals are not even connected.
  • I get the feeling that your entire functionality requires less than half a postcard of code.
  • Your inner FOR loop stops after the wired number of iteration or the comparison wired to the conditional terminal. Whatever results in fewer wins.
  • If you autoindex, you should not wire the array size to N. That's redundant.
  • Your two ramp cases differ by a single operations (add vs. subtract), and you could combine most of the other code.
  • If "Start" is false, you have a greedy loop that spins millions of time per second burning the CPU....
  • Your outer while loop cannot be stopped
  • etc.

Waiting for a new VI with all controls having values, a description of how you run it, and what you expect to happen.

0 Kudos
Message 3 of 10
(351 Views)

Wellll ok but this doesn't solve my problem... I know that my code is not perfect and can be improved but at the moment I only care that it works, then I will think about how to optimize it.
With 'bypassed' I mean that the first two pairs of speed and time values ​​are skipped without ramping inside the small for loops.

Essentially the code performs the speed ramp by reading the initial speed at t = 0 and the third pair of values.
If you run the code you can see it.

0 Kudos
Message 4 of 10
(276 Views)

Hi zeta,

 


@zeta1928 wrote:

If you run the code you can see it.


Well, if you would downconvert your code then more people would actually be able to run it!

 

General suggestion: Downconvert using File->Save for previous to LV2021 or older, I prefer LV2019…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 5 of 10
(269 Views)

Hi sorry i forgot to do this
Here you have 🙂

0 Kudos
Message 6 of 10
(267 Views)

Hi zeta,

 

you should not autoindex the "desired speed" and "time" arrays at your FOR loop!

Instead you should use ArrayIndex inside the loop and only index a new element when you want to start a new ramp…

(Due to autoindexing the first 3 speed/time values will be already "used" for the first 3 states of "start", "comparison", and "salita"/"discesa"!)

 

Additionally that FOR should be a while loop…

 

Btw. you also forgot to set some reasonable default values in those controls as requested by Altenbach!

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 7 of 10
(252 Views)

Sorry but I didn't quite understand.

How can I use an indexArray inside the loop? Once inside the loop I will already have a single value so I cannot use indexArray right?
Sorry so this is probably a trivial problem but I just started using labview 🙂

0 Kudos
Message 8 of 10
(242 Views)

Right click the tunnel and disable autoindexing. Then you get the whole array inside the loop.

0 Kudos
Message 9 of 10
(238 Views)

@zeta1928 wrote:

Hi sorry i forgot to do this
Here you have 🙂


  • Your VI still have empty arrays and zeroed as default values
  • Your front panel is still disorganized and mazimized to the screen,
  • You did not follow any of my advice,

 

You would not have a problem with "double for loop" (sic) if you would implement a proper state machine and use the outer while loop for all the spinning. That's all you need! You don't even need to distinguish between ramp up or down of you would use the same loop but a single increment (positive or negative, depending on end points)

0 Kudos
Message 10 of 10
(200 Views)