Question: Using EyeSim app, give the code to drive the robot in a lawnmower pattern. Use the code below to help. The below code is to;drive

Using EyeSim app, give the code to drive the robot in a lawnmower pattern. Use the code below to help.
The below code is to;drive the robot straight and collision-free close to the
wall in front, then turn to the right, so it is parallel to the wall (at the robots left-hand side) in about 15cm distance.
#include "eyebot.h"
int main(){
//drive to wall
VWSetSpeed(50,0);
while (true){
if (PSDGet (1)<150){
VWSetSpeed(0,0);
break;
}
}
int PSDOld =1000000;
VWSetSpeed(0,10);
//parallel to wall
while (true){
int PSDNew = PSDGet (2);
if (PSDOld < PSDNew){
VWSetSpeed (0,0);
break;
}
PSDOld = PSDNew;
}
}
The below code is to: drive one complete (and collision-free) loop around the driving area, always keeping a similar distance to the wall on the left-hand-side of the robot.
#include "eyebot.h"
void driveToWall (){
VWSetSpeed(50,0);
while (true){
if (PSDGet (1)<50){
VWSetSpeed(0,0);
break;
}
}
return;
}
void driveParallelToWall (){
VWSetSpeed(50,0);
while (true){
if (PSDGet (1)<50){
VWSetSpeed(0,0);
break;
}
int leftPSD = PSDGet (2);
if (leftPSD <13){
VWSetSpeed(50,-10); //Turns slightly right
} else if (leftPSD >17){
VWSetSpeed(50,10); //Turns slightly left
} else {
VWSetSpeed(50,0); //Goes straight
}
}
return;
}
int main(){
driveToWall();
//parallel to wall
int PSDOld =1000000;
VWSetSpeed(0,-10);
while (true){
int PSDNew = PSDGet (2);
if (PSDOld < PSDNew){
VWSetSpeed (0,0);
break;
}
PSDOld = PSDNew;
}
for (int i =0; i <5; i++){
driveToWall();
VWTurn(90,30); //tweak 90 value as it wont be exact
}
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!