comparison org/proprioception.org @ 190:2902aca33c6e

added proprioception debug view.
author Robert McIntyre <rlm@mit.edu>
date Sat, 04 Feb 2012 10:26:11 -0700
parents 0b9ae09eaec3
children df46a609fed9
comparison
equal deleted inserted replaced
189:facc2ef3fe5c 190:2902aca33c6e
14 in jMonkeyEngine3. Reads specially prepared blender files to 14 in jMonkeyEngine3. Reads specially prepared blender files to
15 automatically generate proprioceptive senses." 15 automatically generate proprioceptive senses."
16 (:use (cortex world util sense body)) 16 (:use (cortex world util sense body))
17 (:use clojure.contrib.def) 17 (:use clojure.contrib.def)
18 (:import com.jme3.scene.Node) 18 (:import com.jme3.scene.Node)
19 (:import java.awt.image.BufferedImage)
19 (:import (com.jme3.math Vector3f Quaternion))) 20 (:import (com.jme3.math Vector3f Quaternion)))
20 21
21 (defn right-handed? 22 (defn right-handed?
22 "true iff the three vectors form a right handed coordinate 23 "true iff the three vectors form a right handed coordinate
23 system. The three vectors do not have to be normalized or 24 system. The three vectors do not have to be normalized or
83 (joints creature))] 84 (joints creature))]
84 (fn [] 85 (fn []
85 (map #(%) senses)))) 86 (map #(%) senses))))
86 87
87 88
88 (import java.awt.image.BufferedImage)
89
90 (defn draw-sprite [image sprite x y color ] 89 (defn draw-sprite [image sprite x y color ]
91 (dorun 90 (dorun
92 (for [[u v] sprite] 91 (for [[u v] sprite]
93 (.setRGB image (+ u x) (+ v y) color)))) 92 (.setRGB image (+ u x) (+ v y) color))))
93
94 94
95 (defn view-angle 95 (defn view-angle
96 "create a debug view of an angle" 96 "create a debug view of an angle"
97 [color] 97 [color]
98 (let [image (BufferedImage. 50 50 BufferedImage/TYPE_INT_RGB) 98 (let [image (BufferedImage. 50 50 BufferedImage/TYPE_INT_RGB)
107 (draw-sprite image sprite (@previous 0) (@previous 1) 0x000000) 107 (draw-sprite image sprite (@previous 0) (@previous 1) 0x000000)
108 (draw-sprite image sprite (position 0) (position 1) color) 108 (draw-sprite image sprite (position 0) (position 1) color)
109 (reset! previous position)) 109 (reset! previous position))
110 image)))) 110 image))))
111 111
112 (defn proprioception-debug-window 112
113 (defn proprioception-display-kernel
114 "Display proprioception angles in a BufferedImage"
115 [[h p r]]
116 (let [image (BufferedImage. 50 50 BufferedImage/TYPE_INT_RGB)
117 previous-heading (atom [25 25])
118 previous-pitch (atom [25 25])
119 previous-roll (atom [25 25])
120
121 heading-sprite [[0 0] [0 1] [0 -1] [-1 0] [1 0]]
122 pitch-sprite [[0 0] [0 1] [0 -1] [-1 0] [1 0]]
123 roll-sprite [[0 0] [0 1] [0 -1] [-1 0] [1 0]]
124 draw-angle
125 (fn [angle sprite previous color]
126 (let [angle (float angle)]
127 (let [position
128 [(+ 25 (int (* 20 (Math/cos angle))))
129 (+ 25 (int (* -20 (Math/sin angle))))]]
130 (draw-sprite image sprite (@previous 0) (@previous 1) 0x000000)
131 (draw-sprite image sprite (position 0) (position 1) color)
132 (reset! previous position))
133 image))]
134 (dorun (map draw-angle
135 [h p r]
136 [heading-sprite pitch-sprite roll-sprite]
137 [previous-heading previous-pitch previous-roll]
138 [0xFF0000 0x00FF00 0xFFFFFF]))
139 image))
140
141 (defn view-proprioception
142 "Creates a function which accepts a list of proprioceptive data and
143 display each element of the list to the screen as an image."
113 [] 144 []
114 (let [heading (view-angle 0xFF0000) 145 (view-sense proprioception-display-kernel))
115 pitch (view-angle 0x00FF00) 146
116 roll (view-angle 0xFFFFFF) 147
117 v-heading (view-image)
118 v-pitch (view-image)
119 v-roll (view-image)
120 ]
121 (fn [prop-data]
122 (dorun
123 (map
124 (fn [[h p r]]
125 (v-heading (heading h))
126 (v-pitch (pitch p))
127 (v-roll (roll r)))
128 prop-data)))))
129 148
130 #+end_src 149 #+end_src
131 150
132 * COMMENT generate source 151 * COMMENT generate source
133 #+begin_src clojure :tangle ../src/cortex/proprioception.clj 152 #+begin_src clojure :tangle ../src/cortex/proprioception.clj