P Control Basics
The first useful feedback controller.
The first useful feedback controller.
In this lesson, you will:
Proportional control converts current error into output. It is the simplest way to make a mechanism move toward a target using feedback.
The robot is repeatedly asking how far away it is and pushing in proportion to that distance. Large error produces larger output; small error produces smaller output.
You already know that proportional control multiplies error by kP. Let's follow one update from target to output and watch the correction shrink as the measurement approaches the target. The target is 1,000 ticks and the measurement is 600 ticks. Target minus measurement gives us an error of 400 ticks. For this calculation, we'll use kP as 0.0005, so the raw output is 0.2. We generally like to keep the units and sign visible. If the target is above the measurement, this convention produces a positive correction. Keep in mind that this gain is only sample data. It is not something to put on your actual robot. This software fixture performs that exact sequence once per loop. It reads the encoder, calculates target minus measurement, multiplies by kP, and keeps that between negative 0.25 and positive 0.25. Then it publishes that and writes every stage to telemetry. At 600 ticks, the error is 400 and the output is 0.2. At 900 ticks, the error is 100 and the output is 0.05. At 990 ticks, the error is 10 and the output is 0.005. That shrinking correction is the basic behavior of P control. It also explains why friction or gravity can leave a small steady error. The correction may become too small to move or actually hold the mechanism. If we accidentally calculate measurement minus target, the same starting point produces negative 400 and negative 0.2. The controller pushes away from the target. Do not try to tune a sign mistake with a smaller gain. Stop and look at the target, measurement, coordinate convention, encoder direction, motor direction, and the actual error equation. Once you have looked at those, use a low-power environment from the current robot and choose a small gain and output limit just to test. Direction errors can be one of the most dangerous things to test, especially with bigger mechanisms, so make sure you are taking all the proper precautions.
Read position, calculate error, multiply by kP, clamp, command motor, and print all values. Tune slowly with small target changes.
PController.javaJava
double error = targetTicks - lift.getCurrentPosition(); double output = kP * error; output = Math.max(-1.0, Math.min(1.0, output)); lift.setPower(output);
If the mechanism runs away, check encoder sign. If it oscillates, kP may be too high or the mechanism may need damping. If it never moves, output may be too small to overcome friction.
Tune a proportional-only lift on blocks and graph target, position, error, and output.
Check your understanding before moving on.
0 of 2 answered