Skip to content

PID Controller

Lucas edited this page Aug 14, 2020 · 8 revisions

PID Controller

What is a PID Controller?

A PID controller, or Proportional Integral Derivative Controller, is a type of control mechanism that uses feedback loops where continual modulated control is desirable. PID has seen widespread use in robotics, industrial control systems, and other applications for precise and optimized control. Though the basic form only has 3 adjustable constants, one each for P, I, and D, their interaction is capable of outstanding results for complicated dynamic systems, and much work has been done to develop tuning methods.

A continually calculated error serves as input to the system. At a basic level, the proportional component takes into consideration the size of the current error, and contributes a proportional response. The integral term considers the accumulated error over time. The derivative error factors in the change in error. Together, an aggregate response is designed to reduce the error, thus bringing the system to its desired setpoint. Not all systems require the use of all 3 terms for acceptable performance. For instance, a PI controller does not consider the derivative of the error.

To learn more, see the Wikipedia page

How sciencebot Uses PID Controllers

PID control is useful for vehicle movement and orientation.

Firstly, an angular controller (whose input is the difference between the vehicle's current heading and its desired heading) can be used to instruct the vehicle to rotate to a desired heading in an efficient manner.

A linear controller can be used to inform the vehicle how fast to move based on an error of distance to the target location.

Such a setup would be considered a position PID system.

Error formulas for the angular and linear controllers. Be careful when applying trigonometry to find the angle differential. Mind the quadrants!

position_pid

When these two controllers are combined, a waypoint seeking control system can be developed to move your vehicle to a desired location. A well tuned system will not only efficiently navigate to the waypoint, but is also robust to differences between theoretical motion and real movement. On each loop, the PID controller gets a chance to adjust its response based on new error feedback.

Experience this waypoint system in action with the ROS turtlesim demo, and play with the control parameters yourself! See README section "turtlesim PID Control".

turtles

Finding an optimal set of parameters for real world operation is much more difficult than in the world of the turtlesim, where the theoretical model is always perfectly simulated.

Firstly, a desired next move, in this case a linear and angular velocity (from a linear controller and an angular controller respectively), must be translated to a set of motor commands to result in real movement. A translation mechanism will depend on the type and configuration of motors on your vehicle. Additionally, any real motors will not be able to service a limitless range of velocity requests due to power and granularity constraints. With the commodity level motors used for this project, only a limited range of velocities are achievable. Further complicating the matter, friction (both static and kinetic) come into play, as some power levels will be insufficient to cause movement from a standstill, but be sufficient to continue movement on an already moving vehicle.

Additionally, the interplay between the angular and linear controller is non-trivial. Even if both controllers were individually well tuned, they are not guaranteed to work well together. As the two controllers essentially "compete for attention" over influencing the next motor command, a desirable balance must be struck between them.

The sciencebot implementation uses a modified combination of an angular and linear controller. When the vehicle is pointed too far in the angular direction, the software choose to prioritize turning only. Once within a certain threshold, a combination of forward linear movement and angular (turning) is employed.

Within each regime of operation, special limits are imposed on the controllers. When the vehicle is pointing in a relatively correct heading, the angular controller is prevented from modifying the linear controller's input by too much. This prevents the vehicle from "swerving" back and forth, as it endlessly attempts to achieve an exact heading, sacrificing effective forward progress.

The linear controller also has an imposed maximum integration term limit. This is necessary within this system, as the vehicle effectively only moves "forward" (whichever direction it is facing). The linear error is simply the Euclidean distance between current location and desired location, which is always positive. If this error term were allowed to continually integrate, the linear controller would at a certain point always request maximum forward speed, even if the vehicle were to be very close to the target location. The strongest possible integration limit is zero, in other words, removing integrated error from consideration. In fact, the vehicle is capable of effectively reaching the target using a P controller for linear response, which modulates only on the consideration of current distance to the target. Sometimes less is more.

Vehicles with wheel encoders often implement velocity PID, which you can learn more about here

Clone this wiki locally