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

ArActionAvoidSide.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 "ArExport.h"
00027 #include "ariaOSDef.h"
00028 #include "ArActionAvoidSide.h"
00029 #include "ArRobot.h"
00030 
00037 AREXPORT ArActionAvoidSide::ArActionAvoidSide(const char *name,
00038                           double obstacleDistance,
00039                           double turnAmount) :
00040   ArAction(name, "Avoids side obstacles, ie walls")
00041 {
00042   setNextArgument(ArArg("obstacle distance", &myObsDist, 
00043             "Distance at which to start avoiding (mm)"));
00044   myObsDist = obstacleDistance;
00045   setNextArgument(ArArg("turn amount", &myTurnAmount,
00046             "Degrees at which to turn (deg)"));
00047   myTurnAmount = turnAmount;
00048 
00049   myTurning = false;
00050 
00051 }
00052 
00053 AREXPORT ArActionAvoidSide::~ArActionAvoidSide()
00054 {
00055 
00056 }
00057 
00058 AREXPORT ArActionDesired *ArActionAvoidSide::fire(
00059     ArActionDesired currentDesired)
00060 {
00061   double leftDist, rightDist;
00062 
00063   leftDist = (myRobot->checkRangeDevicesCurrentPolar(60, 120) - 
00064           myRobot->getRobotRadius());
00065   rightDist = (myRobot->checkRangeDevicesCurrentPolar(-120, -60) - 
00066           myRobot->getRobotRadius());
00067   
00068   myDesired.reset();
00069   if (leftDist < myObsDist)
00070   {
00071     myDesired.setDeltaHeading(-myTurnAmount);
00072     myDesired.setVel(0);
00073     myTurning = true;
00074   }
00075   else if (rightDist < myObsDist)
00076   {
00077     myDesired.setDeltaHeading(myTurnAmount);
00078     myDesired.setVel(0);
00079     myTurning = true;
00080   }
00081   else if (myTurning)
00082     myDesired.setDeltaHeading(0);
00083 
00084   return &myDesired;
00085 }

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