00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #include "Aria.h"
00027
00048 ArActionGroup *teleop;
00049 ArActionGroup *wander;
00050
00051
00052
00053 void teleopMode(void)
00054 {
00055 teleop->activateExclusive();
00056 printf("\n== Teleoperation Mode ==\n");
00057 printf(" Use the arrow keys to drive, and the spacebar to stop.\n For joystick control hold the trigger button.\n Press 'w' to switch to wander mode.\n Press escape to exit.\n");
00058 }
00059
00060
00061
00062 void wanderMode(void)
00063 {
00064 wander->activateExclusive();
00065 printf("\n== Wander Mode ==\n");
00066 printf(" The robot will now just wander around avoiding things.\n Press 't' to switch to teleop mode.\n Press escape to exit.\n");
00067 }
00068
00069
00070 int main(int argc, char** argv)
00071 {
00072 Aria::init();
00073 ArArgumentParser argParser(&argc, argv);
00074 ArSimpleConnector con(&argParser);
00075 ArRobot robot;
00076 ArSonarDevice sonar;
00077
00078 argParser.loadDefaultArguments();
00079 if(!Aria::parseArgs() || !argParser.checkHelpAndWarnUnparsed())
00080 {
00081 Aria::logOptions();
00082 return 1;
00083 }
00084
00085
00086 teleop = new ArActionGroup(&robot);
00087
00088
00089 teleop->addAction(new ArActionLimiterTableSensor, 100);
00090
00091
00092 teleop->addAction(new ArActionLimiterForwards("speed limiter near",
00093 300, 600, 250), 95);
00094
00095
00096 teleop->addAction(new ArActionLimiterForwards("speed limiter far",
00097 300, 1100, 400), 90);
00098
00099
00100 teleop->addAction(new ArActionLimiterBackwards, 85);
00101
00102
00103 ArActionJoydrive joydriveAct("joydrive", 400, 15);
00104 teleop->addAction(&joydriveAct, 50);
00105
00106
00107 teleop->addAction(new ArActionKeydrive, 45);
00108
00109
00110
00111
00112 wander = new ArActionGroup(&robot);
00113
00114
00115 wander->addAction(new ArActionStallRecover, 100);
00116
00117
00118 wander->addAction(new ArActionBumpers, 75);
00119
00120
00121 wander->addAction(new ArActionAvoidFront("Avoid Front Near", 225, 0), 50);
00122
00123
00124 wander->addAction(new ArActionAvoidFront, 45);
00125
00126
00127 wander->addAction(new ArActionConstantVelocity("Constant Velocity", 400), 25);
00128
00129
00130
00131
00132
00133
00134
00135 ArKeyHandler *keyHandler = Aria::getKeyHandler();
00136 if (keyHandler == NULL)
00137 {
00138 keyHandler = new ArKeyHandler;
00139 Aria::setKeyHandler(keyHandler);
00140 robot.attachKeyHandler(keyHandler);
00141 }
00142
00143
00144 ArGlobalFunctor teleopCB(&teleopMode);
00145 ArGlobalFunctor wanderCB(&wanderMode);
00146 keyHandler->addKeyHandler('w', &wanderCB);
00147 keyHandler->addKeyHandler('W', &wanderCB);
00148 keyHandler->addKeyHandler('t', &teleopCB);
00149 keyHandler->addKeyHandler('T', &teleopCB);
00150
00151
00152 if (!joydriveAct.joystickInited())
00153 printf("Note: Do not have a joystick, only the arrow keys on the keyboard will work.\n");
00154
00155
00156 joydriveAct.setStopIfNoButtonPressed(false);
00157
00158
00159
00160
00161 robot.addRangeDevice(&sonar);
00162 if(!con.connectRobot(&robot))
00163 {
00164 ArLog::log(ArLog::Terse, "actionGroupExample: Could not connect to the robot.");
00165 Aria::shutdown();
00166 return 1;
00167 }
00168
00169 robot.enableMotors();
00170 teleopMode();
00171 robot.run(true);
00172
00173 Aria::shutdown();
00174 return 0;
00175 }