View Single Post
Old February 4th, 2022, 01:14 PM   #84
Taylor Turner
Member
United States

Taylor Turner is offline
 
Join Date: Sep 2020
Location: Midwest
Posts: 69
Checking the rate of stuffs

Code:
//Sets sample rate
tonr(tSampleRate);
tSampleRate.PRE := 100;

if not tSampleRate.DN then
    tSampleRate.Reset := 0;
    tSampleRate.TimerEnable := 1;
else
    tSampleRate.Reset := 1;
    tSampleRate.TimerEnable := 0;
    rAcceleration[1] := rAcceleration[0];
    rVelocityEMA[1] := rVelocityEMA[0];
    rVelocity[1] := rVelocity[0];
    rPosition[2] := rPosition[1];
    rPosition[1] := rPosition[0];
    rPosition[0] := LocalIOHere;
    rVelocity[0] := (rPosition[1]-rPosition[0])*(60*1000)/tSampleRate.PRE;
    rAcceleration[0] := (rVelocity[1]-rVelocity[0])*(60*1000)/tSampleRate.PRE;
    rJerk := (rAcceleration[1]-rAcceleration[0])*(60*1000)/tSampleRate.PRE;
end_if;


//Filter
rAlpha := 1;

rVelocityEMA[0] := trunc((rAlpha*rVelocity[0]+(1-rAlpha)*rVelocityEMA[1])*100)/100;
  Reply With Quote