# HG changeset patch # User Robert McIntyre # Date 1329219340 25200 # Node ID 2fdcbe8185b1a2c30fcece3697f8b629f8f3ec70 # Parent 959127e21f8163c9233ffdb175f61454925a97e4 first draft of movement.org complete diff -r 959127e21f81 -r 2fdcbe8185b1 assets/Models/test-creature/basic-muscle.png Binary file assets/Models/test-creature/basic-muscle.png has changed diff -r 959127e21f81 -r 2fdcbe8185b1 assets/Models/test-creature/worm.blend Binary file assets/Models/test-creature/worm.blend has changed diff -r 959127e21f81 -r 2fdcbe8185b1 images/worm-with-muscle.png Binary file images/worm-with-muscle.png has changed diff -r 959127e21f81 -r 2fdcbe8185b1 org/ideas.org --- a/org/ideas.org Tue Feb 14 03:16:50 2012 -0700 +++ b/org/ideas.org Tue Feb 14 04:35:40 2012 -0700 @@ -100,6 +100,7 @@ - [ ] show sensor maps in HUD display? -- 4 days - [ ] show sensor maps in AWT display? -- 2 days - [ ] upgrade to clojure 1.3, replace all defvars with new def + - [ ] common video creation code. diff -r 959127e21f81 -r 2fdcbe8185b1 org/movement.org --- a/org/movement.org Tue Feb 14 03:16:50 2012 -0700 +++ b/org/movement.org Tue Feb 14 04:35:40 2012 -0700 @@ -59,7 +59,7 @@ These functions define the expected meta-data for a muscle node. -#+name: movement +#+name: muscle-meta-data #+begin_src clojure (in-ns 'cortex.movement) @@ -101,7 +101,10 @@ senses. This is purely an aesthetic touch. * Creating Muscles +#+name: muscle-kernel #+begin_src clojure +(in-ns 'cortex.movement) + (defn movement-kernel "Returns a function which when called with a integer value inside a running simulation will cause movement in the creature according @@ -147,6 +150,7 @@ Muscle exertion is a percent of a total, so the visulazation is just a simple percent bar. +#+name: visualization #+begin_src clojure (defn movement-display-kernel "Display muscle exertion data as a bar filling up with red." @@ -171,6 +175,110 @@ * Adding Touch to the Worm +#+begin_src clojure +(defn test-movement + ([] (test-movement false)) + ([record?] + (let [creature (doto (worm) (body!)) + + muscle-exertion (atom 0) + muscles (movement! creature) + muscle-display (view-movement)] + (.setMass + (.getControl (.getChild creature "worm-11") RigidBodyControl) + (float 0)) + (world + (nodify [creature (floor)]) + (merge standard-debug-controls + {"key-h" + (fn [_ value] + (if value + (swap! muscle-exertion (partial + 20)))) + "key-n" + (fn [_ value] + (if value + (swap! muscle-exertion (fn [v] (- v 20)))))}) + (fn [world] + (if record? + (Capture/captureVideo + world + (File. "/home/r/proj/cortex/render/worm-muscles/main-view"))) + (light-up-everything world) + (enable-debug world) + (.setTimer world (RatchetTimer. 60)) + (set-gravity world (Vector3f. 0 0 0)) + (.setLocation (.getCamera world) + (Vector3f. -4.912815, 2.004171, 0.15710819)) + (.setRotation (.getCamera world) + (Quaternion. 0.13828252, 0.65516764, + -0.12370994, 0.7323449)) + + (comment + (com.aurellem.capture.Capture/captureVideo + world (file-str "/home/r/proj/ai-videos/hand")))) + (fn [world tpf] + (muscle-display + (map #(% @muscle-exertion) muscles) + (if record? + (File. "/home/r/proj/cortex/render/worm-muscles/muscles")))))))) +#+end_src + +* Video Demonstration + +#+begin_html +
+
+ +
+

The worm is now able to move. The bar in the lower right displays + the power output of the muscle . Each jump causes 20 more motor neurons to + be recruited. Notice that the power output increases non-linearly + with motror neuron recruitement, similiar to a human muscle.

+
+#+end_html + + +** Making the Worm Muscles Video +#+name: magick7 +#+begin_src clojure +(ns cortex.video.magick7 + (:import java.io.File) + (:use clojure.contrib.shell-out)) + +(defn images [path] + (sort (rest (file-seq (File. path))))) + +(def base "/home/r/proj/cortex/render/worm-muscles/") + +(defn pics [file] + (images (str base file))) + +(defn combine-images [] + (let [main-view (pics "main-view") + muscles (pics "muscles/0") + targets (map + #(File. (str base "out/" (format "%07d.png" %))) + (range 0 (count main-view)))] + (dorun + (pmap + (comp + (fn [[ main-view muscles target]] + (println target) + (sh "convert" + main-view + muscles "-geometry" "+320+440" "-composite" + target)) + (fn [& args] (map #(.getCanonicalPath %) args))) + main-view muscles targets)))) +#+end_src + +#+begin_src sh :results silent +cd ~/proj/cortex/render/worm-muscles +ffmpeg -r 60 -i out/%07d.png -b:v 9000k -c:v libtheora worm-muscles.ogg +#+end_src * Headers #+name: muscle-header @@ -187,9 +295,42 @@ (:import com.jme3.bullet.control.RigidBodyControl)) #+end_src +#+name: test-header +#+begin_src clojure +(ns cortex.test.movement + (:use (cortex world util sense body movement)) + (:use cortex.test.body) + (:use clojure.contrib.def) + (:import java.io.File) + (:import java.awt.image.BufferedImage) + (:import com.jme3.scene.Node) + (:import com.jme3.math.Vector3f) + (:import (com.aurellem.capture Capture RatchetTimer)) + (:import com.jme3.bullet.control.RigidBodyControl)) +(cortex.import/mega-import-jme3) +#+end_src + +* Source Listing + - [[../src/cortex/movement.clj][cortex.movement]] + - [[../src/cortex/test/movement.clj][cortex.test.movement]] + - [[../src/cortex/video/magick7.clj][cortex.video.magick7]] +#+html: + - [[http://hg.bortreb.com ][source-repository]] * COMMENT code generation #+begin_src clojure :tangle ../src/cortex/movement.clj -<> +<> +<> +<> +<> #+end_src + +#+begin_src clojure :tangle ../src/cortex/test/movement.clj +<> +<> +#+end_src + +#+begin_src clojure :tangle ../src/cortex/video/magick7.clj +<> +#+end_src