RobotArmLib  0.0.4
Robot Arm Library [WIP]
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
polynomial.h
Go to the documentation of this file.
1 
7 #ifndef RB_POLYNOMIAL_H_
8 #define RB_POLYNOMIAL_H_
9 #include <vector>
10 
11 #include "matrix.h"
12 
13 namespace rb
14 {
15 namespace math
16 {
21 {
22 public:
24  Polynomial() : degree_(0), c_(degree_+1), t_(0.)
25  {
26  // Construct a straight line as Default.
27  };
28 
30  Polynomial(const short deg, const double t=0.) :
31  degree_(deg), c_(deg+1), t_(t)
32  {
33  };
34 
43  const std::vector<double>& start,
44  const std::vector<double>& end,
45  const double& T
46  )
47  {
48  // from initial condition at t=0.
49  this->c_[0] = start[0];
50  this->c_[1] = start[1];
51  this->c_[2] = start[2]/2.;
52 
53  // from initial condition at t=T.
54  this->t_ = T;
55  double T2 = T * T;
56  double T3 = T2 * T;
57  double T4 = T2 * T2;
58  double T5 = T3 * T2;
59  double p1 = c_[0] + c_[1] * T + c_[2] * T2;
60  double p2 = c_[1] + 2. * c_[2] * T;
61  double p3 = 2. * c_[2];
62 
63 
65  A << T3 , T4 , T5 ,
66  3 * T2 , 4 * T3 , 5 * T4 ,
67  6 * T , 12 * T2 , 20 * T3;
68 
69  rb::math::VectorX B(3, 1);
70  B << end[0] - p1,
71  end[1] - p2,
72  end[2] - p3;
73 
74  rb::math::VectorX X = A.inverse() * B;
75 
76  this->c_[3] = X[0];
77  this->c_[4] = X[1];
78  this->c_[5] = X[2];
79  };
80 
86  double getPosition(const double& T) const
87  {
88  rb::math::VectorX vecT(degree_+1);
89  for(int i=0; i<vecT.size(); ++i)
90  {
91  vecT[i] = pow(T, i);
92  }
93  double position = c_.transpose() * vecT;
94  return position;
95  };
96 
103  double getVelocity(const double& T) const
104  {
106  for(int i=0; i<vecT.size(); ++i)
107  {
108  vecT[i] = (i+1) * pow(T, i);
109  }
110 
111  double vel = c_.tail(degree_).transpose() * vecT;
112  return vel;
113  }
114 
119  short getDegree(void) const
120  {
121  return this->degree_;
122  };
123 
129  {
130  return this->c_;
131  };
132 
133 
134 protected:
135  short degree_;
137  double t_;
138 
139 private:
140 
141 };
142 
143 } // namespace math
144 } // namespace rb
145 #endif // RB_POLYNOMIAL_H_
double getPosition(const double &T) const
Get the value (position) of polynomial f(t) at time T.
Definition: polynomial.h:86
Polynomial()
Default Construction.
Definition: polynomial.h:24
short degree_
An integer indicate degree of polynomial.
Definition: polynomial.h:131
void coeffQuintic(const std::vector< double > &start, const std::vector< double > &end, const double &T)
Compute the coefficients of quintic (fifth order) polynomial by giving initial conditions of start an...
Definition: polynomial.h:42
short getDegree(void) const
Get the degree (order) of the polynomial function.
Definition: polynomial.h:119
double t_
The duration (time) of polynomial function f(t).
Definition: polynomial.h:137
Eigen::Matrix3d Matrix3
make Matrix3 as alias of Eigen::Matrix3d
Definition: matrix.h:19
double getVelocity(const double &T) const
Get the 1st order differential value (velocity) of polynomial f(t) at time T.
Definition: polynomial.h:103
Polynomial(const short deg, const double t=0.)
Construct polynomial with given degree.
Definition: polynomial.h:30
rb::math::VectorX getCoeff(void) const
Get the coefficients of the polynomial function.
Definition: polynomial.h:128
A class for constructing polynomial function.
Definition: polynomial.h:20
A head file define tpyes, and function for matrix manipulating.
rb::math::VectorX c_
A vector of coefficient of polynomial.
Definition: polynomial.h:136
Eigen::VectorXd VectorX
make VectorX as alias of Eigen::VectorXd
Definition: matrix.h:22