Lab 2: Sensing with robots

Copy the files you will need from ~cs102/robot_labs/Lab_Skeletons/Lab2/ to your Lab2 directory.

In this lab you will experiment with the basics of of moving the robots and using sensors.

Topics:

The main topics you may need in this lab are:

Part I: Sensing with the Robot

Your job is to write a program named Lab2Driver.cpp that:

Remember:

There are plenty of ways to move the robot. You can make use of robot.forward(), robot.motors() or any other locomotion commands within the parameters outlined above. At a minimum you will need to move forward and backward, spinning in place is not good enough

In order for the robot to sense what is in front of it you will need to use the getIR() command. Here is an example:

int left=robot.getIR("left");

int right=robot.getIR("right");
These functions return 0 if there's an obstacle, otherwise they return 1. Use this to set up an obstacle avoiding behavior.

Part II: Using Loops

A while loop is a conditional loop that executes a block of code repeatedly until the condition it takes as an argument is met. The condition we'll be using in this lab is part of the Myro API and is known as timeRemaining.

timeRemaining takes an interger as input, and will return true until that many seconds have passed: that is, the loop will excicute until the given number of seconds has passed.

//In this examples seconds is an integer
	
while(timeRemaining(seconds))
{
	//code you wish to exiecute repeatedly goes here
}
Use this to make sure your code executes for a full 30 seconds. As always, upon completion of this lab submit your work vi the submitscript.