Skip to content

Commit 41b5881

Browse files
committed
Set up nextage-interface.l and nextage-utils.l
1 parent 89d4a9e commit 41b5881

13 files changed

Lines changed: 346 additions & 91 deletions

nextage_tutorials/.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
nextage.dae
2-
nextage.l
2+
nextage.l
3+
launch/ft_sensor_calib.launch
4+
launch/manual_tf_calib.launch
5+
scripts/tf_to_imu.py
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/usr/bin/env roseus
2+
3+
(require "package://nextage_tutorials/euslisp/nextage-utils.l")
4+
(nextage-init)
5+
(lhand-init)
6+
(rhand-init)
7+
8+
(setq *robot* *nextage*)
9+
(objects (list *robot*))
10+
(send *robot* :reset-pose)
11+
(send *robot* :head :angle-vector #f(0 60))
12+
(send *robot* :larm :move-end-pos #f(0 0 100))
13+
(send *robot* :rarm :move-end-pos #f(0 0 100))
14+
(send *ri* :angle-vector (send *nextage* :angle-vector) 2000)
15+
(send *ri* :wait-interpolation)
16+
(send *ri* :close-holder :rarm)
17+
(send *ri* :open-forceps :larm)
18+
(send *irtviewer* :draw-objects)
Lines changed: 24 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,20 @@
11
#!/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")
54
(ros::roseus-add-msgs "geometry_msgs")
65
(ros::roseus-add-msgs "omni_msgs")
6+
77
(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")
119

1210
;; Parameters
1311
(setq *use-torso* nil)
1412
(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)
2018

2119
(defun initialize-variables()
2220
(setq *lpos* nil)
@@ -36,34 +34,20 @@
3634
(defun check-work-limit()
3735
)
3836

39-
(defun check-collision()
40-
)
41-
4237
(defun left-phantom-cb (msg)
4338
(setq *lpos* (send msg :pose :position))
4439
(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)
4940
(setq *lclose* (send msg :close_gripper))
5041
(setq *llocked* (send msg :locked))
5142
)
5243

5344
(defun right-phantom-cb (msg)
5445
(setq *rpos* (send msg :pose :position))
5546
(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)
6047
(setq *rclose* (send msg :close_gripper))
6148
(setq *rlocked* (send msg :locked))
6249
)
6350

64-
65-
;; Initialize
66-
(ros::rate 10)
6751
(ros::subscribe "/left_device/phantom/state" omni_msgs::OmniState #'left-phantom-cb)
6852
(ros::subscribe "/right_device/phantom/state" omni_msgs::OmniState #'right-phantom-cb)
6953

@@ -86,7 +70,7 @@
8670

8771
;; Reset robot
8872
(send *nextage* :reset-pose)
89-
(send *nextage* :head :angle-vector #f(0 10))
73+
(send *nextage* :head :angle-vector #f(0 60))
9074
(send *ri* :angle-vector (send *nextage* :angle-vector) 1000)
9175
(send *ri* :wait-interpolation)
9276
(send *irtviewer* :draw-objects)
@@ -100,7 +84,9 @@
10084
(do-until-key
10185
(ros::spin-once)
10286

103-
(when (and *lcoords* (not *llocked*))
87+
(setq ik-success t)
88+
89+
(when (and *lpos* *lrot* (not *llocked*))
10490
(setq *lx* (+ (* (send *lpos* :y) *ratio*) (elt *base-offset-l* 0)))
10591
(setq *ly* (+ (* (- 0 (send *lpos* :x)) *ratio*) (elt *base-offset-l* 1)))
10692
(setq *lz* (+ (* (send *lpos* :z) *ratio*) (elt *base-offset-l* 2)))
@@ -110,9 +96,8 @@
11096
(send *lrot* :z))))
11197
(setq lR_dst (m* R_map lR_src))
11298
(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)))
116101

117102
(when (and *rpos* *rrot* (not *rlocked*))
118103
(setq *rx* (+ (* (send *rpos* :y) *ratio*) (elt *base-offset-r* 0)))
@@ -124,25 +109,18 @@
124109
(send *rrot* :z))))
125110
(setq rR_dst (m* R_map rR_src))
126111
(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)))
128114

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))
130119

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+
)
140123

141124
(send *irtviewer* :draw-objects)
142125
(ros::sleep)
143126
)
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-
=#

nextage_tutorials/euslisp/nextage-interface.l

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
(load "package://pr2eus/robot-interface.l")
22
(require :nextage "package://nextage_tutorials/nextage.l")
33

4+
(when (ros::resolve-ros-path "package://dynamixel_detachable_hand/euslisp/lhand-interface.l")
5+
(load "package://dynamixel_detachable_hand/euslisp/lhand-interface.l")
6+
(load "package://dynamixel_detachable_hand/euslisp/rhand-interface.l"))
7+
48
(defclass nextage-interface
59
:super robot-interface
610
:slots ())
11+
712
(defmethod nextage-interface
813
(:init (&rest args)
914
(send-super :init :robot nextageopen-robot))
@@ -41,6 +46,50 @@
4146
(cons :controller-state "/head_controller/fstate")
4247
(cons :action-type control_msgs::FollowJointTrajectoryAction)
4348
(cons :joint-names (send-all (send robot :head :joint-list) :name)))))
49+
(:lhand-init ()
50+
(unless (boundp '*lhand*)
51+
(setq *lhand* (instance lhand-interface :init)))
52+
*lhand*)
53+
(:rhand-init ()
54+
(unless (boundp '*rhand*)
55+
(setq *rhand* (instance rhand-interface :init)))
56+
*rhand*)
57+
(:start-grasp (&optional (arm :arms) &rest args)
58+
(case arm
59+
(:larm (send* (send self :lhand-init) :close args))
60+
(:rarm (send* (send self :rhand-init) :close args))
61+
(:arms (send* (send self :lhand-init) :close args)
62+
(send* (send self :rhand-init) :close args))))
63+
(:stop-grasp (&optional (arm :arms) &rest args)
64+
(case arm
65+
(:larm (send* (send self :lhand-init) :open args))
66+
(:rarm (send* (send self :rhand-init) :open args))
67+
(:arms (send* (send self :lhand-init) :open args)
68+
(send* (send self :rhand-init) :open args))))
69+
(:open-forceps (&optional (arm :arms) &rest args)
70+
(case arm
71+
(:larm (send* (send self :lhand-init) :open-forceps args))
72+
(:rarm (send* (send self :rhand-init) :open-forceps args))
73+
(:arms (send* (send self :lhand-init) :open-forceps args)
74+
(send* (send self :rhand-init) :open-forceps args))))
75+
(:close-forceps (&optional (arm :arms) &rest args)
76+
(case arm
77+
(:larm (send* (send self :lhand-init) :close-forceps args))
78+
(:rarm (send* (send self :rhand-init) :close-forceps args))
79+
(:arms (send* (send self :lhand-init) :close-forceps args)
80+
(send* (send self :rhand-init) :close-forceps args))))
81+
(:open-holder (&optional (arm :arms) &rest args)
82+
(case arm
83+
(:larm (send* (send self :lhand-init) :open-holder args))
84+
(:rarm (send* (send self :rhand-init) :open-holder args))
85+
(:arms (send* (send self :lhand-init) :open-holder args)
86+
(send* (send self :rhand-init) :open-holder args))))
87+
(:close-holder (&optional (arm :arms) &rest args)
88+
(case arm
89+
(:larm (send* (send self :lhand-init) :close-holder args))
90+
(:rarm (send* (send self :rhand-init) :close-holder args))
91+
(:arms (send* (send self :lhand-init) :close-holder args)
92+
(send* (send self :rhand-init) :close-holder args))))
4493
)
4594

4695
(defun nextage-init ()
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
(require :nextage "package://nextage_tutorials/nextage.l")
2+
(require "package://nextage_tutorials/euslisp/nextage-interface.l")
3+
4+
(defmethod NextageOpen-robot
5+
(:inverse-kinematics
6+
(target-coords &rest args &key (avoid-collision-distance 5) &allow-other-keys)
7+
(let ((r) (original-av (send self :angle-vector)))
8+
(setq r (send-super* :inverse-kinematics target-coords :avoid-collision-distance avoid-collision-distance :warnp nil :dump-command nil args))
9+
(unless r
10+
(format *error-output* "; failed for normal ik, try to start from ik-friendly position~%")
11+
(let* ((move-joints (send-all (cadr (memq :link-list args)) :joint))
12+
(av-after-first-ik (send self :angle-vector)))
13+
(send self :angle-vector original-av)
14+
(send self :reset-pose)
15+
(send self :head :angle-vector #f(0 60))
16+
(send self :larm :move-end-pos #f(0 0 50))
17+
(send self :rarm :move-end-pos #f(0 0 50))
18+
(mapcar #'(lambda (j a)
19+
(if (not (memq j move-joints))
20+
(send j :joint-angle a)))
21+
(send self :joint-list) original-av)
22+
(setq r (send-super* :inverse-kinematics target-coords :avoid-collision-distance avoid-collision-distance :warnp nil :dump-command nil args))
23+
(unless r
24+
(if (and (memq :revert-if-fail args) (null (cadr (memq :revert-if-fail args))))
25+
(send self :angle-vector original-av)
26+
(send self :angle-vector av-after-first-ik)))))
27+
r))
28+
(:l/r-reverse
29+
(av)
30+
(let ((av-tmp (copy-list av)))
31+
(setf (elt av-tmp 0) (- (elt av-tmp 0)))
32+
(setf (elt av-tmp 3) (- (elt av-tmp 3)))
33+
(setf (elt av-tmp 5) (- (elt av-tmp 5)))
34+
av-tmp))
35+
(:self-collision-check (&rest args)
36+
(let ((ret (send-super* :self-collision-check args)))
37+
(when ret
38+
(setq ret (remove-if #'(lambda (l)
39+
(or (and (eq (car l) (send self :link "CHEST_JOINT0_Link"))
40+
(eq (cdr l) (send self :link "HEAD_JOINT1_Link")))
41+
(and (eq (cdr l) (send self :link "CHEST_JOINT0_Link"))
42+
(eq (car l) (send self :link "HEAD_JOINT1_Link")))
43+
(and (eq (car l) (send self :link "LARM_JOINT4_Link"))
44+
(eq (cdr l) (send self :link "LARM_JOINT5_Link")))
45+
(and (eq (cdr l) (send self :link "LARM_JOINT4_Link"))
46+
(eq (car l) (send self :link "LARM_JOINT5_Link")))
47+
(and (eq (car l) (send self :link "RARM_JOINT4_Link"))
48+
(eq (cdr l) (send self :link "RARM_JOINT5_Link")))
49+
(and (eq (cdr l) (send self :link "RARM_JOINT4_Link"))
50+
(eq (car l) (send self :link "RARM_JOINT5_Link")))))
51+
ret)))
52+
ret)))

0 commit comments

Comments
 (0)