00001 #ifndef __INTERPOLATOR_H__
00002 #define __INTERPOLATOR_H__
00003
00004 #include <deque>
00005 #include <string>
00006 #include <coil/Mutex.h>
00007
00008 using namespace std;
00009
00010 class interpolator
00011 {
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 public:
00023 typedef enum {LINEAR, HOFFARBIB,QUINTICSPLINE,CUBICSPLINE} interpolation_mode;
00024 interpolator(int dim_, double dt_, interpolation_mode imode_=HOFFARBIB, double default_avg_vel_=0.5);
00025 ~interpolator();
00026 void push(const double *x_, const double *v_, const double *a_, bool immediate=true);
00027 double *front();
00028
00029
00030
00031
00032 void get(double *x_, bool popp=true);
00033 void get(double *x_, double *v_, bool popp=true);
00034 void get(double *x_, double *v_, double *a_, bool popp=true);
00035
00036 void set(const double *x, const double *v=NULL);
00037
00038
00039 void go(const double *gx, const double *gv, double time, bool immediate=true);
00040 void go(const double *gx, double time, bool immediate=true);
00041 void pop();
00042 void pop_back();
00043 void clear();
00044 void sync();
00045 void load(string fname, double time_to_start=1.0, double scale=1.0,
00046 bool immediate=true, size_t offset1 = 0, size_t offset2 = 0);
00047 void load(const char *fname, double time_to_start=1.0, double scale=1.0,
00048 bool immediate=true, size_t offset1 = 0, size_t offset2 = 0);
00049 bool isEmpty();
00050 double remain_time();
00051 double calc_interpolation_time(const double *g);
00052 bool setInterpolationMode (interpolation_mode i_mode_);
00053
00054
00055 void setGoal(const double *gx, const double *gv, double time,
00056 bool online=true);
00057 void setGoal(const double *gx, double time, bool online=true);
00058
00059
00060 void interpolate(double& remain_t_);
00061 double deltaT() const { return dt; }
00062 int dimension() const { return dim; }
00063 void setName (const std::string& _name) { name = _name; };
00064 private:
00065
00066 interpolation_mode imode;
00067
00068 deque<double *> q, dq, ddq;
00069
00070 int length;
00071
00072 int dim;
00073
00074 double dt;
00075
00076 double *x, *v, *a;
00077
00078 double *gx, *gv, *ga;
00079
00080
00081 double target_t, remain_t;
00082
00083 double *a0, *a1, *a2, *a3, *a4, *a5;
00084
00085 double default_avg_vel;
00086
00087 std::string name;
00088
00089 void hoffarbib(double &remain_t_,
00090 double a0, double a1, double a2,
00091 double a3, double a4, double a5,
00092 double &xx, double &vv, double &aa);
00093 void linear_interpolation(double &remain_t_,
00094 double gx,
00095 double &xx, double &vv, double &aa);
00096
00097 coil::Mutex pop_mutex_;
00098 };
00099
00100 #endif