Mercurial > cortex
changeset 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 | bee5145ce463 d487348c461c |
files | assets/Models/test-creature/basic-muscle.png assets/Models/test-creature/worm.blend images/worm-with-muscle.png org/ideas.org org/movement.org |
diffstat | 5 files changed, 144 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
1.1 Binary file assets/Models/test-creature/basic-muscle.png has changed
2.1 Binary file assets/Models/test-creature/worm.blend has changed
3.1 Binary file images/worm-with-muscle.png has changed
4.1 --- a/org/ideas.org Tue Feb 14 03:16:50 2012 -0700 4.2 +++ b/org/ideas.org Tue Feb 14 04:35:40 2012 -0700 4.3 @@ -100,6 +100,7 @@ 4.4 - [ ] show sensor maps in HUD display? -- 4 days 4.5 - [ ] show sensor maps in AWT display? -- 2 days 4.6 - [ ] upgrade to clojure 1.3, replace all defvars with new def 4.7 + - [ ] common video creation code. 4.8 4.9 4.10
5.1 --- a/org/movement.org Tue Feb 14 03:16:50 2012 -0700 5.2 +++ b/org/movement.org Tue Feb 14 04:35:40 2012 -0700 5.3 @@ -59,7 +59,7 @@ 5.4 5.5 These functions define the expected meta-data for a muscle node. 5.6 5.7 -#+name: movement 5.8 +#+name: muscle-meta-data 5.9 #+begin_src clojure 5.10 (in-ns 'cortex.movement) 5.11 5.12 @@ -101,7 +101,10 @@ 5.13 senses. This is purely an aesthetic touch. 5.14 5.15 * Creating Muscles 5.16 +#+name: muscle-kernel 5.17 #+begin_src clojure 5.18 +(in-ns 'cortex.movement) 5.19 + 5.20 (defn movement-kernel 5.21 "Returns a function which when called with a integer value inside a 5.22 running simulation will cause movement in the creature according 5.23 @@ -147,6 +150,7 @@ 5.24 Muscle exertion is a percent of a total, so the visulazation is just a 5.25 simple percent bar. 5.26 5.27 +#+name: visualization 5.28 #+begin_src clojure 5.29 (defn movement-display-kernel 5.30 "Display muscle exertion data as a bar filling up with red." 5.31 @@ -171,6 +175,110 @@ 5.32 5.33 * Adding Touch to the Worm 5.34 5.35 +#+begin_src clojure 5.36 +(defn test-movement 5.37 + ([] (test-movement false)) 5.38 + ([record?] 5.39 + (let [creature (doto (worm) (body!)) 5.40 + 5.41 + muscle-exertion (atom 0) 5.42 + muscles (movement! creature) 5.43 + muscle-display (view-movement)] 5.44 + (.setMass 5.45 + (.getControl (.getChild creature "worm-11") RigidBodyControl) 5.46 + (float 0)) 5.47 + (world 5.48 + (nodify [creature (floor)]) 5.49 + (merge standard-debug-controls 5.50 + {"key-h" 5.51 + (fn [_ value] 5.52 + (if value 5.53 + (swap! muscle-exertion (partial + 20)))) 5.54 + "key-n" 5.55 + (fn [_ value] 5.56 + (if value 5.57 + (swap! muscle-exertion (fn [v] (- v 20)))))}) 5.58 + (fn [world] 5.59 + (if record? 5.60 + (Capture/captureVideo 5.61 + world 5.62 + (File. "/home/r/proj/cortex/render/worm-muscles/main-view"))) 5.63 + (light-up-everything world) 5.64 + (enable-debug world) 5.65 + (.setTimer world (RatchetTimer. 60)) 5.66 + (set-gravity world (Vector3f. 0 0 0)) 5.67 + (.setLocation (.getCamera world) 5.68 + (Vector3f. -4.912815, 2.004171, 0.15710819)) 5.69 + (.setRotation (.getCamera world) 5.70 + (Quaternion. 0.13828252, 0.65516764, 5.71 + -0.12370994, 0.7323449)) 5.72 + 5.73 + (comment 5.74 + (com.aurellem.capture.Capture/captureVideo 5.75 + world (file-str "/home/r/proj/ai-videos/hand")))) 5.76 + (fn [world tpf] 5.77 + (muscle-display 5.78 + (map #(% @muscle-exertion) muscles) 5.79 + (if record? 5.80 + (File. "/home/r/proj/cortex/render/worm-muscles/muscles")))))))) 5.81 +#+end_src 5.82 + 5.83 +* Video Demonstration 5.84 + 5.85 +#+begin_html 5.86 +<div class="figure"> 5.87 +<center> 5.88 +<video controls="controls" width="550"> 5.89 + <source src="../video/worm-muscles.ogg" type="video/ogg" 5.90 + preload="none" poster="../images/aurellem-1280x480.png" /> 5.91 +</video> 5.92 +</center> 5.93 +<p>The worm is now able to move. The bar in the lower right displays 5.94 + the power output of the muscle . Each jump causes 20 more motor neurons to 5.95 + be recruited. Notice that the power output increases non-linearly 5.96 + with motror neuron recruitement, similiar to a human muscle.</p> 5.97 +</div> 5.98 +#+end_html 5.99 + 5.100 + 5.101 +** Making the Worm Muscles Video 5.102 +#+name: magick7 5.103 +#+begin_src clojure 5.104 +(ns cortex.video.magick7 5.105 + (:import java.io.File) 5.106 + (:use clojure.contrib.shell-out)) 5.107 + 5.108 +(defn images [path] 5.109 + (sort (rest (file-seq (File. path))))) 5.110 + 5.111 +(def base "/home/r/proj/cortex/render/worm-muscles/") 5.112 + 5.113 +(defn pics [file] 5.114 + (images (str base file))) 5.115 + 5.116 +(defn combine-images [] 5.117 + (let [main-view (pics "main-view") 5.118 + muscles (pics "muscles/0") 5.119 + targets (map 5.120 + #(File. (str base "out/" (format "%07d.png" %))) 5.121 + (range 0 (count main-view)))] 5.122 + (dorun 5.123 + (pmap 5.124 + (comp 5.125 + (fn [[ main-view muscles target]] 5.126 + (println target) 5.127 + (sh "convert" 5.128 + main-view 5.129 + muscles "-geometry" "+320+440" "-composite" 5.130 + target)) 5.131 + (fn [& args] (map #(.getCanonicalPath %) args))) 5.132 + main-view muscles targets)))) 5.133 +#+end_src 5.134 + 5.135 +#+begin_src sh :results silent 5.136 +cd ~/proj/cortex/render/worm-muscles 5.137 +ffmpeg -r 60 -i out/%07d.png -b:v 9000k -c:v libtheora worm-muscles.ogg 5.138 +#+end_src 5.139 5.140 * Headers 5.141 #+name: muscle-header 5.142 @@ -187,9 +295,42 @@ 5.143 (:import com.jme3.bullet.control.RigidBodyControl)) 5.144 #+end_src 5.145 5.146 +#+name: test-header 5.147 +#+begin_src clojure 5.148 +(ns cortex.test.movement 5.149 + (:use (cortex world util sense body movement)) 5.150 + (:use cortex.test.body) 5.151 + (:use clojure.contrib.def) 5.152 + (:import java.io.File) 5.153 + (:import java.awt.image.BufferedImage) 5.154 + (:import com.jme3.scene.Node) 5.155 + (:import com.jme3.math.Vector3f) 5.156 + (:import (com.aurellem.capture Capture RatchetTimer)) 5.157 + (:import com.jme3.bullet.control.RigidBodyControl)) 5.158 5.159 +(cortex.import/mega-import-jme3) 5.160 +#+end_src 5.161 + 5.162 +* Source Listing 5.163 + - [[../src/cortex/movement.clj][cortex.movement]] 5.164 + - [[../src/cortex/test/movement.clj][cortex.test.movement]] 5.165 + - [[../src/cortex/video/magick7.clj][cortex.video.magick7]] 5.166 +#+html: <ul> <li> <a href="../org/movement.org">This org file</a> </li> </ul> 5.167 + - [[http://hg.bortreb.com ][source-repository]] 5.168 5.169 * COMMENT code generation 5.170 #+begin_src clojure :tangle ../src/cortex/movement.clj 5.171 -<<movement>> 5.172 +<<muscle-header>> 5.173 +<<muscle-meta-data>> 5.174 +<<muscle-kernel>> 5.175 +<<visualization>> 5.176 #+end_src 5.177 + 5.178 +#+begin_src clojure :tangle ../src/cortex/test/movement.clj 5.179 +<<test-header>> 5.180 +<<test-movement>> 5.181 +#+end_src 5.182 + 5.183 +#+begin_src clojure :tangle ../src/cortex/video/magick7.clj 5.184 +<<magick7>> 5.185 +#+end_src