changeset 296:1eed471e2ebf

first version of a mini motor-control script language
author Robert McIntyre <rlm@mit.edu>
date Thu, 16 Feb 2012 11:04:22 -0700
parents 67a4e92d4628
children d1206b11ae2d
files assets/Models/test-creature/hand.blend org/integration.org org/movement.org
diffstat 3 files changed, 81 insertions(+), 22 deletions(-) [+]
line wrap: on
line diff
     1.1 Binary file assets/Models/test-creature/hand.blend has changed
     2.1 --- a/org/integration.org	Thu Feb 16 09:59:44 2012 -0700
     2.2 +++ b/org/integration.org	Thu Feb 16 11:04:22 2012 -0700
     2.3 @@ -31,10 +31,77 @@
     2.4  
     2.5  (def output-base (File. "/home/r/proj/cortex/render/hand"))
     2.6  
     2.7 +(defn motor-control-program
     2.8 +  "Create a function which will execute the motor script"
     2.9 +  [muscle-positions
    2.10 +   script]
    2.11 +  (let [current-frame (atom -1)
    2.12 +        keyed-script (group-by first script)
    2.13 +        current-forces (atom {}) ]
    2.14 +    (fn [effectors]
    2.15 +      (let [indexed-effectors (vec effectors)]
    2.16 +        (dorun 
    2.17 +         (for [[_ part force] (keyed-script (swap! current-frame inc))]
    2.18 +           (swap! current-forces (fn [m] (assoc m part force)))))
    2.19 +        (doall (map (fn [effector power]
    2.20 +                      (effector (int power)))
    2.21 +                    effectors
    2.22 +                    (map #(@current-forces % 0) muscle-positions)))))))
    2.23 +
    2.24 +(def muscle-positions
    2.25 +  [:pointer-2-e
    2.26 +   :pointer-2-f
    2.27 +   :thumb-1
    2.28 +   :thumb-1
    2.29 +   :pointer-1-e
    2.30 +   :pointer-1-f
    2.31 +   :thumb-2-e
    2.32 +   :thumb-2-f
    2.33 +   :middle-1-e
    2.34 +   :middle-1-f
    2.35 +   :pointer-3-f
    2.36 +   :pointer-3-e
    2.37 +   :middle-2-e
    2.38 +   :middle-2-f
    2.39 +   :middle-3-f
    2.40 +   :middle-3-e
    2.41 +   :pinky-2-e
    2.42 +   :pinky-2-f
    2.43 +   :pinky-3-f
    2.44 +   :pinky-3-e
    2.45 +   :ring-3-e
    2.46 +   :ring-3-f
    2.47 +   :ring-2-f
    2.48 +   :ring-2-e
    2.49 +   :ring-1-e
    2.50 +   :ring-1-f
    2.51 +   :thumb-1-e
    2.52 +   :thumb-1-f
    2.53 +   :pinky-1-f
    2.54 +   :pinky-1-e])
    2.55 +
    2.56 +(def full 9001)
    2.57 +;; the systax here is [keyframe body-part force]
    2.58 +(def wiggle-each-finger-tip
    2.59 +  [[200 :pointer-3-f full]
    2.60 +   [200 :pointer-3-f 40]
    2.61 +
    2.62 +   [400 :middle-3-f full]
    2.63 +   [401 :middle-3-f 40]
    2.64 +
    2.65 +   [600 :ring-3-f full]
    2.66 +   [601 :ring-3-f 40]
    2.67 +
    2.68 +   [800 :pinky-3-f full]
    2.69 +   [801 :pinky-3-f 40]])
    2.70 +
    2.71 +
    2.72 +
    2.73 +
    2.74  (def control-list
    2.75   [
    2.76    0 ;;pointer-21 #<Vector3f (0.99999994, 0.0, 0.0)>
    2.77 -  1 ;;pointer-21 #<Vector3f (-0.99999994, 0.0, 0.0)>
    2.78 +  0 ;;pointer-21 #<Vector3f (-0.99999994, 0.0, 0.0)>
    2.79    0 ;;thumb-11 #<Vector3f (-0.8802276, -0.39781287, -0.25873658)>
    2.80    0 ;;thumb-11 #<Vector3f (0.8485723, 0.46149826, 0.2587364)>
    2.81    0 ;;pointer-11 #<Vector3f (0.99999994, 0.0, 0.0)>
    2.82 @@ -43,7 +110,7 @@
    2.83    0 ;;thumb-2.0011 #<Vector3f (-0.10567085, 0.83862597, 0.53435963)>
    2.84    0 ;;middle-11 #<Vector3f (0.99999994, 0.0, 0.0)>
    2.85    0 ;;middle-11 #<Vector3f (-0.99999994, 0.0, 0.0)>
    2.86 -  0 ;;pointer-31 #<Vector3f (-0.99999994, 0.0, 0.0)>
    2.87 +  1 ;;pointer-31 #<Vector3f (-0.99999994, 0.0, 0.0)>
    2.88    0 ;;pointer-31 #<Vector3f (0.99999994, 0.0, 0.0)>
    2.89    0 ;;middle-21 #<Vector3f (0.99999994, 0.0, 0.0)>
    2.90    0 ;;middle-21 #<Vector3f (-0.99999994, 0.0, 0.0)>
    2.91 @@ -51,7 +118,8 @@
    2.92    0 ;;middle-31 #<Vector3f (0.99999994, 0.0, 0.0)>
    2.93    0 ;;pinky-21 #<Vector3f (0.99999994, 0.0, 0.0)>
    2.94    0 ;;pinky-21 #<Vector3f (-0.99999994, 0.0, 0.0)>
    2.95 -  0 ;;pinky-31 #<Vector3f (0.99999994, 0.0, 0.0)>
    2.96 +  0 ;;pinky-31 #<Vector3f (-1, 0.0, 0.0)>
    2.97 +  0 ;;pinky-31 #<Vector3f (1.0, 0.0, 0.0)>
    2.98    0 ;;ring-31 #<Vector3f (0.99999994, 0.0, 0.0)>
    2.99    0 ;;ring-31 #<Vector3f (-0.99999994, 0.0, 0.0)>
   2.100    0 ;;ring-21 #<Vector3f (-0.99999994, 0.0, 0.0)>
   2.101 @@ -87,7 +155,8 @@
   2.102          prop (proprioception! creature)
   2.103          prop-display (view-proprioception)
   2.104  
   2.105 -        muscle-exertion (atom 0)
   2.106 +        control-script (motor-control-program
   2.107 +                        muscle-positions wiggle-each-finger-tip)
   2.108          muscles (movement! creature)
   2.109          muscle-display (view-movement)
   2.110          ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
   2.111 @@ -102,15 +171,8 @@
   2.112              {"key-return"
   2.113               (fn [_ value]
   2.114                 (if value
   2.115 -                   (.play bell)))
   2.116 -             "key-h"
   2.117 -             (fn [_ value]
   2.118 -               (if value
   2.119 -                 (swap!  muscle-exertion (partial + 20))))
   2.120 -             "key-n"
   2.121 -             (fn [_ value]
   2.122 -               (if value
   2.123 -                 (swap! muscle-exertion (fn [v] (- v 20)))))})
   2.124 +                   (.play bell)))})
   2.125 +
   2.126       (fn [world]
   2.127         (.setTimer world (RatchetTimer. 60))
   2.128         (light-up-everything world)
   2.129 @@ -127,11 +189,9 @@
   2.130         ;;(vision-display (map #(% world) vision))
   2.131         ;;(hearing-display (map #(% world) hearing))
   2.132  
   2.133 -       (muscle-display
   2.134 -        (map (fn [effector control]
   2.135 -               (effector (int (* @muscle-exertion control))))
   2.136 -             muscles
   2.137 -             control-list))
   2.138 +       ;;(muscle-display
   2.139 +       (control-script muscles)
   2.140 +       ;;)
   2.141               
   2.142         (.setLocalTranslation me (.getLocation (.getCamera world)))
   2.143         (fix-display world))))))
     3.1 --- a/org/movement.org	Thu Feb 16 09:59:44 2012 -0700
     3.2 +++ b/org/movement.org	Thu Feb 16 11:04:22 2012 -0700
     3.3 @@ -118,15 +118,14 @@
     3.4          
     3.5          pool (motor-pool muscle)
     3.6          pool-integral (reductions + pool)
     3.7 -        force-index
     3.8 +        forces
     3.9          (vec (map  #(float (* strength (/ % (last pool-integral))))
    3.10                pool-integral))
    3.11          control (.getControl target RigidBodyControl)]
    3.12 -    (println-repl "adding muscle to" (.getName target))
    3.13 -    (println-repl "points" axis)
    3.14 +    (println-repl (.getName target) axis)
    3.15      (fn [n]
    3.16        (let [pool-index (max 0 (min n (dec (count pool))))
    3.17 -            force (force-index pool-index)]
    3.18 +            force (forces pool-index)]
    3.19          (.applyTorque control (.mult axis force))
    3.20          (float (/ force strength))))))
    3.21