Mercurial > cortex
changeset 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 | bab47091534e |
children | e98850b83c2c |
files | assets/Models/creature1/basic-muscle.png assets/Models/creature1/try-again.blend org/body.org org/test-creature.org |
diffstat | 4 files changed, 161 insertions(+), 30 deletions(-) [+] |
line wrap: on
line diff
1.1 Binary file assets/Models/creature1/basic-muscle.png has changed
2.1 Binary file assets/Models/creature1/try-again.blend has changed
3.1 --- a/org/body.org Mon Jan 30 00:25:11 2012 -0700 3.2 +++ b/org/body.org Mon Jan 30 05:47:51 2012 -0700 3.3 @@ -82,6 +82,7 @@ 3.4 (doto (Quaternion.) 3.5 (.fromRotationMatrix rotate-a))) 3.6 arm-b)] 3.7 + ;;(println-repl (.getName object-a) (.getName object-b)) 3.8 [pitch yaw roll])) 3.9 3.10 (defn proprioception 3.11 @@ -225,6 +226,61 @@ 3.12 (dorun (worm-motor-map 3.13 (worm-pattern @time))))))) 3.14 3.15 + 3.16 +(require 'cortex.silly) 3.17 +(defn join-at-point [obj-a obj-b world-pivot] 3.18 + (cortex.silly/joint-dispatch 3.19 + {:type :point} 3.20 + (.getControl obj-a RigidBodyControl) 3.21 + (.getControl obj-b RigidBodyControl) 3.22 + (cortex.silly/world-to-local obj-a world-pivot) 3.23 + (cortex.silly/world-to-local obj-b world-pivot) 3.24 + nil 3.25 + )) 3.26 + 3.27 + 3.28 + 3.29 +(defn blab-* [] 3.30 + (let [hand (box 0.5 0.2 0.2 :position (Vector3f. 0 0 0) 3.31 + :mass 0 :color ColorRGBA/Green) 3.32 + finger (box 0.5 0.2 0.2 :position (Vector3f. 2.4 0 0) 3.33 + :mass 1 :color ColorRGBA/Red) 3.34 + connection-point (Vector3f. 1.2 0 0) 3.35 + root (nodify [hand finger])] 3.36 + 3.37 + (join-at-point hand finger (Vector3f. 1.2 0 0)) 3.38 + 3.39 + (.setCollisionGroup 3.40 + (.getControl hand RigidBodyControl) 3.41 + PhysicsCollisionObject/COLLISION_GROUP_NONE) 3.42 + (world 3.43 + root 3.44 + standard-debug-controls 3.45 + (fn [world] 3.46 + (enable-debug world) 3.47 + (.setTimer world (com.aurellem.capture.RatchetTimer. 60)) 3.48 + (set-gravity world Vector3f/ZERO) 3.49 + ) 3.50 + no-op))) 3.51 + 3.52 +(defn proprioception-debug-window 3.53 + [] 3.54 + (let [vi (view-image)] 3.55 + (fn [prop-data] 3.56 + (dorun 3.57 + (map 3.58 + (comp 3.59 + println-repl 3.60 + (fn [[p y r]] 3.61 + (format 3.62 + "pitch: %1.2f\nyaw: %1.2f\nroll: %1.2f\n" 3.63 + p y r))) 3.64 + prop-data))))) 3.65 + 3.66 + 3.67 + 3.68 + 3.69 + 3.70 (defn test-proprioception 3.71 "Testing proprioception: 3.72 You should see two foating bars, and a printout of pitch, yaw, and 3.73 @@ -236,7 +292,7 @@ 3.74 (let [hand (box 1 0.2 0.2 :position (Vector3f. 0 2 0) 3.75 :mass 0 :color ColorRGBA/Green) 3.76 finger (box 1 0.2 0.2 :position (Vector3f. 2.4 2 0) 3.77 - :mass 1 :color (ColorRGBA. 0.20 0.40 0.99 1.0)) 3.78 + :mass 1 :color ColorRGBA/Red) 3.79 floor (box 10 0.5 10 :position (Vector3f. 0 -5 0) 3.80 :mass 0 :color ColorRGBA/Gray) 3.81 3.82 @@ -247,15 +303,23 @@ 3.83 roll-left? (atom false) 3.84 roll-right? (atom false) 3.85 control (.getControl finger RigidBodyControl) 3.86 - joint 3.87 - (doto 3.88 - (Point2PointJoint. 3.89 - (.getControl hand RigidBodyControl) 3.90 - control 3.91 - (Vector3f. 1.2 0 0) 3.92 - (Vector3f. -1.2 0 0 )) 3.93 - (.setCollisionBetweenLinkedBodys false)) 3.94 - time (atom 0)] 3.95 + time (atom 0) 3.96 + joint (join-at-point hand finger (Vector3f. 1.2 2 0 )) 3.97 + creature (nodify [hand finger]) 3.98 + prop (proprioception creature) 3.99 + 3.100 + prop-view (proprioception-debug-window) 3.101 + 3.102 + 3.103 + ] 3.104 + 3.105 + 3.106 + 3.107 + (.setCollisionGroup 3.108 + (.getControl hand RigidBodyControl) 3.109 + PhysicsCollisionObject/COLLISION_GROUP_NONE) 3.110 + 3.111 + 3.112 (world 3.113 (nodify [hand finger floor]) 3.114 (merge standard-debug-controls 3.115 @@ -266,10 +330,8 @@ 3.116 "key-v" (fn [_ pressed?] (reset! roll-left? pressed?)) 3.117 "key-b" (fn [_ pressed?] (reset! roll-right? pressed?))}) 3.118 (fn [world] 3.119 - (.setTimer world (NanoTimer.)) 3.120 + (.setTimer world (com.aurellem.capture.RatchetTimer. 60)) 3.121 (set-gravity world (Vector3f. 0 0 0)) 3.122 - (.setMoveSpeed (.getFlyByCamera world) 50) 3.123 - (.setRotationSpeed (.getFlyByCamera world) 50) 3.124 (light-up-everything world)) 3.125 (fn [_ _] 3.126 (if @move-up? 3.127 @@ -297,15 +359,16 @@ 3.128 (.mult (.getPhysicsRotation control) 3.129 (Vector3f. 1 0 0)))) 3.130 3.131 - (if (= 0 (rem (swap! time inc) 2000)) 3.132 - (do 3.133 - (apply 3.134 - (comp 3.135 - println-repl 3.136 - #(format "pitch: %1.2f\nyaw: %1.2f\nroll: %1.2f\n" %1 %2 %3)) 3.137 - (joint-proprioception joint)))))))) 3.138 + (if (= 0 (rem (swap! time inc) 20)) 3.139 + (prop-view 3.140 + (joint-proprioception joint))))))) 3.141 + 3.142 + 3.143 #+end_src 3.144 3.145 +#+results: test-body 3.146 +: #'cortex.test.body/test-proprioception 3.147 + 3.148 3.149 * COMMENT code-limbo 3.150 #+begin_src clojure
4.1 --- a/org/test-creature.org Mon Jan 30 00:25:11 2012 -0700 4.2 +++ b/org/test-creature.org Mon Jan 30 05:47:51 2012 -0700 4.3 @@ -321,11 +321,33 @@ 4.4 (defmethod joint-dispatch :point 4.5 [constraints control-a control-b pivot-a pivot-b rotation] 4.6 (println-repl "creating POINT2POINT joint") 4.7 - (Point2PointJoint. 4.8 - control-a 4.9 - control-b 4.10 - pivot-a 4.11 - pivot-b)) 4.12 + ;; bullet's point2point joints are BROKEN, so we must use the 4.13 + ;; generic 6DOF joint instead of an actual Point2Point joint! 4.14 + 4.15 + ;; should be able to do this: 4.16 + (comment 4.17 + (Point2PointJoint. 4.18 + control-a 4.19 + control-b 4.20 + pivot-a 4.21 + pivot-b)) 4.22 + 4.23 + ;; but instead we must do this: 4.24 + (println-repl "substuting 6DOF joint for POINT2POINT joint!") 4.25 + (doto 4.26 + (SixDofJoint. 4.27 + control-a 4.28 + control-b 4.29 + pivot-a 4.30 + pivot-b 4.31 + false) 4.32 + (.setLinearLowerLimit Vector3f/ZERO) 4.33 + (.setLinearUpperLimit Vector3f/ZERO) 4.34 + ;;(.setAngularLowerLimit (Vector3f. 1 1 1)) 4.35 + ;;(.setAngularUpperLimit (Vector3f. 0 0 0)) 4.36 + 4.37 +)) 4.38 + 4.39 4.40 (defmethod joint-dispatch :hinge 4.41 [constraints control-a control-b pivot-a pivot-b rotation] 4.42 @@ -411,6 +433,9 @@ 4.43 joint-rotation)) 4.44 (println-repl "could not find joint meta-data!")))) 4.45 4.46 + 4.47 + 4.48 + 4.49 (defn assemble-creature [#^Node pieces joints] 4.50 (dorun 4.51 (map 4.52 @@ -1015,7 +1040,7 @@ 4.53 (bit-shift-left num 8) 4.54 (bit-shift-left num 16))) 4.55 4.56 -(defn debug-window 4.57 +(defn debug-touch-window 4.58 "creates function that offers a debug view of sensor data" 4.59 [] 4.60 (let [vi (view-image)] 4.61 @@ -1066,8 +1091,49 @@ 4.62 4.63 4.64 4.65 -;; here's how motor-control/ proprioception will work: 4.66 +;; here's how motor-control/ proprioception will work: Each muscle is 4.67 +;; defined by a 1-D array of numbers (the "motor pool") each of which 4.68 +;; represent muscle fibers. A muscle also has a scalar :strength 4.69 +;; factor which determines how strong the muscle as a whole is. 4.70 +;; The effector function for a muscle takes a number < (count 4.71 +;; motor-pool) and that number is said to "activate" all the muscle 4.72 +;; fibers whose index is lower than the number. Each fiber will apply 4.73 +;; force in proportion to its value in the array. Lower values cause 4.74 +;; less force. The lower values can be put at the "beginning" of the 4.75 +;; 1-D array to simulate the layout of actual human muscles, which are 4.76 +;; capable of more percise movements when exerting less force. 4.77 4.78 +;; I don't know how to encode proprioception, so for now, just return 4.79 +;; a function for each joint that returns a triplet of floats which 4.80 +;; represent relative roll, pitch, and yaw. Write display code for 4.81 +;; this though. 4.82 + 4.83 +(defn muscle-fibre-values 4.84 + "Take the first row of the image and return the low-order bytes." 4.85 + [#^BufferedImage image] 4.86 + (let [width (.getWidth image)] 4.87 + (for [x (range width)] 4.88 + (bit-and 4.89 + 0xFF 4.90 + (.getRGB image x 0))))) 4.91 + 4.92 + 4.93 +(defn rad->deg [rad] 4.94 + (* 180 (/ Math/PI) rad)) 4.95 + 4.96 + 4.97 +(defn debug-prop-window 4.98 + "create a debug view for proprioception" 4.99 + [] 4.100 + (let [vi (view-image)] 4.101 + (fn [sensor-data] 4.102 + (println-repl 4.103 + (map 4.104 + (fn [[yaw pitch roll]] 4.105 + [(rad->deg yaw) 4.106 + (rad->deg pitch) 4.107 + (rad->deg roll)]) 4.108 + sensor-data))))) 4.109 4.110 4.111 4.112 @@ -1083,7 +1149,7 @@ 4.113 (box 0.01 0.01 1 :physical? false :color ColorRGBA/Blue) 4.114 creature (blender-creature thing) 4.115 touch-nerves (touch creature) 4.116 - touch-debug-windows (map (fn [_] (debug-window)) touch-nerves) 4.117 + touch-debug-windows (map (fn [_] (debug-touch-window)) touch-nerves) 4.118 [init-vision-fns vision-data] (vision creature) 4.119 vision-debug (map (fn [_] (debug-vision-window)) vision-data) 4.120 me (sphere 0.5 :color ColorRGBA/Blue :physical? false) 4.121 @@ -1092,6 +1158,8 @@ 4.122 hearing-senses) 4.123 bell (AudioNode. (asset-manager) 4.124 "Sounds/pure.wav" false) 4.125 + prop (proprioception creature) 4.126 + prop-debug (debug-prop-window) 4.127 ;; dream 4.128 4.129 ] 4.130 @@ -1131,7 +1199,7 @@ 4.131 ;;(dorun 4.132 ;; (map #(%1 %2) touch-nerves (repeat (.getRootNode world)))) 4.133 4.134 - 4.135 + (prop-debug (prop)) 4.136 4.137 (dorun 4.138 (map #(%1 (%2 (.getRootNode world))) 4.139 @@ -1201,7 +1269,7 @@ 4.140 sim 4.141 (world node 4.142 {"key-space" 4.143 -vvvvvv (fn [_ value] 4.144 + (fn [_ value] 4.145 (if value 4.146 (let [cr (CollisionResults.)] 4.147 (.collideWith node bounds-b cr)