Using the Scribbler 2
Goals
This lab introduces the Scribbler 2 robot and combines the Scribbler 2 with eSpeak.
The MyroC Library
Just as the eSpeakPackage provides a programming interface for the eSpeak speech synthesizer, the MyroC package provides an interface to control Scribbler 2 robots.
scribblerlab.c: A first C program using the Scribbler 2 robot
Using the MyroC infrastructure to control a Scribbler 2 robot is illustrated in the program scribblerlab.c, which directs a Scribbler 2 robot to beep for 1 second. Steps for compiling and running the code follow the program listing.
Notes on using MyroC
When a C program is used to control a Scribbler 2 robot, processing follows four main steps:
/* This program illustrates how to connect * to the Scribbler robot, beep, and disconnect. */ // include the library for Scribbler commands #include
-
The program references the
MyroC
library, which identifies numerous operations for the Scribbler 2 robot.
int main() { // connect to Scribbler rConnect("/dev/rfcomm0");
-
The workstation establishes a wireless connection with the robot, using the function:
rConnect
-
Some Linux machines configured, so that
parameter /dev/rfcomm0 establishes a connection with
a specified robot previously paired with the local workstation.
rConnect("/dev/rfcomm0");
-
Macintosh computers often are paired over Bluetooth with
selected robots.
- Specifying the serial number of the Fluke will make an
immediate connection (if pairing already is set up).
rConnect("0950");
establishes a Bluetooth connection with the given serial number. - If any string is given, but not recognized by the workstation, then rConnect prints out the known robots, and the user types in the number of the one desired.
- Specifying the serial number of the Fluke will make an
immediate connection (if pairing already is set up).
-
Some Linux machines configured, so that
parameter /dev/rfcomm0 establishes a connection with
a specified robot previously paired with the local workstation.
// beep for 1 second at a frequency of 880 Hz. rBeep(1,880);
-
Processing with the robot continues, using commands from the
MyroC
library.
For consistency in naming, all robot commands start with "r
", such asrConnect
,rBeep
, andrDisconnect
// disconnect from Scribbler rDisconnect(); // return, indicating no errors have occurred return 0; } // main
-
The workstation terminates its wireless connection with the robot, using the command:
rDisconnect();
.
Every program using MyroC to control a Scribbler 2 robot will need the rConnect and rDisconnect commands. The MyroC.h header file describes the full range of commands available for controlling these robots.
Compiling and Running Programs with MyroC
When using the gcc compiler directly, one must include information about where to find the relevant libraries for the Scribbler robots. The full command is:
gcc -Wall -Wno-deprecated-declarations -std=gnu99 -pthread -lMyroC -leSpeakPackage -lMyroC -leSpeakPackage -framework OpenGL -framework GLUT scribblerlab.c -o scribblerlab
Although this line is long, the basic motivation involves identifying where the gcc compiler can find relevant pieces at various stages of compiling and running the program.
- -l indicates a specific library to be used when running a program. In this line, -lMyroC tells the computer to consult a MyroC file within a system library.
-
-framework OpenGL -framework GLUT indicate two additional files of compiled code, both of which include details about handling images (e.g., from the robot's camera).
Command Flags in Linux
In the jargon of Linux and Mac OS X, the options -l and -framework are called flags for the gcc command. More generally, many Linux and Mac OS X commands provide many options to users. Typically, an option or flag begins with a dash (-) and one (or more) letters. As an example,
-
typing the ls command in a terminal window yields a brief listing of names of files in a directory, and
-
typing ls -l (e.g., using ls with its -l or "long" flag or option) yields a listing of files, including the file name, its permissions, its size, when it was accessed, etc.
Since the gcc line is awkward (with numerous flags: "-l", "-W", and "-framework"), the suggested approach for compiling a program depends upon installing a Makefile, which supplies the relevant library information.
Also, if you have not done so already, copy this Makefile to the directory containing your program.
Assuming you have updated your .bashrc file, copied the Makefile, and called your program scribblerlab.c, you can compile the program using the following line in your terminal window:
make scribblerlab
Once the program has been compiled (with compiled
name scribblerlab
):
-
Be sure the Scribbler 2 robot is turned on, with its lights on.
(If the program does not respond to subsequent commands, either turn it off and back on again, or press the "reset" button near the IPRE fluke card.) -
Run the program in your terminal window just as you would any C program:
./scribblerlab
Makefiles
A Makefile provides a mechanism to collect compilation details in one place. Once a Makefile is created, a programmer need not write out those details again, but rather just use a command, called make, that refers to those details.
For this reading and corresponding labs, we simply copy a relevant, existing Makefile to work with the eSpeak and MyroC environments. Later in the course, we consider how to write our own Makefiles.
eSpeak together with MyroC and a Scribbler 2 Robot
Programming a Scribbler 2 robot presents challenges in testing, because regular testing requires the programmer to look at both the robot and the code at the same time.
The eSpeak library provides a capability to resolve this problem, because the eSpeakPackage allows you to look at the robot while the program speaks the intended robot action.
The program, myroc-espeak-1.c, demonstrates the full capability of eSpeak with MyroC.
Although the details of the program require moderate length (about 107 lines), the idea can be described with just a few points:
-
The program has 3 main parts:
- Part 1 directs the program move in stages forward and to the right (3 times), with beeps of increasing pitch as it moves.
- Part 2 directs the program move in stages forward and to the left (3 times), with beeps of decreasing pitch.
- Part 3 is the same as Part 1.
- The program prints to the terminal at the start of each part.
- For each part, and during each Part, the speech synthesizer describes what the robot is doing.
Notes for myroc-espeak-1.c
Capabilities of various functions are described in the eSpeakPackage.h header file and in the MyroC package.
/* Program combining test-to-speech capabilities * with Scribbler 2 motion and sound * * Part 1: robot moves forward and right three times * while playing an ascending musical chord * Part 2: robot moves forward and left three times * while playing a descending musical chord * Part 3: repeats Part 1 * * Author: Henry M. Walker * Date created: 12 May 2016 * */ #include "eSpeakPackage.h" #include "MyroC.h" #include <stdio.h>
-
myroc-espeak-1.c draws upon three libraries:
- eSpeakPackage.h
- MyroC.h
- stdio.h
-
The include statements at the start of the program tell the compiler that these resources may be used.
/* List musical notes for a C chord */ const int pitchC6 = 1047; const int pitchE6 = 1319; const int pitchG6 = 1568; const int pitchC7 = 2092;
-
The program will command the program to beep, we need to specify the frequencies for the relevant notes. Frequencies are integers (ints). The const specifier indicates that these frequencies are not allowed to change throughout the program (each pitch must be constant).
int main () { // connect for both MyroC and eSpeak rConnect ("/dev/rfcomm0"); eSpeakConnect ();
-
Both MyroC and eSpeak require initialization before they can be used.
/* Part 1: robot moves forward and right three times while playing an ascending musical chord */ printf ("starting Part 1\n"); eSpeakTalk ("move forward and turn right"); /* rForward, rTurnRight, rTurnLeft require speed and duration max speed forward is 1.0 duration in seconds */ rForward (1.0, 1.0); rBeep (0.5, pitchC6); rTurnRight (0.7, 0.75); eSpeakTalk ("move forward and turn right again"); rForward (1.0, 1.0); rBeep (0.5, pitchE6); rTurnRight (0.7, 0.5); eSpeakTalk ("move and turn a third time"); rForward (1.0, 1.0); rBeep (0.5, pitchG6); rTurnRight (0.7, 0.25); rBeep (0.5, pitchC7);
-
Each part begins by printing text at the terminal window, and sending other text to the speech synthesizer.
-
Following the the MyroC header file, the rForward and rTurnRight function utilize a similar format:
void rForward (double speed, double time) void rTurnRight (double speed, double time)
In each case, twodouble numbers are needed in parentheses when using these functions. The first number should be a number between -1.0 and 1.0:
- 1.0 indicates full speed ahead
- 0.0 indicates no speed
- -1.0 indicates full speed backward
Values between 0.0 and 1.0 represent partial speeds ahead, and values between -1.0 and 0.0 represent partial speeds backward.
/* Part 2: robot moves forward and left three times while playing a descending musical chord */ eSpeakSetGender ("female"); // specify voice characteristics printf ("starting Part 2\n"); eSpeakTalk ("move forward and turn left"); rForward (1.0, 1.0); rBeep (0.5, pitchC7); rTurnLeft (0.7, 0.25); eSpeakTalk ("move forward and turn left again"); rForward (1.0, 1.0); rBeep (0.5, pitchG6); rTurnLeft (0.7, 0.5); eSpeakTalk ("move and turn a third time"); rForward (1.0, 1.0); rBeep (0.5, pitchE6); rTurnLeft (0.7, 0.75); rBeep (0.5, pitchC6); /* Part 3: robot moves forward and right three times while playing an ascending musical chord */ eSpeakSetGender ("male"); // specify voice characteristics printf ("starting Part 3\n"); eSpeakTalk ("Part 3 repeats Part 1"); eSpeakTalk ("move forward and turn right"); rForward (1.0, 1.0); rBeep (0.5, pitchC6); rTurnRight (0.7, 0.75); eSpeakTalk ("move forward and turn right again"); rForward (1.0, 1.0); rBeep (0.5, pitchE6); rTurnRight (0.7, 0.5); eSpeakTalk ("move and turn a third time"); rForward (1.0, 1.0); rBeep (0.5, pitchG6); rTurnRight (0.7, 0.25); rBeep (0.5, pitchC7);
-
eSpeakSetGender allows the program to change the voice characteristics of the eSpeak speech synthesizer.
// finish with no errors eSpeakTalk ("Enough of this; I am going to stop now"); rDisconnect (); eSpeakDisconnect (); return 0; }
-
Before ending the program, we need to close the connections with both eSpeak and MyroC.
Although the idea of the program has structure (prologue and 3 parts), the long sequence of commands may obscure that structure. Later in this module, we will start exploring ways to clarify the structure and simplify elements of the code.
created 18 July 2011 by Henry M. Walker revised 19 September 2011 by Henry M. Walker updated for make/Makefiles 15 January 2015 by Henry M. Walker reformatted with extended eSpeak example 13 May 2016 by Henry M. Walker |
![]() ![]() |
For more information, please contact Henry M. Walker at walker@cs.grinnell.edu. |