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];
64  bool light_bumpers[6];
65  bool contact_bumpers[2];
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:918
static RobotModel CREATE_1
Compatible with Create 1 or Roomba 500 series.
Definition: types.h:68
bool isLeftBumper() const
Definition: create.cpp:626
uint16_t getLightSignalFrontLeft() const
Get the signal strength from the front-left light sensor.
Definition: create.cpp:978
bool isLightBumperCenterRight() const
Definition: create.cpp:938
bool isLightBumperFrontRight() const
Definition: create.cpp:948
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:988
bool isLightBumperLeft() const
Definition: create.cpp:908
uint16_t getLightSignalLeft() const
Get the signal strength from the left light sensor.
Definition: create.cpp:968
bool isRightBumper() const
Definition: create.cpp:636
uint16_t getLightSignalCenterRight() const
Get the signal strength from the center-right light sensor.
Definition: create.cpp:1018
uint16_t getLightSignalRight() const
Get the signal strength from the right light sensor.
Definition: create.cpp:998
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
bool setMode(const create::CreateMode &mode)
Change Create mode.
Definition: create.cpp:301
bool isLightBumperRight() const
Definition: create.cpp:958
bool isLightBumperCenterLeft() const
Definition: create.cpp:928
uint16_t getLightSignalFrontRight() const
Get the signal strength from the front-right light sensor.
Definition: create.cpp:1008


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