speeduino
speeduino copied to clipboard
integerPID improvements and negative values on VVT
Change the PID implementation, to allow negative values on the input, change the anti-windup machanism, remove the unused and undocumented pOnE condition. This will create a better integral action, for better control, the former implementation did had windup problems.
Allow negative values for vvtCLMinAng and vvtCLMaxAng, switch to signed variables and whole digit precision in tunerstudio
Looked at this. All this PID thing seems to be kind of raw. Maybe originally the old library. The current standard Arduino library is using foats and so is quite solid but with really bad impact to the performance. There is also unofficial integer version that I have found:https://github.com/mike-matera/FastPID but this is lacking the imprevements, for example "Proportional on Measurement" that seems quite big improvement (http://brettbeauregard.com/blog/2017/06/proportional-on-measurement-the-code/). So the good solution is write and adjust our own as now.
What catches my eye here at first glimpse is: applying bit shifts to signed variables
FeedForwardTerm <<= PID_SHIFTS;
Also for example output >> PID_SHIFTS;
Bit shift applied to the signed variable without it being clearly limited to positive values only is just looking for trouble. As the library lets you have impression that negative values are also enabled, while they really are not catered for. Although it is possible to write integer PID that caters for negative values too.
The shifts are because the fixed point math, shifting a negative value is possible and the compiler take care of it as only the right shifting need attention (arithmetic/logical shift). This fear led to the current code limitation for negative numbers on the first place.
As this PR goes it didn't improve anything, it does remove some features introduced before. You don't need negative target if you apply an offset to the values.