00001
00002
00003
00004
00005
00006
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
00026 enum ActionfieldType {SINGLE_ACTION_FIELD, FIXED_SEQUENCE_FIELD, BEST_SEQUENCE_FIELD};
00027
00028
00029 enum ActionType {MOVE_OBJECT, MOVE_SELF, MEASURE_OBJECT, MEASURE_SELF};
00030
00031
00032 enum TransformationType {TRANSLATION, ROTATION, NO_TRANSFORMATION};
00033
00034
00035
00036
00037
00038
00039
00040 class Action
00041 {
00042 public:
00043
00044 std::string name;
00045
00046 PotentialFieldsObject* manipulatedObject;
00047
00048 unsigned int objectIdx;
00049
00050 bool joinAction;
00051
00052 std::vector<Polygon> impactAreas;
00053
00054 std::vector<PotentialfieldTransformation*> transformations;
00055
00056 ActionType actionType;
00057
00058 PfPose motionParameters;
00059
00060 double time;
00061
00062
00063 Action();
00064
00065
00066 ~Action();
00067
00068
00069
00070
00071 Action(const Action& a);
00072
00073
00074
00075
00076
00077 bool canBeApplied(const PfPose& robotPose,
00078 const std::vector<PotentialFieldsObject*>& objects);
00079
00080 protected:
00081
00082
00083
00084
00085
00086 bool poseInsideImpactArea(const PfPose& robPose, const PfPose& objPose);
00087 };
00088
00089
00090
00091
00092
00093
00094
00095
00096 class Actionfield : public Potentialfield
00097 {
00098 public:
00099
00100 Actionfield(const std::string& name);
00101
00102
00103 virtual ~Actionfield();
00104
00105
00106
00107
00108 virtual void init();
00109
00110
00111
00112
00113
00114 void execute(const PfPose& pose, PotentialfieldResult& result);
00115
00116
00117
00118
00119 virtual void addObject(PotentialFieldsObject* object);
00120
00121
00122
00123
00124 void addAction(const Action& action);
00125
00126
00127
00128
00129
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
00139
00140
00141 void setConsiderTime(bool considerTime)
00142 { this->considerTime = considerTime;}
00143
00144
00145
00146
00147
00148
00149
00150
00151 PfVec getFutureFieldVecAt(const PfPose& pose, const std::vector<PotentialFieldsObject*>& dynamicObjects,
00152 int excludedDynamicObject = -1);
00153
00154
00155
00156
00157 BehaviorFieldType getBehaviorFieldType() const
00158 { return ACTION_FIELD;}
00159
00160 protected:
00161
00162 std::vector<PotentialFieldsObject*> staticObjects;
00163
00164 std::vector<PotentialFieldsObject*> dynamicObjects;
00165
00166 std::vector< std::vector<PotentialFieldsObject*> > futureWorldStates;
00167
00168 std::vector< PfPose > futureRobotPoses;
00169
00170 std::vector<Action> actions;
00171
00172 FutureWorldModelGenerator* futureWorldModelGenerator;
00173
00174 ActionfieldType actionfieldType;
00175
00176 unsigned int worldStateDepth;
00177
00178 bool decreasingValuesOnly;
00179
00180 double maxTolerance;
00181
00182 bool considerTime;
00183
00184
00185
00186
00187
00188
00189
00190
00191 double computeValueAtPose(const PfPose& pose, const std::vector<PotentialFieldsObject*>& dynamicObjects,
00192 int excludedDynamicObject = -1);
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
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
00212
00213
00214
00215 void addManipulatedObject(Action& action);
00216
00217
00218
00219
00220
00221
00222
00223
00224
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
00236
00237
00238
00239 class PotentialfieldTransformation
00240 {
00241 public:
00242
00243 double probability;
00244
00245 double time;
00246
00247
00248 virtual ~PotentialfieldTransformation() {};
00249
00250
00251
00252
00253 virtual TransformationType getType() = 0;
00254
00255
00256
00257
00258 virtual PotentialfieldTransformation* copy() = 0;
00259 };
00260
00261
00262
00263
00264
00265
00266
00267 class Translation: public PotentialfieldTransformation
00268 {
00269 public:
00270
00271 PfVec translation;
00272
00273 bool alongGradient;
00274
00275 double stepLength;
00276
00277 double maxGradientDeviation;
00278
00279 double maxLength;
00280
00281 PotentialFieldsObject* toObject;
00282
00283
00284 double speed;
00285
00286
00287
00288
00289 TransformationType getType()
00290 { return TRANSLATION;}
00291
00292
00293
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
00315
00316
00317
00318 class Rotation : public PotentialfieldTransformation
00319 {
00320 public:
00321
00322 double angle;
00323
00324 bool toGradient;
00325
00326 PotentialFieldsObject* toObject;
00327
00328
00329 double speed;
00330
00331
00332
00333
00334 TransformationType getType()
00335 { return ROTATION;}
00336
00337
00338
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
00357
00358
00359
00360 class NoTransformation : public PotentialfieldTransformation
00361 {
00362 public:
00363
00364
00365
00366 TransformationType getType()
00367 { return NO_TRANSFORMATION;}
00368
00369
00370
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_