comparison org/proprioception.org @ 257:5d7961d7fded

wrote intro text for proprioception
author Robert McIntyre <rlm@mit.edu>
date Tue, 14 Feb 2012 00:37:42 -0700
parents df46a609fed9
children f4b67005b702
comparison
equal deleted inserted replaced
256:96b746a0b398 257:5d7961d7fded
4 #+description: proprioception for simulated creatures 4 #+description: proprioception for simulated creatures
5 #+keywords: simulation, jMonkeyEngine3, clojure 5 #+keywords: simulation, jMonkeyEngine3, clojure
6 #+SETUPFILE: ../../aurellem/org/setup.org 6 #+SETUPFILE: ../../aurellem/org/setup.org
7 #+INCLUDE: ../../aurellem/org/level-0.org 7 #+INCLUDE: ../../aurellem/org/level-0.org
8 8
9 #+name: proprioception 9 * Proprioception
10 #+begin_src clojure 10
11 (ns cortex.proprioception 11 Close your eyes, and touch your nose with your right index finger. How
12 "Simulate the sense of proprioception (ability to detect the 12 did you do it? You could not see your hand, and neither your hand nor
13 relative positions of body parts with repsect to other body parts) 13 your nose could use the sense of touch to guide the path of your hand.
14 in jMonkeyEngine3. Reads specially prepared blender files to 14 There are no sound cues, and Taste and Smell certainly don't provide
15 automatically generate proprioceptive senses." 15 any help. You know where your hand is without your other senses
16 (:use (cortex world util sense body)) 16 because of Proprioception.
17 (:use clojure.contrib.def) 17
18 (:import com.jme3.scene.Node) 18 Humans can sometimes loose this sense through viral infections or
19 (:import java.awt.image.BufferedImage) 19 damage to the spinal cord or brain, and when they do, they loose the
20 (:import (com.jme3.math Vector3f Quaternion))) 20 ability to control their own bodies without looking directly at the
21 parts they want to move. In [[http://en.wikipedia.org/wiki/The_Man_Who_Mistook_His_Wife_for_a_Hat][The Man Who Mistook His Wife for a Hat]],
22 a woman named Christina looses this sense and has to learn how to move
23 by carefully watching her arms and legs. She describes proprioception
24 as the "eyes of the body, the way the body sees itself".
25
26 Proprioception in humans is mediated by [[http://en.wikipedia.org/wiki/Articular_capsule][joint capsules]], [[http://en.wikipedia.org/wiki/Muscle_spindle][muscle
27 spindles]], and the [[http://en.wikipedia.org/wiki/Golgi_tendon_organ][Golgi tendon organs]]. These measure the relative
28 positions of each pody part by monitoring muscle strain and length.
29
30 It's clear that this is a vital sense for fulid, graceful
31 movement. It's also particurally easy to implement in jMonkeyEngine.
32
33 My simulated proprioception calculates the relative angles of each
34 joint from the rest position defined in the blender file. This
35 simulates the muscle-spindles and joint capsules. I will deal with
36 Golgi tendon organs, which calculate muscle strain, in the [[./movement.org][next post]].
37
38 * Helper Functions
39
40
41 #+name: helpers
42 #+begin_src clojure
43 (in-ns 'cortex.proprioception)
21 44
22 (defn right-handed? 45 (defn right-handed?
23 "true iff the three vectors form a right handed coordinate 46 "true iff the three vectors form a right handed coordinate
24 system. The three vectors do not have to be normalized or 47 system. The three vectors do not have to be normalized or
25 orthogonal." 48 orthogonal."
26 [vec1 vec2 vec3] 49 [vec1 vec2 vec3]
27 (< 0 (.dot (.cross vec1 vec2) vec3))) 50 (< 0 (.dot (.cross vec1 vec2) vec3)))
28 51
29 (defn absolute-angle 52 (defn absolute-angle
30 "The angle between 'vec1 and 'vec2. Positive if the angle to get 53 "The angle between 'vec1 and 'vec2. Positive if the angle to get
32 otherwise." 55 otherwise."
33 [vec1 vec2 axis] 56 [vec1 vec2 axis]
34 (let [angle (.angleBetween vec1 vec2)] 57 (let [angle (.angleBetween vec1 vec2)]
35 (if (right-handed? vec1 vec2 axis) 58 (if (right-handed? vec1 vec2 axis)
36 angle (- (* 2 Math/PI) angle)))) 59 angle (- (* 2 Math/PI) angle))))
37 60 #+end_src
38 (defn proprioception-fn 61
62 #+name: proprioception
63 #+begin_src clojure
64 (defn proprioception-kernel
39 "Returns a function which returns proprioceptive sensory data when 65 "Returns a function which returns proprioceptive sensory data when
40 called inside a running simulation." 66 called inside a running simulation."
41 [#^Node parts #^Node joint] 67 [#^Node parts #^Node joint]
42 (let [[obj-a obj-b] (joint-targets parts joint) 68 (let [[obj-a obj-b] (joint-targets parts joint)
43 joint-rot (.getWorldRotation joint) 69 joint-rot (.getWorldRotation joint)
78 sequence of functions, one for each child of the \"joints\" node in 104 sequence of functions, one for each child of the \"joints\" node in
79 the creature, which each report proprioceptive information about 105 the creature, which each report proprioceptive information about
80 that joint." 106 that joint."
81 [#^Node creature] 107 [#^Node creature]
82 ;; extract the body's joints 108 ;; extract the body's joints
83 (let [senses (map (partial proprioception-fn creature) 109 (let [senses (map (partial proprioception-kernel creature)
84 (joints creature))] 110 (joints creature))]
85 (fn [] 111 (fn []
86 (map #(%) senses)))) 112 (map #(%) senses))))
87 113 #+end_src
114
115 #+name: visualize
116 #+begin_src clojure
117 (in-ns 'cortex.proprioception)
88 118
89 (defn draw-sprite [image sprite x y color ] 119 (defn draw-sprite [image sprite x y color ]
90 (dorun 120 (dorun
91 (for [[u v] sprite] 121 (for [[u v] sprite]
92 (.setRGB image (+ u x) (+ v y) color)))) 122 (.setRGB image (+ u x) (+ v y) color))))
93
94 123
95 (defn view-angle 124 (defn view-angle
96 "create a debug view of an angle" 125 "create a debug view of an angle"
97 [color] 126 [color]
98 (let [image (BufferedImage. 50 50 BufferedImage/TYPE_INT_RGB) 127 (let [image (BufferedImage. 50 50 BufferedImage/TYPE_INT_RGB)
141 (defn view-proprioception 170 (defn view-proprioception
142 "Creates a function which accepts a list of proprioceptive data and 171 "Creates a function which accepts a list of proprioceptive data and
143 display each element of the list to the screen as an image." 172 display each element of the list to the screen as an image."
144 [] 173 []
145 (view-sense proprioception-display-kernel)) 174 (view-sense proprioception-display-kernel))
146 175 #+end_src
147 176
148 177 #+name: proprioception-header
178 #+begin_src clojure
179 (ns cortex.proprioception
180 "Simulate the sense of proprioception (ability to detect the
181 relative positions of body parts with repsect to other body parts)
182 in jMonkeyEngine3. Reads specially prepared blender files to
183 automatically generate proprioceptive senses."
184 (:use (cortex world util sense body))
185 (:use clojure.contrib.def)
186 (:import com.jme3.scene.Node)
187 (:import java.awt.image.BufferedImage)
188 (:import (com.jme3.math Vector3f Quaternion)))
149 #+end_src 189 #+end_src
150 190
151 #+name: test-body 191 #+name: test-body
152 #+begin_src clojure 192 #+begin_src clojure
153
154
155 (defn test-proprioception 193 (defn test-proprioception
156 "Testing proprioception: 194 "Testing proprioception:
157 You should see two foating bars, and a printout of pitch, yaw, and 195 You should see two foating bars, and a printout of pitch, yaw, and
158 roll. Pressing key-r/key-t should move the blue bar up and down and 196 roll. Pressing key-r/key-t should move the blue bar up and down and
159 change only the value of pitch. key-f/key-g moves it side to side 197 change only the value of pitch. key-f/key-g moves it side to side
244 #+end_src 282 #+end_src
245 283
246 284
247 * COMMENT generate source 285 * COMMENT generate source
248 #+begin_src clojure :tangle ../src/cortex/proprioception.clj 286 #+begin_src clojure :tangle ../src/cortex/proprioception.clj
287 <<proprioception-header>>
288 <<helpers>>
249 <<proprioception>> 289 <<proprioception>>
250 #+end_src 290 <<visualize>>
291 #+end_src