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(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
62 
63  bool enable_check_robot_led = true;
64  bool enable_debris_led = false;
65  bool enable_dock_led = true;
66  bool enable_spot_led = false;
67  uint8_t power_led = 0;
68  char digit_buffer[5];
69 
70  while (true) {
71  // Set LEDs
72  robot.enableCheckRobotLED(enable_check_robot_led);
73  robot.enableDebrisLED(enable_debris_led);
74  robot.enableDockLED(enable_dock_led);
75  robot.enableSpotLED(enable_spot_led);
76  robot.setPowerLED(power_led);
77 
78  // Set 7-segment displays
79  const int len = sprintf(digit_buffer, "%d", power_led);
80  for (int i = len; i < 4; i++) digit_buffer[i] = ' ';
81  robot.setDigitsASCII(digit_buffer[0], digit_buffer[1], digit_buffer[2], digit_buffer[3]);
82 
83  // Update LED values
84  enable_check_robot_led = !enable_check_robot_led;
85  enable_debris_led = !enable_debris_led;
86  enable_dock_led = !enable_dock_led;
87  enable_spot_led = !enable_spot_led;
88  power_led++;
89 
90  usleep(250000); // 5 Hz
91  }
92 
93  return 0;
94 }
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:572
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:546
bool setPowerLED(const uint8_t &power, const uint8_t &intensity=255)
Set the center power LED.
Definition: create.cpp:562
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:554
bool enableSpotLED(const bool &enable)
Set the green "spot" LED on/off.
Definition: create.cpp:538
bool enableDebrisLED(const bool &enable)
Set the blue "debris" LED on/off.
Definition: create.cpp:530
bool connect(const std::string &port, const int &baud)
Make a serial connection to Create.
Definition: create.cpp:293
static RobotModel CREATE_2
Compatible with Create 2 or Roomba 600 series and greater.
Definition: types.h:73
bool setMode(const create::CreateMode &mode)
Change Create mode.
Definition: create.cpp:325


libcreate
Author(s): Jacob Perron
autogenerated on Sat May 8 2021 03:02:37