comparison thesis/cortex.org @ 508:c11d3fc3e6f0

inspecting cortex section.
author Robert McIntyre <rlm@mit.edu>
date Sun, 30 Mar 2014 01:07:19 -0400
parents f2f029e1a6a9
children 81c845a91378
comparison
equal deleted inserted replaced
507:f2f029e1a6a9 508:c11d3fc3e6f0
639 #+caption: of muscles, ears, eyes, or joints. 639 #+caption: of muscles, ears, eyes, or joints.
640 #+name: sense-nodes 640 #+name: sense-nodes
641 #+ATTR_LaTeX: :width 10cm 641 #+ATTR_LaTeX: :width 10cm
642 [[./images/empty-sense-nodes.png]] 642 [[./images/empty-sense-nodes.png]]
643 643
644 ** COMMENT Bodies are composed of segments connected by joints 644 ** Bodies are composed of segments connected by joints
645 645
646 Blender is a general purpose animation tool, which has been used in 646 Blender is a general purpose animation tool, which has been used in
647 the past to create high quality movies such as Sintel 647 the past to create high quality movies such as Sintel
648 \cite{sintel}. Though Blender can model and render even complicated 648 \cite{blender}. Though Blender can model and render even complicated
649 things like water, it is crucual to keep models that are meant to 649 things like water, it is crucual to keep models that are meant to
650 be simulated as creatures simple. =Bullet=, which =CORTEX= uses 650 be simulated as creatures simple. =Bullet=, which =CORTEX= uses
651 though jMonkeyEngine3, is a rigid-body physics system. This offers 651 though jMonkeyEngine3, is a rigid-body physics system. This offers
652 a compromise between the expressiveness of a game level and the 652 a compromise between the expressiveness of a game level and the
653 speed at which it can be simulated, and it means that creatures 653 speed at which it can be simulated, and it means that creatures
955 #+caption: simulation environment. 955 #+caption: simulation environment.
956 #+name: name 956 #+name: name
957 #+ATTR_LaTeX: :width 15cm 957 #+ATTR_LaTeX: :width 15cm
958 [[./images/physical-hand.png]] 958 [[./images/physical-hand.png]]
959 959
960 ** COMMENT Eyes reuse standard video game components 960 ** Eyes reuse standard video game components
961 961
962 Vision is one of the most important senses for humans, so I need to 962 Vision is one of the most important senses for humans, so I need to
963 build a simulated sense of vision for my AI. I will do this with 963 build a simulated sense of vision for my AI. I will do this with
964 simulated eyes. Each eye can be independently moved and should see 964 simulated eyes. Each eye can be independently moved and should see
965 its own version of the world depending on where it is. 965 its own version of the world depending on where it is.
989 is a =FrameBuffer= which represents the rendered image in the GPU. 989 is a =FrameBuffer= which represents the rendered image in the GPU.
990 990
991 #+caption: =ViewPorts= are cameras in the world. During each frame, 991 #+caption: =ViewPorts= are cameras in the world. During each frame,
992 #+caption: the =RenderManager= records a snapshot of what each view 992 #+caption: the =RenderManager= records a snapshot of what each view
993 #+caption: is currently seeing; these snapshots are =FrameBuffer= objects. 993 #+caption: is currently seeing; these snapshots are =FrameBuffer= objects.
994 #+name: name 994 #+name: rendermanagers
995 #+ATTR_LaTeX: :width 10cm 995 #+ATTR_LaTeX: :width 10cm
996 [[../images/diagram_rendermanager2.png]] 996 [[./images/diagram_rendermanager2.png]]
997 997
998 Each =ViewPort= can have any number of attached =SceneProcessor= 998 Each =ViewPort= can have any number of attached =SceneProcessor=
999 objects, which are called every time a new frame is rendered. A 999 objects, which are called every time a new frame is rendered. A
1000 =SceneProcessor= receives its =ViewPort's= =FrameBuffer= and can do 1000 =SceneProcessor= receives its =ViewPort's= =FrameBuffer= and can do
1001 whatever it wants to the data. Often this consists of invoking GPU 1001 whatever it wants to the data. Often this consists of invoking GPU
1163 #+caption: This is the core of vision in =CORTEX=. A given eye node 1163 #+caption: This is the core of vision in =CORTEX=. A given eye node
1164 #+caption: is converted into a function that returns visual 1164 #+caption: is converted into a function that returns visual
1165 #+caption: information from the simulation. 1165 #+caption: information from the simulation.
1166 #+name: vision-kernel 1166 #+name: vision-kernel
1167 #+begin_listing clojure 1167 #+begin_listing clojure
1168 #+BEGIN_SRC clojure
1168 (defn vision-kernel 1169 (defn vision-kernel
1169 "Returns a list of functions, each of which will return a color 1170 "Returns a list of functions, each of which will return a color
1170 channel's worth of visual information when called inside a running 1171 channel's worth of visual information when called inside a running
1171 simulation." 1172 simulation."
1172 [#^Node creature #^Spatial eye & {skip :skip :or {skip 0}}] 1173 [#^Node creature #^Spatial eye & {skip :skip :or {skip 0}}]
1203 (pixel-sense 1204 (pixel-sense
1204 sensitivity 1205 sensitivity
1205 (.getRGB @vision-image x y)))))) 1206 (.getRGB @vision-image x y))))))
1206 register-eye!))) 1207 register-eye!)))
1207 retinal-map)))) 1208 retinal-map))))
1209 #+END_SRC
1208 #+end_listing 1210 #+end_listing
1209 1211
1210 Note that since each of the functions generated by =vision-kernel= 1212 Note that since each of the functions generated by =vision-kernel=
1211 shares the same =register-eye!= function, the eye will be 1213 shares the same =register-eye!= function, the eye will be
1212 registered only once the first time any of the functions from the 1214 registered only once the first time any of the functions from the
1222 #+caption: With =vision!=, =CORTEX= is already a fine simulation 1224 #+caption: With =vision!=, =CORTEX= is already a fine simulation
1223 #+caption: environment for experimenting with different types of 1225 #+caption: environment for experimenting with different types of
1224 #+caption: eyes. 1226 #+caption: eyes.
1225 #+name: vision! 1227 #+name: vision!
1226 #+begin_listing clojure 1228 #+begin_listing clojure
1229 #+BEGIN_SRC clojure
1227 (defn vision! 1230 (defn vision!
1228 "Returns a list of functions, each of which returns visual sensory 1231 "Returns a list of functions, each of which returns visual sensory
1229 data when called inside a running simulation." 1232 data when called inside a running simulation."
1230 [#^Node creature & {skip :skip :or {skip 0}}] 1233 [#^Node creature & {skip :skip :or {skip 0}}]
1231 (reduce 1234 (reduce
1232 concat 1235 concat
1233 (for [eye (eyes creature)] 1236 (for [eye (eyes creature)]
1234 (vision-kernel creature eye)))) 1237 (vision-kernel creature eye))))
1238 #+END_SRC
1235 #+end_listing 1239 #+end_listing
1236 1240
1237 #+caption: Simulated vision with a test creature and the 1241 #+caption: Simulated vision with a test creature and the
1238 #+caption: human-like eye approximation. Notice how each channel 1242 #+caption: human-like eye approximation. Notice how each channel
1239 #+caption: of the eye responds differently to the differently 1243 #+caption: of the eye responds differently to the differently
1252 1256
1253 This vision code has already been absorbed by the jMonkeyEngine 1257 This vision code has already been absorbed by the jMonkeyEngine
1254 community and is now (in modified form) part of a system for 1258 community and is now (in modified form) part of a system for
1255 capturing in-game video to a file. 1259 capturing in-game video to a file.
1256 1260
1257 ** COMMENT Hearing is hard; =CORTEX= does it right 1261 ** Hearing is hard; =CORTEX= does it right
1258 1262
1259 At the end of this section I will have simulated ears that work the 1263 At the end of this section I will have simulated ears that work the
1260 same way as the simulated eyes in the last section. I will be able to 1264 same way as the simulated eyes in the last section. I will be able to
1261 place any number of ear-nodes in a blender file, and they will bind to 1265 place any number of ear-nodes in a blender file, and they will bind to
1262 the closest physical object and follow it as it moves around. Each ear 1266 the closest physical object and follow it as it moves around. Each ear
1373 1377
1374 #+caption: Program for extending =OpenAL= to support multiple 1378 #+caption: Program for extending =OpenAL= to support multiple
1375 #+caption: listeners via context copying/switching. 1379 #+caption: listeners via context copying/switching.
1376 #+name: sync-openal-sources 1380 #+name: sync-openal-sources
1377 #+begin_listing C 1381 #+begin_listing C
1382 #+BEGIN_SRC C
1378 void syncSources(ALsource *masterSource, ALsource *slaveSource, 1383 void syncSources(ALsource *masterSource, ALsource *slaveSource,
1379 ALCcontext *masterCtx, ALCcontext *slaveCtx){ 1384 ALCcontext *masterCtx, ALCcontext *slaveCtx){
1380 ALuint master = masterSource->source; 1385 ALuint master = masterSource->source;
1381 ALuint slave = slaveSource->source; 1386 ALuint slave = slaveSource->source;
1382 ALCcontext *current = alcGetCurrentContext(); 1387 ALCcontext *current = alcGetCurrentContext();
1436 } 1441 }
1437 } 1442 }
1438 // Restore whatever context was previously active. 1443 // Restore whatever context was previously active.
1439 alcMakeContextCurrent(current); 1444 alcMakeContextCurrent(current);
1440 } 1445 }
1446 #+END_SRC
1441 #+end_listing 1447 #+end_listing
1442 1448
1443 With this special context-switching device, and some ugly JNI 1449 With this special context-switching device, and some ugly JNI
1444 bindings that are not worth mentioning, =CORTEX= gains the ability 1450 bindings that are not worth mentioning, =CORTEX= gains the ability
1445 to access multiple sound streams from =OpenAL=. 1451 to access multiple sound streams from =OpenAL=.
1447 #+caption: Program to create an ear from a blender empty node. The ear 1453 #+caption: Program to create an ear from a blender empty node. The ear
1448 #+caption: follows around the nearest physical object and passes 1454 #+caption: follows around the nearest physical object and passes
1449 #+caption: all sensory data to a continuation function. 1455 #+caption: all sensory data to a continuation function.
1450 #+name: add-ear 1456 #+name: add-ear
1451 #+begin_listing clojure 1457 #+begin_listing clojure
1458 #+BEGIN_SRC clojure
1452 (defn add-ear! 1459 (defn add-ear!
1453 "Create a Listener centered on the current position of 'ear 1460 "Create a Listener centered on the current position of 'ear
1454 which follows the closest physical node in 'creature and 1461 which follows the closest physical node in 'creature and
1455 sends sound data to 'continuation." 1462 sends sound data to 'continuation."
1456 [#^Application world #^Node creature #^Spatial ear continuation] 1463 [#^Application world #^Node creature #^Spatial ear continuation]
1462 (.setRotation lis (.getWorldRotation ear)) 1469 (.setRotation lis (.getWorldRotation ear))
1463 (bind-sense target lis) 1470 (bind-sense target lis)
1464 (update-listener-velocity! target lis) 1471 (update-listener-velocity! target lis)
1465 (.addListener audio-renderer lis) 1472 (.addListener audio-renderer lis)
1466 (.registerSoundProcessor audio-renderer lis sp))) 1473 (.registerSoundProcessor audio-renderer lis sp)))
1474 #+END_SRC
1467 #+end_listing 1475 #+end_listing
1468
1469 1476
1470 The =Send= device, unlike most of the other devices in =OpenAL=, 1477 The =Send= device, unlike most of the other devices in =OpenAL=,
1471 does not render sound unless asked. This enables the system to 1478 does not render sound unless asked. This enables the system to
1472 slow down or speed up depending on the needs of the AIs who are 1479 slow down or speed up depending on the needs of the AIs who are
1473 using it to listen. If the device tried to render samples in 1480 using it to listen. If the device tried to render samples in
1476 all of the sound in its environment! 1483 all of the sound in its environment!
1477 1484
1478 #+caption: Program to enable arbitrary hearing in =CORTEX= 1485 #+caption: Program to enable arbitrary hearing in =CORTEX=
1479 #+name: hearing 1486 #+name: hearing
1480 #+begin_listing clojure 1487 #+begin_listing clojure
1488 #+BEGIN_SRC clojure
1481 (defn hearing-kernel 1489 (defn hearing-kernel
1482 "Returns a function which returns auditory sensory data when called 1490 "Returns a function which returns auditory sensory data when called
1483 inside a running simulation." 1491 inside a running simulation."
1484 [#^Node creature #^Spatial ear] 1492 [#^Node creature #^Spatial ear]
1485 (let [hearing-data (atom []) 1493 (let [hearing-data (atom [])
1502 hearing. Will return a sequence of functions, one for each ear, 1510 hearing. Will return a sequence of functions, one for each ear,
1503 which when called will return the auditory data from that ear." 1511 which when called will return the auditory data from that ear."
1504 [#^Node creature] 1512 [#^Node creature]
1505 (for [ear (ears creature)] 1513 (for [ear (ears creature)]
1506 (hearing-kernel creature ear))) 1514 (hearing-kernel creature ear)))
1515 #+END_SRC
1507 #+end_listing 1516 #+end_listing
1508 1517
1509 Armed with these functions, =CORTEX= is able to test possibly the 1518 Armed with these functions, =CORTEX= is able to test possibly the
1510 first ever instance of multiple listeners in a video game engine 1519 first ever instance of multiple listeners in a video game engine
1511 based simulation! 1520 based simulation!
1513 #+caption: Here a simple creature responds to sound by changing 1522 #+caption: Here a simple creature responds to sound by changing
1514 #+caption: its color from gray to green when the total volume 1523 #+caption: its color from gray to green when the total volume
1515 #+caption: goes over a threshold. 1524 #+caption: goes over a threshold.
1516 #+name: sound-test 1525 #+name: sound-test
1517 #+begin_listing java 1526 #+begin_listing java
1527 #+BEGIN_SRC java
1518 /** 1528 /**
1519 * Respond to sound! This is the brain of an AI entity that 1529 * Respond to sound! This is the brain of an AI entity that
1520 * hears its surroundings and reacts to them. 1530 * hears its surroundings and reacts to them.
1521 */ 1531 */
1522 public void process(ByteBuffer audioSamples, 1532 public void process(ByteBuffer audioSamples,
1537 entity.getMaterial().setColor("Color", ColorRGBA.Green); 1547 entity.getMaterial().setColor("Color", ColorRGBA.Green);
1538 } 1548 }
1539 else { 1549 else {
1540 entity.getMaterial().setColor("Color", ColorRGBA.Gray); 1550 entity.getMaterial().setColor("Color", ColorRGBA.Gray);
1541 } 1551 }
1552 #+END_SRC
1542 #+end_listing 1553 #+end_listing
1543 1554
1544 #+caption: First ever simulation of multiple listerners in =CORTEX=. 1555 #+caption: First ever simulation of multiple listerners in =CORTEX=.
1545 #+caption: Each cube is a creature which processes sound data with 1556 #+caption: Each cube is a creature which processes sound data with
1546 #+caption: the =process= function from listing \ref{sound-test}. 1557 #+caption: the =process= function from listing \ref{sound-test}.
2356 #+caption: The hand then uses its muscles to launch the cube! 2367 #+caption: The hand then uses its muscles to launch the cube!
2357 #+name: integration 2368 #+name: integration
2358 #+ATTR_LaTeX: :width 16cm 2369 #+ATTR_LaTeX: :width 16cm
2359 [[./images/integration.png]] 2370 [[./images/integration.png]]
2360 2371
2361 ** COMMENT =CORTEX= enables many possiblities for further research 2372 ** =CORTEX= enables many possiblities for further research
2362 2373
2363 Often times, the hardest part of building a system involving 2374 Often times, the hardest part of building a system involving
2364 creatures is dealing with physics and graphics. =CORTEX= removes 2375 creatures is dealing with physics and graphics. =CORTEX= removes
2365 much of this initial difficulty and leaves researchers free to 2376 much of this initial difficulty and leaves researchers free to
2366 directly pursue their ideas. I hope that even undergrads with a 2377 directly pursue their ideas. I hope that even undergrads with a