00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
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
00137
00138 if (currentDesired.getMaxVelStrength() > ArActionDesired::MIN_STRENGTH
00139 && fabs(myMaxVel) < fabs(currentDesired.getMaxVel()))
00140 myDesired.setMaxVel(myMaxVel);
00141
00142
00143 else
00144 myDesired.setMaxVel(myMaxVel, ArActionDesired::MIN_STRENGTH);
00145 }
00146
00147 if (fabs(myMaxNegVel) >= 1)
00148 {
00149
00150
00151 if (currentDesired.getMaxNegVelStrength() > ArActionDesired::MIN_STRENGTH
00152 && fabs(myMaxNegVel) < fabs(currentDesired.getMaxNegVel()))
00153 myDesired.setMaxNegVel(myMaxNegVel);
00154
00155
00156 else
00157 myDesired.setMaxNegVel(myMaxNegVel, ArActionDesired::MIN_STRENGTH);
00158 }
00159
00160 if (fabs(myTransAccel) >= 1)
00161 {
00162
00163
00164
00165 if (currentDesired.getTransAccelStrength() > ArActionDesired::MIN_STRENGTH
00166 && fabs(myTransAccel) < fabs(currentDesired.getTransAccel()))
00167 myDesired.setTransAccel(myTransAccel);
00168
00169
00170 else
00171 myDesired.setTransAccel(myTransAccel, ArActionDesired::MIN_STRENGTH);
00172 }
00173
00174 if (fabs(myTransDecel) >= 1)
00175 {
00176
00177
00178 if (currentDesired.getTransDecelStrength() > ArActionDesired::MIN_STRENGTH
00179 && fabs(myTransDecel) < fabs(currentDesired.getTransDecel()))
00180 myDesired.setTransDecel(myTransDecel);
00181
00182
00183 else
00184 myDesired.setTransDecel(myTransDecel, ArActionDesired::MIN_STRENGTH);
00185 }
00186
00187 if (fabs(myMaxRotVel) >= 1)
00188 {
00189
00190
00191 if (currentDesired.getMaxRotVelStrength() > ArActionDesired::MIN_STRENGTH
00192 && fabs(myMaxRotVel) < fabs(currentDesired.getMaxRotVel()))
00193 myDesired.setMaxRotVel(myMaxRotVel);
00194
00195
00196
00197 else
00198 myDesired.setMaxRotVel(myMaxRotVel, ArActionDesired::MIN_STRENGTH);
00199 }
00200
00201
00202 if (fabs(myRotAccel) >= 1)
00203 {
00204
00205
00206 if (currentDesired.getRotAccelStrength() > ArActionDesired::MIN_STRENGTH
00207 && fabs(myRotAccel) < fabs(currentDesired.getRotAccel()))
00208 myDesired.setRotAccel(myRotAccel);
00209
00210
00211 else
00212 myDesired.setRotAccel(myRotAccel, ArActionDesired::MIN_STRENGTH);
00213 }
00214
00215 if (fabs(myRotDecel) >= 1)
00216 {
00217
00218
00219 if (currentDesired.getRotDecelStrength() > ArActionDesired::MIN_STRENGTH
00220 && fabs(myRotDecel) < fabs(currentDesired.getRotDecel()))
00221 myDesired.setRotAccel(myRotDecel);
00222
00223
00224 else
00225 myDesired.setRotDecel(myRotDecel, ArActionDesired::MIN_STRENGTH);
00226 }
00227
00228 return &myDesired;
00229 }