fifth_order_polynomial_trajectory.cpp
Go to the documentation of this file.
1 /*******************************************************************************
2 * Copyright 2018 ROBOTIS CO., LTD.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *******************************************************************************/
16 
17 /*
18  * fifth_order_polynomial_trajectory.cpp
19  *
20  * Created on: 2016. 8. 24.
21  * Author: Jay Song
22  */
23 
25 
26 using namespace robotis_framework;
27 
28 FifthOrderPolynomialTrajectory::FifthOrderPolynomialTrajectory(double initial_time, double initial_pos, double initial_vel, double initial_acc,
29  double final_time, double final_pos, double final_vel, double final_acc)
30 {
31  position_coeff_.resize(6, 1);
32  velocity_coeff_.resize(6, 1);
33  acceleration_coeff_.resize(6, 1);
34  time_variables_.resize(1, 6);
35 
36  position_coeff_.fill(0);
37  velocity_coeff_.fill(0);
38  acceleration_coeff_.fill(0);
39  time_variables_.fill(0);
40 
41  if(final_time > initial_time)
42  {
43  initial_time_ = initial_time;
44  initial_pos_ = initial_pos;
45  initial_vel_ = initial_vel;
46  initial_acc_ = initial_acc;
47 
48  current_time_ = initial_time;
49  current_pos_ = initial_pos;
50  current_vel_ = initial_vel;
51  current_acc_ = initial_acc;
52 
53  final_time_ = final_time;
54  final_pos_ = final_pos;
55  final_vel_ = final_vel;
56  final_acc_ = final_acc;
57 
58  Eigen::MatrixXd time_mat;
59  Eigen::MatrixXd conditions_mat;
60 
61  time_mat.resize(6,6);
63  5.0*powDI(initial_time_, 4), 4.0*powDI(initial_time_, 3), 3.0*powDI(initial_time_, 2), 2.0*initial_time_, 1.0, 0.0,
64  20.0*powDI(initial_time_, 3), 12.0*powDI(initial_time_, 2), 6.0*initial_time_, 2.0, 0.0, 0.0;
66  5.0*powDI(final_time_, 4), 4.0*powDI(final_time_, 3), 3.0*powDI(final_time_, 2), 2.0*final_time_, 1.0, 0.0,
67  20.0*powDI(final_time_, 3), 12.0*powDI(final_time_, 2), 6.0*final_time_, 2.0, 0.0, 0.0;
68 
69  conditions_mat.resize(6,1);
71 
72  position_coeff_ = time_mat.inverse() * conditions_mat;
73  velocity_coeff_ << 0.0,
74  5.0*position_coeff_.coeff(0,0),
75  4.0*position_coeff_.coeff(1,0),
76  3.0*position_coeff_.coeff(2,0),
77  2.0*position_coeff_.coeff(3,0),
78  1.0*position_coeff_.coeff(4,0);
79  acceleration_coeff_ << 0.0,
80  0.0,
81  20.0*position_coeff_.coeff(0,0),
82  12.0*position_coeff_.coeff(1,0),
83  6.0*position_coeff_.coeff(2,0),
84  2.0*position_coeff_.coeff(3,0);
85  }
86 
87 }
88 
90 {
91  initial_time_ = 0;
92  initial_pos_ = 0;
93  initial_vel_ = 0;
94  initial_acc_ = 0;
95 
96  current_time_ = 0;
97  current_pos_ = 0;
98  current_vel_ = 0;
99  current_acc_ = 0;
100 
101  final_time_ = 0;
102  final_pos_ = 0;
103  final_vel_ = 0;
104  final_acc_ = 0;
105 
106  position_coeff_.resize(6, 1);
107  velocity_coeff_.resize(6, 1);
108  acceleration_coeff_.resize(6, 1);
109  time_variables_.resize(1, 6);
110 
111  position_coeff_.fill(0);
112  velocity_coeff_.fill(0);
113  acceleration_coeff_.fill(0);
114  time_variables_.fill(0);
115 }
116 
118 {
119 
120 }
121 
122 bool FifthOrderPolynomialTrajectory::changeTrajectory(double final_pos, double final_vel, double final_acc)
123 {
124  final_pos_ = final_pos;
125  final_vel_ = final_vel;
126  final_acc_ = final_acc;
127 
128  Eigen::MatrixXd time_mat;
129  Eigen::MatrixXd conditions_mat;
130 
131  time_mat.resize(6,6);
133  5.0*powDI(initial_time_, 4), 4.0*powDI(initial_time_, 3), 3.0*powDI(initial_time_, 2), 2.0*initial_time_, 1.0, 0.0,
134  20.0*powDI(initial_time_, 3), 12.0*powDI(initial_time_, 2), 6.0*initial_time_, 2.0, 0.0, 0.0,
136  5.0*powDI(final_time_, 4), 4.0*powDI(final_time_, 3), 3.0*powDI(final_time_, 2), 2.0*final_time_, 1.0, 0.0,
137  20.0*powDI(final_time_, 3), 12.0*powDI(final_time_, 2), 6.0*final_time_, 2.0, 0.0, 0.0;
138 
139  conditions_mat.resize(6,1);
141 
142  position_coeff_ = time_mat.inverse() * conditions_mat;
143  velocity_coeff_ << 0.0,
144  5.0*position_coeff_.coeff(0,0),
145  4.0*position_coeff_.coeff(1,0),
146  3.0*position_coeff_.coeff(2,0),
147  2.0*position_coeff_.coeff(3,0),
148  1.0*position_coeff_.coeff(4,0);
149  acceleration_coeff_ << 0.0,
150  0.0,
151  20.0*position_coeff_.coeff(0,0),
152  12.0*position_coeff_.coeff(1,0),
153  6.0*position_coeff_.coeff(2,0),
154  2.0*position_coeff_.coeff(3,0);
155 
156  return true;
157 }
158 
159 bool FifthOrderPolynomialTrajectory::changeTrajectory(double final_time, double final_pos, double final_vel, double final_acc)
160 {
161  if(final_time < initial_time_)
162  return false;
163 
164  final_time_ = final_time;
165  return changeTrajectory(final_pos, final_vel, final_acc);
166 }
167 
168 bool FifthOrderPolynomialTrajectory::changeTrajectory(double initial_time, double initial_pos, double initial_vel, double initial_acc,
169  double final_time, double final_pos, double final_vel, double final_acc)
170 {
171  if(final_time < initial_time)
172  return false;
173 
174  initial_time_ = initial_time;
175  initial_pos_ = initial_pos;
176  initial_vel_ = initial_vel;
177  initial_acc_ = initial_acc;
178 
179  final_time_ = final_time;
180 
181  return changeTrajectory(final_pos, final_vel, final_acc);
182 }
183 
185 {
186  if(time >= final_time_)
187  {
192  return final_pos_;
193  }
194  else if(time <= initial_time_ )
195  {
200  return initial_pos_;
201  }
202  else
203  {
204  current_time_ = time;
205  time_variables_ << powDI(time, 5), powDI(time, 4), powDI(time, 3), powDI(time, 2), time, 1.0;
209  return current_pos_;
210  }
211 }
212 
214 {
215  if(time >= final_time_)
216  {
221  return final_vel_;
222  }
223  else if(time <= initial_time_ )
224  {
229  return initial_vel_;
230  }
231  else
232  {
233  current_time_ = time;
234  time_variables_ << powDI(time, 5), powDI(time, 4), powDI(time, 3), powDI(time, 2), time, 1.0;
238  return current_vel_;
239  }
240 }
241 
243 {
244  if(time >= final_time_)
245  {
250  return final_acc_;
251  }
252  else if(time <= initial_time_ )
253  {
258  return initial_acc_;
259  }
260  else
261  {
262  current_time_ = time;
263  time_variables_ << powDI(time, 5), powDI(time, 4), powDI(time, 3), powDI(time, 2), time, 1.0;
267  return current_acc_;
268  }
269 }
270 
272 {
273  if(time >= final_time_)
274  {
279  }
280  else if(time <= initial_time_ )
281  {
286  }
287  else
288  {
289  current_time_ = time;
290  time_variables_ << powDI(time, 5), powDI(time, 4), powDI(time, 3), powDI(time, 2), time, 1.0;
294  }
295 }
296 
298 {
299  return current_pos_;
300 }
301 
303 {
304  return current_vel_;
305 }
306 
308 {
309  return current_acc_;
310 }
double powDI(double a, int b)
bool changeTrajectory(double final_pos, double final_vel, double final_acc)


robotis_math
Author(s): SCH , Kayman , Jay Song
autogenerated on Fri Jul 17 2020 03:17:50