|
1 | 1 | #!/usr/bin/env roseus |
2 | | -;; Load packages |
3 | | -(ros::load-ros-manifest "roseus") |
4 | | -(ros::roseus "nextage-phantom") |
| 2 | + |
| 3 | +(ros::roseus "jsk-nextage-teleop") |
5 | 4 | (ros::roseus-add-msgs "geometry_msgs") |
6 | 5 | (ros::roseus-add-msgs "omni_msgs") |
| 6 | + |
7 | 7 | (load "models/arrow-object.l") |
8 | | -(require "package://nextage_tutorials/euslisp/nextage-interface.l") |
9 | | -(require "package://dynamixel_detachable_hand/euslisp/lhand-interface.l") |
10 | | -(require "package://dynamixel_detachable_hand/euslisp/rhand-interface.l") |
| 8 | +(require "package://nextage_tutorials/euslisp/nextage-utils.l") |
11 | 9 |
|
12 | 10 | ;; Parameters |
13 | 11 | (setq *use-torso* nil) |
14 | 12 | (setq *use-hand* nil) |
15 | | -(setq *base-offset-l* (float-vector 380 200 0)) |
16 | | -(setq *base-offset-r* (float-vector 380 -200 0)) |
17 | | -(setq *ratio* 3.0) ;; control ratio |
18 | | -(setq *send-time* 100) ;; ms |
19 | | -(ros::rate 10) ;; Hz *send-time* and rate should be balanced. |
| 13 | +(setq *base-offset-l* (float-vector 400 100 50)) |
| 14 | +(setq *base-offset-r* (float-vector 400 -100 50)) |
| 15 | +(setq *send-time* 200) |
| 16 | +(setq *ratio* 0.5) |
| 17 | +(ros::rate 5) |
20 | 18 |
|
21 | 19 | (defun initialize-variables() |
22 | 20 | (setq *lpos* nil) |
|
36 | 34 | (defun check-work-limit() |
37 | 35 | ) |
38 | 36 |
|
39 | | -(defun check-collision() |
40 | | - ) |
41 | | - |
42 | 37 | (defun left-phantom-cb (msg) |
43 | 38 | (setq *lpos* (send msg :pose :position)) |
44 | 39 | (setq *lrot* (send msg :pose :orientation)) |
45 | | -;; (setq *ltf* (ros::tf-pose->coords (send msg :pose))) |
46 | | -;; (setq *lcoords* (make-coords :rot (copy-object (send *ltf* :rot)))) |
47 | | -;; (send *lcoords* :rotate pi/2 :x :world) |
48 | | -;; (send *lcoords* :locate (send *ltf* :worldpos) :world) |
49 | 40 | (setq *lclose* (send msg :close_gripper)) |
50 | 41 | (setq *llocked* (send msg :locked)) |
51 | 42 | ) |
52 | 43 |
|
53 | 44 | (defun right-phantom-cb (msg) |
54 | 45 | (setq *rpos* (send msg :pose :position)) |
55 | 46 | (setq *rrot* (send msg :pose :orientation)) |
56 | | -;; (setq *rtf* (ros::tf-pose->coords (send msg :pose))) |
57 | | -;; (setq *rcoords* (make-coords :rot (copy-object (send *rtf* :rot)))) |
58 | | -;; (send *rcoords* :rotate pi/2 :x :world) |
59 | | -;; (send *rcoords* :locate (send *rtf* :worldpos) :world) |
60 | 47 | (setq *rclose* (send msg :close_gripper)) |
61 | 48 | (setq *rlocked* (send msg :locked)) |
62 | 49 | ) |
63 | 50 |
|
64 | | - |
65 | | -;; Initialize |
66 | | -(ros::rate 10) |
67 | 51 | (ros::subscribe "/left_device/phantom/state" omni_msgs::OmniState #'left-phantom-cb) |
68 | 52 | (ros::subscribe "/right_device/phantom/state" omni_msgs::OmniState #'right-phantom-cb) |
69 | 53 |
|
|
86 | 70 |
|
87 | 71 | ;; Reset robot |
88 | 72 | (send *nextage* :reset-pose) |
89 | | -(send *nextage* :head :angle-vector #f(0 10)) |
| 73 | +(send *nextage* :head :angle-vector #f(0 60)) |
90 | 74 | (send *ri* :angle-vector (send *nextage* :angle-vector) 1000) |
91 | 75 | (send *ri* :wait-interpolation) |
92 | 76 | (send *irtviewer* :draw-objects) |
|
100 | 84 | (do-until-key |
101 | 85 | (ros::spin-once) |
102 | 86 |
|
103 | | - (when (and *lcoords* (not *llocked*)) |
| 87 | + (setq ik-success t) |
| 88 | + |
| 89 | + (when (and *lpos* *lrot* (not *llocked*)) |
104 | 90 | (setq *lx* (+ (* (send *lpos* :y) *ratio*) (elt *base-offset-l* 0))) |
105 | 91 | (setq *ly* (+ (* (- 0 (send *lpos* :x)) *ratio*) (elt *base-offset-l* 1))) |
106 | 92 | (setq *lz* (+ (* (send *lpos* :z) *ratio*) (elt *base-offset-l* 2))) |
|
110 | 96 | (send *lrot* :z)))) |
111 | 97 | (setq lR_dst (m* R_map lR_src)) |
112 | 98 | (setq *larm-target* (make-coords :pos (float-vector *lx* *ly* *lz*) :rot lR_dst)) |
113 | | - (send *la-target* :move-to *larm-target* :world) |
114 | | - (send *la-end* :move-to (send (send *nextage* :larm :end-coords) :copy-worldcoords) :world) |
115 | | - (send *nextage* :larm :inverse-kinematics *larm-target* :use-torso *use-torso* :rotation-axis t :stop 4 :revert-if-fail nil)) |
| 99 | + (unless (send *nextage* :larm :inverse-kinematics *larm-target* :use-torso *use-torso* :rotation-axis t :stop 10 :revert-if-fail t) |
| 100 | + (setq ik-success nil))) |
116 | 101 |
|
117 | 102 | (when (and *rpos* *rrot* (not *rlocked*)) |
118 | 103 | (setq *rx* (+ (* (send *rpos* :y) *ratio*) (elt *base-offset-r* 0))) |
|
124 | 109 | (send *rrot* :z)))) |
125 | 110 | (setq rR_dst (m* R_map rR_src)) |
126 | 111 | (setq *rarm-target* (make-coords :pos (float-vector *rx* *ry* *rz*) :rot rR_dst)) |
127 | | - (send *nextage* :rarm :inverse-kinematics *rarm-target* :use-torso *use-torso* :rotation-axis t :stop 4 :revert-if-fail nil)) |
| 112 | + (unless (send *nextage* :rarm :inverse-kinematics *rarm-target* :use-torso *use-torso* :rotation-axis t :stop 10 :revert-if-fail t) |
| 113 | + (setq ik-success nil))) |
128 | 114 |
|
129 | | - (send *ri* :angle-vector (send *nextage* :angle-vector) 100) |
| 115 | + (when *lclose* (send *ri* :close-forceps :larm)) |
| 116 | + (unless *lclose* (send *ri* :open-forceps :larm)) |
| 117 | + (when *rclose* (send *ri* :close :rarm)) |
| 118 | + (unless *rclose* (send *ri* :open-holder :rarm)) |
130 | 119 |
|
131 | | - (when (and *lclose* (not *llocked*)) |
132 | | - (if *lclose* |
133 | | - (send *lhand* :close) |
134 | | - (send *lhand* :open))) |
135 | | - |
136 | | - (when (and *rclose* (not *rlocked*)) |
137 | | - (if *rclose* |
138 | | - (send *rhand* :close-holder) |
139 | | - (send *rhand* :open-holder))) |
| 120 | + (when (and ik-success (not (send *nextage* :self-collision-check))) |
| 121 | + (send *ri* :angle-vector (send *nextage* :angle-vector) *send-time* nil 0 :min-time 0) |
| 122 | + ) |
140 | 123 |
|
141 | 124 | (send *irtviewer* :draw-objects) |
142 | 125 | (ros::sleep) |
143 | 126 | ) |
144 | | - |
145 | | -#| |
146 | | -Memo: Using the tf conversion method descripted in https://github.com/YUKINA-3252/jsk_hironx_teleop/issues/2, we cannot control the ration of :translate, |
147 | | -So I don't use it intentionally. |
148 | | -=# |
0 commit comments