Mercurial > cortex
diff org/worm_learn.clj @ 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 | 939bcc5950b2 |
line wrap: on
line diff
1.1 --- a/org/worm_learn.clj Tue Mar 04 23:04:43 2014 -0500 1.2 +++ b/org/worm_learn.clj Sun Mar 16 23:30:32 2014 -0400 1.3 @@ -14,13 +14,14 @@ 1.4 (dorun (cortex.import/mega-import-jme3)) 1.5 (rlm.rlm-commands/help) 1.6 1.7 +(load-bullet) 1.8 1.9 (def hand "Models/test-creature/hand.blend") 1.10 1.11 (defn worm-model [] 1.12 (load-blender-model "Models/worm/worm.blend")) 1.13 1.14 -(def output-base (File. "/home/r/proj/cortex/render/worm-learn/")) 1.15 +(def output-base (File. "/home/r/proj/cortex/render/worm-learn/curl")) 1.16 1.17 1.18 (defn motor-control-program 1.19 @@ -40,19 +41,25 @@ 1.20 effectors 1.21 (map #(@current-forces % 0) muscle-positions))))))) 1.22 1.23 + 1.24 + 1.25 + 1.26 +;; These are scripts that direct the worm to move in two radically 1.27 +;; different patterns -- a sinusoidal wiggling motion, and a curling 1.28 +;; motions that causes the worm to form a circle. 1.29 + 1.30 +(def curl-script 1.31 + [[370 :d-up 40] 1.32 + [600 :d-up 0]]) 1.33 + 1.34 +(def period 18) 1.35 + 1.36 (def muscle-labels 1.37 [:base-up :base-down 1.38 :a-up :a-down 1.39 :b-up :b-down 1.40 :c-up :c-down 1.41 - :d-up :d-down 1.42 - ]) 1.43 - 1.44 -(def curl-script 1.45 - [[370 :d-up 20] 1.46 - [390 :d-up 0]]) 1.47 - 1.48 -(def period 18) 1.49 + :d-up :d-down]) 1.50 1.51 (defn gen-wiggle [[flexor extensor :as muscle-pair] time-base] 1.52 (let [period period 1.53 @@ -63,24 +70,68 @@ 1.54 [(+ time-base (+ (* 2 period) 2)) extensor 0]])) 1.55 1.56 (def wiggle-script 1.57 - (mapcat gen-wiggle [[:d-up :d-down] 1.58 - [:c-up :c-down] 1.59 - [:b-up :b-down] 1.60 - [:a-up :a-down]] (range 100 1000 12))) 1.61 - 1.62 -(def wiggle-script 1.63 (mapcat gen-wiggle (repeat 40 [:a-down :a-up]) 1.64 (range 100 10000 (+ 3 (* period 2))))) 1.65 1.66 1.67 +;; Normally, we'd use unsupervised/supervised machine learning to pick 1.68 +;; out the defining features of the different actions available to the 1.69 +;; worm. For this project, I am going to explicitely define functions 1.70 +;; that recognize curling and wiggling respectively. These functions 1.71 +;; are defined using all the information available from an embodied 1.72 +;; simulation of the action. Note how much easier they are to define 1.73 +;; than if I only had vision to work with. Things like scale/position 1.74 +;; invariance are complete non-issues here. This is the advantage of 1.75 +;; body-centered action recognition and what I hope to show with this 1.76 +;; thesis. 1.77 + 1.78 +(defn last-nth 1.79 + "Create function that will, when called each frame with the senses 1.80 + of a creature, will record those results and return the last n 1.81 + results." 1.82 + [n] 1.83 + (let [last-n '()] 1.84 + (fn [frame-num {:keys [touch proprioception muscles hearing]}] 1.85 + (take n (cons [frame-num :stuff] last-n))))) 1.86 + 1.87 + 1.88 +(defn wiggling? 1.89 + "Generate a function which, when called each frame with the sensory 1.90 + inputs of a worm, will determine whether the worm is wiggling." 1.91 + [{:keys [touch proprioception muscles hearing]}] 1.92 + (map (fn [f] (f)) proprioception 1.93 + 1.94 + 1.95 +)) 1.96 + 1.97 +(defn curling? 1.98 + "Is the worm curled up?" 1.99 + [] 1.100 + ) 1.101 + 1.102 +(defn resting? 1.103 + "Is the worm on the ground in a neutral position?" 1.104 + []) 1.105 + 1.106 +(def standard-world-view 1.107 + [(Vector3f. 4.207176, -3.7366982, 3.0816958) 1.108 + (Quaternion. 0.11118768, 0.87678415, 0.24434438, -0.3989771)]) 1.109 + 1.110 +(def worm-side-view 1.111 + [(Vector3f. 4.207176, -3.7366982, 3.0816958) 1.112 + (Quaternion. -0.11555642, 0.88188726, -0.2854942, -0.3569518)]) 1.113 + 1.114 +(def degenerate-worm-view 1.115 + [(Vector3f. -0.0708936, -8.570261, 2.6487997) 1.116 + (Quaternion. -2.318909E-4, 0.9985348, 0.053941682, 0.004291452)]) 1.117 1.118 (defn worm-world 1.119 "" 1.120 ([] (worm-world curl-script)) 1.121 ([motion-script] 1.122 - (let [record? false 1.123 + (let [record? false ;;true 1.124 worm (doto (worm-model) (body!)) 1.125 - touch '();;(touch! worm) 1.126 + touch (touch! worm) 1.127 prop (proprioception! worm) 1.128 muscles (movement! worm) 1.129 1.130 @@ -99,19 +150,7 @@ 1.131 1.132 (fn [world] 1.133 ;; (set-gravity world Vector3f/ZERO) 1.134 - ;; (position-camera 1.135 - ;; world (Vector3f. 4.207176, -3.7366982, 3.0816958) 1.136 - ;; (Quaternion. 0.11118768, 0.87678415, 0.24434438, -0.3989771)) 1.137 - 1.138 - 1.139 - 1.140 - (position-camera 1.141 - world (Vector3f. 4.207176, -3.7366982, 3.0816958) 1.142 - (Quaternion. -0.11555642, 0.88188726, -0.2854942, -0.3569518)) 1.143 - 1.144 - 1.145 - 1.146 - 1.147 + (position-camera world degenerate-worm-view) 1.148 (let [timer (IsoTimer. 60)] 1.149 (.setTimer world timer) 1.150 (display-dilated-time world timer)) 1.151 @@ -121,7 +160,6 @@ 1.152 (File. output-base "main-view"))) 1.153 (speed-up world) 1.154 (light-up-everything world)) 1.155 - 1.156 (fn [world tpf] 1.157 (muscle-display 1.158 (control-script muscles)