Go to Post hmm..."give the gift of ChiefDelphi"? "This holiday season, send some Pontiac cheer to someone you love"? "Don't forget to put The Chief under your tree!" The possibilities are endless. - Jessica Boucher [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 30-09-2015, 07:53
Ari423's Avatar
Ari423 Ari423 is offline
LabVIEW aficionado and robot addict
AKA: The guy with the yellow hat
FRC #5987 (Galaxia)
Team Role: Mentor
 
Join Date: Mar 2015
Rookie Year: 2012
Location: Haifa, Israel
Posts: 634
Ari423 has much to be proud ofAri423 has much to be proud ofAri423 has much to be proud ofAri423 has much to be proud ofAri423 has much to be proud ofAri423 has much to be proud ofAri423 has much to be proud ofAri423 has much to be proud ofAri423 has much to be proud of
Get/Set Refnum vs Global

On my team, we always store refnums using the Get and Set Refnum methods to store references to pieces of the robot across VIs. When I was looking at some other teams' code, I noticed that some teams ignore the Get and Set Refnum methods and store the refnums in global variables. I can see that both work, but I would imaginge one is better than the other. Can someone with more knowledge of how the Get and Set methods work explain the pros and cons of using them over global variables?
__________________
2017-present: Mentor FRC 5987
2017-present: CSA for FIRST in Israel
2012-2016: Member FRC 423
2013: Programmer
2014: Head Programmer, Wiring
2015: Head Programmer, Wiring
2016: Captain, Head Programmer, Wiring, Manipulator, Chassis, CAD, Business, Outreach (basically everything)


Reply With Quote
  #2   Spotlight this post!  
Unread 30-09-2015, 08:41
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: Get/Set Refnum vs Global

The get/set refnum is what we refer to as a functional global. It stores data as a side-effect of its execution. It implements a name -> value lookup for some number of refnums of a given type.

Regular globals will work, but it will be more work to add one more sensor, one more motor, etc. With changes being made to the framework this year, it won't be as necessary to use either of these ... but that is for another day.

Greg McKaskle
Reply With Quote
  #3   Spotlight this post!  
Unread 30-09-2015, 11:34
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,113
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: Get/Set Refnum vs Global

Our code the first year of LabVIEW was weird, with shift registers and accidental feedback nodes and wires looping all over the place. The second year, we used global variables. Then we used the RefNum Registry. A few years ago we did a hybrid, using a collection of global constants to programmatically create all the various motors, sensors, pneumatic actuators, etc.

Last year we used a different kind of functional global. We combined all the RefNum values for each subsystem into a bundle in a VI full of cases for Begin, Teleop, 100 ms repeat, etc. That let us select the desired resource from a menu instead of having to spell it exactly each time we wanted to use it. We found that doing a RefNum Set was still necessary in order for Test Mode to work. RefNum Get was not used in our main code.

I'm looking forward to finding out what suggestions were implemented in the framework this year, and what unexpected improvements are waiting for us.
Reply With Quote
  #4   Spotlight this post!  
Unread 30-09-2015, 17:43
Thad House Thad House is online now
Volunteer, WPILib Contributor
no team (Waiting for 2021)
Team Role: Mentor
 
Join Date: Feb 2011
Rookie Year: 2010
Location: Thousand Oaks, California
Posts: 1,105
Thad House has a reputation beyond reputeThad House has a reputation beyond reputeThad House has a reputation beyond reputeThad House has a reputation beyond reputeThad House has a reputation beyond reputeThad House has a reputation beyond reputeThad House has a reputation beyond reputeThad House has a reputation beyond reputeThad House has a reputation beyond reputeThad House has a reputation beyond reputeThad House has a reputation beyond repute
Re: Get/Set Refnum vs Global

Quote:
Originally Posted by Greg McKaskle View Post
The get/set refnum is what we refer to as a functional global. It stores data as a side-effect of its execution. It implements a name -> value lookup for some number of refnums of a given type.

Regular globals will work, but it will be more work to add one more sensor, one more motor, etc. With changes being made to the framework this year, it won't be as necessary to use either of these ... but that is for another day.

Greg McKaskle
This could actually be really nice. I have had to help so many teams debug their code because they accidentally put an extra space or changed a capitol in a refnum name. We have actually not used refnums at all since 2010, and instead implement our own functional globals for each subsystem with a Begin, Run and End enum, because of all the troubles refnums caused, plus the speed hit involved with a string lookup table. It will be interesting to see if the new changes do anything like this, even though this season is probably our last using LabVIEW.

As for the original question, the refnums are/were good because you could access the state of any IO object from anywhere in your code. The other solutions are like you said storing all these in globals, implementing your own storage, or running wires between every VI with the object state. For FRC, refnums were the easiest way to do this it seemed, but without compiler checking for the string, it caused a lot of headache.
__________________
All statements made are my own and not the feelings of any of my affiliated teams.
Teams 1510 and 2898 - Student 2010-2012
Team 4488 - Mentor 2013-2016
Co-developer of RobotDotNet, a .NET port of the WPILib.
Reply With Quote
  #5   Spotlight this post!  
Unread 09-10-2015, 22:03
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: Get/Set Refnum vs Global

Just to clarify terminology, open nodes return refnums. The approach in 2009 was that you would just wire the refnum through the connector pane, possibly using clusters. No names, and not that hard, but there are a number of syntax errors that can come up.

In order to avoid concepts such as modifying a connector or building a cluster, we added the refnum registry in 2010. The benefit is that you don't need to cluster various I/O refnums and send them to the auto and tele routines via connector. But instead, you would use a name lookup. In general, I also prefer earlier syntax checking, but this was a way to avoid several concepts. I don't think the name lookup is very expensive, but if I were to try and avoid it, I'd choose wires over globals or functional globals.

The new framework I was eluding to is to have subsystems own I/O. Very little I/O will likely be published for use in tele or auto. Instead, it will belong to the state machines or control loops that are directed by auto and tele alike. This is similar to Command-Based programming offered by WPILib, but with distinct differences.

None of the other frameworks will be removed, but an additional complementary organizational structure will be added. I'm excited to see what teams do with it. It was covered in a Champs presentation last year, and will be a part of this season's beta testing which gets underway any day now.

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 21:31.

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