Skip to content

Commit 36d6866

Browse files
authored
Merge pull request #541 from Naoki-Hiraoka/fix-calc-static-balance-point
Fix calc static balance point
2 parents 10f292c + 5653165 commit 36d6866

File tree

2 files changed

+50
-2
lines changed

2 files changed

+50
-2
lines changed

irteus/irtrobot.l

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1037,7 +1037,7 @@
10371037
"Calculate static balance point which is equivalent to static extended ZMP.
10381038
The output is expressed by the world coordinates.
10391039
target-points are end-effector points on which force-list and moment-list apply.
1040-
force-list [N] and moment-list [Nm] are list of force and moment at target-points.
1040+
force-list [N] and moment-list [Nm] are list of force and moment that robot receives at target-points.
10411041
static-balance-point-height is height of static balance point [mm]."
10421042
(let* ((sbp (float-vector 0 0 static-balance-point-height))
10431043
(mg (* 1e-6 (send self :weight update-mass-properties) (elt *g-vec* 2))))
@@ -1049,7 +1049,7 @@
10491049
(+ nume
10501050
(- (* (- (elt tp 2) static-balance-point-height) (elt f idx))
10511051
(* (elt tp idx) (elt f 2)))
1052-
(case idx (0 (- (elt m 1))) (1 (elt m 0))))
1052+
(* 1e3 (case idx (0 (elt m 1)) (1 (- (elt m 0))))))
10531053
denom (- denom (elt f 2))))
10541054
force-list moment-list target-points)
10551055
(setf (elt sbp idx) (/ nume denom))

irteus/test/test-irt-motion.l

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -871,6 +871,50 @@
871871
(send robot :calc-static-balance-point :force-list (list #f(10 20 0) #f(25 20 0))))))
872872
))
873873

874+
;; test for static balance point
875+
(defun fullbody-ik-with-forces-moments (robot &key (debug-view :no-message))
876+
(send robot :newcoords (make-coords))
877+
(send robot :reset-pose)
878+
(send robot :fix-leg-to-coords (make-coords))
879+
(send robot :legs :move-end-pos (float-vector 0 0 50))
880+
(send robot :fix-leg-to-coords (make-coords))
881+
(objects (list robot))
882+
(let* ((centroid-thre 10)
883+
(force-list '(#f(10 20 0) #f(25 20 0)))
884+
(moment-list '(#f(20 -10 0) #f(10 -20 0)))
885+
(result
886+
(send robot :fullbody-inverse-kinematics
887+
(list (send robot :rleg :end-coords :copy-worldcoords)
888+
(send robot :lleg :end-coords :copy-worldcoords)
889+
(make-coords :pos #f(150 -300 600))
890+
(make-coords :pos #f(150 300 600)))
891+
:move-target (mapcar #'(lambda (x)
892+
(send robot x :end-coords))
893+
(list :rleg :lleg :rarm :larm))
894+
:link-list (mapcar #'(lambda (x)
895+
(send robot :link-list (send robot x :end-coords :parent)))
896+
(list :rleg :lleg :rarm :larm))
897+
:centroid-thre centroid-thre
898+
:centroid-offset-func #'(lambda () (send robot :calc-static-balance-point :force-list force-list :moment-list moment-list))
899+
:debug-view debug-view)))
900+
(and result
901+
(> centroid-thre (distance (apply #'midpoint 0.5 (send robot :legs :end-coords :worldpos))
902+
(send robot :calc-static-balance-point :force-list force-list :moment-list moment-list)))
903+
;;check static balance
904+
;;The sum of force and moment that robot receives at target-points, ZMP and centroid should be almost zero (except yaw moment).
905+
(> 1.0
906+
(norm (subseq (transform (send robot :calc-grasp-matrix
907+
(append (mapcar #'(lambda (x) (send robot x :end-coords :worldpos)) (list :rarm :larm))
908+
(list (send robot :centroid)
909+
(send (send robot :foot-midcoords) :worldpos))))
910+
(concatenate float-vector
911+
(mapcan #'(lambda (f m) (concatenate cons f m))
912+
force-list moment-list)
913+
(v- (scale (* 1e-6 (send robot :weight)) *g-vec*)) #F(0 0 0)
914+
(v- (scale (* 1e-6 (send robot :weight)) *g-vec*) (reduce #'v+ force-list)) #F(0 0 0)))
915+
0 5))))
916+
))
917+
874918
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
875919
;; unit tests
876920
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@@ -954,6 +998,10 @@
954998
(assert
955999
(fullbody-ik-with-forces *sample-robot*)))
9561000

1001+
(deftest test-fullbody-ik-with-forces-moments-samplerobot
1002+
(assert
1003+
(fullbody-ik-with-forces-moments *sample-robot*)))
1004+
9571005
(deftest test-fullbody-ik-draw-param-check-samplerobot
9581006
(dotimes (i 5) (send *sample-robot* :move-centroid-on-foot :both '(:rleg :lleg)))
9591007
(assert

0 commit comments

Comments
 (0)