00001 // ---------------------------------------------------------------------------- 00002 // 00003 // $Id$ 00004 // 00005 // Copyright 2008, 2009, 2010, 2011, 2012 Antonio Franchi and Paolo Stegagno 00006 // 00007 // This file is part of MIP. 00008 // 00009 // MIP is free software: you can redistribute it and/or modify 00010 // it under the terms of the GNU General Public License as published by 00011 // the Free Software Foundation, either version 3 of the License, or 00012 // (at your option) any later version. 00013 // 00014 // MIP is distributed in the hope that it will be useful, 00015 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00016 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00017 // GNU General Public License for more details. 00018 // 00019 // You should have received a copy of the GNU General Public License 00020 // along with MIP. If not, see <http://www.gnu.org/licenses/>. 00021 // 00022 // Contact info: antonio.franchi@tuebingen.mpg.de stegagno@diag.uniroma1.it 00023 // 00024 // ---------------------------------------------------------------------------- 00025 00026 00031 00032 00036 00038 /* @{ */ 00039 00040 00041 00042 00043 #ifndef TRAJECTORY_H 00044 #define TRAJECTORY_H 00045 00046 #ifdef MIP_HOST_APPLE 00047 #include <applePatch.h> 00048 #endif 00049 00050 #include <iostream> 00051 #include <math.h> 00052 #include <Spaces.h> 00053 #include <Time.h> 00054 #include <Path.h> 00055 #include <TimeLaw.h> 00056 00057 using namespace std; 00058 00059 00060 namespace MipBaselib { 00066 class AnalyticalTrajParam { 00067 private: 00068 static const Decimal _threshold; 00070 Decimal _start; 00071 Decimal _stop; 00072 Decimal _V; 00073 Decimal _Vsquare; 00074 Decimal _Vmax; 00075 Decimal _W; 00076 Decimal _Wmax; 00077 Decimal _root; 00078 Decimal _vp; 00079 Decimal _vpd; 00080 Decimal _vpdd; 00081 public: 00083 AnalyticalTrajParam(){ 00084 setStart(0.0); 00085 setStop(1.0); 00086 setVp(0); 00087 setWmax(1); 00088 } 00090 AnalyticalTrajParam(Decimal start, Decimal stop){ 00091 setStart(start); 00092 setStop(stop); 00093 setVp(0); 00094 setWmax(1); 00095 } 00097 AnalyticalTrajParam(Decimal Wmax){ 00098 setStart(0.0); 00099 setStop(1.0); 00100 setVp(0); 00101 setWmax(Wmax); 00102 } 00103 00106 AnalyticalTrajParam(const AnalyticalTrajParam& param){ 00107 _start=param._start; 00108 _stop=param._stop; 00109 _V=param._V; 00110 _Vsquare=param._Vsquare; 00111 _Vmax=param._Vmax; 00112 _W=param._W; 00113 _Wmax=param._Wmax; 00114 _root=param._root; 00115 _vp=param._vp; 00116 _vpd=param._vpd; 00117 _vpdd=param._vpdd; 00118 } 00119 00122 AnalyticalTrajParam& operator=(const AnalyticalTrajParam& param){ 00123 if (this != ¶m){ 00124 _start=param._start; 00125 _stop=param._stop; 00126 _V=param._V; 00127 _Vsquare=param._Vsquare; 00128 _Vmax=param._Vmax; 00129 _W=param._W; 00130 _Wmax=param._Wmax; 00131 _root=param._root; 00132 _vp=param._vp; 00133 _vpd=param._vpd; 00134 _vpdd=param._vpdd; 00135 } 00136 return *this; 00137 } 00138 /*************************************************************************************************** 00139 *********************************** SET FUNCTIONS *********************************** 00140 ***************************************************************************************************/ 00142 void setStart(Decimal value){ 00143 _start=value; 00144 } 00145 00147 void setStop(Decimal value){ 00148 _stop=value; 00149 } 00150 00152 void setV(Decimal value){ 00153 _V=value; 00154 } 00155 00157 void setVsquare(Decimal value){ 00158 _Vsquare=value; 00159 } 00160 00162 void setVmax(Decimal value){ 00163 _Vmax=value; 00164 } 00165 00167 void setW(Decimal value){ 00168 _W=value; 00169 } 00170 00172 void setWmax(Decimal value){ 00173 _Wmax=value; 00174 } 00175 00177 void setRoot(Decimal value){ 00178 _root=value; 00179 } 00180 00182 void setVp(Decimal value){ 00183 _vp=value; 00184 } 00185 00187 void setVpd(Decimal value){ 00188 _vpd=value; 00189 } 00190 00192 void setVpdd(Decimal value){ 00193 _vpdd=value; 00194 } 00195 /*************************************************************************************************** 00196 *********************************** GET FUNCTIONS *********************************** 00197 ***************************************************************************************************/ 00199 Decimal start(){ 00200 return _start; 00201 } 00202 00204 Decimal stop(){ 00205 return _stop; 00206 } 00207 00209 Decimal V(){ 00210 return _V; 00211 } 00212 00214 Decimal Vsquare(){ 00215 return _Vsquare; 00216 } 00217 00219 Decimal Vmax(){ 00220 return _Vmax; 00221 } 00222 00224 Decimal W(){ 00225 return _W; 00226 } 00227 00229 Decimal Wmax(){ 00230 return _Wmax; 00231 } 00232 00234 Decimal root(){ 00235 return _root; 00236 } 00237 00239 Decimal vp(){ 00240 return _vp; 00241 } 00242 00244 Decimal vpd(){ 00245 return _vpd; 00246 } 00247 00249 Decimal vpdd(){ 00250 return _vpdd; 00251 } 00252 00254 Decimal threshold(){ 00255 return _threshold; 00256 } 00257 00259 string print(){ 00260 stringstream s; 00261 s.precision(3); 00262 s.setf(ios::fixed,ios::floatfield); 00263 s<<"start\t"<<_start<<endl; 00264 s<<"stop\t"<<_stop<<endl; 00265 s<<"V\t"<<_V<<endl; 00266 s<<"Vsquare\t"<<_Vsquare<<endl; 00267 s<<"Vmax\t"<<_Vmax<<endl; 00268 s<<"W\t"<<_W<<endl; 00269 s<<"Wmax\t"<<_Wmax<<endl; 00270 s<<"root\t"<<_root<<endl; 00271 s<<"vp\t"<<_vp<<endl; 00272 s<<"vpd\t"<<_vpd<<endl; 00273 s<<"vpdd\t"<<_vpdd<<endl; 00274 return s.str(); 00275 } 00276 }; 00277 00278 00284 class SampledTrajParam{ 00285 }; 00286 00287 00294 class Trajectory{ 00295 private: 00296 Time _Tc; 00298 public: 00300 Trajectory(){ 00301 } 00302 00305 Trajectory(const Trajectory& t){ 00306 _Tc=t._Tc; 00307 } 00308 00311 Trajectory& operator=(const Trajectory& t){ 00312 if (this != &t){ 00313 _Tc=t._Tc; 00314 } 00315 return *this; 00316 } 00317 00319 void setTc(Time value){ 00320 _Tc=value; 00321 } 00322 00324 Time Tc(){ 00325 return _Tc; 00326 } 00327 00329 virtual Position getPos(Time t) = 0; 00330 00332 virtual Position getFirstDeriv(Time t) = 0; 00333 00335 virtual Position getSecondDeriv(Time t) = 0; 00336 }; 00337 00338 00345 //AnalyticalTrajectory = x(s(t)), y(s(t)) e derivate 00346 class AnalyticalTrajectory:public Trajectory{ 00347 private: 00348 AnalyticalTrajParam _param; 00349 Path* _path; 00350 TimeLaw* _timeLaw; 00351 Time _Tc; 00352 bool _firstAssignement; 00353 00355 void evaluateVW(); 00356 00358 void evaluateXY(); 00359 00361 Decimal Wsat(Decimal omega,Decimal threshold); 00362 00364 bool singularity(Decimal value){ 00365 _param.setRoot(sqrt((_path->evalCentredPosp(value)).x()*(_path->evalCentredPosp(value)).x() + (_path->evalCentredPosp(value)).y()*(_path->evalCentredPosp(value)).y())); 00366 return (_param.root()<_param.threshold()); 00367 } 00368 void updateS(Time time); 00369 public: 00371 AnalyticalTrajectory(){ 00372 setFirstAssignement(); 00373 setPath(new Segment()); 00374 setTimeLaw(new Stillness()); 00375 }; 00377 AnalyticalTrajectory(AnalyticalTrajParam param, Path* path, TimeLaw* timeLaw){ 00378 setFirstAssignement(); 00379 setPath(path); 00380 setTimeLaw(timeLaw); 00381 setParam(_param); 00382 } 00383 00386 AnalyticalTrajectory(const AnalyticalTrajectory& t){ 00387 _param=t._param; 00388 _path=t._path; 00389 _timeLaw=t._timeLaw; 00390 _Tc=t._Tc; 00391 _firstAssignement=t._firstAssignement; 00392 } 00393 00396 AnalyticalTrajectory& operator=(const AnalyticalTrajectory& t){ 00397 if (this != &t){ 00398 _param=t._param; 00399 _path=t._path; 00400 _timeLaw=t._timeLaw; 00401 _Tc=t._Tc; 00402 _firstAssignement=t._firstAssignement; 00403 } 00404 return *this; 00405 } 00406 00407 /*************************************************************************************************** 00408 *********************************** SET FUNCTIONS *********************************** 00409 ***************************************************************************************************/ 00411 void setParam(AnalyticalTrajParam param){ 00412 _param=param; 00413 } 00414 00416 void setPath(Path* path){ 00417 if (!firstAssignement()){ 00418 delete _path; 00419 unsetFirstAssignement(); 00420 } 00421 _path=path; 00422 } 00423 00425 void setTimeLaw(TimeLaw* timeLaw){ 00426 if (!firstAssignement()){ 00427 delete _timeLaw; 00428 unsetFirstAssignement(); 00429 } 00430 _timeLaw=timeLaw; 00431 } 00432 00434 void setTc(Time value){ 00435 _Tc=value; 00436 } 00437 00439 void setFirstAssignement(){ 00440 _firstAssignement=true; 00441 } 00442 00444 void unsetFirstAssignement(){ 00445 _firstAssignement=false; 00446 } 00447 00448 /*************************************************************************************************** 00449 *********************************** GET FUNCTIONS *********************************** 00450 ***************************************************************************************************/ 00452 AnalyticalTrajParam param(){ 00453 return _param; 00454 } 00455 00457 Path* path(){ 00458 return _path; 00459 } 00460 00462 TimeLaw* timeLaw(){ 00463 return _timeLaw; 00464 } 00465 00467 Time Tc(){ 00468 return _Tc; 00469 } 00470 00472 bool firstAssignement(){ 00473 return _firstAssignement; 00474 } 00475 00477 Position getPos(Time t); 00478 00480 Position getFirstDeriv(Time t); 00481 00483 Position getSecondDeriv(Time t); 00484 00486 // string print(){/TODO switch per dynamic_cast di path e timeLaw 00487 // stringstream s; 00488 // s.precision(3); 00489 // s.setf(ios::fixed,ios::floatfield); 00490 // s<<"PATH:\n"<<PathNames[_path->pathType()]<<endl; 00491 // s<<"TimeLaw type -> "<<TimeLawNames[_timeLaw->timeLawType()]<<endl; 00492 // return s.str(); 00493 // } 00494 }; 00495 00496 00503 class SampledTrajectory:public Trajectory{ 00504 private: 00505 vector<Position> _pos; 00506 vector<Position> _posp; 00507 vector<Position> _pospp; 00508 vector<Time> _samplingInstants; 00509 Time _duration; 00510 int _addedTrajectories; 00511 Time _samplingTime; 00512 int _lastReadIndex; 00513 00514 bool _findIndex(Time time, int &index); 00515 00516 public: 00517 00519 SampledTrajectory(); 00520 00522 SampledTrajectory(Time samplingTime); 00523 00525 SampledTrajectory(SampledTrajectory &traj); 00526 00528 void addTrajectory(AnalyticalTrajectory* traj); 00529 00531 void getSample(Time instant,Position &pos, Position &posp, Position &pospp); 00532 00534 void clear(); 00535 00539 Position getPos(Time t); 00540 00544 Position getFirstDeriv(Time t); 00545 00549 Position getSecondDeriv(Time t); 00550 }; 00551 00552 00553 00554 00555 }; // end of namespace 00556 00557 00558 00559 #endif 00560 00561 /* @} */ 00562