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 /* 00002 MobileRobots Advanced Robotics Interface for Applications (ARIA) 00003 Copyright (C) 2004,2005 ActivMedia Robotics LLC 00004 Copyright (C) 2006 MobileRobots, Inc. 00005 00006 This program is free software; you can redistribute it and/or modify 00007 it under the terms of the GNU General Public License as published by 00008 the Free Software Foundation; either version 2 of the License, or 00009 (at your option) any later version. 00010 00011 This program is distributed in the hope that it will be useful, 00012 but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 GNU General Public License for more details. 00015 00016 You should have received a copy of the GNU General Public License 00017 along with this program; if not, write to the Free Software 00018 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00019 00020 If you wish to redistribute ARIA under different terms, contact 00021 MobileRobots for information about a commercial version of ARIA at 00022 robots@mobilerobots.com or 00023 MobileRobots Inc, 19 Columbia Drive, Amherst, NH 03031; 800-639-9481 00024 */ 00025 00026 00036 #include "Aria.h" 00037 00038 00039 int main(int argc, char **argv) 00040 { 00041 Aria::init(); 00042 00043 // parse our args and make sure they were all accounted for 00044 ArSimpleConnector connector(&argc, argv); 00045 00046 ArRobot robot; 00047 00048 // the laser. ArActionTriangleDriveTo will use this laser object since it is 00049 // named "laser" when added to the ArRobot. 00050 ArSick sick; 00051 00052 if (!connector.parseArgs() || argc > 1) 00053 { 00054 connector.logOptions(); 00055 exit(1); 00056 } 00057 00058 // a key handler so we can do our key handling 00059 ArKeyHandler keyHandler; 00060 // let the global aria stuff know about it 00061 Aria::setKeyHandler(&keyHandler); 00062 // toss it on the robot 00063 robot.attachKeyHandler(&keyHandler); 00064 00065 // add the laser to the robot 00066 robot.addRangeDevice(&sick); 00067 00068 ArSonarDevice sonar; 00069 robot.addRangeDevice(&sonar); 00070 00071 ArActionTriangleDriveTo triangleDriveTo; 00072 ArFunctorC<ArActionTriangleDriveTo> lineGoCB(&triangleDriveTo, 00073 &ArActionTriangleDriveTo::activate); 00074 keyHandler.addKeyHandler('g', &lineGoCB); 00075 keyHandler.addKeyHandler('G', &lineGoCB); 00076 ArFunctorC<ArActionTriangleDriveTo> lineStopCB(&triangleDriveTo, 00077 &ArActionTriangleDriveTo::deactivate); 00078 keyHandler.addKeyHandler('s', &lineStopCB); 00079 keyHandler.addKeyHandler('S', &lineStopCB); 00080 00081 ArActionLimiterForwards limiter("limiter", 150, 0, 0, 1.3); 00082 robot.addAction(&limiter, 70); 00083 ArActionLimiterBackwards limiterBackwards; 00084 robot.addAction(&limiterBackwards, 69); 00085 00086 robot.addAction(&triangleDriveTo, 60); 00087 00088 ArActionKeydrive keydrive; 00089 robot.addAction(&keydrive, 55); 00090 00091 00092 ArActionStop stopAction; 00093 robot.addAction(&stopAction, 50); 00094 00095 // try to connect, if we fail exit 00096 if (!connector.connectRobot(&robot)) 00097 { 00098 printf("Could not connect to robot... exiting\n"); 00099 Aria::shutdown(); 00100 return 1; 00101 } 00102 00103 robot.comInt(ArCommands::SONAR, 1); 00104 robot.comInt(ArCommands::ENABLE, 1); 00105 00106 // start the robot running, true so that if we lose connection the run stops 00107 robot.runAsync(true); 00108 00109 // now set up the laser 00110 connector.setupLaser(&sick); 00111 00112 sick.runAsync(); 00113 00114 if (!sick.blockingConnect()) 00115 { 00116 printf("Could not connect to SICK laser... exiting\n"); 00117 Aria::shutdown(); 00118 return 1; 00119 } 00120 00121 printf("If you press the 'g' key it'll go find a triangle, if you press 's' it'll stop.\n"); 00122 00123 robot.waitForRunExit(); 00124 return 0; 00125 } 00126 00127 00128
1.4.7