Go to Post It's easy to get overwhelmed. Don't get overwhelmed, just keep working at things a little bit at a time. (Oh, and don't forget to have fun!) - DominickC [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 Rating: Thread Rating: 2 votes, 4.50 average. Display Modes
  #1   Spotlight this post!  
Unread 31-12-2014, 17:00
BitTwiddler's Avatar
BitTwiddler BitTwiddler is offline
electronics/programming mentor
AKA: Mr Tanguay
FRC #1726 (N.E.R.D.S.)
Team Role: Mentor
 
Join Date: Oct 2008
Rookie Year: 2006
Location: Sierra Vista, AZ
Posts: 243
BitTwiddler is on a distinguished road
Team 1726 button toggle & SR Latch code

We used these handy little utilities last year and I'd like to be able to re-use the code this year if it comes in handy again. Therefore I am posting the source VI code for other teams to use in the spirit of R13 for the 2015 game.
Button toggle allows the drive team to use a game controller button like a toggle switch. It detects the button press and flips the true/false state of the toggle output to turn something on or off as desired.
SR latch uses one button to set the output to true and second button to reset it back to false.
If you wish to clone multiple copies of these VIs in your code make sure to make them re-entrant to avoid confusion with shared resources.
Hope some other teams also find these useful.
Attached Files
File Type: vi Button Toggle.vi (11.8 KB, 65 views)
File Type: vi s-rflipflop.vi (8.5 KB, 34 views)

Last edited by BitTwiddler : 31-12-2014 at 18:50.
Reply With Quote
  #2   Spotlight this post!  
Unread 01-01-2015, 19:21
nwall nwall is offline
It's a hardware problem
AKA: Nicholas
FRC #0418 (LASA Robotics)
Team Role: Programmer
 
Join Date: Sep 2012
Rookie Year: 2012
Location: Austin, TX
Posts: 13
nwall is an unknown quantity at this point
Re: Team 1726 button toggle & SR Latch code

Thank you for posting this. Our team has always done it one way (since I've been here) and haven't really thought about other ways of doing it because it worked. I do have a question about your "Button Toggle.vi", which is why you use the blocks used. (i.e. Not and And for "Pulse Out", Not and Select for "Toggle")

I have attached our version of the "Button Toggle.vi", which swaps out the two sets mentioned above with Greater Than and XOR. I ran a benchmark on both methods to compare the time required to do each operation 100 million times, and after taking the average of 25 runs, our method took ~1551ms to complete the 100 million iterations, with your method taking ~2000ms. I assume that this is because LabVIEW doesn't have to wait on the output from a block to put it into the next block, but I'm not sure.

For a competition, either would be plenty fast enough, so I'm just wondering why you do it this way.
Attached Files
File Type: vi Button Toggle.vi (11.5 KB, 28 views)
Reply With Quote
  #3   Spotlight this post!  
Unread 01-01-2015, 22:38
wt200999's Avatar
wt200999 wt200999 is offline
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: Team 1726 button toggle & SR Latch code

Quote:
Originally Posted by nwall View Post
I ran a benchmark on both methods to compare the time required to do each operation 100 million times, and after taking the average of 25 runs, our method took ~1551ms to complete the 100 million iterations, with your method taking ~2000ms.
For your benchmark, try setting your execution settings to preallocated clone reentrant, remove the checks for debugging, and add the check for inline and run it again. (see attached)
Attached Thumbnails
Click image for larger version

Name:	ExecutionSettings.PNG
Views:	40
Size:	52.3 KB
ID:	17694  
__________________
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
  #4   Spotlight this post!  
Unread 01-01-2015, 22:58
nwall nwall is offline
It's a hardware problem
AKA: Nicholas
FRC #0418 (LASA Robotics)
Team Role: Programmer
 
Join Date: Sep 2012
Rookie Year: 2012
Location: Austin, TX
Posts: 13
nwall is an unknown quantity at this point
Re: Team 1726 button toggle & SR Latch code

Quote:
Originally Posted by wt200999 View Post
For your benchmark, try setting your execution settings to preallocated clone reentrant, remove the checks for debugging, and add the check for inline and run it again. (see attached)
Thank you! I did that, and you're right, they both ran for an average of ~459ms. I've never really messed with the Execution settings too much, so would you recommend disabling debugging once the robot code is finalized and on the robot, or would the speed gained be negligible for the loss of debugging?
Reply With Quote
  #5   Spotlight this post!  
Unread 01-01-2015, 23:32
wt200999's Avatar
wt200999 wt200999 is offline
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: Team 1726 button toggle & SR Latch code

You shouldn't have to worry about it for the robot code since when you 'deploy' the code (at least by default) debugging is disabled. You can see that this is true if you look under the Advanced category for the build specification in the default robot project. In fact I would leave it in for most of your VIs so when you load your code using just the Run button, you can still debug as usual.

Inlining the VI will give you some small performance benefits at the expense of larger compiled code. Just this check box alone will change your benchmark results. It is good for small widgets like the ones in this thread. For the reeentrancy you just have to be careful depending on the VI.
__________________
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
  #6   Spotlight this post!  
Unread 02-01-2015, 00:02
BitTwiddler's Avatar
BitTwiddler BitTwiddler is offline
electronics/programming mentor
AKA: Mr Tanguay
FRC #1726 (N.E.R.D.S.)
Team Role: Mentor
 
Join Date: Oct 2008
Rookie Year: 2006
Location: Sierra Vista, AZ
Posts: 243
BitTwiddler is on a distinguished road
Re: Team 1726 button toggle & SR Latch code

Quote:
Originally Posted by nwall View Post
Thank you for posting this. Our team has always done it one way (since I've been here) and haven't really thought about other ways of doing it because it worked. I do have a question about your "Button Toggle.vi", which is why you use the blocks used. (i.e. Not and And for "Pulse Out", Not and Select for "Toggle")

.
As a digital electronic technician (now retired) I am used to approaching these kind of problems at the lowest bitwise level. The use of the greater than comparison operator just seems wrong to me but that's just me. I must admit however that I had a "slap myself on the forehead" moment when I saw your elegant use of the XOR operator for the actual toggling of the output. I'm gonna use that one from now on.

Since Labview is an optimizing compiler, it will probably come up with a more efficient solution during compilation anyway.
Reply With Quote
  #7   Spotlight this post!  
Unread 02-01-2015, 00:07
BitTwiddler's Avatar
BitTwiddler BitTwiddler is offline
electronics/programming mentor
AKA: Mr Tanguay
FRC #1726 (N.E.R.D.S.)
Team Role: Mentor
 
Join Date: Oct 2008
Rookie Year: 2006
Location: Sierra Vista, AZ
Posts: 243
BitTwiddler is on a distinguished road
Re: Team 1726 button toggle & SR Latch code

Quote:
Originally Posted by wt200999 View Post

Inlining the VI will give you some small performance benefits at the expense of larger compiled code. Just this check box alone will change your benchmark results. It is good for small widgets like the ones in this thread. For the reeentrancy you just have to be careful depending on the VI.
Thanks for your insight regarding the inlining. I missed that one.
Reply With Quote
  #8   Spotlight this post!  
Unread 02-01-2015, 00:31
nwall nwall is offline
It's a hardware problem
AKA: Nicholas
FRC #0418 (LASA Robotics)
Team Role: Programmer
 
Join Date: Sep 2012
Rookie Year: 2012
Location: Austin, TX
Posts: 13
nwall is an unknown quantity at this point
Re: Team 1726 button toggle & SR Latch code

Quote:
Originally Posted by wt200999 View Post
You shouldn't have to worry about it for the robot code since when you 'deploy' the code (at least by default) debugging is disabled
Oh, okay. Thank you! I figured this was the case, but I wasn't sure, because I haven't spent enough time in the settings.

Quote:
Originally Posted by BitTwiddler View Post
As a digital electronic technician (now retired) I am used to approaching these kind of problems at the lowest bitwise level. The use of the greater than comparison operator just seems wrong to me but that's just me.
.....
Since Labview is an optimizing compiler, it will probably come up with a more efficient solution during compilation anyway.
I assumed it was something like personal preference, but I was curious if there was something I didn't know about LabVIEW (turns out how to turn off debugging). Our previous programming lead showed me the greater than two years ago, and because it worked I've never really given it too much thought until today. Thanks for putting this up!
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 04:37.

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