Profiles & Configuration - addonovan/ftc-ext GitHub Wiki

What is a Profile?

Imagine, if you will, that your robot has to perform slightly different autonomous programs based on which alliance you're assigned in the match. The most common solution is to have two different programs, one for the red alliance and one for the blue alliance; however, it is easy for these programs to get out-of-sync with each other, especially if they are actually two separate classes (as opposed to having one actual program which is passed an input (by the OpModes built on top of it) to tell it the alliance color and), and having two OpModes in the available list for every type of autonomous can get kind of cluttered.

A profile aims to fix this, and more, by allowing you to assign certain variables values based off of a configuration file (and, if that fails, the variable will default to a value you've set), and then edit that file. If you were to make every constant in your programs into a configurable variable, you would essentially never have to reprogram the robot, simple edit the profile, from the Robot Controller app itself!

Using the configuration framework

Currently, four data types are supported:

  • long
  • double
  • boolean
  • String (note: ints would be supported, but there is no need to differentiate them from longs when longs might be used for things ints couldn't (i.e. timing).) If you need a data type that isn't one of these, you will need to find a way to convert it to and from one.

To access the profile configurations, you will need to call one of the four get methods, supplied by the OpMode and LinearOpMode classes, passing in the name of the key to fetch and the default value that will be used if the value couldn't be found. The correct method will be determined by the compiler based on the default value. The four signatures are listed below:

  • long get( String, long )
  • double get( String, double )
  • boolean get( String, boolean )
  • String get( String, String ) Neither the name (the first parameter) nor the default (the second) may be null, and a NullPointerException will be thrown if either is.

And voilà, you're all set up to start creating profiles and using the configuration framework!

Configuring Profiles

Profile configuration is actually done in-app in the robot controller app! It's pretty neat. On your first run with the library, a toast message should notify you of how to access the configuration settings; however, if you missed it, or are just reading this guide before using the library, here's how you can access the menu.

Watch the phone icon with the robot in the top-left corner, the "button" on the phone will start blinking red, as seen below. This is a signal that you can click on the icon to access the configuration settings.
Flashing robot icon
Once you're in the configuration settings, simply select the OpMode you wish the configure, then that OpMode's profile (or create a new one, also possible), and configure to your heart's desire. To set the active profile (which is the profile that is used by the OpMode when running), simply press the button labeled to do so.

In order to tell what configuration an OpMode is running with, the profile is appended to the OpMode's name when the OpMode is selected, so the robot controller will say "OpMode: {OpModeName} [{Profile Name}]".