Set up 4: add the library
Do it once per robot project, usually a mentor or the code lead. After you commit and push it, everyone who clones the project gets the library.
Skip this page if there is already an ftc-helper-lib folder next to TeamCode, with files in it.
How it works
Section titled “How it works”The library goes inside your robot project as a git submodule: a project kept inside another project. Your project remembers exactly which version of the library it uses. Why a submodule: it works at events with no internet, you can read the library’s code in Android Studio, and the whole team gets the same version.
You need
Section titled “You need”- The robot project open in Android Studio, synced (page 3).
- Git in Android Studio’s Terminal tab:
git --versionprintsgit version 2...(the Terminal).
Step 1: add the submodule
Section titled “Step 1: add the submodule”Type this line and press Enter.
Where: Android Studio’s Terminal tab, in the project folder (a new Terminal tab starts there). (Which folder)
git submodule add https://github.com/crossbotics/ftc-helper-lib.git ftc-helper-libA new folder, ftc-helper-lib, is now next to TeamCode.
For a fixed version instead of the newest, read Use a specific version after this page.
Step 2: tell Gradle about the library
Section titled “Step 2: tell Gradle about the library”-
Open
settings.gradle. It is in the top project folder, not inTeamCode. -
At the bottom you see:
include ':FtcRobotController'include ':TeamCode' -
Add these two lines under them:
include ':ftc-helper-lib'project(':ftc-helper-lib').projectDir = new File(rootDir, 'ftc-helper-lib/library')
Why the second line: the submodule also holds examples, docs and the simulator. The robot app needs
only the library folder.
Step 3: let TeamCode use the library
Section titled “Step 3: let TeamCode use the library”-
Open
TeamCode/build.gradle. -
Find the
dependencies { ... }block at the bottom. -
Add one line inside it:
dependencies {implementation project(':FtcRobotController')implementation project(':ftc-helper-lib') // <- add this line}
Step 4: sync
Section titled “Step 4: sync”Click Sync Now in the yellow bar at the top of the editor (or File > Sync Project with Gradle Files). Wait until it finishes with no red errors.
Step 5: check that it works
Section titled “Step 5: check that it works”-
In the
teamcodefolder, make a new Java file namedHelperCheck(right-clickteamcode> New > Java Class). -
Replace everything in it with this:
package org.firstinspires.ftc.teamcode;import com.qualcomm.robotcore.eventloop.opmode.LinearOpMode;import com.qualcomm.robotcore.eventloop.opmode.TeleOp;import com.crossbotics.ftchelper.util.Angles;@TeleOp(name = "Helper Check")public class HelperCheck extends LinearOpMode {@Overridepublic void runOpMode() {telemetry.addData("Library works", Angles.shortestDiff(-170, 170) == 20);telemetry.update();waitForStart();}} -
Build: Build > Make Project (or the hammer: the buttons). When it builds, the library is in. Why it proves it: the
import com.crossbotics...line only works when the library is there. -
Delete
HelperCheck.java.
Step 6: commit and push
Section titled “Step 6: commit and push”Why: teammates get the library only after you commit and push it.
Where: Android Studio’s Terminal tab, in the project folder (a new Terminal tab starts there). (Which folder)
git add .gitmodules ftc-helper-lib settings.gradle TeamCode/build.gradlegit commit -m "Add ftc-helper-lib"git pushIn GitHub Desktop: tick those four, type the message, click Commit to main, then click Push origin.
The simulator buttons (you do nothing)
Section titled “The simulator buttons (you do nothing)”At each Gradle sync, the library adds three entries to the run list (the buttons):
- Simulator: a pretend robot on your laptop, in your browser (the simulator).
- Simulator tests: runs your project’s simulator tests.
- Update library: gets the newest library version (Keep it up to date).
If they are not in the list, click File > Close Project, then open the project again.
To turn them off, write simulatorButtons=false in your project’s gradle.properties.
Done when
Section titled “Done when”The test build passed, you deleted HelperCheck.java, and you pushed the change.
Next: Update the hubs.
Look it up: Keep the library up to date and The simulator.
Something wrong on this page? Tell us with a short GitHub form.