Skip to content

Commit

Permalink
dump ik log both sucess/fail
Browse files Browse the repository at this point in the history
  • Loading branch information
k-okada authored and k-okada committed Mar 29, 2012
1 parent 16f0be0 commit 8f9e79e
Showing 1 changed file with 31 additions and 9 deletions.
40 changes: 31 additions & 9 deletions irteus/irtmodel.l
Original file line number Diff line number Diff line change
Expand Up @@ -1732,7 +1732,7 @@
(t (make-list (length move-target) :initial-element (deg2rad 1)))))
(union-link-list)
(centroid-thre 1.0) (target-centroid-pos) (centroid-offset-func)
(dump-command "/tmp")
(dump-command t)
&allow-other-keys)
;; target-coords, move-target, rotation-axis, translation-axis, link-list
;; -> both list and atom OK.
Expand All @@ -1747,14 +1747,35 @@
;;
(success t)
(old-analysis-level (send-all union-link-list :analysis-level))
ik-args)
command-directory command-filename command-id ik-args)
(send-all union-link-list :analysis-level :coords)
;; argument check
(when (or (null link-list) (null move-target))
(warn ";; ERROR: :link-list or :move-target required~%")
(return-from :inverse-kinematics t))
(if (and (null translation-axis) (null rotation-axis))
(return-from :inverse-kinematics t))
;; setup fname for log
(when dump-command

This comment has been minimized.

Copy link
@snozawa

snozawa Jul 23, 2015

Contributor

I forgot the reason of this commit, but why we started dump log even if in success?
The section (when dump-command is slow compared with IK itself.
In worse case on my pc, it takes 0.02[s] and it will be a problem when we solve many small IK (such as closed-link loop closing ik).

This comment has been minimized.

Copy link
@k-okada

k-okada via email Jul 23, 2015

Author Member

This comment has been minimized.

Copy link
@snozawa

snozawa Jul 24, 2015

Contributor

or I'm ok t disable dump log for all cases in default

For my case, dump-command in ik fail is OK and it would be nice to disable dump-command in ik success by default.
How about to introduce some kind of mode for dump-command?

  • dump-command is nil, do not dump command for ik success and ik fail.
  • dump-command is t, always dump command
  • dump-command is :fail-only, do not dump in ik success and dump in ik fail

This comment has been minimized.

Copy link
@k-okada

k-okada via email Jul 24, 2015

Author Member
(setq command-directory
(format nil "/tmp/irtmodel-ik-~A" (unix::getpid))
command-id
(let ((lt (unix::localtime))) (substitute #\0 #\ (format nil "~04d-~02d-~02d-~02d-~02d-~02d" (+ 1900 (elt lt 5)) (elt lt 4) (elt lt 3) (elt lt 2) (elt lt 1) (elt lt 0))))
command-filename
(format nil "~A-~A" (send (class self) :name) command-id))
(unix::mkdir command-directory)
(with-open-file
(f (format nil "~A/~A.l" command-directory command-filename) :direction :output)
(format f ";; ik ~A log at ~A on ~A~%;;~%" (if success "success" "fail") (string-trim '(10) (unix:asctime (unix:localtime))) lisp::lisp-implementation-version)
(format f ";; link-list ~A~%" link-list)
(format f ";; move-target ~A~%" move-target)
(format f ";; rotatoin-axis ~A, translation-axis ~A~%" rotation-axis translation-axis)
(format f ";; thre ~A, rthre ~A, stop ~A~%" thre rthre stop)
(if (atom target-coords)
(dump-structure f `(setq c0 ,target-coords))
(dump-structure f `(setq c0 ',(mapcar #'(lambda (x) x) target-coords))))
(dump-structure f `(setq av0 ,(send self :angle-vector)))
))
;; atom -> list
(when debug-view
(if (atom debug-view) (setq debug-view (list debug-view)))
Expand Down Expand Up @@ -1829,6 +1850,9 @@
centroid-thre target-centroid-pos centroid-offset-func)))
;; update difference
(mapcar #'(lambda (l a) (send l :analysis-level a)) union-link-list old-analysis-level)
;; rename log file
(when dump-command
(unix::rename (format nil "~A/~A.l" command-directory command-filename ) (format nil "~A/~A-~A.l" command-directory command-filename (if (or success (not revert-if-fail)) "success" "failure"))))
;; check solved or not
(if (or success (not revert-if-fail))
(send self :angle-vector)
Expand All @@ -1846,7 +1870,7 @@
(warn ";; angles : ~a~%" av0)
(warn ";; args : ~a~%" (append (list target-coords) args))
(when dump-command
(let (i (print-args (copy-list args)) command-init command-setup command-args command-id)
(let (i (print-args (copy-list args)) command-init command-setup command-args)
(dotimes (j (count :link-list print-args))
(if (setq i (position :link-list print-args :count (1+ j)))
(cond ((atom (car (elt print-args (+ i 1))))
Expand All @@ -1870,15 +1894,13 @@
(elt print-args (+ i 1)))))))))
(setq command-init `(instance ,(send (class self) :name) :init)
command-setup `(progn (send r :newcoords (make-coords :4x4 ,(send self :4x4))) (mapc #'(lambda (j a) (send* j :joint-angle a ,joint-args)) (list . ,(mapcar #'(lambda (x) `(send r ,(intern (string-upcase x) *keyword-package*))) (send-all (remove-duplicates (append (send-all union-link-list :joint) joint-list)) :name))) ,(list 'quote av0)) (objects (list r)))
command-args (nconc `(list . ,(mapcar #'(lambda (x) `(make-coords :pos ,(send x :worldpos) :rot ,(send x :worldrot))) target-coords)) (list :dump-command nil :debug-view t) print-args)
command-id (let ((lt (unix::localtime))) (substitute #\0 #\ (format nil "~A-~04d-~02d-~02d-~02d-~02d-~02d" (send (class self) :name) (+ 1900 (elt lt 5)) (elt lt 4) (elt lt 3) (elt lt 2) (elt lt 1) (elt lt 0)))))
command-args (nconc `(list . ,(mapcar #'(lambda (x) `(make-coords :pos ,(send x :worldpos) :rot ,(send x :worldrot))) target-coords)) (list :dump-command nil :debug-view t) print-args))
(warn ";; command : ~a~%" `(let ((r ,command-init)) ,command-setup (send* r :inverse-kinematics ,command-args)))
(warn ";; dump debug command to /~A/~A.l~%" dump-command command-id)
(warn ";; (progn (load \"/~A/~A.l\")(ik-setup)(ik-check))~%" dump-command command-id)
(warn ";; dump debug command to ~A/~A~%" command-directory command-filename)
(warn ";; (progn (load \"~A\")(ik-setup)(ik-check))~%" command-directory command-filename)
;; dump
(with-open-file
(f (format nil "/~A/~A.l" dump-command command-id) :direction :output)
(format f ";; ik ~A log at ~A on ~A~%~%" (if success "success" "fail") (string-trim '(10) (unix:asctime (unix:localtime))) lisp::lisp-implementation-version)
(f (format nil "~A/~A-failure.l" command-directory command-filename) :direction :output :if-exists :append)
(format f "(defun ~A-setup () (let ((r ~A)) (setq *robot* r) ~A (objects (list *robot*))))~%" command-id command-init command-setup)
(format f "(defun ~A-check () (send* *robot* :inverse-kinematics ~A))~%" command-id command-args)
(format f "(defun ik-setup () (~A-setup))~%" command-id)
Expand Down

0 comments on commit 8f9e79e

Please sign in to comment.