Skip to content

Instantly share code, notes, and snippets.

@MatthewOates36
Last active April 29, 2024 00:11
Show Gist options
  • Save MatthewOates36/1e38452236dc9f145c3a6b2addfb418f to your computer and use it in GitHub Desktop.
Save MatthewOates36/1e38452236dc9f145c3a6b2addfb418f to your computer and use it in GitHub Desktop.
Installation and Usage Instructions for FTC Fast Load v0.1.2

FTC Fast Load

Library for FTC teams allowing quick changes to TeamCode files to speed up the software development process.

The fast load works through a combination of an Android Gradle plugin and a small Android library included in the FtcRobotController app. The Gradle plugin creates a streamlined build process for TeamCode classes. The result of this build process is a slim bundle containing only TeamCode classes which is a few hundred KB opposed to the full FtcRobotController APK which is ~50MB. This small bundle allows for sub-second installs. Finally, the Android library contains a custom classloader to reload the TeamCode classes from this bundle which eliminates the need for restarting the FtcRobotController app.

The result of these optimizations is, in our testing, a 70-90% reduction in deploy times depending on development computer. Note that the majority of install time will now be the Gradle build as the actual install and reload takes approximately 4 seconds will little variance.

Warnings

  1. Changes through fast load will NOT be reloaded after a robot power cycle (Control Hub being turned off and back on causing the FtcRobotController app to reboot) so a TeamCode install must be preformed for changes to become permanent.
  2. Fast Load is NOT compatible with OnBotJava. The library uses part of the OnBotJava mechanism for classloading, so once a fast load is run OnBotJava will not work until the app is restarted.

Installation

In the TeamCode build.gradle file located at TeamCode/build.gradle insert the listed lines to add the fast load plugin and library as dependencies to your project. Here is a reference adding these items to the default FtcRobotController v8.2 TeamCode build.gradle, if you copy this file be sure to replace {version} with the latest version of the dependencies listed below or in the title of this gist.

  1. by default a buildscript block is not included. if this is the case add the following before the apply section at the top of the file
    buildscript {
    
    }
    
  2. inside the buildscript block add repositories and dependencies blocks if they do not yet exist
    repositories {
    
    }
    
    dependencies {
    
    }
    
  3. in buildscript.repositories add
    mavenCentral()
    
  4. in buildscript.repositories add
    maven {
        url = 'https://www.matthewo.tech/maven/'
    }
    
  5. in buildscript.dependencies add
    classpath 'org.team11260:fast-load-plugin:0.1.2'
    
  6. now at the end of the apply section after lines that look like apply from ... put
    apply plugin: 'org.team11260.fast-load-plugin'
    
  7. the repositories block (not to be confused with buildscripts.repositories) does not exist by default in this file, if it doesn't add
    repositories {
            
    }
    
  8. inside at the end of the repositories block add
    maven {
        url = 'https://www.matthewo.tech/maven/'
    }
    
  9. inside at the end of the dependencies block (should exist in the base FtcRobotController) add
    implementation 'org.team11260:fast-load:0.1.2'
    
  10. finally, run a Gradle sync in Android Studio to pull in the new dependencies

Usage

ADB is required for the fast load process. Wireless ADB has the most testing and was the focus in development but wired ADB is also compatible.

A standard TeamCode install must be run after the Installation steps have been completed before the fast load will work. To run a fast load use the Gradle tasks tool window (at the top of the right sidebar in Android Studio by default). There are two ways of running the task for the first time:

  • To run from the Execute Gradle Task menu open from the Gradle tool window.

    image

    Type in reloadFastLoad and hit enter to run.

    image

  • You can also run the task by navigating to {project name}.TeamCode.Tasks.install.

    image

    Finally, run reloadFastLoad by double-clicking on it.

When this Gradle task has completed successfully the fast load is finished. After running this task for the first time you can choose between fast load (reloadFastLoad) and standard (TeamCode) installs from the Run Configuration selector.

image

Notes

  1. The library does not modify the SDK, but does use reflection to edit private fields only when a fast load is preformed.
  2. All modifications to Op Mode registrations should properly be reflected on the Driver Station after a fast load.
  3. For teams which use FTC Dashboard, it will not properly handle Op Mode registration changes or Configuration Variable editing with a fast load. If you modify Op Mode registration name, class name, or enabled status a robot restart or TeamCode download should be preformed to refresh Op Mode registration.

Source

Benchmarks

The following are speed benchmarks from the computers used by the 11260 software team. Times are an average of 3 runs from beginning the Gradle build until the robot is ready to run. For a TeamCode install ready to run is the Control Hub lights turning green indicating the robot is ready to run. For a fast load when the reloadFastLoad task completes the robot is ready to run.

First, an initial run of the given Gradle task was used to warm up the Gradle cache. The benchmark runs then occurred after changing the string name of a single Op Mode which would force an incremental build to best match the standard software development workflow.

All tests were completed using wireless ADB.

Results:

  1. 2021 Apple MacBook Pro, M1 Max, 64GB unified memory
    1. Team11260 CRI codebase (includes Java and Kotlin classes)
      1. TeamCode install + app startup: 58s
      2. fast load: 7s
      3. 88% faster
    2. FTCRobotController v8.2 (containing a single Java Op Mode)
      1. TeamCode install + app startup: 53s
      2. fast load: 5s
      3. 91% faster
  2. 2018 Dell XPS 13 9365, Intel i7-7Y75, 16GB ram
    1. Team11260 CRI codebase (includes Java and Kotlin classes)
      1. TeamCode install + app startup: 89s
      2. fast load: 27s
      3. 70% faster
    2. FTCRobotController v8.2 (containing a single Java Op Mode)
      1. TeamCode install + app startup: 78s
      2. fast load: 18s
      3. 77% faster

Note that in general faster computers will have a higher percentage increase in download speed as the fast load cuts the majority of time out of the installation and reload process.

Release Information

  • v0.1.2
    • Fixed bug where Op Modes containing method references may not appear after a fast load (thanks to FTC discord user @thesimg for reporting).
    • Fixed bug where removed or renamed classes cause a non-fatal error.
    • Minor speed improvement thanks to reduced exceptional control flow and logging.
  • v0.1.1
    • Updated dependencies for SDK v9.0 compatibility.
    • Enhanced Gradle task exception handling to give more specific errors and remedies.
  • v0.1
    • Initial release.
@FriendlyGuardian
Copy link

FTC Team 21430 BroomBots here, FTC fast load was the first thing that we installed into our Center Stage repo. Right out of the gate our software changes had already been installed on our control hub before we even touched the driver station! This tool will save my team SO MUCH TIME and let us focus on the more important things like programming our autonomous and not staring at slow progress bars. On behalf of the BroomBots, we thank the creator of this tool for making it possible to have a functioning robot by our first scrimmage in 3 weeks. Thank you :)

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