Tracker.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
00031
00035
00036
00037 #ifndef __TRACKER_H_
00038 #define __TRACKER_H_
00039
00040 #include <Task.h>
00041 #include <Resource.h>
00042 #include <SharedMem.h>
00043 #include <MobileRob.h>
00044 #include <Time.h>
00045 #include <CommonOptions.h>
00046 #include <TrajControl.h>
00047 #include <Odometry.h>
00048 #include <DraWin.h>
00049
00050
00051 using namespace MipAlgorithms;
00052 using namespace MipResources;
00053
00054
00055 namespace MipTasks{
00056
00058
00059
00060
00063 enum TrackerState{
00064 TRACKER_IDLE_STATE,
00065 TRACKER_FIRST_STATE,
00066 TRACKER_NORMAL_STATE,
00067 TRACKER_NUM_STATES
00068 };
00069
00072 enum TrackerPath{
00073 TRACKER_ASTEROID_PATH,
00074 TRACKER_CARDIOID_PATH,
00075 TRACKER_CLOTHOID_PATH,
00076 TRACKER_EIGHT_PATH,
00077 TRACKER_ELLIPSE_PATH,
00078 TRACKER_SEGMENT_PATH,
00079 TRACKER_NUM_PATHS
00080 };
00081
00084 static const char* TrackerPathNames[TRACKER_NUM_PATHS]={
00085 "Asteroid",
00086 "Cardioid",
00087 "Clothoid",
00088 "Eight",
00089 "Ellipse",
00090 "Segment"
00091 };
00092
00095 enum TrackerTimeLaw{
00096 TRACKER_STILLNESS_TIMELAW,
00097 TRACKER_CONST_SPEED_TIMELAW,
00098 TRACKER_TRIANGULAR_SPEED_TIMELAW,
00099 TRACKER_TRAPEZOIDAL_SPEED_TIMELAW,
00100 TRACKER_CUBIC_SPEED_TIMELAW,
00101 TRACKER_TRAPEZOIDAL_ACC_TIMELAW,
00102 TRACKER_TRAPEZOIDAL_DEC_TIMELAW,
00103 TRACKER_NUM_TIMELAWS
00104 };
00105
00108 static const char* TrackerTimeLawNames[TRACKER_NUM_TIMELAWS]={
00109 "Stillness",
00110 "ConstantSpeed",
00111 "TriangularSpeed",
00112 "TrapezoidalSpeed",
00113 "CubicSpeed",
00114 "TrapezoidalAcc",
00115 "TrapezoidalDec",
00116 };
00117
00118
00122 class TrackerSharedMem : public SharedMem{
00123 public:
00124
00125 void initSharedMem(){}
00126
00128 Path* getPath(){
00129 if(path!=NULL){
00130 }
00131 return path;
00132 }
00133
00134 TimeLaw* getTimeLaw(){
00135 return timeLaw;
00136 }
00137
00138 bool getDoTracking(){
00139 return _doTracking;
00140 }
00141
00142 void unsetNewPath(){
00143 _newPath=false;
00144 }
00145
00146 bool getNewPath(){
00147 return _newPath;
00148 }
00149
00150 bool getUseDFL(){
00151 return _useDFL;
00152 }
00153
00154 Angle getOrientation(){
00155 return orientation;
00156 }
00157
00158
00159
00160
00161
00162 };
00163
00164
00168 class TrackerOptions : public Options {
00169 public:
00170 StringOption* path;
00171 StringOption* timeLaw;
00172
00173 IntOption* pathSource;
00174 IntOption* timeLawSource;
00175
00176 DecimalOption* pathAmplitude;
00177 DecimalOption* pathHorAxis;
00178 DecimalOption* pathVertAxis;
00179 DecimalOption* pathCenterAbs;
00180 DecimalOption* pathCenterOrd;
00181 DecimalOption* pathRotation;
00182 DecimalOption* pathStartAbs;
00183 DecimalOption* pathStartOrd;
00184 DecimalOption* pathEndAbs;
00185 DecimalOption* pathEndOrd;
00186
00187 DecimalOption* timeLawSpeed;
00188 DecimalOption* timeLawAcceleration;
00189 DecimalOption* timeLawJerk;
00190 IntOption* timeLawCommTime1;
00191 IntOption* timeLawCommTime2;
00192 DecimalOption* timeLawStart;
00193 DecimalOption* timeLawStop;
00194
00195 DecimalOption* trajectoryStart;
00196 DecimalOption* trajectoryStop;
00197
00198 BoolOption* saveTStates;
00199
00200 TrackerOptions();
00201
00202 string getObjectName() const {
00203 return "TrackerOptions";
00204 }
00205 };
00206
00207
00211 class Tracker : public Task{
00212 private:
00213 static const TaskPlate _plate = TKR_TASK;
00214 static const long int _maxDurSec = 0, _maxDurUsec = 500000;
00215 static const long int _maxSamplPeriodSec = 2, _maxSamplPeriodUsec = 0;
00216 static const long int _minSamplPeriodSec = 0, _minSamplPeriodUsec = 10000;
00217
00218 TrackerOptions options;
00219 TrackerSharedMem* sharedMem;
00220
00221 vector<Position> _realtrajGL;
00222 vector<Position> _destrajGL;
00223
00224 Odometry odo;
00225
00226 Path* path;
00227 TimeLaw* timeLaw;
00228
00229 bool _noSharedMemory;
00230
00231 fstream _saveTState;
00232 fstream _saveTStateTime;
00233
00234 TrackerState state;
00235 AnalyticalTrajParam trajParam;
00236 AnalyticalTrajectory traj;
00237 TrajControl control;
00238
00239
00240 VelVec command;
00241 Time passato;
00242 Timer _timer;
00243 Timer runTimer;
00244 TrajectoryState status;
00245
00246 MobileRob* _mobileRob;
00247 MotionModuleTState _mrTState;
00248
00249 #ifndef MIP_PLATFORM_ARM
00250 DraWin* _draWin;
00251 unsigned int _drawList;
00252 unsigned int _drawListWake;
00253 bool dwOn;
00254 #endif
00255
00256
00257
00258 public:
00259 bool first;
00260 bool last;
00262 Tracker(ResourcePointers resources,int argc, const char* argv[]);
00263
00265 ~Tracker(){
00266 }
00267
00269 TaskPlate getPlate() const {
00270 return _plate;
00271 }
00273 Time getMaxDuration(){
00274 return Time(_maxDurSec,_maxDurUsec);
00275 }
00277 Time getMaxSamplPeriod(){
00278 return Time(_maxSamplPeriodSec,_maxSamplPeriodUsec);
00279 }
00281 Time getMinSamplPeriod(){
00282 return Time(_minSamplPeriodSec,_minSamplPeriodUsec);
00283 }
00284
00286 TaskOutputs run();
00287
00288 private:
00290 void idleRun();
00292 void normalRun();
00294 void firstRun();
00295
00296 void switchPath(Path* newPath){
00297 path=newPath;
00298 }
00299
00300 void switchTimeLaw(TimeLaw* newTimeLaw){
00301 timeLaw=newTimeLaw;
00302 }
00303
00305 void draw();
00306 };
00307
00308
00309
00310 };
00311
00312 #endif
00313
00314
00315
00316