EasyManua.ls Logo

SunFounder GalaxyRVR - Page 68

Default Icon
120 pages
Print Icon
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
SunFounder GalaxyRVR Kit for Arduino, Release 1.0
In the loop() function, we call readSensorData() and stores its returned value in the distance variable.
float distance = readSensorData();
Depending on this distance, the Rover will move forward, move backward, or stop.
// Control rover based on distance reading
if (distance > 50) { // If it's safe to move forward
moveForward(200);
} else if (distance < 15) { // If there's an obstacle close
moveBackward(200);
delay(500); // Wait for a while before attempting to turn
backLeft(150);
delay(1000);
} else { // For distances in between, proceed with caution
moveForward(150);
}
If the path is clear (the obstacle is more than 50 cm away), our Rover boldly moves forward.
And if an obstacle is getting close (less than 50 cm but more than 15 cm away), our Rover will move forward
at a lower speed.
If an obstacle is too close for comfort (less than 15 cm away), the Mars rover will move backward and then
turn to the left.
64 Chapter 3. Course Mode

Related product manuals