Suggested Upgrade to PID_V1 Library

I propose updates to the PID_V1 Library. I was having difficulty working with this PID library because it has a Fixed time window for the calculation of the PID Values.

My Problems occured when the actual time is longer due to delays caused by hardware providing the data.

example: MPU6050 a popular gyroscope has a DMP feature that calculates the Yaw Pitch roll for you. when the unit gets enough readings it will trigger a interrupt to tell the MPU to get the data. this occures at @ 10 milliseconds. since the PID loop is always fixed at exactly X milliseconds we may or may not give the PID loop a new reading when it calculates. the Integral-Derivative are time and error based. so trouble arises when A) we resend the same value because the source didn’t change yet or B we calculate a different time than the actual time between readings.

The attached code compensates for delays in code.
the fixed time interval is now changed to the minimum time interval and so the compute function can be triggered any time after that and the exact time differential will be used. so the cycle time could be delayed with no ill affect.

I have a video showing this PID loop in action for both the balancing and the precision turning. The Motor control/MPU board is a custom creation I made using a atmega328P chip and it is loaded and programmed just like an Arduino UNO.

Thank You

PID_v1.cpp (10.4 KB)

PID_v1.h (3.49 KB)