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

Tools/PotentialFields/FormationObject.h

Go to the documentation of this file.
00001 /**
00002 * @file FormationObject.h
00003 * 
00004 * Definition of class FormationObject
00005 *
00006 * @author <a href="mailto:timlaue@informatik.uni-bremen.de">Tim Laue</a>
00007 */
00008 
00009 #ifndef FORMATIONOBJECT_H_
00010 #define FORMATIONOBJECT_H_
00011 
00012 
00013 #include <string>
00014 #include <vector>
00015 #include "FieldObject.h"
00016 #include "PotentialFunctions.h"
00017 #include "PfieldDatatypes.h"
00018 
00019 class PotentialfieldComposition;
00020 
00021 
00022 /** A type used by RelativeFormation to distinguish between two coordinate systems*/
00023 enum FormationCoordinates {RELATIVE_FORMATION, ABSOLUTE_FORMATION}; 
00024 
00025 /** A type used by BestFitFormation to describe the selection criterion*/
00026 enum BestFitSelection {SELECT_MAX_GRADIENT, SELECT_MIN_GRADIENT, 
00027                        SELECT_MIN_DISTANCE, SELECT_MAX_PRIORITY};
00028 
00029 
00030 /**
00031 * @class SingleFormation
00032 *
00033 * An abstract class representing a simple formation
00034 */
00035 class SingleFormation
00036 {
00037 public:
00038   /** Constructor*/
00039   SingleFormation();
00040 
00041   /** Destructor*/
00042   virtual ~SingleFormation(){}
00043 
00044   /** Checks if the formation is active
00045   * @return true, if the formation is active
00046   */
00047   virtual bool isActive() const
00048   { return false;}
00049 
00050   /** Checks if the formation has a static position
00051   * @return true, if the formation has a static position
00052   */
00053   virtual bool isStatic() const;
00054 
00055   /** Returns the position of the formation in reference to the robot pose
00056   *   (used for A*-search to a formation)
00057   * @param robotPose The robot pose
00058   * @return The position of the formation
00059   */
00060   virtual PfVec getPosition(const PfPose& robotPose);
00061 
00062   /** Returns the field vector to/from a formation to/from a given pose
00063   * @param otherPose The pose on which the formation affects
00064   * @return The vector
00065   */
00066   virtual PfVec getVec(const PfPose& otherPose);
00067 
00068   /** Returns the field charge of the formation at a given pose
00069   * @param otherPose The pose
00070   * @return The charge of the formation
00071   */
00072   virtual double getCharge(const PfPose& otherPose);
00073 
00074   /** Returns the distance between a pose and the formation area
00075   * @param otherPose The pose
00076   * @return The distance
00077   */
00078   double getDistanceToFormation(const PfPose& otherPose) const;
00079 
00080   /** Adds an object to the formation
00081   * @param object The object
00082   */
00083   void addObject(Object* object);
00084 
00085   /** Sets the function of the field of the formation
00086   * @param function The function
00087   */
00088   void setFunction(PotentialfieldFunction* function)
00089   { this->geometricFormationObject.setFunction(function);}
00090 
00091   /** Sets the priority of the formation
00092   * @param priority
00093   */
00094   void setPriority(double priority)
00095   { this->priority = priority;}
00096 
00097   /** Returns the priority of the formation
00098   * @return The priority
00099   */
00100   double getPriority() const
00101   { return priority;}
00102 
00103   /** Initializes the formation*/
00104   void init()
00105   { updateGeometry();}
00106 
00107   /** Checks if a position is inside the formation area
00108   * @param p The position
00109   * @return true, if the position is inside
00110   */
00111   virtual bool positionInsideFormation(const PfVec& p) const
00112   { return false;}
00113 
00114   /** Creates a copy of the formation object
00115   * @return A pointer to a copy
00116   */
00117   virtual SingleFormation* copy() const;
00118 
00119 protected:
00120   /** The objects the formation is spanning*/
00121   std::vector<Object*> objects;
00122   /** An object representing the shape of the formation*/
00123   Object geometricFormationObject;
00124   /** The position of the robot (kept for internal purposes)*/
00125   PfVec robotPosition;
00126   /** The priority of the formation (may be used for selection)*/
00127   double priority;
00128   /** Updates the positions of the formation*/
00129   virtual void updateGeometry() {};
00130 
00131 };
00132 
00133 
00134 /**
00135 * @class BetweenFormation
00136 *
00137 * A class representing a formation between two other objects
00138 */
00139 class BetweenFormation: public SingleFormation
00140 {
00141 public:
00142   /** Constructor*/
00143   BetweenFormation();
00144 
00145   /** Checks if the formation is active
00146   * @return true, if the formation is active
00147   */
00148   bool isActive() const;
00149 
00150   /** Checks if a position is inside the formation area
00151   * @param p The position
00152   * @return true, if the position is inside
00153   */
00154   virtual bool positionInsideFormation(const PfVec& p) const;
00155 
00156 protected:
00157   /** Updates the positions of the formation*/
00158   virtual void updateGeometry();
00159 };
00160 
00161 
00162 /**
00163 * @class AmongFormation
00164 *
00165 * A class representing a formation among several objects
00166 */
00167 class AmongFormation: public SingleFormation
00168 {
00169 public:
00170   /** Constructor*/
00171   AmongFormation();
00172 
00173   /** Checks if the formation is active
00174   * @return true, if the formation is active
00175   */
00176   bool isActive() const;
00177 
00178   /** Checks if a position is inside the formation area
00179   * @param p The position
00180   * @return true, if the position is inside
00181   */
00182   virtual bool positionInsideFormation(const PfVec& p) const;
00183 
00184 protected:
00185   /** Updates the positions of the formation*/
00186   virtual void updateGeometry();
00187 };
00188 
00189 
00190 /**
00191 * @class RelativeFormation
00192 *
00193 * A class representing a formation relative to another object
00194 */
00195 class RelativeFormation: public SingleFormation
00196 {
00197 public:
00198   /** Constructor*/
00199   RelativeFormation();
00200 
00201   /** Checks if the formation is active
00202   * @return true, if the formation is active
00203   */
00204   bool isActive() const;
00205 
00206   /** Sets the two specific parameters of a RelativeFormation
00207   * @param angle The angle to the other object
00208   * @param coordinates The coordinate system used
00209   */
00210   void setParameters(double angle, FormationCoordinates coordinates)
00211   { this->angle = angle; this->coordinates = coordinates;}
00212 
00213   /** Creates a copy of the formation object
00214   * @return A pointer to a copy
00215   */
00216   SingleFormation* copy() const;
00217 
00218 protected:
00219   /** The angle to the other object*/
00220   double angle;
00221   /** The coordinate system used*/
00222   FormationCoordinates coordinates;
00223 
00224   /** Updates the positions of the formation*/
00225   virtual void updateGeometry();
00226 };
00227 
00228 
00229 /**
00230 * @class BestFitFormation
00231 *
00232 * A class representing a formation selection the "best fitting"
00233 * formation out of a set of SingleFormations.
00234 */
00235 class BestFitFormation: public SingleFormation
00236 {
00237 public:
00238   /** Constructor*/
00239   BestFitFormation();
00240 
00241   /** Destructor*/
00242   ~BestFitFormation();
00243 
00244   /** Checks if the formation is active
00245   * @return true, if the formation is active
00246   */
00247   bool isActive() const;
00248 
00249   /** Checks if the formation has a static position
00250   * @return true, if the formation has a static position
00251   */
00252   bool isStatic() const;
00253 
00254   /** Returns the position of the formation in reference to the robot pose
00255   *   (used for A*-search to a formation)
00256   * @param robotPose The robot pose
00257   * @return The position of the formation
00258   */
00259   virtual PfVec getPosition(const PfPose& robotPose);
00260 
00261   /** Returns the field vector to/from a formation to/from a given pose
00262   * @param otherPose The pose on which the formation affects
00263   * @return The vector
00264   */  
00265   PfVec getVec(const PfPose& otherPose);
00266 
00267   /** Returns the field charge of the formation at a given pose
00268   * @param otherPose The pose
00269   * @return The charge of the formation
00270   */
00271   double getCharge(const PfPose& otherPose);
00272 
00273   /** Adds a single formation to the set of formations
00274   * @param formation The formation
00275   */
00276   void addFormation(SingleFormation* formation)
00277   { 
00278     formations.push_back(formation);
00279     resultVecs.push_back(PfVec(0.0,0.0));
00280     resultDistances.push_back(0.0);
00281   }
00282 
00283   /** Sets the criterion for choosing the best fitting formation
00284   * @param bestFitSelection The selection criterion
00285   */
00286   void setBestFitSelection(BestFitSelection bestFitSelection)
00287   { this->bestFitSelection = bestFitSelection;}
00288 
00289   /** Creates a copy of the formation object
00290   * @return A pointer to a copy
00291   */
00292   SingleFormation* copy() const;
00293 
00294 protected:
00295   /** The set of formations*/
00296   std::vector<SingleFormation*> formations;
00297   /** A list of vectors corresponding to the formations*/
00298   std::vector<PfVec> resultVecs;
00299   /** A list of distances corresponding to the formations*/
00300   std::vector<double> resultDistances;
00301   /** The selection criterion*/
00302   BestFitSelection bestFitSelection;
00303 
00304   /** Updates the positions of the formation*/
00305   virtual void updateGeometry() {};
00306 
00307   /** Determines the best formation
00308   * @param otherPose The pose to find the bestFormationFor
00309   * @return The index of the best formation, -1 if none exists
00310   */
00311   int findBestFormation(const PfPose& otherPose);
00312 };
00313 
00314 
00315 /**
00316 * @class FormationObject
00317 *
00318 * A class representing a formation in a potential field
00319 */
00320 class FormationObject: public Object
00321 {
00322 public:
00323   /** Constructor 
00324   * @param name The name of the formation object
00325   */
00326   FormationObject(const std::string& name);
00327 
00328   /** Destructor */
00329   virtual ~FormationObject();
00330 
00331   /** Returns the pose of the object in reference to the robot pose
00332   *   (used for getting a pose from formation objects)
00333   * @param robotPose The robot pose
00334   * @return The object pose
00335   */
00336   virtual PfPose getPose(const PfPose& robotPose);
00337 
00338   /** Computes the gradient of the formation at a given pose
00339   * @param otherPose The pose
00340   * @return The gradient (= f'(otherPose))
00341   */
00342   virtual PfVec computeAbsFieldVecAt(const PfPose& otherPose);
00343 
00344   /** Computes the "charge" of the formation at a given pose
00345   * @param otherPose The pose
00346   * @return The charge (= f(otherPose))
00347   */
00348   virtual double computeChargeAt(const PfPose& otherPose);
00349   
00350   /** Return whether the object is static or not
00351   * @return true, if the object is static
00352   */
00353   virtual bool isStatic() const;
00354 
00355   /** Returns whether the object is active or not
00356   * @return true, if active
00357   */
00358   virtual bool isActive() const;
00359 
00360   /** Returns a pointer to the geometry of the object
00361   * @return The geometric description
00362   */
00363   virtual PfieldGeometricObject* getGeometry() const
00364   { return NULL;}
00365 
00366   /** Returns a pointer to the absolute geometry of the object
00367   * @return The geometric description
00368   */
00369   virtual PfieldGeometricObject* getAbsGeometry() const
00370   { return NULL;}
00371  
00372   /** Overrides function from Object, does nothing*/
00373   virtual void updateData() {}
00374 
00375   /** Polymorph copy function
00376   * @return A copy of the FormationObject
00377   */
00378   virtual Object* getCopy();
00379 
00380   /** Adds a new formation to his object
00381   * @param formation The formation
00382   */
00383   void addSingleFormation(SingleFormation* formation)
00384   { singleFormations.push_back(formation);}
00385 
00386 protected:  
00387   /** The list of single formations belonging to this object*/
00388   std::vector< SingleFormation* > singleFormations;
00389 };
00390 
00391 
00392 #endif  //FORMATIONOBJECT_H_
00393 
00394 
00395 /*
00396 * $Log: FormationObject.h,v $
00397 * Revision 1.1.1.1  2004/05/22 17:37:26  cvsadm
00398 * created new repository GT2004_WM
00399 *
00400 * Revision 1.1  2004/01/20 15:42:19  tim
00401 * Added potential fields implementation
00402 *
00403 */

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