bumper_example.cpp
Go to the documentation of this file.
00001 #include "create/create.h"
00002 
00003 int main(int argc, char** argv) {
00004   std::string port = "/dev/ttyUSB0";
00005   int baud = 115200;
00006   create::RobotModel model = create::RobotModel::CREATE_2;
00007 
00008   create::Create* robot = new create::Create(model);
00009 
00010   // Attempt to connect to Create
00011   if (robot->connect(port, baud))
00012     std::cout << "Successfully connected to Create" << std::endl;
00013   else {
00014     std::cout << "Failed to connect to Create on port " << port.c_str() << std::endl;
00015     return 1;
00016   }
00017 
00018   robot->setMode(create::MODE_FULL);
00019 
00020   uint16_t signals[6];
00021   bool contact_bumpers[2];
00022   bool light_bumpers[6];
00023 
00024   // Stop program when clean button is pressed
00025   while (!robot->isCleanButtonPressed()) {
00026     signals[0] = robot->getLightSignalLeft();
00027     signals[1] = robot->getLightSignalFrontLeft();
00028     signals[2] = robot->getLightSignalCenterLeft();
00029     signals[3] = robot->getLightSignalCenterRight();
00030     signals[4] = robot->getLightSignalFrontRight();
00031     signals[5] = robot->getLightSignalRight();
00032 
00033     contact_bumpers[0] = robot->isLeftBumper();
00034     contact_bumpers[1] = robot->isRightBumper();
00035 
00036     light_bumpers[0] = robot->isLightBumperLeft();
00037     light_bumpers[1] = robot->isLightBumperFrontLeft();
00038     light_bumpers[2] = robot->isLightBumperCenterLeft();
00039     light_bumpers[3] = robot->isLightBumperCenterRight();
00040     light_bumpers[4] = robot->isLightBumperFrontRight();
00041     light_bumpers[5] = robot->isLightBumperRight();
00042 
00043     // print signals from left to right
00044     std::cout << "[ " << signals[0] << " , "
00045                       << signals[1] << " , "
00046                       << signals[2] << " , "
00047                       << signals[3] << " , "
00048                       << signals[4] << " , "
00049                       << signals[5]
00050               << " ]" << std::endl;
00051     std::cout << "[ " << light_bumpers[0] << " , "
00052                       << light_bumpers[1] << " , "
00053                       << light_bumpers[2] << " , "
00054                       << light_bumpers[3] << " , "
00055                       << light_bumpers[4] << " , "
00056                       << light_bumpers[5]
00057               << " ]" << std::endl;
00058     std::cout << "[ " << contact_bumpers[0] << " , "
00059                       << contact_bumpers[1]
00060               << " ]" << std::endl;
00061     std::cout << std::endl;
00062 
00063     usleep(1000 * 100); //10hz
00064   }
00065 
00066   std::cout << "Stopping Create" << std::endl;
00067 
00068   // Disconnect from robot
00069   robot->disconnect();
00070   delete robot;
00071 
00072   return 0;
00073 }


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