Mercurial > cortex
diff org/test-creature.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 | bab47091534e |
children | 2ed7e60d3821 |
line wrap: on
line diff
1.1 --- a/org/test-creature.org Mon Jan 30 00:25:11 2012 -0700 1.2 +++ b/org/test-creature.org Mon Jan 30 05:47:51 2012 -0700 1.3 @@ -321,11 +321,33 @@ 1.4 (defmethod joint-dispatch :point 1.5 [constraints control-a control-b pivot-a pivot-b rotation] 1.6 (println-repl "creating POINT2POINT joint") 1.7 - (Point2PointJoint. 1.8 - control-a 1.9 - control-b 1.10 - pivot-a 1.11 - pivot-b)) 1.12 + ;; bullet's point2point joints are BROKEN, so we must use the 1.13 + ;; generic 6DOF joint instead of an actual Point2Point joint! 1.14 + 1.15 + ;; should be able to do this: 1.16 + (comment 1.17 + (Point2PointJoint. 1.18 + control-a 1.19 + control-b 1.20 + pivot-a 1.21 + pivot-b)) 1.22 + 1.23 + ;; but instead we must do this: 1.24 + (println-repl "substuting 6DOF joint for POINT2POINT joint!") 1.25 + (doto 1.26 + (SixDofJoint. 1.27 + control-a 1.28 + control-b 1.29 + pivot-a 1.30 + pivot-b 1.31 + false) 1.32 + (.setLinearLowerLimit Vector3f/ZERO) 1.33 + (.setLinearUpperLimit Vector3f/ZERO) 1.34 + ;;(.setAngularLowerLimit (Vector3f. 1 1 1)) 1.35 + ;;(.setAngularUpperLimit (Vector3f. 0 0 0)) 1.36 + 1.37 +)) 1.38 + 1.39 1.40 (defmethod joint-dispatch :hinge 1.41 [constraints control-a control-b pivot-a pivot-b rotation] 1.42 @@ -411,6 +433,9 @@ 1.43 joint-rotation)) 1.44 (println-repl "could not find joint meta-data!")))) 1.45 1.46 + 1.47 + 1.48 + 1.49 (defn assemble-creature [#^Node pieces joints] 1.50 (dorun 1.51 (map 1.52 @@ -1015,7 +1040,7 @@ 1.53 (bit-shift-left num 8) 1.54 (bit-shift-left num 16))) 1.55 1.56 -(defn debug-window 1.57 +(defn debug-touch-window 1.58 "creates function that offers a debug view of sensor data" 1.59 [] 1.60 (let [vi (view-image)] 1.61 @@ -1066,8 +1091,49 @@ 1.62 1.63 1.64 1.65 -;; here's how motor-control/ proprioception will work: 1.66 +;; here's how motor-control/ proprioception will work: Each muscle is 1.67 +;; defined by a 1-D array of numbers (the "motor pool") each of which 1.68 +;; represent muscle fibers. A muscle also has a scalar :strength 1.69 +;; factor which determines how strong the muscle as a whole is. 1.70 +;; The effector function for a muscle takes a number < (count 1.71 +;; motor-pool) and that number is said to "activate" all the muscle 1.72 +;; fibers whose index is lower than the number. Each fiber will apply 1.73 +;; force in proportion to its value in the array. Lower values cause 1.74 +;; less force. The lower values can be put at the "beginning" of the 1.75 +;; 1-D array to simulate the layout of actual human muscles, which are 1.76 +;; capable of more percise movements when exerting less force. 1.77 1.78 +;; I don't know how to encode proprioception, so for now, just return 1.79 +;; a function for each joint that returns a triplet of floats which 1.80 +;; represent relative roll, pitch, and yaw. Write display code for 1.81 +;; this though. 1.82 + 1.83 +(defn muscle-fibre-values 1.84 + "Take the first row of the image and return the low-order bytes." 1.85 + [#^BufferedImage image] 1.86 + (let [width (.getWidth image)] 1.87 + (for [x (range width)] 1.88 + (bit-and 1.89 + 0xFF 1.90 + (.getRGB image x 0))))) 1.91 + 1.92 + 1.93 +(defn rad->deg [rad] 1.94 + (* 180 (/ Math/PI) rad)) 1.95 + 1.96 + 1.97 +(defn debug-prop-window 1.98 + "create a debug view for proprioception" 1.99 + [] 1.100 + (let [vi (view-image)] 1.101 + (fn [sensor-data] 1.102 + (println-repl 1.103 + (map 1.104 + (fn [[yaw pitch roll]] 1.105 + [(rad->deg yaw) 1.106 + (rad->deg pitch) 1.107 + (rad->deg roll)]) 1.108 + sensor-data))))) 1.109 1.110 1.111 1.112 @@ -1083,7 +1149,7 @@ 1.113 (box 0.01 0.01 1 :physical? false :color ColorRGBA/Blue) 1.114 creature (blender-creature thing) 1.115 touch-nerves (touch creature) 1.116 - touch-debug-windows (map (fn [_] (debug-window)) touch-nerves) 1.117 + touch-debug-windows (map (fn [_] (debug-touch-window)) touch-nerves) 1.118 [init-vision-fns vision-data] (vision creature) 1.119 vision-debug (map (fn [_] (debug-vision-window)) vision-data) 1.120 me (sphere 0.5 :color ColorRGBA/Blue :physical? false) 1.121 @@ -1092,6 +1158,8 @@ 1.122 hearing-senses) 1.123 bell (AudioNode. (asset-manager) 1.124 "Sounds/pure.wav" false) 1.125 + prop (proprioception creature) 1.126 + prop-debug (debug-prop-window) 1.127 ;; dream 1.128 1.129 ] 1.130 @@ -1131,7 +1199,7 @@ 1.131 ;;(dorun 1.132 ;; (map #(%1 %2) touch-nerves (repeat (.getRootNode world)))) 1.133 1.134 - 1.135 + (prop-debug (prop)) 1.136 1.137 (dorun 1.138 (map #(%1 (%2 (.getRootNode world))) 1.139 @@ -1201,7 +1269,7 @@ 1.140 sim 1.141 (world node 1.142 {"key-space" 1.143 -vvvvvv (fn [_ value] 1.144 + (fn [_ value] 1.145 (if value 1.146 (let [cr (CollisionResults.)] 1.147 (.collideWith node bounds-b cr)