Using the Scribbler 2 with MyroC
Today we introduce how to program the Scribbler 2 robot in using the MyroC library, demonstrating how to integrate the eSpeak package to vocalize commands.
Introducing the Scribbler 2
First, you should read the S2 start-up guide, pp. 3-6 (one is with each robot) to familiarize yourself with the general logistics of using the robot.
Programming the Scribbler 2 with MyroC
When a C program is used to control a Scribbler 2 robot, processing follows four main steps:
-
The program references the
MyroClibrary, which contains numerous operations for the Scribbler 2 robot. -
The workstation establishes a wireless connection with the robot, using
the command:
rConnect("/dev/rfcomm0"); -
Processing with the robot continues, using commands from
the
MyroClibrary.
For consistency in naming, all robot commands start with "r", such asrConnect,rBeep, andrDisconnect -
The workstation stops its wireless connect with the robot, using
the command:
rDisconnect();.
These steps are illustrated in the following program; steps for compiling and running the code follow the program listing.
/* This program illustrates how to
* connect to the Scribbler robot,
* beep, and
* disconnect.
*/
#include /* include the signatures for Scribbler commands */
int
main()
{
rConnect("/dev/rfcomm0"); /* connect to Scribbler */
rBeep(1,550); /* beep for 1 second at a frequency of 550 Hz. */
rDisconnect(); /* disconnect from Scribbler */
return 0; /* return, indicating no errors have occurred */
} /* main */
Compiling and Running Scribbler2/MyroC Programs
From the lab on Linux basics,
the following lines should already be placed at the bottom of your .bashrc file:
# make the libraries known to the execution environment LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/home/walker/Myro/lib" export LD_LIBRARY_PATH
Assuming the program is called scribblerlab.c, you could compile the
program using the following line in your terminal window:
gcc -I/home/walker/Myro/include/MyroC -L/home/walker/Myro/lib -lMyroC -lbluetooth -ljpeg -o scribblerlab scribblerlab.c
The MyroC interacts directly with a bluetooth
package for Bluetooth communication in Linux. This requires the
additional parameter -lbluetooth. In addition, some
Scribbler operations include image processing, and this requires
the parameter -ljpeg
This line is clearly too long and awkward to type for compiling each
MyroC/eSpeak program. Thankfully, if you have placed a copy of the Makefile, (as described in
the lab
on linux basics) in the same directory, you can simply use make
make scribblerlabCommentary: Look at the
Makefile you copied to
your directory during
the lab on Linux
basics.
-
The
makecommand utilizesMakefilefor information about how to compile. -
In using
make, the program name is given without the.csuffix (e.g.,make scribbler-lab). -
makeassumes the program name has a.cextension, andmakeproduces an executable program using the name (without the.c). -
The variable
LDFLAGSidentifies the libraries that are needed for MyroC programs when running eSpeak and MyroC and where they are located. These flags are exactly what appears in thegccline above. -
The variable
CFLAGSprovides guidance in compiling programs.-
The
-Wallflag asks the compiler to notify you of all warnings that something might not be right (read-Wallas "Warnings all"). -
The
-std=gnu99flag specifies that the compiler should utilize the most recent implementation of the C 1999 standard, as implemented by the gnu project of the Free Software Foundation.
-
The
-
Altogether, the
makeapproach uses the fullgccline, together with a directive about printing warnings and a specification of which version of C to utilize.
Once the program has been compiled (with compiled
name scribblerlab):
-
Be sure the Scribbler 2 robot is turned on, with its lights on.
Note: 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
Examples
Read over the longer examples, earsHangLow.c and spirit-song.c
You should also briefly review the MyroC.h header file to see what functions you will eventually be able to use with the robot.
