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

ArActionMovementParameters.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 "ArActionMovementParameters.h"
00029 #include "ArConfig.h"
00030 #include "ArRobot.h"
00031 
00040 AREXPORT ArActionMovementParameters::ArActionMovementParameters(
00041     const char *name,
00042     bool overrideFaster) : 
00043   ArAction(name, "Sets all the max vel and accels/decels")
00044 {
00045   myOverrideFaster = overrideFaster;
00046   myEnabled = true;
00047   myEnableOnce = false;
00048   setParameters();
00049 }
00050 
00051 AREXPORT ArActionMovementParameters::~ArActionMovementParameters()
00052 {
00053 
00054 }
00055 
00056 AREXPORT void ArActionMovementParameters::setParameters(double maxVel, 
00057                            double maxNegVel,
00058                            double transAccel,
00059                            double transDecel,
00060                            double rotVelMax, 
00061                            double rotAccel,
00062                            double rotDecel)
00063 {
00064   myMaxVel = maxVel;
00065   myMaxNegVel = maxNegVel;
00066   myTransAccel = transAccel;
00067   myTransDecel = transDecel;
00068   myMaxRotVel = rotVelMax;
00069   myRotAccel = rotAccel;
00070   myRotDecel = rotDecel;
00071 }
00072 
00073 AREXPORT void ArActionMovementParameters::addToConfig(ArConfig *config, 
00074                               const char *section, 
00075                               const char *prefix)
00076 {
00077   std::string strPrefix;
00078   std::string name;
00079   if (prefix == NULL || prefix[0] == '\0')
00080     strPrefix = "";
00081   else
00082     strPrefix = prefix;
00083 
00084   config->addParam(ArConfigArg(ArConfigArg::SEPARATOR), section, ArPriority::DETAILED);
00085   name = strPrefix;
00086   name += "TransVelMax";
00087   config->addParam(
00088       ArConfigArg(name.c_str(), &myMaxVel, 
00089               "Maximum forward translational velocity (0 means use default)", 
00090               0),
00091               //myRobot->getAbsoluteMaxTransVel()),
00092       section, ArPriority::DETAILED);
00093 
00094 
00095   name = strPrefix;
00096   name += "TransNegVelMax";
00097   config->addParam(
00098       ArConfigArg(name.c_str(), &myMaxNegVel, 
00099               "Maximum backwards translational velocity (0 means use default)", 
00100               0),
00101       //myRobot->getAbsoluteMaxTransVel()),
00102       section, ArPriority::DETAILED);
00103 
00104   name = strPrefix;
00105   name += "TransAccel";
00106   config->addParam(
00107       ArConfigArg(name.c_str(), &myTransAccel, 
00108               "Translational acceleration (0 means use default)", 0),
00109               //myRobot->getAbsoluteMaxTransAccel()),             
00110       section, ArPriority::DETAILED);
00111 
00112   name = strPrefix;
00113   name += "TransDecel";
00114   config->addParam(
00115       ArConfigArg(name.c_str(), &myTransDecel, 
00116               "Translational deceleration (0 means use default)", 0),
00117               //myRobot->getAbsoluteMaxTransDecel()),             
00118       section, ArPriority::DETAILED);
00119 
00120   name = strPrefix;
00121   name += "RotVelMax";
00122   config->addParam(
00123       ArConfigArg(name.c_str(), &myMaxRotVel, 
00124               "Maximum rotational velocity (0 means use default)", 
00125               0), // myRobot->getAbsoluteMaxRotVel()),
00126       section, ArPriority::DETAILED);
00127 
00128   name = strPrefix;
00129   name += "RotAccel";
00130   config->addParam(
00131       ArConfigArg(name.c_str(), &myRotAccel, 
00132               "Rotational acceleration (0 means use default)", 0),
00133       //myRobot->getAbsoluteMaxRotAccel()),
00134       section, ArPriority::DETAILED);
00135 
00136   name = strPrefix;
00137   name += "RotDecel";
00138   config->addParam(
00139       ArConfigArg(name.c_str(), &myRotDecel, 
00140               "Rotational deceleration (0 means use default)", 0),
00141               //myRobot->getAbsoluteMaxRotDecel()),
00142       section, ArPriority::DETAILED);
00143   config->addParam(ArConfigArg(ArConfigArg::SEPARATOR), section, ArPriority::DETAILED);
00144 
00145 
00146 }
00147 
00148 AREXPORT ArActionDesired *ArActionMovementParameters::fire(
00149     ArActionDesired currentDesired)
00150 {
00151   myDesired.reset();
00152 
00153   if (!myEnabled && !myEnableOnce)
00154     return NULL;
00155   myEnableOnce = false;
00156 
00157   if (fabs(myMaxVel) >= 1)
00158     myDesired.setMaxVel(myMaxVel);
00159 
00160   if (fabs(myMaxNegVel) >= 1)
00161     myDesired.setMaxNegVel(myMaxNegVel);
00162 
00163   if (fabs(myTransAccel) >= 1)
00164     myDesired.setTransAccel(myTransAccel);
00165 
00166   if (fabs(myTransDecel) >= 1)
00167     myDesired.setTransDecel(myTransDecel);
00168 
00169   if (fabs(myMaxRotVel) >= 1)
00170     myDesired.setMaxRotVel(myMaxRotVel);
00171 
00172   if (fabs(myRotAccel) >= 1)
00173     myDesired.setRotAccel(myRotAccel);
00174 
00175   if (fabs(myRotDecel) >= 1)
00176     myDesired.setRotDecel(myRotDecel);
00177   
00178   return &myDesired;
00179 }

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