comparison org/integration.org @ 296:1eed471e2ebf

first version of a mini motor-control script language
author Robert McIntyre <rlm@mit.edu>
date Thu, 16 Feb 2012 11:04:22 -0700
parents 67a4e92d4628
children d1206b11ae2d
comparison
equal deleted inserted replaced
295:67a4e92d4628 296:1eed471e2ebf
29 29
30 (def hand "Models/test-creature/hand.blend") 30 (def hand "Models/test-creature/hand.blend")
31 31
32 (def output-base (File. "/home/r/proj/cortex/render/hand")) 32 (def output-base (File. "/home/r/proj/cortex/render/hand"))
33 33
34 (defn motor-control-program
35 "Create a function which will execute the motor script"
36 [muscle-positions
37 script]
38 (let [current-frame (atom -1)
39 keyed-script (group-by first script)
40 current-forces (atom {}) ]
41 (fn [effectors]
42 (let [indexed-effectors (vec effectors)]
43 (dorun
44 (for [[_ part force] (keyed-script (swap! current-frame inc))]
45 (swap! current-forces (fn [m] (assoc m part force)))))
46 (doall (map (fn [effector power]
47 (effector (int power)))
48 effectors
49 (map #(@current-forces % 0) muscle-positions)))))))
50
51 (def muscle-positions
52 [:pointer-2-e
53 :pointer-2-f
54 :thumb-1
55 :thumb-1
56 :pointer-1-e
57 :pointer-1-f
58 :thumb-2-e
59 :thumb-2-f
60 :middle-1-e
61 :middle-1-f
62 :pointer-3-f
63 :pointer-3-e
64 :middle-2-e
65 :middle-2-f
66 :middle-3-f
67 :middle-3-e
68 :pinky-2-e
69 :pinky-2-f
70 :pinky-3-f
71 :pinky-3-e
72 :ring-3-e
73 :ring-3-f
74 :ring-2-f
75 :ring-2-e
76 :ring-1-e
77 :ring-1-f
78 :thumb-1-e
79 :thumb-1-f
80 :pinky-1-f
81 :pinky-1-e])
82
83 (def full 9001)
84 ;; the systax here is [keyframe body-part force]
85 (def wiggle-each-finger-tip
86 [[200 :pointer-3-f full]
87 [200 :pointer-3-f 40]
88
89 [400 :middle-3-f full]
90 [401 :middle-3-f 40]
91
92 [600 :ring-3-f full]
93 [601 :ring-3-f 40]
94
95 [800 :pinky-3-f full]
96 [801 :pinky-3-f 40]])
97
98
99
100
34 (def control-list 101 (def control-list
35 [ 102 [
36 0 ;;pointer-21 #<Vector3f (0.99999994, 0.0, 0.0)> 103 0 ;;pointer-21 #<Vector3f (0.99999994, 0.0, 0.0)>
37 1 ;;pointer-21 #<Vector3f (-0.99999994, 0.0, 0.0)> 104 0 ;;pointer-21 #<Vector3f (-0.99999994, 0.0, 0.0)>
38 0 ;;thumb-11 #<Vector3f (-0.8802276, -0.39781287, -0.25873658)> 105 0 ;;thumb-11 #<Vector3f (-0.8802276, -0.39781287, -0.25873658)>
39 0 ;;thumb-11 #<Vector3f (0.8485723, 0.46149826, 0.2587364)> 106 0 ;;thumb-11 #<Vector3f (0.8485723, 0.46149826, 0.2587364)>
40 0 ;;pointer-11 #<Vector3f (0.99999994, 0.0, 0.0)> 107 0 ;;pointer-11 #<Vector3f (0.99999994, 0.0, 0.0)>
41 0 ;;pointer-11 #<Vector3f (-0.99999994, 0.0, 0.0)> 108 0 ;;pointer-11 #<Vector3f (-0.99999994, 0.0, 0.0)>
42 0 ;;thumb-2.0011 #<Vector3f (-0.71705645, -0.44753736, -0.5343599)> 109 0 ;;thumb-2.0011 #<Vector3f (-0.71705645, -0.44753736, -0.5343599)>
43 0 ;;thumb-2.0011 #<Vector3f (-0.10567085, 0.83862597, 0.53435963)> 110 0 ;;thumb-2.0011 #<Vector3f (-0.10567085, 0.83862597, 0.53435963)>
44 0 ;;middle-11 #<Vector3f (0.99999994, 0.0, 0.0)> 111 0 ;;middle-11 #<Vector3f (0.99999994, 0.0, 0.0)>
45 0 ;;middle-11 #<Vector3f (-0.99999994, 0.0, 0.0)> 112 0 ;;middle-11 #<Vector3f (-0.99999994, 0.0, 0.0)>
46 0 ;;pointer-31 #<Vector3f (-0.99999994, 0.0, 0.0)> 113 1 ;;pointer-31 #<Vector3f (-0.99999994, 0.0, 0.0)>
47 0 ;;pointer-31 #<Vector3f (0.99999994, 0.0, 0.0)> 114 0 ;;pointer-31 #<Vector3f (0.99999994, 0.0, 0.0)>
48 0 ;;middle-21 #<Vector3f (0.99999994, 0.0, 0.0)> 115 0 ;;middle-21 #<Vector3f (0.99999994, 0.0, 0.0)>
49 0 ;;middle-21 #<Vector3f (-0.99999994, 0.0, 0.0)> 116 0 ;;middle-21 #<Vector3f (-0.99999994, 0.0, 0.0)>
50 0 ;;middle-31 #<Vector3f (-0.99999994, 0.0, 0.0)> 117 0 ;;middle-31 #<Vector3f (-0.99999994, 0.0, 0.0)>
51 0 ;;middle-31 #<Vector3f (0.99999994, 0.0, 0.0)> 118 0 ;;middle-31 #<Vector3f (0.99999994, 0.0, 0.0)>
52 0 ;;pinky-21 #<Vector3f (0.99999994, 0.0, 0.0)> 119 0 ;;pinky-21 #<Vector3f (0.99999994, 0.0, 0.0)>
53 0 ;;pinky-21 #<Vector3f (-0.99999994, 0.0, 0.0)> 120 0 ;;pinky-21 #<Vector3f (-0.99999994, 0.0, 0.0)>
54 0 ;;pinky-31 #<Vector3f (0.99999994, 0.0, 0.0)> 121 0 ;;pinky-31 #<Vector3f (-1, 0.0, 0.0)>
122 0 ;;pinky-31 #<Vector3f (1.0, 0.0, 0.0)>
55 0 ;;ring-31 #<Vector3f (0.99999994, 0.0, 0.0)> 123 0 ;;ring-31 #<Vector3f (0.99999994, 0.0, 0.0)>
56 0 ;;ring-31 #<Vector3f (-0.99999994, 0.0, 0.0)> 124 0 ;;ring-31 #<Vector3f (-0.99999994, 0.0, 0.0)>
57 0 ;;ring-21 #<Vector3f (-0.99999994, 0.0, 0.0)> 125 0 ;;ring-21 #<Vector3f (-0.99999994, 0.0, 0.0)>
58 0 ;;ring-21 #<Vector3f (0.99999994, 0.0, 0.0)> 126 0 ;;ring-21 #<Vector3f (0.99999994, 0.0, 0.0)>
59 0 ;;ring-11 #<Vector3f (0.99999994, 0.0, 0.0)> 127 0 ;;ring-11 #<Vector3f (0.99999994, 0.0, 0.0)>
85 ;;hearing-display (view-hearing) 153 ;;hearing-display (view-hearing)
86 154
87 prop (proprioception! creature) 155 prop (proprioception! creature)
88 prop-display (view-proprioception) 156 prop-display (view-proprioception)
89 157
90 muscle-exertion (atom 0) 158 control-script (motor-control-program
159 muscle-positions wiggle-each-finger-tip)
91 muscles (movement! creature) 160 muscles (movement! creature)
92 muscle-display (view-movement) 161 muscle-display (view-movement)
93 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 162 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
94 163
95 fix-display (gen-fix-display)] 164 fix-display (gen-fix-display)]
100 me]) 169 me])
101 (merge standard-debug-controls 170 (merge standard-debug-controls
102 {"key-return" 171 {"key-return"
103 (fn [_ value] 172 (fn [_ value]
104 (if value 173 (if value
105 (.play bell))) 174 (.play bell)))})
106 "key-h" 175
107 (fn [_ value]
108 (if value
109 (swap! muscle-exertion (partial + 20))))
110 "key-n"
111 (fn [_ value]
112 (if value
113 (swap! muscle-exertion (fn [v] (- v 20)))))})
114 (fn [world] 176 (fn [world]
115 (.setTimer world (RatchetTimer. 60)) 177 (.setTimer world (RatchetTimer. 60))
116 (light-up-everything world) 178 (light-up-everything world)
117 (enable-debug world) 179 (enable-debug world)
118 (add-camera! world 180 (add-camera! world
125 ;;(prop-display (prop)) 187 ;;(prop-display (prop))
126 ;;(touch-display (map #(% (.getRootNode world)) touch)) 188 ;;(touch-display (map #(% (.getRootNode world)) touch))
127 ;;(vision-display (map #(% world) vision)) 189 ;;(vision-display (map #(% world) vision))
128 ;;(hearing-display (map #(% world) hearing)) 190 ;;(hearing-display (map #(% world) hearing))
129 191
130 (muscle-display 192 ;;(muscle-display
131 (map (fn [effector control] 193 (control-script muscles)
132 (effector (int (* @muscle-exertion control)))) 194 ;;)
133 muscles
134 control-list))
135 195
136 (.setLocalTranslation me (.getLocation (.getCamera world))) 196 (.setLocalTranslation me (.getLocation (.getCamera world)))
137 (fix-display world)))))) 197 (fix-display world))))))
138 #+end_src 198 #+end_src
139 199