# HG changeset patch # User Robert McIntyre # Date 1395091799 14400 # Node ID 939bcc5950b2d7d0bab857e2a692199a0aee209c # Parent 92acbe7e5c91021b58e78638ce8f6b1ddc6320ac completed debug control of worm. diff -r 92acbe7e5c91 -r 939bcc5950b2 org/world.org --- a/org/world.org Mon Mar 17 14:01:02 2014 -0400 +++ b/org/world.org Mon Mar 17 17:29:59 2014 -0400 @@ -177,7 +177,7 @@ (defn initialize-inputs "Establish key-bindings for a particular virtual world." - [game input-manager key-map] + [game input-manager key-map] (doall (map (fn [[name trigger]] (.addMapping @@ -192,9 +192,6 @@ #+end_src -#+results: input -: #'cortex.world/initialize-inputs - These functions are for controlling the world through the keyboard and mouse. @@ -247,7 +244,7 @@ "the =world= function takes care of the details of initializing a SimpleApplication. - ***** Arguments: + ,***** Arguments: - root-node : a com.jme3.scene.Node object which contains all of the objects that should be in the simulation. diff -r 92acbe7e5c91 -r 939bcc5950b2 org/worm_learn.clj --- a/org/worm_learn.clj Mon Mar 17 14:01:02 2014 -0400 +++ b/org/worm_learn.clj Mon Mar 17 17:29:59 2014 -0400 @@ -41,8 +41,34 @@ effectors (map #(@current-forces % 0) muscle-positions))))))) - - +(defn worm-direct-control + "Create keybindings and a muscle control program that will enable + the user to control the worm via the keyboard." + [muscle-labels activation-strength] + (let [strengths (mapv (fn [_] (atom 0)) muscle-labels) + activator + (fn [n] + (fn [world pressed?] + (let [strength (if pressed? activation-strength 0)] + (swap! (nth strengths n) (constantly strength))))) + activators + (map activator (range (count muscle-labels))) + worm-keys + ["key-f" "key-r" + "key-g" "key-t" + "key-y" "key-h" + "key-j" "key-u" + "key-i" "key-k" + "key-o" "key-l"]] + {:motor-control + (fn [effectors] + (doall + (map (fn [strength effector] + (effector (deref strength))) + strengths effectors))) + :keybindings + ;; assume muscles are listed in pairs and map them to keys. + (zipmap worm-keys activators)})) ;; These are scripts that direct the worm to move in two radically ;; different patterns -- a sinusoidal wiggling motion, and a curling @@ -54,11 +80,11 @@ (def period 18) -(def muscle-labels +(def worm-muscle-labels [:base-up :base-down - :a-up :a-down + :a-down :a-up :b-up :b-down - :c-up :c-down + :c-down :c-up :d-up :d-down]) (defn gen-wiggle [[flexor extensor :as muscle-pair] time-base] @@ -125,49 +151,60 @@ [(Vector3f. -0.0708936, -8.570261, 2.6487997) (Quaternion. -2.318909E-4, 0.9985348, 0.053941682, 0.004291452)]) +(defn worm-world-defaults [] + (let [direct-control (worm-direct-control worm-muscle-labels 40)] + {:view worm-side-view + :motor-control (:motor-control direct-control) + :keybindings (:keybindings direct-control) + :record nil})) + +(defn dir! [file] + (if (not (.exists file)) + (.mkdir file)) + file) + (defn worm-world - "" - ([] (worm-world curl-script)) - ([motion-script] - (let [record? false ;;true - worm (doto (worm-model) (body!)) - touch (touch! worm) - prop (proprioception! worm) - muscles (movement! worm) - - touch-display (view-touch) - prop-display (view-proprioception) - muscle-display (view-movement) + [& {:keys [record motor-control keybindings view] :as settings}] + (let [{:keys [record motor-control keybindings view]} + (merge (worm-world-defaults) settings) + worm (doto (worm-model) (body!)) + touch (touch! worm) + prop (proprioception! worm) + muscles (movement! worm) + + touch-display (view-touch) + prop-display (view-proprioception) + muscle-display (view-movement) + + floor (box 10 1 10 :position (Vector3f. 0 -10 0) + :color ColorRGBA/Gray :mass 0)] - floor (box 10 1 10 :position (Vector3f. 0 -10 0) - :color ColorRGBA/Gray :mass 0) + (world + (nodify [worm floor]) + (merge standard-debug-controls keybindings) + (fn [world] + (position-camera world view) + (let [timer (IsoTimer. 60)] + (.setTimer world timer) + (display-dilated-time world timer)) + (if record + (Capture/captureVideo + world + (dir! (File. record "main-view")))) + (speed-up world) + (light-up-everything world)) + (fn [world tpf] + (let [strong! (motor-control muscles)] + (println strong!) + (muscle-display + strong! + (if record (dir! (File. record "muscle"))))) + (prop-display + (prop) + (if record (dir! (File. record "proprio")))) + (touch-display + (map #(% (.getRootNode world)) touch) + (if record + (File. record "touch"))))))) - control-script (motor-control-program - muscle-labels motion-script)] - (world - (nodify [worm floor]) - standard-debug-controls - - (fn [world] - ;; (set-gravity world Vector3f/ZERO) - (position-camera world degenerate-worm-view) - (let [timer (IsoTimer. 60)] - (.setTimer world timer) - (display-dilated-time world timer)) - (if record? - (Capture/captureVideo - world - (File. output-base "main-view"))) - (speed-up world) - (light-up-everything world)) - (fn [world tpf] - (muscle-display - (control-script muscles) - (if record? (File. output-base "muscle"))) - (prop-display - (prop) - (if record? (File. output-base "proprio"))) - (touch-display - (map #(% (.getRootNode world)) touch) - (if record? - (File. output-base "touch")))))))) + \ No newline at end of file diff -r 92acbe7e5c91 -r 939bcc5950b2 thesis/org/roadmap.org --- a/thesis/org/roadmap.org Mon Mar 17 14:01:02 2014 -0400 +++ b/thesis/org/roadmap.org Mon Mar 17 17:29:59 2014 -0400 @@ -185,8 +185,9 @@ ** Final stretch up to First Draft -*** TODO complete debug control of worm - SCHEDULED: <2014-03-17 Mon> +*** DONE complete debug control of worm + CLOSED: [2014-03-17 Mon 17:29] SCHEDULED: <2014-03-17 Mon> + CLOCK: [2014-03-17 Mon 14:01]--[2014-03-17 Mon 17:29] => 3:28 *** TODO add phi-space output to debug control SCHEDULED: <2014-03-17 Mon> *** TODO complete phi-stream action predicatates; test them with debug control