Skip to content

Commit

Permalink
use gnuplotlib.l for demo/walk-motion.l and example code of irtmath.h…
Browse files Browse the repository at this point in the history
… kalmanlib.l
  • Loading branch information
k-okada committed Nov 29, 2021
1 parent 5496b9b commit b4325e8
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 42 deletions.
25 changes: 15 additions & 10 deletions irteus/demo/walk-motion.l
Original file line number Diff line number Diff line change
Expand Up @@ -302,8 +302,9 @@
"replot '/tmp/test-preview-control-data.dat' using 1:3 title 'cog' with lines;"
"replot '/tmp/test-preview-control-data.dat' using 1:4 title 'refzmp' with lines;"
"pause -1;")))
(unix:system (format nil "gnuplot -e \"~A\""
(let ((str "")) (dolist (gpc gp-command-list) (setq str (format nil "~A ~A" str gpc))) str)))))
(setq *g* (gnuplot))
(send *g* :command (apply #'concatenate string gp-command-list))
))
(mapcar #'(lambda (tm zmp cog refzmp)
(list :time tm :zmp zmp :cog cog :refzmp refzmp))
tm-list (reverse zmp-list) (reverse cog-list) (reverse ref-zmp-list2))
Expand Down Expand Up @@ -346,8 +347,9 @@
"replot '/tmp/test-preview-control-data.dat' using 1:3 title 'cog' with lines;"
"replot '/tmp/test-preview-control-data.dat' using 1:4 title 'refzmp' with lines;"
"pause -1;")))
(unix:system (format nil "gnuplot -e \"~A\""
(let ((str "")) (dolist (gpc gp-command-list) (setq str (format nil "~A ~A" str gpc))) str)))))
(setq *g* (gnuplot))
(send *g* :command (apply #'concatenate string gp-command-list))
))
(mapcar #'(lambda (tm zmp cog refzmp)
(list :time tm :zmp zmp :cog cog :refzmp refzmp))
tm-list (reverse zmp-list) (reverse cog-list) (reverse ref-zmp-list2))
Expand Down Expand Up @@ -399,8 +401,9 @@
"replot '/tmp/test-preview-control-data.dat' using 1:3 title 'cog' with lines;"
"replot '/tmp/test-preview-control-data.dat' using 1:4 title 'refzmp' with lines;"
"pause -1;")))
(unix:system (format nil "gnuplot -e \"~A\""
(let ((str "")) (dolist (gpc gp-command-list) (setq str (format nil "~A ~A" str gpc))) str)))))
(setq *g* (gnuplot))
(send *g* :command (apply #'concatenate string gp-command-list))
))
(mapcar #'(lambda (tm zmp cog refzmp)
(list :time tm :zmp zmp :cog cog :refzmp refzmp))
tm-list (reverse zmp-list) (reverse cog-list) (reverse ref-zmp-list2))
Expand Down Expand Up @@ -445,8 +448,9 @@
"replot '/tmp/test-preview-control-data.dat' using 1:3 title 'cog' with lines;"
"replot '/tmp/test-preview-control-data.dat' using 1:4 title 'refzmp' with lines;"
"pause -1;")))
(unix:system (format nil "gnuplot -e \"~A\""
(let ((str "")) (dolist (gpc gp-command-list) (setq str (format nil "~A ~A" str gpc))) str)))))
(setq *g* (gnuplot))
(send *g* :command (apply #'concatenate string gp-command-list))
))
(mapcar #'(lambda (tm zmp cog refzmp)
(list :time tm :zmp zmp :cog cog :refzmp refzmp))
tm-list (reverse zmp-list) (reverse cog-list) (reverse ref-zmp-list2))
Expand Down Expand Up @@ -500,8 +504,9 @@
"replot '/tmp/test-preview-control-data-2.dat' using 1:4 title 'output cog' with lines;"
"replot '/tmp/test-preview-control-data-2.dat' using 1:5 title 'input cog' with lines;"
"pause -1;")))
(unix:system (format nil "gnuplot -e \"~A\""
(let ((str "")) (dolist (gpc gp-command-list) (setq str (format nil "~A ~A" str gpc))) str)))))
(setq *g* (gnuplot))
(send *g* :command (apply #'concatenate string gp-command-list))
))
data
)))

Expand Down
24 changes: 8 additions & 16 deletions irteus/irtmath.l
Original file line number Diff line number Diff line change
Expand Up @@ -667,21 +667,13 @@
(defun lms-draw (r point-list)
(let (bs b str)
(setq bs nil)
(setq str "plot [0:80][0:50] '< echo \"")
(dotimes (i (length point-list))
(setq str (concatenate string str (format nil "~A ~A\\n"
(elt (elt point-list i) 0)
(elt (elt point-list i) 1)
)))
)
(setq str (concatenate string str (format nil "\"' title \"data\"~%")))
(format *gnuplot* "~a~%" str)
(setq str (format nil "replot ~A * x + ~A title \"regression\""
(/ (elt (car r) 0) (- (elt (car r) 1)))
(/ (cadr r) (- (elt (car r) 1)))
))
(format *gnuplot* "~a~%" str)
(send *gnuplot* :command (format nil "plot [0:80][0:50] ~A * x + ~A title \"regression\", '-' with point title \"data\"~%~Ae"
(/ (elt (car r) 0) (- (elt (car r) 1)))
(/ (cadr r) (- (elt (car r) 1)))
(apply #'concatenate string
(mapcar #'(lambda (x) (format nil "~A ~A~%" (elt x 0) (elt x 1)))
point-list))
))
t))
(defun lms-demo (num)
Expand All @@ -696,7 +688,7 @@
#f(39.0 27.0) #f(38.0 31.0) #f(32.0 25.0)))
)
(when (not (boundp '*gnuplot*))
(setq *gnuplot* (piped-fork "gnuplot")))
(setq *gnuplot* (gnuplot)))
(format t "apply lms with data~%")
(setq r (lms data1))
Expand Down
26 changes: 10 additions & 16 deletions irteus/kalmanlib.l
Original file line number Diff line number Diff line change
Expand Up @@ -200,20 +200,14 @@
(format f "~A ~A ~A ~A~%" (elt x i) (elt z 1) (send kf :error) (aref (send kf :P) 1 1))))

;; write graph data
(let ((fname (format nil "visualize_~A.sh" suffix)))
(format t ";; Writing gnuplot script to ~s~%" fname)
(with-open-file
(f fname :direction :output :permission #o744)
(format f "#!/usr/bin/env gnuplot~%")
(format f "~%")
(format f "set title \"~A\"~%" suffix)
(format f "plot [0:100][-0.6:0] 'data_~a.dat' title \"observed\" with linespoints~%" suffix)
(format f "set y2tics~%")
(format f "set y2range [0:0.01]~%")
(format f "replot 'kalman_result_~a.dat' title \"estimated\" with linespoints~%" suffix)
(format f "replot 'kalman_result_~a.dat' using 3 axes x1y2 title \"error\" with linespoints~%" suffix)
(format f "replot 'kalman_result_~a.dat' using 4 axes x1y2 title 'P covariance' with linespoints~%" suffix)
(format f "replot -0.37727 title \"baseline\"~%")
(format f "pause -1~%"))
(piped-fork (concatenate string (unix:getwd) "/" fname))
(setq *g* (gnuplot))
(send *g* :command (format nil "set title \"~A\"" suffix))
(send *g* :command (format nil "plot [0:100][-0.6:0] 'data_~a.dat' title \"observed\" with linespoints" suffix))
(send *g* :command "set y2tics")
(send *g* :command "set y2range [0:0.01]")
(send *g* :command (format nil "replot 'kalman_result_~a.dat' title \"estimated\" with linespoints" suffix))
(send *g* :command (format nil "replot 'kalman_result_~a.dat' using 3 axes x1y2 title \"error\" with linespoints" suffix))
(send *g* :command (format nil "replot 'kalman_result_~a.dat' using 4 axes x1y2 title 'P covariance' with linespoints" suffix))
(send *g* :command "replot -0.37727 title \"baseline\"")
(send *g* :command "pause -1")
t))

0 comments on commit b4325e8

Please sign in to comment.