comparison org/touch.org @ 244:f23217324f72

changed semantics of feeler lengths
author Robert McIntyre <rlm@mit.edu>
date Sun, 12 Feb 2012 14:29:09 -0700
parents f33fec68f775
children 102ac596cc3f
comparison
equal deleted inserted replaced
243:f33fec68f775 244:f23217324f72
3 #+email: rlm@mit.edu 3 #+email: rlm@mit.edu
4 #+description: Simulated touch for AI research using JMonkeyEngine and clojure. 4 #+description: Simulated touch for AI research using JMonkeyEngine and clojure.
5 #+keywords: simulation, tactile sense, jMonkeyEngine3, clojure 5 #+keywords: simulation, tactile sense, 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
9
10 8
11 * Touch 9 * Touch
12 10
13 Touch is critical to navigation and spatial reasoning and as such I 11 Touch is critical to navigation and spatial reasoning and as such I
14 need a simulated version of it to give to my AI creatures. 12 need a simulated version of it to give to my AI creatures.
116 #+begin_src clojure 114 #+begin_src clojure
117 (in-ns 'cortex.touch) 115 (in-ns 'cortex.touch)
118 116
119 (declare touch-topology feelers set-ray) 117 (declare touch-topology feelers set-ray)
120 118
121 (defn set-ray [#^Ray ray #^Matrix4f transform #^Vector3f origin 119 (defn set-ray [#^Ray ray #^Matrix4f transform
122 #^Vector3f tip length] 120 #^Vector3f origin #^Vector3f tip]
123 ;; Doing everything locally recduces garbage collection by enough to 121 ;; Doing everything locally recduces garbage collection by enough to
124 ;; be worth it. 122 ;; be worth it.
125 (.mult transform origin (.getOrigin ray)) 123 (.mult transform origin (.getOrigin ray))
126 124
127 (.mult transform tip (.getDirection ray)) 125 (.mult transform tip (.getDirection ray))
128 (.subtractLocal (.getDirection ray) (.getOrigin ray)) 126 (.subtractLocal (.getDirection ray) (.getOrigin ray)))
129 (.setLimit ray length))
130 127
131 (defn touch-kernel 128 (defn touch-kernel
132 "Constructs a function which will return tactile sensory data from 129 "Constructs a function which will return tactile sensory data from
133 'geo when called from inside a running simulation" 130 'geo when called from inside a running simulation"
134 [#^Geometry geo] 131 [#^Geometry geo]
135 (if-let 132 (if-let
136 [profile (tactile-sensor-profile geo)] 133 [profile (tactile-sensor-profile geo)]
137 (let [ray-reference-origins (feeler-origins geo profile) 134 (let [ray-reference-origins (feeler-origins geo profile)
138 ray-reference-tips (feeler-tips geo profile) 135 ray-reference-tips (feeler-tips geo profile)
139 ray-lengths (repeat 9000 0.1) 136 ray-length (tactile-scale geo)
140 current-rays (map (fn [_] (Ray.)) ray-reference-origins) 137 current-rays (map (fn [_] (Ray.)) ray-reference-origins)
141 topology (touch-topology geo profile)] 138 topology (touch-topology geo profile)]
139 (dorun (map #(.setLimit % ray-length) current-rays))
142 (fn [node] 140 (fn [node]
143 (let [transform (.getWorldMatrix geo)] 141 (let [transform (.getWorldMatrix geo)]
144 (dorun 142 (dorun
145 (map (fn [ray ref-origin ref-tip length] 143 (map (fn [ray ref-origin ref-tip]
146 (set-ray ray transform ref-origin ref-tip length)) 144 (set-ray ray transform ref-origin ref-tip))
147 current-rays ray-reference-origins 145 current-rays ray-reference-origins
148 ray-reference-tips ray-lengths)) 146 ray-reference-tips))
149 (vector 147 (vector
150 topology 148 topology
151 (vec 149 (vec
152 (for [ray current-rays] 150 (for [ray current-rays]
153 (do 151 (do
478 touch-display (view-touch)] 476 touch-display (view-touch)]
479 (world (nodify [the-worm (floor)]) 477 (world (nodify [the-worm (floor)])
480 standard-debug-controls 478 standard-debug-controls
481 479
482 (fn [world] 480 (fn [world]
481 (speed-up world)
483 (light-up-everything world)) 482 (light-up-everything world))
484 483
485 (fn [world tpf] 484 (fn [world tpf]
486 485 (touch-display (map #(% (.getRootNode world)) touch))
487
488 (dorun (map #(% (.getRootNode world)) touch))
489
490
491 )))) 486 ))))
492 #+end_src 487 #+end_src
493 * Source Listing 488 * Source Listing
494 * Next 489 * Next
495 490