test_manual_base_motors.cpp
Go to the documentation of this file.
00001 
00024 #include "base_motor_driver.h"
00025 #include <iostream>
00026 
00027 using namespace std;
00028 
00029 int menu()
00030 {
00031     int option = -1;
00032 
00033     cout << "1.  Set velocities" << endl;
00034     cout << "2.  Print data" << endl;
00035     cout << "3.  Move ahead a distance" << endl;
00036     cout << "4.  Turn an angle" << endl;
00037     cout << "5.  Move a distance" << endl;
00038     cout << "6.  Reset odometry" << endl;
00039     cout << "7.  Update odometry" << endl;
00040     cout << "8.  Enable motors" << endl;
00041     cout << "9.  Disable motors" << endl;
00042     cout << "10. Set estimate position" << endl;
00043     cout << "11. Get estimate position" << endl;
00044     cout << "0.  Quit" << endl;
00045 
00046     cout << "Choose option: " << endl;
00047     cin >> option;
00048 
00049     return option;
00050 }
00051 
00052 int main()
00053 {
00054     BaseMotor bm;
00055 
00056     double x = 1000, y = 0, theta = 0;
00057     int linear_velocity = 0, angular_velocity = 0, distance = 0, angle = 0;
00058     cinematic_data *data;
00059 
00060     bm.init_communication();
00061 
00062     int option = -1;
00063     do {
00064         option = menu();
00065 
00066         switch(option) {
00067             case 1:
00068                 cout << "Set linear velocity (degrees/sec): " << endl;
00069                 cin >> linear_velocity;
00070 
00071                 cout << "Set angular velocity (degrees/sec): " << endl;
00072                 cin >> angular_velocity;
00073 
00074                 if (bm.set_velocity(linear_velocity, angular_velocity) == 0) {
00075                     cout << "OK" << endl;
00076                 }
00077                 else {
00078                     cout << "ERROR" << endl;
00079                 }
00080                 break;
00081 
00082             case 2:
00083                 if (bm.read_data(data) == 0) {
00084                     cout << "Linear velocity: " << data->v << endl;
00085                     cout << "Angular velocity: " << data->w << endl;
00086                     cout << "X position: " << data->x << endl;
00087                     cout << "Y position: " << data->y << endl;
00088                     cout << "Theta: " << data->theta << endl;
00089                 }
00090                 else {
00091                     cout << "ERROR" << endl;
00092                 }
00093                 break;
00094 
00095             case 3:
00096                 cout << "Set distance (mm) to move ahead: " << endl;
00097                 cin >> distance;
00098 
00099                 if (bm.move_ahead(distance) == 0) {
00100                     cout << "OK" << endl;
00101 
00102                 }
00103                 else {
00104                     cout << "ERROR" << endl;
00105                 }
00106                 break;
00107 
00108             case 4:
00109                 cout << "Set angle to turn: " << endl;
00110                 cin >> angle;
00111 
00112                 if (bm.relative_turn(angle) == 0) {
00113                     cout << "OK" << endl;
00114                 }
00115                 else {
00116                     cout << "ERROR" << endl;
00117                 }
00118                 break;
00119 
00120             case 5:
00121                 cout << "Set linear velocity (mm/sec): " << endl;
00122                 cin >> linear_velocity;
00123 
00124                 cout << "Set angular velocity (degrees/sec): " << endl;
00125                 cin >> angular_velocity;
00126 
00127                 cout << "Set distance to move (mm): " << endl;
00128                 cin >> distance;
00129 
00130                 if (bm.set_displacement_velocity(distance, linear_velocity, angular_velocity) == 0) {
00131                     cout << "OK" << endl;
00132                 }
00133                 else {
00134                     cout << "ERROR" << endl;
00135                 }
00136                 break;
00137 
00138             case 6:
00139                 bm.reset_odometry();
00140                 break;
00141 
00142             case 7:
00143                 cout << "x: " << endl;
00144                 cin >> x;
00145                 cout << "y: " << endl;
00146                 cin >> y;
00147                 cout << "theta: " << endl;
00148                 cin >> theta;
00149 
00150                 bm.update_odometry(x, y, theta);
00151                 break;
00152 
00153             case 8:
00154                 if (bm.enable_motors()) {
00155                     cout << "ERROR" << endl;
00156                 }
00157                 break;
00158 
00159             case 9:
00160                 if (bm.disable_motors()) {
00161                     cout << "ERROR" << endl;
00162                 }
00163                 break;
00164 
00165             case 10:
00166                 x = 0;
00167                 y = 0;
00168                 theta = 0;
00169 
00170                 cout << "x: " << endl;
00171                 cin >> x;
00172                 cout << "y: " << endl;
00173                 cin >> y;
00174                 cout << "theta: " << endl;
00175                 cin >> theta;
00176 
00177                 bm.set_estimate_position(x, y, theta);
00178                 break;
00179 
00180             case 11:
00181                 data = bm.get_estimate_position();
00182 
00183                 cout << "Velocidad Lineal: " << data->v << endl;
00184                 cout << "Velocidad Angular: " << data->w << endl;
00185                 cout << "Posicion estimada x: " << data->x << endl;
00186                 cout << "Posicion estimada y: " << data->y << endl;
00187                 cout << "Posicion angular estimada : " << data->theta << endl;
00188                 break;
00189         }
00190     }
00191     while(option != 0);
00192 
00193     bm.end_communication();
00194 
00195     return 0;
00196 }


maggie_base
Author(s): Raul Perula-Martinez
autogenerated on Thu Apr 23 2015 22:19:14