create_demo.cpp
Go to the documentation of this file.
00001 #include "create/create.h"
00002 
00003 create::Create* robot;
00004 
00005 int main(int argc, char** argv) {
00006   std::string port = "/dev/ttyUSB0";
00007   int baud = 115200;
00008   create::RobotModel model = create::RobotModel::CREATE_2;
00009 
00010   if (argc > 1 && std::string(argv[1]) == "create1") {
00011     model = create::RobotModel::CREATE_1;
00012     baud = 57600;
00013     std::cout << "1st generation Create selected" << std::endl;
00014   }
00015 
00016   robot = new create::Create(model);
00017 
00018   // Attempt to connect to Create
00019   if (robot->connect(port, baud))
00020     std::cout << "Successfully connected to Create" << std::endl;
00021   else {
00022     std::cout << "Failed to connect to Create on port " << port.c_str() << std::endl;
00023     return 1;
00024   }
00025 
00026   // Note: Some functionality does not work as expected in Safe mode
00027   robot->setMode(create::MODE_FULL);
00028 
00029   std::cout << "battery level: " <<
00030     robot->getBatteryCharge() / (float) robot->getBatteryCapacity() * 100.0 << "%" << std::endl;
00031 
00032   bool drive = false;
00033 
00034   // Make a song
00035   //uint8_t songLength = 16;
00036   //uint8_t notes[16] = { 67, 67, 66, 66, 65, 65, 66, 66,
00037   //                      67, 67, 66, 66, 65, 65, 66, 66 };
00038   //float durations[songLength];
00039   //for (int i = 0; i < songLength; i++) {
00040   //  durations[i] = 0.25;
00041   //}
00042   //robot->defineSong(0, songLength, notes, durations);
00043   //usleep(1000000);
00044   //robot->playSong(0);
00045 
00046   // Quit when center "Clean" button pressed
00047   while (!robot->isCleanButtonPressed()) {
00048     // Check for button presses
00049     if (robot->isDayButtonPressed())
00050       std::cout << "day button press" << std::endl;
00051     if (robot->isMinButtonPressed())
00052       std::cout << "min button press" << std::endl;
00053     if (robot->isDockButtonPressed()) {
00054       std::cout << "dock button press" << std::endl;
00055       robot->enableCheckRobotLED(false);
00056     }
00057     if (robot->isSpotButtonPressed()) {
00058       std::cout << "spot button press" << std::endl;
00059       robot->enableCheckRobotLED(true);
00060     }
00061     if (robot->isHourButtonPressed()) {
00062       std::cout << "hour button press" << std::endl;
00063       drive = !drive;
00064     }
00065 
00066     // Check for wheeldrop or cliffs
00067     if (robot->isWheeldrop() || robot->isCliff()) {
00068       drive = false;
00069       robot->setPowerLED(255);
00070     }
00071 
00072     // If everything is ok, drive forward using IR's to avoid obstacles
00073     if (drive) {
00074       robot->setPowerLED(0); // green
00075       if (robot->isLightBumperLeft() ||
00076           robot->isLightBumperFrontLeft() ||
00077           robot->isLightBumperCenterLeft()) {
00078         // turn right
00079         robot->drive(0.1, -1.0);
00080         robot->setDigitsASCII('-','-','-',']');
00081       }
00082       else if (robot->isLightBumperRight() ||
00083                robot->isLightBumperFrontRight() ||
00084                robot->isLightBumperCenterRight()) {
00085         // turn left
00086         robot->drive(0.1, 1.0);
00087         robot->setDigitsASCII('[','-','-','-');
00088       }
00089       else {
00090         // drive straight
00091         robot->drive(0.1, 0.0);
00092         robot->setDigitsASCII(' ','^','^',' ');
00093       }
00094     }
00095     else { // drive == false
00096       // stop moving
00097       robot->drive(0, 0);
00098       robot->setDigitsASCII('S','T','O','P');
00099     }
00100 
00101     // Turn on blue 'debris' light if moving forward
00102     if (robot->isMovingForward()) {
00103       robot->enableDebrisLED(true);
00104     }
00105     else {
00106       robot->enableDebrisLED(false);
00107     }
00108 
00109     // Check bumpers
00110     if (robot->isLeftBumper()) {
00111       std::cout << "left bump detected!" << std::endl;
00112     }
00113     if (robot->isRightBumper()) {
00114       std::cout << "right bump detected!" << std::endl;
00115     }
00116 
00117     usleep(1000 * 100); //10hz
00118   }
00119 
00120   std::cout << "Stopping Create." << std::endl;
00121 
00122   // Turn off lights
00123   robot->setPowerLED(0, 0);
00124   robot->enableDebrisLED(false);
00125   robot->enableCheckRobotLED(false);
00126   robot->setDigitsASCII(' ', ' ', ' ', ' ');
00127 
00128   // Make sure to disconnect to clean up
00129   robot->disconnect();
00130   delete robot;
00131 
00132   return 0;
00133 }


libcreate
Author(s): Jacob Perron
autogenerated on Sat Nov 26 2016 03:41:46