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

Modules/BehaviorControl/CommonXabsl2Symbols/MathFunctions.cpp

Go to the documentation of this file.
00001 /** 
00002 * @file MathFunctions.cpp
00003 *
00004 * Implementation of class MathFunctions.
00005 *
00006 * @author Matthias Jüngel
00007 */
00008 
00009 #include "MathFunctions.h"
00010 #include "Tools/Math/Geometry.h"
00011 
00012 MathFunctions::MathFunctions(const BehaviorControlInterfaces& interfaces)
00013 : BehaviorControlInterfaces(interfaces)
00014 {
00015 }
00016 
00017 
00018 void MathFunctions::registerSymbols(Xabsl2Engine& engine)
00019 {
00020   // "distance-to"
00021   engine.registerDecimalInputFunction("distance-to",this,
00022     (double (Xabsl2FunctionProvider::*)())&MathFunctions::distanceTo);
00023   engine.registerDecimalInputFunctionParameter("distance-to","distance-to.x",distanceToX);
00024   engine.registerDecimalInputFunctionParameter("distance-to","distance-to.y",distanceToY);
00025 
00026   // "angle-to"
00027   engine.registerDecimalInputFunction("angle-to",this,
00028     (double (Xabsl2FunctionProvider::*)())&MathFunctions::angleTo);
00029   engine.registerDecimalInputFunctionParameter("angle-to","angle-to.x",angleToX);
00030   engine.registerDecimalInputFunctionParameter("angle-to","angle-to.y",angleToY);
00031 
00032   // "abs"
00033   engine.registerDecimalInputFunction("abs",this,
00034     (double (Xabsl2FunctionProvider::*)())&MathFunctions::getAbs);
00035   engine.registerDecimalInputFunctionParameter("abs","abs.value",absValue);
00036 
00037   // "min"
00038   engine.registerDecimalInputFunction("min",this,
00039     (double (Xabsl2FunctionProvider::*)())&MathFunctions::getMin);
00040   engine.registerDecimalInputFunctionParameter("min","min.value0",min0Value);
00041   engine.registerDecimalInputFunctionParameter("min","min.value1",min1Value);
00042 
00043   // "max"
00044   engine.registerDecimalInputFunction("max",this,
00045     (double (Xabsl2FunctionProvider::*)())&MathFunctions::getMax);
00046   engine.registerDecimalInputFunctionParameter("max","max.value0",max0Value);
00047   engine.registerDecimalInputFunctionParameter("max","max.value1",max1Value);
00048 
00049   // "sgn"
00050   engine.registerDecimalInputFunction("sgn",this,
00051     (double (Xabsl2FunctionProvider::*)())&MathFunctions::getSgn);
00052   engine.registerDecimalInputFunctionParameter("sgn","sgn.value",sgnValue);
00053 
00054   // "sin"
00055   engine.registerDecimalInputFunction("sin",this,
00056     (double (Xabsl2FunctionProvider::*)())&MathFunctions::getSin);
00057   engine.registerDecimalInputFunctionParameter("sin","sin.alpha",alphaValue);
00058 
00059   // "cos"
00060   engine.registerDecimalInputFunction("cos",this,
00061     (double (Xabsl2FunctionProvider::*)())&MathFunctions::getCos);
00062   engine.registerDecimalInputFunctionParameter("cos","cos.alpha",alphaValue);
00063 
00064   // "random"
00065   engine.registerDecimalInputSymbol("random",this,
00066     (double (Xabsl2FunctionProvider::*)())&MathFunctions::getRandom);
00067 
00068   // "normalize"
00069   engine.registerDecimalInputFunction("normalize",this,
00070     (double (Xabsl2FunctionProvider::*)())&MathFunctions::getNormalize);
00071   engine.registerDecimalInputFunctionParameter("normalize","normalize.angle",normalizeAngle);
00072 
00073   // "freeze-value" math.unfreeze-value has to be true (1), before freezing is possible
00074   engine.registerEnumeratedOutputSymbol("math.unfreeze-value",(int*)&unFreezeValue);
00075   engine.registerEnumeratedOutputSymbolEnumElement("math.unfreeze-value","true", 1);
00076 
00077   engine.registerDecimalInputFunction("freeze",this,
00078     (double (Xabsl2FunctionProvider::*)())&MathFunctions::getFrozenValue);
00079   engine.registerDecimalInputFunctionParameter("freeze","freeze.value",valueToFreeze);
00080 
00081   engine.registerDecimalInputFunction("is-in-interval",this,
00082     (double (Xabsl2FunctionProvider::*)())&MathFunctions::isInInterval);
00083   engine.registerDecimalInputFunctionParameter("is-in-interval","is-in-interval.a",isInIntervalA);
00084   engine.registerDecimalInputFunctionParameter("is-in-interval","is-in-interval.b",isInIntervalB);
00085   engine.registerDecimalInputFunctionParameter("is-in-interval","is-in-interval.value",isInIntervalValue);
00086 
00087 }
00088 
00089 void MathFunctions::update()
00090 {
00091 }
00092 
00093 double MathFunctions::distanceTo()
00094 {
00095   return Geometry::distanceTo(robotPose,Vector2<double>(distanceToX,distanceToY));
00096 }
00097 
00098 double MathFunctions::angleTo()
00099 {
00100   return toDegrees(Geometry::angleTo(robotPose,Vector2<double>(angleToX,angleToY)));
00101 }
00102 
00103 double MathFunctions::getSgn()
00104 {
00105   return sgnValue > 0 ? 1 : -1;
00106 }
00107 
00108 double MathFunctions::getAbs()
00109 {
00110   return fabs(absValue);
00111 }
00112 
00113 double MathFunctions::getMin()
00114 {
00115   if (min0Value < min1Value)
00116     return min0Value;
00117   return min1Value;
00118 }
00119 
00120 double MathFunctions::getMax()
00121 {
00122   if (max0Value > max1Value)
00123     return max0Value;
00124   return max1Value;
00125 }
00126 
00127 double MathFunctions::getSin()
00128 {
00129   return sin(fromDegrees(alphaValue));
00130 }
00131 
00132 double MathFunctions::getCos()
00133 {
00134   return cos(fromDegrees(alphaValue));
00135 }
00136 
00137 double MathFunctions::getRandom()
00138 {
00139   return ((double) rand() / (RAND_MAX+1.0));
00140 }
00141 
00142 double MathFunctions::getNormalize()
00143 {
00144   return toDegrees(normalize(fromDegrees(normalizeAngle)));
00145 }
00146 
00147 double MathFunctions::getFrozenValue()
00148 {
00149   if (unFreezeValue == 1)
00150   {
00151     frozenValue = valueToFreeze;
00152     unFreezeValue = 0;
00153   }
00154   return frozenValue;
00155 }
00156 
00157 double MathFunctions::isInInterval()
00158 {
00159    if (isInIntervalA < isInIntervalB)
00160    {
00161         if ((isInIntervalA <= isInIntervalValue) && (isInIntervalValue <= isInIntervalB))
00162     {
00163       return 1;
00164     }
00165     else
00166     {
00167       return 0;
00168     }
00169    }
00170    else 
00171    {
00172      if ((isInIntervalB <= isInIntervalValue) && (isInIntervalValue <= isInIntervalA))
00173      {
00174        return 1;
00175      }
00176      else
00177      {
00178        return 0;
00179      }
00180    }
00181 }
00182 
00183 
00184 /*
00185 * Change Log
00186 * 
00187 * $Log: MathFunctions.cpp,v $
00188 * Revision 1.1.1.1  2004/05/22 17:16:58  cvsadm
00189 * created new repository GT2004_WM
00190 *
00191 * Revision 1.5  2004/04/08 15:33:01  wachter
00192 * GT04 checkin of Microsoft-Hellounds
00193 *
00194 * Revision 1.4  2004/03/16 14:00:21  juengel
00195 * Integrated Improvments from "Günne"
00196 * -ATH2004ERS7Behavior
00197 * -ATHHeadControl
00198 * -KickSelectionTable
00199 * -KickEditor
00200 *
00201 * Revision 1.3  2004/03/08 00:58:56  roefer
00202 * Interfaces should be const
00203 * Revision 1.2  2004/03/11 17:32:20  loetzsch
00204 * added input function "angle-to"
00205 *
00206 * Revision 1.2  2004/01/08 13:51:22  loetzsch
00207 * added input function sin and cos
00208 *
00209 * Revision 1.1  2003/10/22 22:18:44  loetzsch
00210 * prepared the cloning of the GT2003BehaviorControl
00211 *
00212 * Revision 1.1  2003/10/06 13:39:28  cvsadm
00213 * Created GT2004 (M.J.)
00214 *
00215 * Revision 1.2  2003/07/02 17:48:01  risler
00216 * added math function abs
00217 *
00218 * Revision 1.1.1.1  2003/07/02 09:40:23  cvsadm
00219 * created new repository for the competitions in Padova from the 
00220 * tamara CVS (Tuesday 2:00 pm)
00221 *
00222 * removed unused solutions
00223 *
00224 * Revision 1.3  2003/06/24 10:08:23  risler
00225 * added function normalize
00226 *
00227 * Revision 1.2  2003/06/19 14:48:24  risler
00228 * symbol random added
00229 *
00230 * Revision 1.1  2003/05/07 17:54:39  juengel
00231 * Added missing symbols to GT2003BehaviorControl.
00232 *
00233 */
00234 

Generated on Thu Sep 23 19:57:25 2004 for GT2004 by doxygen 1.3.6