Bullet's btGeneric6DofSpringConstraint in Blender

aspfreakout
Posts: 6
Joined: Mon Jan 24, 2011 10:15 am

Bullet's btGeneric6DofSpringConstraint in Blender

Post by aspfreakout »

Hi,

I'd like to model a robot of that has some passive compliant joints (so springs basically).
Bullet has the right tool for the job, the btGeneric6DofSpringConstraint, but I can't find a way to use this from within Blender (2.56).

Is it possible to use it from within Blender (if not, what would be the best way to model realistic springs in Blender)?

Thanks!
RBD
Posts: 141
Joined: Tue Sep 16, 2008 11:31 am

Re: Bullet's btGeneric6DofSpringConstraint in Blender

Post by RBD »

Yes, the 6dof spring constraint is available inside Blender, but not from the UI, only from BGE python... here is some sample Blender 2.5 code to set up a 6 dof spring constraint:

Code: Select all

# Create a 6dof spring constraint on Z between two cubes
from bge import logic, constraints

scene = logic.getCurrentScene()
cube1p = scene.objects["Cube.001"].getPhysicsId()
cube2p = scene.objects["Cube.002"].getPhysicsId()

# obj1, obj2, type (12 = PHY_GENERIC_6DOF_CONSTRAINT), pivotx, y, z , axisx, y, z
cube6dofspring = constraints.createConstraint( cube2p, cube1p, 12, 0, 0, -2, 0, 0, 0)
# min max for 6 degrees of freedom (0-5 = tx,ty,tz,rx,ry,rz)
cube6dofspring.setParam(0, 0.0, 0.0)
cube6dofspring.setParam(1, 0.0, 0.0)
cube6dofspring.setParam(2, -5.0, 5.0)									
cube6dofspring.setParam(3, 0.0, 0.0)
cube6dofspring.setParam(4, 0.0, 0.0)
cube6dofspring.setParam(5, 0.0, 0.0)
# stiffness, damping for 6dof (12-17 = tx,ty,tz,rx,ry,rz) motorized spring
cube6dofspring.setParam(14, 50.0, 1)
Note that my personal opinion is that Bullet's 6dofspringconstraint is lacking because, with gravity, it never really stops bouncing, unless you use sleep. What I mean is that I would expect the closer the spring gets to it's "normal" position, it should bounce less and less until full stop (even without using sleeping)... but (currently) it doesn't.

Here is what I recommend for a spring between two rigid bodies in Blender: Given obj1 and obj2:

For one of them, let's say obj1:
Add Constraint: regular 6dof with target: obj2, limit all axes, to zero for all except the spring axis where you would set the maximum - and + hard limits of travel you want.
In Game Logic:
Add to both obj1 and obj2 an actuator (attached to an Always Sensor And controller):
Motion, type: Servo Control, where reference is the other object, set limit to zero others axes except spring axis which should have no limit.
For a bouncy spring, try:
  • Integral Coefficient: 1.0
  • Proportional Coefficient: 5.0
  • Derivate Coefficient: 0.0
You can see an example of this used in the first scene: Blender 2.5 smoke / rocket tests (YouTube)
aspfreakout
Posts: 6
Joined: Mon Jan 24, 2011 10:15 am

Re: Bullet's btGeneric6DofSpringConstraint in Blender

Post by aspfreakout »

Thanks for your reply!

I don't think your second solution can work for me, as the Blender documentation states that a servo motor actuator can only be used for Dynamic bodies and not for rigid bodies.

So I tried the first option by adding the constraints directly in python based on your code, but I get really unrealistic results.
I've attached an example with 4 springs (rotational).
Logically, the large object (1kg) should fall and stay in about the same place (it's a damped system).
Instead it starts jumping around...

Any idea how to get some realistic results (no cheating ;)?

I looked at CcdPhysicsEnvironment.cpp, to see if I could enable ODE's Dantzig solver, but a call to constraints.setSolverType doesn't seem to do anything.
You do not have the required permissions to view the files attached to this post.
RBD
Posts: 141
Joined: Tue Sep 16, 2008 11:31 am

Re: Bullet's btGeneric6DofSpringConstraint in Blender

Post by RBD »

I did look quickly at your file, and there are a few issues, but I'm sorry I don't have much time to help right now.
The main reason it's jumping around is because there is a collision between your "body" and "FL" "RL" because they are within the convex hull space of the body (the body is concave, and its convex hull "fills" the concave areas). And sorry but I really don't understand what you are trying to do with rotational springs? (rotation springs on x?). Don't you want translational springs on z?

If you look at that video I linked you to: the five "feet" are connected to the five "legs" using regular 6dof constraints (with some z limits) and then the "legs" are all connected to the "body" using regular 6dof constraints (all locked). The "legs" and "feet" are all Rigid Bodies and are all using Servo Control on z as I explained above (example attached!).
You do not have the required permissions to view the files attached to this post.
aspfreakout
Posts: 6
Joined: Mon Jan 24, 2011 10:15 am

Re: Bullet's btGeneric6DofSpringConstraint in Blender

Post by aspfreakout »

Thanks a lot, I got it working!

I used the python approach, as I can't use a servo motor: it controls the velocity, not the position, it gives visually pleasing results though, but not really realistic physically I guess.
The main problem was the convex hull bounding box, a really stupid mistake...

Now I'm trying to model some sensors (e.g. force/torque), but maybe I'll just add my own functions to Blender's wrapper around Bullet for that.