Skip to content
CrocoDocs
Starter GuideProgrammingEngineeringDesignPortfolio
Documentation

Introduction

IntroductionBIOBUZZ game overview

Getting started

Getting startedBlocksOnBot JavaAndroid StudioYour first OpModeJava basicsMotors and servosNonblocking codeDebugging robot code

Control systems

Control systemsJoystick mappingField-centric mecanum drivePID controlFeedforwardFlywheel velocity controlSystem identificationMotion profilingKalman filterLow-pass filter

Autonomous

AutonomousTimed and encoder movementOdometryLocalization troubleshootingMotion planningReliable autonomous sequencesPure PursuitSensor fusionAuto to TeleOp handoff

Season topics

Season topicsProjectile mathematicsTurret aimingShooting on the move

Code practices

Code practicesNaming conventionsCode organizationLoop timing and bulk readsFormattingComments and documentationTeam collaboration

Libraries

LibrariesNextFTCFTCLibSolversLibPedro PathingRoad RunnerFTC DashboardMercurial v2Mercurial v1PanelsSloth

Community software

Community softwareBlaze FTCOpenLoopHive Vision

Sensors and vision

Vision overviewVision basicsLimelight 3A
Starter Guide
Engineering
Design
Portfolio
Appearance

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 .

Four steps in the Android Studio workflow: edit TeamCode, build the app, install it on the Robot Controller, and test from the Driver Station.

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:

  1. hardwareMap.get finds the configured motor.
  2. waitForStart pauses until a driver presses START.
  3. Each trip through the while loop reads the left stick, sets motor power, and shows that value on the Driver Station.
  4. - makes a forward stick push positive. 0.25 limits 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

  1. Use Build → Make Project. Fix any error shown in the Build window before continuing.
  2. 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.
  3. On the Driver Station, select One Motor, press , then START.
  4. 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.

Sources

  • FTC Android Studio tutorial
  • FTC SDK project and release notes
  • Android Studio
  • FTC SDK release notes

OnBot Java

Write, build, and run Java OpModes in a browser

Your first OpMode

Read the FTC lifecycle and run a complete telemetry-only Java program

On this page

OverviewSoftware setupTeamCodeMotor exampleDeployment and testingNext stepsSources