00001 #include <iostream> 00002 00003 #include <signal.h> 00004 00005 #include <RFlex.H> 00006 00007 00008 using namespace std; 00009 00010 00011 void button(const int number) {cout << "Button: " << number << endl;} 00012 void axis(const int number) {cout << "Axis: " << number << endl;} 00013 00014 00015 int main() { 00016 #ifdef B21 00017 RFlex rflex("/dev/ttyR0"); 00018 #endif 00019 00020 #ifdef ATRV 00021 RFlex rflex("/dev/ttyS0"); 00022 #endif 00023 00024 bool sonars = false; 00025 bool brake = false; 00026 00027 double velocity; 00028 00029 char ch = 'a'; 00030 while (ch != 'q') { 00031 cout << "\nRequest? " << flush; 00032 cin >> ch; 00033 00034 switch (ch) { 00035 case 's': 00036 sonars = !sonars; 00037 cout << "Sonars "; 00038 if (sonars) { 00039 cout << "on" << endl; 00040 rflex.sonarOn(); 00041 } else { 00042 cout << "off" << endl; 00043 rflex.sonarOff(); 00044 } 00045 break; 00046 00047 case 'b': 00048 brake = !brake; 00049 cout << "Brake "; 00050 if (brake) { 00051 cout << "on"; 00052 rflex.brakeOn(); 00053 } else { 00054 cout << "off"; 00055 rflex.brakeOff(); 00056 } 00057 break; 00058 00059 case 'r': 00060 cin >> velocity; 00061 rflex.motorSetRotateVelocity(velocity); 00062 cout << "Rotate at " << velocity << " radians/sec" << endl; 00063 break; 00064 00065 case 't': 00066 cin >> velocity; 00067 rflex.motorSetTranslateVelocity(velocity); 00068 cout << "Translate at " << velocity << " metres/sec" << endl; 00069 break; 00070 00071 case '0': 00072 cout << "Stopping motion" << endl; 00073 rflex.motorSetRotateVelocity(0.0); 00074 rflex.motorSetTranslateVelocity(0.0); 00075 break; 00076 00077 case 'd': 00078 cout << "Odometry: (" << rflex.x() << ", " << rflex.y() << ") at " << rflex.heading() << " radians" << endl; 00079 cout << "Brake: " << ((rflex.brakeOn())?("on"):("off")) << endl; 00080 cout << "Battery voltage: " << rflex.batteryVoltage() << endl; 00081 cout << "Translate:\n velocity: " << rflex.translateVelocity() << "\n acceleration: " << rflex.translateAcceleration() << "\n torque: " << rflex.translateTorque() << endl; 00082 cout << "Rotate:\n velocity: " << rflex.rotateVelocity() << "\n acceleration: " << rflex.rotateAcceleration() << "\n torque: " << rflex.rotateTorque() << endl; 00083 00084 case 'q': 00085 break; 00086 00087 default: 00088 cerr << "Unknown request: " << ch << endl; 00089 break; 00090 } 00091 } 00092 00093 return 0; 00094 }