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

# Tools/PotentialFields/Actionfield.h

Go to the documentation of this file.

    00001 /**
    00002 * @file Actionfield.h
    00003 *
    00004 * Definition of class Actionfield
    00005 *
    00006 * @author <a href="mailto:timlaue@informatik.uni-bremen.de">Tim Laue</a>
    00007 */
    00008
    00009 #ifndef ACTIONFIELD_H_
    00010 #define ACTIONFIELD_H_
    00011
    00012
    00013 #include "PfieldConfig.h"
    00014 #include "PfieldDatatypes.h"
    00015 #include "Pfield.h"
    00016 #include "PfieldGeometry.h"
    00017 #include <vector>
    00018 #include <cfloat>
    00019
    00020 class FutureWorldModelGenerator;
    00021 class PotentialfieldTransformation;
    00022 class PotentialFieldsObject;
    00023
    00024
    00025 /** A type for setting the type of an Actionfield*/
    00026 enum ActionfieldType {SINGLE_ACTION_FIELD, FIXED_SEQUENCE_FIELD, BEST_SEQUENCE_FIELD};
    00027
    00028 /** A type for setting the type of an Action*/
    00029 enum ActionType {MOVE_OBJECT, MOVE_SELF, MEASURE_OBJECT, MEASURE_SELF};
    00030
    00031 /** The possible transformations*/
    00032 enum TransformationType {TRANSLATION, ROTATION, NO_TRANSFORMATION};
    00033
    00034
    00035 /**
    00036 * @class Action
    00037 *
    00038 * A class describing a single action
    00039 */
    00040 class Action
    00041 {
    00042 public:
    00043   /** The name of the action*/
    00044   std::string name;
    00045   /** The manipulated object*/
    00046   PotentialFieldsObject* manipulatedObject;
    00047   /** Index of the manipulated object in a dynamicObjects field (for internal use)*/
    00048   unsigned int objectIdx;
    00049   /** Flag, true if the robot joins the action*/
    00050   bool joinAction;
    00051   /** The impact areas*/
    00052   std::vector<Polygon> impactAreas;
    00053   /** The transformations*/
    00054   std::vector<PotentialfieldTransformation*> transformations;
    00055   /** The type of the action*/
    00056   ActionType actionType;
    00057   /** Motion parameters resulting from some transformations*/
    00058   PfPose motionParameters;
    00059   /** The time this action takes*/
    00060   double time;
    00061
    00062   /** Constructor */
    00063   Action();
    00064
    00065   /** Destructor */
    00066   ~Action();
    00067
    00068   /** Copy-Constructor
    00069   * @param a Another action
    00070   */
    00071   Action(const Action& a);
    00072
    00073   /** Checks if this Action can be applied
    00074   * @param robotPose The current pose of the robot
    00075   * @param objects A list of objects, containing a current version of the manipulated object
    00076   */
    00077   bool canBeApplied(const PfPose& robotPose,
    00078                     const std::vector<PotentialFieldsObject*>& objects);
    00079
    00080 protected:
    00081   /** Checks if a single pose is inside any of the robot's impact areas
    00082   * @param robPose The robot pose
    00083   * @param objPose The pose of an object
    00084   * @return true, if the pose is inside any impact area
    00085   */
    00086   bool poseInsideImpactArea(const PfPose& robPose, const PfPose& objPose);
    00087 };
    00088
    00089
    00090
    00091 /**
    00092 * @class Actionfield
    00093 *
    00094 * A class for selecting an action using potentialfields
    00095 */
    00096 class Actionfield : public Potentialfield
    00097 {
    00098 public:
    00099   /** Constructor */
    00100   Actionfield(const std::string& name);
    00101
    00102   /** Destructor */
    00103   virtual ~Actionfield();
    00104
    00105   /** Initializes values and / or allocates additional memory for subsequent computations.
    00106       This function should be called after all values are set and all objects and
    00107       actions have been assigned */
    00108   virtual void init();
    00109
    00110   /** Computes the result of a field
    00111   * @param pose The pose of the robot on which the field affects
    00112   * @param result The returned result
    00113   */
    00114   void execute(const PfPose& pose, PotentialfieldResult& result);
    00115
    00116   /** Adds an object to the field
    00117   * @param object The object
    00118   */
    00119   virtual void addObject(PotentialFieldsObject* object);
    00120
    00121   /** Adds an action to the field
    00122   * @param action The action
    00123   */
    00124   void addAction(const Action& action);
    00125
    00126   /** Sets the type of the action field
    00127   * @param actionfieldType The type
    00128   * @param decreasingValuesOnly Pruning option, used for sequences
    00129   * @param searchDepth The searchDepth used if (actionfieldType==FIND_BEST_SEQUENCE)
    00130   */
    00131   void setActionfieldType(ActionfieldType actionfieldType,
    00132                           bool decreasingValuesOnly=false,
    00133                           unsigned int searchDepth=0)
    00134   { this->actionfieldType = actionfieldType;
    00135     worldStateDepth = searchDepth;
    00136     this->decreasingValuesOnly = decreasingValuesOnly;}
    00137
    00138   /** Sets the value of considerTime
    00139   * @param considerTime The new value for considerTime
    00140   */
    00141   void setConsiderTime(bool considerTime)
    00142   { this->considerTime = considerTime;}
    00143
    00144   /** Computes the gradient at a spezific pose in a field consisting of all
    00145   *   static objects and all the other, possibly transformed, objects.
    00146   * @param pose The pose to compute the gradient at
    00147   * @param dynamicObjects A set of objects
    00148   * @param excludedDynamicObject An object not to use for gradient computation
    00149   * @return The gradient at pose
    00150   */
    00151   PfVec getFutureFieldVecAt(const PfPose& pose, const std::vector<PotentialFieldsObject*>& dynamicObjects,
    00152                             int excludedDynamicObject = -1);
    00153
    00154   /** Returns the type of the field
    00155   * @return The type
    00156   */
    00157   BehaviorFieldType getBehaviorFieldType() const
    00158   { return ACTION_FIELD;}
    00159
    00160 protected:
    00161   /** Container for static objects*/
    00162   std::vector<PotentialFieldsObject*> staticObjects;
    00163   /** Container for dynamic objects*/
    00164   std::vector<PotentialFieldsObject*> dynamicObjects;
    00165   /** The future world states*/
    00166   std::vector< std::vector<PotentialFieldsObject*> > futureWorldStates;
    00167   /** The future poses of the robot*/
    00168   std::vector< PfPose > futureRobotPoses;
    00169   /** The actions to be applied*/
    00170   std::vector<Action> actions;
    00171   /** A pointer to the FutureWorldModelGenerator*/
    00172   FutureWorldModelGenerator* futureWorldModelGenerator;
    00173   /** The type of this action field*/
    00174   ActionfieldType actionfieldType;
    00175   /** The depth of future world states*/
    00176   unsigned int worldStateDepth;
    00177   /** Pruning option, accept only sequences with decreasing values*/
    00178   bool decreasingValuesOnly;
    00179   /** Pruning option, maximum deviation between two action values*/
    00180   double maxTolerance;
    00181   /** Flag: true, if the time of an action when computing its value is to be considered*/
    00182   bool considerTime;
    00183
    00184   /** Computes the value at a spezific pose in a field consisting of all
    00185   *   static objects and all the other, possibly transformed, objects.
    00186   * @param pose The pose to compute the value at
    00187   * @param dynamicObjects A set of objects
    00188   * @param excludedDynamicObject An object not to use for value computation
    00189   * @return The value at pose
    00190   */
    00191   double computeValueAtPose(const PfPose& pose, const std::vector<PotentialFieldsObject*>& dynamicObjects,
    00192                             int excludedDynamicObject = -1);
    00193
    00194   /** Computes the value of an action considering the criterion
    00195   * @param action The action
    00196   * @param time The execution of the action / action sequence
    00197   * @param ownPoseBefore The robot pose before the action
    00198   * @param ownPoseAfter The robot pose after the action
    00199   * @param objectsBefore The state of the objects before the action
    00200   * @param objectsAfter The state of the objects after the action
    00201   * @param passedPruningCheck Flag: true, if the action has not to be pruned
    00202   * @return The value
    00203   */
    00204   double computeActionValue(const Action& action, double time,
    00205                             const PfPose& ownPoseBefore,
    00206                             const PfPose& ownPoseAfter,
    00207                             const std::vector<PotentialFieldsObject*>& objectsBefore,
    00208                             const std::vector<PotentialFieldsObject*>& objectsAfter,
    00209                             bool& passedPruningCheck);
    00210
    00211   /** Adds a manipulated object to the object lists (if it has not been added before) and
    00212   *   sets the objectIdx member of the action
    00213   * @param action The action manipulating the object
    00214   */
    00215   void addManipulatedObject(Action& action);
    00216
    00217   /** Searches recursively for the best possible action sequence
    00218   *   and sets the result
    00219   * @param depth The current depth
    00220   * @param robotPose The pose of the robot before any actions
    00221   * @param actionSequenceList A list with the sequence of actions
    00222   * @param time The time of the previous sequence
    00223   * @param previousValue The previous value of the sequence
    00224   * @param result The currently best result of the search
    00225   */
    00226   void findBestSequence(unsigned int depth, const PfPose& robotPose,
    00227                         std::vector<unsigned int>& actionSequenceList,
    00228                         double time, double previousValue,
    00229                         PotentialfieldResult& result);
    00230 };
    00231
    00232
    00233
    00234 /**
    00235 * @class PotentialfieldTransformation
    00236 *
    00237 * Abstract class, describing a transformation
    00238 */
    00239 class PotentialfieldTransformation
    00240 {
    00241 public:
    00242   /** The probability of a transformation*/
    00243   double probability;
    00244   /** The time a transformation takes*/
    00245   double time;
    00246
    00247   /** Destructor*/
    00248   virtual ~PotentialfieldTransformation() {};
    00249
    00250   /** Returns the type of the transformation
    00251   * @return The type
    00252   */
    00253   virtual TransformationType getType() = 0;
    00254
    00255   /** Returns a pointer to a copy of the object
    00256   * @return A pointer to a copy
    00257   */
    00258   virtual PotentialfieldTransformation* copy() = 0;
    00259 };
    00260
    00261
    00262 /**
    00263 * @class Translation
    00264 *
    00265 * Describes a translation
    00266 */
    00267 class Translation: public PotentialfieldTransformation
    00268 {
    00269 public:
    00270   /** Translation vector*/
    00271   PfVec translation;
    00272   /** Flag: true, if the transformation is along the current gradient*/
    00273   bool alongGradient;
    00274   /** Step length on the gradient (only used, if along gradient has been set)*/
    00275   double stepLength;
    00276   /** Maximum deviation from the gradient (only used, if along gradient has been set)*/
    00277   double maxGradientDeviation;
    00278   /** Maximum length of a translation (only used, if along gradient has been set)*/
    00279   double maxLength;
    00280   /** An object to translate to */
    00281   PotentialFieldsObject* toObject;
    00282   /** The speed of a translation in millimeters per second,
    00283       only used in combination with alongGradient of toObject*/
    00284   double speed;
    00285
    00286   /** Returns the type of the action
    00287   * @return The type
    00288   */
    00289   TransformationType getType()
    00290   { return TRANSLATION;}
    00291
    00292   /** Returns a pointer to a copy of the object
    00293   * @return A pointer to a copy
    00294   */
    00295   PotentialfieldTransformation* copy()
    00296   {
    00297     Translation* translation = new Translation();
    00298     translation->translation = this->translation;
    00299     translation->toObject = toObject;
    00300     translation->alongGradient = alongGradient;
    00301     translation->stepLength = stepLength;
    00302     translation->maxGradientDeviation = maxGradientDeviation;
    00303     translation->maxLength = maxLength;
    00304     translation->time = time;
    00305     translation->speed = speed;
    00306     PotentialfieldTransformation* transformation = translation;
    00307     transformation->probability = probability;
    00308     return transformation;
    00309   }
    00310 };
    00311
    00312
    00313 /**
    00314 * @class Rotation
    00315 *
    00316 * Describes a rotation
    00317 */
    00318 class Rotation : public PotentialfieldTransformation
    00319 {
    00320 public:
    00321   /** The rotation angle*/
    00322   double angle;
    00323   /** Flag: true, if the rotation has to be the angle to the current gradient*/
    00324   bool toGradient;
    00325   /** An object to rotate to */
    00326   PotentialFieldsObject* toObject;
    00327   /** The speed of a rotation in radian per second,
    00328       only used in combination with toGradient of toObject*/
    00329   double speed;
    00330
    00331   /** Returns the type of the transformation
    00332   * @return The type
    00333   */
    00334   TransformationType getType()
    00335   { return ROTATION;}
    00336
    00337   /** Returns a pointer to a copy of the object
    00338   * @return A pointer to a copy
    00339   */
    00340   PotentialfieldTransformation* copy()
    00341   {
    00342     Rotation* rotation = new Rotation();
    00343     rotation->angle = angle; rotation->toGradient = toGradient;
    00344     rotation->toObject = toObject;
    00345     rotation->time = time;
    00346     rotation->toGradient = toGradient;
    00347     rotation->speed = speed;
    00348     PotentialfieldTransformation* transformation = rotation;
    00349     transformation->probability = probability;
    00350     return transformation;
    00351   }
    00352 };
    00353
    00354
    00355 /**
    00356 * @class NoTransformation
    00357 *
    00358 * Describes no transformation ;-)
    00359 */
    00360 class NoTransformation : public PotentialfieldTransformation
    00361 {
    00362 public:
    00363   /** Returns the type of the transformation
    00364   * @return The type
    00365   */
    00366   TransformationType getType()
    00367   { return NO_TRANSFORMATION;}
    00368
    00369   /** Returns a pointer to a copy of the object
    00370   * @return A pointer to a copy
    00371   */
    00372   PotentialfieldTransformation* copy()
    00373   {
    00374     NoTransformation* noTransformation = new NoTransformation();
    00375     PotentialfieldTransformation* transformation = noTransformation;
    00376     transformation->probability = probability;
    00377     transformation->time = time;
    00378     return transformation;
    00379   }
    00380 };
    00381
    00382
    00383 #endif  //ACTIONFIELD_H_