8 #include "hrpsys/util/Hrpsys.h" 23 std::vector<std::vector<Eigen::Vector2d> >
fs;
28 std::cerr <<
"distribution_algorithm = ";
29 if (distribution_algorithm==
EEFM) std::cerr <<
"EEFM";
30 else if (distribution_algorithm==
EEFMQP) std::cerr <<
"EEFMQP";
31 else if (distribution_algorithm==
EEFMQP2) std::cerr <<
"EEFMQP(cop_distribution)";
32 else if (distribution_algorithm==
EEFMQPCOP) std::cerr <<
"EEFMQPCOP";
33 else if (distribution_algorithm==
EEFMQPCOP2) std::cerr <<
"EEFMQPCOP2";
34 else std::cerr <<
"None?";
35 std::cerr <<
", sleep_msec = " << sleep_msec <<
"[msec]" << std::endl;
39 std::vector<double> x_vec;
45 std::vector<double> y_vec;
51 std::vector<hrp::Vector3> refzmp_vec;
52 for (
size_t xx = 0; xx < x_vec.size(); xx++) {
53 for (
size_t yy = 0; yy < y_vec.size(); yy++) {
54 refzmp_vec.push_back(
hrp::Vector3(x_vec[xx], y_vec[yy], 0.0));
65 gp =
popen(
"gnuplot",
"w");
66 gp_m =
popen(
"gnuplot",
"w");
67 gp_f =
popen(
"gnuplot",
"w");
68 gp_a =
popen(
"gnuplot",
"w");
70 std::string fname_fm(
"/tmp/plot-fm.dat");
71 FILE* fp_fm = fopen(fname_fm.c_str(),
"w");
72 std::vector<std::string> names;
73 names.push_back(
"rleg");
74 names.push_back(
"lleg");
75 std::vector<double> limb_gains(names.size(), 1.0);
76 std::vector<double> toeheel_ratio(names.size(), 1.0);
77 std::vector<hrp::Vector3> ref_foot_force(names.size(), hrp::Vector3::Zero()), ref_foot_moment(names.size(), hrp::Vector3::Zero());
78 std::vector<std::vector<Eigen::Vector2d> >
fs;
81 std::ostringstream oss_foot_params(
"");
82 oss_foot_params <<
"'/tmp/plotrleg.dat' using 1:2:3 with lines title 'rleg', " 83 <<
"'/tmp/plotlleg.dat' using 1:2:3 with lines title 'lleg', " 84 <<
"'/tmp/plotrleg-cop.dat' using 1:2:3 with points title 'rleg cop', " 85 <<
"'/tmp/plotlleg-cop.dat' using 1:2:3 with points title 'lleg cop', ";
86 std::string foot_params_str = oss_foot_params.str();
88 for (
size_t i = 0;
i < refzmp_vec.size();
i++) {
89 double alpha = szd->
calcAlpha(refzmp_vec[
i], ee_pos, ee_rot, names);
90 if (distribution_algorithm ==
EEFMQP) {
92 ee_pos, cop_pos, ee_rot, names, limb_gains, toeheel_ratio,
93 refzmp_vec[i], refzmp_vec[i],
95 }
else if (distribution_algorithm ==
EEFMQP || distribution_algorithm ==
EEFMQP2) {
97 ee_pos, cop_pos, ee_rot, names, limb_gains, toeheel_ratio,
98 refzmp_vec[i], refzmp_vec[i],
99 total_fz, dt,
true,
"", (distribution_algorithm ==
EEFMQP2));
100 }
else if (distribution_algorithm ==
EEFMQPCOP) {
102 ee_pos, cop_pos, ee_rot, names, limb_gains, toeheel_ratio,
103 refzmp_vec[i], refzmp_vec[i],
104 total_fz, dt,
true,
"");
105 }
else if (distribution_algorithm ==
EEFMQPCOP2) {
112 for (
size_t j = 0;
j < fs.size();
j++) {
113 std::string fname(
"/tmp/plot"+names[
j]+
".dat");
114 FILE*
fp = fopen(fname.c_str(),
"w");
115 for (
size_t i = 0; i < fs[
j].size(); i++) {
117 fprintf(fp,
"%f %f %f\n", tmpf(0), tmpf(1), tmpf(2));
120 fprintf(fp,
"%f %f %f\n", tmpf(0), tmpf(1), tmpf(2));
123 for (
size_t j = 0;
j < fs.size();
j++) {
124 std::string fname(
"/tmp/plot"+names[
j]+
"-cop.dat");
125 FILE*
fp = fopen(fname.c_str(),
"w");
126 fprintf(fp,
"%f %f %f\n", ee_pos[
j](0), ee_pos[
j](1), ee_pos[
j](2));
129 for (
size_t j = 0;
j < fs.size();
j++) {
130 std::string fname(
"/tmp/plot"+names[
j]+
"fm.dat");
131 FILE*
fp = fopen(fname.c_str(),
"w");
133 cop(0) = -ref_foot_moment[
j](1)/ref_foot_force[
j](2) + cop_pos[
j](0);
134 cop(1) = ref_foot_moment[
j](0)/ref_foot_force[
j](2) + cop_pos[
j](1);
135 fprintf(fp,
"%f %f 0\n", cop(0), cop(1));
136 fprintf(fp,
"%f %f %f\n", cop(0), cop(1), ref_foot_force[
j](2));
139 fprintf(fp_fm,
"%f %f %f %f %f %f %f %f %f\n",
140 refzmp_vec[i](0), refzmp_vec[i](1),
141 ref_foot_force[0](2), ref_foot_force[1](2),
142 ref_foot_moment[0](0), ref_foot_moment[1](0),
143 ref_foot_moment[0](1), ref_foot_moment[1](1),
146 std::string fname(
"/tmp/plotzmp.dat");
147 FILE*
fp = fopen(fname.c_str(),
"w");
148 fprintf(fp,
"%f %f %f\n", refzmp_vec[i](0), refzmp_vec[i](1), refzmp_vec[i](2));
152 std::ostringstream oss(
"");
153 oss <<
"splot [-0.5:0.5][-0.5:0.5][-1:1000] " << foot_params_str
154 <<
"'/tmp/plotrlegfm.dat' using 1:2:3 with lines title 'rleg fm' lw 5, " 155 <<
"'/tmp/plotllegfm.dat' using 1:2:3 with lines title 'lleg fm' lw 5, " 156 <<
"'/tmp/plotzmp.dat' using 1:2:3 with points title 'zmp' lw 10";
157 fprintf(gp,
"%s\n", oss.str().c_str());
164 std::ostringstream oss(
"");
165 oss <<
"splot [-0.5:0.5][-0.5:0.5][-100:100] " << foot_params_str
166 <<
"'/tmp/plot-fm.dat' using 1:2:5 with points title 'rleg nx' lw 5, " 167 <<
"'/tmp/plot-fm.dat' using 1:2:6 with points title 'lleg nx' lw 5, " 168 <<
"'/tmp/plot-fm.dat' using 1:2:7 with points title 'rleg ny' lw 5, " 169 <<
"'/tmp/plot-fm.dat' using 1:2:8 with points title 'lleg ny' lw 5";
170 fprintf(gp_m,
"%s\n", oss.str().c_str());
173 oss <<
"splot [-0.5:0.5][-0.5:0.5][-50:" << total_fz*1.1 <<
"] " << foot_params_str
174 <<
"'/tmp/plot-fm.dat' using 1:2:3 with points title 'rleg fz' lw 5, " 175 <<
"'/tmp/plot-fm.dat' using 1:2:4 with points title 'lleg fz' lw 5";
176 fprintf(gp_f,
"%s\n", oss.str().c_str());
179 oss <<
"splot [-0.5:0.5][-0.5:0.5][-0.1:1.1] " << foot_params_str
180 <<
"'/tmp/plot-fm.dat' using 1:2:9 with points title 'alpha' lw 5";
181 fprintf(gp_a,
"%s\n", oss.str().c_str());
207 for (
int i = 0;
i < arg_strs.size(); ++
i) {
208 if ( arg_strs[
i]==
"--distribution-algorithm" ) {
209 if (++
i < arg_strs.size()) {
210 if (arg_strs[
i]==
"EEFM") {
211 distribution_algorithm =
EEFM;
212 }
else if (arg_strs[
i]==
"EEFMQP") {
213 distribution_algorithm =
EEFMQP;
214 }
else if (arg_strs[
i]==
"EEFMQP2") {
215 distribution_algorithm =
EEFMQP2;
216 }
else if (arg_strs[
i]==
"EEFMQPCOP") {
218 }
else if (arg_strs[
i]==
"EEFMQPCOP") {
220 }
else if (arg_strs[
i]==
"EEFMQPCOP2") {
223 distribution_algorithm =
EEFM;
226 }
else if ( arg_strs[
i]==
"--sleep-msec" ) {
227 if (++
i < arg_strs.size()) sleep_msec = atoi(arg_strs[
i].c_str());
228 }
else if ( arg_strs[
i]==
"--use-gnuplot" ) {
229 if (++
i < arg_strs.size()) use_gnuplot = (arg_strs[
i]==
"true");
236 std::cerr <<
"test0 : Default foot pos" << std::endl;
239 ee_rot.push_back(hrp::Matrix33::Identity());
240 ee_rot.push_back(hrp::Matrix33::Identity());
246 std::cerr <<
"test1 : Fwd foot pos" << std::endl;
251 ee_rot.push_back(hrp::Matrix33::Identity());
252 ee_rot.push_back(hrp::Matrix33::Identity());
258 std::cerr <<
"test2 : Rot foot pos" << std::endl;
265 ee_rot.push_back(tmpr);
267 ee_rot.push_back(tmpr);
306 std::cerr <<
"Usage : testZMPDistributor [robot-name] [test-type] [option]" << std::endl;
307 std::cerr <<
" [robot-name] should be: --hrp2jsk, --jaxon_red" << std::endl;
308 std::cerr <<
" [test-type] should be:" << std::endl;
309 std::cerr <<
" --test0 : Default foot pos" << std::endl;
310 std::cerr <<
" --test1 : Fwd foot pos" << std::endl;
311 std::cerr <<
" --test2 : Rot foot pos" << std::endl;
314 int main(
int argc,
char* argv[])
319 if (std::string(argv[1]) ==
"--hrp2jsk") {
321 }
else if (std::string(argv[1]) ==
"--jaxon_red") {
328 for (
int i = 2;
i < argc; ++
i) {
329 tzd->
arg_strs.push_back(std::string(argv[
i]));
331 if (std::string(argv[2]) ==
"--test0") {
333 }
else if (std::string(argv[2]) ==
"--test1") {
335 }
else if (std::string(argv[2]) ==
"--test2") {
std::vector< std::vector< Eigen::Vector2d > > fs
testZMPDistributor(const double _dt)
RTC::ReturnCode_t ret(RTC::Local::ReturnCode_t r)
std::vector< hrp::Vector3 > ee_pos
testZMPDistributorJAXON_RED()
void distributeZMPToForceMomentsQP(std::vector< hrp::Vector3 > &ref_foot_force, std::vector< hrp::Vector3 > &ref_foot_moment, const std::vector< hrp::Vector3 > &ee_pos, const std::vector< hrp::Vector3 > &cop_pos, const std::vector< hrp::Matrix33 > &ee_rot, const std::vector< std::string > &ee_name, const std::vector< double > &limb_gains, const std::vector< double > &toeheel_ratio, const hrp::Vector3 &new_refzmp, const hrp::Vector3 &ref_zmp, const double total_fz, const double dt, const bool printp=true, const std::string &print_str="", const bool use_cop_distribution=false)
SimpleZMPDistributor * szd
double calcAlpha(const hrp::Vector3 &tmprefzmp, const std::vector< hrp::Vector3 > &ee_pos, const std::vector< hrp::Matrix33 > &ee_rot, const std::vector< std::string > &ee_name)
enum testZMPDistributor::@13 distribution_algorithm
Matrix33 rotFromRpy(const Vector3 &rpy)
void set_leg_inside_margin(const double a)
void set_leg_front_margin(const double a)
std::vector< std::string > arg_strs
testZMPDistributorHRP2JSK()
def j(str, encoding="cp932")
int main(int argc, char *argv[])
void set_vertices_from_margin_params()
FILE * popen(const char *cmd, const char *mode)
void distributeZMPToForceMoments(std::vector< hrp::Vector3 > &ref_foot_force, std::vector< hrp::Vector3 > &ref_foot_moment, const std::vector< hrp::Vector3 > &ee_pos, const std::vector< hrp::Vector3 > &cop_pos, const std::vector< hrp::Matrix33 > &ee_rot, const std::vector< std::string > &ee_name, const std::vector< double > &limb_gains, const std::vector< double > &toeheel_ratio, const hrp::Vector3 &new_refzmp, const hrp::Vector3 &ref_zmp, const double total_fz, const double dt, const bool printp=true, const std::string &print_str="")
void print_params(const std::string &str)
void set_leg_outside_margin(const double a)
void get_vertices(std::vector< std::vector< Eigen::Vector2d > > &vs)
void set_leg_rear_margin(const double a)
void print_vertices(const std::string &str)
void distributeZMPToForceMomentsPseudoInverse(std::vector< hrp::Vector3 > &ref_foot_force, std::vector< hrp::Vector3 > &ref_foot_moment, const std::vector< hrp::Vector3 > &ee_pos, const std::vector< hrp::Vector3 > &cop_pos, const std::vector< hrp::Matrix33 > &ee_rot, const std::vector< std::string > &ee_name, const std::vector< double > &limb_gains, const std::vector< double > &toeheel_ratio, const hrp::Vector3 &new_refzmp, const hrp::Vector3 &ref_zmp, const double total_fz, const double dt, const bool printp=true, const std::string &print_str="", const bool use_cop_distribution=true, const std::vector< bool > is_contact_list=std::vector< bool >())
std::vector< hrp::Vector3 > cop_pos
std::vector< hrp::Matrix33 > ee_rot
std::vector< hrp::Vector3 > leg_pos
virtual ~testZMPDistributor()
int usleep(useconds_t usec)