Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Java (http://www.chiefdelphi.com/forums/forumdisplay.php?f=184)
-   -   Get SmartDashboard keys? (http://www.chiefdelphi.com/forums/showthread.php?t=134701)

Toa Circuit 16-02-2015 14:25

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

legts 16-02-2015 14:51

Re: Get SmartDashboard keys?
 
It is possible to display values in the SmartDashboard, but I'm not really sure that you mean by "keys"

otherguy 16-02-2015 16:05

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"

Toa Circuit 16-02-2015 16:14

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.

Ozuru 16-02-2015 16:31

Re: Get SmartDashboard keys?
 
Quote:

Originally Posted by Toa Circuit (Post 1445210)
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.

fovea1959 17-02-2015 10:04

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

fovea1959 17-02-2015 10:09

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

MatthewC529 18-02-2015 15:35

Re: Get SmartDashboard keys?
 
Quote:

Originally Posted by Toa Circuit (Post 1445210)
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);
                }
        }


nfusselman1 19-02-2015 10:36

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

fovea1959 19-02-2015 11:12

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...


All times are GMT -5. The time now is 22:23.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi