changeset 202:d5c597a7aed4

writing prose for body.org
author Robert McIntyre <rlm@mit.edu>
date Wed, 08 Feb 2012 05:50:15 -0700
parents 1c915cc1118b
children 0e5d5ee5a914
files assets/Models/creature1/basic-muscle.png assets/Models/creature1/hand.png assets/Models/creature1/one.bk.blend assets/Models/creature1/one.blend assets/Models/creature1/retina-UV-small.png assets/Models/creature1/retina-small.png assets/Models/creature1/retina-small.xcf assets/Models/creature1/retina-uv.png assets/Models/creature1/retina.png assets/Models/creature1/retina.xcf assets/Models/creature1/tip.png assets/Models/creature1/tip.xcf assets/Models/creature1/touch.blend assets/Models/creature1/try-again.blend assets/Models/creature1/worm-2-UV-layout.png assets/Models/creature1/worm-2-UV-layout.svg assets/Models/test-creature/basic-muscle.png assets/Models/test-creature/hand.blend assets/Models/test-creature/hand.png assets/Models/test-creature/palm-UV.png assets/Models/test-creature/palm.png assets/Models/test-creature/palm.xcf assets/Models/test-creature/retina-UV-small.png assets/Models/test-creature/retina-small.png assets/Models/test-creature/retina-small.xcf assets/Models/test-creature/retina-uv.png assets/Models/test-creature/retina.png assets/Models/test-creature/retina.xcf assets/Models/test-creature/tip.png assets/Models/test-creature/tip.xcf assets/Models/test-creature/worm-2-UV-layout.png assets/Models/test-creature/worm-2-UV-layout.svg assets/Models/test-creature/worm.blend images/Eve.jpg images/hand-screenshot.png images/hand-screenshot0.png images/hand-screenshot1.png org/body.org org/sense.org
diffstat 39 files changed, 223 insertions(+), 58 deletions(-) [+]
line wrap: on
line diff
     1.1 Binary file assets/Models/creature1/basic-muscle.png has changed
     2.1 Binary file assets/Models/creature1/hand.png has changed
     3.1 Binary file assets/Models/creature1/one.bk.blend has changed
     4.1 Binary file assets/Models/creature1/one.blend has changed
     5.1 Binary file assets/Models/creature1/retina-UV-small.png has changed
     6.1 Binary file assets/Models/creature1/retina-small.png has changed
     7.1 Binary file assets/Models/creature1/retina-small.xcf has changed
     8.1 Binary file assets/Models/creature1/retina-uv.png has changed
     9.1 Binary file assets/Models/creature1/retina.png has changed
    10.1 Binary file assets/Models/creature1/retina.xcf has changed
    11.1 Binary file assets/Models/creature1/tip.png has changed
    12.1 Binary file assets/Models/creature1/tip.xcf has changed
    13.1 Binary file assets/Models/creature1/touch.blend has changed
    14.1 Binary file assets/Models/creature1/try-again.blend has changed
    15.1 Binary file assets/Models/creature1/worm-2-UV-layout.png has changed
    16.1 --- a/assets/Models/creature1/worm-2-UV-layout.svg	Tue Feb 07 07:13:45 2012 -0700
    16.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    16.3 @@ -1,8 +0,0 @@
    16.4 -<?xml version="1.0" standalone="no"?>
    16.5 -<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" 
    16.6 -  "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
    16.7 -<svg width="1024px" height="1024px" viewBox="0px 0px 1024px 1024px"
    16.8 -     xmlns="http://www.w3.org/2000/svg" version="1.1">
    16.9 -<desc>'try-again.blend', worm-2, (Blender 2.59 (sub 4))</desc>
   16.10 -
   16.11 -</svg>
    17.1 Binary file assets/Models/test-creature/basic-muscle.png has changed
    18.1 Binary file assets/Models/test-creature/hand.blend has changed
    19.1 Binary file assets/Models/test-creature/hand.png has changed
    20.1 Binary file assets/Models/test-creature/palm-UV.png has changed
    21.1 Binary file assets/Models/test-creature/palm.png has changed
    22.1 Binary file assets/Models/test-creature/palm.xcf has changed
    23.1 Binary file assets/Models/test-creature/retina-UV-small.png has changed
    24.1 Binary file assets/Models/test-creature/retina-small.png has changed
    25.1 Binary file assets/Models/test-creature/retina-small.xcf has changed
    26.1 Binary file assets/Models/test-creature/retina-uv.png has changed
    27.1 Binary file assets/Models/test-creature/retina.png has changed
    28.1 Binary file assets/Models/test-creature/retina.xcf has changed
    29.1 Binary file assets/Models/test-creature/tip.png has changed
    30.1 Binary file assets/Models/test-creature/tip.xcf has changed
    31.1 Binary file assets/Models/test-creature/worm-2-UV-layout.png has changed
    32.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    32.2 +++ b/assets/Models/test-creature/worm-2-UV-layout.svg	Wed Feb 08 05:50:15 2012 -0700
    32.3 @@ -0,0 +1,8 @@
    32.4 +<?xml version="1.0" standalone="no"?>
    32.5 +<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" 
    32.6 +  "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
    32.7 +<svg width="1024px" height="1024px" viewBox="0px 0px 1024px 1024px"
    32.8 +     xmlns="http://www.w3.org/2000/svg" version="1.1">
    32.9 +<desc>'try-again.blend', worm-2, (Blender 2.59 (sub 4))</desc>
   32.10 +
   32.11 +</svg>
    33.1 Binary file assets/Models/test-creature/worm.blend has changed
    34.1 Binary file images/Eve.jpg has changed
    35.1 Binary file images/hand-screenshot.png has changed
    36.1 Binary file images/hand-screenshot0.png has changed
    37.1 Binary file images/hand-screenshot1.png has changed
    38.1 --- a/org/body.org	Tue Feb 07 07:13:45 2012 -0700
    38.2 +++ b/org/body.org	Wed Feb 08 05:50:15 2012 -0700
    38.3 @@ -1,31 +1,200 @@
    38.4 -#+title: The BODY!!!
    38.5 +#+title: Building a Body
    38.6  #+author: Robert McIntyre
    38.7  #+email: rlm@mit.edu
    38.8  #+description: Simulating a body (movement, touch, propioception) in jMonkeyEngine3.
    38.9  #+SETUPFILE: ../../aurellem/org/setup.org
   38.10  #+INCLUDE: ../../aurellem/org/level-0.org
   38.11  
   38.12 -* Making a solid, connected body.
   38.13 -#+name: joints
   38.14 +
   38.15 +* Design Constraints
   38.16 +
   38.17 +I use [[www.blender.org/][blender]] to design bodies.  The design of the bodies is
   38.18 +determined by the requirements of the AI that will use them. The
   38.19 +bodies must be easy for an AI to sense and control, and they must be
   38.20 +relatively simple for jMonkeyEngine to compute.  
   38.21 +
   38.22 +** Bag of Bones
   38.23 +
   38.24 +How to create such a body? One option I ultimately rejected is to use
   38.25 +blender's [[http://wiki.blender.org/index.php/Doc:2.6/Manual/Rigging/Armatures][armature]] system. The idea would have been to define a mesh
   38.26 +which describes the creature's entire body. To this you add an
   38.27 +(skeleton) which deforms this mesh. This technique is used extensively
   38.28 +to model humans and create realistic animations. It is hard to use for
   38.29 +my purposes because it is difficult to update the creature's Physics
   38.30 +Collision Mesh in tandem with its Geometric Mesh under the influence
   38.31 +of the armature. Withouth this the creature will not be able to grab
   38.32 +things in its environment, and it won't be able to tell where its
   38.33 +physical body is by using its eyes. Also, armatures do not specify
   38.34 +any rotational limits for a joint, making it hard to model elbows,
   38.35 +shoulders, etc.
   38.36 +
   38.37 +** EVE
   38.38 +
   38.39 +Instead of using the human-like "deformable bag of bones" approach, I
   38.40 +decided to base my body plans on the robot EVE from the movie wall-E. 
   38.41 +
   38.42 +#+caption: EVE from the movie WALL-E.  This body plan turns out to be much better suited to my purposes than a more human-like one.
   38.43 +[[../images/Eve.jpg]]
   38.44 +
   38.45 +The main reason that I use eve-style bodies is so that there will be
   38.46 +correspondence between the AI's vision and the physical presence of
   38.47 +its body. 
   38.48 +
   38.49 +* Solidifying the Body
   38.50 +
   38.51 +Here is a hand designed eve-style in blender.
   38.52 +
   38.53 +
   38.54 +#+attr_html: width="500"
   38.55 +[[../images/hand-screenshot0.png]]
   38.56 +
   38.57 +If we load it directly into jMonkeyEngine, we get this:
   38.58 +
   38.59 +#+name: test-0
   38.60 +#+begin_src clojure
   38.61 +(ns cortex.test.body
   38.62 +  (:use (cortex world util body))
   38.63 +  (:import (com.aurellem.capture Capture RatchetTimer)
   38.64 +           (com.jme3.math Quaternion Vector3f)
   38.65 +           java.io.File))
   38.66 +
   38.67 +(def hand-path "Models/test-creature/hand.blend")
   38.68 +
   38.69 +(defn hand [] (load-blender-model hand-path))
   38.70 +
   38.71 +(defn setup [world]
   38.72 +  (let [cam (.getCamera world)]
   38.73 +    (println-repl cam)
   38.74 +    (.setLocation
   38.75 +     cam (Vector3f. 
   38.76 +          -6.9015837, 8.644911, 5.6043186))
   38.77 +    (.setRotation
   38.78 +     cam
   38.79 +     (Quaternion.
   38.80 +      0.14046453, 0.85894054, -0.34301838, 0.3533118)))
   38.81 +  (light-up-everything world)
   38.82 +  (.setTimer world (RatchetTimer. 60))
   38.83 +  world)
   38.84 +
   38.85 +(defn test-one []
   38.86 +  (world (hand)
   38.87 +         standard-debug-controls
   38.88 +         (comp
   38.89 +          #(Capture/captureVideo
   38.90 +            % (File. "/home/r/proj/cortex/render/body/1"))
   38.91 +          setup)
   38.92 +         no-op))
   38.93 +#+end_src
   38.94 +
   38.95 +
   38.96 +#+begin_src clojure :results silent
   38.97 +(.start (cortex.test.body/test-one))
   38.98 +#+end_src
   38.99 +
  38.100 +#+begin_html
  38.101 +<video controls="controls" width="755">
  38.102 +  <source src="../video/ghost-hand.ogg" type="video/ogg"
  38.103 +	  preload="none" poster="../images/aurellem-1280x480.png" />
  38.104 +</video>
  38.105 +#+end_html
  38.106 +
  38.107 +You will notice that the hand has no physical presence -- it's a
  38.108 +hologram through witch everything passes.  Therefore, the first thing
  38.109 +to do is to make it solid.  Blender has physics simulation on par with
  38.110 +jMonkeyEngine (they both use bullet as their physics backend), but it
  38.111 +can be difficult to translate between the two systems, so for now I
  38.112 +specify the mass of each object in blender and construct the physics
  38.113 +shape based on the mesh in jMonkeyEngine.
  38.114 +
  38.115 +#+name: joints-1
  38.116 +#+begin_src clojure
  38.117 +(defn physical!
  38.118 +  "Iterate through the nodes in creature and make them real physical
  38.119 +   objects in the simulation."
  38.120 +  [#^Node creature]
  38.121 +  (dorun
  38.122 +   (map
  38.123 +    (fn [geom]
  38.124 +      (let [physics-control
  38.125 +            (RigidBodyControl.
  38.126 +             (HullCollisionShape.
  38.127 +              (.getMesh geom))
  38.128 +             (if-let [mass (meta-data geom "mass")]
  38.129 +               (do
  38.130 +                 (println-repl
  38.131 +                  "setting" (.getName geom) "mass to" (float mass))
  38.132 +                 (float mass))
  38.133 +               (float 1)))]
  38.134 +        (.addControl geom physics-control)))
  38.135 +    (filter #(isa? (class %) Geometry )
  38.136 +            (node-seq creature)))))
  38.137 +#+end_src
  38.138 +
  38.139 +=(physical!)= iterates through a creature's node structure, creating
  38.140 +CollisionShapes for each geometry with the mass specified in that
  38.141 +geometry's meta-data.
  38.142 +
  38.143  #+begin_src clojure 
  38.144 -(ns cortex.body
  38.145 -  "Assemble a physical creature using the definitions found in a
  38.146 -   specially prepared blender file. Creates rigid bodies and joints so
  38.147 -   that a creature can have a physical presense in the simulation."
  38.148 -  {:author "Robert McIntyre"}
  38.149 -  (:use (cortex world util sense))
  38.150 -  (:use clojure.contrib.def)
  38.151 -  (:import
  38.152 -   (com.jme3.math Vector3f Quaternion Vector2f Matrix3f)
  38.153 -   (com.jme3.bullet.joints
  38.154 -    SixDofJoint Point2PointJoint HingeJoint ConeJoint)
  38.155 -   com.jme3.bullet.control.RigidBodyControl
  38.156 -   com.jme3.collision.CollisionResults
  38.157 -   com.jme3.bounding.BoundingBox
  38.158 -   com.jme3.scene.Node
  38.159 -   com.jme3.scene.Geometry
  38.160 -   com.jme3.bullet.collision.shapes.HullCollisionShape))
  38.161 +(in-ns 'cortex.test.body)
  38.162  
  38.163 +(def normal-gravity 
  38.164 +  {"key-g" (fn [world _]
  38.165 +             (set-gravity world (Vector3f. 0 -9.81 0)))})
  38.166 +
  38.167 +(defn floor [] 
  38.168 +  (box 10 3 10 :position (Vector3f. 0 -10 0)
  38.169 +       :color ColorRGBA/Gray :mass 0))
  38.170 +
  38.171 +(defn test-two []
  38.172 +  (world (nodify
  38.173 +          [(doto (hand)
  38.174 +             (physical!))
  38.175 +          (floor)])
  38.176 +         (merge standard-debug-controls normal-gravity)
  38.177 +         (comp
  38.178 +          #(Capture/captureVideo
  38.179 +            % (File. "/home/r/proj/cortex/render/body/2"))
  38.180 +          #(do (set-gravity % Vector3f/ZERO) %)
  38.181 +          setup)
  38.182 +         no-op))
  38.183 +#+end_src
  38.184 +
  38.185 +#+begin_html
  38.186 +<video controls="controls" width="755">
  38.187 +  <source src="../video/crumbly-hand.ogg" type="video/ogg"
  38.188 +	  preload="none" poster="../images/aurellem-1280x480.png" />
  38.189 +</video>
  38.190 +#+end_html
  38.191 +
  38.192 +Now that's some progress.
  38.193 +
  38.194 +
  38.195 +* Joints
  38.196 +
  38.197 +Obviously, an AI is not going to be doing much just lying in pieces on
  38.198 +the floor.  So, the next step to making a proper body is to connect
  38.199 +those pieces together with joints.  jMonkeyEngine has a large array of
  38.200 +joints available via bullet, such as Point2Point, Cone, Hinge, and a
  38.201 +generic Six Degree of Freedom joint, with or without spring
  38.202 +restitution.
  38.203 +
  38.204 +Although it should be possible to specify the joints using blender's
  38.205 +physics system, and then automatically import them with jMonkeyEngine,
  38.206 +the support isn't there yet, and there are a few problems with bullet
  38.207 +itself that need to be solved before it can happen. 
  38.208 +
  38.209 +So, I will use the same system for specifying joints as I will do for
  38.210 +some senses.  Each joint is specified by an empty node whose parent
  38.211 +has the name "joints". Their orientation and meta-data determine what
  38.212 +joint is created.
  38.213 +
  38.214 +[[../images/hand-screenshot1.png]]
  38.215 +
  38.216 +
  38.217 +
  38.218 +
  38.219 +#+name: joints-2
  38.220 +#+begin_src clojure 
  38.221  (defn joint-targets
  38.222    "Return the two closest two objects to the joint object, ordered
  38.223    from bottom to top according to the joint's rotation."
  38.224 @@ -183,28 +352,6 @@
  38.225    (sense-nodes "joints")
  38.226    "Return the children of the creature's \"joints\" node.")
  38.227  
  38.228 -(defn physical!
  38.229 -  "Iterate through the nodes in creature and make them real physical
  38.230 -   objects in the simulation."
  38.231 -  [#^Node creature]
  38.232 -  (dorun
  38.233 -   (map
  38.234 -    (fn [geom]
  38.235 -      (let [physics-control
  38.236 -            (RigidBodyControl.
  38.237 -             (HullCollisionShape.
  38.238 -              (.getMesh geom))
  38.239 -             (if-let [mass (meta-data geom "mass")]
  38.240 -               (do
  38.241 -                 (println-repl
  38.242 -                  "setting" (.getName geom) "mass to" (float mass))
  38.243 -                 (float mass))
  38.244 -               (float 1)))]
  38.245 -               
  38.246 -        (.addControl geom physics-control)))
  38.247 -    (filter #(isa? (class %) Geometry )
  38.248 -            (node-seq creature)))))
  38.249 -
  38.250  (defn joints!
  38.251    "Connect the solid parts of the creature with physical joints. The
  38.252     joints are taken from the \"joints\" node in the creature."
  38.253 @@ -225,13 +372,32 @@
  38.254    (joints! creature))
  38.255  #+end_src
  38.256  
  38.257 -#+results: joints
  38.258 -: #'cortex.body/body!
  38.259 +* Bookkeeping
  38.260  
  38.261 -#+results: proprioception
  38.262 -: #'cortex.body/proprioception-debug-window
  38.263 +#+name: body-0
  38.264 +#+begin_src clojure
  38.265 +(ns cortex.body
  38.266 +  "Assemble a physical creature using the definitions found in a
  38.267 +   specially prepared blender file. Creates rigid bodies and joints so
  38.268 +   that a creature can have a physical presense in the simulation."
  38.269 +  {:author "Robert McIntyre"}
  38.270 +  (:use (cortex world util sense))
  38.271 +  (:use clojure.contrib.def)
  38.272 +  (:import
  38.273 +   (com.jme3.math Vector3f Quaternion Vector2f Matrix3f)
  38.274 +   (com.jme3.bullet.joints
  38.275 +    SixDofJoint Point2PointJoint HingeJoint ConeJoint)
  38.276 +   com.jme3.bullet.control.RigidBodyControl
  38.277 +   com.jme3.collision.CollisionResults
  38.278 +   com.jme3.bounding.BoundingBox
  38.279 +   com.jme3.scene.Node
  38.280 +   com.jme3.scene.Geometry
  38.281 +   com.jme3.bullet.collision.shapes.HullCollisionShape))
  38.282 +#+end_src
  38.283  
  38.284 -* Examples
  38.285 +* Source 
  38.286 +
  38.287 +* COMMENT Examples
  38.288  
  38.289  #+name: test-body
  38.290  #+begin_src clojure
  38.291 @@ -967,7 +1133,7 @@
  38.292  #+end_src
  38.293  
  38.294  #+begin_src clojure :tangle ../src/cortex/test/body.clj
  38.295 -<<test-body>>
  38.296 +<<test-0>>
  38.297  #+end_src  
  38.298  
  38.299  
    39.1 --- a/org/sense.org	Tue Feb 07 07:13:45 2012 -0700
    39.2 +++ b/org/sense.org	Wed Feb 08 05:50:15 2012 -0700
    39.3 @@ -1,4 +1,4 @@
    39.4 -#+title: 
    39.5 +#+title: Helper Functions / Motivations
    39.6  #+author: Robert McIntyre
    39.7  #+email: rlm@mit.edu
    39.8  #+description: sensory utilities
    39.9 @@ -461,7 +461,6 @@
   39.10    <source src="../video/bind-sense.ogg" type="video/ogg"
   39.11  	  preload="none" poster="../images/aurellem-1280x480.png" />
   39.12  </video>
   39.13 -
   39.14  #+end_html
   39.15  
   39.16  With this, eyes are easy --- you just bind the camera closer to the