{"action":"created","issue":{"url":"https://api.github.com/repos/jsk-ros-pkg/jsk_pr2eus/issues/175","labels_url":"https://api.github.com/repos/jsk-ros-pkg/jsk_pr2eus/issues/175/labels{/name}","comments_url":"https://api.github.com/repos/jsk-ros-pkg/jsk_pr2eus/issues/175/comments","events_url":"https://api.github.com/repos/jsk-ros-pkg/jsk_pr2eus/issues/175/events","html_url":"https://github.com/jsk-ros-pkg/jsk_pr2eus/issues/175","id":106967061,"number":175,"title":"Introducing `robot-init` function","user":{"login":"garaemon","id":40454,"avatar_url":"https://avatars.githubusercontent.com/u/40454?v=3","gravatar_id":"","url":"https://api.github.com/users/garaemon","html_url":"https://github.com/garaemon","followers_url":"https://api.github.com/users/garaemon/followers","following_url":"https://api.github.com/users/garaemon/following{/other_user}","gists_url":"https://api.github.com/users/garaemon/gists{/gist_id}","starred_url":"https://api.github.com/users/garaemon/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/garaemon/subscriptions","organizations_url":"https://api.github.com/users/garaemon/orgs","repos_url":"https://api.github.com/users/garaemon/repos","events_url":"https://api.github.com/users/garaemon/events{/privacy}","received_events_url":"https://api.github.com/users/garaemon/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":4,"created_at":"2015-09-17T11:55:28Z","updated_at":"2015-09-17T12:12:34Z","closed_at":null,"body":"robot-init関数を導入したい。\r\n\r\n解決したい問題は\r\n1. 複数のロボットで動くプログラムを書くときに、`pr2-init`や`hrp2jsk-init`のような関数を書くのが面倒\r\n2. さらっとプログラムを書くときに`(load \"package://hrpsys_ros_bridge_tutorials/euslisp/hrp2jsk-interface.l)\"`と書くのが結構面倒\r\n3. パラメータを変えるだけで対象ロボットが変わるプログラムを書きたい\r\n\r\n解決する方法は`robot-init (robot-name)`という関数を導入する.\r\nロボットの定義がどのファイルに書いてあるかは仕方ないので手書きしておく(`robot-interface-file`)。\r\n\r\n```lisp\r\n(defun robot-init (&optional (robot-name (ros::get-param \"/robot/type\")))\r\n  (require (robot-interface-file robot-name))\r\n  (let ((klass (read-from-string (format nil \"~A-interface\" robot-name))))\r\n    (if (and (boundp klass) (subclassp (eval klass) robot-interface))\r\n        (setq *ri* (instance* (eval klass) :init args))))\r\n  (setq *robot* (make-robot-model-from-name robot-name))\r\n  *ri*)\r\n\r\n(defun robot-interface-file (name)\r\n  \"You can get robot-interface file according to `name' argument.\r\nYou can create `*ri*' like \r\n(progn (load (robot-file (ros::get-param \\\"/robot/type\\\")))\r\n       (init-robot-from-name (ros::get-param \\\"/robot/type\\\")))\r\n\"\r\n  (let ((lower-name (string-downcase name)))\r\n    (cond\r\n     ((string= lower-name \"pr2\")\r\n      \"package://pr2eus/pr2-interface.l\")\r\n     ((string= lower-name \"hrp2jsk\")\r\n      \"package://hrpsys_ros_bridge_tutorials/euslisp/hrp2jsk-interface.l\")\r\n     ((string= lower-name \"hrp2jsknt\")\r\n      \"package://hrpsys_ros_bridge_tutorials/euslisp/hrp2jsknt-interface.l\")\r\n     ((string= lower-name \"hrp2jsknts\")\r\n      \"package://hrpsys_ros_bridge_tutorials/euslisp/hrp2jsknts-interface.l\")\r\n     ((string= lower-name \"staro\")\r\n      \"package://hrpsys_ros_bridge_tutorials/euslisp/staro-interface.l\")\r\n     ((string= lower-name \"jaxon\")\r\n      \"package://hrpsys_ros_bridge_tutorials/euslisp/jaxon-interface.l\")\r\n     ((string= lower-name \"jaxon_red\")\r\n      \"package://hrpsys_ros_bridge_tutorials/euslisp/jaxon_red-interface.l\")\r\n     ((string= lower-name \"urataleg\")\r\n      \"package://hrpsys_ros_bridge_tutorials/euslisp/urataleg-interface.l\")\r\n     ((string= lower-name \"samplerobot\")\r\n      \"package://hrpsys_ros_bridge_tutorials/euslisp/samplerobot-interface.l\")\r\n     ((string= lower-name \"hrp2w\")\r\n      \"package://hrpsys_ros_bridge_tutorials/euslisp/hrp2w-interface.l\")\r\n     ((string= lower-name \"pepper\")\r\n      \"package://peppereus/pepper-interface.l\")\r\n     ((string= lower-name \"nao\")\r\n      \"package://naoeus/euslisp/nao-interface.l\")\r\n     (t (error \"uknown robot ~A\" name))\r\n     )))\r\n```\r\n\r\n# 移行について\r\n2段階で移行する。\r\n1. `hogehoge-init`を`robot-init`を利用するように書き換えて、warningを出す\r\n2. `hogehoge-init`を消す\r\n\r\n`hogehoge-init` :arrow_right: `robot-init`の変換のためのsedスクリプトみたいなものは用意したい。\r\n\r\n# 議論ポイント\r\n- [ ] どこに定義するのか?\r\n\r\n  robot-interface.lが良いきがする。ちょっと依存関係はおかしいかも.\r\n- [ ] 本当にファイルを書き下さなくてはいけないのか\r\n\r\n  package.xmlにうまいことexportタグで書くという技がある気がしてきた \r\n- [ ] 移行をどうするか"},"comment":{"url":"https://api.github.com/repos/jsk-ros-pkg/jsk_pr2eus/issues/comments/141059582","html_url":"https://github.com/jsk-ros-pkg/jsk_pr2eus/issues/175#issuecomment-141059582","issue_url":"https://api.github.com/repos/jsk-ros-pkg/jsk_pr2eus/issues/175","id":141059582,"user":{"login":"garaemon","id":40454,"avatar_url":"https://avatars.githubusercontent.com/u/40454?v=3","gravatar_id":"","url":"https://api.github.com/users/garaemon","html_url":"https://github.com/garaemon","followers_url":"https://api.github.com/users/garaemon/followers","following_url":"https://api.github.com/users/garaemon/following{/other_user}","gists_url":"https://api.github.com/users/garaemon/gists{/gist_id}","starred_url":"https://api.github.com/users/garaemon/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/garaemon/subscriptions","organizations_url":"https://api.github.com/users/garaemon/orgs","repos_url":"https://api.github.com/users/garaemon/repos","events_url":"https://api.github.com/users/garaemon/events{/privacy}","received_events_url":"https://api.github.com/users/garaemon/received_events","type":"User","site_admin":false},"created_at":"2015-09-17T12:12:34Z","updated_at":"2015-09-17T12:12:34Z","body":"つまり作戦としては、\r\n* package.xmlのexport部分に名前 :left_right_arrow:  interfaceファイルの対応を書く\r\n* `robot-init`の中で`rospack plugins`を読んで実行時に対応関係を知る(fileとnameで二回呼ばないといけないのがちょっとダサイ)\r\n\r\nというのでどうでしょうか。"}}