Skip to content

Commit eb89602

Browse files
committed
Merge pull request #267 from snozawa/add_sbp
Add static balance point method and test for it
2 parents ef9768c + ba3c2f4 commit eb89602

File tree

2 files changed

+62
-0
lines changed

2 files changed

+62
-0
lines changed

irteus/irtrobot.l

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -939,6 +939,35 @@
939939
(setq links (append links (list l0 l1 l2)))
940940
(setq joint-list (append joint-list (list j0 j1 j2)))
941941
))
942+
(:calc-static-balance-point
943+
(&key (target-points
944+
(mapcar #'(lambda (tmp-arm)
945+
(send (send self tmp-arm :end-coords) :worldpos))
946+
'(:rarm :larm)))
947+
(force-list (make-list (length target-points) :initial-element (float-vector 0 0 0)))
948+
(moment-list (make-list (length target-points) :initial-element (float-vector 0 0 0)))
949+
(static-balance-point-height (elt (apply #'midpoint 0.5 (send self :legs :end-coords :worldpos)) 2))
950+
(update-mass-properties t))
951+
"Calculate static balance point which is equivalent to static extended ZMP.
952+
target-points are end-effector points on which force-list and moment-list apply.
953+
force-list [N] and moment-list [Nm] are list of force and moment at target-points.
954+
static-balance-point-height is height of static balance point [mm]."
955+
(let* ((sbp (float-vector 0 0 static-balance-point-height))
956+
(mg (* 1e-6 (send self :weight nil) (elt *g-vec* 2))))
957+
(dotimes (idx 2)
958+
(let ((denom mg)
959+
(nume (* mg (elt (send self :centroid update-mass-properties) idx))))
960+
(mapcar #'(lambda (f m tp)
961+
(setq nume
962+
(+ nume
963+
(- (* (- (elt tp 2) static-balance-point-height) (elt f idx))
964+
(* (elt tp idx) (elt f 2)))
965+
(case idx (0 (- (elt m 1))) (1 (elt m 0))))
966+
denom (- denom (elt f 2))))
967+
force-list moment-list target-points)
968+
(setf (elt sbp idx) (/ nume denom))
969+
))
970+
sbp))
942971
)
943972
(in-package "GEOMETRY")
944973

irteus/test/test-irt-motion.l

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -726,6 +726,35 @@
726726
)
727727
))
728728

729+
;; test for static balance point
730+
(defun fullbody-ik-with-forces (robot &key (debug-view :no-message))
731+
(send robot :newcoords (make-coords))
732+
(send robot :reset-pose)
733+
(send robot :fix-leg-to-coords (make-coords))
734+
(send robot :legs :move-end-pos (float-vector 0 0 50))
735+
(send robot :fix-leg-to-coords (make-coords))
736+
(objects (list robot))
737+
(let* ((centroid-thre 10)
738+
(result
739+
(send robot :fullbody-inverse-kinematics
740+
(list (send robot :rleg :end-coords :copy-worldcoords)
741+
(send robot :lleg :end-coords :copy-worldcoords)
742+
(make-coords :pos #f(150 -300 600))
743+
(make-coords :pos #f(150 300 600)))
744+
:move-target (mapcar #'(lambda (x)
745+
(send robot x :end-coords))
746+
(list :rleg :lleg :rarm :larm))
747+
:link-list (mapcar #'(lambda (x)
748+
(send robot :link-list (send robot x :end-coords :parent)))
749+
(list :rleg :lleg :rarm :larm))
750+
:centroid-thre centroid-thre
751+
:centroid-offset-func #'(lambda () (send robot :calc-static-balance-point :force-list (list #f(10 20 0) #f(25 20 0))))
752+
:debug-view debug-view)))
753+
(and result
754+
(> centroid-thre (distance (apply #'midpoint 0.5 (send robot :legs :end-coords :worldpos))
755+
(send robot :calc-static-balance-point :force-list (list #f(10 20 0) #f(25 20 0))))))
756+
))
757+
729758
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
730759
;; unit tests
731760
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@@ -795,5 +824,9 @@
795824
(assert
796825
(test-self-collision-check-IK)))
797826

827+
(deftest test-fullbody-ik-with-forces-samplerobot
828+
(assert
829+
(fullbody-ik-with-forces *sample-robot*)))
830+
798831
(run-all-tests)
799832
(exit 0)

0 commit comments

Comments
 (0)