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
00030
00031
00037
00038
00039 #ifndef __PHD_FILTER_TASK_H_
00040 #define __PHD_FILTER_TASK_H_
00041
00042 #include <armadillo>
00043
00044 #include <Task.h>
00045 #include <Resource.h>
00046 #include <MobileRob.h>
00047 #include <GMPHDUnicycle2DIdFilter.h>
00048 #include <GMPHDUnicycle2DIdRCFilter.h>
00049 #include <GMPHDUnicycle2DIdCoopFilter.h>
00050 #include <GMPHDUnicycle2DIdCoopFilter2.h>
00051 #include <GMPHDUnicycle2DIdCoopRCFilter.h>
00052 #include <GMPHDUnicycle2DIdCoop3Filter.h>
00053 #include <GMPHDUnicycle2DIdCoop4Filter.h>
00054 #include <GMPHDUnicycle2DNoIdFilter.h>
00055 #include <GMPHDLinear2DTargetNoIdFilter.h>
00056 #include <GMIDPHDUnicycle2DRCFilter.h>
00057 #include <PHDRansac.h>
00058 #include <PHDIDRansac.h>
00059
00060 #include <SharedMem.h>
00061 #include <CommonOptions.h>
00062 #ifndef MIP_PLATFORM_ARM
00063 #include <DraWin.h>
00064 #endif
00065 #include <CommModule.h>
00066
00067 #include <EKFilterUnicycle2D.h>
00068 #include <SimTime.h>
00069 #include <OfflineMR.h>
00070
00071 using namespace MipAlgorithms;
00072 using namespace MipResources;
00073 using namespace arma;
00074
00075
00076 namespace MipTasks{
00077
00078
00081 enum PHDFilterTaskFunctionalities{
00082 PHDF_TASK_COMM_MYPOSE,
00083 PHDF_TASK_COMM_MYCI,
00084 PHDF_TASK_COMM_MYGM,
00085 PHDF_TASK_COMM_MYPF,
00086 PHDF_TASK_COMP_EKF,
00087 PHDF_TASK_USEOTH_PF,
00088 PHDF_TASK_SELF_ESTIM,
00089 PHDF_TASK_ROBOCENTRIC,
00090 PHDF_TASK_PHD_FILT,
00091 PHDF_TASK_FUNCTIONALITIES_NUM
00092 };
00093
00099 static const bool PHDFilterTaskFunctionalitiesTable[PHD_FILTER_TYPE_NUM][PHDF_TASK_FUNCTIONALITIES_NUM]={
00100
00101 false, false, false, false, false, false, false, false, true,
00102 true, true, true, false, false, false, false, false, true,
00103 true, true, true, false, true, false, false, true, true,
00104 true, false, false, true, false, true, true, false, true,
00105 true, false, false, true, false, true, true, false, true,
00106 true, false, false, true, false, true, false, true, true,
00107 true, false, false, true, false, true, true, false, true,
00108 true, false, false, true, false, true, true, false, true,
00109 true, false, false, false, false, false, false, false, false,
00110 false, false, false, false, false, false, false, false, true,
00111 true, false, false, false, false, false, false, true, true,
00112 false, true, false, false, true, false, false, false, false,
00113 true, true, true, false, true, false, false, true, true
00114 };
00115
00116
00117
00119
00120
00124 class PHDFilterTaskOptions : public Options {
00125 public:
00126
00128 DecimalOption* timeBetweenMeasUpdates;
00130 DecimalOption* timeBetweenSysUpdates;
00132 StringOption* filterType;
00134 DecimalOption* survivalProbability;
00136 DecimalOption* detectionProbability;
00139 DecimalOption* truncationThreshold;
00141 IntOption* maxComponentNumber;
00144 DecimalOption* mergingThreshold;
00146 IntOption* particleNumber;
00147
00149 DecimalOption* sensorDetectionRay;
00151 DecimalOption* targetDimension;
00153 DecimalOption* maxDetectionBearing;
00154
00156 StringOption* rootFiles;
00158 BoolOption* saveGMFiles;
00160 BoolOption* offlineSimulation;
00161
00163 PHDFilterTaskOptions();
00164
00165 string getObjectName() const {
00166 return "PHDFilterTaskOptions";
00167 }
00168 };
00169
00170
00174 class PHDFilterTaskSharedMem : public SharedMem{
00175 public:
00178 void initSharedMem();
00179
00183 PosiFeatures getMyProtrusions(MotionModuleTState &state);
00184
00187 void getMyControlInputs(MRControlInputs &ci);
00188
00191 bool doMloc();
00192
00194 void unsetDoMloc();
00195
00198 bool printFormation();
00199
00202 bool printFormationDetails();
00203
00206 void setMyGaussianMixture(string &gm);
00207
00210 void getMyGaussianMixture(string &gm);
00211 };
00212
00213
00217 class PHDFilterTask : public Task{
00218 private:
00219
00220 static const TaskPlate _plate = PHD_TASK;
00221
00222 static const long int _maxDurSec = 0, _maxDurUsec = 150000;
00223 static const long int _maxSamplPeriodSec = 0, _maxSamplPeriodUsec = 500000;
00224 static const long int _minSamplPeriodSec = 0, _minSamplPeriodUsec = 200000;
00225
00226 PHDFilter* _phdFilter;
00227 PHDFilterType _phdFilterType;
00228
00229 MobileRob* _mobileRob;
00230
00231 CommModule* _commModule;
00232
00233 #ifndef MIP_PLATFORM_ARM
00234 DraWin* _draWin;
00235 unsigned int _drawList;
00236 bool dwOn;
00237 #endif
00238
00239 fstream *_saveGMFile;
00240
00241 PHDFilterTaskSharedMem* _sharedMem;
00242
00243 PHDFilterTaskOptions _options;
00244
00245
00246 int _myId;
00247 Pose _myEstimatePose;
00248 Pose _myPose;
00249 PosiFeatures _myPosiFeatures;
00250
00251 map<int,PosiFeatures> _othersPosiFeatures;
00252 vector<int> _othersPosiFeaturesNums;
00253
00254 map<int,GaussianMixtureJointId> _othersGM;
00255 vector<int> _othersGMNums;
00256
00257 int counter;
00258
00259 MRControlInputs _myCI;
00260
00261 EKFilterUnicycle2D* ekf;
00262 map<int,EKFilterUnicycle2D*> _ekfs;
00263 vector<int> _activeEKFs;
00264
00265 PHDRansac* _ransac;
00266 SimTimer _counterSendGM;
00267
00268
00269 map<int, MRControlInput > _othersCI;
00270 vector<int> _othersVelNums;
00271
00272
00273 map<int,Pose> _othersPose;
00274 vector<int> _othersPoseNums;
00275 map<int,SimTimer> _timeFromLastMessage;
00276 SimTimer _lastStepTime;
00277
00278
00279 void _draw();
00280
00282 void _communicate();
00283
00285 void _sendMyPose(CommNode &sender, CommNode &recipient);
00286
00288 void _sendMyControlInput(CommNode &sender, CommNode &recipient);
00289
00291 void _sendMyGaussianMixture(CommNode &sender, CommNode &recipient);
00292
00294 void _sendMyPosiFeature(CommNode &sender, CommNode &recipient);
00295
00297 void _receiveMyPose(CommPacket* packet, int senderId);
00298
00300 void _receiveMyControlInput(CommPacket *packet, int senderId);
00301
00303 void _receiveMyGaussianMixture(CommPacket *packet, int senderId);
00304
00306 void _receiveMyPosiFeature(CommPacket *packet, int senderId);
00307
00308 public:
00310 PHDFilterTask(ResourcePointers resources,int argc, const char* argv[]);
00311
00313 ~PHDFilterTask();
00314
00317 TaskPlate getPlate() const {
00318 return _plate;
00319 }
00322 Time getMaxDuration(){
00323 return Time(_maxDurSec,_maxDurUsec);
00324 }
00327 Time getMaxSamplPeriod(){
00328 return Time(_maxSamplPeriodSec,_maxSamplPeriodUsec);
00329 }
00332 Time getMinSamplPeriod(){
00333 return Time(_minSamplPeriodSec,_minSamplPeriodUsec);
00334 }
00335
00338 TaskOutputs run();
00339 };
00340
00341
00342
00343 };
00344
00345 #endif
00346
00347
00348
00349
00350