19 int main(
int argc,
char *argv[])
22 double Q_angle = 0.001;
23 double Q_rate = 0.003;
26 std::string pose_file(
"test.pose"), acc_file(
"test.acc"), rate_file(
"test.rate");
27 bool use_gnuplot =
false;
30 for (
int i = 0;
i < argc; ++
i) {
31 std::string
arg(argv[
i]);
32 if ( arg ==
"--Q-angle" ) {
33 if (++i < argc) Q_angle = atof(argv[i]);
34 }
else if ( arg ==
"--Q-rate" ) {
35 if (++i < argc) Q_rate = atof(argv[i]);
36 }
else if ( arg ==
"--R-angle" ) {
37 if (++i < argc) R_angle = atof(argv[i]);
38 }
else if ( arg ==
"--dt" ) {
39 if (++i < argc) dt = atof(argv[i]);
40 }
else if ( arg ==
"--rate-file" ) {
41 if (++i < argc) rate_file = argv[i];
42 }
else if ( arg ==
"--acc-file" ) {
43 if (++i < argc) acc_file = argv[i];
44 }
else if ( arg ==
"--pose-file" ) {
45 if (++i < argc) pose_file = argv[i];
46 }
else if ( arg ==
"--use-gnuplot" ) {
47 if (++i < argc) use_gnuplot = (std::string(argv[i])==
"true"?
true:
false);
52 std::ifstream ratef(rate_file.c_str()), accf(acc_file.c_str()), posef(pose_file.c_str());
53 std::cerr <<
"File : " << rate_file <<
" " << acc_file <<
" " << pose_file << std::endl;
54 if (!ratef.is_open() || !accf.is_open() || !posef.is_open()) {
55 std::cerr <<
"No such " << rate_file <<
" " << acc_file <<
" " << pose_file << std::endl;
58 std::string ofname(
"/tmp/testKalmanFilterEstimation.dat");
59 std::ofstream ofs(ofname.c_str());
63 rpy_kf.
setParam(dt, Q_angle, Q_rate, R_angle);
64 hrp::Vector3 rate, acc, rpy, rpyRaw, baseRpyCurrent, rpyAct;
65 double time, time2=0.0;
67 posef >> time >> time >> time >> time >> rpyAct[0] >> rpyAct[1] >> rpyAct[2];
68 ratef >> time >> rate[0] >> rate[1] >> rate[2];
69 accf >> time >> acc[0] >> acc[1] >> acc[2];
70 rpy_kf.main_one(rpy, rpyRaw, baseRpyCurrent, acc, rate, 0.0, hrp::Matrix33::Identity());
75 ofs << time2 <<
" " << rpy[0] <<
" " << rpy[1] <<
" " << rpy[2] <<
" " << rpyAct[0] <<
" " << rpyAct[1] <<
" " << rpyAct[2] << std::endl;
77 std::cout << rpy[0] <<
" " << rpy[1] <<
" " << rpy[2] <<
" " << rpyAct[0] <<
" " << rpyAct[1] <<
" " << rpyAct[2] << std::endl;
84 std::string titles[3] = {
"Roll",
"Pitch",
"Yaw"};
85 for (
size_t ii = 0; ii < 3; ii++) {
86 gp[ii] =
popen(
"gnuplot",
"w");
87 fprintf(gp[ii],
"set title \"%s\"\n", titles[ii].c_str());
88 fprintf(gp[ii],
"set xlabel \"Time [s]\"\n");
89 fprintf(gp[ii],
"set ylabel \"Attitude [rad]\"\n");
90 fprintf(gp[ii],
"plot \"%s\" using 1:%d with lines title \"Estimated\"\n", ofname.c_str(), (2 + ii));
91 fprintf(gp[ii],
"replot \"%s\" using 1:%d with lines title \"Actual\"\n", ofname.c_str(), (2 + ii + 3));
94 std::cout <<
"Type any keys + enter to exit." << std::endl;
int main(int argc, char *argv[])
void setParam(const double _dt, const double _Q_angle, const double _Q_rate, const double _R_angle, const std::string print_str="")
def j(str, encoding="cp932")
FILE * popen(const char *cmd, const char *mode)