23 std::string fname(
"/tmp/plot-octd.dat");
24 FILE*
fp = fopen(fname.c_str(),
"w");
25 bool detected =
false;
26 double max_f = -1e10, min_f = 1e10;
27 for (
size_t i = 0;
i < time_vec.size();
i++) {
28 bool tmp_detected = octd.
checkDetection(forces_vec[
i], moments_vec[i], hpos_vec[i]);
29 if (tmp_detected && !detected) {
30 detect_time = time_vec[i];
34 fprintf(fp,
"%f %f %f %f\n", time_vec[i], log_data[1], log_data[2], log_data[3], detected);
35 max_f =
std::max(max_f, log_data[1]);
36 min_f =
std::min(min_f, log_data[1]);
41 std::string titles[2] = {
"Wrench",
"Dwrench"};
43 FILE* gp =
popen(
"gnuplot",
"w");
44 fprintf(gp,
"set multiplot layout 2, 1 title 'Results'\n");
45 fprintf(gp,
"set xlabel 'Time [s]'\n");
46 fprintf(gp,
"set ylabel 'Wrench'\n");
47 fprintf(gp,
"set arrow from %f,%f to %f,%f\n", detect_time, min_f, detect_time, max_f);
48 fprintf(gp,
"plot '/tmp/plot-octd.dat' using 1:2 with lines title 'Wrench' lw 4, '/tmp/plot-octd.dat' using 1:3 with lines title 'FilteredWrench' lw 4\n");
49 fprintf(gp,
"unset arrow\n");
50 fprintf(gp,
"set xlabel 'Time [s]'\n");
51 fprintf(gp,
"set ylabel 'Dwrench'\n");
52 fprintf(gp,
"plot '/tmp/plot-octd.dat' using 1:4 with lines title 'Dwrench' lw 4\n");
66 octd.
setAxis(hrp::Vector3::UnitZ());
72 for (
size_t i = 0;
i < force_vec.size();
i++) {
73 std::vector<hrp::Vector3> tmpv(1, hrp::Vector3::Zero());
74 moments_vec.push_back(tmpv);
75 hpos_vec.push_back(tmpv);
76 tmpv[0] = force_vec[
i] * force_dir;
77 forces_vec.push_back(tmpv);
83 ccm1(idx) = (is_positive?1.0:-1.0);
92 for (
size_t i = 0;
i < 3;
i++) resultant_wrench_direction_vector(
i) = tmp(
i);
93 tmp = fpos.cross(fdir);
94 for (
size_t i = 0;
i < 3;
i++) resultant_wrench_direction_vector(
i+3) = tmp(
i);
95 return -1*ccm1.dot(resultant_wrench_direction_vector) * df;
99 const double start_resultant_force,
const double turnaround_resultant_force,
102 std::vector<double> phi_vec;
103 double dphi = (turnaround_resultant_force-start_resultant_force)/(turnaround_tm-start_tm);
104 true_turnaround_time = turnaround_tm;
105 for (
size_t i = 0; i < static_cast<size_t>(total_tm/
dt);
i++) {
106 double current_tm =
i*
dt;
107 time_vec.push_back(current_tm);
108 if (current_tm < start_tm) {
109 phi_vec.push_back(start_resultant_force);
110 }
else if (current_tm < turnaround_tm) {
111 phi_vec.push_back(start_resultant_force+dphi*(current_tm-start_tm));
113 phi_vec.push_back(turnaround_resultant_force);
120 const double start_resultant_force,
const double turnaround_resultant_force,
123 std::vector<double> phi_vec;
124 double dphi = (turnaround_resultant_force-start_resultant_force)/(turnaround_tm-start_tm);
125 true_turnaround_time = turnaround_tm;
126 for (
size_t i = 0; i < static_cast<size_t>(total_tm/
dt);
i++) {
127 double current_tm =
i*
dt;
128 time_vec.push_back(current_tm);
129 if (current_tm < start_tm) {
130 phi_vec.push_back(start_resultant_force);
131 }
else if (current_tm < turnaround_tm) {
132 phi_vec.push_back(start_resultant_force+dphi*(current_tm-start_tm));
134 phi_vec.push_back(turnaround_resultant_force+(current_tm-turnaround_tm)*-2*dphi );
142 std::cerr <<
"test0 : Increasing->saturation (TOTAL_FORCE)" << std::endl;
143 double total_tm = 4.0, start_tm = total_tm*0.1, turnaround_tm = total_tm*0.4, start_resultant_force = 0.0, turnaround_resultant_force = 40.0, dphi;
150 std::cerr <<
"test1 : Increasing->decreasing (TOTAL_FORCE)" << std::endl;
151 double total_tm = 4.0, start_tm = total_tm*0.1, turnaround_tm = total_tm*0.4, start_resultant_force = 0.0, turnaround_resultant_force = 40.0, dphi;
158 std::cerr <<
"test2 : Deacreasing->saturation (TOTAL_FORCE)" << std::endl;
159 double total_tm = 4.0, start_tm = total_tm*0.1, turnaround_tm = total_tm*0.4, start_resultant_force = 0.0, turnaround_resultant_force = -40.0, dphi;
166 std::cerr <<
"test3 : Decreasing->increasing (TOTAL_FORCE)" << std::endl;
167 double total_tm = 4.0, start_tm = total_tm*0.1, turnaround_tm = total_tm*0.4, start_resultant_force = 0.0, turnaround_resultant_force = -40.0, dphi;
174 std::cerr <<
"test4 : Lift up (GENERALIZED_WRENCH)" << std::endl;
175 double total_tm = 4.0, start_tm = total_tm*0.1, turnaround_tm = total_tm*0.4, start_resultant_force = 0.0, turnaround_resultant_force = -40.0, dphi;
181 std::vector<hrp::dvector6>(1, hrp::dvector6::Zero()),
182 std::vector<double>(1, ref_dwrench));
189 std::cerr <<
"test5 : Push fwd (GENERALIZED_WRENCH)" << std::endl;
190 double total_tm = 4.0, start_tm = total_tm*0.1, turnaround_tm = total_tm*0.4, start_resultant_force = 0.0, turnaround_resultant_force = -40.0, dphi;
191 dphi = std::fabs(
gen_forces_moments_for_saturation(total_tm, start_tm, turnaround_tm, start_resultant_force, turnaround_resultant_force, hrp::Vector3::UnitX()));
196 std::vector<hrp::dvector6>(1, hrp::dvector6::Zero()),
197 std::vector<double>(1, ref_dwrench));
204 std::cerr <<
"test6 : Push bwd (GENERALIZED_WRENCH)" << std::endl;
205 double total_tm = 4.0, start_tm = total_tm*0.1, turnaround_tm = total_tm*0.4, start_resultant_force = 0.0, turnaround_resultant_force = 40.0, dphi;
206 dphi = std::fabs(
gen_forces_moments_for_saturation(total_tm, start_tm, turnaround_tm, start_resultant_force, turnaround_resultant_force, hrp::Vector3::UnitX()));
211 std::vector<hrp::dvector6>(1, hrp::dvector6::Zero()),
212 std::vector<double>(1, ref_dwrench));
219 std::cerr <<
"test7 : Tilt upward (GENERALIZED_WRENCH)" << std::endl;
220 double total_tm = 4.0, start_tm = total_tm*0.1, turnaround_tm = total_tm*0.4, start_resultant_force = 0.0, turnaround_resultant_force = -40.0, dphi;
223 std::vector<hrp::dvector6> ccm1(1, hrp::dvector6::Zero());
224 ccm1[0](2) = 0.9; ccm1[0](4) = 1.0;
227 std::vector<hrp::dvector6>(1, hrp::dvector6::Zero()),
228 std::vector<double>(1, ref_dwrench));
239 std::cerr <<
"Results:" << std::endl;
240 std::cerr <<
" Detected? : " << (octd.
isDetected()?
"true":
"false") << std::endl;
241 std::cerr <<
" Detection time : " << (
check_detection_time_validity()?
"true":
"false") <<
", detect_time = " << detect_time <<
"[s], true_turnaround_time = " << true_turnaround_time <<
"[s]" << std::endl;
246 for (
unsigned int i = 0;
i < arg_strs.size(); ++
i) {
247 if ( arg_strs[
i]==
"--use-gnuplot" ) {
248 if (++
i < arg_strs.size()) use_gnuplot = (arg_strs[
i]==
"true");
256 std::cerr <<
"Usage : testObjectContactTurnaroundDetectorBase [option]" << std::endl;
257 std::cerr <<
" [option] should be:" << std::endl;
258 std::cerr <<
" --test0 : Increasing->saturation (TOTAL_FORCE)" << std::endl;
259 std::cerr <<
" --test1 : Increasing->saturation (GENERALIZED_WRENCH)" << std::endl;
260 std::cerr <<
" --test2 : Increasing->decreasing (GENERALIZED_WRENCH)" << std::endl;
261 std::cerr <<
" --test3 : Decreasing->saturation (GENERALIZED_WRENCH)" << std::endl;
262 std::cerr <<
" --test4 : Decreasing->increasing (GENERALIZED_WRENCH)" << std::endl;
265 int main(
int argc,
char* argv[])
270 for (
int i = 1;
i < argc; ++
i) {
271 toctd.
arg_strs.push_back(std::string(argv[
i]));
273 if (std::string(argv[1]) ==
"--test0") {
275 }
else if (std::string(argv[1]) ==
"--test1") {
277 }
else if (std::string(argv[1]) ==
"--test2") {
279 }
else if (std::string(argv[1]) ==
"--test3") {
281 }
else if (std::string(argv[1]) ==
"--test4") {
283 }
else if (std::string(argv[1]) ==
"--test5") {
285 }
else if (std::string(argv[1]) ==
"--test6") {
287 }
else if (std::string(argv[1]) ==
"--test7") {
RTC::ReturnCode_t ret(RTC::Local::ReturnCode_t r)
FILE * popen(const char *cmd, const char *mode)
Eigen::Matrix< double, 6, 1 > dvector6