Editing code in a nutshell - Brighton-FTC/FTC-2023 GitHub Wiki
| Table of Contents |
|---|
| What's what in the code |
| Creating an OpMode |
| OpMode Examples |
| Testing Code |
| 1. Click the bar above the files and select "Android" | 2. Please see the following diagram for the useful code files we can edit. They will be commented with documentation. |
|---|---|
![]() |
![]() |
- There are also external libraries not visible in this view. To show one,
Ctrl+Clicka reference to it in the code.
-
com.arcrobotics.ftclibFTCLib - our main library for hardware, etc. [Docs] [Reference] -
com.qualcomm.robotcore.hardwareHardware - Use FTCLib instead of these if you can. [Reference]
โ ๏ธ Our method of creating an OpMode with our libraries is slightly different to the vanilla methods. Please be careful when looking at other documentation.
- Either:
a) Right-click the file and copy your OpMode from the external.samples folder, then paste it in our opModes folder (see above). Rename it (using CamelCaseWhereWordsAreJoinedLikeThis), click "OK", then comment out the @Disabled line (Ctrl+/)
| 1 | 2 | 3 |
|---|---|---|
![]() |
![]() |
![]() |
or:
b) Right-click our opModes folder, create a new Java class, give it a name, and paste one of the templates below into the file. Click the first package line where an error may appear and then Alt+Enter and Enter, to fix it if necessary. Then, replace "<ClassName>" with the name you just used for the class.
| 1 | 2 | 3 |
|---|---|---|
![]() |
![]() |
![]() |
package org.firstinspires.ftc.teamcode.opModes;
import com.qualcomm.robotcore.eventloop.opmode.TeleOp;
import org.firstinspires.ftc.teamcode.libs.brightonCollege.modeBases.TeleOpModeBase;
/**
* Description: [Fill in]
* Hardware:
* [motor0] Unused
* [motor1] Unused
* [motor2] Unused
* [motor3] Unused
* [servo0] Unused
* [servo1] Unused
* [servo2] Unused
* [servo3] Unused
* Controls:
* [Button] Function
*/
@TeleOp(name="<OpMode name>", group="<OpMode group name>")
public class <ClassName> extends TeleOpModeBase {
// Declare class members here
@Override
public void setup() {
// Code to run once after `INIT` is pressed
}
@Override
public void every_tick() {
// Code to run in a loop after `PLAY` is pressed
}
}package org.firstinspires.ftc.teamcode.opModes;
import com.qualcomm.robotcore.eventloop.opmode.Autonomous;
import org.firstinspires.ftc.teamcode.libs.brightonCollege.modeBases.AutonomousModeBase;
/**
* Description: [Fill in]
* Hardware:
* [motor0] Unused
* [motor1] Unused
* [motor2] Unused
* [motor3] Unused
* [servo0] Unused
* [servo1] Unused
* [servo2] Unused
* [servo3] Unused
*/
@Autonomous(name="<OpMode name>", group="<OpMode group name>")
public class <ClassName> extends AutonomousModeBase {
// Declare class members here
@Override
public void setup() {
// Code to run once after `INIT` is pressed
}
@Override
public void every_tick() {
// Code to run in a loop after `PLAY` is pressed
}
}package org.firstinspires.ftc.teamcode.opModes;
import com.qualcomm.robotcore.eventloop.opmode.Autonomous;
import com.qualcomm.robotcore.util.ElapsedTime;
import org.firstinspires.ftc.teamcode.libs.brightonCollege.modeBases.AutonomousLinearModeBase;
/**
* Description: [Fill in]
* Hardware:
* [motor0] Unused
* [motor1] Unused
* [motor2] Unused
* [motor3] Unused
* [servo0] Unused
* [servo1] Unused
* [servo2] Unused
* [servo3] Unused
*/
@Autonomous(name="<OpMode name>", group="<OpMode group name>")
public class <ClassName> extends AutonomousLinearModeBase {
// Declare class members here
private ElapsedTime runtime = new ElapsedTime();
@Override
public void run() {
// Code to run once INIT is pressed
waitForStart();
// Code to run once PLAY is pressed
runtime.reset();
// Run until the driver presses STOP
while (opModeIsActive()) {
// Code to run in a loop
telemetry.addData("Status", "Run Time: " + runtime.toString());
telemetry.update();
}
}
}Please click a heading to view the code.
- You're now ready to use the OpMode! Here are some vital classes from our library:
-
Inputs.gamepad1andInputs.gamepad2- the GamepadEx classes for getting inputs from the driver. Please use gamepad1 most of the time. (Only works in Driver-Controlled) -
TelemetryContainer.getTelemetry()- returns a Telemetry object used to print messages to the driver. -
HardwareMapContainer.getMap()- returns a HardwareMap needed in some situations, e.g. with FTCLib. -
HardwareMapContainer.motor0through toHardwareMapContainer.motor3- returns a Motor plugged into the port indicated by the number. -
HardwareMapContainer.servo0through toHardwareMapContainer.servo3- returns a Servo plugged into the port indicated by the number.
- Anywhere, when not connected to the robot, click "Build" to check that the code can compile.
| 1 - Build the project | 2 - View the logs |
|---|---|
![]() |
![]() |









