# HG changeset patch # User Robert McIntyre # Date 1396062992 14400 # Node ID a5480a06d5fe3f5e8df6ec12909462dbf9aaa8ef # Parent 76d44e969289c10449d77cd275bed20822a3fe57 first draft of proprioception complete. diff -r 76d44e969289 -r a5480a06d5fe thesis/cortex.org --- a/thesis/cortex.org Fri Mar 28 22:51:55 2014 -0400 +++ b/thesis/cortex.org Fri Mar 28 23:16:32 2014 -0400 @@ -12,6 +12,8 @@ #+caption: #+name: name #+begin_listing clojure + #+BEGIN_SRC clojure + #+END_SRC #+end_listing #+caption: @@ -2050,6 +2052,153 @@ ** Proprioception is the sense that makes everything ``real'' + Close your eyes, and touch your nose with your right index finger. + How did you do it? You could not see your hand, and neither your + hand nor your nose could use the sense of touch to guide the path + of your hand. There are no sound cues, and Taste and Smell + certainly don't provide any help. You know where your hand is + without your other senses because of Proprioception. + + Humans can sometimes loose this sense through viral infections or + damage to the spinal cord or brain, and when they do, they loose + the ability to control their own bodies without looking directly at + the 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]], a woman named Christina looses this sense and has to learn how + to move by carefully watching her arms and legs. She describes + proprioception as the "eyes of the body, the way the body sees + itself". + + Proprioception in humans is mediated by [[http://en.wikipedia.org/wiki/Articular_capsule][joint capsules]], [[http://en.wikipedia.org/wiki/Muscle_spindle][muscle + spindles]], and the [[http://en.wikipedia.org/wiki/Golgi_tendon_organ][Golgi tendon organs]]. These measure the relative + positions of each body part by monitoring muscle strain and length. + + It's clear that this is a vital sense for fluid, graceful movement. + It's also particularly easy to implement in jMonkeyEngine. + + My simulated proprioception calculates the relative angles of each + joint from the rest position defined in the blender file. This + simulates the muscle-spindles and joint capsules. I will deal with + Golgi tendon organs, which calculate muscle strain, in the next + section. + +*** Helper functions + + =absolute-angle= calculates the angle between two vectors, + relative to a third axis vector. This angle is the number of + radians you have to move counterclockwise around the axis vector + to get from the first to the second vector. It is not commutative + like a normal dot-product angle is. + + The purpose of these functions is to build a system of angle + measurement that is biologically plausable. + + + #+caption: Program to measure angles along a vector + #+name: helpers + #+begin_listing clojure + #+BEGIN_SRC clojure +(defn right-handed? + "true iff the three vectors form a right handed coordinate + system. The three vectors do not have to be normalized or + orthogonal." + [vec1 vec2 vec3] + (pos? (.dot (.cross vec1 vec2) vec3))) + +(defn absolute-angle + "The angle between 'vec1 and 'vec2 around 'axis. In the range + [0 (* 2 Math/PI)]." + [vec1 vec2 axis] + (let [angle (.angleBetween vec1 vec2)] + (if (right-handed? vec1 vec2 axis) + angle (- (* 2 Math/PI) angle)))) + #+END_SRC + #+end_listing + + + + #+caption: + #+caption: + #+caption: + #+caption: + #+name: name + #+begin_listing clojure + #+BEGIN_SRC clojure + #+END_SRC + #+end_listing + + +*** Proprioception Kernel + + Given a joint, =proprioception-kernel= produces a function that + calculates the Euler angles between the the objects the joint + connects. The only tricky part here is making the angles relative + to the joint's initial ``straightness''. + + #+caption: Program to return biologially reasonable proprioceptive + #+caption: data for each joint. + #+name: proprioception + #+begin_listing clojure + #+BEGIN_SRC clojure +(defn proprioception-kernel + "Returns a function which returns proprioceptive sensory data when + called inside a running simulation." + [#^Node parts #^Node joint] + (let [[obj-a obj-b] (joint-targets parts joint) + joint-rot (.getWorldRotation joint) + x0 (.mult joint-rot Vector3f/UNIT_X) + y0 (.mult joint-rot Vector3f/UNIT_Y) + z0 (.mult joint-rot Vector3f/UNIT_Z)] + (fn [] + (let [rot-a (.clone (.getWorldRotation obj-a)) + rot-b (.clone (.getWorldRotation obj-b)) + x (.mult rot-a x0) + y (.mult rot-a y0) + z (.mult rot-a z0) + + X (.mult rot-b x0) + Y (.mult rot-b y0) + Z (.mult rot-b z0) + heading (Math/atan2 (.dot X z) (.dot X x)) + pitch (Math/atan2 (.dot X y) (.dot X x)) + + ;; rotate x-vector back to origin + reverse + (doto (Quaternion.) + (.fromAngleAxis + (.angleBetween X x) + (let [cross (.normalize (.cross X x))] + (if (= 0 (.length cross)) y cross)))) + roll (absolute-angle (.mult reverse Y) y x)] + [heading pitch roll])))) + +(defn proprioception! + "Endow the creature with the sense of proprioception. Returns a + sequence of functions, one for each child of the \"joints\" node in + the creature, which each report proprioceptive information about + that joint." + [#^Node creature] + ;; extract the body's joints + (let [senses (map (partial proprioception-kernel creature) + (joints creature))] + (fn [] + (map #(%) senses)))) + #+END_SRC + #+end_listing + + + =proprioception!= maps =proprioception-kernel= across all the + joints of the creature. It uses the same list of joints that + =joints= uses. Proprioception is the easiest sense to implement in + =CORTEX=, and it will play a crucial role when efficiently + implementing empathy. + + #+caption: In the upper right corner, the three proprioceptive + #+caption: angle measurements are displayed. Red is yaw, Green is + #+caption: pitch, and White is roll. + #+name: proprio + #+ATTR_LaTeX: :width 11cm + [[./images/proprio.png]] + ** Muscles are both effectors and sensors ** =CORTEX= brings complex creatures to life! diff -r 76d44e969289 -r a5480a06d5fe thesis/images/proprio.png Binary file thesis/images/proprio.png has changed