11 #define rad2deg(rad) (rad * 180 / M_PI) 14 #define deg2rad(deg) (deg * M_PI / 180) 24 const std::vector<double>& time_vec)
27 std::string fname(
"/tmp/plot-otd.dat");
28 FILE*
fp = fopen(fname.c_str(),
"w");
30 bool detected =
false;
31 for (
size_t i = 0;
i < time_vec.size();
i++) {
33 if (tmp_detected && !detected) {
34 detect_time = time_vec[i];
42 std::string titles[2] = {
"Wrench",
"Dwrench"};
44 FILE* gp =
popen(
"gnuplot",
"w");
45 fprintf(gp,
"set multiplot layout 2, 1 title 'Results'\n");
46 fprintf(gp,
"set xlabel 'Time [s]'\n");
47 fprintf(gp,
"set ylabel 'Wrench'\n");
48 fprintf(gp,
"set arrow from %f,%f to %f,%f\n", detect_time, force_vec.front(), detect_time, force_vec.back());
49 fprintf(gp,
"plot '/tmp/plot-otd.dat' using 1:2 with lines title 'Wrench' lw 4, '/tmp/plot-otd.dat' using 1:3 with lines title 'FilteredWrench' lw 4\n");
50 fprintf(gp,
"set xlabel 'Time [s]'\n");
51 fprintf(gp,
"set ylabel 'Dwrench'\n");
52 fprintf(gp,
"plot '/tmp/plot-otd.dat' using 1:4 with lines title 'Dwrench' lw 4\n");
64 std::cerr <<
"test0 : Set" << std::endl;
65 double tm = 0.0, total_tm = 2.0, df = 10;
66 std::vector<double> time_vec, force_vec;
67 for (
size_t i = 0; i < static_cast<size_t>(total_tm/
dt);
i++) {
68 time_vec.push_back(tm);
69 if (
i*dt < total_tm*0.2) {
70 force_vec.push_back(0);
71 }
else if (
i*dt > total_tm*0.8) {
72 force_vec.push_back(df*total_tm*(0.8-0.2));
74 force_vec.push_back(df*(
i*dt-total_tm*0.2));
83 for (
unsigned int i = 0;
i < arg_strs.size(); ++
i) {
84 if ( arg_strs[
i]==
"--use-gnuplot" ) {
85 if (++
i < arg_strs.size()) use_gnuplot = (arg_strs[
i]==
"true");
93 std::cerr <<
"Usage : testObjectTurnaroundDetector [option]" << std::endl;
94 std::cerr <<
" [option] should be:" << std::endl;
95 std::cerr <<
" --test0 : Set ref force" << std::endl;
99 int main(
int argc,
char* argv[])
104 for (
int i = 1;
i < argc; ++
i) {
105 totd.
arg_strs.push_back(std::string(argv[
i]));
107 if (std::string(argv[1]) ==
"--test0") {
double getFilteredWrench() const
RTC::ReturnCode_t ret(RTC::Local::ReturnCode_t r)
bool checkDetection(const std::vector< hrp::Vector3 > &fmv, const std::vector< hrp::Vector3 > &hposv)
int main(int argc, char *argv[])
ObjectTurnaroundDetector otd
FILE * popen(const char *cmd, const char *mode)
testObjectTurnaroundDetector(const double _dt=0.004)
std::vector< std::string > arg_strs
void gen_pattern_and_plot(const std::vector< double > &force_vec, const std::vector< double > &time_vec)
void startDetection(const double _ref_diff_wrench, const double _max_time)
double getFilteredDwrench() const