Go to Post I used to be a FIRST Robotics mentor...then I took a Frisbee to the knee. - Travis Hoffman [more]
Home
Go Back   Chief Delphi > Technical > Programming > NI LabVIEW
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 16-04-2011, 04:31
cabbagekid2 cabbagekid2 is offline
Registered User
#0368 (Kika Mana)
 
Join Date: Jun 2001
Rookie Year: 2000
Location: Honolulu, HI
Posts: 85
cabbagekid2 has a spectacular aura aboutcabbagekid2 has a spectacular aura aboutcabbagekid2 has a spectacular aura about
Wait Function

We were wondering how the wait function works (the clock timer in periodic task). Initially we thought that the clock time is the minimum time that the while loop will wait to execute the next cycle (it will either be this time or the actual time it takes to execute all the code in the while loop - which ever is longer). However, using the elapsed time vi we see that even though we set the wait to 10ms the actual time shown in elapsed time the time is less than this (see screenshot it shows 2ms).

Can anyone clarify what is going on here? Thanks.
Attached Thumbnails
Click image for larger version

Name:	minimum.png
Views:	72
Size:	47.3 KB
ID:	10592  
Reply With Quote
  #2   Spotlight this post!  
Unread 16-04-2011, 09:38
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,751
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: Wait Function

Your definition of how things work is correct. The problem is with noise in the measurement.

The loop iteration in LV finishes when its contents finish. Thus it is gated by the slowest path through the loop. Placing a wait ms in the loop in parallel is a somewhat reasonable way to declare that the loop should take at least 10ms to execute, and it is pretty typical that it will result in a ~10ms or ~100Hz loop provided nothing else slows it down.

Looking more closely at the loop iteration, there are a number of parallel tasks inside the loop ...
1. False wired to loop continue
2. 10 wired to wait ms
3. nothing wired to the Elapsed Time
4. DIO Get
5. DIO Get
6. DIO Get

Then there is a bit of code dependent upon the outputs of the DIO Gets and the global update.

I labeled the initial tasks 1 through 6, but that order isn't fixed, or at least it isn't guaranteed to be. One explanation of your measurement is that subsequent loop contents are scheduled in different orders. On one loop call, Elapsed time is called last, and on the next loop call it is called first. On average, I suspect the timing is fine. Looking at a small sample like the single number of elapsed times, you'll see some, and apparently quite a bit of variation.

Also, you are using an early version of the Elapsed Times VI that returns a single measurement, with no statistical data to improve or represent the quality of the time measurement. I apologize for putting it out there like that.

In general, LV users don't worry that much about the parallelism of small things like this, but it can introduce noise in your timing. Since timing can be very important, LabVIEW Real-Time introduced a new loop structure with a more precise definition of loop time. It is in the subPalette at the upper right and is called the timed loop. It is more complex to use, but far more capable and precise about timing. The terminals on the inside right of the loop even include measurements about when the loop was supposed to start versus when it did start, when it was supposed to end versus when it did end, etc. The LV framework doesn't actually use any RT (real-time) elements in order to keep things simple.

We mentioned in another forum thread that we'll be doing a presentation in St Louis about the architecture, and this includes improvements to it. Perhaps next year, we should offer a realtime version of the framework?

To verify this explanation works for what you are seeing, run the code and you should see a blur of numbers that are typically closer to 10. You can add statistics to the Elapsed Times. You can put the code inside the loop in a sequence structure and call the Elapsed time before or after the contents of the loop. You can also modify Elapsed time to show a graph of the delays.

Feel free to post additional results if things seem fishy.

Greg McKaskle
Reply With Quote
  #3   Spotlight this post!  
Unread 16-04-2011, 10:46
Mark McLeod's Avatar
Mark McLeod Mark McLeod is online now
Just Itinerant
AKA: Hey dad...Father...MARK
FRC #0358 (Robotic Eagles)
Team Role: Engineer
 
Join Date: Mar 2003
Rookie Year: 2002
Location: Hauppauge, Long Island, NY
Posts: 8,795
Mark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond repute
Re: Wait Function

Here are some examples to help illuminate what Wait really does and how it and it's cousins (Wait Until Next Multiple & Timed loop) affect loop timing. Some of the descriptions are probably over simplified.
TimingIsEverything
__________________
"Rationality is our distinguishing characteristic - it's what sets us apart from the beasts." - Aristotle

Last edited by Mark McLeod : 16-04-2011 at 11:01.
Reply With Quote
  #4   Spotlight this post!  
Unread 16-04-2011, 11:24
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,751
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: Wait Function

Great article. And great title.

Greg McKaskle
Reply With Quote
  #5   Spotlight this post!  
Unread 16-04-2011, 14:50
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,065
Ether has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond repute
Re: Wait Function

Quote:
Originally Posted by Mark McLeod View Post
Some of the descriptions are probably over simplified.
Would this be an example?
Quote:
a single Timed Loop set for 1ms and a higher priority will lockout your driver controls or make response very erratic, because the Teleop loop will never get time on the CPU.
I assume the above is true only if the code in the 1ms loop takes some significant percentage of 1ms to execute? In other words, the context switching overhead is nowhere near 1ms, is it?


Reply With Quote
  #6   Spotlight this post!  
Unread 17-04-2011, 08:24
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,751
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: Wait Function

It is nowhere near 1ms. And the overhead of the loop is relatively small. Of course it very much depends on what you put in it, and whether you configure it to try to regain the schedule or slip it.

If you want to look at it under a microscope, you modify those sample loops to call into the RT Trace toolkit and that will let you see all the details of the scheduling. I've attached one of the example log screenshots. I would attach a typical 20ms teleop execution, but again, no cRIO at home.

Greg McKaskle
Attached Thumbnails
Click image for larger version

Name:	Clipboard 1.png
Views:	23
Size:	72.9 KB
ID:	10594  
Reply With Quote
  #7   Spotlight this post!  
Unread 17-04-2011, 15:58
WizenedEE's Avatar
WizenedEE WizenedEE is offline
Registered User
AKA: Adam
FRC #3238 (Cyborg Ferrets)
Team Role: Leadership
 
Join Date: Jan 2011
Rookie Year: 2010
Location: Anacortes, WA
Posts: 395
WizenedEE is a name known to allWizenedEE is a name known to allWizenedEE is a name known to allWizenedEE is a name known to allWizenedEE is a name known to allWizenedEE is a name known to all
Re: Wait Function

None of your posts really say why a loop with a 10ms delay would run at 500hz consistently, just why it may be noisy. I think the original poster meant that it was pretty consistent with its 2ms time.

The probably may be that you didn't wire up a string to the "name" part of the vi, and you're calling it twice within the same vi. Not wiring up a name is fine for teleop, where there's only one loop, but you probably want to do it in periodic tasks, where there may be multiple loops you want to measure.
Reply With Quote
  #8   Spotlight this post!  
Unread 17-04-2011, 19:45
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,751
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: Wait Function

Doh. That would explain a lot. I normally wire the string, but it was built so that when unwired, it will use the VI name. Are you calling the Elapsed time multiple times with the same string -- unwired from the same VI? Because honestly, I wasn't liking my explanation. I wouldn't expect more than about 2ms of noise jitter.

Greg McKaskle
Reply With Quote
  #9   Spotlight this post!  
Unread 17-04-2011, 20:32
cabbagekid2 cabbagekid2 is offline
Registered User
#0368 (Kika Mana)
 
Join Date: Jun 2001
Rookie Year: 2000
Location: Honolulu, HI
Posts: 85
cabbagekid2 has a spectacular aura aboutcabbagekid2 has a spectacular aura aboutcabbagekid2 has a spectacular aura about
Re: Wait Function

No, we only call the elapsed time vi once in periodic task and once in teleop. Both times we left them un-named. But it should be okay since we only dropped it in one of the while loops in periodic task and not multiple loops?
Reply With Quote
  #10   Spotlight this post!  
Unread 17-04-2011, 23:27
Mark McLeod's Avatar
Mark McLeod Mark McLeod is online now
Just Itinerant
AKA: Hey dad...Father...MARK
FRC #0358 (Robotic Eagles)
Team Role: Engineer
 
Join Date: Mar 2003
Rookie Year: 2002
Location: Hauppauge, Long Island, NY
Posts: 8,795
Mark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond repute
Re: Wait Function

Something is incorrect.
Care to zip and post the project as-is?

I ran a test on the default framework to be sure and I get 10-11ms
__________________
"Rationality is our distinguishing characteristic - it's what sets us apart from the beasts." - Aristotle
Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 09:28.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi