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(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
63 
64  // There's a delay between switching modes and when the robot will accept drive commands
65  usleep(100000);
66 
67  // Command robot to drive a radius of 0.15 metres at 0.2 m/s
68  robot.driveRadius(0.2, 0.15);
69 
70  while (true) {
71  // Get robot odometry and print
72  const create::Pose pose = robot.getPose();
73 
74  std::cout << std::fixed << std::setprecision(2) << "\rOdometry (x, y, yaw): ("
75  << pose.x << ", " << pose.y << ", " << pose.yaw << ") ";
76 
77  usleep(10000); // 10 Hz
78  }
79 
80  return 0;
81 }
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:1127
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:379
float x
Definition: types.h:276
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
int main(int argc, char **argv)
bool setMode(const create::CreateMode &mode)
Change Create mode.
Definition: create.cpp:325


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