RobotArmLib 0.0.6
Robot Arm Library [WIP]
Loading...
Searching...
No Matches
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
13namespace rb
14{
15namespace math
16{
21{
22public:
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 {
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
121 double getAcceleration(const double& T) const
122 {
124 for (int i = 0; i < vecT.size(); ++i)
125 {
126 vecT[i] = (i + 1) * (i + 2) * pow(T, i);
127 }
128 double accel = c_.tail(degree_ - 1).transpose() * vecT;
129 return accel;
130 }
131
136 short getDegree(void) const
137 {
138 return this->degree_;
139 };
140
146 {
147 return this->c_;
148 };
149
150
151protected:
152 short degree_;
154 double t_;
155
156private:
157
158};
159
160} // namespace math
161} // namespace rb
162#endif // RB_POLYNOMIAL_H_
A class for constructing polynomial function.
Definition polynomial.h:21
short degree_
An integer indicate degree of polynomial.
Definition polynomial.h:152
rb::math::VectorX getCoeff(void) const
Get the coefficients of the polynomial function.
Definition polynomial.h:145
double t_
The duration (time) of polynomial function f(t).
Definition polynomial.h:154
Polynomial()
Default Construction.
Definition polynomial.h:24
rb::math::VectorX c_
A vector of coefficient of polynomial.
Definition polynomial.h:153
Polynomial(const short deg, const double t=0.)
Construct polynomial with given degree.
Definition polynomial.h:30
double getAcceleration(const double &T) const
Get the 2nd order differential value (acceleration) of polynomial f(t) at time T.
Definition polynomial.h:121
double getPosition(const double &T) const
Get the value (position) of polynomial f(t) at time T.
Definition polynomial.h:86
short getDegree(void) const
Get the degree (order) of the polynomial function.
Definition polynomial.h:136
double getVelocity(const double &T) const
Get the 1st order differential value (velocity) of polynomial f(t) at time T.
Definition polynomial.h:103
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
A head file define tpyes, and function for matrix manipulating.
Eigen::Array< T, R, C > Array
make Array as alias of Eigen::Array (class template)
Definition matrix.h:31
Eigen::Matrix3d Matrix3
make Matrix3 as alias of Eigen::Matrix3d
Definition matrix.h:20
Eigen::VectorXd VectorX
make VectorX as alias of Eigen::VectorXd
Definition matrix.h:23
Robot Arm Library namespace.
Definition artic.cpp:13