PreviewController.cpp
Go to the documentation of this file.
1 /* -*- coding:utf-8-unix; mode:c++; -*- */
2 #include "PreviewController.h"
3 
4 using namespace hrp;
5 using namespace rats;
6 
7 template <std::size_t dim>
8 void preview_control_base<dim>::update_x_k(const hrp::Vector3& pr, const std::vector<hrp::Vector3>& _qdata)
9 {
10  zmp_z = pr(2);
11  Eigen::Matrix<double, 2, 1> tmpv;
12  tmpv(0,0) = pr(0);
13  tmpv(1,0) = pr(1);
14  p.push_back(tmpv);
15  pz.push_back(pr(2));
16  qdata.push_back(_qdata);
17  if ( p.size() > 1 + delay ) {
18  p.pop_front();
19  pz.pop_front();
20  qdata.pop_front();
21  }
22  if ( is_doing() ) calc_x_k();
23 }
24 
25 // template <std::size_t dim>
26 // void preview_control_base<dim>::update_zc(double zc)
27 // {
28 // riccati.c(0, 2) = - zc / gravitational_acceleration;
29 // riccati.solve();
30 // }
31 
32 void preview_control::calc_f()
33 {
34  f.resize(delay+1);
35  f(0)=0;
36  Eigen::Matrix<double, 1, 1> fa;
37  hrp::Matrix33 gsi(hrp::Matrix33::Identity());
38  for (size_t i = 0; i < delay; i++) {
39  fa = riccati.R_btPb_inv * riccati.b.transpose() * (gsi * riccati.Q * riccati.c.transpose());
40  gsi = riccati.A_minus_bKt * gsi;
41  f(i+1) = fa(0,0);
42  }
43 }
44 
45 void preview_control::calc_u()
46 {
47  Eigen::Matrix<double, 1, 2> gfp(Eigen::Matrix<double, 1, 2>::Zero());
48  for (size_t i = 0; i < 1 + delay; i++)
49  gfp += f(i) * p[i];
50  u_k = -riccati.K * x_k + gfp;
51 };
52 
53 void preview_control::calc_x_k()
54 {
55  calc_u();
56  x_k = riccati.A * x_k + riccati.b * u_k;
57 }
58 
59 void extended_preview_control::calc_f()
60 {
61  f.resize(delay + 1);
62  f(0)=0;
63  Eigen::Matrix<double, 1, 1> fa;
64  Eigen::Matrix<double, 4, 4> gsi(Eigen::Matrix<double, 4, 4>::Identity());
65  Eigen::Matrix<double, 4, 1> qt(riccati.Q * riccati.c.transpose());
66  for (size_t i = 0; i < delay; i++) {
67  if ( i == delay - 1 ) qt = riccati.P * qt;
68  fa = riccati.R_btPb_inv * riccati.b.transpose() * (gsi * qt);
69  gsi = riccati.A_minus_bKt * gsi;
70  f(i+1) = fa(0,0);
71  }
72 }
73 
74 void extended_preview_control::calc_u()
75 {
76  Eigen::Matrix<double, 1, 2> gfp(Eigen::Matrix<double, 1, 2>::Zero());
77  for (size_t i = 0; i < 1 + delay; i++)
78  gfp += f(i) * p[i];
79  u_k = -riccati.K * x_k_e + gfp;
80 };
81 
82 void extended_preview_control::calc_x_k()
83 {
84  calc_u();
85  x_k_e = riccati.A * x_k_e + riccati.b * u_k;
86  for (size_t i = 0; i < 3; i++)
87  for (size_t j = 0; j < 2; j++)
88  x_k(i,j) += x_k_e(i+1,j);
89 }
90 
png_uint_32 i
Eigen::Vector3d Vector3
Eigen::Matrix3d Matrix33
def j(str, encoding="cp932")


hrpsys
Author(s): AIST, Fumio Kanehiro
autogenerated on Thu May 6 2021 02:41:50