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

ArActionTurn.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 "ArActionTurn.h"
00029 #include "ArRobot.h"
00030 
00031 AREXPORT ArActionTurn::ArActionTurn(const char *name, double speedStartTurn,
00032                     double speedFullTurn, double turnAmount) :
00033   ArAction(name, 
00034        "Turns the robot depending on actions by higher priority actions.")
00035 {
00036   setNextArgument(ArArg("speed start turn", &mySpeedStart,
00037             "max vel at which to start turning (mm/sec)"));
00038   mySpeedStart = speedStartTurn;
00039 
00040   setNextArgument(ArArg("speed full turn", &mySpeedFull,
00041             "max vel at which to turn the full amount (mm/sec)"));
00042   mySpeedFull = speedFullTurn;
00043 
00044   setNextArgument(ArArg("turn amount", &myTurnAmount,
00045             "max vel at which to start turning (mm/sec)"));
00046   myTurnAmount = turnAmount;
00047 
00048   myTurning = 0;
00049 
00050 }
00051 
00052 AREXPORT ArActionTurn::~ArActionTurn()
00053 {
00054 
00055 }
00056 
00057 AREXPORT ArActionDesired *ArActionTurn::fire(ArActionDesired currentDesired)
00058 {
00059   myDesired.reset();
00060   double turnAmount;
00061   double angle;
00062 
00063   // if there's no strength, bail
00064   // if our max velocity is higher than our start turn, bail
00065   if (myRobot->getVel() > mySpeedStart)
00066   {
00067     if (myTurning != 0)
00068     {
00069       //printf("Resetting\n");
00070       myTurning = 0;
00071     }
00072     return NULL;
00073   }
00074 
00075   // we're going to turn now... so figure out the amount to turn
00076 
00077   // if our max vel is lower than the turn amount, just do the full turn
00078   if (myRobot->getVel() < mySpeedFull)
00079   {
00080     //printf("full\n");
00081     turnAmount = myTurnAmount;
00082   }
00083   // otherwise scale it
00084   else
00085   {
00086     turnAmount = ((mySpeedStart - myRobot->getVel()) /
00087           (mySpeedStart - mySpeedFull)) * myTurnAmount;
00088   
00089     //printf("%.2f\n", (mySpeedStart - currentDesired.getMaxVel()) / (mySpeedStart - mySpeedFull));
00090   }
00091   // if we're already turning, turn that direction
00092   if (myTurning != 0)
00093     turnAmount *= myTurning;
00094   // find out which side the closest obstacle is, and turn away
00095   else
00096   {
00097     if (myRobot->checkRangeDevicesCurrentPolar(-90, 90, &angle) < 3000)
00098     {
00099       if (angle > 0)
00100       {
00101     //printf("### right\n");
00102     myTurning = -1;
00103       }
00104       else
00105       {
00106     //printf("### left\n");
00107     myTurning = 1;
00108       }
00109     }
00110     else
00111     {
00112       //printf("### left\n");
00113       myTurning = 1;
00114     }
00115     turnAmount *= myTurning;
00116   }
00117   myDesired.setDeltaHeading(turnAmount);
00118   return &myDesired;
00119 }

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