Mercurial > cortex
comparison org/movement.org @ 261:2fdcbe8185b1
first draft of movement.org complete
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Tue, 14 Feb 2012 04:35:40 -0700 |
parents | 959127e21f81 |
children | d487348c461c |
comparison
equal
deleted
inserted
replaced
260:959127e21f81 | 261:2fdcbe8185b1 |
---|---|
57 In blender, each muscle is an empty node whose top level parent is | 57 In blender, each muscle is an empty node whose top level parent is |
58 named "muscles", just like eyes, ears, and joints. | 58 named "muscles", just like eyes, ears, and joints. |
59 | 59 |
60 These functions define the expected meta-data for a muscle node. | 60 These functions define the expected meta-data for a muscle node. |
61 | 61 |
62 #+name: movement | 62 #+name: muscle-meta-data |
63 #+begin_src clojure | 63 #+begin_src clojure |
64 (in-ns 'cortex.movement) | 64 (in-ns 'cortex.movement) |
65 | 65 |
66 (defvar | 66 (defvar |
67 ^{:arglists '([creature])} | 67 ^{:arglists '([creature])} |
99 image in a way that allows me to use gradients between white and red, | 99 image in a way that allows me to use gradients between white and red, |
100 instead of shades of gray as I've been using for all the other | 100 instead of shades of gray as I've been using for all the other |
101 senses. This is purely an aesthetic touch. | 101 senses. This is purely an aesthetic touch. |
102 | 102 |
103 * Creating Muscles | 103 * Creating Muscles |
104 #+begin_src clojure | 104 #+name: muscle-kernel |
105 #+begin_src clojure | |
106 (in-ns 'cortex.movement) | |
107 | |
105 (defn movement-kernel | 108 (defn movement-kernel |
106 "Returns a function which when called with a integer value inside a | 109 "Returns a function which when called with a integer value inside a |
107 running simulation will cause movement in the creature according | 110 running simulation will cause movement in the creature according |
108 to the muscle's position and strength profile. Each function | 111 to the muscle's position and strength profile. Each function |
109 returns the amount of force applied / max force." | 112 returns the amount of force applied / max force." |
145 | 148 |
146 * Visualizing Muscle Tension | 149 * Visualizing Muscle Tension |
147 Muscle exertion is a percent of a total, so the visulazation is just a | 150 Muscle exertion is a percent of a total, so the visulazation is just a |
148 simple percent bar. | 151 simple percent bar. |
149 | 152 |
153 #+name: visualization | |
150 #+begin_src clojure | 154 #+begin_src clojure |
151 (defn movement-display-kernel | 155 (defn movement-display-kernel |
152 "Display muscle exertion data as a bar filling up with red." | 156 "Display muscle exertion data as a bar filling up with red." |
153 [exertion] | 157 [exertion] |
154 (let [height 20 | 158 (let [height 20 |
169 (view-sense movement-display-kernel)) | 173 (view-sense movement-display-kernel)) |
170 #+end_src | 174 #+end_src |
171 | 175 |
172 * Adding Touch to the Worm | 176 * Adding Touch to the Worm |
173 | 177 |
178 #+begin_src clojure | |
179 (defn test-movement | |
180 ([] (test-movement false)) | |
181 ([record?] | |
182 (let [creature (doto (worm) (body!)) | |
183 | |
184 muscle-exertion (atom 0) | |
185 muscles (movement! creature) | |
186 muscle-display (view-movement)] | |
187 (.setMass | |
188 (.getControl (.getChild creature "worm-11") RigidBodyControl) | |
189 (float 0)) | |
190 (world | |
191 (nodify [creature (floor)]) | |
192 (merge standard-debug-controls | |
193 {"key-h" | |
194 (fn [_ value] | |
195 (if value | |
196 (swap! muscle-exertion (partial + 20)))) | |
197 "key-n" | |
198 (fn [_ value] | |
199 (if value | |
200 (swap! muscle-exertion (fn [v] (- v 20)))))}) | |
201 (fn [world] | |
202 (if record? | |
203 (Capture/captureVideo | |
204 world | |
205 (File. "/home/r/proj/cortex/render/worm-muscles/main-view"))) | |
206 (light-up-everything world) | |
207 (enable-debug world) | |
208 (.setTimer world (RatchetTimer. 60)) | |
209 (set-gravity world (Vector3f. 0 0 0)) | |
210 (.setLocation (.getCamera world) | |
211 (Vector3f. -4.912815, 2.004171, 0.15710819)) | |
212 (.setRotation (.getCamera world) | |
213 (Quaternion. 0.13828252, 0.65516764, | |
214 -0.12370994, 0.7323449)) | |
215 | |
216 (comment | |
217 (com.aurellem.capture.Capture/captureVideo | |
218 world (file-str "/home/r/proj/ai-videos/hand")))) | |
219 (fn [world tpf] | |
220 (muscle-display | |
221 (map #(% @muscle-exertion) muscles) | |
222 (if record? | |
223 (File. "/home/r/proj/cortex/render/worm-muscles/muscles")))))))) | |
224 #+end_src | |
225 | |
226 * Video Demonstration | |
227 | |
228 #+begin_html | |
229 <div class="figure"> | |
230 <center> | |
231 <video controls="controls" width="550"> | |
232 <source src="../video/worm-muscles.ogg" type="video/ogg" | |
233 preload="none" poster="../images/aurellem-1280x480.png" /> | |
234 </video> | |
235 </center> | |
236 <p>The worm is now able to move. The bar in the lower right displays | |
237 the power output of the muscle . Each jump causes 20 more motor neurons to | |
238 be recruited. Notice that the power output increases non-linearly | |
239 with motror neuron recruitement, similiar to a human muscle.</p> | |
240 </div> | |
241 #+end_html | |
242 | |
243 | |
244 ** Making the Worm Muscles Video | |
245 #+name: magick7 | |
246 #+begin_src clojure | |
247 (ns cortex.video.magick7 | |
248 (:import java.io.File) | |
249 (:use clojure.contrib.shell-out)) | |
250 | |
251 (defn images [path] | |
252 (sort (rest (file-seq (File. path))))) | |
253 | |
254 (def base "/home/r/proj/cortex/render/worm-muscles/") | |
255 | |
256 (defn pics [file] | |
257 (images (str base file))) | |
258 | |
259 (defn combine-images [] | |
260 (let [main-view (pics "main-view") | |
261 muscles (pics "muscles/0") | |
262 targets (map | |
263 #(File. (str base "out/" (format "%07d.png" %))) | |
264 (range 0 (count main-view)))] | |
265 (dorun | |
266 (pmap | |
267 (comp | |
268 (fn [[ main-view muscles target]] | |
269 (println target) | |
270 (sh "convert" | |
271 main-view | |
272 muscles "-geometry" "+320+440" "-composite" | |
273 target)) | |
274 (fn [& args] (map #(.getCanonicalPath %) args))) | |
275 main-view muscles targets)))) | |
276 #+end_src | |
277 | |
278 #+begin_src sh :results silent | |
279 cd ~/proj/cortex/render/worm-muscles | |
280 ffmpeg -r 60 -i out/%07d.png -b:v 9000k -c:v libtheora worm-muscles.ogg | |
281 #+end_src | |
174 | 282 |
175 * Headers | 283 * Headers |
176 #+name: muscle-header | 284 #+name: muscle-header |
177 #+begin_src clojure | 285 #+begin_src clojure |
178 (ns cortex.movement | 286 (ns cortex.movement |
185 (:import com.jme3.scene.Node) | 293 (:import com.jme3.scene.Node) |
186 (:import com.jme3.math.Vector3f) | 294 (:import com.jme3.math.Vector3f) |
187 (:import com.jme3.bullet.control.RigidBodyControl)) | 295 (:import com.jme3.bullet.control.RigidBodyControl)) |
188 #+end_src | 296 #+end_src |
189 | 297 |
190 | 298 #+name: test-header |
299 #+begin_src clojure | |
300 (ns cortex.test.movement | |
301 (:use (cortex world util sense body movement)) | |
302 (:use cortex.test.body) | |
303 (:use clojure.contrib.def) | |
304 (:import java.io.File) | |
305 (:import java.awt.image.BufferedImage) | |
306 (:import com.jme3.scene.Node) | |
307 (:import com.jme3.math.Vector3f) | |
308 (:import (com.aurellem.capture Capture RatchetTimer)) | |
309 (:import com.jme3.bullet.control.RigidBodyControl)) | |
310 | |
311 (cortex.import/mega-import-jme3) | |
312 #+end_src | |
313 | |
314 * Source Listing | |
315 - [[../src/cortex/movement.clj][cortex.movement]] | |
316 - [[../src/cortex/test/movement.clj][cortex.test.movement]] | |
317 - [[../src/cortex/video/magick7.clj][cortex.video.magick7]] | |
318 #+html: <ul> <li> <a href="../org/movement.org">This org file</a> </li> </ul> | |
319 - [[http://hg.bortreb.com ][source-repository]] | |
191 | 320 |
192 * COMMENT code generation | 321 * COMMENT code generation |
193 #+begin_src clojure :tangle ../src/cortex/movement.clj | 322 #+begin_src clojure :tangle ../src/cortex/movement.clj |
194 <<movement>> | 323 <<muscle-header>> |
195 #+end_src | 324 <<muscle-meta-data>> |
325 <<muscle-kernel>> | |
326 <<visualization>> | |
327 #+end_src | |
328 | |
329 #+begin_src clojure :tangle ../src/cortex/test/movement.clj | |
330 <<test-header>> | |
331 <<test-movement>> | |
332 #+end_src | |
333 | |
334 #+begin_src clojure :tangle ../src/cortex/video/magick7.clj | |
335 <<magick7>> | |
336 #+end_src |