18 int main(
int argc,
char *argv[])
25 std::string input_file(
"test.dat");
26 bool use_gnuplot =
false;
29 for (
int i = 0;
i < argc; ++
i) {
30 std::string
arg(argv[
i]);
31 if ( arg ==
"--Q-pos" ) {
32 if (++i < argc) Q_pos = atof(argv[i]);
33 }
else if ( arg ==
"--Q-vel" ) {
34 if (++i < argc) Q_vel = atof(argv[i]);
35 }
else if ( arg ==
"--R-pos" ) {
36 if (++i < argc) R_pos = atof(argv[i]);
37 }
else if ( arg ==
"--dt" ) {
38 if (++i < argc) dt = atof(argv[i]);
39 }
else if ( arg ==
"--input-file" ) {
40 if (++i < argc) input_file = argv[i];
41 }
else if ( arg ==
"--use-gnuplot" ) {
42 if (++i < argc) use_gnuplot = (std::string(argv[i])==
"true"?
true:
false);
47 std::ifstream inputf(input_file.c_str());
48 std::cerr <<
"File : " << input_file << std::endl;
49 if (!inputf.is_open()) {
50 std::cerr <<
"No such " << input_file << std::endl;
53 std::string ofname(
"/tmp/testKalmanFilter.dat");
54 std::ofstream ofs(ofname.c_str());
60 kf.
setQ(Q_pos*dt, 0, 0, Q_vel*dt);
66 double time, time2=0.0;
69 inputf >> time >> data;
72 ofs << time2 <<
" " << data <<
" " << kf.getx()[0] <<
" " << kf.getx()[1] << std::endl;
74 std::cout << data << std::endl;
81 std::string titles[2] = {
"Pos",
"Vel"};
82 for (
size_t ii = 0; ii < 2; ii++) {
83 gp[ii] =
popen(
"gnuplot",
"w");
84 fprintf(gp[ii],
"set title \"%s\"\n", titles[ii].c_str());
85 fprintf(gp[ii],
"set xlabel \"Time [s]\"\n");
86 fprintf(gp[ii],
"set ylabel \"Pos\"\n");
88 fprintf(gp[ii],
"plot \"%s\" using 1:%d with lines title \"Filtered\"\n", ofname.c_str(), 2);
89 fprintf(gp[ii],
"replot \"%s\" using 1:%d with lines title \"Raw\"\n", ofname.c_str(), 3);
91 fprintf(gp[ii],
"plot \"%s\" using 1:%d with lines title \"Vel\"\n", ofname.c_str(), 4);
95 std::cout <<
"Type any keys + enter to exit." << std::endl;
int main(int argc, char *argv[])
def j(str, encoding="cp932")
FILE * popen(const char *cmd, const char *mode)
void setQ(const double _q0, const double _q1, const double _q2, const double _q3)