changeset 404:939bcc5950b2

completed debug control of worm.
author Robert McIntyre <rlm@mit.edu>
date Mon, 17 Mar 2014 17:29:59 -0400
parents 92acbe7e5c91
children 9b4a4da08b78
files org/world.org org/worm_learn.clj thesis/org/roadmap.org
diffstat 3 files changed, 90 insertions(+), 55 deletions(-) [+]
line wrap: on
line diff
     1.1 --- a/org/world.org	Mon Mar 17 14:01:02 2014 -0400
     1.2 +++ b/org/world.org	Mon Mar 17 17:29:59 2014 -0400
     1.3 @@ -177,7 +177,7 @@
     1.4  
     1.5  (defn initialize-inputs
     1.6    "Establish key-bindings for a particular virtual world."
     1.7 -  [game  input-manager key-map]
     1.8 +  [game input-manager key-map]
     1.9    (doall
    1.10     (map (fn [[name trigger]]
    1.11            (.addMapping
    1.12 @@ -192,9 +192,6 @@
    1.13  
    1.14  #+end_src
    1.15  
    1.16 -#+results: input
    1.17 -: #'cortex.world/initialize-inputs
    1.18 -
    1.19  These functions are for controlling the world through the keyboard and
    1.20  mouse.
    1.21  
    1.22 @@ -247,7 +244,7 @@
    1.23    "the =world= function takes care of the details of initializing a
    1.24    SimpleApplication.
    1.25  
    1.26 -   ***** Arguments:
    1.27 +   ,***** Arguments:
    1.28  
    1.29     - root-node : a com.jme3.scene.Node object which contains all of
    1.30         the objects that should be in the simulation.
     2.1 --- a/org/worm_learn.clj	Mon Mar 17 14:01:02 2014 -0400
     2.2 +++ b/org/worm_learn.clj	Mon Mar 17 17:29:59 2014 -0400
     2.3 @@ -41,8 +41,34 @@
     2.4                      effectors
     2.5                      (map #(@current-forces % 0) muscle-positions)))))))
     2.6  
     2.7 -
     2.8 -
     2.9 +(defn worm-direct-control
    2.10 +  "Create keybindings and a muscle control program that will enable
    2.11 +   the user to control the worm via the keyboard."
    2.12 +  [muscle-labels activation-strength]
    2.13 +  (let [strengths (mapv (fn [_] (atom 0)) muscle-labels)
    2.14 +        activator
    2.15 +        (fn [n]
    2.16 +          (fn [world pressed?]
    2.17 +            (let [strength (if pressed? activation-strength 0)]
    2.18 +              (swap! (nth strengths n) (constantly strength)))))
    2.19 +        activators
    2.20 +        (map activator (range (count muscle-labels)))
    2.21 +        worm-keys
    2.22 +        ["key-f" "key-r"
    2.23 +         "key-g" "key-t"
    2.24 +         "key-y" "key-h"
    2.25 +         "key-j" "key-u"
    2.26 +         "key-i" "key-k"
    2.27 +         "key-o" "key-l"]]
    2.28 +    {:motor-control
    2.29 +     (fn [effectors]
    2.30 +      (doall
    2.31 +       (map (fn [strength effector]
    2.32 +              (effector (deref strength)))
    2.33 +            strengths effectors)))
    2.34 +     :keybindings
    2.35 +     ;; assume muscles are listed in pairs and map them to keys.
    2.36 +     (zipmap worm-keys activators)}))
    2.37  
    2.38  ;; These are scripts that direct the worm to move in two radically
    2.39  ;; different patterns -- a sinusoidal wiggling motion, and a curling
    2.40 @@ -54,11 +80,11 @@
    2.41  
    2.42  (def period 18)
    2.43  
    2.44 -(def muscle-labels
    2.45 +(def worm-muscle-labels
    2.46    [:base-up :base-down
    2.47 -   :a-up :a-down
    2.48 +   :a-down :a-up
    2.49     :b-up :b-down
    2.50 -   :c-up :c-down
    2.51 +   :c-down :c-up
    2.52     :d-up :d-down])
    2.53  
    2.54  (defn gen-wiggle [[flexor extensor :as muscle-pair] time-base]
    2.55 @@ -125,49 +151,60 @@
    2.56    [(Vector3f. -0.0708936, -8.570261, 2.6487997)
    2.57     (Quaternion. -2.318909E-4, 0.9985348, 0.053941682, 0.004291452)])
    2.58  
    2.59 +(defn worm-world-defaults []
    2.60 +  (let [direct-control (worm-direct-control worm-muscle-labels 40)]
    2.61 +    {:view worm-side-view
    2.62 +     :motor-control (:motor-control direct-control)
    2.63 +     :keybindings (:keybindings direct-control)
    2.64 +     :record nil}))
    2.65 +
    2.66 +(defn dir! [file]
    2.67 +  (if (not (.exists file))
    2.68 +    (.mkdir file))
    2.69 +  file)
    2.70 +  
    2.71  (defn worm-world
    2.72 -  ""
    2.73 -  ([] (worm-world curl-script))
    2.74 -  ([motion-script]
    2.75 -     (let [record? false ;;true
    2.76 -           worm (doto (worm-model) (body!))
    2.77 -           touch   (touch! worm)
    2.78 -           prop    (proprioception! worm)
    2.79 -           muscles (movement! worm)
    2.80 -           
    2.81 -           touch-display  (view-touch)
    2.82 -           prop-display   (view-proprioception)
    2.83 -           muscle-display (view-movement)
    2.84 +  [& {:keys [record motor-control keybindings view] :as settings}]
    2.85 +  (let [{:keys [record motor-control keybindings view]}
    2.86 +        (merge (worm-world-defaults) settings)
    2.87 +        worm (doto (worm-model) (body!))
    2.88 +        touch   (touch! worm)
    2.89 +        prop    (proprioception! worm)
    2.90 +        muscles (movement! worm)
    2.91 +        
    2.92 +        touch-display  (view-touch)
    2.93 +        prop-display   (view-proprioception)
    2.94 +        muscle-display (view-movement)
    2.95 +        
    2.96 +        floor (box 10 1 10 :position (Vector3f. 0 -10 0)
    2.97 +                   :color ColorRGBA/Gray :mass 0)]
    2.98  
    2.99 -           floor (box 10 1 10 :position (Vector3f. 0 -10 0)
   2.100 -                      :color ColorRGBA/Gray :mass 0)
   2.101 +    (world
   2.102 +       (nodify [worm floor])
   2.103 +       (merge standard-debug-controls keybindings)
   2.104 +       (fn [world]
   2.105 +         (position-camera world view)
   2.106 +         (let [timer (IsoTimer. 60)]
   2.107 +           (.setTimer world timer)
   2.108 +           (display-dilated-time world timer))
   2.109 +         (if record
   2.110 +           (Capture/captureVideo
   2.111 +            world
   2.112 +            (dir! (File. record "main-view"))))
   2.113 +         (speed-up world)
   2.114 +         (light-up-everything world))
   2.115 +       (fn [world tpf]
   2.116 +         (let [strong! (motor-control muscles)]
   2.117 +           (println strong!)
   2.118 +           (muscle-display
   2.119 +            strong!
   2.120 +            (if record (dir! (File. record "muscle")))))
   2.121 +         (prop-display
   2.122 +          (prop)
   2.123 +          (if record (dir! (File. record "proprio"))))
   2.124 +         (touch-display 
   2.125 +          (map #(% (.getRootNode world)) touch)
   2.126 +          (if record
   2.127 +            (File. record "touch")))))))
   2.128  
   2.129 -           control-script (motor-control-program
   2.130 -                           muscle-labels motion-script)]
   2.131 -       (world
   2.132 -        (nodify [worm floor])
   2.133 -        standard-debug-controls
   2.134 -        
   2.135 -        (fn [world]
   2.136 -          ;; (set-gravity world Vector3f/ZERO)
   2.137 -          (position-camera world degenerate-worm-view)
   2.138 -          (let [timer (IsoTimer. 60)]
   2.139 -            (.setTimer world timer)
   2.140 -            (display-dilated-time world timer))
   2.141 -          (if record?
   2.142 -            (Capture/captureVideo
   2.143 -             world
   2.144 -             (File. output-base "main-view")))
   2.145 -          (speed-up world)
   2.146 -          (light-up-everything world))
   2.147 -        (fn [world tpf]
   2.148 -          (muscle-display
   2.149 -           (control-script muscles)
   2.150 -           (if record? (File. output-base "muscle")))
   2.151 -          (prop-display
   2.152 -           (prop)
   2.153 -           (if record? (File. output-base "proprio")))             
   2.154 -          (touch-display 
   2.155 -           (map #(% (.getRootNode world)) touch)
   2.156 -           (if record?
   2.157 -             (File. output-base "touch"))))))))
   2.158 +   
   2.159 \ No newline at end of file
     3.1 --- a/thesis/org/roadmap.org	Mon Mar 17 14:01:02 2014 -0400
     3.2 +++ b/thesis/org/roadmap.org	Mon Mar 17 17:29:59 2014 -0400
     3.3 @@ -185,8 +185,9 @@
     3.4  
     3.5  ** Final stretch up to First Draft
     3.6  
     3.7 -*** TODO complete debug control of worm
     3.8 -    SCHEDULED: <2014-03-17 Mon>
     3.9 +*** DONE complete debug control of worm
    3.10 +    CLOSED: [2014-03-17 Mon 17:29] SCHEDULED: <2014-03-17 Mon>
    3.11 +    CLOCK: [2014-03-17 Mon 14:01]--[2014-03-17 Mon 17:29] =>  3:28
    3.12  *** TODO add phi-space output to debug control
    3.13      SCHEDULED: <2014-03-17 Mon>
    3.14  *** TODO complete phi-stream action predicatates; test them with debug control