Go to Post You can sometimes step outside the box if you have properly thought through the question. - Jim Zondag [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
  #16   Spotlight this post!  
Unread 13-02-2014, 00:37
Alan Anderson's Avatar
Alan Anderson Alan Anderson is offline
Software Architect
FRC #0045 (TechnoKats)
Team Role: Mentor
 
Join Date: Feb 2004
Rookie Year: 2004
Location: Kokomo, Indiana
Posts: 9,112
Alan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond repute
Re: 100% CPU Utilization Using 10ms Periodic Task

Congratulations on finding and fixing the problem.

In normal usage, an incorrect RefNum name should have given you an error message on the Driver Station. Did you do something with the error output on the RefNum Get function that would have caused the system to think you were checking and handling the error yourself?
Reply With Quote
  #17   Spotlight this post!  
Unread 13-02-2014, 06:16
Chris Hibner's Avatar Unsung FIRST Hero
Chris Hibner Chris Hibner is offline
Eschewing Obfuscation Since 1990
AKA: Lars Kamen's Roadie
FRC #0051 (Wings of Fire)
Team Role: Engineer
 
Join Date: May 2001
Rookie Year: 1997
Location: Canton, MI
Posts: 1,488
Chris Hibner has a reputation beyond reputeChris Hibner has a reputation beyond reputeChris Hibner has a reputation beyond reputeChris Hibner has a reputation beyond reputeChris Hibner has a reputation beyond reputeChris Hibner has a reputation beyond reputeChris Hibner has a reputation beyond reputeChris Hibner has a reputation beyond reputeChris Hibner has a reputation beyond reputeChris Hibner has a reputation beyond reputeChris Hibner has a reputation beyond repute
Re: 100% CPU Utilization Using 10ms Periodic Task

Quote:
Originally Posted by Phalanx View Post
I found the problem. One of the GetRefNum's had an incorrect name. The name in Begin.VI was "Ball Collector Limit Switch" and in PeriodicTasks.VI it was "Ball Limit Switch". I corrected that issue and now CPU is back to normal levels.

So as I'm fond of saying.... "Programmers don't need to spell correctly, just consistently!!!"

Thanks for your insights, help and input.
I have a rule with our software students: if I catch you typing a refnum name in any VI other than Begin.vi, you get the mother superior whack on the knuckles with a ruler. Copy/Paste ONLY!!!!
__________________
-
An ounce of perception is worth a pound of obscure.
Reply With Quote
  #18   Spotlight this post!  
Unread 13-02-2014, 07:04
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,748
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: 100% CPU Utilization Using 10ms Periodic Task

I'm also curious if it is clear why the error message wasn't making its way to the DS.

Greg McKaskle
Reply With Quote
  #19   Spotlight this post!  
Unread 13-02-2014, 08:30
Alan Anderson's Avatar
Alan Anderson Alan Anderson is offline
Software Architect
FRC #0045 (TechnoKats)
Team Role: Mentor
 
Join Date: Feb 2004
Rookie Year: 2004
Location: Kokomo, Indiana
Posts: 9,112
Alan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond repute
Re: 100% CPU Utilization Using 10ms Periodic Task

Quote:
Originally Posted by Chris Hibner View Post
I have a rule with our software students: if I catch you typing a refnum name in any VI other than Begin.vi, you get the mother superior whack on the knuckles with a ruler. Copy/Paste ONLY!!!!
We're going one better than that this year. The names only appear in one place in the code.
Reply With Quote
  #20   Spotlight this post!  
Unread 13-02-2014, 09:35
Chris Hibner's Avatar Unsung FIRST Hero
Chris Hibner Chris Hibner is offline
Eschewing Obfuscation Since 1990
AKA: Lars Kamen's Roadie
FRC #0051 (Wings of Fire)
Team Role: Engineer
 
Join Date: May 2001
Rookie Year: 1997
Location: Canton, MI
Posts: 1,488
Chris Hibner has a reputation beyond reputeChris Hibner has a reputation beyond reputeChris Hibner has a reputation beyond reputeChris Hibner has a reputation beyond reputeChris Hibner has a reputation beyond reputeChris Hibner has a reputation beyond reputeChris Hibner has a reputation beyond reputeChris Hibner has a reputation beyond reputeChris Hibner has a reputation beyond reputeChris Hibner has a reputation beyond reputeChris Hibner has a reputation beyond repute
Re: 100% CPU Utilization Using 10ms Periodic Task

Quote:
Originally Posted by Alan Anderson View Post
We're going one better than that this year. The names only appear in one place in the code.
Global variables? Please share how you're doing it.
__________________
-
An ounce of perception is worth a pound of obscure.
Reply With Quote
  #21   Spotlight this post!  
Unread 13-02-2014, 09:37
chris.boyle's Avatar
chris.boyle chris.boyle is offline
Programming Mentor
FRC #0068 (Truck Town Thunder)
Team Role: Mentor
 
Join Date: Nov 2011
Rookie Year: 2012
Location: Truck Town Thunder (Brandon)
Posts: 36
chris.boyle is on a distinguished road
Re: 100% CPU Utilization Using 10ms Periodic Task

Quote:
Originally Posted by Alan Anderson View Post
We're going one better than that this year. The names only appear in one place in the code.
We have the same philosophy about keeping the names in only one place.

This is how we are avoiding refnum errors. Requires more work up front, but should never have an 'invalid' refnum problem. Just make sure you pick the correct one.

Timing is not an issue, as they are only called once at start up and the refnum values are stored in the shift registers for the duration. In addition, we only allow access to a particular device in one loop. It is not allowed to have multiple loops trying to access the same refnum.
Attached Thumbnails
Click image for larger version

Name:	RefNumNaming.png
Views:	33
Size:	60.5 KB
ID:	16220  
__________________
2014 Chairman's Award--Michigan State Championship
2014 Chairman's Award--Waterford District
2014 Winner--Great Lakes Bay District
2013 Chairman's Award--Kettering District
2012 Championship Division Finalists--Thanks 330 and 639
Reply With Quote
  #22   Spotlight this post!  
Unread 13-02-2014, 11:35
Alan Anderson's Avatar
Alan Anderson Alan Anderson is offline
Software Architect
FRC #0045 (TechnoKats)
Team Role: Mentor
 
Join Date: Feb 2004
Rookie Year: 2004
Location: Kokomo, Indiana
Posts: 9,112
Alan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond repute
Re: 100% CPU Utilization Using 10ms Periodic Task

We have our code separated into drivebase and "other" sections. The Drivebase vi is a Case statement with cases for Begin, Teleop, Finish, and 10ms Periodic. The refnum name constants are outside the case and tunneled in.

We call the Drivebase vi from inside Begin, passing it the "Begin" selector. We also call it from within Teleop, Finish, and a 10ms loop in Periodic Tasks, passing the appropriate selector each time.

The "other" vi (name withheld to protect the mechanism) is similar, but also includes 5ms and 100ms cases.

I started out trying to use shift registers in a single-execution while loop to hold the refnum values, but Test mode requires everything to be in the RefNum Registry. Since I had to use Refnum Set anyway, I went with Refnum Get wherever resources are used. I might do some timing tests to see how the timing is affected by using shift registers instead.
Reply With Quote
  #23   Spotlight this post!  
Unread 13-02-2014, 11:42
Joe Ross's Avatar Unsung FIRST Hero
Joe Ross Joe Ross is offline
Registered User
FRC #0330 (Beachbots)
Team Role: Engineer
 
Join Date: Jun 2001
Rookie Year: 1997
Location: Los Angeles, CA
Posts: 8,562
Joe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond repute
Re: 100% CPU Utilization Using 10ms Periodic Task

Quote:
Originally Posted by chris.boyle View Post
This is how we are avoiding refnum errors. Requires more work up front, but should never have an 'invalid' refnum problem. Just make sure you pick the correct one.
You can simplify this by using "Format Into String" on the enum.
Reply With Quote
  #24   Spotlight this post!  
Unread 13-02-2014, 12:02
Alan Anderson's Avatar
Alan Anderson Alan Anderson is offline
Software Architect
FRC #0045 (TechnoKats)
Team Role: Mentor
 
Join Date: Feb 2004
Rookie Year: 2004
Location: Kokomo, Indiana
Posts: 9,112
Alan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond repute
Re: 100% CPU Utilization Using 10ms Periodic Task

Quote:
Originally Posted by Joe Ross View Post
You can simplify this by using "Format Into String" on the enum.
That's how we did it last year. It was a lot of upfront work to create all the typedefs, but it made the programming completely safe from simple typing errors. We wrote wrappers around all the RefNum Get functions so they could accept either strings or enums.

We also had bunch of special global cluster arrays defining everything necessary to open relays, digital inputs, counters, encoders, drivebase motor sets, individual motors, solenoids, analog inputs, etc. Begin and Finish ran through the arrays opening (and closing) everything, so once we had the basic code framework written we never needed to touch those VIs again.
Reply With Quote
  #25   Spotlight this post!  
Unread 13-02-2014, 15:39
Phalanx's Avatar
Phalanx Phalanx is offline
Formerly Team 1089 (Mercury)
AKA: Michael Reffler
FRC #5431 (Titan Robotics)
Team Role: Mentor
 
Join Date: Jun 2005
Rookie Year: 1999
Location: Lewisville, TX (previously NJ)
Posts: 384
Phalanx has a reputation beyond reputePhalanx has a reputation beyond reputePhalanx has a reputation beyond reputePhalanx has a reputation beyond reputePhalanx has a reputation beyond reputePhalanx has a reputation beyond reputePhalanx has a reputation beyond reputePhalanx has a reputation beyond reputePhalanx has a reputation beyond reputePhalanx has a reputation beyond reputePhalanx has a reputation beyond repute
Re: 100% CPU Utilization Using 10ms Periodic Task

Quote:
Originally Posted by Alan Anderson View Post
In normal usage, an incorrect RefNum name should have given you an error message on the Driver Station. Did you do something with the error output on the RefNum Get function that would have caused the system to think you were checking and handling the error yourself?
We didn't wire anything to the error out terminal. So we weren't masking it or handling it ourselves. I didn't see an error message at the time.

Quote:
Originally Posted by Greg McKaskle View Post
I'm also curious if it is clear why the error message wasn't making its way to the DS.
Greg, I can't answer that other than to say, that the error message was probably missed and the DS log wasn't closely scrutinized. My programming team told me last night, that they did see an error message the next day.

I've got to do a better job teaching this stuff. This is for a team that had zero programmers at the start of build season. I'm not that dissatisfied with where they've gotten given the short time.
__________________
Don't just ask the experts, become one!
Leadership is not about ability. It's about responsibility!
Diagonally Parked in a Parallel Universe. It's okay we do Quantum Physics


Reply With Quote
  #26   Spotlight this post!  
Unread 13-02-2014, 16:27
wt200999's Avatar
wt200999 wt200999 is online now
Texas Instruments
AKA: Will Toth
FRC #3005 (Robochargers)
Team Role: Mentor
 
Join Date: Mar 2006
Rookie Year: 2004
Location: Dallas, Texas
Posts: 323
wt200999 has much to be proud ofwt200999 has much to be proud ofwt200999 has much to be proud ofwt200999 has much to be proud ofwt200999 has much to be proud ofwt200999 has much to be proud ofwt200999 has much to be proud ofwt200999 has much to be proud ofwt200999 has much to be proud of
Send a message via MSN to wt200999
Re: 100% CPU Utilization Using 10ms Periodic Task

Quote:
Originally Posted by chris.boyle View Post
This is how we are avoiding refnum errors. Requires more work up front, but should never have an 'invalid' refnum problem. Just make sure you pick the correct one.
Do you inline this SubVI?

If my understanding of the LabVIEW compiler/optimizer is correct, if you were to inline that VI, every instance of that VI would be copied down into the code and the controls would all be optimized out. The case structure would also be optimized out leaving the 'normal' method for accessing resources. This would give you the less CPU usage overhead compared to format into string or a subVI call, while supporting the normal methodology used by the WPI Library.
Attached Thumbnails
Click image for larger version

Name:	RefNumNaming.png
Views:	19
Size:	19.6 KB
ID:	16222  Click image for larger version

Name:	RefNumNaming Optimized.png
Views:	58
Size:	11.7 KB
ID:	16223  
__________________
Programming in LabVIEW? Try VI Snippets!

FIRST LEGO League 2004 - 2005
FRC Team 870 Student 2006 - 2009
FRC Team 3005 Mentor 2013 -
Reply With Quote
  #27   Spotlight this post!  
Unread 13-02-2014, 19:47
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,748
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: 100% CPU Utilization Using 10ms Periodic Task

I was asking just to see if there was a bug or something that could be improved for the future.

One such thing is to make the errors be on the front page instead of the second page. Other things can be done so that the errors or number of errors are more obvious. The other issue is that the current error routing is too slow and often causes watchdog issues. I believe that is fixed for next year along with a deploy issue that it can sometimes cause.

As for the string dictionary that was demonstrated. That is a great way of preventing inconsistent spelling. I'm not sure if it is necessary or good for all teams, but if you have the skills to make the subVI and update the typedef enum, it is a great solution. The overhead of the subVI should be quite small. Making it a subroutine would shrink that by quite a bit. Making it be inlined will, as pointed out, should make it disappear entirely as the compiler substitutes the code, then propagates constants, then removes unreachable code.

Greg McKaskle
Reply With Quote
  #28   Spotlight this post!  
Unread 14-02-2014, 14:52
chris.boyle's Avatar
chris.boyle chris.boyle is offline
Programming Mentor
FRC #0068 (Truck Town Thunder)
Team Role: Mentor
 
Join Date: Nov 2011
Rookie Year: 2012
Location: Truck Town Thunder (Brandon)
Posts: 36
chris.boyle is on a distinguished road
Re: 100% CPU Utilization Using 10ms Periodic Task

We are not really concerned with the efficiency of the string dictionary as these are only called once at the entry of Begin, Periodic Tasks, Finish and Disabled if they are motors.

The references returned are stored in the Shift Register for the duration of the execution. With our rule of only a single Get Reference allowed, it has not been a problem with speed, just planning.
__________________
2014 Chairman's Award--Michigan State Championship
2014 Chairman's Award--Waterford District
2014 Winner--Great Lakes Bay District
2013 Chairman's Award--Kettering District
2012 Championship Division Finalists--Thanks 330 and 639
Reply With Quote
  #29   Spotlight this post!  
Unread 14-02-2014, 19:02
plnyyanks's Avatar
plnyyanks plnyyanks is offline
Data wins arguments.
AKA: Phil Lopreiato
FRC #1124 (The ÜberBots), FRC #2900 (The Mighty Penguins)
Team Role: College Student
 
Join Date: Apr 2010
Rookie Year: 2010
Location: NYC/Washington, DC
Posts: 1,113
plnyyanks has a reputation beyond reputeplnyyanks has a reputation beyond reputeplnyyanks has a reputation beyond reputeplnyyanks has a reputation beyond reputeplnyyanks has a reputation beyond reputeplnyyanks has a reputation beyond reputeplnyyanks has a reputation beyond reputeplnyyanks has a reputation beyond reputeplnyyanks has a reputation beyond reputeplnyyanks has a reputation beyond reputeplnyyanks has a reputation beyond repute
Re: 100% CPU Utilization Using 10ms Periodic Task

Quote:
Originally Posted by wt200999 View Post
If my understanding of the LabVIEW compiler/optimizer is correct, if you were to inline that VI, every instance of that VI would be copied down into the code and the controls would all be optimized out.
Close. Making a sub-VI inline makes LabVIEW think that the code in that VI is actually on the block diagram's parent (and avoids the overhead of making a subVI call). So having an inline subVI is exactly equivalent to not having the subVI there at all (and its code just in the block diagram of its parent).

Quote:
A third way to minimize subVI overhead is to inline subVIs into their calling VIs. When you inline a subVI, LabVIEW inserts the compiled code of the subVI into the compiled code of the calling VI. If you then make changes to the subVI, LabVIEW recompiles all calling VIs of that subVI to include those changes. Essentially, inlining a subVI removes the need to call the subVI at run time. Instead, LabVIEW executes the subVI code inside the compiled code of the calling VI.

Inlining subVIs is most useful for small subVIs, subVIs within a loop, subVIs with unwired outputs, or subVIs you call only once. To inline a subVI, place a checkmark in the Inline subVI into calling VIs checkbox on the Execution page of the VI Properties dialog box. You must also place a checkmark in the Reentrant execution checkbox on the same page of the dialog box. LabVIEW automatically preallocates clones for each instance when it inlines the subVI.
Source, and for more light reading on the subject, a description of how the compiler works with some nifty diagrams on what inlining does if you scroll down a little.
__________________
Phil Lopreiato - "It's a hardware problem"
Team 1124 (2010 - 2013), Team 1418 (2014), Team 2900 (2016)
FRC Notebook The Blue Alliance for Android

Last edited by plnyyanks : 14-02-2014 at 19:05.
Reply With Quote
  #30   Spotlight this post!  
Unread 15-02-2014, 00:19
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,748
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: 100% CPU Utilization Using 10ms Periodic Task

Once the code is inlined, the compiler will propagate constants, we call it constant-folding. The result of this is that the string is known at compile time and all other cases are eliminated for that instance because they are unreachable. The overhead when inlined, both in runtime size and execution is equivalent to wiring a constant.

Greg McKaskle
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 14:17.

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