Skip to content

Instantly share code, notes, and snippets.

@NoahAndrews
Last active December 7, 2017 03:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NoahAndrews/bf86b3fef3fcbfd4962b530947422c01 to your computer and use it in GitHub Desktop.
Save NoahAndrews/bf86b3fef3fcbfd4962b530947422c01 to your computer and use it in GitHub Desktop.
Switching the config file from within an OpMode

To start with, create a new RobotConfigFileManager. You'll need to pass in the main activity if you want the UI to update when the config changes (which you should so no one gets confused). However, if you pass null, that shouldn't cause any problems. There are null checks whereever the parameter is used internally.

To get the main activity, use (FtcRobotControllerActivity)hardwareMap.appContext (only guaranteed to work on version 3.5)

Next, create a new RobotConfigFile. You'll need to pass in the file manager you created before, as well as the name of the config you want to switch to.It should work with or without the .xml extension, but it will strip out the extension behind the scenes.

Then call setActiveConfigAndUpdateUI(false, myRobotConfigFile) on your instance of RobotConfigFileManager. (replace myRobotConfigFile with whatever you named your instance of RobotConfigFile) There are variations on that method, but that is the one you want. It will tell the Driver Station about the new config.

That should do it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment