bumpers.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  uint16_t light_signals[6];
66  bool light_bumpers[6];
67  bool contact_bumpers[2];
68 
69  while (!robot->isCleanButtonPressed()) {
70  // Get light sensor data (only available for Create 2 or later robots)
71  if (model == create::RobotModel::CREATE_2) {
72  // Get raw light signal values
73  light_signals[0] = robot->getLightSignalLeft();
74  light_signals[1] = robot->getLightSignalFrontLeft();
75  light_signals[2] = robot->getLightSignalCenterLeft();
76  light_signals[3] = robot->getLightSignalCenterRight();
77  light_signals[4] = robot->getLightSignalFrontRight();
78  light_signals[5] = robot->getLightSignalRight();
79 
80  // Get obstacle data from light sensors (true/false)
81  light_bumpers[0] = robot->isLightBumperLeft();
82  light_bumpers[1] = robot->isLightBumperFrontLeft();
83  light_bumpers[2] = robot->isLightBumperCenterLeft();
84  light_bumpers[3] = robot->isLightBumperCenterRight();
85  light_bumpers[4] = robot->isLightBumperFrontRight();
86  light_bumpers[5] = robot->isLightBumperRight();
87  }
88 
89  // Get state of bumpers
90  contact_bumpers[0] = robot->isLeftBumper();
91  contact_bumpers[1] = robot->isRightBumper();
92 
93  // Print signals from left to right
94  std::cout << "[ " << light_signals[0] << " , "
95  << light_signals[1] << " , "
96  << light_signals[2] << " , "
97  << light_signals[3] << " , "
98  << light_signals[4] << " , "
99  << light_signals[5]
100  << " ]" << std::endl;
101  std::cout << "[ " << light_bumpers[0] << " , "
102  << light_bumpers[1] << " , "
103  << light_bumpers[2] << " , "
104  << light_bumpers[3] << " , "
105  << light_bumpers[4] << " , "
106  << light_bumpers[5]
107  << " ]" << std::endl;
108  std::cout << "[ " << contact_bumpers[0] << " , "
109  << contact_bumpers[1]
110  << " ]" << std::endl;
111  std::cout << std::endl;
112 
113  usleep(100000); // 10 Hz
114  }
115 
116  std::cout << std::endl;
117 
118  // Call disconnect to avoid leaving robot in Full mode
119  robot->disconnect();
120 
121  // Clean up
122  delete robot;
123 
124  std::cout << "Bye!" << std::endl;
125  return 0;
126 }
bool isLightBumperFrontLeft() const
Definition: create.cpp:853
static RobotModel CREATE_1
Compatible with Create 1 or Roomba 500 series.
Definition: types.h:68
bool isLeftBumper() const
Definition: create.cpp:600
uint16_t getLightSignalFrontLeft() const
Get the signal strength from the front-left light sensor.
Definition: create.cpp:913
bool isLightBumperCenterRight() const
Definition: create.cpp:873
bool isLightBumperFrontRight() const
Definition: create.cpp:883
int main(int argc, char **argv)
Definition: bumpers.cpp:35
uint16_t getLightSignalCenterLeft() const
Get the signal strength from the center-left light sensor.
Definition: create.cpp:923
bool isLightBumperLeft() const
Definition: create.cpp:843
bool isCleanButtonPressed() const
Get state of &#39;clean&#39; button (&#39;play&#39; button on Create 1).
Definition: create.cpp:709
uint16_t getLightSignalLeft() const
Get the signal strength from the left light sensor.
Definition: create.cpp:903
bool isRightBumper() const
Definition: create.cpp:610
uint16_t getLightSignalCenterRight() const
Get the signal strength from the center-right light sensor.
Definition: create.cpp:953
uint16_t getLightSignalRight() const
Get the signal strength from the right light sensor.
Definition: create.cpp:933
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
bool isLightBumperRight() const
Definition: create.cpp:893
bool isLightBumperCenterLeft() const
Definition: create.cpp:863
uint16_t getLightSignalFrontRight() const
Get the signal strength from the front-right light sensor.
Definition: create.cpp:943


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