You are on page 1of 1

#define dt 3 float Kp = 25; float Ki = 1; float Kd = 10; int PrevError; long Integral; long Derivative; int Mid; int

Error; int PWR; task main() { SetSensorLight(IN_3); Off(OUT_A); repeat(3) { PlayToneEx(660,200,4,false); Wait(800); } Mid=SENSOR_3; PlayToneEx(780,200,4,false); while(abs(PWR)<1000) { Error=SENSOR_3-Mid; Integral += Error; Derivative=Error-PrevError; PrevError=Error; PWR=(Kp*Error)+(Ki*Integral)+(Kd*Derivative); OnFwd(OUT_BC,PWR); Wait(dt); } Wait(50); Float(OUT_ABC); }

You might also like