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

ArActionTurn.cpp

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

Generated on Wed Oct 19 12:56:34 2005 for Aria by  doxygen 1.4.0