Mercurial > cortex
view 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 |
line wrap: on
line source
1 (ns org.aurellem.worm-learn2 "General worm creation framework."3 {:author "Robert McIntyre"}4 (:use (cortex world util import body sense5 hearing touch vision proprioception movement))6 (:import (com.jme3.math ColorRGBA Vector3f))7 (:import java.io.File)8 (:import com.jme3.audio.AudioNode)9 (:import com.aurellem.capture.RatchetTimer)10 (:import (com.aurellem.capture Capture IsoTimer))11 (:import (com.jme3.math Vector3f ColorRGBA)))14 (dorun (cortex.import/mega-import-jme3))15 (rlm.rlm-commands/help)18 (def hand "Models/test-creature/hand.blend")20 (defn worm-model []21 (load-blender-model "Models/worm/worm.blend"))23 (def output-base (File. "/home/r/proj/cortex/render/worm-learn/"))26 (defn motor-control-program27 "Create a function which will execute the motor script"28 [muscle-positions29 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 (dorun36 (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 effectors41 (map #(@current-forces % 0) muscle-positions)))))))43 (def muscle-labels44 [:base-up :base-down45 :a-up :a-down46 :b-up :b-down47 :c-up :c-down48 :d-up :d-down49 ])51 (def curl-script52 [[370 :d-up 20]53 [390 :d-up 0]])55 (def period 18)57 (defn gen-wiggle [[flexor extensor :as muscle-pair] time-base]58 (let [period period59 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]]))65 (def wiggle-script66 (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)))71 (def wiggle-script72 (mapcat gen-wiggle (repeat 40 [:a-down :a-up])73 (range 100 10000 (+ 3 (* period 2)))))77 (defn worm-world78 ""79 ([] (worm-world curl-script))80 ([motion-script]81 (let [record? false82 worm (doto (worm-model) (body!))83 touch '();;(touch! worm)84 prop (proprioception! worm)85 muscles (movement! worm)87 touch-display (view-touch)88 prop-display (view-proprioception)89 muscle-display (view-movement)91 floor (box 10 1 10 :position (Vector3f. 0 -10 0)92 :color ColorRGBA/Gray :mass 0)94 control-script (motor-control-program95 muscle-labels motion-script)]96 (world97 (nodify [worm floor])98 standard-debug-controls100 (fn [world]101 ;; (set-gravity world Vector3f/ZERO)102 ;; (position-camera103 ;; world (Vector3f. 4.207176, -3.7366982, 3.0816958)104 ;; (Quaternion. 0.11118768, 0.87678415, 0.24434438, -0.3989771))108 (position-camera109 world (Vector3f. 4.207176, -3.7366982, 3.0816958)110 (Quaternion. -0.11555642, 0.88188726, -0.2854942, -0.3569518))115 (let [timer (IsoTimer. 60)]116 (.setTimer world timer)117 (display-dilated-time world timer))118 (if record?119 (Capture/captureVideo120 world121 (File. output-base "main-view")))122 (speed-up world)123 (light-up-everything world))125 (fn [world tpf]126 (muscle-display127 (control-script muscles)128 (if record? (File. output-base "muscle")))129 (prop-display130 (prop)131 (if record? (File. output-base "proprio")))132 (touch-display133 (map #(% (.getRootNode world)) touch)134 (if record?135 (File. output-base "touch"))))))))