Go to Post first robotics is a ten - Hiteak [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 23-01-2015, 16:05
GuyM142's Avatar
GuyM142 GuyM142 is offline
Registered User
AKA: Guy
FRC #3339 (BumbleBee)
Team Role: Mentor
 
Join Date: Jul 2013
Rookie Year: 2012
Location: Israel
Posts: 158
GuyM142 is just really niceGuyM142 is just really niceGuyM142 is just really niceGuyM142 is just really niceGuyM142 is just really nice
Using shared variables instead of global variables

This year we have a big amount of global variables and it becomes hard to find the one I need each time.
Separating the variables to different global variables also isn't ideal because I have to drag the correct one and only then choose the one I'm looking for.

I've noticed that shared variables can be chosen very easily by library and I wish to use them instead.

What are the differences between those two types?
Is one of them more efficient than the other?

Thanks!

Last edited by GuyM142 : 23-01-2015 at 16:17.
Reply With Quote
  #2   Spotlight this post!  
Unread 23-01-2015, 16:39
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: 325
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: Using shared variables instead of global variables

The Shared Variable is meant for sharing data over a network while hiding the network implementation. I can't speak much to the performance, but I can recommend other ways to help.

Ideally you should try to reduce the number of global variables that you use in the first place. If you are getting lost in the number of global variables that you are using, you are probably using too many. There are a number of ways to reduce the number of globals.

The easiest way would be to send a cluster using the global, instead of using single data types and multiple globals.

If you want to get into the more advanced LabVIEW topics, you can change your architecture to use other message passing schemes (Notifiers, Queues etc). Depending on your implementation, you could possibly get away with not using any global variables at all.
__________________
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
  #3   Spotlight this post!  
Unread 23-01-2015, 17:00
GuyM142's Avatar
GuyM142 GuyM142 is offline
Registered User
AKA: Guy
FRC #3339 (BumbleBee)
Team Role: Mentor
 
Join Date: Jul 2013
Rookie Year: 2012
Location: Israel
Posts: 158
GuyM142 is just really niceGuyM142 is just really niceGuyM142 is just really niceGuyM142 is just really niceGuyM142 is just really nice
Re: Using shared variables instead of global variables

Quote:
Originally Posted by wt200999 View Post
The Shared Variable is meant for sharing data over a network while hiding the network implementation. I can't speak much to the performance, but I can recommend other ways to help.

Ideally you should try to reduce the number of global variables that you use in the first place. If you are getting lost in the number of global variables that you are using, you are probably using too many. There are a number of ways to reduce the number of globals.

The easiest way would be to send a cluster using the global, instead of using single data types and multiple globals.

If you want to get into the more advanced LabVIEW topics, you can change your architecture to use other message passing schemes (Notifiers, Queues etc). Depending on your implementation, you could possibly get away with not using any global variables at all.
We are working with state machines so that we have a state machine for every sub-system on the robot. for example: Tote grabbing arms
For each state machine we have commands/actions like open or close.

Then, in the Teleop.vi we send different commands to the state machines which run in parallel, based on driver's input.

*We have an enum typeDef for each state machine and for each set of actions.

for example:
the grabber state machine is in close state,
pressing button 1 sends "open" to the grabber state machine,
the grabber state machines then moves to "moving to open" state,
and when it detects it reached the target it moves to "open".

Which architecture do you recommend using?
Reply With Quote
  #4   Spotlight this post!  
Unread 23-01-2015, 17:27
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: Using shared variables instead of global variables

The big difference is that global variables are scoped to your application, specifically the target context within your application. Shared variables are shared between computers, between processes, and that brings a decent amount of overhead with it. I know teams who successfully use them, but we don't use them for the default framework because global variables are all most teams need.

Greg McKaskle
Reply With Quote
  #5   Spotlight this post!  
Unread 23-01-2015, 17:32
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: Using shared variables instead of global variables

My previous post was open in my editor for quite awhile, so was largely redundant by the time I pressed the button.

Responding to your newer post, I think it will help if you can put the inputs to a state machine into a cluster. Put the outputs into a cluster as well. This will probably cut down by a factor of eight to ten.

In some code I've done that sounds similar, I also moved most of these globals into what we call a functional global. This is sometimes called a LV2 style global. It is a function with state data that has operations such as read and write, but sometimes read/and/clear, or append and remove. Anyway, these functions are often a good way to clean up scattered sets of globals into a small intelligent object that stores the data and makes access safe for a parallel language.

Greg McKaskle
Reply With Quote
  #6   Spotlight this post!  
Unread 23-01-2015, 18: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,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: Using shared variables instead of global variables

I don't see the connection between state machines and global variables. A state machine keeps its own state, and shouldn't need to share it with anything else, right?

If it's just persistent storage you're looking for, I suggest putting the state machine inside a single-run While with a shift register. There are at least three other ways I can think of to do what I assume you want, including local variables.
Reply With Quote
  #7   Spotlight this post!  
Unread 26-01-2015, 04:56
GuyM142's Avatar
GuyM142 GuyM142 is offline
Registered User
AKA: Guy
FRC #3339 (BumbleBee)
Team Role: Mentor
 
Join Date: Jul 2013
Rookie Year: 2012
Location: Israel
Posts: 158
GuyM142 is just really niceGuyM142 is just really niceGuyM142 is just really niceGuyM142 is just really niceGuyM142 is just really nice
Quote:
Originally Posted by Alan Anderson View Post
I don't see the connection between state machines and global variables. A state machine keeps its own state, and shouldn't need to share it with anything else, right?

If it's just persistent storage you're looking for, I suggest putting the state machine inside a single-run While with a shift register. There are at least three other ways I can think of to do what I assume you want, including local variables.
Some state machines do different things depending on the state of other state machines, so I use global variables in order to read other state machines' current state.
__________________
2016-2017 - Programming Mentor
Curie Sub-Division Champions with 694, 379 & 1511
2015 - Team Captain & Head of Programming Crew
Carson Sub-Division Champions with 1325, 20 & 1711
First ever Israeli team on Einstein
2014 - Team Captain & Head of Programming Crew
2013 - Head of Programming Crew
2012 - Member of Programming Crew
Reply With Quote
  #8   Spotlight this post!  
Unread 26-01-2015, 09:32
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: Using shared variables instead of global variables

Quote:
Originally Posted by GuyM142 View Post
Some state machines do different things depending on the state of other state machines,...
That sounds like it could get confusing. No wonder you're having difficulty finding things. I can understand how it can be helpful to encapsulate groups of states into their own machine, but you probably see now that it's often a false optimization to do it from the bottom up (or the inside out, depending on your perspective).

I know there's not a lot of time left, and you've probably put a lot of effort into what you already have, so I won't seriously suggest refactoring your code so there aren't so many intersystem connections. But next time you do something similar, I hope you'll be able to come up with a less tangled architecture.
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 20:10.

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