preview_control.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 
18 
19 using namespace robotis_framework;
20 
22 {
23 
24 }
25 
27 {
28 
29 }
30 
31 Eigen::MatrixXd PreviewControl::calcPreviewParam(double preview_time, double control_cycle,
32  double lipm_height,
33  Eigen::MatrixXd K, Eigen::MatrixXd P)
34 {
35  double t = control_cycle;
36  double preview_size_ = round(preview_time/control_cycle) + 1;
37 
38  Eigen::MatrixXd A;
39  A.resize(3,3);
40  A << 1, t, t*t/2.0,
41  0, 1, t,
42  0, 0, 1;
43 
44  Eigen::MatrixXd b;
45  b.resize(3,1);
46  b << t*t*t/6.0,
47  t*t/2.0,
48  t;
49 
50  Eigen::MatrixXd c_;
51  c_.resize(1,3);
52  c_ << 1, 0, -lipm_height/9.81;
53 
54  Eigen::MatrixXd tempA = Eigen::MatrixXd::Zero(4,4);
55  Eigen::MatrixXd tempb = Eigen::MatrixXd::Zero(4,1);
56  Eigen::MatrixXd tempc = Eigen::MatrixXd::Zero(1,4);
57 
58  tempA.coeffRef(0,0) = 1;
59  tempA.block<1,3>(0,1) = c_*A;
60  tempA.block<3,3>(1,1) = A;
61 
62  tempb.coeffRef(0,0) = (c_*b).coeff(0,0);
63  tempb.block<3,1>(1,0) = b;
64 
65  tempc.coeffRef(0,0) = 1;
66 
67  double R = 1e-6;
68  double Q_e = 1;
69  double Q_x = 0;
70 
71  Eigen::MatrixXd Q = Eigen::MatrixXd::Zero(4,4);
72  Q.coeffRef(0,0) = Q_e;
73  Q.coeffRef(1,1) = Q_e;
74  Q.coeffRef(2,2) = Q_e;
75  Q.coeffRef(3,3) = Q_x;
76 
77  Eigen::MatrixXd f;
78  f.resize(1, preview_size_);
79 
80  Eigen::MatrixXd mat_R = Eigen::MatrixXd::Zero(1,1);
81  mat_R.coeffRef(0,0) = R;
82 
83  Eigen::MatrixXd tempCoeff1 = mat_R + ((tempb.transpose() * P) * tempb);
84  Eigen::MatrixXd tempCoeff1_inv = tempCoeff1.inverse();
85  Eigen::MatrixXd tempCoeff2 = tempb.transpose();
86  Eigen::MatrixXd tempCoeff3 = Eigen::MatrixXd::Identity(4,4);
87  Eigen::MatrixXd tempCoeff4 = P*tempc.transpose();
88 
89  f.block<1,1>(0,0) = ((tempCoeff1_inv*tempCoeff2)* tempCoeff3) * tempCoeff4;
90 
91  for(int i = 1; i < preview_size_; i++)
92  {
93  tempCoeff3 = tempCoeff3*((tempA - tempb*K).transpose());
94  f.block<1,1>(0,i) = ((tempCoeff1_inv*tempCoeff2)* tempCoeff3) * tempCoeff4;
95  }
96 
97  return f;
98 }
f
Eigen::MatrixXd calcPreviewParam(double preview_time, double control_cycle, double lipm_height, Eigen::MatrixXd K, Eigen::MatrixXd P)


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