# HG changeset patch # User Robert McIntyre # Date 1395027032 14400 # Node ID 6ba908c1a0a976f050076696391ce41f2bf6a2d9 # Parent 85393ec986dc9c6d50160cd111c2bdc5f543c1c5 on the warpath to the final stretch. diff -r 85393ec986dc -r 6ba908c1a0a9 assets/Models/worm-segment/touch-profile.png Binary file assets/Models/worm-segment/touch-profile.png has changed diff -r 85393ec986dc -r 6ba908c1a0a9 assets/Models/worm-segment/touch-profile.xcf Binary file assets/Models/worm-segment/touch-profile.xcf has changed diff -r 85393ec986dc -r 6ba908c1a0a9 assets/Models/worm-segment/worm-segment.blend Binary file assets/Models/worm-segment/worm-segment.blend has changed diff -r 85393ec986dc -r 6ba908c1a0a9 assets/Models/worm-segment/worm.blend Binary file assets/Models/worm-segment/worm.blend has changed diff -r 85393ec986dc -r 6ba908c1a0a9 assets/Models/worm/basic-muscle.png Binary file assets/Models/worm/basic-muscle.png has changed diff -r 85393ec986dc -r 6ba908c1a0a9 assets/Models/worm/touch-profile.png Binary file assets/Models/worm/touch-profile.png has changed diff -r 85393ec986dc -r 6ba908c1a0a9 assets/Models/worm/touch-profile.xcf Binary file assets/Models/worm/touch-profile.xcf has changed diff -r 85393ec986dc -r 6ba908c1a0a9 assets/Models/worm/worm-segment.blend Binary file assets/Models/worm/worm-segment.blend has changed diff -r 85393ec986dc -r 6ba908c1a0a9 assets/Models/worm/worm.blend Binary file assets/Models/worm/worm.blend has changed diff -r 85393ec986dc -r 6ba908c1a0a9 org/util.org --- a/org/util.org Tue Mar 04 23:04:43 2014 -0500 +++ b/org/util.org Sun Mar 16 23:30:32 2014 -0400 @@ -128,10 +128,13 @@ (defn position-camera "Change the position of the in-world camera." - [world #^Vector3f position #^Quaternion rotation] + ([world #^Vector3f position #^Quaternion rotation] (doto (.getCamera world) (.setLocation position) (.setRotation rotation))) + ([world [position rotation]] + (position-camera world position rotation))) + (defn enable-debug "Turn on debug wireframes for every object in this simulation." @@ -614,7 +617,7 @@ #+end_src -* COMMENT code generation +* code generation #+begin_src clojure :tangle ../src/cortex/import.clj <> #+end_src diff -r 85393ec986dc -r 6ba908c1a0a9 org/worm_learn.clj --- a/org/worm_learn.clj Tue Mar 04 23:04:43 2014 -0500 +++ b/org/worm_learn.clj Sun Mar 16 23:30:32 2014 -0400 @@ -14,13 +14,14 @@ (dorun (cortex.import/mega-import-jme3)) (rlm.rlm-commands/help) +(load-bullet) (def hand "Models/test-creature/hand.blend") (defn worm-model [] (load-blender-model "Models/worm/worm.blend")) -(def output-base (File. "/home/r/proj/cortex/render/worm-learn/")) +(def output-base (File. "/home/r/proj/cortex/render/worm-learn/curl")) (defn motor-control-program @@ -40,19 +41,25 @@ effectors (map #(@current-forces % 0) muscle-positions))))))) + + + +;; These are scripts that direct the worm to move in two radically +;; different patterns -- a sinusoidal wiggling motion, and a curling +;; motions that causes the worm to form a circle. + +(def curl-script + [[370 :d-up 40] + [600 :d-up 0]]) + +(def period 18) + (def muscle-labels [:base-up :base-down :a-up :a-down :b-up :b-down :c-up :c-down - :d-up :d-down - ]) - -(def curl-script - [[370 :d-up 20] - [390 :d-up 0]]) - -(def period 18) + :d-up :d-down]) (defn gen-wiggle [[flexor extensor :as muscle-pair] time-base] (let [period period @@ -63,24 +70,68 @@ [(+ time-base (+ (* 2 period) 2)) extensor 0]])) (def wiggle-script - (mapcat gen-wiggle [[:d-up :d-down] - [:c-up :c-down] - [:b-up :b-down] - [:a-up :a-down]] (range 100 1000 12))) - -(def wiggle-script (mapcat gen-wiggle (repeat 40 [:a-down :a-up]) (range 100 10000 (+ 3 (* period 2))))) +;; Normally, we'd use unsupervised/supervised machine learning to pick +;; out the defining features of the different actions available to the +;; worm. For this project, I am going to explicitely define functions +;; that recognize curling and wiggling respectively. These functions +;; are defined using all the information available from an embodied +;; simulation of the action. Note how much easier they are to define +;; than if I only had vision to work with. Things like scale/position +;; invariance are complete non-issues here. This is the advantage of +;; body-centered action recognition and what I hope to show with this +;; thesis. + +(defn last-nth + "Create function that will, when called each frame with the senses + of a creature, will record those results and return the last n + results." + [n] + (let [last-n '()] + (fn [frame-num {:keys [touch proprioception muscles hearing]}] + (take n (cons [frame-num :stuff] last-n))))) + + +(defn wiggling? + "Generate a function which, when called each frame with the sensory + inputs of a worm, will determine whether the worm is wiggling." + [{:keys [touch proprioception muscles hearing]}] + (map (fn [f] (f)) proprioception + + +)) + +(defn curling? + "Is the worm curled up?" + [] + ) + +(defn resting? + "Is the worm on the ground in a neutral position?" + []) + +(def standard-world-view + [(Vector3f. 4.207176, -3.7366982, 3.0816958) + (Quaternion. 0.11118768, 0.87678415, 0.24434438, -0.3989771)]) + +(def worm-side-view + [(Vector3f. 4.207176, -3.7366982, 3.0816958) + (Quaternion. -0.11555642, 0.88188726, -0.2854942, -0.3569518)]) + +(def degenerate-worm-view + [(Vector3f. -0.0708936, -8.570261, 2.6487997) + (Quaternion. -2.318909E-4, 0.9985348, 0.053941682, 0.004291452)]) (defn worm-world "" ([] (worm-world curl-script)) ([motion-script] - (let [record? false + (let [record? false ;;true worm (doto (worm-model) (body!)) - touch '();;(touch! worm) + touch (touch! worm) prop (proprioception! worm) muscles (movement! worm) @@ -99,19 +150,7 @@ (fn [world] ;; (set-gravity world Vector3f/ZERO) - ;; (position-camera - ;; world (Vector3f. 4.207176, -3.7366982, 3.0816958) - ;; (Quaternion. 0.11118768, 0.87678415, 0.24434438, -0.3989771)) - - - - (position-camera - world (Vector3f. 4.207176, -3.7366982, 3.0816958) - (Quaternion. -0.11555642, 0.88188726, -0.2854942, -0.3569518)) - - - - + (position-camera world degenerate-worm-view) (let [timer (IsoTimer. 60)] (.setTimer world timer) (display-dilated-time world timer)) @@ -121,7 +160,6 @@ (File. output-base "main-view"))) (speed-up world) (light-up-everything world)) - (fn [world tpf] (muscle-display (control-script muscles)