Getting Started with FTC Programming: A Complete Beginner's Guide
Learn the fundamentals of FTC robot programming, from setting up Android Studio to writing your first OpMode. Perfect for teams just starting their coding journey.
Getting Started with FTC Programming
Welcome to the world of FTC programming! Whether you’re a complete beginner or transitioning from another programming environment, this guide will help you understand the basics and get your robot moving.
What You’ll Need
Before we dive in, make sure you have:
- Android Studio - The official IDE for FTC development
- FTC SDK - The software development kit provided by FIRST
- A Control Hub or Phone - Your robot’s brain
- Basic Java knowledge - Don’t worry, we’ll cover the essentials!
Setting Up Your Environment
Step 1: Install Android Studio
Download Android Studio from the official website. During installation, make sure to include the Android SDK and emulator tools.
Step 2: Clone the FTC SDK
git clone https://github.com/FIRST-Tech-Challenge/FtcRobotController.git
Open the project in Android Studio and let Gradle sync. This might take a few minutes on first run.
Step 3: Connect Your Control Hub
Connect your Control Hub to your computer via USB. Android Studio should recognize it as a device.
Your First OpMode
An OpMode is the code that runs on your robot. There are two types:
- LinearOpMode - Runs sequentially from top to bottom
- OpMode - Uses a loop-based structure with init, loop, and stop methods
For beginners, we recommend starting with LinearOpMode:
@TeleOp(name = "My First OpMode", group = "Tutorial")
public class MyFirstOpMode extends LinearOpMode {
// Declare motors
private DcMotor leftMotor;
private DcMotor rightMotor;
@Override
public void runOpMode() {
// Initialize hardware
leftMotor = hardwareMap.get(DcMotor.class, "left_motor");
rightMotor = hardwareMap.get(DcMotor.class, "right_motor");
// Wait for the game to start
telemetry.addData("Status", "Initialized");
telemetry.update();
waitForStart();
// Run until the end of the match
while (opModeIsActive()) {
// Get gamepad input
double drive = -gamepad1.left_stick_y;
double turn = gamepad1.right_stick_x;
// Calculate motor powers
double leftPower = drive + turn;
double rightPower = drive - turn;
// Set motor powers
leftMotor.setPower(leftPower);
rightMotor.setPower(rightPower);
// Show telemetry
telemetry.addData("Left Power", leftPower);
telemetry.addData("Right Power", rightPower);
telemetry.update();
}
}
}
Understanding the Code
Let’s break down what’s happening:
Hardware Mapping
leftMotor = hardwareMap.get(DcMotor.class, "left_motor");
This line tells the code to look for a motor named “left_motor” in your robot configuration. Make sure the name matches exactly!
The Game Loop
while (opModeIsActive()) {
// Your code here
}
This loop runs continuously while your OpMode is active. It’s where you read inputs and control outputs.
Telemetry
telemetry.addData("Status", "Running");
telemetry.update();
Telemetry displays information on the Driver Station. It’s incredibly useful for debugging!
Common Mistakes to Avoid
- Forgetting
telemetry.update()- Data won’t show without this call - Wrong hardware names - Double-check your configuration
- Not reversing motors - One side usually needs to be reversed for proper driving
- Blocking in the loop - Avoid
sleep()calls that freeze everything
Next Steps
Now that you have the basics down, explore these topics:
- Autonomous programming - Pre-programmed routines
- Sensors - Adding touch, color, and distance sensors
- Encoders - Precise motor control
- Computer Vision - Using the camera for detection
Happy coding! Remember, every expert was once a beginner. Keep practicing, keep learning, and most importantly—have fun!