drive_circle.cpp
Go to the documentation of this file.
1 
31 #include "create/create.h"
32 
33 #include <iomanip>
34 #include <iostream>
35 
36 int main(int argc, char** argv) {
37  // Select robot. Assume Create 2 unless argument says otherwise
39  std::string port = "/dev/ttyUSB0";
40  int baud = 115200;
41  if (argc > 1 && std::string(argv[1]) == "create1") {
43  baud = 57600;
44  std::cout << "Running driver for Create 1" << std::endl;
45  }
46  else {
47  std::cout << "Running driver for Create 2" << std::endl;
48  }
49 
50  // Construct robot object
51  create::Create* robot = new create::Create(model);
52 
53  // Connect to robot
54  if (robot->connect(port, baud))
55  std::cout << "Connected to robot" << std::endl;
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
62  robot->setMode(create::MODE_FULL);
63 
64  std::cout << std::endl << "Press center 'Clean' button to disconnect and end program" << std::endl;
65 
66  // There's a delay between switching modes and when the robot will accept drive commands
67  usleep(100000);
68 
69  // Command robot to drive a radius of 0.15 metres at 0.2 m/s
70  robot->driveRadius(0.2, 0.15);
71 
72  while (!robot->isCleanButtonPressed()) {
73  // Get robot odometry and print
74  const create::Pose pose = robot->getPose();
75 
76  std::cout << std::fixed << std::setprecision(2) << "\rOdometry (x, y, yaw): ("
77  << pose.x << ", " << pose.y << ", " << pose.yaw << ") ";
78 
79  usleep(10000); // 10 Hz
80  }
81 
82  std::cout << std::endl;
83 
84  // Call disconnect to avoid leaving robot in Full mode
85  // Also, this consequently stops the robot from moving
86  robot->disconnect();
87 
88  // Clean up
89  delete robot;
90 
91  std::cout << "Bye!" << std::endl;
92  return 0;
93 }
float y
Definition: types.h:277
static RobotModel CREATE_1
Compatible with Create 1 or Roomba 500 series.
Definition: types.h:68
float yaw
Definition: types.h:278
create::Pose getPose() const
Get the estimated pose of Create based on wheel encoders.
Definition: create.cpp:1004
Represents a robot pose.
Definition: types.h:275
bool driveRadius(const float &velocity, const float &radius)
Set the average wheel velocity and turning radius of Create.
Definition: create.cpp:358
bool isCleanButtonPressed() const
Get state of &#39;clean&#39; button (&#39;play&#39; button on Create 1).
Definition: create.cpp:709
float x
Definition: types.h:276
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)
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