00001
00002
00003
00004
00005
00006
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
00020 typedef AStarSearch<PotentialfieldAStarNode,PotentialfieldAStarParameterSet,double> PfieldAStarSearch;
00021
00022
00023
00024
00025
00026
00027
00028 class Motionfield : public Potentialfield
00029 {
00030 public:
00031
00032 Motionfield(const std::string& name);
00033
00034
00035 virtual ~Motionfield();
00036
00037
00038
00039
00040
00041 void execute(const PfPose& pose, PotentialfieldResult& result);
00042
00043
00044
00045
00046
00047 void disableDegreesOfFreedom(bool translation, bool rotation)
00048 { translationDisabled = translation; rotationDisabled = rotation;}
00049
00050
00051
00052
00053
00054 void setAccelerationLimits(double maxAccel, double maxGradientDifference)
00055 { this->maxAccel = maxAccel; this->maxGradientDifference = maxGradientDifference;};
00056
00057
00058
00059
00060 void addRandomMotionGenerator(RandomMotionGenerator* randomMotionGenerator)
00061 { this->randomMotionGenerator = randomMotionGenerator;}
00062
00063
00064
00065
00066
00067
00068
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
00083
00084
00085 PfVec getRandomVector()
00086 {
00087 if(randomMotionGenerator)
00088 return randomMotionGenerator->getMotionVector();
00089 else
00090 return PfVec(0.0,0.0);
00091 }
00092
00093
00094
00095
00096 BehaviorFieldType getBehaviorFieldType() const
00097 { return MOTION_FIELD;}
00098
00099 protected:
00100
00101 bool translationDisabled;
00102
00103 bool rotationDisabled;
00104
00105 double maxAccel;
00106
00107 double maxGradientDifference;
00108
00109 RandomMotionGenerator* randomMotionGenerator;
00110
00111 PfieldAStarSearch* pathPlanner;
00112
00113 PotentialfieldAStarParameterSet aStarParameterSet;
00114
00115 bool alwaysUsePathPlanner;
00116
00117 bool pathPlannerActive;
00118
00119 Object* goal;
00120
00121 double plannedPathLengthToGoal;
00122
00123 double maxGradientLengthForLocalMinimum;
00124
00125 PfVec lastMotionVector;
00126
00127
00128
00129
00130
00131 PfVec getFieldVecFromAStarSearch(const PfPose& pose);
00132
00133
00134
00135
00136
00137 bool reachedLocalMinimum(double currentGradientLength);
00138
00139
00140
00141
00142
00143 bool pathPlanningStillNeeded(const PfPose& pose);
00144
00145
00146
00147
00148 void correctMotionVector(PfVec& motionVec) const;
00149 };
00150
00151
00152 #endif //MOTIONFIELD_H_
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176