The GitHub - br3ttb/Arduino-PID-Library library does do the derivative-on-input here:
and Brett discusses the need for solving "derivative kick" here: Improving the Beginner’s PID – Derivative Kick | Project Blog
Brett's use of the minimum sample time instead of the actual time dilutes the integral effect and amplifies the derivative effect, so using the actual times will do the opposite: amplify the integral and dilute the derivative (as compared to Brett's library)
The issue I have with Brett's library is that it allows the integral to accumulate even when the controller output is saturated by other terms. Your code allows that as well:
I think that integral conditional-integration should trigger if pTerm + iTerm + dTerm
exceeds the output limits, not just when if the iTerm exceeds the limits. See https://info.erdosmiller.com/blog/pid-anti-windup-techniques or Integral (Reset) Windup, Jacketing Logic and the Velocity PI Form – Control Guru for some graphs of the differences.
Or if you are set on your anti-windup scheme, it would be good would be to expose 'integral' as public, or add some getIntegral/setIntegral functions so it is possible to track what that part of the process and enable application of user-space anti-windup techniques as per Expose integral to enable user-space hacking by drf5n · Pull Request #133 · br3ttb/Arduino-PID-Library · GitHub