Application Struct Reference

Collaboration diagram for Application:

Collaboration graph
[legend]

List of all members.

Public Member Functions

 Application (int argc, char **argv, std::iostream &stream)
Create::Opcode getMode (const std::string &m)
void help (int status=0)
void sendScript (int argc, char **argv)
void sendSong (int argc, char **argv)
void sendQueryList (int argc, char **argv)
void sendStream (int argc, char **argv)
void showSensors ()
void usage ()
void version ()
 Application (int argc, char **argv, std::iostream &stream)
Create::Opcode getMode (const std::string &m)
void help (int status=0)
void sendScript (int argc, char **argv)
void sendSong (int argc, char **argv)
void sendQueryList (int argc, char **argv)
void sendStream (int argc, char **argv)
void showSensors ()
void usage ()
void version ()


Constructor & Destructor Documentation

Application::Application ( int  argc,
char **  argv,
std::iostream &  stream 
) [inline]

00165     : binaryName_ (argv[0]),
00166       mode_ (),
00167       robot_ (stream)
00168   {
00169     if (argc < 2)
00170       usage ();
00171     std::string argv1 = argv[1];
00172     if (argv1 == "--help"
00173         || argv1 == "-h"
00174         || argv1 == "help")
00175       help ();
00176     if (argv1 == "--version"
00177         || argv1 == "-v"
00178         || argv1 == "version")
00179       version ();
00180 
00181     mode_ = getMode (argv[1]);
00182 
00183     try
00184       {
00185         if (mode_ == Create::OPCODE_START)
00186           return;
00187         robot_.sendSafeCommand ();
00188         switch (mode_)
00189           {
00190             APPLY_ON_OPCODES (SEND_CMD)
00191           default:
00192               usage ();
00193           }
00194       }
00195     catch (std::runtime_error& e)
00196       {
00197         std::cerr << e.what () << std::endl;
00198         exit (2);
00199       }
00200     catch (...)
00201       {
00202         std::cerr << "Unexpected error" << std::endl;
00203         exit (42);
00204       }
00205   }

Application::Application ( int  argc,
char **  argv,
std::iostream &  stream 
) [inline]

00165     : binaryName_ (argv[0]),
00166       mode_ (),
00167       robot_ (stream)
00168   {
00169     if (argc < 2)
00170       usage ();
00171     std::string argv1 = argv[1];
00172     if (argv1 == "--help"
00173         || argv1 == "-h"
00174         || argv1 == "help")
00175       help ();
00176     if (argv1 == "--version"
00177         || argv1 == "-v"
00178         || argv1 == "version")
00179       version ();
00180 
00181     mode_ = getMode (argv[1]);
00182 
00183     try
00184       {
00185         if (mode_ == Create::OPCODE_START)
00186           return;
00187         robot_.sendSafeCommand ();
00188         switch (mode_)
00189           {
00190             APPLY_ON_OPCODES (SEND_CMD)
00191           default:
00192               usage ();
00193           }
00194       }
00195     catch (std::runtime_error& e)
00196       {
00197         std::cerr << e.what () << std::endl;
00198         exit (2);
00199       }
00200     catch (...)
00201       {
00202         std::cerr << "Unexpected error" << std::endl;
00203         exit (42);
00204       }
00205   }


Member Function Documentation

Create::Opcode Application::getMode ( const std::string &  m  )  [inline]

00212   {
00213     APPLY_ON_OPCODES (STR_TO_OPCODE);
00214     return static_cast<Create::Opcode> (0);
00215   }

void Application::help ( int  status = 0  )  [inline]

00221   {
00222     std::cout
00223       << "Usage: irobot-create-ctl <action> [options]" << std::endl
00224       << std::endl
00225       << "Available actions are:" << std::endl;
00226     APPLY_ON_OPCODES (PRINT_ACTIONS);
00227     std::cout << std::endl;
00228     std::cout << "Additional actions are:" << std::endl
00229               << "\t" "help (this message)" << std::endl
00230               << "\t" "version" << std::endl;
00231 
00232     std::cout
00233       << std::endl
00234       << "Display the specified action on the standard output using the"
00235       << std::endl
00236       << "Open Interface protocol version 2. The stream can be redirected"
00237       << std::endl
00238       << "to a device file to send the action to a real robot." << std::endl
00239       << std::endl
00240       << "Example (serial port): irobot-create-ctl safe > /dev/ttySO"
00241       << std::endl
00242       << "Example (bluetooth): irobot-create-ctl safe > /dev/rfcomm0"
00243       << std::endl;
00244 
00245     std::cout
00246       << std::endl
00247       << "Report bugs to <" << PACKAGE_BUGREPORT << ">" << std::endl;
00248 
00249     exit (status);
00250   }

void Application::sendScript ( int  argc,
char **  argv 
) [inline]

00253   {
00254     Create::opcodes_t script;
00255 
00256     for (int i = 2; i < argc; ++i)
00257       script.push_back (castArg<unsigned char> (argv[i]));
00258     robot_.sendScriptCommand (script);
00259   }

void Application::sendSong ( int  argc,
char **  argv 
) [inline]

00262   {
00263     Create::song_t song;
00264     if (argc % 2 == 0)
00265       usage ();
00266 
00267     const unsigned char sid = castArg<unsigned char> (argv[2]);
00268     for (int i = 3; i + 1 < argc; i += 2)
00269       song.push_back (std::make_pair (castArg<unsigned char> (argv[i]),
00270                                       castArg<unsigned char> (argv[i+1])));
00271     robot_.sendSongCommand (sid, song);
00272   }

void Application::sendQueryList ( int  argc,
char **  argv 
) [inline]

00281   {
00282     SENSOR_CMD (robot_.sendQueryListCommand (sensors));
00283     showSensors ();
00284   }

void Application::sendStream ( int  argc,
char **  argv 
) [inline]

00287   {
00288     SENSOR_CMD (robot_.sendStreamCommand (sensors));
00289     showSensors ();
00290   }

void Application::showSensors (  )  [inline]

00293   {
00294     std::cerr
00295       << "Wheeldrop: "
00296       << " caster: " << ((!!robot_.wheeldropCaster ()) ? "true" : "false")
00297       << " left wheel: " << ((!!robot_.wheeldropLeft ()) ? "true" : "false")
00298       << " right wheel: " << ((!!robot_.wheeldropRight ()) ? "true" : "false")
00299       << " bump left: " << ((!!robot_.bumpLeft ()) ? "true" : "false")
00300       << " bump right: " << ((!!robot_.bumpRight ()) ? "true" : "false")
00301       << std::endl;
00302 
00303     std::cerr
00304       << "Wall: " << ((!!robot_.wall ()) ? "true" : "false")
00305       << std::endl;
00306 
00307     std::cerr
00308       << "Cliff: "
00309       << " left: " << ((!!robot_.cliffLeft ()) ? "true" : "false")
00310       << " front-left: " << ((!!robot_.cliffFrontLeft ()) ? "true" : "false")
00311       << " front-right: " << ((!!robot_.cliffFrontRight ()) ? "true" : "false")
00312       << " right: " << ((!!robot_.cliffRight ()) ? "true" : "false") << std::endl;
00313 
00314     std::cerr
00315       << "Digital pin status: "
00316       << " device detect: " << ((!!robot_.deviceDetect ()) ? "true" : "false")
00317       << " 3: " << ((!!robot_.digitalInput3 ()) ? "true" : "false")
00318       << " 2: " << ((!!robot_.digitalInput2 ()) ? "true" : "false")
00319       << " 1: " << ((!!robot_.digitalInput1 ()) ? "true" : "false")
00320       << " 0: " << ((!!robot_.digitalInput0 ()) ? "true" : "false") << std::endl;
00321 
00322     std::cerr
00323       << "Analog signal: " << robot_.analogSignal () << std::endl;
00324 
00325     std::cerr
00326       << "Chargers available? "
00327       << " home base: "
00328       << ((!!robot_.homeBaseChargerAvailable ()) ? "true" : "false")
00329       << " internal: "
00330       << ((!!robot_.internalChargerAvailable ()) ? "true" : "false") << std::endl;
00331 
00332     std::cerr
00333       << "Virtual Wall: "
00334       << ((!!robot_.virtualWall ()) ? "true" : "false") << std::endl;
00335 
00336     std::cerr
00337       << "Overcurrent: "
00338       << " left wheel: "
00339       << ((!!robot_.leftWheelOvercurrent ()) ? "true" : "false")
00340       << " right wheel: "
00341       << ((!!robot_.rightWheelOvercurrent ()) ? "true" : "false")
00342       << " LD2: " << ((!!robot_.ld2Overcurrent ()) ? "true" : "false")
00343       << " LD1: " << ((!!robot_.ld1Overcurrent ()) ? "true" : "false")
00344       << " LD0: " << ((!!robot_.ld0Overcurrent ()) ? "true" : "false");
00345 
00346     std::cerr
00347       << "IR: " << robot_.ir () << std::endl;
00348 
00349     std::cerr
00350       << "Buttons: "
00351       << " advance: "<< ((!!robot_.advanceButton ()) ? "true" : "false")
00352       << " play: " << ((!!robot_.playButton ()) ? "true" : "false") << std::endl;
00353 
00354     std::cerr
00355       << "Distance: " << robot_.distance () << std::endl;
00356 
00357     std::cerr
00358       << "Angle: " << robot_.angle () << std::endl;
00359 
00360     std::cerr
00361       << "Charging state: " << robot_.chargingState () << std::endl;
00362 
00363     std::cerr
00364       << "Battery voltage: " << robot_.batteryVoltage () << std::endl;
00365 
00366     std::cerr
00367       << "Battery current: " << robot_.batteryCurrent () << std::endl;
00368 
00369     std::cerr
00370       << "Battery temperature: " << robot_.batteryTemperature () << std::endl;
00371 
00372     std::cerr
00373       << "Battery charge: " << robot_.batteryCharge () << std::endl;
00374 
00375     std::cerr
00376       << "Battery capacity: " << robot_.batteryCapacity () << std::endl;
00377 
00378     std::cerr
00379       << "Wall signal: " << robot_.wallSignal () << std::endl;
00380 
00381     std::cerr
00382       << "Cliff left signal: "
00383       << robot_.cliffLeftSignal () << std::endl;
00384 
00385     std::cerr
00386       << "Cliff front-left signal: "
00387       << robot_.cliffFrontLeftSignal () << std::endl;
00388 
00389     std::cerr
00390       << "Cliff front-right signal: "
00391       << robot_.cliffFrontRightSignal () << std::endl;
00392 
00393     std::cerr
00394       << "Cliff right signal: " << robot_.cliffRightSignal () << std::endl;
00395 
00396     std::cerr
00397       << "Song number: " << static_cast<int> (robot_.songNumber ())
00398       << std::endl;
00399 
00400     std::cerr
00401       << "Song playing: "
00402       << ((!!robot_.songPlaying ()) ? "true" : "false") << std::endl;
00403 
00404     std::cerr
00405       << "Streamed packets: " << robot_.streamPackets () << std::endl;
00406 
00407     std::cerr
00408       << "Requested velocty: "
00409       << robot_.requestedVelocity () << std::endl;
00410 
00411     std::cerr
00412       << "Request radius: "
00413       << robot_.requestedRadius () << std::endl;
00414 
00415     std::cerr
00416       << "Request left velocity: "
00417       << robot_.requestedLeftVelocity () << std::endl;
00418 
00419     std::cerr
00420       << "Request right velocity: "
00421       << robot_.requestedRightVelocity () << std::endl;
00422 
00423   }

void Application::usage (  )  [inline]

00426   {
00427     help (1);
00428   }

void Application::version (  )  [inline]

00431   {
00432     std::cerr
00433       << PACKAGE_STRING << std::endl
00434       << "Copyright (C) 2008  iLab."
00435       << std::endl
00436       << "This is free software; see the source for copying conditions."
00437       << std::endl
00438       << "There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A"
00439       << std::endl
00440       << "PARTICULAR PURPOSE." << std::endl;
00441     exit (0);
00442   }

Create::Opcode Application::getMode ( const std::string &  m  )  [inline]

00212   {
00213     APPLY_ON_OPCODES (STR_TO_OPCODE);
00214     return static_cast<Create::Opcode> (0);
00215   }

void Application::help ( int  status = 0  )  [inline]

00221   {
00222     std::cout
00223       << "Usage: irobot-create-ctl <action> [options]" << std::endl
00224       << std::endl
00225       << "Available actions are:" << std::endl;
00226     APPLY_ON_OPCODES (PRINT_ACTIONS);
00227     std::cout << std::endl;
00228     std::cout << "Additional actions are:" << std::endl
00229               << "\t" "help (this message)" << std::endl
00230               << "\t" "version" << std::endl;
00231 
00232     std::cout
00233       << std::endl
00234       << "Display the specified action on the standard output using the"
00235       << std::endl
00236       << "Open Interface protocol version 2. The stream can be redirected"
00237       << std::endl
00238       << "to a device file to send the action to a real robot." << std::endl
00239       << std::endl
00240       << "Example (serial port): irobot-create-ctl safe > /dev/ttySO"
00241       << std::endl
00242       << "Example (bluetooth): irobot-create-ctl safe > /dev/rfcomm0"
00243       << std::endl;
00244 
00245     std::cout
00246       << std::endl
00247       << "Report bugs to <" << PACKAGE_BUGREPORT << ">" << std::endl;
00248 
00249     exit (status);
00250   }

void Application::sendScript ( int  argc,
char **  argv 
) [inline]

00253   {
00254     Create::opcodes_t script;
00255 
00256     for (int i = 2; i < argc; ++i)
00257       script.push_back (castArg<unsigned char> (argv[i]));
00258     robot_.sendScriptCommand (script);
00259   }

void Application::sendSong ( int  argc,
char **  argv 
) [inline]

00262   {
00263     Create::song_t song;
00264     if (argc % 2 == 0)
00265       usage ();
00266 
00267     const unsigned char sid = castArg<unsigned char> (argv[2]);
00268     for (int i = 3; i + 1 < argc; i += 2)
00269       song.push_back (std::make_pair (castArg<unsigned char> (argv[i]),
00270                                       castArg<unsigned char> (argv[i+1])));
00271     robot_.sendSongCommand (sid, song);
00272   }

void Application::sendQueryList ( int  argc,
char **  argv 
) [inline]

00281   {
00282     SENSOR_CMD (robot_.sendQueryListCommand (sensors));
00283     showSensors ();
00284   }

void Application::sendStream ( int  argc,
char **  argv 
) [inline]

00287   {
00288     SENSOR_CMD (robot_.sendStreamCommand (sensors));
00289     showSensors ();
00290   }

void Application::showSensors (  )  [inline]

00293   {
00294     std::cerr
00295       << "Wheeldrop: "
00296       << " caster: " << ((!!robot_.wheeldropCaster ()) ? "true" : "false")
00297       << " left wheel: " << ((!!robot_.wheeldropLeft ()) ? "true" : "false")
00298       << " right wheel: " << ((!!robot_.wheeldropRight ()) ? "true" : "false")
00299       << " bump left: " << ((!!robot_.bumpLeft ()) ? "true" : "false")
00300       << " bump right: " << ((!!robot_.bumpRight ()) ? "true" : "false")
00301       << std::endl;
00302 
00303     std::cerr
00304       << "Wall: " << ((!!robot_.wall ()) ? "true" : "false")
00305       << std::endl;
00306 
00307     std::cerr
00308       << "Cliff: "
00309       << " left: " << ((!!robot_.cliffLeft ()) ? "true" : "false")
00310       << " front-left: " << ((!!robot_.cliffFrontLeft ()) ? "true" : "false")
00311       << " front-right: " << ((!!robot_.cliffFrontRight ()) ? "true" : "false")
00312       << " right: " << ((!!robot_.cliffRight ()) ? "true" : "false") << std::endl;
00313 
00314     std::cerr
00315       << "Digital pin status: "
00316       << " device detect: " << ((!!robot_.deviceDetect ()) ? "true" : "false")
00317       << " 3: " << ((!!robot_.digitalInput3 ()) ? "true" : "false")
00318       << " 2: " << ((!!robot_.digitalInput2 ()) ? "true" : "false")
00319       << " 1: " << ((!!robot_.digitalInput1 ()) ? "true" : "false")
00320       << " 0: " << ((!!robot_.digitalInput0 ()) ? "true" : "false") << std::endl;
00321 
00322     std::cerr
00323       << "Analog signal: " << robot_.analogSignal () << std::endl;
00324 
00325     std::cerr
00326       << "Chargers available? "
00327       << " home base: "
00328       << ((!!robot_.homeBaseChargerAvailable ()) ? "true" : "false")
00329       << " internal: "
00330       << ((!!robot_.internalChargerAvailable ()) ? "true" : "false") << std::endl;
00331 
00332     std::cerr
00333       << "Virtual Wall: "
00334       << ((!!robot_.virtualWall ()) ? "true" : "false") << std::endl;
00335 
00336     std::cerr
00337       << "Overcurrent: "
00338       << " left wheel: "
00339       << ((!!robot_.leftWheelOvercurrent ()) ? "true" : "false")
00340       << " right wheel: "
00341       << ((!!robot_.rightWheelOvercurrent ()) ? "true" : "false")
00342       << " LD2: " << ((!!robot_.ld2Overcurrent ()) ? "true" : "false")
00343       << " LD1: " << ((!!robot_.ld1Overcurrent ()) ? "true" : "false")
00344       << " LD0: " << ((!!robot_.ld0Overcurrent ()) ? "true" : "false");
00345 
00346     std::cerr
00347       << "IR: " << robot_.ir () << std::endl;
00348 
00349     std::cerr
00350       << "Buttons: "
00351       << " advance: "<< ((!!robot_.advanceButton ()) ? "true" : "false")
00352       << " play: " << ((!!robot_.playButton ()) ? "true" : "false") << std::endl;
00353 
00354     std::cerr
00355       << "Distance: " << robot_.distance () << std::endl;
00356 
00357     std::cerr
00358       << "Angle: " << robot_.angle () << std::endl;
00359 
00360     std::cerr
00361       << "Charging state: " << robot_.chargingState () << std::endl;
00362 
00363     std::cerr
00364       << "Battery voltage: " << robot_.batteryVoltage () << std::endl;
00365 
00366     std::cerr
00367       << "Battery current: " << robot_.batteryCurrent () << std::endl;
00368 
00369     std::cerr
00370       << "Battery temperature: " << robot_.batteryTemperature () << std::endl;
00371 
00372     std::cerr
00373       << "Battery charge: " << robot_.batteryCharge () << std::endl;
00374 
00375     std::cerr
00376       << "Battery capacity: " << robot_.batteryCapacity () << std::endl;
00377 
00378     std::cerr
00379       << "Wall signal: " << robot_.wallSignal () << std::endl;
00380 
00381     std::cerr
00382       << "Cliff left signal: "
00383       << robot_.cliffLeftSignal () << std::endl;
00384 
00385     std::cerr
00386       << "Cliff front-left signal: "
00387       << robot_.cliffFrontLeftSignal () << std::endl;
00388 
00389     std::cerr
00390       << "Cliff front-right signal: "
00391       << robot_.cliffFrontRightSignal () << std::endl;
00392 
00393     std::cerr
00394       << "Cliff right signal: " << robot_.cliffRightSignal () << std::endl;
00395 
00396     std::cerr
00397       << "Song number: " << static_cast<int> (robot_.songNumber ())
00398       << std::endl;
00399 
00400     std::cerr
00401       << "Song playing: "
00402       << ((!!robot_.songPlaying ()) ? "true" : "false") << std::endl;
00403 
00404     std::cerr
00405       << "Streamed packets: " << robot_.streamPackets () << std::endl;
00406 
00407     std::cerr
00408       << "Requested velocty: "
00409       << robot_.requestedVelocity () << std::endl;
00410 
00411     std::cerr
00412       << "Request radius: "
00413       << robot_.requestedRadius () << std::endl;
00414 
00415     std::cerr
00416       << "Request left velocity: "
00417       << robot_.requestedLeftVelocity () << std::endl;
00418 
00419     std::cerr
00420       << "Request right velocity: "
00421       << robot_.requestedRightVelocity () << std::endl;
00422 
00423   }

void Application::usage (  )  [inline]

00426   {
00427     help (1);
00428   }

void Application::version (  )  [inline]

00431   {
00432     std::cerr
00433       << PACKAGE_STRING << std::endl
00434       << "Copyright (C) 2008  iLab."
00435       << std::endl
00436       << "This is free software; see the source for copying conditions."
00437       << std::endl
00438       << "There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A"
00439       << std::endl
00440       << "PARTICULAR PURPOSE." << std::endl;
00441     exit (0);
00442   }


The documentation for this struct was generated from the following files:
Generated on Thu Aug 28 13:54:20 2008 for iRobot Create library by  doxygen 1.5.4