top of page

PID Tracer [October 2019]

THE PID AlGORITHM

closedloopfeedbackmechanism.PNG

Closed Loop Control System

The PID control mechanism is an extremely handy example of the a closed loop control system. The output consistently has an error signal component to it, where the error signal is the difference between the desired output and current output.

 

The aim is to drive the system towards the point at which Error = 0, where we obtain our desired signal.

pid control mechanism.png
pid formula.png

PID Control Equation

  • Output: The control signal or action to be applied to the robot's motors to adjust its behavior (steering, direction, speed).

  • Kp: The proportional gain or coefficient for the proportional term.

  • Ki: The integral gain or coefficient for the integral term.

  • Kd: The derivative gain or coefficient for the derivative term.

  • P: The proportional term, representing the current error.

  • I: The integral term, representing the cumulative sum of past errors.

  • D: The derivative term, representing the rate of change of the error.

Proportional (P) Term:

  • The proportional term is based solely on the current error, which is the difference between the desired setpoint (e.g., the center of the line) and the actual measured value (e.g., the position of the robot on the line, gathered via the reflected light values of the sensor).

  • Mathematically, P = Setpoint - Actual Value.

  • The proportional term amplifies the error by a factor of Kp, which determines the sensitivity of the control action to the error.

  • The proportional term's function is to provide an immediate response to the current error. A larger error results in a stronger corrective action, making the robot steer more aggressively back toward the line.

steering.png

Steering Value = Kp * P

Steering value is dependent on both the Kp constant, and directly proportional to the proportional error. 

The greater the error (the further away the robot is from the line), the higher the steering value (the faster the robot will turn to compensate).

For tuning, a small Kp will meant the robot will not be able to turn fast enough, while a larger Kp value will overcompensate for the error and cause the robot to oscillate.

Integral (I) Term:

  • The integral term considers the cumulative sum of past errors over time to address steady-state errors that the proportional term might not fully correct.

  • Mathematically, I = ∫(Setpoint - Actual Value) dt, where the integral is calculated over time.

  • The integral term is multiplied by the coefficient Ki to control its influence on the control signal.

  • The integral term's role is to eliminate small, persistent errors that could accumulate over time and cause the robot to deviate from the line. It helps to correct biases and inaccuracies in the system.
     

Derivative (D) Term:

  • The derivative term considers the rate of change of the error, helping the control system anticipate how the error might change in the near future.

  • Mathematically, D = d/dt (Setpoint - Actual Value), where d/dt represents the derivative with respect to time.

  • The derivative term is multiplied by the coefficient Kd to control its influence on the control signal.

  • The derivative term acts as a predictive element, dampening the response of the control system to sudden changes in error. It helps prevent overshooting and oscillations.

we can find out how fast the error is changing (the derivative of the error).

If the error is decreasing too fast, then the steering is slow down so the robot does not overshoot.

A higher Kd value will make the turn smooth but slow,

while a lower Kd value will make the turn extremely jerky.

rateofchangeofsteering.png

In summary, the proportional term provides an immediate response to the current error, the integral term addresses accumulated errors over time, and the derivative term anticipates and dampens rapid changes in the error.

 

The combination of these three terms in the PID control equation allows the robot to make precise and stable adjustments to its movement, enabling it to accurately follow a line on the ground. The coefficients Kp, Ki, and Kd are tuned to achieve the desired balance between responsiveness, stability, and accuracy for the specific application. 

thresholdval.png

A Robot that is programmed to follow the black line using 3 Light sensors. The middle sensor feeds the microcontroller with changing light values, which then allows the microcontroller to control the velocity of its motors using a PID control algorithm. The left and right sensors limits the curvature of the robot's turn, to ensure it does not run out of the track. I used a 3:1 Geared Transmission to increase its velocity too.

This robot served as an avenue to test my understanding of the PID algorithm, in combination with interrupt-based programming (by the outer light diodes). One can observe that the run increasingly gets smoother, where towards the 2nd and 3rd lap the robot was capable of sprinting down the straight line. There is still a significant amount of oscillation on the turns, an I'm in an attempt to further improve the PID algorithm to achieve smoother runs.

However these are pretty much bottlenecked by the hardrware of the robot here. 

A good way to improve this would be to improve the mechanical properties of this robot. Lower CG, smaller motors, lighter weight overall to decrease inertia when turning, will help reduce swing as well.

bottom of page