wheeldrop.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  while (!robot->isCleanButtonPressed()) {
66  // Get wheeldrop status
67  const bool wheeldrop = robot->isWheeldrop();
68 
69  // Print status
70  std::cout << "\rWheeldrop status: " << wheeldrop;
71 
72  // If dropped, then make light red
73  if (wheeldrop)
74  robot->setPowerLED(255); // Red
75  else
76  robot->setPowerLED(0); // Green
77 
78  usleep(10000); // 10 Hz
79  }
80 
81  std::cout << std::endl;
82 
83  // Call disconnect to avoid leaving robot in Full mode
84  robot->disconnect();
85 
86  // Clean up
87  delete robot;
88 
89  std::cout << "Bye!" << std::endl;
90  return 0;
91 }
bool isWheeldrop() const
Definition: create.cpp:590
static RobotModel CREATE_1
Compatible with Create 1 or Roomba 500 series.
Definition: types.h:68
bool setPowerLED(const uint8_t &power, const uint8_t &intensity=255)
Set the center power LED.
Definition: create.cpp:532
bool isCleanButtonPressed() const
Get state of &#39;clean&#39; button (&#39;play&#39; button on Create 1).
Definition: create.cpp:709
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
int main(int argc, char **argv)
Definition: wheeldrop.cpp:35
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