trajectory_composite.cpp

Go to the documentation of this file.
00001 /*****************************************************************************
00002  *  \author
00003  *      Erwin Aertbelien, Div. PMA, Dep. of Mech. Eng., K.U.Leuven
00004  *
00005  *  \version
00006  *              LRL V0.2
00007  *
00008  *      \par History
00009  *              - $log$
00010  *
00011  *      \par Release
00012  *              $Id: trajectory_composite.cpp 22 2004-09-21 08:58:54Z eaertbellocal $
00013  *              $Name:  $
00014  ****************************************************************************/
00015 
00016 #include "trajectory_composite.hpp"
00017 #include "path_composite.hpp"
00018 
00019 namespace KDL {
00020 
00021     using namespace std;
00022 
00023 
00024     Trajectory_Composite::Trajectory_Composite():duration(0.0)
00025     {
00026         path = new Path_Composite();
00027     }
00028 
00029     double Trajectory_Composite::Duration() const{
00030         return duration;
00031     }
00032 
00033     Frame Trajectory_Composite::Pos(double time) const {
00034         // not optimal, could be done in log(#elem)
00035         // or one could buffer the last segment and start looking from there.
00036         unsigned int i;
00037         double previoustime;
00038         Trajectory* traj;
00039         if (time < 0) {
00040             return vt[0]->Pos(0);
00041         }
00042         previoustime = 0;
00043         for (i=0;i<vt.size();i++) {
00044             if (time < vd[i]) {
00045                 return vt[i]->Pos(time-previoustime);
00046             }
00047             previoustime = vd[i];
00048         }
00049         traj = vt[vt.size()-1];
00050         return traj->Pos(traj->Duration());
00051     }
00052 
00053 
00054     Twist Trajectory_Composite::Vel(double time) const {
00055         // not optimal, could be done in log(#elem)
00056         unsigned int i;
00057         Trajectory* traj;
00058         double previoustime;
00059         if (time < 0) {
00060             return vt[0]->Vel(0);
00061         }
00062         previoustime = 0;
00063         for (i=0;i<vt.size();i++) {
00064             if (time < vd[i]) {
00065                 return vt[i]->Vel(time-previoustime);
00066             }
00067             previoustime = vd[i];
00068         }
00069         traj = vt[vt.size()-1];
00070         return traj->Vel(traj->Duration());
00071     }
00072 
00073     Twist Trajectory_Composite::Acc(double time) const {
00074         // not optimal, could be done in log(#elem)
00075         unsigned int i;
00076         Trajectory* traj;
00077         double previoustime;
00078         if (time < 0) {
00079             return vt[0]->Acc(0);
00080         }
00081         previoustime = 0;
00082         for (i=0;i<vt.size();i++) {
00083                 if (time < vd[i]) {
00084                         return vt[i]->Acc(time-previoustime);
00085                 }
00086                 previoustime = vd[i];
00087         }
00088         traj = vt[vt.size()-1];
00089         return traj->Acc(traj->Duration());
00090     }
00091 
00092     void Trajectory_Composite::Add(Trajectory* elem) {
00093         vt.insert(vt.end(),elem);
00094         duration += elem->Duration();
00095         vd.insert(vd.end(),duration);
00096         path->Add(elem->GetPath(),false);
00097     }
00098 
00099     void Trajectory_Composite::Destroy() {
00100         VectorTraj::iterator it;
00101         for (it=vt.begin();it!=vt.end();it++) {
00102             delete *it;
00103         }
00104         vt.erase(vt.begin(),vt.end());
00105         vd.erase(vd.begin(),vd.end());
00106 
00107         delete path;
00108     }
00109 
00110     Trajectory_Composite::~Trajectory_Composite() {
00111         Destroy();
00112     }
00113 
00114 
00115     void Trajectory_Composite::Write(ostream& os) const {
00116         os << "COMPOSITE[ " << vt.size() << endl;
00117         unsigned int i;
00118         for (i=0;i<vt.size();i++) {
00119             vt[i]->Write(os);
00120         }
00121         os << "]" << endl;
00122     }
00123 
00124     Trajectory* Trajectory_Composite::Clone() const{
00125         Trajectory_Composite* comp = new Trajectory_Composite();
00126         for (unsigned int i = 0; i < vt.size(); ++i) {
00127             comp->Add(vt[i]->Clone());
00128         }
00129         return comp;
00130     }
00131 
00132     Path* Trajectory_Composite::GetPath()
00133     {
00134         return path;
00135     }
00136 
00137     VelocityProfile* Trajectory_Composite::GetProfile()
00138     {
00139         return 0;
00140     }
00141 
00142 }
00143 
00144 

Generated on Wed Nov 23 19:00:49 2011 for FreeCAD by  doxygen 1.6.1