Sample Programs

Single-robot Program to Move and Take Pictures

/* program to take several pictures, move, and beep
single-robot version
*/

#include "MyroC.h"
#include "eSpeakPackage.h"
#include // needed for sleep function
#include // 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 beat4 seconds. */
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);
}


int main ()
{
// initialization
rConnect ("/dev/rfcomm0");
eSpeakConnect();

/* take and display first picture looking ahead */
playSongPhrase1 ();
Picture pic = rTakePicture ();
rDisplayPicture (&pic, 3.0, "camera view");

/* second picture on the right */
rTurnRight (0.5, 1.0); // turn right for 0.5 seconds at full speed
playSongPhrase2 ();
pic = rTakePicture ();
rDisplayPicture (&pic, 3.0, "camera view");

/* third picture on the left */
rTurnLeft (1.0, 1.0); // turn left for 1.0 seconds at full speed
playSongPhrase3 ();
pic = rTakePicture ();
rDisplayPicture (&pic, 3.0, "camera view");

// finish up
eSpeakTalk ("Finishing up");
rDisconnect ();
eSpeakDisconnect ();

return 0;
}

Multi-robot Program to Move and Take Pictures

/* program to take several pictures, move, and beep
single-robot version
*/

#include "MyroC.h"
#include "eSpeakPackage.h"
#include // needed for sleep function
#include // 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 beat4 seconds. */
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);
}


int main ()
{
// initialization
int robot1 = rConnect ("0D42");
int robot2 = rConnect ("0913");
eSpeakConnect();

/* take and display first picture looking ahead */
Picture pic = rTakePicture ();
rDisplayPicture (&pic, 0.0, "robot2 view"); // -3.0 indicates non-blocking
rSetConnection (robot1);
pic = rTakePicture ();
rDisplayPicture (&pic, 0.0, "robot1 view");
playSongPhrase1 ();

/* second picture: robot1 moves right; robot2 moves left */
rTurnRight (0.5, 1.0);
pic = rTakePicture ();
rDisplayPicture (&pic, 0.0, "robot1 view");
rSetConnection (robot2);
rTurnLeft (0.5, 1.0);
pic = rTakePicture ();
rDisplayPicture (&pic, 0.0, "robot2 view");
playSongPhrase2 ();

/* third picture: robot1 moves right; robot2 moves left*/
rTurnLeft (0.5, 1.0);
pic = rTakePicture ();
rDisplayPicture (&pic, 0.0, "robot2 view");
rSetConnection (robot1);
pic = rTakePicture ();
playSongPhrase1 ();
rDisplayPicture (&pic, 0.0, "robot1 view");
playSongPhrase3 ();

// finish up
eSpeakTalk ("Finishing up");
rDisconnect ();
eSpeakDisconnect ();

return 0;
}

created 19 March 2016
last revised 19 March 2016
Valid HTML 4.01! Valid CSS! previous  next