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

Tools/PotentialFields/Motionfield.h

Go to the documentation of this file.
00001 /**
00002 * @file Motionfield.h
00003 * 
00004 * Definition of class Motionfield
00005 *
00006 * @author <a href="mailto:timlaue@informatik.uni-bremen.de">Tim Laue</a>
00007 */
00008 
00009 #ifndef MOTIONFIELD_H_
00010 #define MOTIONFIELD_H_
00011 
00012 
00013 #include "PfieldConfig.h"
00014 #include "AStarSearch.h"
00015 #include "Pfield.h"
00016 #include "RandomMotionGenerator.h"
00017 
00018 
00019 /** A type for A* search in a potential field*/
00020 typedef AStarSearch<PotentialfieldAStarNode,PotentialfieldAStarParameterSet,double> PfieldAStarSearch;
00021 
00022 
00023 /**
00024 * @class Motionfield
00025 *
00026 * A class for computing a motion by using a potential field
00027 */
00028 class Motionfield : public Potentialfield
00029 {
00030 public:
00031   /** Constructor */
00032   Motionfield(const std::string& name);
00033 
00034   /** Destructor */
00035   virtual ~Motionfield();
00036 
00037   /** Computes the result of a field
00038   * @param pose The pose on which the field affects
00039   * @param result The returned result
00040   */
00041   void execute(const PfPose& pose, PotentialfieldResult& result);
00042 
00043   /** Activates or deactivates the degrees of freedom of the field
00044   * @param translation Deactivates translation if true
00045   * @param rotation Deactivates rotation if true
00046   */
00047   void disableDegreesOfFreedom(bool translation, bool rotation)
00048   { translationDisabled = translation; rotationDisabled = rotation;}
00049 
00050   /** Sets the acceleration limits
00051   * @param maxAccel The maximum acceleration per second
00052   * @param maxGradientDifference Maximum difference to last gradient in radiant per second
00053   */
00054   void setAccelerationLimits(double maxAccel, double maxGradientDifference)
00055   { this->maxAccel = maxAccel; this->maxGradientDifference = maxGradientDifference;};
00056 
00057   /** Adds a random device to this field
00058   * @param randomMotionGenerator A random motion generator
00059   */
00060   void addRandomMotionGenerator(RandomMotionGenerator* randomMotionGenerator)
00061   { this->randomMotionGenerator = randomMotionGenerator;}
00062 
00063   /** Adds a path planner to this a field
00064   * @param pathPlanner The path planner
00065   * @param useAlways Flag: use always the path planner, if true
00066   * @param goal The object to plan a path to
00067   * @param parameterSet The parameter set for path planning
00068   * @param maxGradientLength The maximum allowed gradient length for not using path planning
00069   */
00070   void addPathPlanner(
00071       PfieldAStarSearch* pathPlanner, bool useAlways, Object* goal, 
00072       const PotentialfieldAStarParameterSet& parameterSet, double maxGradientLength)
00073   { 
00074     this->pathPlanner = pathPlanner; 
00075     alwaysUsePathPlanner = useAlways;
00076     this->goal = goal;
00077     this->aStarParameterSet = parameterSet;
00078     this->aStarParameterSet.field = this;
00079     this->maxGradientLengthForLocalMinimum = maxGradientLength;
00080   }
00081 
00082   /** Computes a random vector
00083   * @return A random vector
00084   */
00085   PfVec getRandomVector()
00086   { 
00087     if(randomMotionGenerator) 
00088       return randomMotionGenerator->getMotionVector();
00089     else 
00090       return PfVec(0.0,0.0);
00091   }
00092 
00093   /** Returns the type of the field
00094   * @return The type
00095   */
00096   BehaviorFieldType getBehaviorFieldType() const
00097   { return MOTION_FIELD;}
00098 
00099 protected:
00100   /** Flag: translation is disabled or not*/
00101   bool translationDisabled;
00102   /** Flag: rotation is disabled or not*/
00103   bool rotationDisabled;
00104   /** Maximum acceleration in vector lengths per square second*/
00105   double maxAccel;
00106   /** Maximum difference to last gradient in radiant per second*/
00107   double maxGradientDifference;
00108   /** A pointer to a random motion generator*/
00109   RandomMotionGenerator* randomMotionGenerator;
00110   /** A pointer to an A* path planner*/
00111   PfieldAStarSearch* pathPlanner;
00112   /** The parameter set for path planning*/
00113   PotentialfieldAStarParameterSet aStarParameterSet;
00114   /** Flag, true, if the pathPlanner is always used*/
00115   bool alwaysUsePathPlanner;
00116   /** Flag, true if the pathPlanner is currently used*/
00117   bool pathPlannerActive;
00118   /** The goal for planning*/
00119   Object* goal;
00120   /** The length of the path generated by the planner*/
00121   double plannedPathLengthToGoal;
00122   /** The upper limit for the gradient length to detect a local minimum*/
00123   double maxGradientLengthForLocalMinimum;
00124   /** The last computed motion vector*/
00125   PfVec lastMotionVector;
00126 
00127   /** Computes a motion vector using A* search
00128   * @param pose The beginning of the path
00129   * @return A vector
00130   */
00131   PfVec getFieldVecFromAStarSearch(const PfPose& pose);
00132 
00133   /** Checks if the field has reached a local minimum
00134   * @param currentGradientLength The length of the current gradient vector
00135   * @return true, if a local minimum has been reached
00136   */
00137   bool reachedLocalMinimum(double currentGradientLength);
00138 
00139   /** Checks if the path planner may be turned off
00140   * @param pose The beginning of the path
00141   * @return false, if the path planner may be turned off
00142   */
00143   bool pathPlanningStillNeeded(const PfPose& pose);
00144 
00145    /** Corrects computed motion vector considering maximum acceleration values
00146   * @param motionVec The vector to be corrected
00147   */
00148   void correctMotionVector(PfVec& motionVec) const;
00149 };
00150 
00151 
00152 #endif  //MOTIONFIELD_H_
00153 
00154 
00155 
00156 /*
00157 * $Log: Motionfield.h,v $
00158 * Revision 1.2  2004/06/07 18:19:39  tim
00159 * removed dynamic_cast and RTTI
00160 *
00161 * Revision 1.1.1.1  2004/05/22 17:37:28  cvsadm
00162 * created new repository GT2004_WM
00163 *
00164 * Revision 1.1  2004/01/20 15:42:19  tim
00165 * Added potential fields implementation
00166 *
00167 * Revision 1.3  2003/06/13 14:27:58  tim
00168 * added random generator and tangential fields
00169 *
00170 * Revision 1.2  2003/04/02 14:39:11  tim
00171 * Changed Bremen Byters Behavior
00172 *
00173 * Revision 1.1  2003/03/23 17:51:27  tim
00174 * Added potentialfields
00175 *
00176 */

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