Mercurial > cortex
changeset 400:6ba908c1a0a9
on the warpath to the final stretch.
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Sun, 16 Mar 2014 23:30:32 -0400 |
parents | 85393ec986dc |
children | 7ee735a836da |
files | assets/Models/worm-segment/touch-profile.png assets/Models/worm-segment/touch-profile.xcf assets/Models/worm-segment/worm-segment.blend assets/Models/worm-segment/worm.blend assets/Models/worm/basic-muscle.png assets/Models/worm/touch-profile.png assets/Models/worm/touch-profile.xcf assets/Models/worm/worm-segment.blend assets/Models/worm/worm.blend org/util.org org/worm_learn.clj |
diffstat | 11 files changed, 74 insertions(+), 33 deletions(-) [+] |
line wrap: on
line diff
1.1 Binary file assets/Models/worm-segment/touch-profile.png has changed
2.1 Binary file assets/Models/worm-segment/touch-profile.xcf has changed
3.1 Binary file assets/Models/worm-segment/worm-segment.blend has changed
4.1 Binary file assets/Models/worm-segment/worm.blend has changed
5.1 Binary file assets/Models/worm/basic-muscle.png has changed
6.1 Binary file assets/Models/worm/touch-profile.png has changed
7.1 Binary file assets/Models/worm/touch-profile.xcf has changed
8.1 Binary file assets/Models/worm/worm-segment.blend has changed
9.1 Binary file assets/Models/worm/worm.blend has changed
10.1 --- a/org/util.org Tue Mar 04 23:04:43 2014 -0500 10.2 +++ b/org/util.org Sun Mar 16 23:30:32 2014 -0400 10.3 @@ -128,10 +128,13 @@ 10.4 10.5 (defn position-camera 10.6 "Change the position of the in-world camera." 10.7 - [world #^Vector3f position #^Quaternion rotation] 10.8 + ([world #^Vector3f position #^Quaternion rotation] 10.9 (doto (.getCamera world) 10.10 (.setLocation position) 10.11 (.setRotation rotation))) 10.12 + ([world [position rotation]] 10.13 + (position-camera world position rotation))) 10.14 + 10.15 10.16 (defn enable-debug 10.17 "Turn on debug wireframes for every object in this simulation." 10.18 @@ -614,7 +617,7 @@ 10.19 #+end_src 10.20 10.21 10.22 -* COMMENT code generation 10.23 +* code generation 10.24 #+begin_src clojure :tangle ../src/cortex/import.clj 10.25 <<import>> 10.26 #+end_src
11.1 --- a/org/worm_learn.clj Tue Mar 04 23:04:43 2014 -0500 11.2 +++ b/org/worm_learn.clj Sun Mar 16 23:30:32 2014 -0400 11.3 @@ -14,13 +14,14 @@ 11.4 (dorun (cortex.import/mega-import-jme3)) 11.5 (rlm.rlm-commands/help) 11.6 11.7 +(load-bullet) 11.8 11.9 (def hand "Models/test-creature/hand.blend") 11.10 11.11 (defn worm-model [] 11.12 (load-blender-model "Models/worm/worm.blend")) 11.13 11.14 -(def output-base (File. "/home/r/proj/cortex/render/worm-learn/")) 11.15 +(def output-base (File. "/home/r/proj/cortex/render/worm-learn/curl")) 11.16 11.17 11.18 (defn motor-control-program 11.19 @@ -40,19 +41,25 @@ 11.20 effectors 11.21 (map #(@current-forces % 0) muscle-positions))))))) 11.22 11.23 + 11.24 + 11.25 + 11.26 +;; These are scripts that direct the worm to move in two radically 11.27 +;; different patterns -- a sinusoidal wiggling motion, and a curling 11.28 +;; motions that causes the worm to form a circle. 11.29 + 11.30 +(def curl-script 11.31 + [[370 :d-up 40] 11.32 + [600 :d-up 0]]) 11.33 + 11.34 +(def period 18) 11.35 + 11.36 (def muscle-labels 11.37 [:base-up :base-down 11.38 :a-up :a-down 11.39 :b-up :b-down 11.40 :c-up :c-down 11.41 - :d-up :d-down 11.42 - ]) 11.43 - 11.44 -(def curl-script 11.45 - [[370 :d-up 20] 11.46 - [390 :d-up 0]]) 11.47 - 11.48 -(def period 18) 11.49 + :d-up :d-down]) 11.50 11.51 (defn gen-wiggle [[flexor extensor :as muscle-pair] time-base] 11.52 (let [period period 11.53 @@ -63,24 +70,68 @@ 11.54 [(+ time-base (+ (* 2 period) 2)) extensor 0]])) 11.55 11.56 (def wiggle-script 11.57 - (mapcat gen-wiggle [[:d-up :d-down] 11.58 - [:c-up :c-down] 11.59 - [:b-up :b-down] 11.60 - [:a-up :a-down]] (range 100 1000 12))) 11.61 - 11.62 -(def wiggle-script 11.63 (mapcat gen-wiggle (repeat 40 [:a-down :a-up]) 11.64 (range 100 10000 (+ 3 (* period 2))))) 11.65 11.66 11.67 +;; Normally, we'd use unsupervised/supervised machine learning to pick 11.68 +;; out the defining features of the different actions available to the 11.69 +;; worm. For this project, I am going to explicitely define functions 11.70 +;; that recognize curling and wiggling respectively. These functions 11.71 +;; are defined using all the information available from an embodied 11.72 +;; simulation of the action. Note how much easier they are to define 11.73 +;; than if I only had vision to work with. Things like scale/position 11.74 +;; invariance are complete non-issues here. This is the advantage of 11.75 +;; body-centered action recognition and what I hope to show with this 11.76 +;; thesis. 11.77 + 11.78 +(defn last-nth 11.79 + "Create function that will, when called each frame with the senses 11.80 + of a creature, will record those results and return the last n 11.81 + results." 11.82 + [n] 11.83 + (let [last-n '()] 11.84 + (fn [frame-num {:keys [touch proprioception muscles hearing]}] 11.85 + (take n (cons [frame-num :stuff] last-n))))) 11.86 + 11.87 + 11.88 +(defn wiggling? 11.89 + "Generate a function which, when called each frame with the sensory 11.90 + inputs of a worm, will determine whether the worm is wiggling." 11.91 + [{:keys [touch proprioception muscles hearing]}] 11.92 + (map (fn [f] (f)) proprioception 11.93 + 11.94 + 11.95 +)) 11.96 + 11.97 +(defn curling? 11.98 + "Is the worm curled up?" 11.99 + [] 11.100 + ) 11.101 + 11.102 +(defn resting? 11.103 + "Is the worm on the ground in a neutral position?" 11.104 + []) 11.105 + 11.106 +(def standard-world-view 11.107 + [(Vector3f. 4.207176, -3.7366982, 3.0816958) 11.108 + (Quaternion. 0.11118768, 0.87678415, 0.24434438, -0.3989771)]) 11.109 + 11.110 +(def worm-side-view 11.111 + [(Vector3f. 4.207176, -3.7366982, 3.0816958) 11.112 + (Quaternion. -0.11555642, 0.88188726, -0.2854942, -0.3569518)]) 11.113 + 11.114 +(def degenerate-worm-view 11.115 + [(Vector3f. -0.0708936, -8.570261, 2.6487997) 11.116 + (Quaternion. -2.318909E-4, 0.9985348, 0.053941682, 0.004291452)]) 11.117 11.118 (defn worm-world 11.119 "" 11.120 ([] (worm-world curl-script)) 11.121 ([motion-script] 11.122 - (let [record? false 11.123 + (let [record? false ;;true 11.124 worm (doto (worm-model) (body!)) 11.125 - touch '();;(touch! worm) 11.126 + touch (touch! worm) 11.127 prop (proprioception! worm) 11.128 muscles (movement! worm) 11.129 11.130 @@ -99,19 +150,7 @@ 11.131 11.132 (fn [world] 11.133 ;; (set-gravity world Vector3f/ZERO) 11.134 - ;; (position-camera 11.135 - ;; world (Vector3f. 4.207176, -3.7366982, 3.0816958) 11.136 - ;; (Quaternion. 0.11118768, 0.87678415, 0.24434438, -0.3989771)) 11.137 - 11.138 - 11.139 - 11.140 - (position-camera 11.141 - world (Vector3f. 4.207176, -3.7366982, 3.0816958) 11.142 - (Quaternion. -0.11555642, 0.88188726, -0.2854942, -0.3569518)) 11.143 - 11.144 - 11.145 - 11.146 - 11.147 + (position-camera world degenerate-worm-view) 11.148 (let [timer (IsoTimer. 60)] 11.149 (.setTimer world timer) 11.150 (display-dilated-time world timer)) 11.151 @@ -121,7 +160,6 @@ 11.152 (File. output-base "main-view"))) 11.153 (speed-up world) 11.154 (light-up-everything world)) 11.155 - 11.156 (fn [world tpf] 11.157 (muscle-display 11.158 (control-script muscles)