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

ArActionLimiterForwards.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 "ArActionLimiterForwards.h"
00029 #include "ArRobot.h"
00030 
00039 AREXPORT ArActionLimiterForwards::ArActionLimiterForwards(const char *name, 
00040                               double stopDistance,
00041                               double slowDistance,
00042                               double slowSpeed,
00043                               double widthRatio) :
00044   ArAction(name,
00045        "Slows the robot down so as not to hit anything in front of it.")
00046 {
00047   setNextArgument(ArArg("stop distance", &myStopDist, 
00048             "Distance at which to stop. (mm)"));
00049   myStopDist = stopDistance;
00050 
00051   setNextArgument(ArArg("slow distance", &mySlowDist, 
00052             "Distance at which to slow down. (mm)"));
00053   mySlowDist = slowDistance;
00054 
00055   setNextArgument(ArArg("slow speed", &mySlowSpeed, 
00056              "Speed at which to slow to at the slow distance, (mm/sec)"));
00057   mySlowSpeed = slowSpeed;
00058   
00059   setNextArgument(ArArg("width ratio", &myWidthRatio,
00060             "Ratio of the width of the box to look at to the robot radius (multiplier)"));
00061   myWidthRatio = widthRatio;
00062   myLastStopped = false;
00063 }
00064 
00065 AREXPORT ArActionLimiterForwards::~ArActionLimiterForwards()
00066 {
00067 
00068 }
00069 
00077 AREXPORT void ArActionLimiterForwards::setParameters(double stopDistance,
00078                              double slowDistance,
00079                              double slowSpeed,
00080                              double widthRatio)
00081 {
00082   myStopDist = stopDistance;
00083   mySlowDist = slowDistance;
00084   mySlowSpeed = slowSpeed;
00085   myWidthRatio = widthRatio;
00086 }
00087 
00088 AREXPORT ArActionDesired *
00089 ArActionLimiterForwards::fire(ArActionDesired currentDesired)
00090 {
00091   double dist;
00092   double maxVel;
00093   bool printing = false;
00094   double checkDist;
00095 
00096   if (myStopDist > mySlowDist)
00097     checkDist = myStopDist;
00098   else
00099     checkDist = mySlowDist;
00100 
00101   myDesired.reset();
00102   dist = myRobot->checkRangeDevicesCurrentBox(0,
00103                 -myRobot->getRobotWidth()/2.0 * myWidthRatio,
00104                     checkDist + myRobot->getRobotLength()/2,
00105                 myRobot->getRobotWidth()/2.0 * myWidthRatio);
00106   dist -= myRobot->getRobotLength() / 2;
00107   //printf("%.0f\n", dist);
00108   if (dist < myStopDist)
00109   {
00110     if (printing && !myLastStopped)
00111       printf("Stopping\n");
00112     myLastStopped = true;
00113     myDesired.setMaxVel(0);
00114     return &myDesired;
00115   }
00116 
00117   if (printing && myLastStopped)
00118     printf("Going\n");
00119   myLastStopped = false;
00120   //printf("%f ", dist);
00121   if (dist > mySlowDist)
00122   {
00123     //printf("Nothing\n");
00124     return NULL;
00125     //return &myDesired;
00126   }
00127       
00128             
00129   maxVel = mySlowSpeed * ((dist - myStopDist) / (mySlowDist - myStopDist));
00130   //printf("Max vel %f (stopdist %.1f slowdist %.1f slowspeed %.1f\n", maxVel,   myStopDist, mySlowDist, mySlowSpeed);
00131   myDesired.setMaxVel(maxVel);
00132   return &myDesired;
00133   
00134 }

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