Translational Constraint

dkfdkf
Posts: 8
Joined: Mon Jul 16, 2007 10:25 pm

Translational Constraint

Post by dkfdkf »

Hi!

So I built this robot in Bullet: (see attachment).
test.png
For now, to make life easy, I want a constraint where the center of the robot (the big green piece) can only translate in the X & Y axis, not in the Z axis, and can't rotate at all. What is the easiest way to do this in Bullet? (It seems like that I have to use the 6DOF Constraint, but the source code says to avoid using it whenever possible.)

I want the robot not translating in the Z axis ,and not rotating at all to be a very very hard constraint.

Thanks!
You do not have the required permissions to view the files attached to this post.
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Re: Translational Constraint

Post by Erwin Coumans »

That looks great.

You should be able to use the generic 6DOF constraint. That comment is obsolete, a recent contribution made this constraint more useable.

Do you have a page/URL where does the documentation recommend not to use it? It needs to be updated.

Please try using those limits, see also the ConstraintDemo how to use the 6DOF constraint:

Totally free linear motion in X,Y, locked in Z (free is achieved by setting lower > upper)

Code: Select all

btVector3 lowerSliderLimit = btVector3(1,1,0);
btVector3 hiSliderLimit = btVector3(0,0,0);
bool useLinearReferenceFrameA = false;//use fixed frame B for linear limits
btGeneric6DofConstraint* slider = new btGeneric6DofConstraint(*d6body0,*fixedBody1,frameInA,frameInB,useLinearReferenceFrameA);
slider->setLinearLowerLimit(lowerSliderLimit);
slider->setLinearUpperLimit(hiSliderLimit);
Lock all angular motion:

Code: Select all

slider->setAngularLowerLimit(btVector3(0,0,0));
slider->setAngularUpperLimit(btVector3(0,0,0));
Can you let us know if this works for you?
Thanks,
Erwin
dkfdkf
Posts: 8
Joined: Mon Jul 16, 2007 10:25 pm

Re: Translational Constraint

Post by dkfdkf »

Amazing! Worked immediately.

I chopped off two legs, here's it falling w/o the constraints:
http://video.google.com/videoplay?docid ... 2096&hl=en

Here's it standing on only two legs (once Google approves this video) due to the constraints support:
http://video.google.com/videoplay?docid ... 0093&hl=en


Now I'm really greedy. If we look at the constraint I've asked for, it's a 2D subspace of the 6D space. In this particular case, it was a plane, and easily mapped to the 6DOF constraint.

(In particular, we said, any (x, y, z, rot) s.t. z = 0, rot = 0 is "a-okay").

Now, here's what'd be even better: I want to constrain the the robot such that:
(1) rot = 0
(2) z = 0
(3) (x,y) satisfy some equation like y = constant + sin ( fraction_part(x / 20) * constant )

This is different from before in two ways:
(1) we have 1 DOF instead of 2 (not a big deal)
(2) the surface/line I want to constrain the center of the robot to is _NOT_ flat, but rather a sine curve. (So it "bounces" up and down)

[Imageine this, the legs try to push it forward, and the center goes up and down; not based on the force of the legs in the Y (vertical) direction, but based on this pre-defined curve.]

... what is the best way to phrase this constraint?

Thanks!
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Re: Translational Constraint

Post by Erwin Coumans »

This is possible, but would require developing a custom point-to-surface constraint. If you complete this, it can be donated as a contribution to Bullet.

You can derive your custom constraint from btTypedConstraint, probably best to duplicate/use the point to point constraint as template. Note you can combine multiple constraints on the same rigidbody, so you can use both the 6DOF constraint (to limit the angular DOFs and some linear DOFs), and your custom point-to-surface constraint.

I recommend Bart Barenbrugs PhD theses, it described this constraint, and his open source Dynamo dynamics library has an implementation of point to surface constraint. It needs changes to make it fit in Bullet's iterative impulse based constraint relaxation loop.

Here are some other references/links to publications and resources.

Hope this helps,
Erwin
dkfdkf
Posts: 8
Joined: Mon Jul 16, 2007 10:25 pm

Re: Translational Constraint

Post by dkfdkf »

Re: Old Translational Constraint stuff

Looking here: http://video.google.com/videoplay?docid ... 3489&hl=en

It seems that the translational constraint (using the bullet 6dof code) is _NOT_ a hard constraint; rather I can do things that will violate the constraint ... and then forces are applied back to make the constraint hold -- is this true? (That I can break the constraint and it "adjusts" for this; rather than forcing me to act within the constraint?)

Is this true (or am I likely doing something wrong since the green body part is undergoing orientations).


Re: New/Custom Constraint

Thanks for the references, I'll read up on them and get back on this.
jackskelyton
Posts: 32
Joined: Mon Nov 05, 2007 3:52 pm

Re: Translational Constraint

Post by jackskelyton »

We're having trouble getting this up and running... we need to constrain an actor to the XY plane like he's doing. We have two blocks of code, as follows:

The first section simply creates a fixed position rigidBody to act as the constraint anchor:

Code: Select all

   // Set up constraint fixed body
   btDefaultMotionState* myMotionState = new btDefaultMotionState();
   mFixedBody = new btRigidBody(0, myMotionState, 0);
   mPhysicsWorld->addRigidBody(mFixedBody);
The second creates a constraint using the relevant actor -- I pretty much just copied your code here:

Code: Select all

      bool useLinearReferenceFrameA = false;//use fixed frame B for linear limits
		btTransform frameInA = btTransform::getIdentity();
		btTransform frameInB = btTransform::getIdentity();
      btVector3 lowerSliderLimit = btVector3(1,1,0);
      btVector3 hiSliderLimit = btVector3(0,0,0);
      btGeneric6DofConstraint* constraint = new btGeneric6DofConstraint(*mRigidBody, 
                                                                     (*mWorld->GetFixedBody()), 
                                                                     frameInA,
                                                                     frameInB,
                                                                     useLinearReferenceFrameA);
      constraint->setLinearLowerLimit(lowerSliderLimit);
      constraint->setLinearUpperLimit(hiSliderLimit);

      mWorld->GetPhysicsWorld()->addConstraint(constraint);
When we run this, we get an access violation and a call stack like this:

....exe!btCollisionObject::getIslandTag() + 0xf bytes
....exe!btGetConstraintIslandId() + 0x27 bytes
....exe!`btDiscreteDynamicsWorld::solveConstraints'::`2'::InplaceSolverIslandCallback::ProcessIsland() + 0xa3 bytes
....exe!btSimulationIslandManager::buildAndProcessIslands() + 0x5e5 bytes
....exe!btDiscreteDynamicsWorld::solveConstraints() + 0x18d bytes
....exe!btDiscreteDynamicsWorld::internalSingleStepSimulation() + 0x93 bytes
....exe!btDiscreteDynamicsWorld::stepSimulation() + 0x181 bytes

The only thing I can think of that might affect it is the fact that this particular actor has most of its translation props hard-set: position, velocity, angular factor, friction, etc. However, we don't ever explicitly set its Z-trans, so I wouldn't think it would be overriding anything... any ideas?