changeset 190:2902aca33c6e

added proprioception debug view.
author Robert McIntyre <rlm@mit.edu>
date Sat, 04 Feb 2012 10:26:11 -0700
parents facc2ef3fe5c
children 66fbab414d45
files org/proprioception.org org/test-creature.org
diffstat 2 files changed, 39 insertions(+), 20 deletions(-) [+]
line wrap: on
line diff
     1.1 --- a/org/proprioception.org	Sat Feb 04 10:13:15 2012 -0700
     1.2 +++ b/org/proprioception.org	Sat Feb 04 10:26:11 2012 -0700
     1.3 @@ -16,6 +16,7 @@
     1.4    (:use (cortex world util sense body))
     1.5    (:use clojure.contrib.def)
     1.6    (:import com.jme3.scene.Node)
     1.7 +  (:import java.awt.image.BufferedImage)
     1.8    (:import (com.jme3.math Vector3f Quaternion)))
     1.9  
    1.10  (defn right-handed?
    1.11 @@ -85,13 +86,12 @@
    1.12        (map #(%) senses))))
    1.13  
    1.14  
    1.15 -(import java.awt.image.BufferedImage)
    1.16 -
    1.17  (defn draw-sprite [image sprite x y color ]
    1.18    (dorun
    1.19     (for [[u v] sprite]
    1.20       (.setRGB image (+ u x) (+ v y) color))))
    1.21  
    1.22 +
    1.23  (defn view-angle
    1.24    "create a debug view of an angle"
    1.25    [color]
    1.26 @@ -109,23 +109,42 @@
    1.27            (reset! previous position))
    1.28          image))))
    1.29  
    1.30 -(defn proprioception-debug-window
    1.31 +
    1.32 +(defn proprioception-display-kernel
    1.33 +  "Display proprioception angles in a BufferedImage"
    1.34 +  [[h p r]]
    1.35 +  (let [image (BufferedImage. 50 50 BufferedImage/TYPE_INT_RGB)
    1.36 +        previous-heading (atom [25 25])
    1.37 +        previous-pitch   (atom [25 25])
    1.38 +        previous-roll    (atom [25 25])
    1.39 +        
    1.40 +        heading-sprite [[0 0] [0 1] [0 -1] [-1 0] [1 0]]
    1.41 +        pitch-sprite   [[0 0] [0 1] [0 -1] [-1 0] [1 0]]
    1.42 +        roll-sprite    [[0 0] [0 1] [0 -1] [-1 0] [1 0]]
    1.43 +        draw-angle
    1.44 +        (fn [angle sprite previous color]
    1.45 +          (let [angle (float angle)]
    1.46 +            (let [position
    1.47 +                  [(+ 25 (int (* 20 (Math/cos angle))))
    1.48 +                   (+ 25 (int (* -20 (Math/sin angle))))]]
    1.49 +              (draw-sprite image sprite (@previous 0) (@previous 1) 0x000000)
    1.50 +              (draw-sprite image sprite (position 0) (position 1) color)
    1.51 +              (reset! previous position))
    1.52 +            image))]
    1.53 +    (dorun (map draw-angle
    1.54 +                [h p r]
    1.55 +                [heading-sprite pitch-sprite roll-sprite]
    1.56 +                [previous-heading previous-pitch previous-roll]
    1.57 +                [0xFF0000 0x00FF00 0xFFFFFF]))
    1.58 +    image))
    1.59 +                
    1.60 +(defn view-proprioception
    1.61 +  "Creates a function which accepts a list of proprioceptive data and
    1.62 +   display each element of the list to the screen as an image."
    1.63    []
    1.64 -  (let [heading (view-angle 0xFF0000)
    1.65 -        pitch (view-angle 0x00FF00)
    1.66 -        roll (view-angle 0xFFFFFF)
    1.67 -        v-heading (view-image)
    1.68 -        v-pitch (view-image)
    1.69 -        v-roll (view-image)
    1.70 -        ]
    1.71 -    (fn [prop-data]
    1.72 -      (dorun
    1.73 -       (map
    1.74 -        (fn [[h p r]]
    1.75 -          (v-heading (heading h))
    1.76 -          (v-pitch (pitch p))
    1.77 -          (v-roll (roll r)))
    1.78 -        prop-data)))))
    1.79 +  (view-sense proprioception-display-kernel))
    1.80 +  
    1.81 +  
    1.82  
    1.83  #+end_src
    1.84  
     2.1 --- a/org/test-creature.org	Sat Feb 04 10:13:15 2012 -0700
     2.2 +++ b/org/test-creature.org	Sat Feb 04 10:26:11 2012 -0700
     2.3 @@ -145,7 +145,7 @@
     2.4          hearing-display (view-hearing)
     2.5  
     2.6          prop (proprioception! creature)
     2.7 -        prop-debug (proprioception-debug-window)
     2.8 +        prop-display (view-proprioception)
     2.9  
    2.10          muscle-fns (movement! creature)
    2.11  
    2.12 @@ -210,7 +210,7 @@
    2.13            ;;(dorun 
    2.14            ;; (map #(%1 %2) touch-nerves (repeat (.getRootNode world))))
    2.15            
    2.16 -          (prop-debug (prop))
    2.17 +          (prop-display (prop))
    2.18            
    2.19            (touch-display (map #(% (.getRootNode world)) touch))
    2.20