PID-to-Point
Mediumdifficulty
You now have what autonomous needs: a pose source checked against the Pose Estimation Contract, a mecanum mixer that turns a drive command into wheel powers, and angle wrapping for heading. PID-to-point connects them.
Get to a target pose, with nothing but feedback
Drive from wherever the robot is to a target pose and stop there. The star marks the target. No planned path, no speed plan: each loop, look at how far off you are and push toward the goal.
"Drive at the point at full power until you're close" overshoots, reverses, overshoots again, and circles the target. You want it to come in fast when it's far, ease off when it's close, and end at the right heading without spinning the long way around.
Feedback on the error, in the robot's frame
Start with how far the target is from the robot, measured along the field's axes. Say the robot is at facing (toward ), and the target is facing :
Here , in, and . The heading error is wrapped, as in Angle Wrapping.
The drivetrain doesn't take field directions, though. It takes forward and sideways in the robot's frame. The robot is facing , so that 30 in along the field's axis is straight ahead of it: 30 in forward, 0 sideways. In general, rotate the error by , the same rotation as field-centric driving:
Check it with the numbers: and , so
and .
Thirty inches forward, as expected.
Now there's a forward distance and a sideways distance, which the drivetrain can act on directly. Run a controller on each. Proportional control is often enough for the two translation directions, with heading on its own gain:
Translation uses one gain for both directions so forward and sideways respond the same way. Heading gets its own gain, because its error is in radians and the drivetrain turns and translates with different strength. Those three numbers are exactly the command the mecanum mixer takes, and its scaling step keeps the robot heading the right way when the gains ask for more than full power.
If proportional alone overshoots, add a D term on each axis. As in the PID lesson, take the rate of change of the measurement (here, the robot's velocity along that axis) so a new target doesn't cause a kick:
kStatic: getting over the last bit of friction
Near the target the error is tiny, so drops below what it takes to overcome friction, and the robot stops a centimeter short. You could add an integral term, but there's a simpler fix: a small, constant push in the direction of the error, only when the robot is already close:
Only applying it near the target keeps it from acting as a constant bias the rest of the time. Real FTC
code does this: SimplicityFTC's PDFSController adds sign(error) * kStatic once |error| is under a
threshold, and FTCclueless's drivetrain adds a flat 0.05 * sign(error) near the goal. It's the
from feedforward, used for position. In code it's called
kStatic, from Common Implementation.
PID-to-point is three one-dimensional controllers, forward, sideways, and heading, sharing one mixer. Tune heading first, so the robot frame is right, then translation.
Braking on time: predictive deceleration
Proportional control still has a problem. is large when far and small when close, which sounds right, but the robot can only slow down so fast. Far out, is well above the speed the robot could stop from in time, so it charges in, brakes too late, and sails past. Lowering fixes the overshoot and makes the whole approach sluggish. No single gain is fast and clean.
Ask a different question: given how far there is to go, how fast is the robot allowed to be moving? Say it can slow down at 60 in/s². From 30 in/s, braking takes s, at an average of 15 in/s, so it covers 7.5 in. So at 7.5 in from the target, the robot shouldn't be going faster than 30 in/s. In general, stopping from speed over distance at deceleration gives:
Check: in/s. Command the smallest of three speeds: the braking cap, the robot's top speed, and the proportional term for a gentle final approach:
Far from the target, the braking cap is bigger than , so the robot cruises. Closer in, the cap drops below and brings the speed down to zero at the target. Following the cap means slowing down at a steady rate the whole way in.
This is the slowing-down half of a motion profile. A full profile plans position, speed, and acceleration for the whole move in advance. The cap works it out each loop from the distance left, which is simpler and enough for point-to-point moves.
assumes the robot always brakes at the same rate. Measure a real drivetrain and its stopping distance fits better, because of drag and the way motor braking changes with speed. The constant-rate version is the right one to learn with. The Pedro Pathing lesson shows how Pedro fits the real curve.
Another way: predict where the robot would coast to. Flip the same formula around to solve for distance: a robot moving at needs to stop. From 30 in/s at 60 in/s², that's 7.5 in. Add that distance, in the direction the robot is moving, to its current position. That's where it would stop if you cut the power now. Then run the ordinary controller as if the robot were already there:
The fraction is just "the stopping distance, pointed the way the robot is moving." Filter the velocity first, because it's noisy and gets squared.
While the robot races in, the predicted stopping point is ahead of it. If it's going too fast, the
predicted point passes the target, the error flips sign, and the controller brakes on its own, with no
separate speed cap. Cyliis's Odo class computes predictedX/Y this way from filtered velocity, and
FTCclueless feeds an expected pose into what they call a "predictive PID."
Chaining points: follow a list without stopping
A real autonomous is a list of poses. Driving to each one and waiting to settle works, but the robot stops at every point along the way, which is slow and jerky. Instead, keep an index into the list, drive toward the current point, and move on to the next one as soon as you're within some radius of it, without settling. Only the last point uses the full "arrived and stopped" check.
The advance radius is looser than the final tolerance, so the robot switches targets while still
moving and only brakes for the last point. SimplicityFTC's PidToPointFollower (pointAdvanceRadius)
and FTCclueless's drivetrain (pathRadius) both work this way. It's also how a
spline, once turned into a list of points, can be followed with PID-to-point.
What's still missing
kStatic and early braking fix how the robot arrives. What's left is that it always aims straight at one point. To follow a smooth curve through many waypoints, later lessons cover splines and pure pursuit.
A go-to-pose loop
One pose sample becomes a wrapped field error, robot-frame commands, a mecanum drive call, and a
MoveStatus. Lengths are in inches, speeds in inches per second, heading in radians, and the mixer takes
normalized power.
void startMove(Pose2d target) {
activeTarget = target;
timer.reset(); // never reset this inside updateMove()
}
MoveStatus updateMove() {
if (activeTarget == null) return null;
PoseSample sample = poseSource.getSample();
MoveStatus status = moveStatus(sample, activeTarget, timer.seconds());
if (status != RUNNING) {
drive(0, 0, 0); // REACHED and TIMED_OUT both stop
return status;
}
commandToward(activeTarget, sample.pose());
return RUNNING;
}
void commandToward(Pose2d target, Pose2d poseForError) {
double ex = target.x() - poseForError.x(); // field frame
double ey = target.y() - poseForError.y();
double eh = wrap(target.heading() - poseForError.heading());
double c = Math.cos(poseForError.heading());
double s = Math.sin(poseForError.heading());
double exBot = ex * c + ey * s; // into the robot frame
double eyBot = -ex * s + ey * c;
double vx = kPxy * exBot + kStatic(exBot);
double vy = kPxy * eyBot + kStatic(eyBot);
double w = kPheading * eh;
drive(vx, vy, w); // the mixer desaturates
}
commandToward takes the target and the pose to measure the error from as separate arguments. Here
the second one is just the robot's pose. The predictive version further down passes the predicted
stopping point instead, and nothing else changes.
The robot faces and the target is straight ahead of it, which on the field is the
direction. What should exBot and eyBot come out to? What would happen if you rotated by
instead?Show solution
exBot should be the whole distance and eyBot zero, since straight ahead is for the robot. With
, and , so exBot = ey and eyBot = -ex. The target is purely in
, so that's the full distance in exBot and nothing in eyBot. Rotating by
would send the robot sideways, at right angles to the target.
The "done" check matters as much as the controller. Check position, heading, and that the robot is
actually slow, or a move will report done while the robot coasts through the point. The timeout keeps a
stuck move, jammed on a wall or confused by a bad pose, from hanging the routine. That's the shared
MoveStatus check. Both outcomes stop the robot, but only REACHED is a
success.
To follow a list of poses without stopping at each one:
void startPath(List<Pose2d> newPoints) {
points = new ArrayList<>(newPoints);
index = 0;
timer.reset();
}
MoveStatus follow() {
if (points.isEmpty()) {
drive(0, 0, 0);
return REACHED; // nothing to do is not a failure
}
PoseSample sample = poseSource.getSample();
Pose2d robot = sample.pose();
boolean last = index == points.size() - 1;
if (!last && robot.vec().minus(points.get(index).vec()).norm()
< ADVANCE_RADIUS) {
index++;
timer.reset(); // each leg gets its own deadline
last = index == points.size() - 1;
}
MoveStatus status = moveTowardTarget(sample, points.get(index)); // as in updateMove()
if (status == TIMED_OUT) return TIMED_OUT;
if (last) return status; // only the last leg may say REACHED
return RUNNING;
}
moveTowardTarget is the body of updateMove() above with the target passed in: check moveStatus,
stop if it's done, otherwise call commandToward.
What would the robot do if it had to settle inside Settling also means being slow, because of the velocity check in POS_TOL at every point along the way?Show solution
moveStatus, so the robot would slow
to a stop at every point, wait, and speed up again. The path turns into a series of lurches, takes
several times as long, and every stop and start pulls a current spike. ADVANCE_RADIUS means "close
enough to start aiming at the next one," so corners round off and the robot keeps moving.
To use the braking cap, limit the size of the command before the mixer:
static final double MAX_SPEED = 40; // inches/second
static final double MAX_DECEL = 60; // inches/second^2, positive magnitude
double brakingCap(double distance) {
double vStop = Math.sqrt(2 * MAX_DECEL * distance);
double vProportional = kPxy * distance * MAX_SPEED;
return Math.min(Math.min(vStop, MAX_SPEED), vProportional) / MAX_SPEED;
}
void driveCapped(double exBot, double eyBot, double w) {
double dist = Math.hypot(exBot, eyBot);
double cap = brakingCap(dist);
double dir = Math.atan2(eyBot, exBot);
drive(cap * Math.cos(dir), cap * Math.sin(dir), w);
}
A robot at speed braking at MAX_DECEL needs inches to stop. Turn that around into "the
fastest I can be going when I'm this far away."
Then: why does the code work out the direction once and cap the speed, instead of capping Set the stopping distance equal to the distance left: , so . points 53.1° off the robot's nose. Capped separately to , it points at 45°, so the
robot drives somewhere it wasn't asked to go. Capping the size and rebuilding from exBot and
eyBot separately? Try exBot = 30, eyBot = 40, and cap each at 20.Show solution
dir keeps the
direction, for the same reason the mecanum mixer scales all four wheels together.
Predictive stopping
The predictive version changes the pose the error is measured from, never the target:
// Where this sample says the robot will coast to a stop.
Pose2d predictedPose(PoseSample sample) {
Pose2d p = sample.pose();
Vector2d v = sample.fieldVelocity(); // filter this; raw velocity is noisy
double speed = v.norm();
if (speed < EPS) return p; // standing still: no glide
double glide = speed * speed / (2 * MAX_DECEL); // the braking distance
return new Pose2d(
p.x() + (v.x() / speed) * glide,
p.y() + (v.y() / speed) * glide,
p.heading()); // only translation is predicted
}
MoveStatus updatePredictiveMove() {
if (activeTarget == null) return null;
PoseSample sample = poseSource.getSample();
MoveStatus status = moveStatus(sample, activeTarget, timer.seconds());
if (status != RUNNING) {
drive(0, 0, 0);
return status;
}
commandToward(activeTarget, predictedPose(sample));
return RUNNING;
}
In that last call the target is the same, and only the pose the error comes from is predicted. Say the target is at , the robot is at , and its predicted stopping point is . The error is instead of , so the robot eases off early instead of charging in and overshooting.
Why is A doubled velocity reading makes v divided by speed, and what happens if you forget? And what does this controller do when
fieldVelocity() is noisy and briefly reads double the true value?Show solution
v / speed is a length-1 vector pointing the way the robot is moving, so multiplying by glide moves
exactly glide inches in that direction. Skip the division and you move speed * glide inches, which
grows with the cube of the speed and puts the predicted point across the field.glide four times bigger, since it depends on . The predicted
point jumps past the target, the error flips sign, and the robot brakes hard or even reverses for a
loop. That's why the velocity needs filtering: the prediction amplifies its noise, and velocity is the
noisiest thing the pose source gives you.
An integral can also fix stopping short, but if it keeps adding up while the robot is maxed out or stuck against a wall, it grows huge and the robot lurches when it comes free. Cap it and only let it run near the target, as in Anti-Windup.
A wrong heading rotates the whole translation command, so a heading bug looks like a translation bug. Get holding heading cleanly before tuning translation.
MAX_DECEL is limited by traction, battery voltage, and weight shifting, not by the motors. Measure it
on the actual field surface and leave some margin so a slippery tile doesn't turn your planned stop
into a slide. And filter the velocity before computing the glide distance, since it gets squared.
(Cyliis filters their odometry velocity first.)
The production techniques on this page are adapted, with attribution, from these open-source FTC team repositories:
- kStatic static feedforward (a constant push toward the target applied only once inside a small
error band) — SimplicityFTC-Quickstart
(
PDFSController) and FTCclueless/Centerstage (subsystems/drive/Drivetrain.java). - Point-advance sequencing (advancing to the next waypoint within an advance radius so the robot
never stops mid-path) — SimplicityFTC-Quickstart
(
PidToPointFollower,pointAdvanceRadius) and FTCclueless/Centerstage (Drivetrain.java,pathRadius). - Predictive deceleration — glide-distance predicted stopping pose (compute
from low-pass-filtered velocity and run PID against
it) — Cyliis_Into_The_Deep_OfficialCode
(
Wrappers/Odo.java,predictedX/Y) and FTCclueless/Centerstage (Drivetrain.java, the "predictive PID" on theexpectedpose).
The code here is an independent reimplementation of these ideas, not a copy of any one repository.