Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | Related Pages | Examples

gotoActionExample.cpp

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 
00037 int main(int argc, char **argv)
00038 {
00039   Aria::init();
00040   ArArgumentParser parser(&argc, argv);
00041   parser.loadDefaultArguments();
00042   ArSimpleConnector simpleConnector(&parser);
00043   ArRobot robot;
00044   ArSonarDevice sonar;
00045   ArAnalogGyro gyro(&robot);
00046   robot.addRangeDevice(&sonar);
00047 
00048   // Make a key handler, so that escape will shut down the program
00049   // cleanly
00050   ArKeyHandler keyHandler;
00051   Aria::setKeyHandler(&keyHandler);
00052   robot.attachKeyHandler(&keyHandler);
00053   printf("You may press escape to exit\n");
00054 
00055   // Collision avoidance actions at higher priority
00056   ArActionLimiterForwards limiterAction("speed limiter near", 300, 600, 250);
00057   ArActionLimiterForwards limiterFarAction("speed limiter far", 300, 1100, 400);
00058   ArActionLimiterTableSensor tableLimiterAction;
00059   robot.addAction(&tableLimiterAction, 100);
00060   robot.addAction(&limiterAction, 95);
00061   robot.addAction(&limiterFarAction, 90);
00062 
00063   // Goto action at lower priority
00064   ArActionGoto gotoPoseAction("goto");
00065   robot.addAction(&gotoPoseAction, 50);
00066   
00067   // Parse all command line arguments
00068   if (!Aria::parseArgs() || !parser.checkHelpAndWarnUnparsed())
00069   {    
00070     Aria::logOptions();
00071     exit(1);
00072   }
00073   
00074   // Connect to the robot
00075   if (!simpleConnector.connectRobot(&robot))
00076   {
00077     printf("Could not connect to robot... exiting\n");
00078     Aria::exit(1);
00079   }
00080   robot.runAsync(true);
00081 
00082   // turn on the motors, turn off amigobot sounds
00083   robot.enableMotors();
00084   robot.comInt(ArCommands::SOUNDTOG, 0);
00085 
00086   bool first = true;
00087   int goalNum = 0;
00088   while (Aria::getRunning()) 
00089   {
00090     robot.lock();
00091 
00092     // Choose a new goal if this is the first loop iteration, or if we 
00093     // achieved the previous goal.
00094     if (first || gotoPoseAction.haveAchievedGoal())
00095     {
00096       first = false;
00097       goalNum++;
00098       if (goalNum > 4)
00099         goalNum = 1; // start again at goal #1
00100 
00101       // set our positions for the different goals
00102       if (goalNum == 1)
00103         gotoPoseAction.setGoal(ArPose(5000, 0));
00104       else if (goalNum == 2)
00105         gotoPoseAction.setGoal(ArPose(5000, 5000));
00106       else if (goalNum == 3)
00107         gotoPoseAction.setGoal(ArPose(0, 5000));
00108       else if (goalNum == 4)
00109         gotoPoseAction.setGoal(ArPose(0, 0));
00110 
00111       ArLog::log(ArLog::Normal, "Going to next goal at %.0f %.0f", 
00112             gotoPoseAction.getGoal().getX(), gotoPoseAction.getGoal().getY());
00113     }
00114     robot.unlock();
00115   }
00116   
00117   // Robot disconnected, shut down
00118   Aria::shutdown();
00119   return 0;
00120 }

Generated on Tue Feb 20 10:51:42 2007 for Aria by  doxygen 1.4.0