View Full Version : Wait.VI on basic motor tutorial, need clarification.
01-12-2009, 07:38 PM
On the following URL: http://decibel.ni.com/content/docs/DOC-3014
Near the middle/bottom of the page you can download the .pdf of the tutorial. We can't use the video for clarification because of our school's site blocks. On page 9 in the 3rd to last sentence it tells you to put a 10ms wait on the while loop. The tutorial doesn't explain how to do this. We assume it has something to do with the Wait.VI given with the FRC software. Can anyone explain if that’s the correct thing to use for the wait and how to implement it into this code?
Comatose Team 135
01-12-2009, 09:43 PM
The wait.vi used in the video is used to sleep the code (thread) running in the while loop for a short period in order to allow the processor time to complete other OS tasks. It is good programming practice to place these in all while loops.
The most common symptom of "starving" threads on the cRIO will be a loss of network connectivity. This would be due to your program consuming 100% of the CPU preventing the network thread from running.
01-12-2009, 09:47 PM
In LabVIEW, EVERYTHING runs in parallel as long as its inputs are ready (and as close to "parallel" as a single-threaded machine can really be).
If you have a while loop that keeps repeating, the innards will execute as quickly as the machine can operate unless you force the loop to execute at a fixed rate.
There are a number of ways to force loop timing in LabVIEW but the easiest are using "wait.vi" and "wait until ms multiple.vi". If you place either of these within your while loop, a new parallel process is created in your VI. The loop iteration cannot end until that wait routine is done. So... if you've got a little snippet of code that executes in 1ms and a wait VI with a 10ms control input, your loop iteration will start at t=0 and, at t=1ms your code will finish then at t=10ms the iteration will be done and will restart (if that's warranted based on the conditional for the loop).
To really understand how the above works, I'd encourage you to create a while loop that's set to execute forever and plop down 2 wait VIs - one with 500ms timer and one with a 1 second timer. View the output from the loop's iteration counter (right-click - create indicator on the the "i"), turn on highlight execution mode and then click run. Watch how the two wait VIs operate in parallel and how the 1 second wait VI rules.
The relatively new Timed Loop construct can really help as well. It's not too hard to use and provides some nice features (eg did my loop actually run as fast as I requested?).
My final comment - a while loop without any delays can be a SERIOUS CPU hog. If you create a simple while loop on a PC, it could run at a few MHz and won't allow you to do anything else on your PC while it's running.
01-16-2009, 12:00 PM
We understand what the VI does and why it should be done but the website gives no directions nor pictures to help explain how to use it. It just says use it on the while loop. Were dumbfounded and have no idea how to attach it to the while loop.
Can anyone give directions how to do this?
01-16-2009, 12:10 PM
Just put it anywhere inside the while loop. It does not need to be attached to anything besides the input that specifies the amount of time you want the loop to wait. If you care about the wait running before or after the rest of the code in the loop, you will need to add a sequence structure, create two frames, put your code in one frame, and put the wait in the other frame.
01-16-2009, 01:18 PM
I've attached a really simple VI (unfortunately with LabVIEW 8.2 so I created a PDF of the block diagram).
It's a while loop that runs forever and just increments a number. The Wait VI forces this loop to execute every 10ms. Without that Wait VI, this would run stupid fast and hog the CPU.
Please try using Highlight Execution mode. It really helps (IMHO) to understand how programs flow in the LabVIEW world. In this particular instance (if you could run it), you'd find that the Wait VI and the increment function operate in parallel. Any other functions that are dropped in the while loop will operate in parallel as long as they don't share data/wires.
01-16-2009, 01:20 PM
How does the wait.vi effect the watchdog? Do you need to use a "Delay and Feed" with the watchdog, or can you simply put a standard delay in the loop?
vBulletin® v3.6.4, Copyright ©2000-2018, Jelsoft Enterprises Ltd.