How to calculate the ERROR value in a PID Controller that includes multiple inputs?

Go To Last Post
2 posts / 0 new
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I understand how a general single input PID controller works, but I'm having trouble understanding how to calculate the ERROR in a multi-input PID controller? For the sake of clarify, let's take the example of a PID controller in a line-following robot. For a single light sensor line-following robot, the pseudo code is something like this:

Kp = 10                              
Offset = 45
MaxMotorSpeed = 50
Ki = 0 
Kd = 0
LastError = 0;
Loop forever
   LightValue = read light sensor    
   ERROR = LightValue - Offset  
     integral = integral + ERROR     
     derivative = ERROR - LastError    
    Turn = Kp*error + Ki*integral + Kd*derivative
End loop forever                      

However, how would you set up the ERROR variable for the PID controller of a line-following robot that has, say, 3 light sensors intended to go across the line in a straight configuration?


Any guidance here would be much appreciated. Thanks in advance!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The PID loop remains the same regardless. The task of the PID loop is to compensate for...


    The magnitude of error (P)

    How long the error lasts (I)

    How rapidly the error changes (D)


It is 'tuned' for the task with parameters which account for the power and inertia of the robot.


The task of the error detector is only to report the sign and magnitude of error to the PID loop. It matters not whether there are two or three,  or thousands of sensors in the error detector, its job is still the same... report the sign and magnitude of error.


The two sensor error detector reports error as the excitation level of the left sensor minus the excitation level of the right...

E = L - R


Perhaps, the most sensible way to use three sensors, is to divide the two-sensor computation by the excitation level of the center sensor

E = ( L - R ) / C


Effectively, this suppresses the error whenever the center sensor is excited.