Mission Instructions

Your mission is to create a robot that can explore remote, narrow canyons. First, you will create a sample canyon system with both a left and right turn. Then you will design, test, and refine your robot until it can navigate the canyon system independently.

8. Code: Drive Forwards

Check your plan to remember what your robot should do when it has room to drive forward after it knows there’s no option to turn left. You haven’t created a custom function for this yet, so it’s time to put on your thinking cap!

If the front-facing distance sensor sees enough room to move forward, then what?

Should it move by a known distance (let’s say 2 inches) before testing for openings, or should it just go ahead until it finds an opening? Which of these 2 blocks would be more appropriate to use?


Drifting

As you test your robot, you might notice that sometimes it drifts from one side of a canyon to another. This happens for a lot of possible reasons: the robot might have started out not quite perfectly aligned with the path, the motors might be slightly imperfectly calibrated, there might be an inconsistency on the texture of the ground, or many others. 


It is less important to figure out why your robot is drifting and more important to create a way for it to help itself when it does, inevitably, drift. 

Drifting will be measured by the side-facing distance sensor. You’ll need to do quite a bit of testing to make this function work for you, but here’s the one that worked for us:


Note that this function does not correct the drifting itself, it only returns information about whether the robot is drifting or not.  

Since you know which side your sensor is facing, you might even change the “away”, “closer”, and “all good” to be more specific: “left”, “right”, and “center”. Your choice!

Once you’ve created your I_am_drifting function, it’s time to add it into your Driving Forward code!