comparison org/body.org @ 130:b26017d1fe9a

added workaround for problem with point2point joints in native bullet; added basic muscle description image.
author Robert McIntyre <rlm@mit.edu>
date Mon, 30 Jan 2012 05:47:51 -0700
parents fb810a2c50c2
children e98850b83c2c
comparison
equal deleted inserted replaced
129:bab47091534e 130:b26017d1fe9a
80 (.mult 80 (.mult
81 (.getLocalRotation object-b) 81 (.getLocalRotation object-b)
82 (doto (Quaternion.) 82 (doto (Quaternion.)
83 (.fromRotationMatrix rotate-a))) 83 (.fromRotationMatrix rotate-a)))
84 arm-b)] 84 arm-b)]
85 ;;(println-repl (.getName object-a) (.getName object-b))
85 [pitch yaw roll])) 86 [pitch yaw roll]))
86 87
87 (defn proprioception 88 (defn proprioception
88 "Create a function that provides proprioceptive information about an 89 "Create a function that provides proprioceptive information about an
89 entire body." 90 entire body."
223 (swap! time inc) 224 (swap! time inc)
224 (Thread/sleep 20) 225 (Thread/sleep 20)
225 (dorun (worm-motor-map 226 (dorun (worm-motor-map
226 (worm-pattern @time))))))) 227 (worm-pattern @time)))))))
227 228
229
230 (require 'cortex.silly)
231 (defn join-at-point [obj-a obj-b world-pivot]
232 (cortex.silly/joint-dispatch
233 {:type :point}
234 (.getControl obj-a RigidBodyControl)
235 (.getControl obj-b RigidBodyControl)
236 (cortex.silly/world-to-local obj-a world-pivot)
237 (cortex.silly/world-to-local obj-b world-pivot)
238 nil
239 ))
240
241
242
243 (defn blab-* []
244 (let [hand (box 0.5 0.2 0.2 :position (Vector3f. 0 0 0)
245 :mass 0 :color ColorRGBA/Green)
246 finger (box 0.5 0.2 0.2 :position (Vector3f. 2.4 0 0)
247 :mass 1 :color ColorRGBA/Red)
248 connection-point (Vector3f. 1.2 0 0)
249 root (nodify [hand finger])]
250
251 (join-at-point hand finger (Vector3f. 1.2 0 0))
252
253 (.setCollisionGroup
254 (.getControl hand RigidBodyControl)
255 PhysicsCollisionObject/COLLISION_GROUP_NONE)
256 (world
257 root
258 standard-debug-controls
259 (fn [world]
260 (enable-debug world)
261 (.setTimer world (com.aurellem.capture.RatchetTimer. 60))
262 (set-gravity world Vector3f/ZERO)
263 )
264 no-op)))
265
266 (defn proprioception-debug-window
267 []
268 (let [vi (view-image)]
269 (fn [prop-data]
270 (dorun
271 (map
272 (comp
273 println-repl
274 (fn [[p y r]]
275 (format
276 "pitch: %1.2f\nyaw: %1.2f\nroll: %1.2f\n"
277 p y r)))
278 prop-data)))))
279
280
281
282
283
228 (defn test-proprioception 284 (defn test-proprioception
229 "Testing proprioception: 285 "Testing proprioception:
230 You should see two foating bars, and a printout of pitch, yaw, and 286 You should see two foating bars, and a printout of pitch, yaw, and
231 roll. Pressing key-r/key-t should move the blue bar up and down and 287 roll. Pressing key-r/key-t should move the blue bar up and down and
232 change only the value of pitch. key-f/key-g moves it side to side 288 change only the value of pitch. key-f/key-g moves it side to side
234 and counterclockwise, and only affect roll." 290 and counterclockwise, and only affect roll."
235 [] 291 []
236 (let [hand (box 1 0.2 0.2 :position (Vector3f. 0 2 0) 292 (let [hand (box 1 0.2 0.2 :position (Vector3f. 0 2 0)
237 :mass 0 :color ColorRGBA/Green) 293 :mass 0 :color ColorRGBA/Green)
238 finger (box 1 0.2 0.2 :position (Vector3f. 2.4 2 0) 294 finger (box 1 0.2 0.2 :position (Vector3f. 2.4 2 0)
239 :mass 1 :color (ColorRGBA. 0.20 0.40 0.99 1.0)) 295 :mass 1 :color ColorRGBA/Red)
240 floor (box 10 0.5 10 :position (Vector3f. 0 -5 0) 296 floor (box 10 0.5 10 :position (Vector3f. 0 -5 0)
241 :mass 0 :color ColorRGBA/Gray) 297 :mass 0 :color ColorRGBA/Gray)
242 298
243 move-up? (atom false) 299 move-up? (atom false)
244 move-down? (atom false) 300 move-down? (atom false)
245 move-left? (atom false) 301 move-left? (atom false)
246 move-right? (atom false) 302 move-right? (atom false)
247 roll-left? (atom false) 303 roll-left? (atom false)
248 roll-right? (atom false) 304 roll-right? (atom false)
249 control (.getControl finger RigidBodyControl) 305 control (.getControl finger RigidBodyControl)
250 joint 306 time (atom 0)
251 (doto 307 joint (join-at-point hand finger (Vector3f. 1.2 2 0 ))
252 (Point2PointJoint. 308 creature (nodify [hand finger])
253 (.getControl hand RigidBodyControl) 309 prop (proprioception creature)
254 control 310
255 (Vector3f. 1.2 0 0) 311 prop-view (proprioception-debug-window)
256 (Vector3f. -1.2 0 0 )) 312
257 (.setCollisionBetweenLinkedBodys false)) 313
258 time (atom 0)] 314 ]
315
316
317
318 (.setCollisionGroup
319 (.getControl hand RigidBodyControl)
320 PhysicsCollisionObject/COLLISION_GROUP_NONE)
321
322
259 (world 323 (world
260 (nodify [hand finger floor]) 324 (nodify [hand finger floor])
261 (merge standard-debug-controls 325 (merge standard-debug-controls
262 {"key-r" (fn [_ pressed?] (reset! move-up? pressed?)) 326 {"key-r" (fn [_ pressed?] (reset! move-up? pressed?))
263 "key-t" (fn [_ pressed?] (reset! move-down? pressed?)) 327 "key-t" (fn [_ pressed?] (reset! move-down? pressed?))
264 "key-f" (fn [_ pressed?] (reset! move-left? pressed?)) 328 "key-f" (fn [_ pressed?] (reset! move-left? pressed?))
265 "key-g" (fn [_ pressed?] (reset! move-right? pressed?)) 329 "key-g" (fn [_ pressed?] (reset! move-right? pressed?))
266 "key-v" (fn [_ pressed?] (reset! roll-left? pressed?)) 330 "key-v" (fn [_ pressed?] (reset! roll-left? pressed?))
267 "key-b" (fn [_ pressed?] (reset! roll-right? pressed?))}) 331 "key-b" (fn [_ pressed?] (reset! roll-right? pressed?))})
268 (fn [world] 332 (fn [world]
269 (.setTimer world (NanoTimer.)) 333 (.setTimer world (com.aurellem.capture.RatchetTimer. 60))
270 (set-gravity world (Vector3f. 0 0 0)) 334 (set-gravity world (Vector3f. 0 0 0))
271 (.setMoveSpeed (.getFlyByCamera world) 50)
272 (.setRotationSpeed (.getFlyByCamera world) 50)
273 (light-up-everything world)) 335 (light-up-everything world))
274 (fn [_ _] 336 (fn [_ _]
275 (if @move-up? 337 (if @move-up?
276 (.applyTorque control 338 (.applyTorque control
277 (.mult (.getPhysicsRotation control) 339 (.mult (.getPhysicsRotation control)
295 (if @roll-right? 357 (if @roll-right?
296 (.applyTorque control 358 (.applyTorque control
297 (.mult (.getPhysicsRotation control) 359 (.mult (.getPhysicsRotation control)
298 (Vector3f. 1 0 0)))) 360 (Vector3f. 1 0 0))))
299 361
300 (if (= 0 (rem (swap! time inc) 2000)) 362 (if (= 0 (rem (swap! time inc) 20))
301 (do 363 (prop-view
302 (apply 364 (joint-proprioception joint)))))))
303 (comp 365
304 println-repl 366
305 #(format "pitch: %1.2f\nyaw: %1.2f\nroll: %1.2f\n" %1 %2 %3))
306 (joint-proprioception joint))))))))
307 #+end_src 367 #+end_src
368
369 #+results: test-body
370 : #'cortex.test.body/test-proprioception
308 371
309 372
310 * COMMENT code-limbo 373 * COMMENT code-limbo
311 #+begin_src clojure 374 #+begin_src clojure
312 ;;(.loadModel 375 ;;(.loadModel