jsk-ros-pkg / jsk_pr2eus

PR2 euslisp packages
https://github.com/jsk-ros-pkg/jsk_pr2eus
4 stars 41 forks source link

made it possible to give a function like lambda to the target value of inverse kinematics #400

Closed kosuke55 closed 5 years ago

kosuke55 commented 5 years ago

made it possible to give a function like lambda to the target value of inverse kinematics.

For example, the following shake-cocktail.

(defun shake-cocktail ()
  (send *irtviewer* :title "shake-cocktail")
  (unless (boundp '*robot*)
    (setq *robot* (instance sample-robot :init)))
  (send *robot* :reset-pose)
  (send *robot* :newcoords (make-coords))

  (setq *obj* (make-cylinder 20 100))
  (send *obj* :set-color #f(1 1 0))
  (send *robot* :reset-pose)
  (objects (list *robot* *obj*))

  (send *robot* :inverse-kinematics
        (list (make-coords :pos #f(400 0 1000)))
        :move-target
        (list (send *robot* :larm :end-coords))
        :link-list
        (list (send *robot* :link-list
                    (send (send *robot* :larm :end-coords) :parent)
                    (car (send *robot* :larm :links))))
        :translation-axis (list t)
        :rotation-axis (list nil))

  (let* ((cnt 0.0))
    (do-until-key
     (incf cnt 0.1)
     (send *robot* :inverse-kinematics
           (list (make-coords :pos (float-vector (+ 400 (* 100 (sin cnt))) (* 50 (cos cnt)) 1000))
                 #'(lambda ()
                     (send (send (send *robot* :larm :end-coords) :copy-worldcoords)
                           :translate #f(0 0 100) :local)))
           :move-target
           (list (send *robot* :larm :end-coords)
                 (send *robot* :rarm :end-coords))
           :link-list
           (list (send *robot* :link-list
                       (send (send *robot* :larm :end-coords) :parent)
                       (car (send *robot* :larm :links)))
                 (send *robot* :link-list
                       (send (send *robot* :rarm :end-coords) :parent)
                       (car (send *robot* :rarm :links))))
           :translation-axis (list :z t)
           :rotation-axis (list nil :z))
     (send *obj* :newcoords (send (send *robot* :larm :end-coords) :copy-worldcoords))
     (send *irtviewer* :draw-objects))))
knorth55 commented 5 years ago

you pass #'lambda but you just eval (actually funcall) it inside :inverse-kinematics method. it seems that you can do the same thing as your example if you first calculate target coordinates before :inverse-kinematics and pass it. why do you need this function? do you need this function for more complicated use case?

kosuke55 commented 5 years ago

I wanted to move both grippers while keeping their relative positions. When the shake-cocktail sample function was executed with pr2, an error occurred in the pr2-roboto part, so I modified it. But certainly I can do the same if I eval before giving it to ik. Also, I don't do anything more complicated than this function, so should I close it?

knorth55 commented 5 years ago

In your case, you don't need to modify this code because you just funcall x with no args.

(setq c (mapcar #'(lambda (x) (if (functionp x) (funcall x) x)) c))

However, if you want to funcall x with args or slot values, it would be interesting. But I have no idea about how to use that kind of complicated use case.

knorth55 commented 5 years ago

If you think you don't need this function and you check that you can do the same thing without this PR, you can close this.

kosuke55 commented 5 years ago

Sorry to reply late. I confirmed that I could do the same without this PR.