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(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  uint16_t light_signals[6] = {0, 0, 0, 0, 0, 0};
64  bool light_bumpers[6] = {false, false, false, false, false, false};
65  bool contact_bumpers[2] = {false, false};
66 
67  while (true) {
68  // Get light sensor data (only available for Create 2 or later robots)
69  if (model == create::RobotModel::CREATE_2) {
70  // Get raw light signal values
71  light_signals[0] = robot.getLightSignalLeft();
72  light_signals[1] = robot.getLightSignalFrontLeft();
73  light_signals[2] = robot.getLightSignalCenterLeft();
74  light_signals[3] = robot.getLightSignalCenterRight();
75  light_signals[4] = robot.getLightSignalFrontRight();
76  light_signals[5] = robot.getLightSignalRight();
77 
78  // Get obstacle data from light sensors (true/false)
79  light_bumpers[0] = robot.isLightBumperLeft();
80  light_bumpers[1] = robot.isLightBumperFrontLeft();
81  light_bumpers[2] = robot.isLightBumperCenterLeft();
82  light_bumpers[3] = robot.isLightBumperCenterRight();
83  light_bumpers[4] = robot.isLightBumperFrontRight();
84  light_bumpers[5] = robot.isLightBumperRight();
85  }
86 
87  // Get state of bumpers
88  contact_bumpers[0] = robot.isLeftBumper();
89  contact_bumpers[1] = robot.isRightBumper();
90 
91  // Print signals from left to right
92  std::cout << "[ " << light_signals[0] << " , "
93  << light_signals[1] << " , "
94  << light_signals[2] << " , "
95  << light_signals[3] << " , "
96  << light_signals[4] << " , "
97  << light_signals[5]
98  << " ]" << std::endl;
99  std::cout << "[ " << light_bumpers[0] << " , "
100  << light_bumpers[1] << " , "
101  << light_bumpers[2] << " , "
102  << light_bumpers[3] << " , "
103  << light_bumpers[4] << " , "
104  << light_bumpers[5]
105  << " ]" << std::endl;
106  std::cout << "[ " << contact_bumpers[0] << " , "
107  << contact_bumpers[1]
108  << " ]" << std::endl;
109  std::cout << std::endl;
110 
111  usleep(100000); // 10 Hz
112  }
113 
114  return 0;
115 }
bool isLightBumperFrontLeft() const
Definition: create.cpp:946
static RobotModel CREATE_1
Compatible with Create 1 or Roomba 500 series.
Definition: types.h:68
bool isLeftBumper() const
Definition: create.cpp:654
uint16_t getLightSignalFrontLeft() const
Get the signal strength from the front-left light sensor.
Definition: create.cpp:1006
bool isLightBumperCenterRight() const
Definition: create.cpp:966
bool isLightBumperFrontRight() const
Definition: create.cpp:976
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:1016
bool isLightBumperLeft() const
Definition: create.cpp:936
uint16_t getLightSignalLeft() const
Get the signal strength from the left light sensor.
Definition: create.cpp:996
bool isRightBumper() const
Definition: create.cpp:664
uint16_t getLightSignalCenterRight() const
Get the signal strength from the center-right light sensor.
Definition: create.cpp:1046
uint16_t getLightSignalRight() const
Get the signal strength from the right light sensor.
Definition: create.cpp:1026
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
bool isLightBumperRight() const
Definition: create.cpp:986
bool isLightBumperCenterLeft() const
Definition: create.cpp:956
uint16_t getLightSignalFrontRight() const
Get the signal strength from the front-right light sensor.
Definition: create.cpp:1036


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