leds.cpp
Go to the documentation of this file.
1 
31 #include "create/create.h"
32 
33 #include <iostream>
34 
35 int main(int argc, char** argv) {
36  // Select robot. Assume Create 2 unless argument says otherwise
38  std::string port = "/dev/ttyUSB0";
39  int baud = 115200;
40  if (argc > 1 && std::string(argv[1]) == "create1") {
42  baud = 57600;
43  std::cout << "Running driver for Create 1" << std::endl;
44  }
45  else {
46  std::cout << "Running driver for Create 2" << std::endl;
47  }
48 
49  // Construct robot object
50  create::Create* robot = new create::Create(model);
51 
52  // Connect to robot
53  if (robot->connect(port, baud))
54  std::cout << "Connected to robot" << std::endl;
55  else {
56  std::cout << "Failed to connect to robot on port " << port.c_str() << std::endl;
57  return 1;
58  }
59 
60  // Switch to Full mode
61  robot->setMode(create::MODE_FULL);
62 
63  std::cout << std::endl << "Press center 'Clean' button to disconnect and end program" << std::endl;
64 
65  bool enable_check_robot_led = true;
66  bool enable_debris_led = false;
67  bool enable_dock_led = true;
68  bool enable_spot_led = false;
69  uint8_t power_led = 0;
70  char digit_buffer[5];
71 
72  while (!robot->isCleanButtonPressed()) {
73  // Set LEDs
74  robot->enableCheckRobotLED(enable_check_robot_led);
75  robot->enableDebrisLED(enable_debris_led);
76  robot->enableDockLED(enable_dock_led);
77  robot->enableSpotLED(enable_spot_led);
78  robot->setPowerLED(power_led);
79 
80  // Set 7-segment displays
81  const int len = sprintf(digit_buffer, "%d", power_led);
82  for (int i = len; i < 4; i++) digit_buffer[i] = ' ';
83  robot->setDigitsASCII(digit_buffer[0], digit_buffer[1], digit_buffer[2], digit_buffer[3]);
84 
85  // Update LED values
86  enable_check_robot_led = !enable_check_robot_led;
87  enable_debris_led = !enable_debris_led;
88  enable_dock_led = !enable_dock_led;
89  enable_spot_led = !enable_spot_led;
90  power_led++;
91 
92  usleep(250000); // 5 Hz
93  }
94 
95  std::cout << std::endl;
96 
97  // Call disconnect to avoid leaving robot in Full mode
98  robot->disconnect();
99 
100  // Clean up
101  delete robot;
102 
103  std::cout << "Bye!" << std::endl;
104  return 0;
105 }
bool setDigitsASCII(const uint8_t &digit1, const uint8_t &digit2, const uint8_t &digit3, const uint8_t &digit4) const
Set the four 7-segment display digits from left to right with ASCII codes. Any code out side the acce...
Definition: create.cpp:542
static RobotModel CREATE_1
Compatible with Create 1 or Roomba 500 series.
Definition: types.h:68
bool enableDockLED(const bool &enable)
Set the green "dock" LED on/off.
Definition: create.cpp:516
bool setPowerLED(const uint8_t &power, const uint8_t &intensity=255)
Set the center power LED.
Definition: create.cpp:532
int main(int argc, char **argv)
Definition: leds.cpp:35
bool enableCheckRobotLED(const bool &enable)
Set the orange "check Create" LED on/off.
Definition: create.cpp:524
bool enableSpotLED(const bool &enable)
Set the green "spot" LED on/off.
Definition: create.cpp:508
bool isCleanButtonPressed() const
Get state of &#39;clean&#39; button (&#39;play&#39; button on Create 1).
Definition: create.cpp:709
bool enableDebrisLED(const bool &enable)
Set the blue "debris" LED on/off.
Definition: create.cpp:500
bool connect(const std::string &port, const int &baud)
Make a serial connection to Create.
Definition: create.cpp:272
static RobotModel CREATE_2
Compatible with Create 2 or Roomba 600 series and greater.
Definition: types.h:73
void disconnect()
Disconnect from serial.
Definition: create.cpp:293
bool setMode(const create::CreateMode &mode)
Change Create mode.
Definition: create.cpp:304


libcreate
Author(s): Jacob Perron
autogenerated on Sat Jun 8 2019 17:58:17