cliffs.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  }
56  else {
57  std::cout << "Failed to connect to robot on port " << port.c_str() << std::endl;
58  return 1;
59  }
60 
61  // Switch to Full mode
63 
64  while (true) {
65  // Get cliff status
66  const bool cliff_left = robot.isCliffLeft();
67  const bool cliff_front_left = robot.isCliffFrontLeft();
68  const bool cliff_front_right = robot.isCliffFrontRight();
69  const bool cliff_right = robot.isCliffRight();
70 
71  // Print status
72  std::cout << "\rCliffs (left to right): [ " <<
73  cliff_left <<
74  ", " <<
75  cliff_front_left <<
76  ", " <<
77  cliff_front_right <<
78  ", " <<
79  cliff_right <<
80  " ]";
81 
82  usleep(10000); // 10 Hz
83  }
84 
85  return 0;
86 }
bool isCliffRight() const
Definition: create.cpp:692
static RobotModel CREATE_1
Compatible with Create 1 or Roomba 500 series.
Definition: types.h:68
bool isCliffFrontRight() const
Definition: create.cpp:702
bool isCliffFrontLeft() const
Definition: create.cpp:682
bool isCliffLeft() const
Definition: create.cpp:672
bool connect(const std::string &port, const int &baud)
Make a serial connection to Create.
Definition: create.cpp:269
static RobotModel CREATE_2
Compatible with Create 2 or Roomba 600 series and greater.
Definition: types.h:73
int main(int argc, char **argv)
Definition: cliffs.cpp:35
bool setMode(const create::CreateMode &mode)
Change Create mode.
Definition: create.cpp:301


libcreate
Author(s): Jacob Perron
autogenerated on Sat Jan 2 2021 04:00:49