Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int U,P,I,D;
- #define KI 1
- #define KD 1
- #define KP 1
- task p()
- {while(true){
- P=(45-Sensor(IN_3));
- } }
- task i()
- {while(true){
- Wait(10);
- if(abs(45-Sensor(IN_3))<2)
- {I=((45-Sensor(IN_3))+I);}
- else
- {I=0;}
- } }
- task d()
- {while(true){
- D=((45-Sensor(IN_3))-D);
- Wait(8);
- } }
- task calc()
- {while(true){
- if (KP*P+KI*I+KD*D<30)
- U=KP*P+KI*I+KD*D;
- else
- U=30;
- } }
- task turn()
- { while(true){
- OnFwd(OUT_A, 40 +U);
- OnFwd(OUT_C, 40 -U);
- } }
- task main()
- {SetSensorLight(IN_3);
- Precedes(p,i,d,calc,turn);
- I=0;
- D=0;}
Add Comment
Please, Sign In to add comment