Advertisement
Guest User

Untitled

a guest
May 24th, 2015
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 36.45 KB | None | 0 0
  1. ;;;;;;;;;;;;;;;;
  2. ;; DRC testbed models
  3. ;; (snozawa, mmurooka, s-noda)
  4. ;;;;;;;;;;;;;;;;
  5.  
  6. #-:jsk
  7. (jsk)
  8. #-:rbrain-basic
  9. (rbrain)
  10.  
  11. (load "~/prog/euslib/rbrain/convert-to-irtmodel.l")
  12.  
  13. ;;;;;;;;;;;;;;;;
  14. ;; Utilities
  15. ;;;;;;;;;;;;;;;;
  16. (defclass single-link-model
  17. :super cascaded-link
  18. :slots ()
  19. )
  20.  
  21. (defmethod single-link-model
  22. (:init
  23. (&key (name) ((:bodies bs)))
  24. (prog1
  25. (send-super :init :name name)
  26. (setq links (list (instance bodyset-link :init (make-cascoords)
  27. :bodies bs :name :root-link)))
  28. (send self :assoc (car links))
  29. (send self :init-ending)
  30. ))
  31. )
  32.  
  33. (defun make-cylinder-shell
  34. (outer-radius inner-radius height)
  35. (let ((b0 (make-cylinder outer-radius height))
  36. (b1 (make-cylinder inner-radius (+ 1 height))))
  37. (body- b0 b1)
  38. ))
  39.  
  40. ;;;;;;;;;;;;;;;;
  41. ;; Model classes
  42. ;;;;;;;;;;;;;;;;
  43.  
  44. ;; copied from jskmapclsas
  45. (defclass valve
  46. :super cascaded-link
  47. :slots (handle valve-joint)
  48. )
  49.  
  50. (defmethod valve
  51. (:init
  52. (&rest args
  53. &key (thick 20) (radius 115)
  54. (ring-color :gray10) (base-color :royalblue)
  55. (type :round) (with-root-pipe t))
  56. (send-super* :init args)
  57. (setq handle nil)
  58. ;; 1. make links links and assoc all links
  59. (let ((rl (send self :make-root-link
  60. :base-color base-color :with-root-pipe with-root-pipe))
  61. (vl (send self :make-valve-link
  62. :thick thick :radius radius :ring-color ring-color :type type)))
  63. (send vl :translate #f(0 0 353) :world) ;;vavle's hight (H)
  64. ;; 2. assoc links
  65. ;; Root link should be associated with "self".
  66. (send self :assoc rl)
  67. (send rl :assoc vl)
  68. ;; 3. make all joints
  69. ;; Before making joints, you should :assoc all links.
  70. (setq valve-joint (instance rotational-joint :init
  71. :parent-link rl :child-link vl
  72. :name :crank-joint :axis :z
  73. :min -3600 :max 3600))
  74. ;; 4. define slots for robot class
  75. ;; links and joint-list for cascaded-link.
  76. (setq links (list rl vl))
  77. (setq joint-list (list valve-joint))
  78. ;; 5. call :init-ending after defining links and joint-list and return "self"
  79. (send self :init-ending)
  80. self))
  81. ;; Methods to define robot links
  82. (:make-root-link
  83. (&key base-color with-root-pipe)
  84. (let (base-cylinder
  85. (r 90)
  86. (L 240)
  87. (H 353)
  88. (thick 30)
  89. tmp
  90. cylinder1
  91. cylinder2
  92. cylinder3
  93. cylinder4
  94. upper-body
  95. sphere
  96. rl
  97. )
  98. ;;base cylinder
  99. (setq base-cylinder (make-cylinder r L))
  100. (send base-cylinder :rotate (deg2rad 90) :x)
  101. (send base-cylinder :locate (float-vector 0 (* 0.5 L) 0) :world)
  102. (setq tmp (make-cube (* L 2) (- L (* thick 2)) (* L 2)))
  103. (setq base-cylinder (body- base-cylinder tmp))
  104. (setq sphere (make-gdome (make-icosahedron r)))
  105. (setq cylinder1 (make-cylinder (* r 0.8) (- L (* 2 thick))))
  106. (send cylinder1 :rotate (deg2rad 90) :x)
  107. (send cylinder1 :locate (float-vector 0 (* 0.5 (- L (* 2 thick))) 0) :world)
  108. ;;
  109. (setq tmp (make-cylinder (* r 0.5) (* L 2)))
  110. (send tmp :rotate (deg2rad 90) :x)
  111. (send tmp :locate (float-vector 0 0 (* -1 L)))
  112. (setq base-cylinder (body- base-cylinder tmp))
  113. (setq cylinder1 (body- cylinder1 tmp))
  114. ;;(setq sphere (body- sphere tmp))
  115. ;;
  116. (setq cylinder2 (make-cylinder r thick))
  117. (send cylinder2 :locate (float-vector 0 0 r))
  118. (setq cylinder3 (make-cylinder (* r 0.8) (* thick 2)))
  119. (send cylinder3 :locate (float-vector 0 0 (- r (* 2 thick))))
  120. ;;
  121. (setq cylinder4 (make-cylinder 20 H))
  122. ;;(send cylinder4 :locate (float-vector 0 0 (* 0.5 H)))
  123. ;;upper body
  124. (setq upper-body
  125. (make-solid-of-revolution
  126. (mapcar #'(lambda (x) (scale (* 0.7 (/ (- H r) 3.5)) x)) (list #f(0 0 3.5) #f(0.6 0 3) #f(1.0 0 2) #f(1.4 0 1) #f(1.0 0 0)))))
  127. (send upper-body :locate (float-vector 0 0 (+ r thick)))
  128. ;;
  129. (send upper-body :assoc sphere)
  130. (send upper-body :assoc cylinder1)
  131. (send upper-body :assoc cylinder2)
  132. (send upper-body :assoc cylinder3)
  133. (send upper-body :assoc cylinder4)
  134. (setq cylinder5 (make-cylinder 45 (+ 500 1130) :pos (float-vector 0 1130 0) :rpy (float-vector 0 0 pi/2)))
  135. (send upper-body :assoc cylinder5)
  136. (send upper-body :assoc base-cylinder)
  137. (setq rl (instance bodyset-link :init (make-cascoords)
  138. :bodies (if with-root-pipe (list upper-body base-cylinder sphere cylinder1 cylinder2 cylinder3 cylinder4 cylinder5) (list upper-body cylinder4))
  139. :name :crank-root-link))
  140. (dolist (l (send rl :bodies))
  141. (send l :set-color base-color))
  142. rl
  143. ))
  144. (:make-valve-link
  145. (&key thick radius ring-color type)
  146. (cond ((equal type :round)
  147. (let* ((segments 16)
  148. (ring-radius radius)
  149. (pipe-radius thick)
  150. (ring (make-ring ring-radius pipe-radius :segments segments))
  151. (cross-bar1 (make-cube pipe-radius (* ring-radius 2) pipe-radius))
  152. (cross-bar2 (make-cube (* ring-radius 2) pipe-radius pipe-radius)))
  153. (send ring :assoc cross-bar1)
  154. (send ring :assoc cross-bar2)
  155. (let ((valve-link (instance bodyset-link :init (make-cascoords)
  156. :bodies (list ring cross-bar1 cross-bar2) :name :valve-handle-link)))
  157. ;;
  158. (push (make-cascoords :coords (send (send (send ring :copy-worldcoords)
  159. :translate (float-vector 0 (* -1 radius) 0))
  160. :rotate (/ pi 2) :y)
  161. :name :valve-handle) handle)
  162. (send valve-link :assoc (car handle))
  163. (dolist (l (send valve-link :bodies))
  164. (send l :set-color ring-color))
  165. valve-link)))
  166. ((equal type :bar)
  167. (let* ((segments 16)
  168. (bar-thick (/ 27 2))
  169. (bar-length 393)
  170. (bar-root-thick (/ 45.5 2))
  171. (bar-root-length 100)
  172. (bar (make-cylinder bar-thick bar-length :segments segments))
  173. (bar-root (make-cylinder bar-root-thick bar-root-length :segments segments)))
  174. (send bar-root :assoc bar)
  175. (send bar-root :rotate pi/2 :x :world)
  176. (send bar-root :translate (float-vector 0 (/ bar-root-length 2.0) 0) :world)
  177. (let ((valve-link (instance bodyset-link :init (make-cascoords)
  178. :bodies (list bar-root bar) :name :valve-handle-link)))
  179. ;;
  180. (push (make-cascoords :coords (send (send (send bar-root :copy-worldcoords)
  181. :translate (float-vector 0 0 350))
  182. :rotate (/ -pi 2) :z)
  183. :name :valve-handle) handle)
  184. (send valve-link :assoc (car handle))
  185. (dolist (l (send valve-link :bodies))
  186. (send l :set-color ring-color))
  187. valve-link))))
  188. )
  189. (:handle (&rest args) (forward-message-to-all handle args))
  190. (:valve-handle () (car handle))
  191. (:valve-joint (&rest args) (forward-message-to valve-joint args))
  192. )
  193.  
  194. (defclass drc-stair
  195. :slots (stair-top-faces ground-body)
  196. :super single-link-model
  197. )
  198.  
  199. (defmethod drc-stair
  200. (:init
  201. (&key (add-groud-p nil))
  202. (setq stair-top-faces nil)
  203. (let* ((blist (append (send self :make-stair-bodies)
  204. (send self :make-top-stair-bodies)
  205. (send self :make-handrail-bodies)
  206. (send self :make-small-handrail-bodies :l/r :right)
  207. (send self :make-small-handrail-bodies)
  208. (send self :make-top-handrail-bodies))))
  209. (if add-groud-p
  210. (let ((b (make-cube 1000 1200 10)))
  211. (send b :translate (float-vector 0 0 -5))
  212. (setq ground-body b)
  213. (setq stair-top-faces (append stair-top-faces
  214. (list (find-if #'(lambda (x) (memq :top (send x :id))) (send ground-body :faces)))))
  215. (push b blist)))
  216. (dolist (b blist) (send b :set-color :gray))
  217. (dolist (b (cdr blist)) (send (car blist) :assoc b))
  218. (send-super :init :name "drc-stair" :bodies blist)))
  219. (:make-stair-bodies
  220. ()
  221. (let ((s1 (make-cube 290 1080 225))
  222. (s2 (make-cube 290 1080 230))
  223. (s3 (make-cube 270 1080 230)))
  224. (send s1 :translate (float-vector (/ 290 2.0) 0 (/ 225 2.0)) :world)
  225. (send s2 :translate (float-vector (+ 290 (/ 290 2.0)) 0 (+ 225 (/ 230 2.0))) :world)
  226. (send s3 :translate (float-vector (+ 290 290 (/ 270 2.0)) 0 (+ 225 230 (/ 230 2.0))) :world)
  227. (setq stair-top-faces
  228. (append stair-top-faces
  229. (mapcar #'(lambda (b)
  230. (find-if #'(lambda (x) (memq :top (send x :id))) (send b :faces)))
  231. (list s1 s2 s3))))
  232. (list s1 s2 s3)
  233. ))
  234. (:make-top-stair-bodies
  235. ()
  236. (let ((s1 (make-cube 1205 2430 85)))
  237. (send s1 :translate (float-vector (+ 290 290 270 (/ 1205 2.0)) (+ 85 (+ (/ 1080 2.0) (- (/ 2430 2.0)))) (+ 225 230 230 (/ 85 2.0) -85 220)))
  238. (setq stair-top-faces
  239. (append stair-top-faces
  240. (mapcar #'(lambda (b)
  241. (find-if #'(lambda (x) (memq :top (send x :id))) (send b :faces)))
  242. (list s1))))
  243. (list s1)
  244. ))
  245. (:make-small-handrail-bodies
  246. (&key (l/r :left))
  247. (let ((b0 (make-cylinder 20 100))
  248. (b1 (make-cylinder 20 100))
  249. (b2 (make-cylinder 20 195)))
  250. (send b0 :rotate -pi/2 :y)
  251. (send b1 :rotate -pi/2 :y)
  252. (send b0 :translate (float-vector 0 0 (/ (+ 850 890) 2.0)) :world)
  253. (send b1 :translate (float-vector 0 0 (/ (+ 1045 1005) 2.0)) :world)
  254. (send b2 :translate (float-vector -100 0 850) :world)
  255. (if (eq l/r :left)
  256. (send-all (list b0 b1 b2) :translate (float-vector 0 (/ 1080 2.0) 0))
  257. (send-all (list b0 b1 b2) :translate (float-vector 0 (/ 1080 -2.0) 0)))
  258. (list b0 b1 b2)
  259. ))
  260. (:make-handrail-bodies
  261. ()
  262. (let ((bf1 (make-cube 50 40 (+ 225 835)))
  263. (bf2 (make-cube 50 40 (+ 225 835)))
  264. (br1 (make-cube 50 40 995))
  265. (br2 (make-cube 50 40 995))
  266. (hr1 (make-cylinder 20 1040))
  267. (hl1 (make-cylinder 20 1040))
  268. (hr2 (make-cylinder 20 1040))
  269. (hl2 (make-cylinder 20 1040)))
  270. (send bf1 :translate (float-vector (/ 50 -2.0) (+ (/ 40 -2.0) (/ 1080 2.0)) (/ (+ 225 835) 2.0)))
  271. (send bf2 :translate (float-vector (/ 50 -2.0) (+ (/ 40 2.0) (/ 1080 -2.0)) (/ (+ 225 835) 2.0)))
  272. (send br1 :translate (float-vector (+ 290 290 230 (/ 50 -2.0)) (+ (/ 40 -2.0) (/ 1080 2.0)) (+ 225 230 230 (/ 995 2.0))))
  273. (send br2 :translate (float-vector (+ 290 290 230 (/ 50 -2.0)) (+ (/ 40 2.0) (/ 1080 -2.0)) (+ 225 230 230 (/ 995 2.0))))
  274. ;;(send hr1 :rotate (deg2rad (- 90 40)) :y)
  275. ;;(send hl1 :rotate (deg2rad (- 90 40)) :y)
  276. (send hr1 :rotate (deg2rad (- 90 38)) :y)
  277. (send hl1 :rotate (deg2rad (- 90 38)) :y)
  278. (send hr2 :rotate (deg2rad (- 90 38)) :y)
  279. (send hl2 :rotate (deg2rad (- 90 38)) :y)
  280. (send hr1 :translate (float-vector -40 (+ (/ 40 -2.0) (/ 1080 2.0)) (+ 225 835 -20)) :world)
  281. (send hl1 :translate (float-vector -40 (+ (/ 40 2.0) (/ 1080 -2.0)) (+ 225 835 -20)) :world)
  282. (send hr2 :translate (float-vector -40 (+ (/ 40 -2.0) (/ 1080 2.0)) (+ 225 385 -20)) :world)
  283. (send hl2 :translate (float-vector -40 (+ (/ 40 2.0) (/ 1080 -2.0)) (+ 225 385 -20)) :world)
  284. (list bf1 bf2 br1 br2 hr1 hl1 hr2 hl2)
  285. ))
  286. (:make-top-handrail-bodies
  287. ()
  288. (let ((b1 (make-cube 35 50 1065))
  289. (b2 (make-cube 35 50 1065))
  290. (b3 (make-cube 35 50 1065))
  291. (b4 (make-cube 35 50 1065))
  292. (b5 (make-cube 35 50 1065))
  293. (b6 (make-cube 35 50 1065))
  294. ;;
  295. (b7 (make-cube 1205 50 40))
  296. (b8 (make-cube 1205 50 40))
  297. (b9 (make-cube 1205 50 40))
  298. (b10 (make-cube 1205 50 40))
  299. (b11 (make-cube 50 2430 40))
  300. (b12 (make-cube 50 2430 40))
  301. ;;
  302. (b13 (make-cube 1205 10 105))
  303. (b14 (make-cube 1205 10 105))
  304. )
  305. (send b1 :translate (float-vector (+ 290 290 270 (/ 35 2.0)) (+ 85 (/ 1080 2.0) (/ 50 2.0)) (+ 225 230 230 220 (/ 1065 2.0))))
  306. (send b2 :translate (float-vector (+ 290 290 270 (/ 35 -2.0) 1205) (+ 85 (/ 1080 2.0) (/ 50 2.0)) (+ 225 230 230 220 (/ 1065 2.0))))
  307. (send b3 :translate (float-vector (+ 290 290 270 (/ 35 -2.0) 1205) (+ 85 (/ 1080 2.0) (/ 50 -2.0) -2430) (+ 225 230 230 220 (/ 1065 2.0))))
  308. (send b4 :translate (float-vector (+ 290 290 270 (/ 35 2.0)) (+ 85 (/ 1080 2.0) (/ 50 -2.0) -2430) (+ 225 230 230 220 (/ 1065 2.0))))
  309. (send b5 :translate (float-vector (+ 290 290 270 1205 (/ 35 2.0)) (+ 85 -100 (/ 1080 2.0) (/ 50 2.0)) (+ 225 230 230 220 (/ 1065 2.0))))
  310. (send b6 :translate (float-vector (+ 290 290 270 1205 (/ 35 2.0)) (+ 85 100 (/ 1080 2.0) (/ 50 -2.0) -2430) (+ 225 230 230 220 (/ 1065 2.0))))
  311. ;;
  312. (send b7 :translate (float-vector (+ 290 290 270 (/ 1205 2.0)) (+ 85 (/ 1080 2.0) (/ 50 2.0)) (+ 225 230 230 220 1065 (/ 40 2.0))))
  313. (send b8 :translate (float-vector (+ 290 290 270 (/ 1205 2.0)) (+ 85 (/ 1080 2.0) (/ 50 2.0)) (+ 225 230 230 220 550 (/ 40 2.0))))
  314. (send b9 :translate (float-vector (+ 290 290 270 (/ 1205 2.0)) (+ 85 (/ 1080 2.0) (/ 50 -2.0) -2430) (+ 225 230 230 220 1065 (/ 40 2.0))))
  315. (send b10 :translate (float-vector (+ 290 290 270 (/ 1205 2.0)) (+ 85 (/ 1080 2.0) (/ 50 -2.0) -2430) (+ 225 230 230 220 550 (/ 40 2.0))))
  316. (send b11 :translate (float-vector (+ 290 290 270 1205 (/ 50 2.0)) (+ 85 (/ 1080 2.0) (/ 2430 -2.0)) (+ 225 230 230 220 1065 (/ 40 2.0))))
  317. (send b12 :translate (float-vector (+ 290 290 270 1205 (/ 50 2.0)) (+ 85 (/ 1080 2.0) (/ 2430 -2.0)) (+ 225 230 230 220 550 (/ 40 2.0))))
  318. ;;
  319. (send b13 :translate (float-vector (+ 290 290 270 (/ 1205 2.0)) (+ 85 (/ 1080 2.0) (/ 10 -2.0) -2430) (+ 225 230 230 220 (/ 40 2.0))))
  320. (send b14 :translate (float-vector (+ 290 290 270 (/ 1205 2.0)) (+ 85 (/ 1080 2.0) (/ 10 -2.0) 0) (+ 225 230 230 220 (/ 40 2.0))))
  321. (list b1 b2 b3 b4 b5 b6
  322. b7 b8 b9 b10 b11 b12
  323. b13 b14)
  324. ))
  325. (:get-all-stair-top-faces
  326. ()
  327. stair-top-faces)
  328. )
  329.  
  330. (defclass drc-hose-wall
  331. :super single-link-model
  332. :slots ()
  333. )
  334.  
  335. (defmethod drc-hose-wall
  336. (:init
  337. ()
  338. (let ((blist (send self :make-hose-wall-bodies)))
  339. (dolist (b (cdr blist)) (send (car blist) :assoc b))
  340. (send-super :init :name "drc-hose-wall" :bodies blist)))
  341. (:make-hose-consent
  342. ()
  343. (let ((b1 (make-cube 75 65 165))
  344. (b2 (make-cylinder-shell (/ 56 2.0) (/ 48 2.0) 25.0))
  345. (b3 (make-cylinder-shell (/ 56 2.0) (/ 48 2.0) 25.0))
  346. (blist))
  347. (send b1 :translate (float-vector (/ 75 -2.0) 0 0))
  348. (send b2 :rotate pi/2 :y)
  349. (send b2 :translate (float-vector (+ -75 -25) 0 (+ (/ 165 2.0) -40)) :world)
  350. (send b3 :translate (float-vector (/ 75 -2.0) 0 (+ (/ 165 -2.0) -25.0)) :world)
  351. (let ((blist (list b1 b2 b3)))
  352. (send-all blist :set-color :gray60)
  353. (dolist (b (cdr blist)) (send (car blist) :assoc b))
  354. blist
  355. )))
  356. (:make-hose-wall-bodies
  357. ()
  358. (let ((b0 (make-cube 10 1210 2430))
  359. (blist1 (send self :make-hose-consent))
  360. (blist2 (send self :make-hose-consent))
  361. (blist))
  362. (send b0 :set-color #F(0.8 0.5 0))
  363. (send b0 :translate (float-vector (/ 10 2.0) 0 (/ 2430 2.0)))
  364. (send (car blist1) :translate (float-vector 0 200 (+ (/ 165 2.0) 1120)))
  365. (send (car blist2) :translate (float-vector 0 -200 (+ (/ 165 2.0) 1120)))
  366. (send b0 :assoc (car blist1))
  367. (send b0 :assoc (car blist2))
  368. (append (list b0) blist1 blist2)))
  369. )
  370.  
  371. (defclass drc-hose-plug
  372. :super single-link-model
  373. :slots ()
  374. )
  375.  
  376. (defmethod drc-hose-plug
  377. (:init
  378. ()
  379. (let ((blist (send self :make-hose-plug-bodies)))
  380. (dolist (b (cdr blist)) (send (car blist) :assoc b))
  381. (send-super :init :name "drc-hose-plug" :bodies blist)))
  382. (:make-hose-plug-bodies
  383. ()
  384. (let ((b1 (make-cylinder (/ 45 2.0) 85.0))
  385. (b2 (make-cube 20 75 10)))
  386. (send b1 :rotate pi/2 :y)
  387. (send b2 :translate (float-vector (/ 20 2.0) 0 0))
  388. (send b1 :assoc b2)
  389. (send-all (list b1 b2) :set-color :gray20)
  390. (list b1 b2)
  391. ))
  392. )
  393.  
  394. (defclass drc-drill-wall
  395. :super single-link-model
  396. :slots ()
  397. )
  398.  
  399. (defmethod drc-drill-wall
  400. (:init
  401. ()
  402. (let ((blist (send self :make-drill-wall-bodies)))
  403. (dolist (b (cdr blist)) (send (car blist) :assoc b))
  404. (send-super :init :name "drc-drill-wall" :bodies blist)))
  405. (:make-drill-wall-bodies
  406. ()
  407. (let ((b1 (make-cube 10 1210 2430))
  408. (b2 (make-cube 10 1210 2430))
  409. (b2- (make-cube 20 810 810))
  410. (b3 (make-cube 250 440 10))
  411. b21 b22 b23 b24)
  412. (send b2- :translate (float-vector 0 0 (+ 720 (/ 810 2.0) (/ 2430 -2.0))))
  413. (setq b2 (body- b2 b2-))
  414. (setq b21 (make-cube 10 (/ (- 1210 810) 2) 2430 :pos (float-vector 0 (+ (/ 810 2) (/ (- 1210 810) 4)) 0))
  415. b22 (make-cube 10 850 720 :pos (float-vector 0 0 (+ (/ 2430 -2) (/ 710 2))))
  416. b23 (make-cube 10 (/ (- 1210 810) 2) 2430 :pos (float-vector 0 (- (+ (/ 810 2) (/ (- 1210 810) 4))) 0))
  417. b24 (make-cube 10 850 720 :pos (float-vector 0 0 (+ (/ 2430 2) (/ 710 -2)))))
  418. (objects (list
  419. b2 ))
  420. (objects (list
  421. b2
  422. b21 b22 b23 b24))
  423. (dolist (b (list b22 b23 b24))
  424. (send b21 :assoc b))
  425. (send b1 :translate (float-vector (/ 10 2.0) 0 (/ 2430 2.0)) :world)
  426. (send b2 :translate (float-vector (/ 10 2.0) 0 (/ 2430 2.0)) :world)
  427. (send b21 :translate (float-vector (/ 10 2.0) 0 (/ 2430 2.0)) :world)
  428. (send b3 :translate (float-vector (/ 250 -2.0) 0 (+ (/ 10 2.0) 1020)))
  429. (send b1 :assoc b3)
  430. (send b1 :rotate (deg2rad 45) :z)
  431. (send b2 :rotate (deg2rad -45) :z)
  432. (send b21 :rotate (deg2rad -45) :z)
  433. (send b1 :translate (float-vector 0 (* 1210 0.5) 0))
  434. (send b2 :translate (float-vector 0 (* 1210 -0.5) 0))
  435. (send b21 :translate (float-vector 0 (* 1210 -0.5) 0))
  436. (send b21 :translate (float-vector 370 150 0))
  437. (send-all (list b1 b2 b3 b21 b22 b23 b24) :set-color #f(0.8 0.5 0))
  438. (list b1 b21 b22 b23 b24 b3)
  439. ;(list b1 b2 b3)
  440. ))
  441. )
  442.  
  443. (defclass drc-terrain
  444. :super cascaded-link
  445. :slots (block-dimensions block-bodies ground-body block-angle)
  446. )
  447.  
  448. (defmethod drc-terrain
  449. (:init
  450. (&rest args &key (name "drc-terrain") ((:block-dimensions bd) (list 390 195 140)) (add-groud-p nil)
  451. ((:block-angle ba) 15.0) ;; [deg]
  452. &allow-other-keys)
  453. (prog1
  454. (send-super* :init :name name args)
  455. (setq block-dimensions bd)
  456. (setq block-angle ba)
  457. (let* ((blist (send self :make-drc-terrain-block-bodies))
  458. (l))
  459. (if add-groud-p
  460. (let ((b (make-cube 3700 3300 10)))
  461. (send b :translate (float-vector 1200 1050 -5))
  462. (send b :set-color :gray)
  463. (setq ground-body b)
  464. (send (car blist) :assoc b)
  465. (setq blist (append blist (list b)))))
  466. (setq l (instance bodyset-link :init (make-cascoords)
  467. :name :root-link
  468. :bodies blist))
  469. (send self :assoc l)
  470. (setq links (list l))
  471. (setq joint-list (list))
  472. (send self :init-ending)
  473. self)))
  474. (:make-drc-block-one
  475. ()
  476. (let* ((block-x (elt block-dimensions 0))
  477. (block-y (elt block-dimensions 1))
  478. (block-z (elt block-dimensions 2))
  479. (block-hole-x 170)
  480. (block-hole-y 200)
  481. (block-hole-z 85)
  482. (block-body (make-cube block-x block-y block-z))
  483. (block-hole1 (make-cube block-hole-x block-hole-y block-hole-z))
  484. (block-hole2 (make-cube block-hole-x block-hole-y block-hole-z))
  485. )
  486. (send block-hole1 :translate (float-vector (/ (+ block-hole-x (/ (- block-x (* block-hole-x 2)) 3.0)) 2.0) 0 0) :local)
  487. (send block-hole2 :translate (float-vector (- (/ (+ block-hole-x (/ (- block-x (* block-hole-x 2)) 3.0)) 2.0)) 0 0) :local)
  488. (setq block-body (body- block-body block-hole1))
  489. (setq block-body (body- block-body block-hole2))
  490. (send block-body :set-color :gray)
  491. block-body
  492. )
  493. )
  494. (:make-drc-block-set-one
  495. ()
  496. (let* ((block-x (elt block-dimensions 0))
  497. (block-y (elt block-dimensions 1))
  498. (block-z (elt block-dimensions 2))
  499. (block1 (send self :make-drc-block-one))
  500. (block2 (send self :make-drc-block-one))
  501. (base-x 90)
  502. (base-y block-x)
  503. (base-z 90)
  504. (base (make-cube base-x base-y base-z))
  505. )
  506. (send block1 :translate (float-vector 0 (/ block-y 2.0) (+ (/ block-z 2.0) (* (/ block-x 2.0) (sin (deg2rad block-angle))))) :local)
  507. (send block2 :translate (float-vector 0 (- (/ block-y 2.0)) (+ (/ block-z 2.0) (* (/ block-x 2.0) (sin (deg2rad block-angle))))) :local)
  508. (send base :translate (float-vector (- (- (/ block-x 2.0) (/ base-x 2.0))) 0 (/ base-x 2.0)) :local)
  509. (send block1 :rotate (deg2rad block-angle) :y :local)
  510. (send block2 :rotate (deg2rad block-angle) :y :local)
  511. (send base :set-color :darkgoldenrod)
  512. (send block1 :assoc block2)
  513. (send block1 :assoc base)
  514. (instance bodyset :init (make-cascoords) :bodies (list block1 block2 base))
  515. )
  516. )
  517. (:make-drc-terrain-block-bodies
  518. ()
  519. (let* ((orientation-map (list (list 1 2 3 0 1 2)
  520. (list 2 3 0 1 2 3)
  521. (list 3 0 1 2 3 0)
  522. (list 0 1 2 3 0 1)
  523. (list 1 2 3 0 1 2)
  524. (list 2 3 0 1 2 3)
  525. (list 3 0 1 2 3 0)))
  526. (height-map (list (list 0 0 0 0 0 0)
  527. (list 0 0 1 1 0 0)
  528. (list 0 0 1 1 0 0)
  529. (list 0 1 1 1 1 0)
  530. (list 1 2 1 1 2 1)
  531. (list 1 1 1 1 1 1)
  532. (list 0 0 0 0 0 0))))
  533. (let* ((block-set-region-x 400)
  534. (block-set-region-y 400))
  535. (dotimes (i (length orientation-map))
  536. (dotimes (j (length (elt orientation-map i)))
  537. (let* ((block-set (send self :make-drc-block-set-one)))
  538. (send block-set :rotate (* (elt (elt orientation-map i) j) pi/2) :z :world)
  539. (send block-set :translate (float-vector (* i block-set-region-x) (* j block-set-region-y) (* (elt (elt height-map i) j) (elt block-dimensions 2))) :world)
  540. (push block-set block-bodies)))))
  541. (setq block-bodies (flatten (send-all block-bodies :bodies)))
  542. (dolist (b (cdr block-bodies)) (send (car block-bodies) :assoc b))
  543. block-bodies)
  544. )
  545. (:block-bodies () block-bodies)
  546. (:get-terrain-top-face-from-block-idx
  547. (block-idx)
  548. (list (elt (send (elt block-bodies (* 3 block-idx)) :faces) 6)
  549. (elt (send (elt block-bodies (+ (* 3 block-idx) 1)) :faces) 6))
  550. )
  551. (:get-all-terrain-top-faces
  552. ()
  553. (let ((ret -1))
  554. (flatten (append (mapcar #'(lambda (x) (send self :get-terrain-top-face-from-block-idx (incf ret))) (make-list (/ (length block-bodies) 3)))
  555. (list (find-if #'(lambda (x) (memq :top (send x :id))) (send ground-body :faces)))))))
  556. )
  557.  
  558.  
  559. (defclass drc-surprise-task-shower
  560. :super cascaded-link
  561. :slots (bar1-joint bar2-joint)
  562. )
  563.  
  564. (defmethod drc-surprise-task-shower
  565. (:init
  566. ()
  567. (prog1
  568. (send-super :init :name "drc-surprise-task-shower")
  569. ;; 1. make links links and assoc all links
  570. (let ((l0 (send self :make-root-link))
  571. (l1 (send self :make-bar1-link))
  572. (l2 (send self :make-bar2-link)))
  573. (send l1 :translate (float-vector (+ -465 190) 600 (+ 1650 190 545)))
  574. (send l2 :translate (float-vector -465 600 (+ 1650 190 545)))
  575. ;; 2. assoc links
  576. ;; Root link should be associated with "self".
  577. (send self :assoc l0)
  578. (send l0 :assoc l1)
  579. (send l1 :assoc l2)
  580. ;; 3. make all joints
  581. ;; Before making joints, you should :assoc all links.
  582. (setq bar1-joint (instance rotational-joint :init
  583. :parent-link l0 :child-link l1
  584. :axis :y
  585. :name :bar1-joint
  586. :min -90 :max 90))
  587. (setq bar2-joint (instance rotational-joint :init
  588. :parent-link l1 :child-link l2
  589. :axis :y
  590. :name :bar2-joint
  591. :min -90 :max 90))
  592. ;; 4. define slots for robot class
  593. ;; links and joint-list for cascaded-link.
  594. (setq links (list l0 l1 l2))
  595. (setq joint-list (list bar1-joint bar2-joint))
  596. ;; 5. call :init-ending after defining links and joint-list and return "self"
  597. (send self :init-ending)
  598. self)))
  599. ;; Methods to define robot links
  600. (:make-root-link
  601. ()
  602. (let* ((b0 (make-cube 10 1330 1590))
  603. (b1 (make-cube (+ 465 150) 10 10))
  604. (b2-height (- (+ 1650 190 545) 1590))
  605. (b2 (make-cube 10 10 b2-height))
  606. (b3 (make-torus (list (float-vector 0 0 0) (float-vector 0 100 -100) (float-vector 0 0 -100)))))
  607. (send b0 :translate (float-vector (/ 10 2.0) 0 (/ 1800 2.0)))
  608. (send b1 :translate (float-vector (/ (+ 465 150) -2.0) 600 (+ 1650 190 545)))
  609. (send b2 :translate (float-vector (/ 10 -2.0) 600 (+ 1650 190 545 (/ b2-height -2.0))))
  610. (send b3 :translate (float-vector (+ -465 -150) 600 (+ 1650 190 545)))
  611. (send b0 :assoc b1)
  612. (send b0 :assoc b2)
  613. (send b0 :assoc b3)
  614. (send b0 :set-color #f(0.8 0.5 0))
  615. (send b1 :set-color :gray40)
  616. (send b2 :set-color :gray60)
  617. (send b3 :set-color :red)
  618. (instance bodyset-link :init (make-cascoords) :bodies (list b0 b1 b2 b3))
  619. ))
  620. (:make-bar1-link
  621. ()
  622. (let ((b0 (make-cube 190 10 10)))
  623. (send b0 :translate (float-vector (/ 190 -2.0) -10 0))
  624. (send b0 :set-color :gray70)
  625. (instance bodyset-link :init (make-cascoords) :bodies (list b0))
  626. ))
  627. (:make-bar2-link
  628. ()
  629. (let ((b0 (make-cube 10 10 545))
  630. (b1 (make-prism (list (float-vector 0 0 0) (float-vector 100 190 0) (float-vector -100 190 0)) 10)))
  631. (send b0 :translate (float-vector 0 0 (/ 545 -2.0)))
  632. (send b1 :rotate -pi/2 :x)
  633. (send b1 :translate (float-vector 0 0 -545) :world)
  634. (send b0 :assoc b1)
  635. (send b0 :set-color :gray60)
  636. (send b1 :set-color :gray50)
  637. (instance bodyset-link :init (make-cascoords) :bodies (list b0 b1))
  638. ))
  639. )
  640.  
  641. (defclass drc-surprise-task-button
  642. :super cascaded-link
  643. :slots (hinge-joint)
  644. )
  645.  
  646. (defmethod drc-surprise-task-button
  647. (:init
  648. ()
  649. (prog1
  650. (send-super :init :name "drc-surprise-task-button")
  651. ;; 1. make links links and assoc all links
  652. (let ((l0 (send self :make-root-link))
  653. (l1 (send self :make-door-link)))
  654. (send l1 :translate (float-vector -130 (/ 200 2.0) 1330))
  655. ;; 2. assoc links
  656. ;; Root link should be associated with "self".
  657. (send self :assoc l0)
  658. (send l0 :assoc l1)
  659. ;; 3. make all joints
  660. ;; Before making joints, you should :assoc all links.
  661. (setq hinge-joint (instance rotational-joint :init
  662. :parent-link l0 :child-link l1
  663. :axis :z
  664. :name :hinge-joint
  665. :min -90 :max 90))
  666. ;; 4. define slots for robot class
  667. ;; links and joint-list for cascaded-link.
  668. (setq links (list l0 l1))
  669. (setq joint-list (list hinge-joint))
  670. ;; 5. call :init-ending after defining links and joint-list and return "self"
  671. (send self :init-ending)
  672. self)))
  673. ;; Methods to define robot links
  674. (:make-root-link
  675. ()
  676. (let ((b0 (make-cube 10 1330 1590))
  677. (b1 (make-cube 130 200 250))
  678. (b1- (make-cube 50 190 240))
  679. (b2 (make-cylinder 30 40)))
  680. (send b1- :translate (float-vector (+ (/ 130 -2.0) (/ 50 2.0) -5) 0 0))
  681. (send b1- :worldcoords)
  682. (setq b1 (body- b1 b1-))
  683. (send b0 :translate (float-vector (/ 10 2.0) 0 (/ 1800 2.0)))
  684. (send b1 :translate (float-vector (/ 130 -2.0) 0 (+ 1330 (/ 250 2.0))))
  685. (send b2 :translate (float-vector -105 0 (+ 1330 (/ 250 2.0))) :world)
  686. (send b2 :rotate -pi/2 :y)
  687. (send b0 :set-color #f(0.8 0.5 0))
  688. (send b1 :set-color :gray60)
  689. (send b2 :set-color :red)
  690. (send b0 :assoc b1)
  691. (send b0 :assoc b2)
  692. (instance bodyset-link :init (make-cascoords) :bodies (list b0 b1 b2))
  693. ))
  694. (:make-door-link
  695. ()
  696. (let ((b0 (make-cube 20 200 250)))
  697. (send b0 :translate (float-vector (/ 20 -2.0) (/ 200 -2.0) (/ 250 2)))
  698. (send b0 :set-color :gray60)
  699. (instance bodyset-link :init (make-cascoords) :bodies (list b0))
  700. ))
  701. )
  702.  
  703. (defclass drc-surprise-task-lever
  704. :super cascaded-link
  705. :slots (lever-joint)
  706. )
  707.  
  708. (defmethod drc-surprise-task-lever
  709. (:init
  710. ()
  711. (prog1
  712. (send-super :init :name "drc-surprise-task-lever")
  713. ;; 1. make links links and assoc all links
  714. (let ((l0 (send self :make-root-link))
  715. (l1 (send self :make-lever-link)))
  716. (send l1 :translate (float-vector 0 (/ 405 -2.0) (+ 910 455)))
  717. ;; 2. assoc links
  718. ;; Root link should be associated with "self".
  719. (send self :assoc l0)
  720. (send l0 :assoc l1)
  721. ;; 3. make all joints
  722. ;; Before making joints, you should :assoc all links.
  723. (setq lever-joint (instance rotational-joint :init
  724. :parent-link l0 :child-link l1
  725. :axis :y
  726. :name :lever-joint
  727. :min -90 :max 90))
  728. ;; 4. define slots for robot class
  729. ;; links and joint-list for cascaded-link.
  730. (setq links (list l0 l1))
  731. (setq joint-list (list lever-joint))
  732. ;; 5. call :init-ending after defining links and joint-list and return "self"
  733. (send self :init-ending)
  734. self)))
  735. ;; Methods to define robot links
  736. (:make-root-link
  737. ()
  738. (let ((b0 (make-cube 10 1330 1590))
  739. (b1 (make-cube 150 405 720)))
  740. (send b0 :translate (float-vector (/ 10 2.0) 0 (/ 1800 2.0)))
  741. (send b1 :translate (float-vector (/ 150 -2.0) 0 (+ 910 (/ 720 2.0))))
  742. (send b1 :set-color :gray50)
  743. (send b0 :set-color #f(0.8 0.5 0))
  744. (send b0 :assoc b1)
  745. (instance bodyset-link :init (make-cascoords) :bodies (list b0 b1))
  746. ))
  747. (:make-lever-link
  748. ()
  749. (let ((b0 (make-cube 230 10 30))
  750. (b1 (make-cylinder (/ 58 2.0) 10)))
  751. (send b0 :translate (float-vector (/ 230 -2.0) (/ 10 -2.0) 0))
  752. (send b1 :translate (float-vector -230 0 0))
  753. (send b1 :rotate pi/2 :x)
  754. (send b0 :set-color :gray60)
  755. (send b1 :set-color :red)
  756. (send b0 :assoc b1)
  757. (instance bodyset-link :init (make-cascoords) :bodies (list b0 b1))
  758. ))
  759. )
  760.  
  761. (defclass drc-surprise-task-rope
  762. :super single-link-model
  763. :slots ()
  764. )
  765.  
  766. (defmethod drc-surprise-task-rope
  767. (:init
  768. ()
  769. (let ((blist (send self :make-surprise-task-rope-bodies)))
  770. (dolist (b (cdr blist)) (send (car blist) :assoc b))
  771. (send-super :init :name "drc-surprise-task-rope" :bodies blist)))
  772. (:make-surprise-task-rope-bodies
  773. ()
  774. (let ((b0 (make-cube 10 1330 1590))
  775. (b1 (make-cube 50 100 50))
  776. (b2 (make-cube 10 1040 10)))
  777. (send b0 :translate (float-vector (/ 10 2.0) 0 (/ 1800 2.0)))
  778. (send b1 :translate (float-vector (/ 50 -2.0) -480 1435))
  779. (send b2 :translate (float-vector (/ 10 -2.0) 80 1435))
  780. (send b0 :set-color #f(0.8 0.5 0))
  781. (send b1 :set-color :blue)
  782. (send b2 :set-color :red)
  783. (send b0 :assoc b1)
  784. (send b0 :assoc b2)
  785. (list b0 b1 b2)))
  786. )
  787.  
  788. ;;;;;;;;;;;;;;;;
  789. ;; Model generation functions
  790. ;;;;;;;;;;;;;;;;
  791. (defun make-drc-stair (&key (add-groud-p))
  792. (setq *stair* (instance drc-stair :init :add-groud-p add-groud-p))
  793. )
  794.  
  795. (defun make-drc-door ()
  796. "Door on drc"
  797. ; (null-output (load "package://drc_task_common/euslisp/test-drc-door-task.l"))
  798. (load "test-drc-door-task.l")
  799. (setq *door* (instance param-door :init 900
  800. 60 102 20
  801. (float-vector 0 (+ 900 -60 -24) 845)
  802. (float-vector -60 (+ 900 -60 -24) 845)
  803. :handle-l/r :left))
  804. )
  805.  
  806. (defun make-drc-hose-wall ()
  807. (setq *hose-wall* (instance drc-hose-wall :init))
  808. )
  809.  
  810. (defun make-drc-hose-plug ()
  811. (setq *hose-plug* (instance drc-hose-plug :init))
  812. )
  813.  
  814. (defun make-drc-drill-wall ()
  815. (setq *drill-wall* (instance drc-drill-wall :init))
  816. )
  817.  
  818. (defun make-drc-terrain (&key (add-groud-p))
  819. (setq *terrain* (instance drc-terrain :init :add-groud-p add-groud-p))
  820. )
  821.  
  822. (defun make-drc-terrain-japanese-block-ver (&key (add-groud-p))
  823. (setq *terrain* (instance drc-terrain :init :block-dimensions (list 390 190 150) :add-groud-p add-groud-p))
  824. )
  825.  
  826. (defun make-drc-terrain-japanese-block-ver-sagami (&key (add-groud-p))
  827. (setq *terrain* (instance drc-terrain :init :block-dimensions (list 390 190 150) :add-groud-p add-groud-p :block-angle 12.5))
  828. )
  829.  
  830. (defun make-drc-valve ()
  831. (setq *drc-valve* (instance valve :init :radius (/ 260 2.0) :thick (/ (- 260 205) 2.0) :ring-color :red))
  832. )
  833.  
  834. (defun make-drc-surprise-task-shower ()
  835. (setq *surprise-task-shower* (instance drc-surprise-task-shower :init))
  836. )
  837.  
  838. (defun make-drc-surprise-task-button ()
  839. (setq *surprise-task-button* (instance drc-surprise-task-button :init))
  840. )
  841.  
  842. (defun make-drc-surprise-task-lever ()
  843. (setq *surprise-task-lever* (instance drc-surprise-task-lever :init))
  844. )
  845.  
  846. (defun make-drc-surprise-task-rope ()
  847. (setq *surprise-task-rope* (instance drc-surprise-task-rope :init))
  848. )
  849.  
  850. (defun make-drc-surprise-task-box ()
  851. (make-drc-surprise-task-shower)
  852. (make-drc-surprise-task-button)
  853. (make-drc-surprise-task-lever)
  854. (make-drc-surprise-task-rope)
  855. (send *surprise-task-shower* :translate (float-vector (/ 1330 -2.0) 0 0))
  856. (send *surprise-task-lever* :translate (float-vector (/ 1330 2.0) 0 0))
  857. (send *surprise-task-lever* :rotate pi :z)
  858. (send *surprise-task-button* :translate (float-vector 0 (/ 1330 -2.0) 0))
  859. (send *surprise-task-button* :rotate pi/2 :z)
  860. (send *surprise-task-rope* :translate (float-vector 0 (/ 1330 2.0) 0))
  861. (send *surprise-task-rope* :rotate -pi/2 :z)
  862. (list *surprise-task-shower* *surprise-task-button* *surprise-task-lever* *surprise-task-rope*)
  863. )
  864.  
  865. ;; TODO : This should be scene
  866. (defun make-drc-testbed-models ()
  867. ;; Generate models
  868. (make-drc-door)
  869. (make-drc-hose-plug)
  870. (make-drc-hose-wall)
  871. (make-drc-stair)
  872. (make-drc-drill-wall)
  873. (make-drc-terrain)
  874. (make-drc-valve)
  875. (let ((sb (make-drc-surprise-task-box)))
  876. ;(send-all sb :translate (float-vector 12000 0 0) :world)
  877. )
  878. ;; Align models
  879. ; (send *stair* :translate (float-vector 8000 0 0) :world)
  880. ; (send *door* :translate (float-vector 0 0 0) :world)
  881. (send *hose-wall* :rotate (deg2rad -45) :z)
  882. ; (send *hose-wall* :translate (float-vector 4000 -3000 0) :world)
  883. (send *drill-wall* :rotate -pi/2 :z)
  884. (objects (list *drill-wall*))
  885. ; (send *drill-wall* :translate (float-vector 2000 -3500 0) :world)
  886. ; (send *terrain* :translate (float-vector 5000 -1000 0) :world)
  887. (send *drc-valve* :rotate -pi/2 :y)
  888. (send *drc-valve* :rotate (deg2rad -135) :x)
  889. ; (send *drc-valve* :translate (float-vector 2000 -3500 1130) :world)
  890. ; (send *drc-valve* :translate (float-vector 0 (/ 1210 -2.0) (+ -110 -400)))
  891. (send *drc-valve* :translate (float-vector 0 0 (+ 1130 (+ -110 -400))))
  892.  
  893. ;; Didplay
  894. (setq *models* (list *hose-plug* *hose-wall* *stair* *door* *drill-wall* *terrain* *drc-valve*
  895. *surprise-task-shower* *surprise-task-button* *surprise-task-lever* *surprise-task-rope*))
  896. (objects *models*)
  897. )
  898. ;(load "/home/k-okada/prog/euslib/rbrain/wrl2eus.l")
  899. (progn ;(load "package://drc_task_common/euslisp/drc-testbed-models.l")
  900. (make-drc-testbed-models)
  901.  
  902. (send *door* :name "drc-testbed-door")
  903. ;; (eus2wrl *door* "/tmp/DRCTestbedDoor.wrl" :mode :openhrp3 :fixed t )
  904.  
  905. (send *drill-wall* :name "drc-testbed-drill-wall")
  906. ;; (eus2wrl *drill-wall* "/tmp/DRCTestbedDrillWall.wrl" :mode :openhrp3 :fixed t)
  907.  
  908. (send *hose-plug* :name "drc-testbed-hose-plug")
  909. ;; (eus2wrl *hose-plug* "/tmp/DRCTestbedHosePlug.wrl" :mode :openhrp3 :fixed t)
  910.  
  911. (send *hose-wall* :name "drc-testbed-hose-wall")
  912. ;; (eus2wrl *hose-wall* "/tmp/DRCTestbedHoseWall.wrl" :mode :openhrp3 :fixed t)
  913.  
  914. (send *drc-valve* :name "drc-testbed-valve")
  915. ;; (eus2wrl *drc-valve* "/tmp/DRCTestbedValve.wrl" :mode :openhrp3 :fixed t)
  916.  
  917. (send *surprise-task-shower* :name "drc-testbed-shower")
  918. ;; (eus2wrl *surprise-task-shower* "/tmp/DRCTestbedShower.wrl" :mode :openhrp3 :fixed t)
  919.  
  920. (send *surprise-task-button* :name "drc-testbed-button")
  921. ;; (eus2wrl *surprise-task-button* "/tmp/DRCTestbedButton.wrl" :mode :openhrp3 :fixed t)
  922.  
  923. (send *surprise-task-lever* :name "drc-testbed-lever")
  924. ;; (eus2wrl *surprise-task-lever* "/tmp/DRCTestbedLever.wrl" :mode :openhrp3 :fixed t)
  925.  
  926. (send *surprise-task-rope* :name "drc-testbed-rope")
  927. ;; (eus2wrl *surprise-task-rope* "/tmp/DRCTestbedRope.wrl" :mode :openhrp3 :fixed t)
  928.  
  929. (dolist (obj *models*)
  930. (convert-to-irtmodel obj :output-directory "models"))
  931. )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement