March 2019
Intermediate to advanced
312 pages
7h 37m
English
The object-following robot program is basically a combination of the obstacle-avoiding program from Chapter 4, Building an Obstacle-Avoiding Robot, and the preceding ball-tracing program. The program is called ObjectFollowingRobot.cpp and you can download it from the Chapter07 folder of the GitHub repository:
int main() { ... float distance = (totalTime * 0.034)/2; if(distance < 15) { cout<<"Object close to Robot"<< " " << Mat(p)<< " " <<distance << " cm" << endl; stop(); } else{ if(x<20 && y< 20) { cout<<"Object not found"<< " " << Mat(p)<< " " <<distance << " cm" << endl; stop(); } if(x > 20 && x < 170 && y > 20 ) { cout<<"LEFT TURN"<< " " << Mat(p)<< " " <<distance << " cm" << endl; left(); } if(x > 170 ...