comparison org/worm_learn.clj @ 413:54ef2e06c3ef

gave main worm a consistent muscle order.
author Robert McIntyre <rlm@mit.edu>
date Wed, 19 Mar 2014 14:24:13 -0400
parents a331d5ff73e0
children 634795361af8
comparison
equal deleted inserted replaced
412:cc9957241076 413:54ef2e06c3ef
8 (:import java.io.File) 8 (:import java.io.File)
9 (:import com.jme3.audio.AudioNode) 9 (:import com.jme3.audio.AudioNode)
10 (:import com.aurellem.capture.RatchetTimer) 10 (:import com.aurellem.capture.RatchetTimer)
11 (:import (com.aurellem.capture Capture IsoTimer)) 11 (:import (com.aurellem.capture Capture IsoTimer))
12 (:import (com.jme3.math Vector3f ColorRGBA))) 12 (:import (com.jme3.math Vector3f ColorRGBA)))
13
14 (import org.apache.commons.math3.transform.TransformType)
15 (import org.apache.commons.math3.transform.FastFourierTransformer)
16 (import org.apache.commons.math3.transform.DftNormalization)
13 17
14 (use 'clojure.pprint) 18 (use 'clojure.pprint)
15 (use 'clojure.set) 19 (use 'clojure.set)
16 (dorun (cortex.import/mega-import-jme3)) 20 (dorun (cortex.import/mega-import-jme3))
17 (rlm.rlm-commands/help) 21 (rlm.rlm-commands/help)
56 activators 60 activators
57 (map activator (range (count muscle-labels))) 61 (map activator (range (count muscle-labels)))
58 worm-keys 62 worm-keys
59 ["key-f" "key-r" 63 ["key-f" "key-r"
60 "key-g" "key-t" 64 "key-g" "key-t"
61 "key-y" "key-h" 65 "key-h" "key-y"
62 "key-j" "key-u" 66 "key-j" "key-u"
63 "key-i" "key-k" 67 "key-k" "key-i"
64 "key-o" "key-l"]] 68 "key-l" "key-o"]]
65 {:motor-control 69 {:motor-control
66 (fn [effectors] 70 (fn [effectors]
67 (doall 71 (doall
68 (map (fn [strength effector] 72 (map (fn [strength effector]
69 (effector (deref strength))) 73 (effector (deref strength)))
81 [600 :d-up 0]]) 85 [600 :d-up 0]])
82 86
83 (def period 18) 87 (def period 18)
84 88
85 (def worm-muscle-labels 89 (def worm-muscle-labels
86 [:base-up :base-down 90 [:base-down :base-up
87 :a-down :a-up 91 :a-down :a-up
88 :b-up :b-down 92 :b-down :b-up
89 :c-down :c-up 93 :c-down :c-up
90 :d-up :d-down]) 94 :d-down :d-up])
91 95
92 (defn gen-wiggle [[flexor extensor :as muscle-pair] time-base] 96 (defn gen-wiggle [[flexor extensor :as muscle-pair] time-base]
93 (let [period period 97 (let [period period
94 power 45] 98 power 45]
95 [[time-base flexor power] 99 [[time-base flexor power]
164 (average) 168 (average)
165 (* 10) 169 (* 10)
166 (- 1) 170 (- 1)
167 (Math/abs))) 171 (Math/abs)))
168 172
173 (defn fft [nums]
174 (.transform
175 (FastFourierTransformer. DftNormalization/UNITARY)
176 (double-array nums) TransformType/FORWARD))
177
178 (def indexed (partial map-indexed vector))
179
169 (defn wiggling? 180 (defn wiggling?
170 "Is the worm wiggling?" 181 "Is the worm wiggling?"
171 [experiences] 182 [experiences]
172 (vector:last-n experiences 200) 183 (map (comp first :muscle) (vector:last-n experiences 200))
173 184
174 ) 185 )
175 186
176 (def standard-world-view 187 (def standard-world-view
177 [(Vector3f. 4.207176, -3.7366982, 3.0816958) 188 [(Vector3f. 4.207176, -3.7366982, 3.0816958)