Mercurial > cortex
diff 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 |
line wrap: on
line diff
1.1 --- a/org/movement.org Tue Feb 14 03:16:50 2012 -0700 1.2 +++ b/org/movement.org Tue Feb 14 04:35:40 2012 -0700 1.3 @@ -59,7 +59,7 @@ 1.4 1.5 These functions define the expected meta-data for a muscle node. 1.6 1.7 -#+name: movement 1.8 +#+name: muscle-meta-data 1.9 #+begin_src clojure 1.10 (in-ns 'cortex.movement) 1.11 1.12 @@ -101,7 +101,10 @@ 1.13 senses. This is purely an aesthetic touch. 1.14 1.15 * Creating Muscles 1.16 +#+name: muscle-kernel 1.17 #+begin_src clojure 1.18 +(in-ns 'cortex.movement) 1.19 + 1.20 (defn movement-kernel 1.21 "Returns a function which when called with a integer value inside a 1.22 running simulation will cause movement in the creature according 1.23 @@ -147,6 +150,7 @@ 1.24 Muscle exertion is a percent of a total, so the visulazation is just a 1.25 simple percent bar. 1.26 1.27 +#+name: visualization 1.28 #+begin_src clojure 1.29 (defn movement-display-kernel 1.30 "Display muscle exertion data as a bar filling up with red." 1.31 @@ -171,6 +175,110 @@ 1.32 1.33 * Adding Touch to the Worm 1.34 1.35 +#+begin_src clojure 1.36 +(defn test-movement 1.37 + ([] (test-movement false)) 1.38 + ([record?] 1.39 + (let [creature (doto (worm) (body!)) 1.40 + 1.41 + muscle-exertion (atom 0) 1.42 + muscles (movement! creature) 1.43 + muscle-display (view-movement)] 1.44 + (.setMass 1.45 + (.getControl (.getChild creature "worm-11") RigidBodyControl) 1.46 + (float 0)) 1.47 + (world 1.48 + (nodify [creature (floor)]) 1.49 + (merge standard-debug-controls 1.50 + {"key-h" 1.51 + (fn [_ value] 1.52 + (if value 1.53 + (swap! muscle-exertion (partial + 20)))) 1.54 + "key-n" 1.55 + (fn [_ value] 1.56 + (if value 1.57 + (swap! muscle-exertion (fn [v] (- v 20)))))}) 1.58 + (fn [world] 1.59 + (if record? 1.60 + (Capture/captureVideo 1.61 + world 1.62 + (File. "/home/r/proj/cortex/render/worm-muscles/main-view"))) 1.63 + (light-up-everything world) 1.64 + (enable-debug world) 1.65 + (.setTimer world (RatchetTimer. 60)) 1.66 + (set-gravity world (Vector3f. 0 0 0)) 1.67 + (.setLocation (.getCamera world) 1.68 + (Vector3f. -4.912815, 2.004171, 0.15710819)) 1.69 + (.setRotation (.getCamera world) 1.70 + (Quaternion. 0.13828252, 0.65516764, 1.71 + -0.12370994, 0.7323449)) 1.72 + 1.73 + (comment 1.74 + (com.aurellem.capture.Capture/captureVideo 1.75 + world (file-str "/home/r/proj/ai-videos/hand")))) 1.76 + (fn [world tpf] 1.77 + (muscle-display 1.78 + (map #(% @muscle-exertion) muscles) 1.79 + (if record? 1.80 + (File. "/home/r/proj/cortex/render/worm-muscles/muscles")))))))) 1.81 +#+end_src 1.82 + 1.83 +* Video Demonstration 1.84 + 1.85 +#+begin_html 1.86 +<div class="figure"> 1.87 +<center> 1.88 +<video controls="controls" width="550"> 1.89 + <source src="../video/worm-muscles.ogg" type="video/ogg" 1.90 + preload="none" poster="../images/aurellem-1280x480.png" /> 1.91 +</video> 1.92 +</center> 1.93 +<p>The worm is now able to move. The bar in the lower right displays 1.94 + the power output of the muscle . Each jump causes 20 more motor neurons to 1.95 + be recruited. Notice that the power output increases non-linearly 1.96 + with motror neuron recruitement, similiar to a human muscle.</p> 1.97 +</div> 1.98 +#+end_html 1.99 + 1.100 + 1.101 +** Making the Worm Muscles Video 1.102 +#+name: magick7 1.103 +#+begin_src clojure 1.104 +(ns cortex.video.magick7 1.105 + (:import java.io.File) 1.106 + (:use clojure.contrib.shell-out)) 1.107 + 1.108 +(defn images [path] 1.109 + (sort (rest (file-seq (File. path))))) 1.110 + 1.111 +(def base "/home/r/proj/cortex/render/worm-muscles/") 1.112 + 1.113 +(defn pics [file] 1.114 + (images (str base file))) 1.115 + 1.116 +(defn combine-images [] 1.117 + (let [main-view (pics "main-view") 1.118 + muscles (pics "muscles/0") 1.119 + targets (map 1.120 + #(File. (str base "out/" (format "%07d.png" %))) 1.121 + (range 0 (count main-view)))] 1.122 + (dorun 1.123 + (pmap 1.124 + (comp 1.125 + (fn [[ main-view muscles target]] 1.126 + (println target) 1.127 + (sh "convert" 1.128 + main-view 1.129 + muscles "-geometry" "+320+440" "-composite" 1.130 + target)) 1.131 + (fn [& args] (map #(.getCanonicalPath %) args))) 1.132 + main-view muscles targets)))) 1.133 +#+end_src 1.134 + 1.135 +#+begin_src sh :results silent 1.136 +cd ~/proj/cortex/render/worm-muscles 1.137 +ffmpeg -r 60 -i out/%07d.png -b:v 9000k -c:v libtheora worm-muscles.ogg 1.138 +#+end_src 1.139 1.140 * Headers 1.141 #+name: muscle-header 1.142 @@ -187,9 +295,42 @@ 1.143 (:import com.jme3.bullet.control.RigidBodyControl)) 1.144 #+end_src 1.145 1.146 +#+name: test-header 1.147 +#+begin_src clojure 1.148 +(ns cortex.test.movement 1.149 + (:use (cortex world util sense body movement)) 1.150 + (:use cortex.test.body) 1.151 + (:use clojure.contrib.def) 1.152 + (:import java.io.File) 1.153 + (:import java.awt.image.BufferedImage) 1.154 + (:import com.jme3.scene.Node) 1.155 + (:import com.jme3.math.Vector3f) 1.156 + (:import (com.aurellem.capture Capture RatchetTimer)) 1.157 + (:import com.jme3.bullet.control.RigidBodyControl)) 1.158 1.159 +(cortex.import/mega-import-jme3) 1.160 +#+end_src 1.161 + 1.162 +* Source Listing 1.163 + - [[../src/cortex/movement.clj][cortex.movement]] 1.164 + - [[../src/cortex/test/movement.clj][cortex.test.movement]] 1.165 + - [[../src/cortex/video/magick7.clj][cortex.video.magick7]] 1.166 +#+html: <ul> <li> <a href="../org/movement.org">This org file</a> </li> </ul> 1.167 + - [[http://hg.bortreb.com ][source-repository]] 1.168 1.169 * COMMENT code generation 1.170 #+begin_src clojure :tangle ../src/cortex/movement.clj 1.171 -<<movement>> 1.172 +<<muscle-header>> 1.173 +<<muscle-meta-data>> 1.174 +<<muscle-kernel>> 1.175 +<<visualization>> 1.176 #+end_src 1.177 + 1.178 +#+begin_src clojure :tangle ../src/cortex/test/movement.clj 1.179 +<<test-header>> 1.180 +<<test-movement>> 1.181 +#+end_src 1.182 + 1.183 +#+begin_src clojure :tangle ../src/cortex/video/magick7.clj 1.184 +<<magick7>> 1.185 +#+end_src