|CSC 161||Grinnell College||Fall, 2013|
|Imperative Problem Solving and Data Structures|
The goal of this lab is to introduce the Scribbler 2 robot to students.
In this lab, you will experiment with the Scribbler 2 robot's sound capabilities, as well as practice writing and compiling programs that use the robot.
For every program using the Scribbler 2 robot, you first must connect
to the robot. At the end of the program (before return 0;), you will disconnect from the
robot. The command to connect to the robot
rConnect("/dev/rfcomm0") . This opens a connection to
the robot using the port
/dev/rfcomm0 . Later in the lab,
you will experiment with what happens when the port is not included. The
command to disconnect from the robot
rDisconnect() . Here, you do not need to state any
Hint: Don't forget to include the library
MyroC.h at the beginning of every program.
In this exercise, you will download the code for a program that
connects to the Scribbler, beeps once, and then disconnects from the
Scribbler. Read the program and its annotations to further understand
what is happening. You will then copy the program to your emacs
file and compile the program on your terminal. Finally you will run the
Here are the steps to do these:
Open a terminal window and move to the directory you are using for this course.
Start emacs with the command:
emacs scribblerlab.c &
Copy the linked program scribblerlab.c to your emacs window. Don't forget to save it every time before you compile.
Compile the program by typing in the terminal:
gcc -lMyroC -o scribblerlab scribblerlab.c
Run it in your terminal by typing:
In the program
scribblerlab.c , delete the
/dev/rfcomm0 port that is in
rConnect() . What happens when you compile
and run? Now type
hello into the port. What happens when you compile
and run? Do the same for the null string "" . Replace the port when you
are done and save the program.
Delete the include statement. What happens when you try to compile? Replace the include statement and save.
Here is the documentation for rBeep() from the MyroC.h header file:
/* function for sending tone to the robot */ void rBeep (double duration, int freq);
In the original program
scribblerlab.c , copy the
beep statement and change the frequency to 600, 700, 900, 400, 15000 and 200. Experiment with frequencies. Which frequencies are audible?
Now vary the length of the beeps. Copy the beep statement again and this time change the duration to 0.75, 2, 2.5, 3, 3.1, and 4. Listen to what happens.
Write a program that connects to the robot, makes it beep a short tune that sounds good to you, then disconnects from the robot.
Hint: The pitches for various notes can be found using Wikipedia or in the example programs for today.
Look in the MyroC.h header file and find the function rBeep2(). Write a simple program and test how rBeep2() works. If you finish this, go through the rest of the header file and see if there is anything else you want to try testing out.
Development of laboratory exercises is an iterative process. Prof. Walker welcomes your feedback! Feel free to talk to him during class or stop by his office.