|CSC 161||Grinnell College||Fall, 2013|
|Imperative Problem Solving and Data Structures|
The goal of this lab is to continue practice with C loops while also gaining some experience with moving the robot around.
Before beginning the following exercises, move to your labs directory and create a file named
this lab. Remember to set the forwardness in every program with
motion using either the command rSetForwardnessTxt("fluke-forward");
or rSetForwardnessTxt("scribbler-forward");. For this lab, you will
want to set the forwardness to "fluke-forward".
Often, you will want to write programs that have the Scribbler 2
move for varying amounts of time. In
write commands that perform the following actions.
Write a loop which moves the scribbler forward 5 times.
Write a loop which moves the Scribbler in some direction for increasing amounts of time.
Write a loop which moves the Scribbler some number of times at changing speeds.
Try changing both speed and time in the same loop.
Here you will combine motion and beeping in both simultaneous and sequential ways.
Tell the robot to move forward for one second, then beep. Run your code when it is finished
connect to the robot move forward for one second beep for one second disconnect from the robot
Now tell the robot to move forward (without specifying a time), then then beep, then stop. Try out your program when it is ready.
connect to the robot move forward beep for one second stop disconnect from the robot
Use a nonblocking command such as
leftSpeed, double rightSpeed)
rMove (double translate, double rotate). You can stop
the robot with
Now, switch the move and beep commands. What happens?
connect to the robot beep for one second move forward stop disconnect from the robot
Now add in the sleep command!
connect to the robot beep for one second move forward sleep stop disconnect from the robot
Use the command sleep (int seconds) to make your program sleep.
Why do you need the sleep command to see any motion when you beep first and then move?
Lets make the robot move spirally! Spirals begin from a center point, with the line moving in a circular motion, with a gradually greater distance from the origin. There are two straightforward ways, each using only one loop, that moves the Scribbler 2 in a spiral motion for at least ten seconds.
Write a program that makes the Scribbler 2 robot behave like turtles in CSC 151. So, the robot would move forward, then turn, then move forward a little further, then turn, and so on in a spiral shape.
Write the program that makes the Scribbler 2 robot move in a spiral pattern using a single command. So, the robot would be turning while moving forward.
Hint: use nonblocking motion calls together with the sleep function.
You now know how to make the robot beep while moving. You also learned in a previous lab how to use a loop to make rising pitches. Now, you will combine the two actions.
Write a program that moves the Scribbler 2 while it beeps fifteen times in a row, with every beep rising in pitch, then stops the Scribbler 2.
While blind motion can be interesting, sensing obstacles is where motion really gets awesome!
Write a simple program which moves the robot forward until it sees an obstacle. Use the rGetObstacleNum(int sensor) function.
Write a simple program which moves the robot forward until it sees an obstacle, then turns right, then moves forward again until it sees an obstacle.
Now generalize your program so that your robot moves forward until it sees an obstacle, then turns right, moves forward until it sees an obstacle, turns right, moves forward until obstacle, turns right, etc. It should do this until the program is terminated.
Development of laboratory exercises is an interative process. Prof. Walker welcomes your feedback! Feel free to talk to him during class or stop by his office.