FormUpdate.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 __FORM_UPDATE_H_
00037 #define __FORM_UPDATE_H_
00038
00039
00040 #include <Task.h>
00041 #include <Resource.h>
00042 #include <MobileRob.h>
00043 #include <DraWin.h>
00044 #include <SharedMem.h>
00045 #include <Time.h>
00046
00047 #include <CommonOptions.h>
00048 #include <CommModule.h>
00049
00050 using namespace MipResources;
00051
00052
00053 namespace MipTasks{
00054
00056
00057
00061 class FormUpdateSharedMem : public SharedMem{
00062 public:
00064 void initSharedMem(){
00065 if (formation == NULL){
00066 formation = new PoseFeatures;
00067 }
00068 if (estimates == NULL){
00069 estimates = new PoseFeatures;
00070 }
00071 }
00072
00074 bool doMloc(){
00075 return _doMloc;
00076 }
00077
00079 PoseFeatures getEstimates(){
00080 return *estimates;
00081 }
00083 PoseFeatures getFormation(){
00084 return *formation;
00085 }
00087 void setFormation(PoseFeatures &form){
00088 *formation = form;
00089 }
00090 };
00091
00092
00096 class FormUpdate : public Task{
00097 private:
00098 static const TaskPlate _plate = FUP_TASK;
00099 static const long int _maxDurSec = 0, _maxDurUsec = 30000;
00100 static const long int _maxSamplPeriodSec = 0, _maxSamplPeriodUsec = 200000;
00101 static const long int _minSamplPeriodSec = 0, _minSamplPeriodUsec = 100000;
00102
00103 MobileRob* _mobileRob;
00104
00105
00106
00107 DraWin* _draWin;
00108 unsigned int _drawList;
00109 bool dwOn;
00110
00111 FormUpdateSharedMem* _sharedMem;
00112
00113 CommModule* _commModule;
00114
00115 map<int, Pose> othersPose;
00116
00117
00118 int myId;
00119 Pose myPose;
00120
00121 PoseFeatures formation;
00122
00123 public:
00125 FormUpdate(ResourcePointers resources,int argc, const char* argv[]){
00126
00127
00128 _mobileRob = (MobileRob*) ResourceUtilities::macroResFromPlate(resources,MR_INIT,MR_END);
00129 if(_mobileRob == 0){
00130 fatalResourceNotPresent(MR_INIT);
00131 }
00132
00133
00134 _commModule = (CommModule*) ResourceUtilities::macroResFromPlate(resources,CM_INIT,CM_END);
00135 if(_commModule == 0){
00136 fatalResourceNotPresent(CM_INIT);
00137 }
00138
00139 _commModule->requestBox(getPlate());
00140
00141
00142 _sharedMem = (FormUpdateSharedMem*) ResourceUtilities::resFromPlate(resources,SHMEM_RES);
00143 if(_sharedMem == 0){
00144 fatalResourceNotPresent(SHMEM_RES);
00145 }
00146 _sharedMem->initSharedMem();
00147
00148 dwOn = false;
00149
00150 if (commonOptions->embVisOn->getValue() == 1){
00151
00152 _draWin = (DraWin*) ResourceUtilities::macroResFromPlate(resources,DW_INIT,DW_END);
00153
00154 if(_draWin == 0){
00155 warningResourceNotPresent(DW_INIT);
00156 }
00157
00158 else{
00159 dwOn = true;
00160 }
00161 }
00162
00163
00164 if (dwOn){
00165 while(!_draWin->addList(Time(0,1000),_drawList)){
00166 usleep(1000);
00167 };
00168 }
00169
00170
00171 myId = commonOptions->robotId->getValue();
00172
00173
00174 }
00175
00176
00178 ~FormUpdate(){
00179 othersPose.clear();
00180
00181 }
00182
00184 TaskPlate getPlate() const {
00185 return _plate;
00186 }
00188 Time getMaxDuration(){
00189 return Time(_maxDurSec,_maxDurUsec);
00190 }
00192 Time getMaxSamplPeriod(){
00193 return Time(_maxSamplPeriodSec,_maxSamplPeriodUsec);
00194 }
00196 Time getMinSamplPeriod(){
00197 return Time(_minSamplPeriodSec,_minSamplPeriodUsec);
00198 }
00200 TaskOutputs run();
00201
00202 private:
00203
00205 void comunicate();
00206
00208 void computeFormation();
00209
00213 void draw();
00214 };
00215
00216
00217
00218 };
00219
00220 #endif
00221
00222
00223
00224
00225