Summary
Since last time I’ve worked on a basic PID controller for class and run into some more problems in research, but I’ll focus PID controller because it’s more interesting.
PID Controller
For the mobile robotics class, we were on the topic of controls. We talked about a few fancy control algorithms in class (model predictive controllers, cascade controllers) but the TA Arun said that oftentimes in industry, PID controllers are the first thing they throw at a problem because they just work.
They are formulated like so:

where u is the output for input t. e(t) is simply the error from set point which is the point you want to reach: $e(t) = setpoint - t$.
There are three ‘parts’ of this system to consider. Generally they can be seen as control to account for the past, present, and future error.
- The Proportional Term $K_p*e(t)$
- This term is made to account for the error RIGHT NOW. The control is tuned directly proportional to the current error. The amount the control is scaled relative to the error is given by the gain term $K_p$. The issue is that as our error shrinks as we get closer to our set point, so does the rate of our corrective control. As we get very close it can get very small to the point that we never hit our set point.
- The Integral Term $K_i\int_{0}^Te(t)dt$*
- This term is made to account for PAST ERROR. The control is tuned proportional to the sum of previous errors. This solves the problem laid out above in the proportional term. As we get close to our set point the proportional term shrinks, but if we have experienced error for a long time, the integral term will be large, which will make keep our corrective control higher so we reach the set point. The simplest way to do this is simply sum all the past errors. More advanced PID controllers make use of terms that exponentially shrink older error so that new error is more weighted than old error. The amount of affect the integral term has on control is scaled by the gain term $K_i$
<aside>
💡 Note that for a lot of applications a PI controller is actually enough!
</aside>
- The Derivative Term $K_d*de(t)/dt$
- This term attempts to account for future error. It is often also referred to as the damping factor. Consider this scenario: we have experienced error for a while, so our integral term is large, but we are actually close to the set point. Because our integral term is large, we have a large amount of corrective control, and we “charge” towards our set point. The issue now is that we may overshoot by a large amount. The integral term tries to take this into account and damp our approach. If the error is decreasing quickly (meaning that the derivative $de(t)/dt$ is large and negative, then this will actually decrease the amount of corrective control and slow our approach a little, preventing an overshoot. This might seem a little counterintuitive because why would you have a term that seemingly tunes the control in the opposite direction of our set point, but it makes sense if you consider a car trying to follow a straight line. If we are far from our goal, then of course we want to decrease error quickly, but as we get close, the proportional term will let up, the integral term will still be large, so we want something to “curve” our approach a little. The integral will also help if we are every quickly increasing our error, adding corrective control proportional to the change in error error over time. The derivative term is scaled by the gain term $K_d$
I learned from tuning my PID controller that they’re pretty finicky, and it was pretty hard for me to predict the behavior of the system after each change. In class we learned that there are a few tricks to tune PID controllers, but generally it’s black magic and often times it is brute forced (but you need a simulation model for this because there is significant cost associated with brute forcing the real systems) or there are specialists who get paid a lot of money because they’ve learned to understand them to some extent.
Of course, you could also have a reverse PID controller if all the gains are negative.
Here are some pics of a the results of PID controllers I tuned for a basic robot with 4 fixed wheels, with it’s only method of turning is changing one side’s wheel speeds.
I tuned two separate PID controllers, one for the forward velocity of the robot, and one for the angular velocity of the robot. Calculating errors for the heading was a little geometrically involved, but nothing too bad.
The results were pretty good, I measured the results using X and Y RSME from the target path

