PID Controllers - frc-7603/VespaRobotics2024-25 GitHub Wiki

Overview

PID Controllers, otherwise known as Proportional-Integral-Derivative Controllers are a type of controller that powers a motor based on an "error value". This essentially calculates the amount of power required to reach the desired position, from the current position. We'll go into these in more depth as the page continues onward.

The PID controllers have multiple specific values they operate on. Specifically, these values are the "error" value e(t), "set point" value r(t), "process variable" value y(t), and the "control variable" u(t). These values are all correlated with each other, and we'll go into how that works now.

Values required

Set Point Value

The "set point" value is the current state of the entity in question. Let's use our swerve wheels as an example: The set point value would be where the current swerve wheels are in terms of rotation. In order to run the calculation that the PID controllers run, we need to understand where our current point is. So, if our current point on the wheels is 45 degrees, that is our set point.

Process Variable Value

The "process variable" value is the targeted state of the entity in question. Going back to our swerve wheels example, the process variable value would be the target position for where the wheels should be. For a PID controller to use calculations, it will need this on top of the set point value, which is why we must know where both of these points are. In this example, I will say that our target is around 90 degrees.

Error Value

The "error" value is one of the most important variables in the PID controller, as it designates the difference between the current position of the entity, and the targeted position. If we look at our swerve wheels example, the error value would be the (-45), since 45-90 = (-45). This error value would represent the difference in degrees between the target and the current, which allows for us to use the PID controllers, since they cannot function without an error value.

How it works

Proportional Process

The proportional process of the PID controllers is to control the system via the magnitude the set point value is from the process variable value. This is of course proportional (hence the name) on the error value, which means that the larger the error value, the stronger the response from the proportional process, and vice versa. That means it will slow down it's efforts as it approaches the target.

The main problem with the proportional process is that it work similar to an asymptote; it can never reach the exact target since it automatically slows itself down when the error value nears zero. This makes it impossible to run such a controller just off the Proportional Process. Luckily, the error correction doesn't rely just on the Proportional Process.

Integral Process

The integral process of the PID controllers works alongside the Proportional process, and it's job is to reduce error over time. Instead of making the error correction strength proportional to the error value, the integral process considers the sum of all error values, and the time it has been since the error correction first started. This helps solve the asymptote problem as the error correction strength.

However, the weakness of the integral process is it's ability to overshoot the target value of zero. Occasionally, the equation will produce a value that is more than needed, and in turn over increases the value to the point where it is less than zero, not ideal. This is why these 2 do not just work, and instead we need the Derivative.

Derivative Process

The main goal of the derivative process is to ensure that the integral process doesn't overshoot. It instead has a "dampening" effect on the strength of the integral process, by attempting to reduce the rate of error to zero. It does this by completely ignoring the magnitude of the error it must correct, and instead purely focuses on the rate of error.

Working with code

WPILIB does have functions that work with PID controllers, which we will be harnessing in our code. However, in order to do such things, we need to understand which functions do what, when they are useful, and why we use them.

Getting started

(WIP)

Sources

Wikipedia Article