vf
Dependencies: Servo ServoArm mbed
Fork of PES_Official by
Diff: Sources/Robot.cpp
- Revision:
- 2:01e9de508316
- Parent:
- 1:388c915756f5
- Child:
- 3:fa61be4ecaa6
diff -r 388c915756f5 -r 01e9de508316 Sources/Robot.cpp --- a/Sources/Robot.cpp Sun Mar 19 12:20:26 2017 +0000 +++ b/Sources/Robot.cpp Tue Mar 21 13:12:54 2017 +0000 @@ -62,21 +62,33 @@ *right= 0.5f; } -void Robot::search(int* counter){ +void Robot::search(int* counter, Timer* t){ int rando; if (*counter >= 5) { + t->reset(); + rando = rand() % 2; while (this->sensors[FWD] < NEAR){ + if ( t->read() > TIMEOUT ){ + break; + } + this->leds[FWD] = 1; this->turnAround(rando); } - this->leds[FWD] = 0; + this->leds[FWD] = 0; } else if (this->sensors[RIGHT] < NEAR){ + t-> reset(); + *counter += 1; while (this->sensors[RIGHT] < NEAR){ + if ( t->read() > TIMEOUT ){ + break; + } + this->turnLeft(); this->leds[RIGHT] = 1; } @@ -84,8 +96,14 @@ } else if (this->sensors[LEFT] < NEAR){ + t-> reset(); + *counter += 1; while (this->sensors[LEFT] < NEAR){ + if ( t->read() > TIMEOUT ){ + break; + } + this->turnRight(); this->leds[LEFT] = 1; } @@ -93,8 +111,14 @@ } else if (this->sensors[FWD] < NEAR) { + t-> reset(); + rando = rand() % 2; while (this->sensors[FWD] < NEAR){ + if ( t->read() > TIMEOUT ){ + break; + } + this->leds[FWD] = 1; this->turnAround(rando); }