|
3 | 3 | (when (probe-file (ros::resolve-ros-path "package://hrpsys_ros_bridge_tutorials/euslisp/hironxjsk-utils.l"))
|
4 | 4 | (require :hironxjsk-utils "package://hrpsys_ros_bridge_tutorials/euslisp/hironxjsk-utils.l"))
|
5 | 5 |
|
6 |
| -;; Waiting for https://github.com/start-jsk/rtmros_common/pull/1095 to be released |
7 |
| -(defmethod rtm-ros-robot-interface |
8 |
| - (:def-limb-controller-method |
9 |
| - (limb &key (debugp nil)) |
10 |
| - "Method to add limb controller action by default setting. |
11 |
| - Currently, FollowJointTrajectoryAction is used. |
12 |
| - This method calls defmethod. If :debugp t, we can see defmethod s-expressions." |
13 |
| - (let ((sexp `(defmethod ,(send (class self):name) |
14 |
| - (,(read-from-string (format nil "~A-controller" limb)) |
15 |
| - () |
16 |
| - (list |
17 |
| - (list |
18 |
| - (cons :group-name ,(string-downcase limb)) |
19 |
| - (cons :controller-action ,(format nil "~A_controller/follow_joint_trajectory_action" (string-downcase limb))) |
20 |
| - (cons :controller-state ,(format nil "~A_controller/state" (string-downcase limb))) |
21 |
| - (cons :action-type control_msgs::FollowJointTrajectoryAction) |
22 |
| - (cons :joint-names (send-all (send robot ,limb :joint-list) :name))) |
23 |
| - ))))) |
24 |
| - (if debugp |
25 |
| - (pprint (macroexpand sexp))) |
26 |
| - (eval sexp) |
27 |
| - )) |
28 |
| - ) |
29 |
| - |
30 | 6 | (defclass hironxjsk-interface
|
31 | 7 | :super rtm-ros-robot-interface
|
32 | 8 | :slots (hand-actions
|
|
35 | 11 |
|
36 | 12 | ;; Initialize
|
37 | 13 | (defmethod hironxjsk-interface
|
38 |
| - ;; Based on https://github.com/start-jsk/rtmros_tutorials/blob/9132c58702b3b193e14271b4c231ad0080187850/hrpsys_ros_bridge_tutorials/euslisp/hrp2jsknts-interface.l |
39 |
| - (:init (&rest args &key (show-default-controller nil) &allow-other-keys) |
40 |
| - (let ((limbs '(:rarm :larm :head :torso))) |
41 |
| - (dolist (limb limbs) |
42 |
| - (send self :def-limb-controller-method limb)) |
43 |
| - ;; If gazebo with ros_control, overwrite :default-controller |
44 |
| - (ros::roseus "default_robot_interface") |
45 |
| - (when (setq on-gazebo-ros-control |
46 |
| - (and (ros::get-param "/gazebo/time_step" nil) |
47 |
| - (ros::service-exists "/controller_manager/load_controller"))) |
48 |
| - (let ((sexp `(defmethod ,(send (class self):name) |
49 |
| - (:default-controller () |
50 |
| - (append |
51 |
| - ,@(mapcar |
52 |
| - #'(lambda (limb) |
53 |
| - `(send self ,(read-from-string |
54 |
| - (format nil "~A-controller" limb)))) |
55 |
| - limbs)))))) |
56 |
| - (when show-default-controller |
57 |
| - (pprint (macroexpand sexp))) |
58 |
| - (eval sexp))) |
59 |
| - (prog1 |
60 |
| - ;; Hironx has two types of joint_states on one topic: whole body and hand, |
61 |
| - ;; so queue size of joint_states should be two. |
62 |
| - ;; https://github.com/jsk-ros-pkg/jsk_pr2eus/blob/0.3.13/pr2eus/robot-interface.l#L120 |
63 |
| - (send-super* :init :joint-states-queue-size 2 :robot hironxjsk-robot args) |
64 |
| - ;; add controller |
65 |
| - (dolist (limb limbs) |
66 |
| - (let ((ctype (read-from-string (format nil "~A-controller" limb)))) |
67 |
| - ;; Avoid overwriting existing controllers to let actionlib-comm-state work |
68 |
| - ;; Without this avoidance, "old client's goal" warning is showed after :angle-vector |
69 |
| - (unless (send self :add-controller ctype :create-actions nil) |
70 |
| - (send self :add-controller ctype |
71 |
| - :joint-enable-check t :create-actions t)))) |
72 |
| - ;; add hand controller for gazebo with ros_control |
73 |
| - (when on-gazebo-ros-control |
74 |
| - (setq hand-actions (make-hash-table)) |
75 |
| - (dolist (hand (list :rhand :lhand)) |
76 |
| - ;; initialize hand action |
77 |
| - (sethash hand hand-actions |
78 |
| - (instance ros::simple-action-client :init |
79 |
| - (format nil "/~A_controller/follow_joint_trajectory_action" |
| 14 | + (:init (&rest args) |
| 15 | + (setq robot (instance hironxjsk-robot :init)) |
| 16 | + ;; Define {limb}-controller, usually we can define manually as jsk_robots |
| 17 | + (dolist (limb '(:rarm :larm :head :torso)) |
| 18 | + (send self :def-limb-controller-method limb)) |
| 19 | + ;; If gazebo with ros_control, overwrite :default-controller |
| 20 | + (setq on-gazebo-ros-control |
| 21 | + (and (ros::get-param "/gazebo/time_step" nil) |
| 22 | + ;; rtm-ros-bridge does not have type parametrs |
| 23 | + (ros::get-param "/torso_controller/type" nil))) |
| 24 | + (when on-gazebo-ros-control |
| 25 | + (ros::ros-warn "Found Gazebo/ros_control environment")) |
| 26 | + (prog1 |
| 27 | + ;; Hironx has two types of joint_states on one topic: whole body and hand, |
| 28 | + ;; so queue size of joint_states should be two. |
| 29 | + ;; https://github.com/jsk-ros-pkg/jsk_pr2eus/blob/0.3.13/pr2eus/robot-interface.l#L120 |
| 30 | + (send-super* :init :joint-states-queue-size 2 :robot robot :type |
| 31 | + (if on-gazebo-ros-control :gazebo-ros-controller :default-controller) |
| 32 | + args) |
| 33 | + ;; add hand controller for gazebo with ros_control |
| 34 | + (when on-gazebo-ros-control |
| 35 | + (setq hand-actions (make-hash-table)) |
| 36 | + (dolist (hand (list :rhand :lhand)) |
| 37 | + ;; initialize hand action |
| 38 | + (sethash hand hand-actions |
| 39 | + (instance ros::simple-action-client :init |
| 40 | + (format nil "/~A_controller/follow_joint_trajectory_action" |
80 | 41 | (string-downcase hand))
|
81 |
| - control_msgs::FollowJointTrajectoryAction |
82 |
| - :groupname groupname)) |
83 |
| - ;; check if hand action is respond (based on baxter-interface) |
84 |
| - (unless |
| 42 | + control_msgs::FollowJointTrajectoryAction |
| 43 | + :groupname groupname)) |
| 44 | + ;; check if hand action is respond (based on baxter-interface) |
| 45 | + (unless |
85 | 46 | (and joint-action-enable (send (gethash hand hand-actions) :wait-for-server 3))
|
86 |
| - (ros::ros-warn "~A is not respond" (gethash hand hand-actions)) |
87 |
| - (ros::ros-info "*** if you do not have hand, you can ignore this message ***")))) |
88 |
| - ;; number of servo motors in one hand |
89 |
| - (setq hand-servo-num 4)))) |
| 47 | + (ros::ros-warn "~A is not respond" (gethash hand hand-actions)) |
| 48 | + (ros::ros-info "*** if you do not have hand, you can ignore this message ***")))) |
| 49 | + ;; number of servo motors in one hand |
| 50 | + (setq hand-servo-num 4))) |
| 51 | + (:gazebo-ros-controller () |
| 52 | + (append |
| 53 | + (send self :rarm-controller) |
| 54 | + (send self :larm-controller) |
| 55 | + (send self :head-controller) |
| 56 | + (send self :torso-controller))) |
90 | 57 | (:call-operation-return (method &rest args)
|
91 | 58 | ;; Call method until it returns true
|
92 | 59 | ;; Used to ensure operation on the hand service calls, that sometimes fail
|
|
0 commit comments