11 #define rad2deg(rad) (rad * 180 / M_PI) 14 #define deg2rad(deg) (deg * M_PI / 180) 24 const std::vector<hrp::Vector3>& moment_diff_vec,
25 const std::vector<hrp::Vector3>& target_p0_vec,
26 const std::vector<hrp::Matrix33>& target_r0_vec,
27 const std::vector<double>& time_vec)
30 std::string fname(
"/tmp/plot-imp.dat");
31 FILE*
fp = fopen(fname.c_str(),
"w");
32 for (
size_t i = 0;
i < time_vec.size();
i++) {
40 eeR, force_diff_vec[
i], moment_diff_vec[i], dt);
44 fprintf(fp,
"%f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f\n",
48 force_diff_vec[i](0)/imp.
K_p, force_diff_vec[i](1)/imp.
K_p, force_diff_vec[i](2)/imp.
K_p,
57 std::string titles[3] = {
"X",
"Y",
"Z"};
59 FILE* gp_pos =
popen(
"gnuplot",
"w");
60 fprintf(gp_pos,
"set multiplot layout 3, 1 title 'Pos results'\n");
61 for (
size_t ii = 0; ii < 3; ii++) {
62 fprintf(gp_pos,
"set xlabel 'Time [s]'\n");
63 fprintf(gp_pos,
"set ylabel 'pos %s [m]'\n", titles[ii].c_str());
64 fprintf(gp_pos,
"plot '/tmp/plot-imp.dat' using 1:%d with lines title 'cur pos(%s)' lw 4, '/tmp/plot-imp.dat' using 1:%d with lines title 'tgt pos(%s)' lw 3, '/tmp/plot-imp.dat' using 1:%d with lines title 'force_diff/K(%s)' lw 2\n",
65 ii+2, titles[ii].c_str(), ii+2+3, titles[ii].c_str(), ii+2+3*2, titles[ii].c_str());
69 FILE* gp_rot =
popen(
"gnuplot",
"w");
70 fprintf(gp_rot,
"set multiplot layout 3, 1 title 'Rot results'\n");
71 for (
size_t ii = 0; ii < 3; ii++) {
72 fprintf(gp_rot,
"set xlabel 'Time [s]'\n");
73 fprintf(gp_rot,
"set ylabel 'rot %s [deg]'\n", titles[ii].c_str());
74 fprintf(gp_rot,
"plot '/tmp/plot-imp.dat' using 1:%d with lines title 'cur rot(%s)' lw 4, '/tmp/plot-imp.dat' using 1:%d with lines title 'tgt rot(%s)' lw 3, '/tmp/plot-imp.dat' using 1:%d with lines title 'moment_diff/K(%s)' lw 2\n",
75 ii+2+9, titles[ii].c_str(), ii+2+3+9, titles[ii].c_str(), ii+2+3*2+9, titles[ii].c_str());
89 std::cerr <<
"test0 : Set ref force" << std::endl;
90 double tm = 0.0, total_tm = 4.0;
91 std::vector<double> time_vec;
92 std::vector<hrp::Vector3> force_diff_vec, moment_diff_vec, target_p0_vec;
93 std::vector<hrp::Matrix33> target_r0_vec;
94 for (
size_t i = 0; i < static_cast<size_t>(total_tm/
dt);
i++) {
95 time_vec.push_back(tm);
96 force_diff_vec.push_back((
i*dt < total_tm * 0.2 ? hrp::Vector3::Zero() :
hrp::Vector3(10,-20,30)));
97 moment_diff_vec.push_back((
i*dt < total_tm * 0.3 ? hrp::Vector3::Zero() :
hrp::Vector3(5,-10,15)));
98 target_p0_vec.push_back(hrp::Vector3::Zero());
99 target_r0_vec.push_back(hrp::Matrix33::Identity());
106 std::cerr <<
"test1 : Move pos and rot" << std::endl;
107 double tm = 0.0, total_tm = 1.0;
108 std::vector<double> time_vec;
109 std::vector<hrp::Vector3> force_diff_vec, moment_diff_vec, target_p0_vec;
110 std::vector<hrp::Matrix33> target_r0_vec;
112 for (
size_t i = 0; i < static_cast<size_t>(total_tm/
dt);
i++) {
113 time_vec.push_back(tm);
114 force_diff_vec.push_back(hrp::Vector3::Zero());
115 moment_diff_vec.push_back(hrp::Vector3::Zero());
116 double ratio = (
i*dt < total_tm * 0.3 ?
i*dt/(total_tm * 0.3) : 1.0);
119 Eigen::AngleAxis<double> tmpr;
120 if (tmpv.norm() != 0.0) {
121 tmpr = Eigen::AngleAxis<double>(tmpv.norm(), tmpv.normalized());
123 tmpr = hrp::Matrix33::Identity();
125 target_r0_vec.push_back(tmpr.toRotationMatrix());
132 for (
unsigned int i = 0;
i < arg_strs.size(); ++
i) {
133 if ( arg_strs[
i]==
"--use-gnuplot" ) {
134 if (++
i < arg_strs.size()) use_gnuplot = (arg_strs[
i]==
"true");
142 std::cerr <<
"Usage : testImpedanceOutputGenerator [option]" << std::endl;
143 std::cerr <<
" [option] should be:" << std::endl;
144 std::cerr <<
" --test0 : Set ref force" << std::endl;
145 std::cerr <<
" --test1 : Move pos and rot" << std::endl;
148 int main(
int argc,
char* argv[])
153 for (
int i = 1;
i < argc; ++
i) {
154 tiog.
arg_strs.push_back(std::string(argv[
i]));
156 if (std::string(argv[1]) ==
"--test0") {
158 }
else if (std::string(argv[1]) ==
"--test1") {
testImpedanceOutputGenerator(const double _dt=0.004)
std::vector< std::string > arg_strs
void difference_rotation(hrp::Vector3 &ret_dif_rot, const hrp::Matrix33 &self_rot, const hrp::Matrix33 &target_rot)
RTC::ReturnCode_t ret(RTC::Local::ReturnCode_t r)
int main(int argc, char *argv[])
ImpedanceOutputGenerator imp
FILE * popen(const char *cmd, const char *mode)
void gen_pattern_and_plot(const std::vector< hrp::Vector3 > &force_diff_vec, const std::vector< hrp::Vector3 > &moment_diff_vec, const std::vector< hrp::Vector3 > &target_p0_vec, const std::vector< hrp::Matrix33 > &target_r0_vec, const std::vector< double > &time_vec)
void calcTargetVelocity(hrp::Vector3 &vel_p, hrp::Vector3 &vel_r, const hrp::Matrix33 &eeR, const hrp::Vector3 &force_diff, const hrp::Vector3 &moment_diff, const double _dt, const bool printp=false, const std::string &print_str="", const std::string &ee_name="")