bhspeedprofiler.h

00001 /***************************************************************************
00002                           bhspeedprofiler.h
00003                              -------------------
00004  one-dimensional continuous filter with a-posteriori discretization, based
00005  on the paper "trajectory generation as a non-linear filter" by john lloyd,
00006  corrected and adapted by torsten scherer.
00007 
00008     copyright            : (c) 2004 Tim Baier
00009     email                : tbaier@informatik.uni-hamburg.de
00010  ***************************************************************************/
00011 
00012 #ifndef BHSPEEDPROFILER_H
00013 #define BHSPEEDPROFILER_H
00014 
00015 #include <iostream>
00016 #include <cmath>
00017 
00026 class BHSpeedProfiler
00027 {
00028 
00029 public:
00030 
00031   BHSpeedProfiler (void)
00032   {
00033     // we need to be able to change parameters later anyway, so there's no
00034     // point in having a full-fledged constructor if there's also a function to
00035     // change all this...
00036     URate = -1.0;                             // ok, at least mark it as illegal
00037   };
00038 
00039   virtual ~BHSpeedProfiler (void){};
00040 
00041   void SetParameters (const double newRate, const double a, const double vm);
00042   void SetPositionAndVelocity (const double startPos, const double v0);
00043   void SetTarget (const double endPos);
00044 
00045   void SetTrajectory (const double startPos, const double endPos);
00046   
00047   // compute deviation of point `p' from trajectory and/or target
00048 
00049   double ComputeTrajectoryError (const double pos);
00050   double ComputeTargetError (const double pos);
00051 
00052   // declaring these to return `const CVEC &' should prohibit writing to them
00053 
00054   double GetTarget (void) const;
00055   double GetTime (void) const;
00056   double GetNewPosition (void) const;
00057   double GetNewVelocity (void) const;
00058 
00059   //
00060 
00061   virtual double ComputeProfile (void) = 0;
00062   virtual bool IntegrateProfile (void) = 0;
00063 
00064   virtual double StretchProfile (const double tMin);
00065 
00066 
00067 protected:
00068 
00069   // generic profile computation, doesn't in fact touch `this'...
00070 
00071   double computeProfile (const double startPos,
00072                          const double startSpeed,
00073                          const double endPos,
00074                          double acce,
00075                          const double vmax,
00076                          double &timeStepInOut,
00077                          double &speedOut) const;
00078 
00079   // generic profile integration, doesn't in fact touch `this'...
00080 
00081   bool integrateProfile (const double x0In,
00082                          const double v0In,
00083                          const double xeIn,
00084                          const double tsIn,
00085                          const double vpIn,
00086                          const double a,
00087                          const double te,
00088                          double &x1Out,
00089                          double &v1Out) const;
00090 
00091   // generic information
00092 
00093   double URate, Accel, VMax;
00094 
00095   // world coordinates
00096 
00097   double StartPos, StartVel, EndPos;
00098   double NextPos, NextVel;   // next setpoint
00099 
00100   // times and peak velocities are always needed. for CFILT_ORTHO there is no
00101   // real projection, so the names are a bit wrong, but what the heck...
00102 
00103   double ProjTimeStep, ProjVelPeak;
00104 
00105   // desired trajectory (start and end point), not obeyed by all filters
00106 
00107   double TrajStart, TrajEnd;
00108 
00109 };
00110 
00111 
00112 // ****************************
00113 // **                        **
00114 // ****************************
00115 inline void BHSpeedProfiler::SetTrajectory (const double startPos, const double endPos)
00116 {
00117   TrajStart = startPos;
00118   TrajEnd = endPos;
00119 }
00120 
00121 // ****************************
00122 // **                        **
00123 // ****************************
00124 inline double BHSpeedProfiler::ComputeTargetError (const double pos)
00125 {
00126   return (EndPos - pos);
00127 }
00128 
00129 // ****************************
00130 // **                        **
00131 // ****************************
00132 inline double BHSpeedProfiler::StretchProfile (const double tMin)
00133 {
00134 #ifdef DEBUG_1
00135   std::cout << " BHSpeedProfiler::StretchProfile()" << std::endl;
00136 #endif
00137 
00138   return tMin;
00139 }
00140 
00141 // ****************************
00142 // **                        **
00143 // ****************************
00144 inline double BHSpeedProfiler::GetTarget (void) const
00145 {
00146   return EndPos;
00147 }
00148 
00149 // ****************************
00150 // **                        **
00151 // ****************************
00152 inline double BHSpeedProfiler::GetTime (void) const
00153 {
00154   return ProjTimeStep;
00155 }
00156   
00157 // ****************************
00158 // **                        **
00159 // ****************************
00160 inline double BHSpeedProfiler::GetNewPosition (void) const
00161 {
00162   return NextPos;
00163 }
00164 
00165 // ****************************
00166 // **                        **
00167 // ****************************
00168 inline double BHSpeedProfiler::GetNewVelocity (void) const
00169 {
00170   return NextVel;
00171 }
00172 
00174 //
00175 // it is silently assumed that you first call `SetPositionAndVelocity()' if
00176 // needed and then `SetTarget()'. the check for matching vector sizes will only
00177 // work this way round...
00178 //
00180 
00181 // ****************************
00182 // **                        **
00183 // ****************************
00184 inline void BHSpeedProfiler::SetTarget (const double endPos)
00185 {
00186 #ifdef DEBUG_1
00187   std::cout << " ## BHSpeedProfiler::SetTarget() : " << endPos <<  std::endl;
00188 #endif
00189 
00190   
00191 
00192   EndPos = endPos;
00193 }
00194 
00195 #endif // BHSPEEDPROFILER_H


tams Tim Baier bhandlib v0.25
Generated Wed Aug 16 14:57:09 2006 by doxygen 1.4.7