Android Studio
Set up the FTC project and run one small Java OpMode
Overview
Android Studio is the computer app used to edit and build the project. Your team's programs live in its TeamCode module. This path is useful when your team wants a full code editor, Git, or libraries that need changes to the Android Studio project.
If this is your first time programming a , start with Blocks to learn how the Robot Controller and work. You can return here when you are comfortable selecting and running an .
The Robot Controller runs your program. The Driver Station selects the program and starts or stops it. Building code on your computer does not put it on the robot; you must install the built app on the Robot Controller.
Software setup
Install Android Studio. The current FTC SDK release notes list the minimum Android Studio version. For SDK 12.0, that is Narwhal 3 Drop or later. Use the release notes again when your the SDK.
Download the official FTC Robot Controller project. You can use Code → Download ZIP and extract it, or clone the repository if you already use Git. A ZIP is enough for this first exercise; Git is not required just to open the project.
Open the project folder in Android Studio and allow its Gradle sync to finish. Gradle downloads the the project needs. Your first sync can take longer because it needs an internet connection.
Keep your team code during SDK updates
Before changing SDK versions, copy or commit your TeamCode work and read the release notes for breaking changes. An SDK update can change an API used by an older OpMode.
TeamCode
In Android Studio, open this folder:
TeamCode/src/main/java/org/firstinspires/ftc/teamcode/TeamCode is your team's module. FtcRobotController contains the controller app and SDK samples. Put the new file below in the teamcode package, and name it OneMotor.java.
Motor example
First, configure a on the Robot Controller and name it test_motor. The text inside hardwareMap.get(..., "test_motor") must match that configuration name exactly, including capitalization.
Support the robot so the motor can turn without moving the robot or catching a . Start at low power.
package org.firstinspires.ftc.teamcode;
import com.qualcomm.robotcore.eventloop.opmode.LinearOpMode;
import com.qualcomm.robotcore.eventloop.opmode.TeleOp;
import com.qualcomm.robotcore.hardware.DcMotor;
@TeleOp(name = "One Motor")
public class OneMotor extends LinearOpMode {
@Override
public void runOpMode() {
DcMotor motor = hardwareMap.get(DcMotor.class, "test_motor");
telemetry.addData("Status", "Ready");
telemetry.update();
waitForStart();
while (opModeIsActive()) {
double power = -gamepad1.left_stick_y * 0.25;
motor.setPower(power);
telemetry.addData("Motor power", power);
telemetry.update();
}
motor.setPower(0);
}
}Read the code in this order:
hardwareMap.getfinds the configured motor.waitForStartpauses until a driver presses START.- Each trip through the
whileloop reads the left stick, sets motor power, and shows that value on the Driver Station. -makes a forward stick push positive.0.25limits this first test to one-quarter power.
The sign of “forward” depends on how your motor is mounted. If the motor turns the opposite way from what you expect, check its direction rather than removing the power limit.
Deployment and testing
- Use Build → Make Project. Fix any error shown in the Build window before continuing.
- Connect your Robot Controller to Android Studio using your team's supported USB or wireless deployment setup, then run the TeamCode app configuration. See the official Android Studio tutorial for the connection and install steps.
- On the Driver Station, select One Motor, press , then START.
- Move the left stick slightly and check both the motor and the Motor power telemetry value. Press STOP when finished.
If One Motor does not appear, confirm that the build succeeded, the new app was installed on the correct Robot Controller, and the file is in TeamCode. If initialization fails with a hardware-name error, compare test_motor with the active robot configuration.
Next steps
Try joystick mapping once one motor responds correctly. Add a second motor only after you can explain what each line above does.