498
Control Lab FRC Programming Curriculum
Fundamentals · L01 of 8

What is a program?

Objectives 0 / 3

Hook

Your first robot task: move an arm from 0° to 90° and hold it there.

You write what seems obvious:

void periodic() {
    arm.moveToAngle(90);
}

The robot doesn’t move. There is no moveToAngle method — the arm doesn’t know what that means. It only knows “set motor power to this number.” You can’t tell the robot what to accomplish. You have to tell it exactly how, step by step.

Core concept

Key Concept

A program is a sequence of instructions, executed in order, by something that does exactly what you say — no more, no less.

That last part is the trap. A computer will do precisely what your program tells it to. If your program is wrong in a subtle way, the robot will be subtly wrong, confidently, fifty times a second.

Walk-through

The task: move an arm from 0° to 90°. The arm has a motor and an encoder (a sensor that measures the current angle).

Instead of “move to 90°” (a goal), the program has to describe exactly what to do:

  1. Read the current angle from the encoder.
  2. If the angle is less than 88°, run the motor forward.
  3. If the angle is greater than 92°, run the motor backward.
  4. If the angle is between 88° and 92°, stop the motor.
  5. Go back to step 1.

That’s not five goals — it’s five actions the hardware can actually do. The robot executes this loop fifty times per second. Each cycle it reads the sensor, makes a decision, and acts.

Interactive demo

Here’s those five steps as real Java code. The arm starts at 45°. Step through and watch what the program actually does:

Code Tracer
1void periodic() {
2 double angle = encoder.getAngle();
3 if (angle < 88) {
4 motor.set(0.5);
5 } else if (angle > 92) {
6 motor.set(-0.5);
7 } else {
8 motor.set(0.0);
9 }
10}
State
call1
angle45
motor0

Step through to see values update.

Press Start to begin stepping through the code.
Initial state

The program never says “go to 90°.” It says: read the sensor, compare to a threshold, set a motor power. The robot reaches 90° as a consequence of running those four lines thousands of times.

⚠ Heads up

Notice what happens if you remove the else branch: the motor never gets turned off. The arm would overshoot 90°, then the angle > 92 check would kick in and drive it back — past 88°, triggering the forward motor again. The arm would oscillate forever. Every branch matters.

Try it yourself

⚡ Try it yourself

Trace this program by hand. Write the value of angle after each step before you check.

int angle = 0;
angle = angle + 30;  // Step A
angle = angle + 30;  // Step B
angle = angle - 10;  // Step C
angle = angle + 30;  // Step D
Code Tracer
1int angle = 0;
2angle = angle + 30;
3angle = angle + 30;
4angle = angle - 10;
5angle = angle + 30;
State
angle0

Step through to see values update.

Press Start to begin stepping through the code.
Initial state
⚡ Check your understanding

What is the value of angle after Step D?

Key takeaways

  • A program is a sequence of instructions, executed in order.
  • Computers do exactly what you say — including your mistakes.
  • Robot programs loop continuously, reading sensors and acting on what they find.
  • “Move to 90°” is a goal. “If angle < 88, run the motor forward” is a program.

Common confusions

“This seems too simple.” It is, on purpose. Programs don’t get conceptually harder — they get longer. The skill you’re building right now is being explicit, and it’s easier to learn on something small.

“Won’t the robot figure out what I mean?” No. A robot has no common sense — only instructions. Every 498 senior has spent at least one late night debugging because they assumed the robot knew something it didn’t.

Challenge

⚡ Try it yourself

A robot arm starts at 0°. Your program runs four moves in sequence. Write them as Java statements and print the final angle.

Moves: add 45°, add 30°, subtract 20°, add 10°

Code EditorJavaCtrl+Enter to run
Stuck? Show hint

Each move is one line: angle = angle + 45; etc. Execute them in order, then print.

What’s next

In Lesson 02, we’ll look at state and memory — how a program remembers values between loop cycles, and why where you declare a variable can quietly break everything.