I'm trying to implement PID control for a two wheeled car. The car has two DC motors with encoders and an H-bridge. The device needs to move along a linear path with acc/dec ramps on both ends. I can determine the position of the wheels by calculating the area under the velocity/time curve at each sampling interval.
My question concerns how to use the PID error to keep the car on track and on schedule.
My guess is that I should determine the error by subtracting the current encoder position from the previous target position (where I should be now). Then, for each wheel, by adding Kp*error + Ki*errSum + Kd*dErr to the new setpoint (next target position), I can calculate the speed of each wheel necessary to get to this new position in the time interval (speed = pulses x delta_t). From there I get the new pwm value. Etc.
Is my thinking correct?
Thanks