Two basic levels involved for using the Scribbler 2 Robots
Hard to test program controlling robot, as two concurrent tasks required
Solution: Use speech synthesizer called eSpeak, so computer can tell user what is supposed to happen
/* program to take several pictures, move, and beep
*/
#include <MyroC.h> // utilize MyroC library
#include <eSpeakPackage.h> // utilize eSpeakPackage library
#include <unistd.h> // needed for sleep function
#include <stdio.h> // needed for printing to terminal
/* Musical notes in the scale, as they correspond to beep frequency */
const int pitchA4 = 440;
const int pitchBf4 = 466;
const int pitchAs4 = 466;
const int pitchB4 = 493;
const int pitchC5 = 523;
const int pitchDf5 = 554;
const int pitchCs5 = 554;
const int pitchD5 = 587;
const int pitchEf5 = 622;
const int pitchDs5 = 622;
const int pitchE5 = 659;
const int pitchF5 = 698;
const int pitchGf5 = 739;
const int pitchFs5 = 739;
const int pitchG5 = 783;
const int pitchAf5 = 830;
const int pitchGs5 = 830;
const int pitchA5 = 880;
const int pitchBf5 = 932;
const int pitchAs5 = 932;
const int pitchB5 = 987;
/* play first phrase of Spirit Song by John Dunbar */
void playSongPhrase1 ()
{
eSpeakTalk ("play first phrase of song");
rBeep (1, pitchA5); // robot beeps with the pitch A5 (references to 880 Hz.) for 1 second.
rBeep (0.75, pitchB5);
rBeep (0.25, pitchA5);
rBeep (1, pitchG5);
rBeep (0.75, pitchE5);
rBeep (0.75, pitchF5);
rBeep (0.25, pitchA5);
rBeep (0.75, pitchG5);
rBeep (0.25, pitchF5);
rBeep (1.25, pitchE5);
}
/* play second phrase of Spirit Song by John Dunbar */
void playSongPhrase2 ()
{
eSpeakTalk ("play second phrase of song");
rBeep (1, pitchA5);
rBeep (0.75, pitchB5);
rBeep (0.25, pitchA5);
rBeep (1, pitchG5);
rBeep (0.75, pitchE5);
}
/* play third phrase of Spirit Song by John Dunbar */
void playSongPhrase3 ()
{
eSpeakTalk ("play third phrase of song");
rBeep (0.75, pitchF5);
rBeep (0.25, pitchE5);
rBeep (0.75, pitchD5);
rBeep (0.25, pitchC5);
rBeep (1.0, pitchC5);
}
/* processing starts with a "main" procedure */
int main ()
{
// initialization
// rConnect ("/dev/rfcomm0"); // connect to paired robot on MathLAN
rConnect ("0950"); // connect to a specific robot
eSpeakConnect();
/* take and display first picture looking ahead */
Picture pic = rTakePicture ();
rForward (-0.7, 1.0); // move forward 0.7 seconds at full speed (non-blocking)
rDisplayPicture (&pic, -20.0, "looking ahead"); // (non-blocking)
playSongPhrase1 ();
rBackward (0.7, 1.0); // move backward 0.7 seconds at full speed
/* second picture on the right */
eSpeakSetGender ("female");
rTurnRight (0.5, 0.6); // turn right for 0.5 seconds at 60% speed
pic = rTakePicture ();
rDisplayPicture (&pic, -15.0, "looking right");
playSongPhrase2 ();
/* third picture on the left */
eSpeakSetGender ("male");
rTurnLeft (1.0, 0.6); // turn left for 1.0 seconds at speed
pic = rTakePicture ();
rDisplayPicture (&pic, -6.0, "looking left");
rForward (-0.7, 1.0); // move forward 0.7 seconds at full speed (non-blocking)
rBackward (0.7, 1.0); // move backward 0.7 seconds at full speed
playSongPhrase3 ();
// finish up
eSpeakTalk ("Finishing up");
rDisconnect ();
eSpeakDisconnect ();
return 0;
}
|
created 25 January 2021 revised 30 January-3 February 2021 |
| previous next |