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

ArActionMovementParameters.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 "ArActionMovementParameters.h"
00030 #include "ArConfig.h"
00031 
00032 ArActionMovementParameters::ArActionMovementParameters(
00033         const char *name) : 
00034   ArAction(name, "Sets all the max vel and accels/decels")
00035 {
00036   setParameters();
00037 }
00038 
00039 ArActionMovementParameters::~ArActionMovementParameters()
00040 {
00041 
00042 }
00043 
00044 void ArActionMovementParameters::setParameters(double maxVel, 
00045                                                    double maxNegVel,
00046                                                    double transAccel,
00047                                                    double transDecel,
00048                                                    double rotVelMax, 
00049                                                    double rotAccel,
00050                                                    double rotDecel)
00051 {
00052   myMaxVel = maxVel;
00053   myMaxNegVel = maxNegVel;
00054   myTransAccel = transAccel;
00055   myTransDecel = transDecel;
00056   myMaxRotVel = rotVelMax;
00057   myRotAccel = rotAccel;
00058   myRotDecel = rotDecel;
00059 }
00060 
00061 void ArActionMovementParameters::addToConfig(ArConfig *config, 
00062                                                       const char *section, 
00063                                                       const char *prefix)
00064 {
00065   std::string strPrefix;
00066   std::string name;
00067   if (prefix == NULL || prefix[0] == '\0')
00068     strPrefix = "";
00069   else
00070     strPrefix = prefix;
00071 
00072   name = strPrefix;
00073   name += "TransVelMax";
00074   config->addParam(
00075           ArConfigArg(name.c_str(), &myMaxVel, 
00076                       "Maximum forward translational velocity (0 means use default)", 
00077                       0),
00078           section, ArPriority::DETAILED);
00079 
00080 
00081   name = strPrefix;
00082   name += "TransNegVelMax";
00083   config->addParam(
00084           ArConfigArg(name.c_str(), &myMaxNegVel, 
00085                       "Maximum backwards translational velocity (0 means use default)", 
00086                       0),
00087           section, ArPriority::DETAILED);
00088 
00089   name = strPrefix;
00090   name += "TransAccel";
00091   config->addParam(
00092           ArConfigArg(name.c_str(), &myTransAccel, 
00093                       "Translational acceleration (0 means use default)", 0),
00094           section, ArPriority::DETAILED);
00095 
00096   name = strPrefix;
00097   name += "TransDecel";
00098   config->addParam(
00099           ArConfigArg(name.c_str(), &myTransDecel, 
00100                       "Translational deceleration (0 means use default)", 0),
00101           section, ArPriority::DETAILED);
00102 
00103   name = strPrefix;
00104   name += "RotVelMax";
00105   config->addParam(
00106           ArConfigArg(name.c_str(), &myMaxRotVel, 
00107                       "Maximum rotational velocity (0 means use default)", 
00108                       0),
00109           section, ArPriority::DETAILED);
00110 
00111   name = strPrefix;
00112   name += "RotAccel";
00113   config->addParam(
00114           ArConfigArg(name.c_str(), &myRotAccel, 
00115                       "Rotational acceleration (0 means use default)", 0),
00116           section, ArPriority::DETAILED);
00117 
00118   name = strPrefix;
00119   name += "RotDecel";
00120   config->addParam(
00121           ArConfigArg(name.c_str(), &myRotDecel, 
00122                       "Rotational deceleration (0 means use default)", 0),
00123           section, ArPriority::DETAILED);
00124 
00125 
00126 
00127 }
00128 
00129 ArActionDesired *ArActionMovementParameters::fire(
00130         ArActionDesired currentDesired)
00131 {
00132   myDesired.reset();
00133 
00134   if (fabs(myMaxVel) >= 1)
00135   {
00136     // if we're set to a larger value than we have use full strength
00137     // (to try to go slower)
00138     if (currentDesired.getMaxVelStrength() > ArActionDesired::MIN_STRENGTH 
00139         && fabs(myMaxVel) < fabs(currentDesired.getMaxVel()))
00140       myDesired.setMaxVel(myMaxVel);
00141     // otherwise use as little as possible so other things can do more
00142     // if they need to
00143     else
00144       myDesired.setMaxVel(myMaxVel, ArActionDesired::MIN_STRENGTH);
00145   }
00146 
00147   if (fabs(myMaxNegVel) >= 1)
00148   {
00149     // if we're set to a larger value than we have use full strength
00150     // (to try to go slower)
00151     if (currentDesired.getMaxNegVelStrength() > ArActionDesired::MIN_STRENGTH 
00152         && fabs(myMaxNegVel) < fabs(currentDesired.getMaxNegVel()))
00153       myDesired.setMaxNegVel(myMaxNegVel);
00154     // otherwise use as little as possible so other things can do more
00155     // if they need to
00156     else
00157       myDesired.setMaxNegVel(myMaxNegVel, ArActionDesired::MIN_STRENGTH);
00158   }
00159 
00160   if (fabs(myTransAccel) >= 1)
00161   {    
00162     
00163     // if we're set to a larger value than we have use full strength
00164     // (to try to go slower)
00165     if (currentDesired.getTransAccelStrength() > ArActionDesired::MIN_STRENGTH 
00166         && fabs(myTransAccel) < fabs(currentDesired.getTransAccel()))
00167       myDesired.setTransAccel(myTransAccel);
00168     // otherwise use as little as possible so other things can do more
00169     // if they need to
00170     else
00171       myDesired.setTransAccel(myTransAccel, ArActionDesired::MIN_STRENGTH);
00172   }
00173 
00174   if (fabs(myTransDecel) >= 1)
00175   {
00176     // if we're set to a larger value than we have use full strength
00177     // (to try to go slower)
00178     if (currentDesired.getTransDecelStrength() > ArActionDesired::MIN_STRENGTH 
00179         && fabs(myTransDecel) < fabs(currentDesired.getTransDecel()))
00180       myDesired.setTransDecel(myTransDecel);
00181     // otherwise use as little as possible so other things can do more
00182     // if they need to
00183     else
00184       myDesired.setTransDecel(myTransDecel, ArActionDesired::MIN_STRENGTH);
00185   }
00186 
00187   if (fabs(myMaxRotVel) >= 1)
00188   {
00189     // if we're set to a larger value than we have use full strength
00190     // (to try to go slower)
00191     if (currentDesired.getMaxRotVelStrength() > ArActionDesired::MIN_STRENGTH 
00192         && fabs(myMaxRotVel) < fabs(currentDesired.getMaxRotVel()))
00193       myDesired.setMaxRotVel(myMaxRotVel);
00194 
00195     // otherwise use as little as possible so other things can do more
00196     // if they need to
00197     else
00198       myDesired.setMaxRotVel(myMaxRotVel, ArActionDesired::MIN_STRENGTH);
00199   }
00200 
00201 
00202   if (fabs(myRotAccel) >= 1)
00203   {
00204     // if we're set to a larger value than we have use full strength
00205     // (to try to go slower)
00206     if (currentDesired.getRotAccelStrength() > ArActionDesired::MIN_STRENGTH 
00207         && fabs(myRotAccel) < fabs(currentDesired.getRotAccel()))
00208       myDesired.setRotAccel(myRotAccel);
00209     // otherwise use as little as possible so other things can do more
00210     // if they need to
00211     else
00212       myDesired.setRotAccel(myRotAccel, ArActionDesired::MIN_STRENGTH);
00213   }
00214 
00215   if (fabs(myRotDecel) >= 1)
00216   {
00217     // if we're set to a larger value than we have use full strength
00218     // (to try to go slower)
00219     if (currentDesired.getRotDecelStrength() > ArActionDesired::MIN_STRENGTH 
00220         && fabs(myRotDecel) < fabs(currentDesired.getRotDecel()))
00221       myDesired.setRotAccel(myRotDecel);
00222     // otherwise use as little as possible so other things can do more
00223     // if they need to
00224     else
00225       myDesired.setRotDecel(myRotDecel, ArActionDesired::MIN_STRENGTH);
00226   }
00227   
00228   return &myDesired;
00229 }

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