interpolator.h
Go to the documentation of this file.
1 #ifndef __INTERPOLATOR_H__
2 #define __INTERPOLATOR_H__
3 
4 #include <deque>
5 #include <string>
6 #include <coil/Mutex.h>
7 
8 using namespace std;
9 
11 {
12  // interpolator class is to interpolate from current value to goal value considering position, velocities, and accelerations.
13  // Two status : empty or not
14  // Interpolator interpolates based on remaining time (remain_t) and pushes value to queue (q, dq, ddq).
15  // Users can get interpolated results from queue (q, dq, ddq).
16  // If remain_t <= 0 and queue is empty, interpolator is "empty", otherwise "not empty".
17  // This is related with isEmpty() function.
18  // Setting goal value : setGoal(), go(), and load()
19  // Getting current value : get()
20  // Resetting current value : set()
21  // Interpolate : interpolate()
22 public:
23  typedef enum {LINEAR, HOFFARBIB,QUINTICSPLINE,CUBICSPLINE} interpolation_mode;
24  interpolator(int dim_, double dt_, interpolation_mode imode_=HOFFARBIB, double default_avg_vel_=0.5); // default_avg_vel = [rad/s]
25  ~interpolator();
26  void push(const double *x_, const double *v_, const double *a_, bool immediate=true);
27  double *front();
28  // Getter function.
29  // 1. Interpolate value if remain_t > 0 (time to goal is remaining).
30  // 2. Get value.
31  // 3. Pop value queue (q, dq, ddq) if popp = true.
32  void get(double *x_, bool popp=true);
33  void get(double *x_, double *v_, bool popp=true);
34  void get(double *x_, double *v_, double *a_, bool popp=true);
35  // Reset current value.
36  void set(const double *x, const double *v=NULL);
37  // Set goal and complete all interpolation.
38  // After calling of go(), value queue (q, dq, ddq) is full and remain_t = 0.
39  void go(const double *gx, const double *gv, double time, bool immediate=true);
40  void go(const double *gx, double time, bool immediate=true);
41  void pop();
42  void pop_back();
43  void clear();
44  void sync();
45  void load(string fname, double time_to_start=1.0, double scale=1.0,
46  bool immediate=true, size_t offset1 = 0, size_t offset2 = 0);
47  void load(const char *fname, double time_to_start=1.0, double scale=1.0,
48  bool immediate=true, size_t offset1 = 0, size_t offset2 = 0);
49  bool isEmpty();
50  double remain_time();
51  double calc_interpolation_time(const double *g);
52  bool setInterpolationMode (interpolation_mode i_mode_);
53  // Set goal
54  // If online=true, user can get and interpolate value through get() function.
55  void setGoal(const double *gx, const double *gv, double time,
56  bool online=true);
57  void setGoal(const double *gx, double time, bool online=true);
58  // Interpolate value and push value to queue (q, dq, ddq).
59  // If remain_t <= 0, do nothing.
60  void interpolate(double& remain_t_);
61  double deltaT() const { return dt; }
62  int dimension() const { return dim; }
63  void setName (const std::string& _name) { name = _name; };
64 private:
65  // Current interpolation mode
66  interpolation_mode imode;
67  // Queue of positions, velocities, and accelerations ([q_t, q_t+1, ...., q_t+n]).
68  deque<double *> q, dq, ddq;
69  // Length of queue.
70  int length;
71  // Dimension of interpolated vector (dim of x, v, a, ... etc)
72  int dim;
73  // Control time [s]
74  double dt;
75  // Current positions, velocities, and accelerations.
76  double *x, *v, *a;
77  // Current goal positions, velocities, and accelerations.
78  double *gx, *gv, *ga;
79  // target_t : time to goal [s] at setGoal
80  // remain_t : time to goal [s] from current time. remain_t is [0, target_t].
81  double target_t, remain_t;
82  // Coefficients for interpolation polynomials.
83  double *a0, *a1, *a2, *a3, *a4, *a5;
84  // Default average velocity for calc_interpolation_time
86  // Interpolator name
87  std::string name;
88 
89  void hoffarbib(double &remain_t_,
90  double a0, double a1, double a2,
91  double a3, double a4, double a5,
92  double &xx, double &vv, double &aa);
93  void linear_interpolation(double &remain_t_,
94  double gx,
95  double &xx, double &vv, double &aa);
96  //Mutex to avoid poping twice the same element
98 };
99 
100 #endif
SequenceElement & front(CorbaSequence &seq)
void clear(CorbaSequence &seq)
std::string name
Definition: interpolator.h:87
double * gx
Definition: interpolator.h:78
png_infop png_charpp name
void setName(const std::string &_name)
Definition: interpolator.h:63
int dimension() const
Definition: interpolator.h:62
coil::Mutex pop_mutex_
Definition: interpolator.h:97
double default_avg_vel
Definition: interpolator.h:85
double target_t
Definition: interpolator.h:81
a0
double * x
Definition: interpolator.h:76
double deltaT() const
Definition: interpolator.h:61
deque< double * > q
Definition: interpolator.h:68
double * a5
Definition: interpolator.h:83


hrpsys
Author(s): AIST, Fumio Kanehiro
autogenerated on Thu May 6 2021 02:41:50