Code:
function dx(aPid: string; aFrame1,aFrame2: integer): double;
var
rise,run: double;
t1,t2: double;
begin
// Ensure frames are in range and are ordered low->high
CoerceAndOrder(aFrame1,aFrame2,0,FrameCount-1);
// Get the change in PID value between the two frames.
rise := pid(aPid,aFrame2)-pid(aPid,aFrame1);
// Get the timestamp in ms for each frame
t2 := time(aFrame2); // ms
t1 := time(aFrame1); // ms
// Calculate the elapsed ms
run := t2-t1;
// Compute the rate of change of the PID value per second
if ( not IsZero(run) ) then
Result := (rise*1000)/run // *1000 to convert from "change per ms" to "change per second"
else
Result := 0;
end;