CSC 161 Grinnell College Fall, 2011
 
Imperative Problem Solving and Data Structures
 

Laboratory Exercise on Scribbler 2 Motion and Loops

Goals

The goal of this lab is to practice using the Scribbler 2 motion commands, while increasing proficiency with loops and conditionals.

Exercises

Before beginning the following exercises, move to the labs folder used for this class and create a file called loops-motion-lab.c for this lab. Also, remember to set the forwardness in every program with motion using the command

     rSetForwardnessTxt("fluke-forward");
  1. Simple Motion Commands

    Often, you will want to write programs that have the Scribbler 2 move for varying amounts of time. In loops-motion-lab.c, write commands that perform the following actions.

    1. Write a loop that moves the Scribbler in some direction for increasing amounts of time (less than 6 seconds).
    2. Write a loop that moves the Scribbler some number of times at changing speeds.
    3. Try changing both speed and time in the same loop.

  2. Spiral Motion

    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.

    1. 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.
    2. 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 rMove(double translate, double rotate).

  3. Motion with Beeping

    The Scribbler 2 robot has many capabilities; so far, you have been introduced to motion and sound. In this exercise, you will try to get the robot to move while beeping. Pseudocode is provided for each exercise.

    1. Tell the robot to move forward for one second, and then beep. Are the actions executed simultaneously?

      Pseudocode:

                  connect to the robot
                  move forward for one second
                  beep for one second
                  disconnect from the robot
      
    2. Now tell the robot to beep, then move forward for one second. Are the actions simultaneous this time?

      Pseudocode:

                  connect to the robot
                  beep for one second
                  move forward for one second
                  disconnect from the robot
                
    3. Tell the robot to move forward (without specifying a time), then stop, then beep. Check to see if the code executes properly.

      Pseudocode:

                  connect to the robot
                  move forward
                  stop
                  beep for one second
                  disconnect from the robot
                

      Hint: use a continuous command such as rMotors or rMove.

    4. Now, move the line that stops the robot to after the beep. Are the actions simultaneous now?

      Pseudocode:

                  connect to the robot
                  move forward
                  beep for one second
                  stop
                  disconnect from the robot
                

  4. Motion and Looped Sound

    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.

Reminder: Complete Evaluation Form

When you have finished this lab, be sure to fill out its evaluation form in the "Lab Evaluation" section for CSC 161 on Pioneer Web


This document is available on the World Wide Web as

     http://www.cs.grinnell.edu/~walker/modules/module-cond-loops-testing/motion-loops-lab.shtml

created 21 July 2011 by April O'Neill
last full revision 29 July 2011 by April O'Neill
minor editing 24 August 2011 by Henry M. Walker
Valid HTML 4.01! Valid CSS!
For more information, please contact Henry M. Walker at walker@cs.grinnell.edu.