Skip to main content

Control & Feedback

Easydifficulty

People tend to meet control through PID, but PID is one rule inside a much bigger pattern. Every mechanism on a robot goes through the same four steps:

  1. You want something to happen.
  2. The mechanism does something close to it, but not exactly.
  3. A sensor tells you what actually happened.
  4. Your code picks the next motor command.

Arm control, flywheel speed, heading hold, odometry correction, and path following are all versions of that loop.

An arm that holds in the pits and sags in a match​

Say you have a scoring arm, and in testing you find that 0.28 motor power holds it at the right angle. The battery is full and the robot is sitting on the bench.

Then the match starts. The battery drops a volt, the intake picks up a game element, and a cable starts rubbing against the arm. 0.28 no longer holds the same angle. Nothing is wrong with the robot. The code sent a fixed command and never checked whether it worked, which is what open-loop control means.

Feedback closes that gap. Each loop the code asks where the arm should be, where it is, and how hard to push next.

When open loop is good enough​

Open-loop control sends an output without looking at the result. A timed autonomous drive is the classic example:

FTCOpen-loop drivetrain timing
frontLeft.setPower(0.5);
frontRight.setPower(0.5);
backLeft.setPower(0.5);
backRight.setPower(0.5);

sleep(700);

frontLeft.setPower(0.0);
frontRight.setPower(0.0);
backLeft.setPower(0.0);
backRight.setPower(0.0);

So is an intake that runs while the driver holds a trigger:

FTCOpen-loop intake
if (gamepad1.right_trigger > 0.2) {
intakeMotor.setPower(1.0);
} else {
intakeMotor.setPower(0.0);
}

Both of these are often fine. The intake doesn't need to stop anywhere in particular, and a short timed move can be good enough for a low-stakes part of auto. Whether you need feedback depends on the job:

  • Does the mechanism need to end up somewhere specific, or just move?
  • Will battery voltage, load, or contact with another robot change the result?
  • Do you have a sensor that can tell you whether it worked?
  • How much does a bad final position cost you in a match?

If accuracy matters, disturbances are likely, and you have a sensor, you want feedback.

Seeing the difference​

The demo uses room temperature instead of an arm because it is easy to read, but it is the same situation. The open-loop heater keeps doing the same thing no matter what. The closed-loop heater measures the temperature and reacts.

Live demoOpen loop vs. closed loop heating
Closed-loop room (feedback)Open-loop room (fixed power)Setpoint 21°C
Drag me down — feel the open-loop room get cold.
Closed-loop: —Open-loop: —Closed-loop heater: —

Change the outside temperature and watch both rooms. The open-loop room has no idea anything changed. The closed-loop room sees its error grow and turns the heat up.

Error, command, and plant​

Take the arm again. You want it at 90° and the encoder says 84°. The difference, 6°, is the error:

e=r−ye = r - y

where rr is the target (the reference or setpoint) and yy is the measurement. Every feedback controller starts by computing this one number.

The controller then turns error into a command uu. You can write that as a function, u=C(e)u = C(e), without saying yet what CC is. Every controller on this site, from bang-bang to PID, is a different choice of CC.

The mechanism answers the command. Engineers call the mechanism the plant, and it's the part you don't get to design:

yk+1=P(yk,uk,dk)y_{k+1} = P(y_k, u_k, d_k)

The whole difference between the two styles is whether the next command uses the latest measurement:

StyleCommandWhat it can handle
Open loopuk=ufixedu_k = u_\text{fixed}only the conditions it was tuned for
Closed loopuk=C(rk−yk)u_k = C(r_k - y_k)changes in load, voltage, friction, and position

Open loop still has a place. Feedforward, which you will meet later, is an open-loop prediction from a model, and it does most of the work in a good controller. But on its own it can't tell when it's wrong. Closed loop can: if the arm sags, the error goes positive; if the flywheel slows after a shot, the speed error grows. The sensor shows you that something changed without you having to predict it.

Two first controllers​

The simplest feedback rule is bang-bang. Below the target, push up. Above it, push down. Close enough, do nothing:

u={uup,e>ϵudown,e<−ϵ0,∣e∣≤ϵu = \begin{cases} u_\text{up}, & e > \epsilon \\ u_\text{down}, & e < -\epsilon \\ 0, & |e| \le \epsilon \end{cases}

The band ϵ\epsilon is what "close enough" means. Without it the controller waits for the encoder to read exactly the target, which almost never happens, so it keeps switching. uupu_\text{up} and udownu_\text{down} are usually different sizes because gravity fights the arm one way and helps it the other.

FTCBang-bang arm hold with tolerance
static final int TOLERANCE = 20; // encoder ticks

double error = target - measuredPosition;

if (error > TOLERANCE) arm.setPower(0.45); // drive up
else if (error < -TOLERANCE) arm.setPower(-0.25); // drive down
else arm.setPower(0);
ExerciseThe two powers and the tolerance

Why is the upward power bigger? What would the arm do with 0.45 in both directions?

Now set TOLERANCE to zero. The error keeps crossing back and forth by a tick, so the motor gets full up, full down, full up. What does that sound like, and what does it do to the battery?

Show solution

Gravity resists the arm on the way up and helps it on the way down, so the same power gives very different accelerations. With 0.45 both ways the arm slams down, and the driver learns not to trust it.

With zero tolerance the motor can reverse every loop, up to 50 times a second. It buzzes, the gearbox takes shock loads, and every reversal pulls a current spike from the battery, which sags the voltage for everything else on the robot.

ExerciseWhat bang-bang can't fix

The controller has three outputs. It pushes just as hard at 500 ticks away as at 5. What happens as the arm reaches the target?

Show solution

It arrives at full speed, the command drops to zero, and the arm coasts through the target, trips the opposite branch, and comes back. Changing the two powers doesn't help, because the controller has no idea it is getting close. The next controller does.

A proportional controller scales the push with the error. Suppose the arm is 500 ticks from its target and you want about half power there. Half power for 500 ticks is 0.001 power per tick. At 100 ticks away that gives 0.1 power, and at 10 ticks away 0.01. That number is the proportional gain, and the rule is just

u=kPeu = k_P e
FTCProportional arm controller
double error = target - measuredPosition;
double command = kP * error;

arm.setPower(clamp(command, -1, +1));

The arm now pushes hard when it's far away and eases off as it gets close, with no tolerance band to tune. It still overshoots, though. Anything with momentum will carry past the target under a proportional rule, and most of this curriculum is about what to add for that.

ExercisePicking a first kP

error is in ticks and the command is in [−1,1][-1, 1], so kPk_P has units of power per tick. Your arm travels 1,200 ticks and you want about 60% power at the far end of its travel. What kPk_P do you start with?

Show solution

0.6/1200=0.00050.6 / 1200 = 0.0005 power per tick. It's only a starting point, but it comes from your own mechanism's travel, which beats copying a number from someone else's arm.

ExerciseWhere proportional control still fails

Match each symptom to what the controller is missing:

  • the arm stops slightly short and stays there
  • the arm sags under gravity at every angle
  • the arm overshoots and oscillates
Show solution

Stopping short needs an integral term: the leftover error is too small to produce a command that moves the arm, and nothing adds it up over time. Sagging everywhere needs feedforward: a pure feedback controller only reacts after gravity has already pulled the arm down. Overshoot needs a derivative term to slow the approach. All three are covered in the Control Theory module.

The proportional rule is the P in PID. The PID lesson adds a memory of past error and a reaction to how fast the error is changing, but the idea of feeding the measurement back is already all here.

The whole loop in one picture​

sumtarget recontrolleru = C(e)mechanismarm, lift, driveoutput ysensormeasurement returns to the comparison point

Closed-loop control. The sensor turns the output back into information, and that information changes the next command.

Writing the loop so the pieces can change​

In robot code it helps to keep the loop visible: sensors read, the controller computes, the actuator writes, and telemetry records what happened.

FTCA small feedback-control architecture
interface FeedbackSensor {
double getMeasurement(); // in real engineering units
}

interface Actuator {
void setCommand(double c); // normalized to [-1, 1]
}

interface FeedbackController {
double calculate(double setpoint, double measurement, double dt);
}

class FeedbackLoop {
FeedbackSensor sensor;
FeedbackController controller;
Actuator actuator;
double setpoint;

void update(double dt) {
double measurement = sensor.getMeasurement();
double command = controller.calculate(setpoint, measurement, dt);
double safeCommand = clamp(command, -1, +1);
actuator.setCommand(safeCommand);
log(setpoint, measurement, setpoint - measurement, safeCommand);
}
}

Put update() next to the diagram above and each line lines up with an arrow.

ExerciseWhat the three interfaces let you swap

What can you change without touching the rest of the loop if you swap the controller? The sensor? The actuator? Then two smaller questions: why does the clamp sit in update() instead of inside each controller, and why log four values instead of just the command?

Show solution

Swapping the controller takes you from bang-bang to P to PID with the loop unchanged. Swapping the sensor lets an encoder become a potentiometer or a camera. The actuator swap gets overlooked: a fake actuator that only records what it was told lets you unit-test the whole loop at your desk, with no robot.

If the clamp lived in each controller, every controller you write would have to remember it, and the one that forgot would fail without any warning.

The four values matter when you're tuning an oscillating arm with one graph. A noisy measurement with a steady setpoint points at the sensor. A clean measurement with a wildly swinging safeCommand points at the controller. The command on its own can't tell those apart.

Later lessons slot into this shape. P, PID, feedforward plus PID, and a motion-profiled controller can all implement the same FeedbackController interface.

Things to try on the robot​

Use a test stand or put the wheels off the ground first.

  • Drive forward for a fixed time on a full battery, then on a tired one. Does the distance change?
  • Hold an arm with bang-bang and a tolerance. Does it chatter near the target?
  • Switch to proportional control and raise kPk_P until it starts to oscillate. Where is that?
  • Put setpoint, measurement, error, and command on telemetry. When something goes wrong, which one tells you the most?

What feedback can't do​

It can only react to what the sensor reports

If the encoder slips, the IMU drifts, or a camera frame arrives late, the controller reacts to wrong information. Feedback makes a robot correctable, and only as correct as the measurement it gets.

It can't create more voltage

Once the motor is at full power, a bigger command does nothing. That limit changes how controllers behave, especially ones with an integral term, so real code needs output clamps, anti-windup, current limits, and reasonable targets.

A quick diagnostic

If a mechanism only misbehaves after the battery drops, the load changes, or a defender bumps it, ask whether your code can measure that failure. If it can't measure it, it can't correct it.

Next, Module 1 starts with State Machines: how to structure robot code so loops like this one never block.

Sources & references
  • CTRL ALT FTC - FTC-focused explanations of feedback control, PID, and feedforward that inspired this module's practical framing.
  • Tyler Veness, Controls Engineering in FRC - an open robotics-controls textbook covering feedback loops and modeling.
  • WPILib: Introduction to PID Control - a competition-robotics reference for setpoints, measurements, error, and actuator limits.