Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma config(Sensor, S1, sSol, sensorLightActive)
- #pragma config(Sensor, S2, sOrta, sensorLightActive)
- #pragma config(Sensor, S3, sSag, sensorLightActive)
- #pragma config(Motor, motorB, mSol, tmotorNXT, PIDControl, encoder)
- #pragma config(Motor, motorC, mSag, tmotorNXT, PIDControl, encoder)
- //*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
- /*
- S1 Sol Sensor
- S2 Orta Sensor
- S3 Sag Sensor
- MB Sol
- MC Sag
- */
- short hizT = 70, hizO = 2, durum[2] = {0 ,0};
- void rIleri(){
- motor[mSag] = hizT;
- motor[mSol] = hizT;
- }
- void rGeri(){
- motor[mSag] = -hizT;
- motor[mSol] = -hizT;
- }
- void rSaga(){
- switch(durum[1]){
- case 1:
- motor[mSol] = (hizT / hizO);
- motor[mSag] = -(hizT / hizO);
- break;
- case 2:
- motor[mSol] = hizT;
- motor[mSag] = -hizT;
- break;
- }
- }
- void rSola(){
- switch(durum[1]){
- case 1:
- motor[mSol] = -(hizT / hizO);
- motor[mSag] = (hizT / hizO);
- break;
- case 2:
- motor[mSol] = -hizT;
- motor[mSag] = hizT;
- break;
- }
- }
- task main(){
- sleep(1500);
- short c[3] = {0, 0, 0};
- short isik[3] = {SensorValue[sSol], SensorValue[sOrta], SensorValue[sSag]};
- short oran = (isik[0] + isik[2]) / 2;
- while(1){
- isik[0] = SensorValue[sSol];
- isik[1] = SensorValue[sOrta];
- isik[2] = SensorValue[sSag];
- for(short i = 0; i < 3; i++){
- if(isik[i] < (oran - 5)){
- c[i] = 1;
- }
- else{
- c[i] = 0;
- }
- }
- //++Ileri++//
- if((c[0] && !c[1] && c[2]) || (!c[0] && c[1] && !c[2])){
- durum[0] = 3;
- durum[1] = 0;
- rIleri();
- }
- //++Saga++//
- else if(!c[0] && !c[1] && c[2]){ //saga dik
- durum[0] = 1;
- durum[1] = 1;
- rSaga();
- }
- else if(!c[0] && c[1] && c[2]){ //saga normal
- durum[0] = 1;
- durum[1] = 2;
- rSaga();
- }
- //++Sola++//
- else if(c[0] && !c[1] && !c[2]){ //sola dik
- durum[0] = 1;
- durum[1] = 1;
- rSola();
- }
- else if(c[0] && c[1] && !c[2]){ //sola normal
- durum[0] = 1;
- durum[1] = 2;
- rSola();
- }
- nxtDisplayTextLine(1, "Izmir Ataturk Lisesi");
- nxtDisplayTextLine(2, "Robotics Team - 2013");
- nxtDisplayTextLine(3, "Oran: %d", oran);
- nxtDisplayTextLine(4, "Sol: %d, %d", c[0], isik[0]);
- nxtDisplayTextLine(5, "Orta: %d, %d", c[1], isik[1]);
- nxtDisplayTextLine(6, "Sag: %d, %d", c[2], isik[2]);
- nxtDisplayTextLine(7, "Durum: %d, %d", durum[0], durum[1]);
- nxtDisplayTextLine(8, "Hiz: &d, %d", hizT, (hizT/hizO));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement