Log in

View Full Version : Java Dynamic Settings


Thomas4019
09-02-2010, 01:28
Our teams have found the deployment times with Java+Netbeans can take quite a while. We have found it to take a long time to fine-tune certain settings. To solve this problem our team has developed a specialized Java class called Settings.

It allows us to store settings on a text file (settings.txt) on the root of the cRIO. Then, we can change the file, upload it through FTP, and the values are instantly changed. This has proved invaluable to our development process. I thought I would share this to help other teams that may be having similar problems.

For example, in our code we use Settings.getDouble("Min Radius") so that the minimum radius required for vision tracking can be changed at run time. This has saved us hours of debugging time!

Our Settings.java file can be found on our team's site here (http://cuttingedgerobotics.org/sites/default/files/settings/Settings.java)

Here's our settings.txt file (http://cuttingedgerobotics.org/sites/default/files/settings/settings.txt) which can be used as an example for the syntax of the file. Basically, it's just "key = value" for each line.

We have been able to configure Textpad (http://www.textpad.com/download/index.htm) to upload the current file to the robot by only pressing Control + 4. If you want help configuring Textpad to do this, I can post a guide here.

If you attempt to retrieve a setting that does not exist in the file it will throw a NullPointerException. Also, any lines in the settings.txt file that don't have an "=" character are simply ignored. Finally, you must have a setting with a key of "Autoupdate Delay" which specifies the number of milliseconds before the settings.txt file will be read again.

Hope this helps,
Thomas Hansen
Team 3006

MattD
09-02-2010, 01:42
Thanks for sharing this! Coincidentally, I was just about to try and write something like this tonight. All this is missing is a way to save a setting back to the file.

Delian
09-02-2010, 11:34
As Thomas mentioned, the way our team FTP's the settings.txt onto the robot is with Textpad since the ftp.config file is already created in the Netbeans project, all you have to do is install the FTP add-on onto Textpad. This makes the change time less than 3 seconds, all you have to do is switch windows and press Ctrl 4 and it will be updated live onto the code.

We will be posting a tutorial on how to use settings onto our website within the next few days.