10 Mission Instructions

Your mission is to create a remote control car that won't get into an accident. 

6. Code: Enable the GoPiGo to Avoid Obstacles

To address the second goal, let’s figure out what conditions are needed for the GoPiGo to avoid collisions. 


The car should stop and react when all of the following conditions are met. 
    • An object is detected ______cm away. 
    • The GoPiGo is going __________ (forward, backward, left , right) 
    • If needed: Other condition: __________________________________ 


Second, we need to decide on the GoPiGo’s reaction when these conditions are met. It might be as simple as stopping, but it might be backing up, turning around, or sending a distress signal. On a piece of paper, write down what your GoPiGo will do if an obstacle is detected. 


The collision-detection code has two distinct parts: one decides if there’s a danger and the second decides what to do. 


Take a look at the code you created so far. Where in that code could you add collision-detection? 


What part of your code corresponds to the above conditions? Is there more than one place? 


There is more than one way to achieve the same result. You may very well find a solution that’s different than the one shown below. As long as it passes your tests, you’re fine!