Press g or G to use ArActionTriangleDriveTo to detect and drive towards a triangular target shape. Press s or S to stop. See ArActionTriangleDriveTo for more information about the triangular target and what the action does and its parameters.
00001 00011 #include "Aria.h" 00012 00013 00014 int main(int argc, char **argv) 00015 { 00016 Aria::init(); 00017 00018 // parse our args and make sure they were all accounted for 00019 ArSimpleConnector connector(&argc, argv); 00020 00021 ArRobot robot; 00022 00023 // the laser. ArActionTriangleDriveTo will use this laser object since it is 00024 // named "laser" when added to the ArRobot. 00025 ArSick sick; 00026 00027 if (!connector.parseArgs() || argc > 1) 00028 { 00029 connector.logOptions(); 00030 exit(1); 00031 } 00032 00033 // a key handler so we can do our key handling 00034 ArKeyHandler keyHandler; 00035 // let the global aria stuff know about it 00036 Aria::setKeyHandler(&keyHandler); 00037 // toss it on the robot 00038 robot.attachKeyHandler(&keyHandler); 00039 00040 // add the laser to the robot 00041 robot.addRangeDevice(&sick); 00042 00043 ArSonarDevice sonar; 00044 robot.addRangeDevice(&sonar); 00045 00046 ArActionTriangleDriveTo triangleDriveTo; 00047 ArFunctorC<ArActionTriangleDriveTo> lineGoCB(&triangleDriveTo, 00048 &ArActionTriangleDriveTo::activate); 00049 keyHandler.addKeyHandler('g', &lineGoCB); 00050 keyHandler.addKeyHandler('G', &lineGoCB); 00051 ArFunctorC<ArActionTriangleDriveTo> lineStopCB(&triangleDriveTo, 00052 &ArActionTriangleDriveTo::deactivate); 00053 keyHandler.addKeyHandler('s', &lineStopCB); 00054 keyHandler.addKeyHandler('S', &lineStopCB); 00055 00056 ArActionLimiterForwards limiter("limiter", 150, 0, 0, 1.3); 00057 robot.addAction(&limiter, 70); 00058 ArActionLimiterBackwards limiterBackwards; 00059 robot.addAction(&limiterBackwards, 69); 00060 00061 robot.addAction(&triangleDriveTo, 60); 00062 00063 ArActionKeydrive keydrive; 00064 robot.addAction(&keydrive, 55); 00065 00066 00067 ArActionStop stopAction; 00068 robot.addAction(&stopAction, 50); 00069 00070 // try to connect, if we fail exit 00071 if (!connector.connectRobot(&robot)) 00072 { 00073 printf("Could not connect to robot... exiting\n"); 00074 Aria::shutdown(); 00075 return 1; 00076 } 00077 00078 robot.comInt(ArCommands::SONAR, 1); 00079 robot.comInt(ArCommands::ENABLE, 1); 00080 00081 // start the robot running, true so that if we lose connection the run stops 00082 robot.runAsync(true); 00083 00084 // now set up the laser 00085 connector.setupLaser(&sick); 00086 00087 sick.runAsync(); 00088 00089 if (!sick.blockingConnect()) 00090 { 00091 printf("Could not connect to SICK laser... exiting\n"); 00092 Aria::shutdown(); 00093 return 1; 00094 } 00095 00096 printf("If you press the 'g' key it'll go find a triangle, if you press 's' it'll stop.\n"); 00097 00098 robot.waitForRunExit(); 00099 return 0; 00100 } 00101 00102 00103
1.4.7