comparison org/worm_learn.clj @ 399:85393ec986dc

completed action definitions.
author Robert McIntyre <rlm@mit.edu>
date Tue, 04 Mar 2014 23:04:43 -0500
parents 36d492f4deab
children 6ba908c1a0a9
comparison
equal deleted inserted replaced
398:36d492f4deab 399:85393ec986dc
13 13
14 (dorun (cortex.import/mega-import-jme3)) 14 (dorun (cortex.import/mega-import-jme3))
15 (rlm.rlm-commands/help) 15 (rlm.rlm-commands/help)
16 16
17 17
18 (defn worm-segment [] 18 (def hand "Models/test-creature/hand.blend")
19 (load-blender-model "Models/worm-segment/worm-segment.blend")) 19
20 (defn worm-model []
21 (load-blender-model "Models/worm/worm.blend"))
22
23 (def output-base (File. "/home/r/proj/cortex/render/worm-learn/"))
20 24
21 25
22 (defn worm [] 26 (defn motor-control-program
23 (load-blender-model "Models/worm-segment/worm.blend")) 27 "Create a function which will execute the motor script"
28 [muscle-positions
29 script]
30 (let [current-frame (atom -1)
31 keyed-script (group-by first script)
32 current-forces (atom {}) ]
33 (fn [effectors]
34 (let [indexed-effectors (vec effectors)]
35 (dorun
36 (for [[_ part force] (keyed-script (swap! current-frame inc))]
37 (swap! current-forces (fn [m] (assoc m part force)))))
38 (doall (map (fn [effector power]
39 (effector (int power)))
40 effectors
41 (map #(@current-forces % 0) muscle-positions)))))))
42
43 (def muscle-labels
44 [:base-up :base-down
45 :a-up :a-down
46 :b-up :b-down
47 :c-up :c-down
48 :d-up :d-down
49 ])
50
51 (def curl-script
52 [[370 :d-up 20]
53 [390 :d-up 0]])
54
55 (def period 18)
56
57 (defn gen-wiggle [[flexor extensor :as muscle-pair] time-base]
58 (let [period period
59 power 45]
60 [[time-base flexor power]
61 [(+ time-base period) flexor 0]
62 [(+ time-base period 1) extensor power]
63 [(+ time-base (+ (* 2 period) 2)) extensor 0]]))
64
65 (def wiggle-script
66 (mapcat gen-wiggle [[:d-up :d-down]
67 [:c-up :c-down]
68 [:b-up :b-down]
69 [:a-up :a-down]] (range 100 1000 12)))
70
71 (def wiggle-script
72 (mapcat gen-wiggle (repeat 40 [:a-down :a-up])
73 (range 100 10000 (+ 3 (* period 2)))))
24 74
25 75
26 (defn gen-worm
27 "create a creature acceptable for testing as a replacement for the
28 worm."
29 []
30 (nodify
31 "worm"
32 [(nodify
33 "eyes"
34 [(doto
35 (Node. "eye1")
36 (.setLocalTranslation (Vector3f. 0 -1.1 0))
37 (.setUserData
38
39 "eye"
40 "(let [retina
41 \"Models/test-creature/retina-small.png\"]
42 {:all retina :red retina
43 :green retina :blue retina})"))])
44 (box
45 0.2 0.2 0.2
46 :name "worm-segment"
47 :position (Vector3f. 0 0 0)
48 :color ColorRGBA/Orange)]))
49 76
77 (defn worm-world
78 ""
79 ([] (worm-world curl-script))
80 ([motion-script]
81 (let [record? false
82 worm (doto (worm-model) (body!))
83 touch '();;(touch! worm)
84 prop (proprioception! worm)
85 muscles (movement! worm)
86
87 touch-display (view-touch)
88 prop-display (view-proprioception)
89 muscle-display (view-movement)
50 90
51 (defn test-basic-touch 91 floor (box 10 1 10 :position (Vector3f. 0 -10 0)
52 "Testing touch: 92 :color ColorRGBA/Gray :mass 0)
53 You should see a cube fall onto a table. There is a cross-shaped
54 display which reports the cube's sensation of touch. This display
55 should change when the cube hits the table, and whenever you hit
56 the cube with balls.
57 93
58 Keys: 94 control-script (motor-control-program
59 <space> : fire ball" 95 muscle-labels motion-script)]
60 ([] (test-basic-touch false))
61 ([record?]
62 (let [head (doto (worm) (body!))
63 touch (touch! head)
64 touch-display (view-touch)]
65 (world 96 (world
66 (nodify [head 97 (nodify [worm floor])
67 (box 10 1 10 :position (Vector3f. 0 -10 0)
68 :color ColorRGBA/Gray :mass 0)])
69
70 standard-debug-controls 98 standard-debug-controls
71 99
72 (fn [world] 100 (fn [world]
101 ;; (set-gravity world Vector3f/ZERO)
102 ;; (position-camera
103 ;; world (Vector3f. 4.207176, -3.7366982, 3.0816958)
104 ;; (Quaternion. 0.11118768, 0.87678415, 0.24434438, -0.3989771))
105
106
107
108 (position-camera
109 world (Vector3f. 4.207176, -3.7366982, 3.0816958)
110 (Quaternion. -0.11555642, 0.88188726, -0.2854942, -0.3569518))
111
112
113
114
73 (let [timer (IsoTimer. 60)] 115 (let [timer (IsoTimer. 60)]
74 (.setTimer world timer) 116 (.setTimer world timer)
75 (display-dilated-time world timer)) 117 (display-dilated-time world timer))
76 (if record? 118 (if record?
77 (Capture/captureVideo 119 (Capture/captureVideo
78 world 120 world
79 (File. "/home/r/proj/cortex/render/touch-cube/main-view/"))) 121 (File. output-base "main-view")))
80 (speed-up world) 122 (speed-up world)
81 (light-up-everything world)) 123 (light-up-everything world))
82 124
83 (fn [world tpf] 125 (fn [world tpf]
126 (muscle-display
127 (control-script muscles)
128 (if record? (File. output-base "muscle")))
129 (prop-display
130 (prop)
131 (if record? (File. output-base "proprio")))
84 (touch-display 132 (touch-display
85 (map #(% (.getRootNode world)) touch) 133 (map #(% (.getRootNode world)) touch)
86 (if record? 134 (if record?
87 (File. "/home/r/proj/cortex/render/touch-cube/touch/")))))))) 135 (File. output-base "touch"))))))))