Main Function:
goStright(120);
Helpful Higher Function:
int calculateCounts(int x){
int result;
result = x / (2*3.14*1.25)*4;
return result;
}
int goToForward(int distance){
motorSpeed(4,45);
int n = getForwardCounts();
int c =calculateCounts(distance);
int d = 0;
int t =0;
while(d< c){
pauseFor(1);
t++;
d = getForwardCounts()-n;
}
return t;
}
void goToBackward(int distance){
motorSpeed(4,-45);
int n = getBackwardCounts();
int c =-calculateCounts(distance);
int d = 0;
while(d> c){
pauseFor(1);
d = getBackwardCounts()-n;
}
// Stop all motors
motorSpeed(4,0);
}
void goStright(int distance){
int t = goToForward(distance);
motorSpeed(4,0);
pauseFor(4);
motorSpeed(4,-60);
pauseFor(t);
motorSpeed(4,0);
pauseFor(4);
}
void goRound(int distance){
int t = goToForward(distance);
// motorSpeed(4,0);
// pauseFor(2);
motorSpeed(4,-60);
pauseFor(1);
motorSpeed(4,-60);
pauseFor(t);
motorSpeed(4,0);
pauseFor(2);
motorSpeed(4,15);
pauseFor(2);
motorSpeed(4,0);
pauseFor(2);
}