Pid tuning issue -- drift in acro

I’ve been trying to tune my copter’s PIDs and I’m seeing an issue that doesn’t make sense to me. To test my PID values, I’ve been doing short flights in acro mode where I command a quick roll or pitch maneuver and then let it sit at the new desired angle with no input for a couple seconds to see how the system responds (as close to a step response as I can get).

I’ve noticed that it will follow my commands quickly and accurately but then it will drift back in the opposite direction slowly. I have acro trainer disabled… in fact it sometimes drifts back past level and keeps going so I’m sure it’s not an acro trainer issue. I thought maybe it was an integral wind-up issue so i turned my “I” term way down but i still have the same issue.

Here is section of a log from one such flight. “P”, “I”, and “D” terms are plotted with a “/100” factor so that their magnitudes will be similar to the “desired roll” and “actual roll” values.

As you can see, I command a step in desired roll (red line) and actual roll (green) follows it pretty well but with some overshoot. The weird thing is that after the overshoot, the actual roll moves back towards and past the desired roll in a long slow slope (a few seconds). Why does it pass the desired instead of simply approaching it?

This offset stays in the system too. Future steps have a larger over shoot because they start with an offset.

Another thing I noticed is that the PID values are not calculated directly from the reported attitude and desired attitude. Look at this zoomed in section from this log. The P value (blue) dips below 0 but the actual roll at this time does not go above the desired (both circled in grey). The P value should always have the opposite sign of the error (actual-desired) but in this case, the P value switches from positive to negative and back to positive all while the error is negative. This suggests that the P (and I and D) value must not be calculated from the actual and desired data that I’m looking at in this log. What are the gains calculated from?

Here’s the full log file (google drive dl link):

Thanks for reading all the way to here and for sharing any ideas you might have,

I’m having the same issue. Could anyone provide some help on this?