leds.cpp
Go to the documentation of this file.
00001 
00031 #include "create/create.h"
00032 
00033 #include <iostream>
00034 
00035 int main(int argc, char** argv) {
00036   // Select robot. Assume Create 2 unless argument says otherwise
00037   create::RobotModel model = create::RobotModel::CREATE_2;
00038   std::string port = "/dev/ttyUSB0";
00039   int baud = 115200;
00040   if (argc > 1 && std::string(argv[1]) == "create1") {
00041     model = create::RobotModel::CREATE_1;
00042     baud = 57600;
00043     std::cout << "Running driver for Create 1" << std::endl;
00044   }
00045   else {
00046     std::cout << "Running driver for Create 2" << std::endl;
00047   }
00048 
00049   // Construct robot object
00050   create::Create* robot = new create::Create(model);
00051 
00052   // Connect to robot
00053   if (robot->connect(port, baud))
00054     std::cout << "Connected to robot" << std::endl;
00055   else {
00056     std::cout << "Failed to connect to robot on port " << port.c_str() << std::endl;
00057     return 1;
00058   }
00059 
00060   // Switch to Full mode
00061   robot->setMode(create::MODE_FULL);
00062 
00063   std::cout << std::endl << "Press center 'Clean' button to disconnect and end program" << std::endl;
00064 
00065   bool enable_check_robot_led = true;
00066   bool enable_debris_led = false;
00067   bool enable_dock_led = true;
00068   bool enable_spot_led = false;
00069   uint8_t power_led = 0; 
00070   char digit_buffer[5];
00071 
00072   while (!robot->isCleanButtonPressed()) {
00073     // Set LEDs
00074     robot->enableCheckRobotLED(enable_check_robot_led);
00075     robot->enableDebrisLED(enable_debris_led);
00076     robot->enableDockLED(enable_dock_led);
00077     robot->enableSpotLED(enable_spot_led);
00078     robot->setPowerLED(power_led);
00079 
00080     // Set 7-segment displays
00081     const int len = sprintf(digit_buffer, "%d", power_led);
00082     for (int i = len; i < 4; i++) digit_buffer[i] = ' ';
00083     robot->setDigitsASCII(digit_buffer[0], digit_buffer[1], digit_buffer[2], digit_buffer[3]);
00084 
00085     // Update LED values
00086     enable_check_robot_led = !enable_check_robot_led;
00087     enable_debris_led = !enable_debris_led;
00088     enable_dock_led = !enable_dock_led;
00089     enable_spot_led = !enable_spot_led;
00090     power_led++;
00091 
00092     usleep(250000);  // 5 Hz
00093   }
00094 
00095   std::cout << std::endl;
00096 
00097   // Call disconnect to avoid leaving robot in Full mode
00098   robot->disconnect();
00099 
00100   // Clean up
00101   delete robot;
00102 
00103   std::cout << "Bye!" << std::endl;
00104   return 0;
00105 }


libcreate
Author(s): Jacob Perron
autogenerated on Thu Jun 6 2019 21:02:06