-
Notifications
You must be signed in to change notification settings - Fork 4
[Tutorial 2.6] Constant Tuning
[Back to the previous tutorial]([Tutorial 2.5] Using the Poultry Inspector)
We already learned about using Cluck to tune values on the robot. It turns out that this is a very common use, but there are other important features provided for tuning constants.
Specifically, it would be nice if tuning values got saved onto the robot so that they don't get erased whenever it restarts.
Fortunately, the CCRE provides functionality for these! Meet the TuningContext
class.
Let's put the following into our previous code
TuningContext context = new TuningContext("Autonomous").publishSavingEvent();
This will create a new TuningContext that publishes on the main Cluck Node and saves data in the "autonomous" storage segment (file), and then it will publish an EventOutput that can be fired to save the data to the robot's disk. The reason that it isn't saved automatically is that it's possible to accidentally change a value, and you only want it to save if you tell it to.
Next, let's replace our previous lines to allocate a FloatStatus with the following:
final FloatStatus autonomousTimeout = context.getFloat("autonomous-timeout", 5);
This means allocate a tunable value with the name "autonomous-timeout" and a default of 5. If you redownload code with a new default value, it will update the saved values regardless of their current setting. This means that you can either tune via the Poultry Inspector as we previously explored or by downloading code if you'd prefer that. (Note that you can also use context.getBoolean(...)
for similar functionality on BooleanStatus
.)
You don't need to publish it - that's already taken care of.
Let's try this out in the emulator! Try changing the value and see it change the length of the timeout, and then reopen the emulator and notice how it still resets. Now try it again, but this time drag out robot/Save Tuning for Autonomous
and right-click on it before restarting the emulator.
Now once you reopen the emulator, notice how the value was preserved from last time.
Cool, huh?
This will prove very useful for rapidly changing options on your robot - keep in mind that it can be used for much more than just Autonomous mode. For example, we used it to control settings on our shooting mechanism.
Next: [The Concurrency Framework]([Tutorial 3.1] The Concurrency Framework)