trajectory_generator.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 /* Authors: Darby Lim, Hye-Jong KIM, Ryan Shim, Yong-Ho Na */
18 
20 
22 {
23  coefficient_ = Eigen::VectorXd::Zero(6);
24 }
25 
27 
29  WayPoint goal,
30  double move_time,
31  double control_time)
32 {
33  uint16_t step_time = uint16_t(floor(move_time / control_time) + 1.0);
34  move_time = double(step_time - 1) * control_time;
35 
36  Eigen::Matrix3d A = Eigen::Matrix3d::Identity(3, 3);
37  Eigen::Vector3d x = Eigen::Vector3d::Zero();
38  Eigen::Vector3d b = Eigen::Vector3d::Zero();
39 
40  A << pow(move_time, 3), pow(move_time, 4), pow(move_time, 5),
41  3 * pow(move_time, 2), 4 * pow(move_time, 3), 5 * pow(move_time, 4),
42  6 * pow(move_time, 1), 12 * pow(move_time, 2), 20 * pow(move_time, 3);
43 
44  coefficient_(0) = start.position;
45  coefficient_(1) = start.velocity;
46  coefficient_(2) = 0.5 * start.acceleration;
47 
48  b << (goal.position - start.position - (start.velocity * move_time + 0.5 * start.acceleration * pow(move_time, 2))),
49  (goal.velocity - start.velocity - (start.acceleration * move_time)),
50  (goal.acceleration - start.acceleration);
51 
52  Eigen::ColPivHouseholderQR<Eigen::Matrix3d> dec(A);
53  x = dec.solve(b);
54 
55  coefficient_(3) = x(0);
56  coefficient_(4) = x(1);
57  coefficient_(5) = x(2);
58 }
59 
60 Eigen::VectorXd MinimumJerk::getCoefficient()
61 {
62  return coefficient_;
63 }
64 
65 //-------------------- Joint trajectory --------------------//
66 
68 
70 
71 void JointTrajectory::init(double move_time,
72  double control_time,
73  std::vector<WayPoint> start,
74  std::vector<WayPoint> goal)
75 {
76  for (uint8_t index = 0; index < start.size(); index++)
77  {
78  trajectory_generator_.calcCoefficient(start.at(index),
79  goal.at(index),
80  move_time,
81  control_time);
82 
83  coefficient_.col(index) = trajectory_generator_.getCoefficient();
84  }
85 }
86 
87 void JointTrajectory::setJointNum(uint8_t joint_num)
88 {
89  joint_num_ = joint_num;
90  coefficient_ = Eigen::MatrixXd::Identity(6, joint_num);
91 }
92 
93 std::vector<WayPoint> JointTrajectory::getJointWayPoint(double tick)
94 {
95  joint_way_point_.clear();
96  for (uint8_t index = 0; index < joint_num_; index++)
97  {
98  WayPoint single_joint_way_point;
99  single_joint_way_point.position = 0.0;
100  single_joint_way_point.velocity = 0.0;
101  single_joint_way_point.acceleration = 0.0;
102 
103  single_joint_way_point.position = coefficient_(0, index) +
104  coefficient_(1, index) * pow(tick, 1) +
105  coefficient_(2, index) * pow(tick, 2) +
106  coefficient_(3, index) * pow(tick, 3) +
107  coefficient_(4, index) * pow(tick, 4) +
108  coefficient_(5, index) * pow(tick, 5);
109 
110  single_joint_way_point.velocity = coefficient_(1, index) +
111  2 * coefficient_(2, index) * pow(tick, 1) +
112  3 * coefficient_(3, index) * pow(tick, 2) +
113  4 * coefficient_(4, index) * pow(tick, 3) +
114  5 * coefficient_(5, index) * pow(tick, 4);
115 
116  single_joint_way_point.acceleration = 2 * coefficient_(2, index) +
117  6 * coefficient_(3, index) * pow(tick, 1) +
118  12 * coefficient_(4, index) * pow(tick, 2) +
119  20 * coefficient_(5, index) * pow(tick, 3);
120 
121  joint_way_point_.push_back(single_joint_way_point);
122  }
123 
124  return joint_way_point_;
125 }
126 
128 {
129  return coefficient_;
130 }
Eigen::VectorXd coefficient_
void setJointNum(uint8_t joint_num)
double acceleration
std::vector< WayPoint > getJointWayPoint(double tick)
void init(double move_time, double control_time, std::vector< WayPoint > start, std::vector< WayPoint > goal)
void calcCoefficient(WayPoint start, WayPoint goal, double move_time, double control_time)
Eigen::VectorXd getCoefficient()
Eigen::MatrixXd getCoefficient()


dynamixel_workbench_controllers
Author(s): Darby Lim , Ryan Shim
autogenerated on Mon Sep 28 2020 03:37:06