diff org/proprioception.org @ 173:1943b3f581c2

renamed proprioception functions
author Robert McIntyre <rlm@mit.edu>
date Sat, 04 Feb 2012 06:26:40 -0700
parents 84c67be00abe
children 136349ac6972
line wrap: on
line diff
     1.1 --- a/org/proprioception.org	Sat Feb 04 05:08:35 2012 -0700
     1.2 +++ b/org/proprioception.org	Sat Feb 04 06:26:40 2012 -0700
     1.3 @@ -9,20 +9,42 @@
     1.4  #+name: proprioception
     1.5  #+begin_src clojure
     1.6  (ns cortex.proprioception
     1.7 -  (:use (cortex world util sense body)))
     1.8 +  "Simulate the sense of proprioception (ability to detect the
     1.9 +  relative positions of body parts with repsect to other body parts)
    1.10 +  in jMonkeyEngine3. Reads specially prepared blender files to
    1.11 +  automatically generate proprioceptive senses."
    1.12 +  (:use (cortex world util sense body))
    1.13 +  (:use clojure.contrib.def))
    1.14 +        
    1.15  
    1.16  (cortex.import/mega-import-jme3)
    1.17  
    1.18 -(defn right-handed? [vec1 vec2 vec3]
    1.19 +(defvar 
    1.20 +  ^{:arglists '([creature])}
    1.21 +  joints
    1.22 +  (sense-nodes "joints")
    1.23 +  "Return the children of the creature's \"joints\" node.")
    1.24 +
    1.25 +(defn right-handed?
    1.26 +  "true iff the three vectors form a right handed coordinate
    1.27 +  system. The three vectors do not have to be normalized or
    1.28 +  orthogonal."
    1.29 +  [vec1 vec2 vec3]
    1.30    (< 0 (.dot (.cross vec1 vec2) vec3)))
    1.31  
    1.32 -(defn absolute-angle [vec1 vec2 axis]
    1.33 +(defn absolute-angle
    1.34 +  "The angle between 'vec1 and 'vec2. Positive if the angle to get
    1.35 +  from 'vec1 to 'vec2 is counterclockwise around 'axis, and negative
    1.36 +  otherwise." 
    1.37 +  [vec1 vec2 axis]
    1.38    (let [angle (.angleBetween vec1 vec2)]
    1.39      (if (right-handed? vec1 vec2 axis)
    1.40        angle (- (* 2 Math/PI) angle))))
    1.41  
    1.42 -
    1.43 -(defn joint-proprioception [#^Node parts #^Node joint]
    1.44 +(defn proprioception-fn
    1.45 +  "Returns a function which returns proprioceptive sensory data when
    1.46 +  called inside a running simulation."
    1.47 +  [#^Node parts #^Node joint]
    1.48    (let [[obj-a obj-b] (joint-targets parts joint)
    1.49          joint-rot (.getWorldRotation joint)
    1.50          x0 (.mult joint-rot Vector3f/UNIT_X)
    1.51 @@ -55,16 +77,17 @@
    1.52                 (let [cross (.normalize (.cross X x))]
    1.53                   (if (= 0 (.length cross)) y cross))))
    1.54              roll (absolute-angle (.mult reverse Y) y x)]
    1.55 -        
    1.56          [heading pitch roll]))))
    1.57  
    1.58 -(defn proprioception
    1.59 -  "Create a function that provides proprioceptive information about an
    1.60 -  entire body."
    1.61 +(defn proprioception!
    1.62 +  "Endow the creature with the sense of proprioception. Returns a
    1.63 +   sequence of functions, one for each child of the \"joints\" node in
    1.64 +   the creature, which each report proprioceptive information about
    1.65 +   that joint."
    1.66    [#^Node creature]
    1.67    ;; extract the body's joints
    1.68 -  (let [joints (creature-joints creature)
    1.69 -        senses (map (partial joint-proprioception creature) joints)]
    1.70 +  (let [senses (map (partial proprioception-fn creature)
    1.71 +                    (joints creature))]
    1.72      (fn []
    1.73        (map #(%) senses))))
    1.74