int main() // main function { drive_setRampStep(10); // 10 ticks/sec / 20 ms drive_ramp(128, 128); // Forward 2 RPS // While disatance greater than or equal // to 20 cm, wait 5 ms & recheck. while(ping_cm(8) >= 20) pause(5); // Wait until object in range drive_ramp(0, 0); // Then stop // Turn in a random direction turn = rand() % 2; // Random val, odd = 1, even = 0 if(turn == 1) // If turn is odd drive_speed(64, -64); // rotate right else // else (if turn is even) drive_speed(-64, 64); // rotate left // Keep turning while object is in view while(ping_cm(8) < 20); // Turn till object leaves view drive_ramp(0, 0); // Stop & let program end }
int main() // Main function { low(26); low(27); int irLeft, irRight; // Add startup code here. int leftDist, rightDist; while(1) { drive_setRampStep(10); drive_ramp(64, 64); while(1) { irLeft = checkLeft(); irRight = checkRight(); irRight = ping_cm(8); print ("left = %d, right = %d \n", irLeft, irRight); if(irLeft == 1) { high(26); } else { low(26); } if(ping_cm(8)<=10) { high(27); } else { low(27); } if(irLeft == 1) { drive_ramp(0, 0); turnLeftH(); print (" Left empty hall detected"); break; } if (ping_cm(8)<=9) { drive_ramp(0, 0); turnBack(); print (" End of the line"); break; } } } }
int main() // main function { pause(1000); //low(27); while(1) { // Realiza el ping frontal y del lado para chequear que haya espacio disponible sFront = ping_cm(8); sRight = ping_cm(10); while(sFront >= 10 && sRight < 19) { sFront = ping_cm(8); sRight = ping_cm(10); drive_ramp(50,50); pause(5); // Wait until object in range } /*drive_ramp(20,20); cont = 0; while(cont < 20) { cont++; pause(5); }*/ // Si el sensor lateral tiene suficiente espacio gira a la derecha if(sRight < 19) { drive_speed(-30,30); cont = 0; while(cont < 97) { cont++; pause(5); } }else{ cont = 0; while(cont < 160) { drive_ramp(30,30); cont++; pause(5); } // Si el frente y la derecha estan cubiertos gira a la izquierda drive_speed(30,-30); cont = 0; while(cont < 148) { cont++; pause(5); } drive_speed(50,50); cont = 0; while(cont < 180) { cont++; pause(5); } } } }