drive_circle.cpp
Go to the documentation of this file.
00001 
00031 #include "create/create.h"
00032 
00033 #include <iomanip>
00034 #include <iostream>
00035 
00036 int main(int argc, char** argv) {
00037   // Select robot. Assume Create 2 unless argument says otherwise
00038   create::RobotModel model = create::RobotModel::CREATE_2;
00039   std::string port = "/dev/ttyUSB0";
00040   int baud = 115200;
00041   if (argc > 1 && std::string(argv[1]) == "create1") {
00042     model = create::RobotModel::CREATE_1;
00043     baud = 57600;
00044     std::cout << "Running driver for Create 1" << std::endl;
00045   }
00046   else {
00047     std::cout << "Running driver for Create 2" << std::endl;
00048   }
00049 
00050   // Construct robot object
00051   create::Create* robot = new create::Create(model);
00052 
00053   // Connect to robot
00054   if (robot->connect(port, baud))
00055     std::cout << "Connected to robot" << std::endl;
00056   else {
00057     std::cout << "Failed to connect to robot on port " << port.c_str() << std::endl;
00058     return 1;
00059   }
00060 
00061   // Switch to Full mode
00062   robot->setMode(create::MODE_FULL);
00063 
00064   std::cout << std::endl << "Press center 'Clean' button to disconnect and end program" << std::endl;
00065 
00066   // There's a delay between switching modes and when the robot will accept drive commands
00067   usleep(100000);
00068 
00069   // Command robot to drive a radius of 0.15 metres at 0.2 m/s
00070   robot->driveRadius(0.2, 0.15);
00071 
00072   while (!robot->isCleanButtonPressed()) {
00073     // Get robot odometry and print
00074     const create::Pose pose = robot->getPose(); 
00075 
00076     std::cout << std::fixed << std::setprecision(2) << "\rOdometry (x, y, yaw): ("
00077               << pose.x << ", " << pose.y << ", " << pose.yaw << ")      ";
00078 
00079     usleep(10000);  // 10 Hz
00080   }
00081 
00082   std::cout << std::endl;
00083 
00084   // Call disconnect to avoid leaving robot in Full mode
00085   // Also, this consequently stops the robot from moving
00086   robot->disconnect();
00087 
00088   // Clean up
00089   delete robot;
00090 
00091   std::cout << "Bye!" << std::endl;
00092   return 0;
00093 }


libcreate
Author(s): Jacob Perron
autogenerated on Thu Jun 6 2019 21:02:06