Log in

View Full Version : Saving values on cRIO


xf!r3
16-02-2014, 23:33
My team's robot has an arm with a potentiometer on it and I am trying to write a method that will save the current value of the pot and save it into the code so we can still have it when we restart the robot and not have to edit our code. Since I'm not exactly sure how to go about it I would like to know what is the most efficient way to do this. The language we are using is Java.

otherguy
17-02-2014, 01:04
You may find team 254s implementation of a constants.txt file useful:
https://github.com/Team254/FRC-2013/blob/master/src/com/team254/lib/util/ConstantsBase.java
https://github.com/Team254/FRC-2013/blob/master/src/com/team254/frc2013/Constants.java

It doesn't write out to a file. It looks for a text file on the crio at startup and allows you to override default values of variables in your program.

I'm assuming you want the ability to calibrate your arm angle without having to recompile code. This could be achieved by uploading new versions of a constants.txt file over FTP to your robot using the above implementation.

You could alternatively extend this implementation to allow the constants.txt file to be written to by the robot. Take a look at java.io.DataOutputStream (http://team2168.org/javadoc-2013/java/io/DataOutputStream.html)

Joe Ross
17-02-2014, 01:42
We use the Preferences class built into WPILib.

CooneyTech
17-02-2014, 07:06
Potentiometer or encoder? A potentiometer will always keep its position even without power whereas an encoder loses its position after power is lost. If it is a potentiometer you shouldn't need to save the value.

otherguy
17-02-2014, 10:14
If it is a potentiometer you shouldn't need to save the value.

Except for when you need to do maintenance on your mechanism, or replace a broken potentiometer. Any time you decouple the pot from the mechanism you'll likely need to recalibrate your zero.