Roaming with ping sensor
sokin
Posts: 32
Hello, I am working on roaming with ultrasound and have followed the instructions until the try this section. All I have to do is add a while(1) with an ( open brace and close ) which I have done. When I try to load the program I get these errors. Does anyone know why?
ping.c:24:5: error: expected expression before 'while'
ping.c:40:3: error: expected ';' before 'drive_ramp'
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
}
ping.c:24:5: error: expected expression before 'while'
ping.c:40:3: error: expected ';' before 'drive_ramp'
/* Detect and Turn from Obstacle.c Detect obstacles in the ActivityBot's path, and turn a random direction to avoid them. */ #include "simpletools.h" // Include simpletools header #include "abdrive.h" // Include abdrive header #include "ping.h" // Include ping header int turn; // Navigation variable int main() // main function { drive_setRampStep(10); // 10 ticks/sec / 20 ms while(1) (
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
}
Comments
Tom