Go to Post As long as teams keep showing their consistency in innovation, FIRST will keep dazzling us all. - Amanda Morrison [more]
Home
Go Back   Chief Delphi > Technical > Programming > Java
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-02-2015, 14:25
Toa Circuit's Avatar
Toa Circuit Toa Circuit is offline
Thaddeus Maximus
AKA: Thad Hughes
FRC #4213 (MetalCow Robotics)
Team Role: Leadership
 
Join Date: Nov 2012
Rookie Year: 2012
Location: Shirley, IL
Posts: 131
Toa Circuit is an unknown quantity at this point
Get SmartDashboard keys?

Is there any way to get a list/array of the keys in the SmartDashboard?
__________________

2012 Head of Programming and Electrical
2013-14 Overall Team Captain and Programming Head
2012-14 Mentor of FLL Team Power Surge
2014 Dean's List Finalist
2014 CIR Xerox Creativity Award
Webpage
Reply With Quote
  #2   Spotlight this post!  
Unread 16-02-2015, 14:51
legts legts is offline
Autonomous Queen
FRC #2399 (The Fighting Unicorns)
Team Role: Programmer
 
Join Date: Jan 2015
Rookie Year: 2012
Location: Ohio
Posts: 78
legts is an unknown quantity at this point
Re: Get SmartDashboard keys?

It is possible to display values in the SmartDashboard, but I'm not really sure that you mean by "keys"
Reply With Quote
  #3   Spotlight this post!  
Unread 16-02-2015, 16:05
otherguy's Avatar
otherguy otherguy is offline
sparkE
AKA: James
FRC #2168 (The Aluminum Falcons)
Team Role: Mentor
 
Join Date: Feb 2010
Rookie Year: 2009
Location: CT
Posts: 434
otherguy is a splendid one to beholdotherguy is a splendid one to beholdotherguy is a splendid one to beholdotherguy is a splendid one to beholdotherguy is a splendid one to beholdotherguy is a splendid one to beholdotherguy is a splendid one to behold
Re: Get SmartDashboard keys?

The Network tables viewer likely does what you need:
http://wpilib.screenstepslive.com/s/...onent-overview

Look at the section titled "Outline Viewer"
__________________
http://team2168.org
Reply With Quote
  #4   Spotlight this post!  
Unread 16-02-2015, 16:14
Toa Circuit's Avatar
Toa Circuit Toa Circuit is offline
Thaddeus Maximus
AKA: Thad Hughes
FRC #4213 (MetalCow Robotics)
Team Role: Leadership
 
Join Date: Nov 2012
Rookie Year: 2012
Location: Shirley, IL
Posts: 131
Toa Circuit is an unknown quantity at this point
Re: Get SmartDashboard keys?

I should clarify. I need to do it programmatically, in the robot code. (I want to save values to disk so we don't keep losing them) I'd sneak through and grab the underlying hashtable, but it's private in WPILib.

When you do
Code:
SmartDashboard.putString("Key","value");
"Key" is the key. I need to, through code, fetch a list of all keys that are on the SmartDashboard/NetworkTable.
__________________

2012 Head of Programming and Electrical
2013-14 Overall Team Captain and Programming Head
2012-14 Mentor of FLL Team Power Surge
2014 Dean's List Finalist
2014 CIR Xerox Creativity Award
Webpage
Reply With Quote
  #5   Spotlight this post!  
Unread 16-02-2015, 16:31
Ozuru's Avatar
Ozuru Ozuru is offline
It's always the programmer's fault.
no team
 
Join Date: May 2013
Rookie Year: 2010
Location: Earth
Posts: 268
Ozuru is a splendid one to beholdOzuru is a splendid one to beholdOzuru is a splendid one to beholdOzuru is a splendid one to beholdOzuru is a splendid one to beholdOzuru is a splendid one to beholdOzuru is a splendid one to behold
Re: Get SmartDashboard keys?

Quote:
Originally Posted by Toa Circuit View Post
I should clarify. I need to do it programmatically, in the robot code. (I want to save values to disk so we don't keep losing them) I'd sneak through and grab the underlying hashtable, but it's private in WPILib.

When you do
Code:
SmartDashboard.putString("Key","value");
"Key" is the key. I need to, through code, fetch a list of all keys that are on the SmartDashboard/NetworkTable.
With each setter method there is (obviously) a getter -- you could try just doing that. I would recommend put it all into function and then just call the function.

I'm unsure but there might be a way to do a for-each loop in the table -- try seeing what datatypes it returns and try doing a simple for-each loop for that.
Reply With Quote
  #6   Spotlight this post!  
Unread 17-02-2015, 10:04
fovea1959's Avatar
fovea1959 fovea1959 is offline
Herder of programmers
AKA: Doug Wegscheid
FRC #3620 (The Average Joes)
Team Role: Mentor
 
Join Date: Jan 2011
Rookie Year: 2011
Location: St Joseph
Posts: 336
fovea1959 will become famous soon enough
Re: Get SmartDashboard keys?

Perhaps edu.wpi.first.wpilibj.Preferences would be useful? It takes care of persisting part of the NetworkTables tree to storage on the roboRIO.

There is a GUI element in the SmartDashboard for manipulating RobotPreferences.

If you don't like that GUI, it's not hard to write a custom GUI for the driver's PC for tweaking settings in the Preferences via the NetworkTables, and persisting them in the cRIO. Haven't double checked it for this year yet, but would be very surprised if it's broken.

https://github.com/fovea1959/FRC3620_PreferencesEditor
Reply With Quote
  #7   Spotlight this post!  
Unread 17-02-2015, 10:09
fovea1959's Avatar
fovea1959 fovea1959 is offline
Herder of programmers
AKA: Doug Wegscheid
FRC #3620 (The Average Joes)
Team Role: Mentor
 
Join Date: Jan 2011
Rookie Year: 2011
Location: St Joseph
Posts: 336
fovea1959 will become famous soon enough
Re: Get SmartDashboard keys?

...and if you really want to iterate over the keys, look at the source for OutlineViewer. I recall that the listener for updates fires off for all existing NetworkTables values when you first connect to the network tables server.

We wrote a server to log data in the network tables to the driver's station disk last year. It was really hard on bandwidth, so we are just logging in the roboRIO this year. The source code for that might help for how to determine what is in the NetworkTables tree.

https://github.com/fovea1959/FRC3620...ggerNoGUI.java

Last edited by fovea1959 : 17-02-2015 at 10:10. Reason: typo
Reply With Quote
  #8   Spotlight this post!  
Unread 18-02-2015, 15:35
MatthewC529 MatthewC529 is offline
Lcom/mattc/halp;
AKA: Matthew
FRC #1554 (Oceanside Sailors)
Team Role: Mentor
 
Join Date: Feb 2014
Rookie Year: 2013
Location: New York
Posts: 39
MatthewC529 is on a distinguished road
Re: Get SmartDashboard keys?

Quote:
Originally Posted by Toa Circuit View Post
I should clarify. I need to do it programmatically, in the robot code. (I want to save values to disk so we don't keep losing them) I'd sneak through and grab the underlying hashtable, but it's private in WPILib.

When you do
Code:
SmartDashboard.putString("Key","value");
"Key" is the key. I need to, through code, fetch a list of all keys that are on the SmartDashboard/NetworkTable.
If you REALLY needed to, what says you can't get the private hashtable? We have experimented with grabbing underlying NetworkTable object via reflection but generally this has been fruitless for our needs, requiring more clever solutions.

Java's Field object allows you to set the access flag and it isn't like WPI's launch script executes the program with the default SecurityManager. Just remember Reflection is expensive and there is probably a better way as long as you have the time to look for the better way.

To retrieve a Field, convert it to the right type, and to ensure it is returned to it's original accessibility we use:
Code:
    private static Object retrieveField(Field field, Object obj) throws IllegalArgumentException, IllegalAccessException {
		Object item = null;
		final boolean accessible = field.isAccessible();

		if (!accessible) {
			field.setAccessible(!accessible);
		}

		item = field.get(obj);

		if (!accessible) {
			field.setAccessible(accessible);
		}

		return item;
	}
   
    public static <T> T getStaticField(Class<?> klass, String fieldName, Class<T> conversionClass) {
		try {
			final Field field = klass.getDeclaredField(fieldName);
			return conversionClass.cast(retrieveField(field, null));
		} catch (final Exception e) {
			throw new RobotExecutionException("Failure to reflectively obtain Static Field '" + fieldName + "'!", e);
		}
	}

    public static <T> T getInstanceField(Class<?> instClass, Object instance, String fieldName, Class<T> conversionClass) {
		try {
			final Field field = instClass.getDeclaredField(fieldName);
			return conversionClass.cast(retrieveField(field, instance));
		} catch (final Exception e) {
			throw new RobotExecutionException("Failure to reflectively obtain Instance Field '" + fieldName + "' from Object '" + instance + "'!", e);
		}
	}
__________________
Team 1554 -- Oceanside Sailors
  • 2013-2014 - Lead/Sole Programmer
  • 2014-2015 - Lead Programmer, President
  • 2015-? - Team 1554 Mentor
Independent Public Projects

Developer at Legend Zero LLC.
Java/C++ Programmer

Last edited by MatthewC529 : 18-02-2015 at 15:39. Reason: Warning: Reflection is Rarely the Best Option
Reply With Quote
  #9   Spotlight this post!  
Unread 19-02-2015, 10:36
nfusselman1 nfusselman1 is offline
Registered User
FRC #4076
 
Join Date: Jan 2015
Location: Justin TX
Posts: 26
nfusselman1 is an unknown quantity at this point
Re: Get SmartDashboard keys?

What do you have to do to program your robot do all of the smart dashboard stuff like cameras and a gyroscope will be shown in the LabView Default Dashboard.

Lead Programmer (4076)
nfusselman1
Reply With Quote
  #10   Spotlight this post!  
Unread 19-02-2015, 11:12
fovea1959's Avatar
fovea1959 fovea1959 is offline
Herder of programmers
AKA: Doug Wegscheid
FRC #3620 (The Average Joes)
Team Role: Mentor
 
Join Date: Jan 2011
Rookie Year: 2011
Location: St Joseph
Posts: 336
fovea1959 will become famous soon enough
Re: Get SmartDashboard keys?

@nfusselman: you usually want to start a new thread if the subject changes, that way the title will be something that someone down the line can search for.

Take a look at http://wpilib.screenstepslive.com/s/...smartdashboard and see if that answers your questions...
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 18:02.

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