testPreviewController.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 struct gait_parameter /* for test */
8 {
9  double tm;
11  gait_parameter (const double _tm, const hrp::Vector3& _ref_zmp)
12  : tm(_tm), ref_zmp(_ref_zmp) {};
13 };
14 
15 #include<cstdio>
16 
17 int main(int argc, char* argv[])
18 {
19  /* this is c++ version example of test-preview-filter1-modified in euslib/jsk/preview.l*/
20  bool use_gnuplot = true;
21  if (argc >= 2) {
22  if ( std::string(argv[1])== "--use-gnuplot" ) {
23  use_gnuplot = (std::string(argv[2])=="true");
24  }
25  }
26 
27  double dt = 0.01, max_tm = 8.0;
28  std::queue<hrp::Vector3> ref_zmp_list;
29  std::deque<double> tm_list;
30  for (size_t i = 0; i < static_cast<size_t>(round(max_tm / dt)); i++) {
31  double tmp_tm = i * dt;
32  tm_list.push_back(tmp_tm);
33  hrp::Vector3 v;
34  if (tmp_tm < 2) {
35  v << 0, 0, 0;
36  } else if (tmp_tm < 4) {
37  v << -0.02, 0.02, 0;
38  } else if (tmp_tm < 6) {
39  v << 0.02, -0.02, 0;
40  } else {
41  v << 0, -0.02, 0;
42  }
43  ref_zmp_list.push(v);
44  }
45 
46  //preview_dynamics_filter<preview_control> df(dt, 0.8, ref_zmp_list.front());
47  preview_dynamics_filter<extended_preview_control> df(dt, 0.8, ref_zmp_list.front());
48  std::string fname("/tmp/plot.dat");
49  FILE* fp = fopen(fname.c_str(), "w");
50  double cart_zmp[3], refzmp[3];
51  bool r = true;
52  size_t index = 0;
53  while (r) {
54  hrp::Vector3 p, x;
55  std::vector<hrp::Vector3> qdata;
56  r = df.update(p, x, qdata, ref_zmp_list.front(), qdata, !ref_zmp_list.empty());
57  if (r) {
58  index++;
59  df.get_cart_zmp(cart_zmp);
60  df.get_current_refzmp(refzmp);
61  fprintf(fp, "%f %f %f %f %f %f %f\n",
62  tm_list[index],
63  cart_zmp[0], /* zmpx ;; this zmp is "zmp as a table-cart model" */
64  x[0], /* cogy */
65  refzmp[0], /* refzmpx */
66  cart_zmp[1], /* zmpy ;; this zmp is "zmp as a table-cart model" */
67  x[1], /* cogy */
68  refzmp[1] /* refzmpy */
69  );
70  } else if ( !ref_zmp_list.empty() ) r = true;
71  if (!ref_zmp_list.empty()) ref_zmp_list.pop();
72  }
73  fclose(fp);
74  if (use_gnuplot) {
75  FILE* gp[3];
76  std::string titles[2] = {"X", "Y"};
77  for (size_t ii = 0; ii < 2; ii++) {
78  gp[ii] = popen("gnuplot", "w");
79  fprintf(gp[ii], "set title \"%s\"\n", titles[ii].c_str());
80  fprintf(gp[ii], "plot \"%s\" using 1:%zu with lines title \"cart-table zmp\"\n", fname.c_str(), ( ii * 3 + 2));
81  fprintf(gp[ii], "replot \"%s\" using 1:%zu with lines title \"cog\"\n", fname.c_str(), ( ii * 3 + 3));
82  fprintf(gp[ii], "replot \"%s\" using 1:%zu with lines title \"refzmp\"\n", fname.c_str(), ( ii * 3 + 4));
83  fflush(gp[ii]);
84  }
85  double tmp;
86  std::cin >> tmp;
87  for (size_t j = 0; j < 2; j++) pclose(gp[j]);
88  }
89  return 0;
90 }
png_uint_32 i
Eigen::Vector3d Vector3
png_FILE_p fp
def j(str, encoding="cp932")
list index
FILE * popen(const char *cmd, const char *mode)
int main(int argc, char *argv[])
gait_parameter(const double _tm, const hrp::Vector3 &_ref_zmp)
void pclose(FILE *fd)


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