FormControl.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
00030
00031
00037
00038
00039 #ifndef __FORM_CONTROL_TASK_H_
00040 #define __FORM_CONTROL_TASK_H_
00041
00042 #include <Task.h>
00043 #include <Resource.h>
00044 #include <Uav.h>
00045 #include <UavControl.h>
00046 #include <ProtrusionExtr.h>
00047 #include <SharedMem.h>
00048 #include <CommonOptions.h>
00049
00050 #include <CommModule.h>
00051
00052 #ifndef MIP_PLATFORM_ARM
00053 #include <DraWin.h>
00054 #endif
00055
00056
00057 namespace MipTasks{
00058
00060
00061
00065 enum FormControlTaskStates{
00066 FORM_CONTROL_FIRST_RUN,
00067 FORM_CONTROL_NORMAL_RUN,
00068 FORM_CONTROL_STATES_NUM
00069 };
00070
00073 static const char* FormControlTaskStatesNames[FORM_CONTROL_STATES_NUM] = {
00074 "FirstRun",
00075 "NormalRun"
00076 };
00077
00078
00082 class FormControlTaskOptions : public Options {
00083 public:
00084 DecimalOption *commPeriod;
00085
00087 FormControlTaskOptions();
00088
00089 string getObjectName() const {
00090 return "FormControlTaskOptions";
00091 }
00092 };
00093
00094
00098 class FormControlTaskSharedMem : public SharedMem{
00099 public:
00102 void initSharedMem();
00103 };
00104
00105
00109 class FormControlTask : public Task{
00110 private:
00111
00112 static const TaskPlate _plate = FCT_TASK;
00113
00114 static const long int _maxDurSec = 0, _maxDurUsec = 100000;
00115 static const long int _maxSamplPeriodSec = 0, _maxSamplPeriodUsec = 100000;
00116 static const long int _minSamplPeriodSec = 0, _minSamplPeriodUsec = 5000;
00117
00118 UavControlPar* _controlPar;
00119 UavControl* _uavControl;
00120
00121 Uav* _uav;
00122
00123 CommModule* _commModule;
00124
00125 #ifndef MIP_PLATFORM_ARM
00126 DraWin* _draWin;
00127 unsigned int _drawList;
00128 bool dwOn;
00129 #endif
00130
00131 FormControlTaskSharedMem* _sharedMem;
00132
00133 FormControlTaskOptions _options;
00134
00135
00136 UavVar* _uavState;
00137 FormControlTaskStates _state;
00138 int _myId;
00139
00140 stringstream _ssdebug;
00141
00142 Timer _commSendTimer;
00143 Time _commSendPeriod;
00144 Timer _commRecTimer;
00145 Time _commRecPeriod;
00146 Time _maxPacketLifeTime;
00147
00148
00149
00150
00151 map<int,Position3D> _receivedPositions;
00152 map<int,Position3D>::iterator _itP;
00153 map<int,Position3D> _receivedVelocities;
00154 map<int,Position3D>::iterator _itA;
00155 map<int,Time> _receivedTimeStamps;
00156 map<int,Time>::iterator _itT;
00157
00158 vector<Position3D> _otherRobotPosi;
00159 vector<Position3D> _otherRobotVel;
00160 vector<int> _otherRobotIds;
00161
00162
00163 void _firstRun();
00164 void _normalRun();
00165
00166 void _sendCommPackets();
00168 void _receiveCommPackets();
00169 bool _getOtherRobotPosi();
00170
00171
00172 public:
00174 FormControlTask(ResourcePointers resources,int argc, const char* argv[]);
00175
00177 ~FormControlTask();
00178
00180 TaskPlate getPlate() const {
00181 return _plate;
00182 }
00184 Time getMaxDuration(){
00185 return Time(_maxDurSec,_maxDurUsec);
00186 }
00188 Time getMaxSamplPeriod(){
00189 return Time(_maxSamplPeriodSec,_maxSamplPeriodUsec);
00190 }
00192 Time getMinSamplPeriod(){
00193 return Time(_minSamplPeriodSec,_minSamplPeriodUsec);
00194 }
00195
00197 TaskOutputs run();
00198 };
00199
00200
00201
00202 };
00203
00204 #endif
00205
00206
00207
00208
00209