ParticleMutLocCamOffTask.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
00026
00030
00035
00036
00037
00038 #ifndef __PARTICLE_MUT_LOC_CAM_OFF_TASK_H_
00039 #define __PARTICLE_MUT_LOC_CAM_OFF_TASK_H_
00040
00041
00042 #include <Task.h>
00043 #include <Resource.h>
00044 #include <MobileRob.h>
00045 #include <DraWin.h>
00046 #include <SharedMem.h>
00047 #include <Time.h>
00048
00049 #include <MultiRegCam.h>
00050 #include <ProbMultiRegCam.h>
00051 #include <CommonOptions.h>
00052 #include <MultiReg.h>
00053 #include <ProbMultiReg.h>
00054 #include <PaFilBFL.h>
00055 #include <PaFilBFLAbsRel.h>
00056 #include <PaFilBFLRelRel.h>
00057 #include <PaFilBFLRelRelBearOnly.h>
00058 #include <CommModule.h>
00059
00060
00061 using namespace MipAlgorithms;
00062 using namespace MipResources;
00063
00064 namespace MipTasks{
00066
00067
00068
00075 enum FrameOffTypes{
00076 FIXED_OFF_FRAME,
00077 ATTACHED_OFF_FRAME,
00078 FRAME_OFF_TYPES_NUM
00079 };
00080
00081 static const char* FrameOffTypesNames[FRAME_OFF_TYPES_NUM] = {
00082 "fixed",
00083 "attached"
00084 };
00085
00086
00090 class ParticleMutLocCamOffOptions : public Options {
00091 public:
00092 DecimalOption* bLinearToll;
00093 DecimalOption* bAngularToll;
00094 IntOption* bObs0Trials;
00095 IntOption* bObs1Trials;
00096 IntOption* bMinInliersNum;
00097 DecimalOption* bPrewarpingToll;
00098
00099 DecimalOption* mLinearToll;
00100 DecimalOption* mAngularToll;
00101 DecimalOption* mMaxVisuale;
00102 DecimalOption* mDiscretizationStep;
00103
00104 DecimalOption* bmDiscretization;
00105
00106 IntOption* minObservationSize;
00107
00108 IntOption* findTarget;
00109 IntOption* targetId;
00110
00111 BoolOption* banIdActive;
00112
00113 StringOption* myFrameType;
00114 StringOption* hisFrameType;
00115 BoolOption* feedbackInMultiReg;
00116 BoolOption* bearingOnlyMeas;
00117
00118 DecimalOption* mcLinearToll;
00119 DecimalOption* mcAngularToll;
00120 DecimalOption* mcProjToll;
00121 BoolOption* mcDrawRealPos;
00122 IntOption* mcExpMethod;
00123
00124
00125 BoolOption* saveEstimates;
00126 BoolOption* saveBestEstimate;
00127 BoolOption* saveRealPos;
00128 BoolOption* saveMultiRegCam;
00129 BoolOption* doOffline;
00130 DecimalOption* thrTimeSec;
00131 DecimalOption* thrTimeUSec;
00132 StringOption* rootFileMeasOff;
00133 StringOption* rootFileTStateOff;
00134 IntOption* measType;
00135
00136 DecimalOption* timeForMeasUpdate;
00137
00138 ParticleMutLocCamOffOptions();
00139
00140 OptionGroupsType getGroup();
00141 string getObjectName() const {
00142 return "ParticleMutLocCamOffOptions";
00143 }
00144 };
00145
00146
00150 class ParticleMutLocCamOffSharedMem : public SharedMem{
00151 public:
00153 void initSharedMem();
00154
00158 PosiFeatures getMyProtrusions(MotionModuleTState &state);
00159
00163 PosiFeatures getMyObservation(MotionModuleTState &state);
00164
00168 vector<Angle> getMyCamObs(MotionModuleTState &state);
00169
00172 void setFormation(PoseFeatures &form);
00173
00176 void setEstimates(PoseFeatures &est);
00177
00180 Pose getTarget();
00181
00184 void setTarget(Pose &t);
00185
00188 bool doMloc();
00189
00192 bool printFormation();
00193
00196 bool printFormationDetails();
00197
00200 vector<int> getAvoidParticleMutLocCamOffIds();
00201 };
00202
00203
00207 class ParticleMutLocCamOffTask : public Task{
00208 private:
00209 static const TaskPlate _plate = PMO_TASK;
00210 static const long int _maxDurSec = 0, _maxDurUsec = 500000;
00211 static const long int _maxSamplPeriodSec = 1, _maxSamplPeriodUsec = 0;
00212 static const long int _minSamplPeriodSec = 0, _minSamplPeriodUsec = 400000;
00213
00214
00215 MobileRob* _mobileRob;
00216 DraWin* _draWin;
00217 unsigned int _drawList;
00218 bool _dwOn;
00219 ParticleMutLocCamOffSharedMem* _sharedMem;
00220 CommModule* _commModule;
00221
00222 FrameOffTypes _myFrameType;
00223 FrameOffTypes _hisFrameType;
00224
00225
00226 ParticleMutLocCamOffOptions _options;
00227
00228
00229 MultiReg* _multiReg;
00230 ProbMultiReg* _probMultiReg;
00231 MultiRegCam* _multiRegCam;
00232 ProbMultiRegCam* _probMultiRegCam;
00233 vector< vector<AngleId> > inputMultiRegOff;
00234 vector<pair<long int,long int> > _timeOffline;
00235 vector<Decimal> _timeOff;
00236 int countMeasOff;
00237 vector< vector<Pose> > _tStateOff;
00238 PoseFeatures _lastValidFormation;
00239
00240 map<int,MutLocFilter*> _filter;
00241 vector<int> _activatedFilters;
00242
00243 map<int,vector<Angle> > _measFromMultiBeaReg;
00244 map<int,vector<Angle> > _measFromMultiBeaRegOri;
00245 vector<int> _measFromMultiBeaRegIds;
00246
00247
00248 bool _domultireg;
00249 bool _dofilter;
00250 vector<int> ignoreIds;
00251 bool _printFormation;
00252 bool _printFormationDetails;
00253
00254
00255 int _myId;
00256 Pose _myPose;
00257 PosiFeatures _myPosiFeatures;
00258 Observation _myObservation;
00259 vector<Angle> _myCamObs;
00260
00261
00262 map<int,PosiFeatures> _othersPosiFeatures;
00263 vector<int> _othersPosiFeaturesNums;
00264 map<int, vector<Angle> > _othersCamObs;
00265 vector<int> _othersCamObsNums;
00266 map<int,Pose> _othersPose;
00267 vector<int> _othersPoseNums;
00268
00269
00270 map<int,Pose> _estimates;
00271 vector<int> _activatedEstimates;
00272 map<int,Timer> _timeFromLastMessage;
00273 PoseFeatures _formation;
00274
00275 fstream _savefile;
00276 fstream _saveRealPosFile;
00277 fstream _saveMultiRegCamFile;
00278 fstream _saveBestEstimate;
00279 fstream _readFile;
00280 fstream _logMultiRegCamFile;
00281 fstream _logMultiRegCamOff;
00282 fstream _logTimeOff;
00283 stringstream s;
00284
00285 public:
00287 ParticleMutLocCamOffTask(ResourcePointers resources,int argc, const char* argv[]);
00288
00290 ~ParticleMutLocCamOffTask();
00291
00294 TaskPlate getPlate() const {
00295 return _plate;
00296 }
00299 Time getMaxDuration(){
00300 return Time(_maxDurSec,_maxDurUsec);
00301 }
00304 Time getMaxSamplPeriod(){
00305 return Time(_maxSamplPeriodSec,_maxSamplPeriodUsec);
00306 }
00309 Time getMinSamplPeriod(){
00310 return Time(_minSamplPeriodSec,_minSamplPeriodUsec);
00311 }
00314 TaskOutputs run();
00315
00316 private:
00317
00319 void _readSharedMemory();
00320
00322 void _comunicate();
00323
00325 void _readDataFromFiles();
00326
00328 void _doOnePropagationFilterStep(map <int, vector <Pose> > &likelihoods, vector<int> &likelihoodsActive);
00329
00331 void _draw();
00332
00334 void _writeSharedMem();
00335
00336 void _computeFormation();
00337
00340 void _insertValidObservations(vector<Observation> &allObservations);
00341
00342 void _insertValidCamObservations(vector<AngleId> &allObservations);
00343
00344 void _insertValidCamOffObservations(vector<AngleId> &allObservations);
00345
00347 void _eraseDuplicateCamInput(vector<AngleId> &input);
00348
00350 void _performNotBearingOnlyMultipleRegistration(map <int, vector <Pose> > &likelihoods, vector<int> &likelihoodsActive, MultiRegSol& multiRegSol);
00351
00354 bool _performBearingOnlyMultipleRegistration(map <int, vector <Pose> > &likelihoods, vector<int> &likelihoodsActive, MultiRegCamSol* multiRegCamSol, ProbMultiRegCamSol* probMultiRegCamSol);
00355
00359 void _completeMutLocFilInput(MutLocFilInput &fStepIn, int hisId);
00360
00363 bool _activeFilter(int hisId);
00364
00367 bool _activeEstimate(int hisId);
00368
00370 void _activateFilter(int hisId);
00371
00373 vector<AngleIdTime> _readMeasFile(ifstream &file,int id);
00374
00376 vector<AngleIdTime> _readLaserFileBO(ifstream &file,int id);
00377
00379 void _readIdsFile(ifstream &file,vector<int> &ris);
00380
00381 vector<Pose> _readTState(ifstream &file);
00382
00383 void _computeInputMultiRegCamOff(vector<vector<AngleIdTime> > &inputTime,vector<vector<AngleId> > &inputMultiRegOff,int myIdPos, vector< vector<Pose> > &inputTStateOffTemp, vector< vector<Pose> > &inputTStateOff);
00384
00385 void selectParticles(vector<Decimal> weights, vector<int> &posBest, int numVis);
00386 };
00387
00388
00389
00390 };
00391
00392
00393 #endif
00394
00395
00396
00397