|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
|
|
Thread Tools | Rate Thread | Display Modes |
|
|
|
#1
|
|||||
|
|||||
|
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");
|
|
#2
|
||||
|
||||
|
Re: Get SmartDashboard keys?
Quote:
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. |
|
#3
|
||||
|
||||
|
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 |
|
#4
|
||||
|
||||
|
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 |
|
#5
|
|||
|
|||
|
Re: Get SmartDashboard keys?
Quote:
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);
}
}
Last edited by MatthewC529 : 18-02-2015 at 15:39. Reason: Warning: Reflection is Rarely the Best Option |
|
#6
|
|||
|
|||
|
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 |
|
#7
|
||||
|
||||
|
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... |
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|