Mercurial > cortex
diff org/integration.org @ 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 |
line wrap: on
line diff
1.1 --- a/org/integration.org Thu Feb 16 09:59:44 2012 -0700 1.2 +++ b/org/integration.org Thu Feb 16 11:04:22 2012 -0700 1.3 @@ -31,10 +31,77 @@ 1.4 1.5 (def output-base (File. "/home/r/proj/cortex/render/hand")) 1.6 1.7 +(defn motor-control-program 1.8 + "Create a function which will execute the motor script" 1.9 + [muscle-positions 1.10 + script] 1.11 + (let [current-frame (atom -1) 1.12 + keyed-script (group-by first script) 1.13 + current-forces (atom {}) ] 1.14 + (fn [effectors] 1.15 + (let [indexed-effectors (vec effectors)] 1.16 + (dorun 1.17 + (for [[_ part force] (keyed-script (swap! current-frame inc))] 1.18 + (swap! current-forces (fn [m] (assoc m part force))))) 1.19 + (doall (map (fn [effector power] 1.20 + (effector (int power))) 1.21 + effectors 1.22 + (map #(@current-forces % 0) muscle-positions))))))) 1.23 + 1.24 +(def muscle-positions 1.25 + [:pointer-2-e 1.26 + :pointer-2-f 1.27 + :thumb-1 1.28 + :thumb-1 1.29 + :pointer-1-e 1.30 + :pointer-1-f 1.31 + :thumb-2-e 1.32 + :thumb-2-f 1.33 + :middle-1-e 1.34 + :middle-1-f 1.35 + :pointer-3-f 1.36 + :pointer-3-e 1.37 + :middle-2-e 1.38 + :middle-2-f 1.39 + :middle-3-f 1.40 + :middle-3-e 1.41 + :pinky-2-e 1.42 + :pinky-2-f 1.43 + :pinky-3-f 1.44 + :pinky-3-e 1.45 + :ring-3-e 1.46 + :ring-3-f 1.47 + :ring-2-f 1.48 + :ring-2-e 1.49 + :ring-1-e 1.50 + :ring-1-f 1.51 + :thumb-1-e 1.52 + :thumb-1-f 1.53 + :pinky-1-f 1.54 + :pinky-1-e]) 1.55 + 1.56 +(def full 9001) 1.57 +;; the systax here is [keyframe body-part force] 1.58 +(def wiggle-each-finger-tip 1.59 + [[200 :pointer-3-f full] 1.60 + [200 :pointer-3-f 40] 1.61 + 1.62 + [400 :middle-3-f full] 1.63 + [401 :middle-3-f 40] 1.64 + 1.65 + [600 :ring-3-f full] 1.66 + [601 :ring-3-f 40] 1.67 + 1.68 + [800 :pinky-3-f full] 1.69 + [801 :pinky-3-f 40]]) 1.70 + 1.71 + 1.72 + 1.73 + 1.74 (def control-list 1.75 [ 1.76 0 ;;pointer-21 #<Vector3f (0.99999994, 0.0, 0.0)> 1.77 - 1 ;;pointer-21 #<Vector3f (-0.99999994, 0.0, 0.0)> 1.78 + 0 ;;pointer-21 #<Vector3f (-0.99999994, 0.0, 0.0)> 1.79 0 ;;thumb-11 #<Vector3f (-0.8802276, -0.39781287, -0.25873658)> 1.80 0 ;;thumb-11 #<Vector3f (0.8485723, 0.46149826, 0.2587364)> 1.81 0 ;;pointer-11 #<Vector3f (0.99999994, 0.0, 0.0)> 1.82 @@ -43,7 +110,7 @@ 1.83 0 ;;thumb-2.0011 #<Vector3f (-0.10567085, 0.83862597, 0.53435963)> 1.84 0 ;;middle-11 #<Vector3f (0.99999994, 0.0, 0.0)> 1.85 0 ;;middle-11 #<Vector3f (-0.99999994, 0.0, 0.0)> 1.86 - 0 ;;pointer-31 #<Vector3f (-0.99999994, 0.0, 0.0)> 1.87 + 1 ;;pointer-31 #<Vector3f (-0.99999994, 0.0, 0.0)> 1.88 0 ;;pointer-31 #<Vector3f (0.99999994, 0.0, 0.0)> 1.89 0 ;;middle-21 #<Vector3f (0.99999994, 0.0, 0.0)> 1.90 0 ;;middle-21 #<Vector3f (-0.99999994, 0.0, 0.0)> 1.91 @@ -51,7 +118,8 @@ 1.92 0 ;;middle-31 #<Vector3f (0.99999994, 0.0, 0.0)> 1.93 0 ;;pinky-21 #<Vector3f (0.99999994, 0.0, 0.0)> 1.94 0 ;;pinky-21 #<Vector3f (-0.99999994, 0.0, 0.0)> 1.95 - 0 ;;pinky-31 #<Vector3f (0.99999994, 0.0, 0.0)> 1.96 + 0 ;;pinky-31 #<Vector3f (-1, 0.0, 0.0)> 1.97 + 0 ;;pinky-31 #<Vector3f (1.0, 0.0, 0.0)> 1.98 0 ;;ring-31 #<Vector3f (0.99999994, 0.0, 0.0)> 1.99 0 ;;ring-31 #<Vector3f (-0.99999994, 0.0, 0.0)> 1.100 0 ;;ring-21 #<Vector3f (-0.99999994, 0.0, 0.0)> 1.101 @@ -87,7 +155,8 @@ 1.102 prop (proprioception! creature) 1.103 prop-display (view-proprioception) 1.104 1.105 - muscle-exertion (atom 0) 1.106 + control-script (motor-control-program 1.107 + muscle-positions wiggle-each-finger-tip) 1.108 muscles (movement! creature) 1.109 muscle-display (view-movement) 1.110 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 1.111 @@ -102,15 +171,8 @@ 1.112 {"key-return" 1.113 (fn [_ value] 1.114 (if value 1.115 - (.play bell))) 1.116 - "key-h" 1.117 - (fn [_ value] 1.118 - (if value 1.119 - (swap! muscle-exertion (partial + 20)))) 1.120 - "key-n" 1.121 - (fn [_ value] 1.122 - (if value 1.123 - (swap! muscle-exertion (fn [v] (- v 20)))))}) 1.124 + (.play bell)))}) 1.125 + 1.126 (fn [world] 1.127 (.setTimer world (RatchetTimer. 60)) 1.128 (light-up-everything world) 1.129 @@ -127,11 +189,9 @@ 1.130 ;;(vision-display (map #(% world) vision)) 1.131 ;;(hearing-display (map #(% world) hearing)) 1.132 1.133 - (muscle-display 1.134 - (map (fn [effector control] 1.135 - (effector (int (* @muscle-exertion control)))) 1.136 - muscles 1.137 - control-list)) 1.138 + ;;(muscle-display 1.139 + (control-script muscles) 1.140 + ;;) 1.141 1.142 (.setLocalTranslation me (.getLocation (.getCamera world))) 1.143 (fix-display world))))))