00001 /* 00002 MobileRobots Advanced Robotics Interface for Applications (ARIA) 00003 Copyright (C) 2004, 2005 ActivMedia Robotics LLC 00004 Copyright (C) 2006, 2007 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 #include "Aria.h" 00027 00039 int main(int argc, char **argv) 00040 { 00041 // robot 00042 ArRobot robot; 00043 // sonar, must be added to the robot 00044 ArSonarDevice sonar; 00045 00046 // the actions we'll use to wander 00047 ArActionStallRecover recover; 00048 ArActionBumpers bumpers; 00049 ArActionAvoidFront avoidFrontNear("Avoid Front Near", 225, 0); 00050 ArActionAvoidFront avoidFrontFar; 00051 ArActionConstantVelocity constantVelocity("Constant Velocity", 400); 00052 00053 // Make a key handler, so that escape will shut down the program 00054 // cleanly 00055 ArKeyHandler keyHandler; 00056 00057 // mandatory init 00058 Aria::init(); 00059 00060 ArSimpleConnector connector(&argc, argv); 00061 00062 if (!connector.parseArgs() || argc > 1) 00063 { 00064 connector.logOptions(); 00065 keyHandler.restore(); 00066 return 1; 00067 } 00068 00069 puts("This program will just have the robot wander around. It uses some avoidance\n" 00070 "actions if obstacles are detected with the sonar, otherwise it just has a\n" 00071 "constant forward velocity.\n\nPress CTRL-C or Escape to exit."); 00072 00073 // Add the key handler to Aria so other things can find it. 00074 // You can comment this out if you want to run this program 00075 // as a background process on Linux. 00076 Aria::setKeyHandler(&keyHandler); 00077 00078 // Attach the key handler to a robot now, so that it actually gets 00079 // some processing time so it can work, this will also make escape 00080 // exit. You can comment this out if you want to run this program 00081 // as a background process on Linux. 00082 robot.attachKeyHandler(&keyHandler); 00083 00084 // add the sonar to the robot 00085 robot.addRangeDevice(&sonar); 00086 00087 // try to connect, if we fail exit 00088 if (!connector.connectRobot(&robot)) 00089 { 00090 printf("Could not connect to robot... exiting\n"); 00091 Aria::shutdown(); 00092 return 1; 00093 } 00094 00095 // turn on the motors, turn off amigobot sounds 00096 robot.comInt(ArCommands::ENABLE, 1); 00097 robot.comInt(ArCommands::SOUNDTOG, 0); 00098 00099 // add the actions 00100 robot.addAction(&recover, 100); 00101 robot.addAction(&bumpers, 75); 00102 robot.addAction(&avoidFrontNear, 50); 00103 robot.addAction(&avoidFrontFar, 49); 00104 robot.addAction(&constantVelocity, 25); 00105 00106 // start the robot running, true so that if we lose connection the run stops 00107 robot.run(true); 00108 00109 // now exit 00110 Aria::shutdown(); 00111 return 0; 00112 }