Thread: waits
View Single Post
  #1   Spotlight this post!  
Unread 05-02-2012, 09:15
Greg McKaskle Greg McKaskle is offline
Registered User
FRC #2468 (Team NI & Appreciate)
 
Join Date: Apr 2008
Rookie Year: 2008
Location: Austin, TX
Posts: 4,752
Greg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond repute
Re: waits

In your situation, a wait will do.

A wait node in LV works as follows:
Once its inputs are available, it notes the time, adds the delay to it, and sets an alarm for delay milliseconds in the future. The node will not be considered complete (it is executing, but without using the CPU), until that alarm goes off. Any dependent code is postponed, and parallel code is not.

Now the reason that it impacts loops and sequences the way it does is because of the most commonly overlooked element of LV -- the diagram. The open space on the window, the white background of the loop and sequence is the same as the {} bracketed code within other languages. The while loop's diagram is not complete until all nodes on it are complete. Same for sequence and other structure nodes that contain a diagram. Executing a diagram consists of executing all nodes it contains once and only once, and it is not complete and cannot execute again until all the nodes complete execution.

For example, I attached an image of a loop with various parallel things going on inside it. They are the i (which some may not count and may even be compiled out), the Bool wired to the loop continuation (similarly trivial), and the three waits (two for 1000ms and one for 500ms).

When the loop starts to execute its diagram, it will allow all of the parallel tasks to proceed at their own rate. So in this case, the three waits will run in parallel and the overall loop rate will be about 1Hz. If additional code is inserted into the loop that reads sensors or computes math, and it runs in parallel, it will not impact the loop rate unless the code takes longer than 1000ms to complete.

The second image shows how to run code before and after a delay, make sure there is an execution dependency -- either a data flow dependency or as shown in the image, a sequence dependency. The third image shows another common usage where you want to start something, not waiting for it to complete, and 500 ms after starting it, start something else.

I hope this helped.

Greg McKaskle
Attached Thumbnails
Click image for larger version

Name:	Screen Shot 2012-02-05 at 7.22.08 AM.png
Views:	63
Size:	8.6 KB
ID:	11732  Click image for larger version

Name:	Screen Shot 2012-02-05 at 7.58.46 AM.png
Views:	71
Size:	10.4 KB
ID:	11733  Click image for larger version

Name:	Screen Shot 2012-02-05 at 8.14.14 AM.png
Views:	69
Size:	10.5 KB
ID:	11734  
Reply With Quote