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
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
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
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047 while (!robot->isCleanButtonPressed()) {
00048
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
00067 if (robot->isWheeldrop() || robot->isCliff()) {
00068 drive = false;
00069 robot->setPowerLED(255);
00070 }
00071
00072
00073 if (drive) {
00074 robot->setPowerLED(0);
00075 if (robot->isLightBumperLeft() ||
00076 robot->isLightBumperFrontLeft() ||
00077 robot->isLightBumperCenterLeft()) {
00078
00079 robot->drive(0.1, -1.0);
00080 robot->setDigitsASCII('-','-','-',']');
00081 }
00082 else if (robot->isLightBumperRight() ||
00083 robot->isLightBumperFrontRight() ||
00084 robot->isLightBumperCenterRight()) {
00085
00086 robot->drive(0.1, 1.0);
00087 robot->setDigitsASCII('[','-','-','-');
00088 }
00089 else {
00090
00091 robot->drive(0.1, 0.0);
00092 robot->setDigitsASCII(' ','^','^',' ');
00093 }
00094 }
00095 else {
00096
00097 robot->drive(0, 0);
00098 robot->setDigitsASCII('S','T','O','P');
00099 }
00100
00101
00102 if (robot->isMovingForward()) {
00103 robot->enableDebrisLED(true);
00104 }
00105 else {
00106 robot->enableDebrisLED(false);
00107 }
00108
00109
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);
00118 }
00119
00120 std::cout << "Stopping Create." << std::endl;
00121
00122
00123 robot->setPowerLED(0, 0);
00124 robot->enableDebrisLED(false);
00125 robot->enableCheckRobotLED(false);
00126 robot->setDigitsASCII(' ', ' ', ' ', ' ');
00127
00128
00129 robot->disconnect();
00130 delete robot;
00131
00132 return 0;
00133 }