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

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

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