Mar 312011
 

[FILES UPDATED TO WORK WITH 2.57b]

.blend files (2.57b – r36339) right-click, save-as
Uno/Deuce/Pogo
Rigid Body Walking Machines
Extras

link to BA thread

This is a collection of studies and experiments in rigid body dynamics and pose control using Blenders game engine and python API. All the animation data was generated in real-time simulations (with the exception of the camera which was keyframed and the cloth which was not real-time)

———NON-BLENDER/3D NERD BRIEF———
These animations are essentially of 3d games. The games have gravity, inertia, object collisions, joints connecting objects and ranges for those joints. Each scene was created by setting up a game, and running it several times (sometimes with simple keyboard interaction which pushed or propelled a projectile). The animation data (the rotation and location of each object) was recorded during each game. The most amusing or interesting results were saved, one was selected to be rendered later.
Camera moves were keyframed (traditional/manual 3d animation) for more interesting views. Hours and hours of painful rendering, and voila.

The rectangular biped and monopod characters are seperate programs within each game. Each has the ‘joints’ and ‘muscles’ of a simplified human. The joints are functions that limit the location and rotation of an object (such as a hip) with respect to another object (such as a torso)

The muscles are ‘PD’ functions (proportional-derivative). At each frame the functions return the torque value that must be applied at a given joint to attempt to reach a given ‘pose’. These actually behave more like damped-springs than muscles.

The poses are defined by a ‘finite state machine’. This is a set of inputs and instructions that tell the robot (or a part of the robot) what state, or pose, it should try to be in. For example, the robots current ‘state’ is its left leg is down (‘stance’ state) and its right leg is swinging (‘swing’ state). The robot detects that its swing leg is now ahead of the stance leg and has made contact with the ground. The state machine will now instruct the stance leg to change to the swing state, and vice-versa.

There are other states that determine what to do when the robot is off-balance (center-of-mass outside of center-of feet) and when the legs become crossed. The monopod has other sensors and states that determine if it in at a safe position to flip or if it should just hop (sometimes comes up wrong), and compensates for linear velocity (tries to slow forward momentum after each jump)

The weird glowing red walking machines are another thing entirely.

These are not programs, they are structures ‘built’ in a game that work pretty much like they look like they work. The only ‘animation’ that is done is that their ‘motor’, red glowing thing is rotated by magical hogwarts force. Everything else is a result of that motion. Axles, cranks, rods, levers, etc, do what you’d expect them to do (though with infinite strength and sometimes invisible and/or impossible connections)

The designs are more or less lifted. The hexapod and ‘toothpicks’ are the only ones I didn’t actually look at internal blueprints of something for, and those are clearly not original mechanisms either.

There are a few other tests and experiments that worked their way into this collection but I won’t go into detail about those. If you’re curious- ask. Better yet, look it up. Better still, figure it out yourself.

———FOR THE BLENDER/3D INCLINED———

—POSE CONTROLLERS—
Simple pose controlled ‘robots’ were created in Python after studying the work of Ari Shapiro (DANCE Dynamic Animation and Control Environment) and Philippe Beaudoin (SIMBICON/Cartwheel-3d). Primarily
-Generalized Biped Walking Control. Siggraph 2010
-Composable Controllers. – Siggraph 2001
-Controller Development. – Siggraph 2007

Not surprisingly, most of the brilliant methods put forth in these papers are absent in these programs. These are just ‘steps’ towards gaining a better understanding of dynamic character control concepts.

These robots are finite state machines with proportional derivative controller ‘muscles’. They also respond to feedback provided by center-of-mass, foot contact with ground, swing/stance foot positions relative to center of mass and torso heading. Uno knows the ‘uprightness’ vector between the feet and torso. Deuce can also detect if his feet are crossed, and will attempt to correct by standing on one leg and swinging the front leg outwards. They also have threshold ‘KO velocities’ beyond which they will go limp. This should be from acceleration but this works for now.

These robots run independent copies of their controllers so they can be copied for rudimentary crowd simulation. Their individual ‘heading goal’ is controlled by a ‘game property’ string in the robots ‘torso’ object. The goal can be another objects name, or use the prefix ‘a:’ then an angle (in degrees). Do not change the object names or numeration after copying, the program depends on these.

DEUCE – v.0001a of my ultimate goal of creating a real-time interactive break-dancing/kung-fu-master/soccer-playing/gymnast pose controller. What the heck- let’s throw in piano and chess-playing too. 15 DOF: Torso-XYZ, Hips-XYZ, Knees-X, Ankles-XY. Next version I will probably add 1-DOF toes and change Ankles from Pitch/Roll to Pitch/Yaw. I plan to utilize more of the SIMBICON methods and I am also looking at work on ‘genetic algorithms’ for evolving different controller params.

UNO – Created as a study for balance feedback. Eventually learned to hop, then to flip (sort of). Uno also alters his hip angle to compensate for linear velocity to try to stabilize his momentum after each jump. 9 DOF: Same configuration as Deuce

POGO – First study of proportional derivative controller. Just a collision sensor that triggers an upward force. Uses PD to angle the peg to compensate for linear velocity on the next bounce.

—RIGID BODY CONSTRAINT WALKING MACHINES—
Obviously a ‘dumber’ approach to walking animation, though strangely visually appealing. It started with a goofy thought, and ended with hours and hours of trial-and-error learning how bge handles various constraint configuations. There is a lot more that could be done with this technique. These are just a few setups.

THEO – based on Theo Jansen’s ‘Jansen Mechanism’
GOODWIN – based on W.F. Goodwin’s – ‘Automatic Toy’
NOGOODWIN – based on W.F. Goodwin’s – ‘Horse Toy’.
HEX – a semi-original design derived from observations of several 6-legged robot designs.
LE STECCHINI – based on those ubiquitous wind up walking toys we all know and love.

—OTHER—
MORTIMER/RINGO – Extremely simple self-firing ‘mortar’ objects. Created to test uno/deuce reaction to perturbation. Actually these should serve as a warning to anyone who thinks Algebra isn’t important. I got tired of trying to learn all the stuff I avoided learning in high school so I ended up finding the midpoint between the mortar and target, choosing an arbitrary height and firing on that vector. Amazingly, it’s a functional targeting system but it’s an insult to mathematics.

DRAWN-AND-QUARTERED RAGDOLL – Joint constraints had to be created programmatically (as opposed to using Blender UI constraints) so joints could be removed in the simulation. Keyboard events trigger joint ‘breaks’. I could probably figure out a way to calculate limb tension and trigger breaks based on a threshhold- but the whole thing was kind of a lark anyway.

TAD – Failed attempt to create a stable unpowered ‘passive walker’ based on Tad McGeers work. Has never taken more than three steps. Unpowered passive walkers are pretty sensitive to begin with and I’m not sure if a game engine simulation is enough to create one that works anything like in real-life. I’ll give it another go at some point.

H.M.S. STUPID – Another early test. A board that keeps level by using 4 ‘thrusters’. Each fires only if it is below the thruster on the opposite side.

—FILES—
All the models/rigs/programs in this .blend file are free to use for any non-machines-destroying-humanity related purposes as far as I’m concerned. Though keep in mind, though this work is original, some of the concepts and designs utilized and referenced are not. The Jansen Mechanism for instance; I have no idea what kind of intellectual property that is.

If you do use these for anything I’d appreciate a nod.

Word to your matrix.

Mar 042011
 

I got a little done on the OSC implementation for Cartwheel-3D but I probably wont be able to go much further for awhile so I thought I’d post what I had.

In the cartwheel source there is a file
\PythonAppSNMApp.py that runs the main animation loop. I edited it to send OSC messages for each joint. To do this I used the pyOSC module and parked it in the same directory for convenience.
The whole thing runs super slow through the py-interpreter. I tried to compile it with py2exe but ran into some trouble. However, I found that I could cheat and use the provided binaries.
Take the modified SNMApp.pyc (and OSC.pyc) and copy them into the \binlibrary.zip file in the binaries. It just works.

Here’s my modified SNMApp.py – the pyOSC module can be found here

Blender uses Python 3 so I had to use a different OSC module here. I just parked it in the same directory as blender.exe – also for convenience.

and here is a .blend file with my OSC listener code in it. I got it to work with the bge and the animation system, but not cleanly.

If you have any success with this let me know.

Mar 022011
 

This is a simple script I wrote that generates meshes using DLA.

I made a little demo animation where I ran the mesh as a cloth sim.

print("-----GO-----")
import bpy
import random
from math import sin, cos, pi, sqrt
from mathutils import Vector

HardRadius = 2
RandWalkRange = .15
StickThresh = .15	   #distance threshold to accrete
MaxVerts = 100		#stop when this many verts have been added
seedLOC = Vector((0.0,0.0,0.0))

D3 = True

mname = "DLAtest"

def brownian():
	dx = random.gauss(0, RandWalkRange)
	dy = random.gauss(0, RandWalkRange)
	dz = random.gauss(0, RandWalkRange) 
	return Vector((dx, dy, dz))

####returns a new wanderer on sphere
def newWanderer():  
	randAngleA = random.uniform(0,2*pi)
	randAngleB = random.uniform(0,2*pi) 
	x = HardRadius * sin(randAngleA) * cos(randAngleB)
	y = HardRadius * sin(randAngleA) * sin(randAngleB)
	z = HardRadius * cos(randAngleA)
	return Vector((x, y, z))

def dist(A, B):
	xd = B.x-A.x
	yd = B.y-A.y
	zd = B.z-A.z
	return sqrt(xd*xd + yd*yd + zd*zd)

def wanderLoop(ob):
	wand = newWanderer()
	mmesh = ob.data
	while len(mmesh.vertices) < MaxVerts:
		brown = brownian()
		wand.x += brown.x
		wand.y += brown.y
		if D3: wand.z += brown.z
		else: wand.z = 0
		if  abs(wand.x) > HardRadius or 
			abs(wand.y) > HardRadius or 
			abs(wand.z) > HardRadius:
				wand = newWanderer()
				
		for vert in range(len(mmesh.vertices)):
			dpt = dist(wand, mmesh.vertices[vert].co)
			dZ = dist(wand, seedLOC)			
			if dpt < StickThresh:
				st = str(len(mmesh.vertices)+1) + " of " + str(MaxVerts) + " has been assimilated"
				print(st, dpt)
				addPoint(ob, wand, vert)
				wand = newWanderer()
				pass

####Object, point to add, index of vert to connect to (None is -1)
def addPoint(ob, pt, conni):
	mmesh = ob.data
	mmesh.vertices.add(1)
	vcounti = len(mmesh.vertices)-1
	mmesh.vertices[vcounti].co = [pt.x, pt.y, pt.z]
	if conni > -1:
		mmesh.edges.add(1)
		ecounti = len(mmesh.edges)-1
		mmesh.edges[ecounti].vertices = [conni, vcounti]


def newDLAMesh(mname):
	mmesh = bpy.data.meshes.new(mname)
	omesh = bpy.data.objects.new(mname, mmesh)
	bpy.context.scene.objects.link(omesh)
	addPoint(omesh, seedLOC, -1)	
	return omesh

ob = newDLAMesh("testDLA")
wanderLoop(ob)