diff org/worm_learn.clj @ 406:40b67bb71430

save progress.
author Robert McIntyre <rlm@mit.edu>
date Tue, 18 Mar 2014 18:34:10 -0400
parents 9b4a4da08b78
children bd6d03596ea8
line wrap: on
line diff
     1.1 --- a/org/worm_learn.clj	Mon Mar 17 20:52:16 2014 -0400
     1.2 +++ b/org/worm_learn.clj	Tue Mar 18 18:34:10 2014 -0400
     1.3 @@ -9,7 +9,8 @@
     1.4    (:import com.aurellem.capture.RatchetTimer)
     1.5    (:import (com.aurellem.capture Capture IsoTimer))
     1.6    (:import (com.jme3.math Vector3f ColorRGBA)))
     1.7 -  
     1.8 +
     1.9 +(use 'clojure.pprint)
    1.10  
    1.11  (dorun (cortex.import/mega-import-jme3))
    1.12  (rlm.rlm-commands/help)
    1.13 @@ -26,7 +27,7 @@
    1.14  
    1.15  (defn motor-control-program
    1.16    "Create a function which will execute the motor script"
    1.17 -  [muscle-positions
    1.18 +  [muscle-labels
    1.19     script]
    1.20    (let [current-frame (atom -1)
    1.21          keyed-script (group-by first script)
    1.22 @@ -39,7 +40,7 @@
    1.23          (doall (map (fn [effector power]
    1.24                        (effector (int power)))
    1.25                      effectors
    1.26 -                    (map #(@current-forces % 0) muscle-positions)))))))
    1.27 +                    (map #(@current-forces % 0) muscle-labels)))))))
    1.28  
    1.29  (defn worm-direct-control
    1.30    "Create keybindings and a muscle control program that will enable
    1.31 @@ -96,8 +97,8 @@
    1.32       [(+ time-base (+ (* 2 period) 2))  extensor 0]]))
    1.33    
    1.34  (def wiggle-script
    1.35 -  (mapcat gen-wiggle (repeat 40 [:a-down :a-up])
    1.36 -                     (range 100 10000 (+ 3 (* period 2)))))
    1.37 +  (mapcat gen-wiggle (repeat 4000 [:a-down :a-up])
    1.38 +                     (range 100 1000000 (+ 3 (* period 2)))))
    1.39  
    1.40  
    1.41  ;; Normally, we'd use unsupervised/supervised machine learning to pick
    1.42 @@ -132,28 +133,40 @@
    1.43    "Does the worm form a majestic circle (one end touching the other)?"
    1.44    [experiences]
    1.45    (and (curled? experiences)
    1.46 -       true))
    1.47 +       true)) ;; TODO: add code here.
    1.48  
    1.49  (defn vector:last-n [v n]
    1.50    (let [c (count v)]
    1.51      (if (< c n) v
    1.52          (subvec v (- c n) c))))
    1.53  
    1.54 +(defn touch-average [[coords touch]]
    1.55 +  (/ (average (map first touch)) (average (map second touch))))
    1.56 +
    1.57 +(defn floor-contact [[coords contact :as touch]]
    1.58 +  (let [raw-average
    1.59 +        (average
    1.60 +         (map
    1.61 +          first
    1.62 +          (vals
    1.63 +           (select-keys
    1.64 +            (zipmap coords contact)
    1.65 +            [[8 15] [8 16] [8 17] [8 18] [8 19] [8 20] [8 21] [8 22] [9 15]
    1.66 +             [9 16] [9 17] [9 18] [9 19] [9 20] [9 21] [9 22] [10 15] [10 16]
    1.67 +             [10 17] [10 18] [10 19] [10 20] [10 21] [10 22] [11 15] [11 16]
    1.68 +             [11 17] [11 18] [11 19] [11 20] [11 21] [11 22] [12 15] [12 16]
    1.69 +             [12 17] [12 18] [12 19] [12 20] [12 21] [12 22] [13 15] [13 16]
    1.70 +             [13 17] [13 18] [13 19] [13 20] [13 21] [13 22] [14 15] [14 16]
    1.71 +             [14 17] [14 18] [14 19] [14 20] [14 21] [14 22]]))))]
    1.72 +    (Math/abs (- 1. (* 10 raw-average)))))
    1.73 +
    1.74 +
    1.75  (defn wiggling?
    1.76    "Is the worm wiggling?"
    1.77    [experiences]
    1.78 -  (vector:last-n
    1.79 +  (vector:last-n experiences 200)
    1.80    
    1.81 -
    1.82 -))
    1.83 -
    1.84 -
    1.85 -
    1.86 -
    1.87 -
    1.88 -(defn resting?
    1.89 -  "Is the worm on the ground in a neutral position?"
    1.90 -  [])
    1.91 +)
    1.92  
    1.93  (def standard-world-view
    1.94    [(Vector3f. 4.207176, -3.7366982, 3.0816958)
    1.95 @@ -223,7 +236,11 @@
    1.96                             :proprioception proprioception-data
    1.97                             :muscle muscle-data})
    1.98               (if (curled? @experiences) (println "Curled"))
    1.99 -             (if (straight? @experiences)    (println "Straight"))
   1.100 +             ;;(if (straight? @experiences)    (println "Straight"))
   1.101 +             (println-repl
   1.102 +              (apply format "%.2f %.2f %.2f %.2f %.2f\n"
   1.103 +                     (map floor-contact touch-data)))
   1.104 +
   1.105               )
   1.106             (muscle-display
   1.107              muscle-data