Controlling an Electronic Throttle Body using a PID controller

arbartz:
Two are needed for automotive safety reasons, so I take the difference of the two for the position.

Using the difference doesn't seem strictly correct, to me. I assume you have them wired in reverse to that one goes from zero to max and the other goes from max to zero. If you just take the difference, the result will go from +max to -max. What you want to do is invert the inverted signal (inverted = max - signal) so that you have two values going from zero to max; now you can validate them against each other and (if valid) take the average.

The validation is why you have two sensors, so you can detect hardware failures. Just blindly taking the average (or difference) doesn't meet this safety objective. Having a separate manual cut-off doesn't remove the need to validate the sensors, IMO.

The idea of PID is that it encompasses the whole control algorithm and once correctly tuned will provide optimal closed loop control over the whole range of positions and errors. You challenge is to find the optimal set of tuning parameters - once chosen, they would be hard-coded and unchanged (unless the physical characteristics of the system changed).

There is a procedure you can go through to get an approximate value for these parameters by observing the system behaviour - Google PID tuning to learn about that. There is also a PID autotune library for the Arduino which you would use in a test sketch to optimise the PID tuning parameters on the live system.