Using the Scribbler 2
This lab introduces the Scribbler 2 robot to students and combines the Scribbler 2 with eSpeak.
Getting Started with the Scribbler 2
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
is 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
is rDisconnect() . Here, you do not need
to state any port.
Hint: Don't forget to include the
library MyroC.h at the beginning of every
program.
Connecting to and disconnecting from the robot
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 program.
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 &
Troubleshooting: If youremacseditor opens with a split screen, and if you find the split screen annoying, you might want to review the section on Modifying emacs in the lab on Linux basics. -
Copy the program
scribblerlab.cto your emacs window. Don't forget to save it every time before you compile. - Compile the program by typing in the terminal. Two approaches are possible.
-
For the
MyroCenvironment, use the line:gcc -I/home/walker/Myro/include/MyroC -L/home/walker/Myro/lib -lMyroC -lbluetooth -ljpeg -leSpeakPackage -o scribblerlab scribblerlab.c
-
Alternatively, you can use the command
make scribblerlab
Troubleshooting:
-
If the
gcccommand prints errors that there are undefined references to`rConnect', `rBeep', and/or`rDisconnect',- Be sure you have included the library flags
-lMyroC -lbluetooth -ljpegin yourgcccommand. - Be sure you included the MyroC material into
your
.bashrcfile, as described in the early parts of the lab on Linux Basics
- Be sure you have included the library flags
-
If the
gcccommand works, but themakecommand indicates errors with undefined references to`rConnect', `rBeep', and/or`rDisconnect', be sure you have copied theMakefilefile to your current directory, as described in theMakefilesection of the lab on Linux Basics
-
If the
-
With either approach for compilation, run the program in your terminal
by typing:
./scribblerlab
Experimenting with Connections
-
In the program
scribblerlab.c, delete the/dev/rfcomm0port that is inrConnect(). What happens when you compile and run? Now typehellointo the port. What happens when you compile and run? Do the same for the empty 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 (you could do this with Emacs' undo command).
Sound from the Scribbler 2 Robot
Here is the documentation for rBeep() from the development version of the MyroC.h header file:
/**
* @brief Beeps with the given duration and frequency
* @param duration length of note in seconds
* @param frequency frequency of pitch in cycles per second (hertz)
* @pre duration > 0.0
*/
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 your own program: Music
-
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 on numerous online sources or in the example programs for today.
Scribbler 2 Robots and eSpeak
A challenge arises when trying to test a robot-based program, in which the robot performs several actions—including movement.
- Testing requires the programmer to look at the code to know what is supposed to happen.
- Testing requires the programmer to watch the robot to see what it does.
Even with two eyes, watching both the program and the robot can be difficult. The eSpeak package can help resolve this difficulty.
-
Examine the
scribbler-espeak.cprogram.-
Open the
scribbler-espeak.cprogram and copy it to your account. -
To compile the program with
gcc, you will need to specify both MyroC and eSpeak with one of the following two lines:gcc -I/home/walker/Myro/include/MyroC -L/home/walker/Myro/lib -lMyroC -lbluetooth -ljpeg -o scribbler-espeak scribbler-espeak.c
Alternatively, use themakecommand:make scribbler-espeak
- Run the program and describe what happens.
- Edit the program, make some changes, and compile and run the revised program to check what happens.
-
Open the
Optional Activity: Playing a Duet
-
Look at the MyroC documentation:
- MyroC data structures (Picture, Pixel)
- MyroC header file (Web-based format)
- MyroC header file (C-style format)
Find the function
rBeep2(). Write a simple program and test howrBeep2()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.
