ObstacleAvoidance.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00029
00030
00034
00035
00036 #ifndef __OBSTACLE_AVOIDANCE_H_
00037 #define __OBSTACLE_AVOIDANCE_H_
00038
00039 #include <Task.h>
00040 #include <Resource.h>
00041 #include <MobileRob.h>
00042 #include <MobileRob3D.h>
00043 #include <IPCommModule.h>
00044 #include <CommonOptions.h>
00045
00046
00047 #include <ObsAvoiAlgoPFM.h>
00048 #include <ObsAvoiAlgoVFH.h>
00049 #include <ObsAvoiAlgoLIP.h>
00050 #include <ObsAvoiAlgoSND.h>
00051
00052 #include <Serialization.h>
00053 #include <SharedMem.h>
00054
00055
00056 using namespace MipAlgorithms;
00057 using namespace MipResources;
00058
00059
00060 namespace MipTasks{
00061
00063
00064
00065
00069 enum ObstacleAvoidanceState{
00070 obstacleAvoidance_FIRST_RUN,
00071 obstacleAvoidance_OBS_AV_NORMAL_RUN,
00072 obstacleAvoidance_NUM_RUNS
00073 };
00074
00075
00079 enum ObstacleAvoidanceMethods{
00080 OBS_AV_NO,
00081 OBS_AV_LIP,
00082 OBS_AV_PFM,
00083 OBS_AV_VFH,
00084 OBS_AV_SND,
00085 OBS_AV_NUM_METHODS
00086 };
00087
00088
00092 enum ObstacleAvoidanceInputTypes{
00093 OBS_AV_POSITION,
00094 OBS_AV_SPEED,
00095 OBS_AV_NUM_INPUT_TYPES
00096 };
00097
00098
00102 class ObstacleAvoidanceOptions : public Options {
00103 public:
00104 StringOption* input;
00105 DecimalOption* obstacleAvoidanceGoalX;
00106 DecimalOption* obstacleAvoidanceGoalY;
00107 DecimalOption* obstacleAvoidanceGoalZ;
00108 DecimalOption* obstacleAvoidanceGoalTheta;
00109 StringOption* obstacleAvoidanceMethod;
00110
00111 string getObjectName() const {
00112 return "ObstacleAvoidanceOptions";
00113 }
00114
00115 ObstacleAvoidanceOptions(){
00116 input = createStringOption("obstacleAvoidanceInput", "Choose among position (default) and speed (drive,turnrate) input", "position");
00117 obstacleAvoidanceGoalX = createDecimalOption("obstacleAvoidanceGoalX", "X coordinate of the Goal pose", 0.0);
00118 obstacleAvoidanceGoalY = createDecimalOption("obstacleAvoidanceGoalY", "Y coordinate of the Goal pose", 0.0);
00119 obstacleAvoidanceGoalZ = createDecimalOption("obstacleAvoidanceGoalZ", "Z coordinate of the Goal pose", 0.0);
00120 obstacleAvoidanceGoalTheta = createDecimalOption("obstacleAvoidanceGoalTheta","Angle (rad) of the Goal pose", 0.0);
00121 obstacleAvoidanceMethod = createStringOption("obstacleAvoidanceMethod", "Choose among NO (NO obstacle avoidance, only actractive potential), PFM (Potential Field Method), LIP (default)(Local Incremental Planning), VFH (Vector Field Histogramm)", "LIP");
00122 updateValues();
00123 }
00124 };
00125
00126
00130 class ObstacleAvoidanceSharedMem : public SharedMem{
00131 public:
00132 };
00133
00134
00138 class ObstacleAvoidancePar {
00139 private:
00140 public:
00142 Decimal goalReachedEps;
00144 Decimal Kv;
00146 Decimal Kw;
00148 Decimal Kwe;
00150 ObstacleAvoidanceInputTypes obAvInputType;
00151
00153 ObstacleAvoidancePar(){
00154
00155 goalReachedEps=0.03;
00156
00157 Kv=0.3;
00158 Kw=0.8;
00159 Kwe=0.3;
00160
00161 obAvInputType=OBS_AV_POSITION;
00162 }
00163
00165 ObstacleAvoidancePar(ObstacleAvoidanceOptions& options){
00166
00167 if (options.obstacleAvoidanceMethod->getValue()=="VFH") goalReachedEps=0.07;
00168 else goalReachedEps=0.03;
00169
00170 Kv=0.3;
00171 Kw=0.8;
00172 Kwe=0.3;
00173
00174 obAvInputType = OBS_AV_NUM_INPUT_TYPES;
00175 if(options.input->getValue() == "speed"){
00176 obAvInputType=OBS_AV_SPEED;
00177 } else if (options.input->getValue() == "position"){
00178 obAvInputType=OBS_AV_POSITION;
00179 }
00180 assert(obAvInputType < OBS_AV_NUM_INPUT_TYPES);
00181 }
00182
00184 ObstacleAvoidancePar(Decimal VmaxP, Decimal WmaxP, Decimal goalReachedEpsP, Decimal KvP, Decimal KwP, Decimal KweP,ObstacleAvoidanceInputTypes obstacleAvoidanceInputP){
00185 goalReachedEps=goalReachedEpsP;
00186 Kv=KvP;
00187 Kw=KwP;
00188 Kwe=KweP;
00189 obAvInputType=obstacleAvoidanceInputP;
00190 }
00191
00193 ObstacleAvoidancePar(const ObstacleAvoidancePar &A){
00194 goalReachedEps=A.goalReachedEps;
00195 Kv=A.Kv;
00196 Kw=A.Kw;
00197 Kwe=A.Kwe;
00198 obAvInputType=A.obAvInputType;
00199 }
00200
00202 ObstacleAvoidancePar operator= (ObstacleAvoidancePar A){
00203 goalReachedEps=A.goalReachedEps;
00204 Kv=A.Kv;
00205 Kw=A.Kw;
00206 Kwe=A.Kwe;
00207 obAvInputType=A.obAvInputType;
00208 }
00209 };
00210
00211
00215 class ObstacleAvoidance : public Task{
00216 private:
00217 static const TaskPlate _plate = OBA_TASK;
00218 static const long int _maxDurSec = 0, _maxDurUsec = 100000;
00219 static const long int _maxSamplPeriodSec = 0, _maxSamplPeriodUsec = 150000;
00220 static const long int _minSamplPeriodSec = 0, _minSamplPeriodUsec = 100000;
00221
00222 static const long int TRACE_ON_DEFAULT = 0;
00223 static const long int COMM_TRACE_ON_DEFAULT = 0;
00224 static const long int BACK_VEL_DEFAULT = 0;
00225
00226 MobileRob* _mobileRob;
00227 MobileRob3D* _mobileRob3D;
00228 CommModule* _commModule;
00229
00230 bool useMobileRob;
00231 bool useMobileRob3D;
00232
00233 ObstacleAvoidanceSharedMem* _sharedMem;
00234
00235 bool commTraceOn;
00236 bool traceOn;
00237
00238
00239 #ifndef MIP_PLATFORM_ARM
00240 DraWin* _draWin;
00241 unsigned int _drawList;
00242 bool dwOn;
00243 #endif
00244
00245 void draw();
00246
00247
00249 ObstacleAvoidanceState state;
00250 ObstacleAvoidancePar par;
00252 ObstacleAvoidanceMethods method;
00253
00255 bool backVelOn;
00256
00258 ObsAvoiAlgoSNDParams* sndParams;
00259 ObsAvoiAlgoLIPParams* lipParams;
00260 ObsAvoiAlgo* OA;
00261 ObsAvoiAlgoIn OAin;
00262 ObsAvoiAlgoOut OAout;
00263
00265 Pose robPose;
00266 Pose3D robPose3D;
00268 Scan scan;
00269
00271 Pose goal;
00272 Pose3D goal3D;
00273 Position goalVel;
00274
00276 Decimal traveledDistance;
00277
00279 Decimal V;
00281 Decimal W;
00282
00283 Timer controlPeriod;
00284
00286 ObstacleAvoidanceOptions options;
00287
00289 void firstRun();
00291 void normalRun();
00292
00294 void getCommPackets();
00296 void getPoseAndScan();
00298 void getGoal();
00300 void getGoalVel();
00302 void getControl();
00304 void drivePos();
00306 void driveVel();
00307
00309 void attractiveControl();
00311 void velSat();
00312
00313 public:
00315 ObstacleAvoidance(ResourcePointers resources,int argc, const char* argv[]);
00316
00318
00319
00320
00321
00322
00324 ~ObstacleAvoidance(){
00325 if (traceOn) cout << "destr ObstacleAvoidance" << endl;
00326 }
00327
00329 TaskPlate getPlate() const {
00330 return _plate;
00331 }
00333 Time getMaxDuration(){
00334 return Time(_maxDurSec,_maxDurUsec);
00335 }
00337 Time getMaxSamplPeriod(){
00338 return Time(_maxSamplPeriodSec,_maxSamplPeriodUsec);
00339 }
00341 Time getMinSamplPeriod(){
00342 return Time(_minSamplPeriodSec,_minSamplPeriodUsec);
00343 }
00344
00346 TaskOutputs run(){
00347 switch(state){
00348 case obstacleAvoidance_FIRST_RUN:
00349 firstRun();
00350 state = obstacleAvoidance_OBS_AV_NORMAL_RUN;
00351 break;
00352 case obstacleAvoidance_OBS_AV_NORMAL_RUN:
00353 normalRun();
00354 break;
00355 }
00356 return TASK_OUT_GO_ON;
00357 }
00358 };
00359
00360
00361
00362 };
00363
00364 #endif
00365
00366
00367
00368
00369