In this lab you will experiment with the basics of of moving the robots and using sensors.
The main topics you may need in this lab are:
Your job is to write a program named Lab2Driver.cpp that:
- Moves the robot in at least two ways. One of which can not be turning.
- Senses when an object is in front of the robot and moves to robot to avoid it.
- Uses a while loop to run for 30 seconds
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:
These functions return 0 if there's an obstacle, otherwise they return 1. Use this to set up an obstacle avoiding behavior.int left=robot.getIR("left"); int right=robot.getIR("right");
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.
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.//In this examples seconds is an integer while(timeRemaining(seconds)) { //code you wish to exiecute repeatedly goes here }