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

ArActionLimiterBackwards.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 "ArActionLimiterBackwards.h"
00029 #include "ArRobot.h"
00030 
00039 AREXPORT ArActionLimiterBackwards::ArActionLimiterBackwards(
00040     const char *name, double stopDistance, double slowDistance, 
00041     double maxBackwardsSpeed, double widthRatio) :
00042   ArAction(name,
00043        "Slows the robot down so as not to hit anything in front of it.")
00044 {
00045   setNextArgument(ArArg("stop distance", &myStopDist, 
00046             "Distance at which to stop. (mm)"));
00047   myStopDist = stopDistance;
00048 
00049   setNextArgument(ArArg("slow distance", &mySlowDist, 
00050             "Distance at which to slow down. (mm)"));
00051   mySlowDist = slowDistance;
00052 
00053   setNextArgument(ArArg("maximum backwards speed", &myMaxBackwardsSpeed, 
00054              "Maximum backwards speed, scales from this to 0 at stopDistance (-mm/sec)"));
00055   myMaxBackwardsSpeed = maxBackwardsSpeed;
00056 
00057   setNextArgument(ArArg("width ratio", &myWidthRatio, 
00058              "The ratio of robot width to how wide an area to check (ratio)"));
00059   myWidthRatio = widthRatio;
00060   
00061 }
00062 
00063 AREXPORT ArActionLimiterBackwards::~ArActionLimiterBackwards()
00064 {
00065 
00066 }
00067 
00068 AREXPORT ArActionDesired *
00069 ArActionLimiterBackwards::fire(ArActionDesired currentDesired)
00070 {
00071   double dist;
00072   double maxVel;
00073   
00074   double slowStopDist = ArUtil::findMax(myStopDist, mySlowDist);
00075   
00076 
00077   myDesired.reset();
00078   dist = myRobot->checkRangeDevicesCurrentBox(-myRobot->getRobotLength()/2,
00079                           -(myRobot->getRobotWidth()/2.0 * 
00080                         myWidthRatio),
00081                    slowStopDist + (-myRobot->getRobotLength()),
00082                           (myRobot->getRobotWidth()/2.0 * 
00083                            myWidthRatio));
00084   dist -= myRobot->getRobotRadius();
00085   if (dist < -myStopDist)
00086   {
00087     //printf("backwards stop\n");
00088     myDesired.setMaxNegVel(0);
00089     return &myDesired;
00090   }
00091   if (dist > -mySlowDist)
00092   {
00093     //printf("backwards nothing\n");
00094     myDesired.setMaxNegVel(-ArMath::fabs(myMaxBackwardsSpeed));
00095     return &myDesired;
00096   }
00097       
00098             
00099   maxVel = -ArMath::fabs(myMaxBackwardsSpeed) * ((-dist - myStopDist) / (mySlowDist - myStopDist));
00100   //printf("Neg Max vel %f (stopdist %.1f slowdist %.1f slowspeed %.1f\n", maxVel,   myStopDist, mySlowDist, myMaxBackwardsSpeed);
00101   myDesired.setMaxNegVel(maxVel);
00102   return &myDesired;
00103   
00104 }

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