# HG changeset patch # User Robert McIntyre # Date 1327927671 25200 # Node ID b26017d1fe9a240d113de6a00ce1db45c6c565d5 # Parent bab47091534eb6052809da8ea378c4c0a94e8c42 added workaround for problem with point2point joints in native bullet; added basic muscle description image. diff -r bab47091534e -r b26017d1fe9a assets/Models/creature1/basic-muscle.png Binary file assets/Models/creature1/basic-muscle.png has changed diff -r bab47091534e -r b26017d1fe9a assets/Models/creature1/try-again.blend Binary file assets/Models/creature1/try-again.blend has changed diff -r bab47091534e -r b26017d1fe9a org/body.org --- a/org/body.org Mon Jan 30 00:25:11 2012 -0700 +++ b/org/body.org Mon Jan 30 05:47:51 2012 -0700 @@ -82,6 +82,7 @@ (doto (Quaternion.) (.fromRotationMatrix rotate-a))) arm-b)] + ;;(println-repl (.getName object-a) (.getName object-b)) [pitch yaw roll])) (defn proprioception @@ -225,6 +226,61 @@ (dorun (worm-motor-map (worm-pattern @time))))))) + +(require 'cortex.silly) +(defn join-at-point [obj-a obj-b world-pivot] + (cortex.silly/joint-dispatch + {:type :point} + (.getControl obj-a RigidBodyControl) + (.getControl obj-b RigidBodyControl) + (cortex.silly/world-to-local obj-a world-pivot) + (cortex.silly/world-to-local obj-b world-pivot) + nil + )) + + + +(defn blab-* [] + (let [hand (box 0.5 0.2 0.2 :position (Vector3f. 0 0 0) + :mass 0 :color ColorRGBA/Green) + finger (box 0.5 0.2 0.2 :position (Vector3f. 2.4 0 0) + :mass 1 :color ColorRGBA/Red) + connection-point (Vector3f. 1.2 0 0) + root (nodify [hand finger])] + + (join-at-point hand finger (Vector3f. 1.2 0 0)) + + (.setCollisionGroup + (.getControl hand RigidBodyControl) + PhysicsCollisionObject/COLLISION_GROUP_NONE) + (world + root + standard-debug-controls + (fn [world] + (enable-debug world) + (.setTimer world (com.aurellem.capture.RatchetTimer. 60)) + (set-gravity world Vector3f/ZERO) + ) + no-op))) + +(defn proprioception-debug-window + [] + (let [vi (view-image)] + (fn [prop-data] + (dorun + (map + (comp + println-repl + (fn [[p y r]] + (format + "pitch: %1.2f\nyaw: %1.2f\nroll: %1.2f\n" + p y r))) + prop-data))))) + + + + + (defn test-proprioception "Testing proprioception: You should see two foating bars, and a printout of pitch, yaw, and @@ -236,7 +292,7 @@ (let [hand (box 1 0.2 0.2 :position (Vector3f. 0 2 0) :mass 0 :color ColorRGBA/Green) finger (box 1 0.2 0.2 :position (Vector3f. 2.4 2 0) - :mass 1 :color (ColorRGBA. 0.20 0.40 0.99 1.0)) + :mass 1 :color ColorRGBA/Red) floor (box 10 0.5 10 :position (Vector3f. 0 -5 0) :mass 0 :color ColorRGBA/Gray) @@ -247,15 +303,23 @@ roll-left? (atom false) roll-right? (atom false) control (.getControl finger RigidBodyControl) - joint - (doto - (Point2PointJoint. - (.getControl hand RigidBodyControl) - control - (Vector3f. 1.2 0 0) - (Vector3f. -1.2 0 0 )) - (.setCollisionBetweenLinkedBodys false)) - time (atom 0)] + time (atom 0) + joint (join-at-point hand finger (Vector3f. 1.2 2 0 )) + creature (nodify [hand finger]) + prop (proprioception creature) + + prop-view (proprioception-debug-window) + + + ] + + + + (.setCollisionGroup + (.getControl hand RigidBodyControl) + PhysicsCollisionObject/COLLISION_GROUP_NONE) + + (world (nodify [hand finger floor]) (merge standard-debug-controls @@ -266,10 +330,8 @@ "key-v" (fn [_ pressed?] (reset! roll-left? pressed?)) "key-b" (fn [_ pressed?] (reset! roll-right? pressed?))}) (fn [world] - (.setTimer world (NanoTimer.)) + (.setTimer world (com.aurellem.capture.RatchetTimer. 60)) (set-gravity world (Vector3f. 0 0 0)) - (.setMoveSpeed (.getFlyByCamera world) 50) - (.setRotationSpeed (.getFlyByCamera world) 50) (light-up-everything world)) (fn [_ _] (if @move-up? @@ -297,15 +359,16 @@ (.mult (.getPhysicsRotation control) (Vector3f. 1 0 0)))) - (if (= 0 (rem (swap! time inc) 2000)) - (do - (apply - (comp - println-repl - #(format "pitch: %1.2f\nyaw: %1.2f\nroll: %1.2f\n" %1 %2 %3)) - (joint-proprioception joint)))))))) + (if (= 0 (rem (swap! time inc) 20)) + (prop-view + (joint-proprioception joint))))))) + + #+end_src +#+results: test-body +: #'cortex.test.body/test-proprioception + * COMMENT code-limbo #+begin_src clojure diff -r bab47091534e -r b26017d1fe9a org/test-creature.org --- a/org/test-creature.org Mon Jan 30 00:25:11 2012 -0700 +++ b/org/test-creature.org Mon Jan 30 05:47:51 2012 -0700 @@ -321,11 +321,33 @@ (defmethod joint-dispatch :point [constraints control-a control-b pivot-a pivot-b rotation] (println-repl "creating POINT2POINT joint") - (Point2PointJoint. - control-a - control-b - pivot-a - pivot-b)) + ;; bullet's point2point joints are BROKEN, so we must use the + ;; generic 6DOF joint instead of an actual Point2Point joint! + + ;; should be able to do this: + (comment + (Point2PointJoint. + control-a + control-b + pivot-a + pivot-b)) + + ;; but instead we must do this: + (println-repl "substuting 6DOF joint for POINT2POINT joint!") + (doto + (SixDofJoint. + control-a + control-b + pivot-a + pivot-b + false) + (.setLinearLowerLimit Vector3f/ZERO) + (.setLinearUpperLimit Vector3f/ZERO) + ;;(.setAngularLowerLimit (Vector3f. 1 1 1)) + ;;(.setAngularUpperLimit (Vector3f. 0 0 0)) + +)) + (defmethod joint-dispatch :hinge [constraints control-a control-b pivot-a pivot-b rotation] @@ -411,6 +433,9 @@ joint-rotation)) (println-repl "could not find joint meta-data!")))) + + + (defn assemble-creature [#^Node pieces joints] (dorun (map @@ -1015,7 +1040,7 @@ (bit-shift-left num 8) (bit-shift-left num 16))) -(defn debug-window +(defn debug-touch-window "creates function that offers a debug view of sensor data" [] (let [vi (view-image)] @@ -1066,8 +1091,49 @@ -;; here's how motor-control/ proprioception will work: +;; here's how motor-control/ proprioception will work: Each muscle is +;; defined by a 1-D array of numbers (the "motor pool") each of which +;; represent muscle fibers. A muscle also has a scalar :strength +;; factor which determines how strong the muscle as a whole is. +;; The effector function for a muscle takes a number < (count +;; motor-pool) and that number is said to "activate" all the muscle +;; fibers whose index is lower than the number. Each fiber will apply +;; force in proportion to its value in the array. Lower values cause +;; less force. The lower values can be put at the "beginning" of the +;; 1-D array to simulate the layout of actual human muscles, which are +;; capable of more percise movements when exerting less force. +;; I don't know how to encode proprioception, so for now, just return +;; a function for each joint that returns a triplet of floats which +;; represent relative roll, pitch, and yaw. Write display code for +;; this though. + +(defn muscle-fibre-values + "Take the first row of the image and return the low-order bytes." + [#^BufferedImage image] + (let [width (.getWidth image)] + (for [x (range width)] + (bit-and + 0xFF + (.getRGB image x 0))))) + + +(defn rad->deg [rad] + (* 180 (/ Math/PI) rad)) + + +(defn debug-prop-window + "create a debug view for proprioception" + [] + (let [vi (view-image)] + (fn [sensor-data] + (println-repl + (map + (fn [[yaw pitch roll]] + [(rad->deg yaw) + (rad->deg pitch) + (rad->deg roll)]) + sensor-data))))) @@ -1083,7 +1149,7 @@ (box 0.01 0.01 1 :physical? false :color ColorRGBA/Blue) creature (blender-creature thing) touch-nerves (touch creature) - touch-debug-windows (map (fn [_] (debug-window)) touch-nerves) + touch-debug-windows (map (fn [_] (debug-touch-window)) touch-nerves) [init-vision-fns vision-data] (vision creature) vision-debug (map (fn [_] (debug-vision-window)) vision-data) me (sphere 0.5 :color ColorRGBA/Blue :physical? false) @@ -1092,6 +1158,8 @@ hearing-senses) bell (AudioNode. (asset-manager) "Sounds/pure.wav" false) + prop (proprioception creature) + prop-debug (debug-prop-window) ;; dream ] @@ -1131,7 +1199,7 @@ ;;(dorun ;; (map #(%1 %2) touch-nerves (repeat (.getRootNode world)))) - + (prop-debug (prop)) (dorun (map #(%1 (%2 (.getRootNode world))) @@ -1201,7 +1269,7 @@ sim (world node {"key-space" -vvvvvv (fn [_ value] + (fn [_ value] (if value (let [cr (CollisionResults.)] (.collideWith node bounds-b cr)