[JBULLET] Axes on BTGeneric6DofConstraint and lock/unlock ?

Baune
Posts: 20
Joined: Tue May 26, 2009 2:36 am

[JBULLET] Axes on BTGeneric6DofConstraint and lock/unlock ?

Post by Baune »

Hello

There are some things that are not really clear to me regarding axis in 6dofconstraints. In HingeJoint you specific set the axis in the constructor but not in 6Dof.
Are they inherited from the bodies rotation matrix or something ?
Also, when talking about only using specific axes, or "unlocking/locking them", how is that achieved ? by setting angularLiminits (for example, 0 and 0 as upper/lower limit in x axis would prevent the joint from moving along the x axis).
I'm using jbullet but it doesnt seem to be any different from the C++ version.
Last edited by Baune on Sun Jun 29, 2014 11:05 pm, edited 1 time in total.
c6burns
Posts: 149
Joined: Fri May 24, 2013 6:08 am

Re: Set the axes on BTGeneric6DofConstraint and lock/unlock

Post by c6burns »

setAngularLowerLimit/setAngularUpperLimit are for angular motion. If you are talking about linear motion you would use setLinearLowerLimit/setLinearUpperLimit. And yes, setting all limits to btVector3(0,0,0) would completely lock motion.

You can really learn a lot by playing with the constraint demo. In fact, the demos are generally great sandboxes for learning and seeing implementation examples.
Baune
Posts: 20
Joined: Tue May 26, 2009 2:36 am

Re: Set the axes on BTGeneric6DofConstraint and lock/unlock

Post by Baune »

c6burns wrote:setAngularLowerLimit/setAngularUpperLimit are for angular motion. If you are talking about linear motion you would use setLinearLowerLimit/setLinearUpperLimit. And yes, setting all limits to btVector3(0,0,0) would completely lock motion.

You can really learn a lot by playing with the constraint demo. In fact, the demos are generally great sandboxes for learning and seeing implementation examples.
OK thanks
Baune
Posts: 20
Joined: Tue May 26, 2009 2:36 am

Re: Set the axes on BTGeneric6DofConstraint and lock/unlock

Post by Baune »

But still, how are the axes defined ?
Basroil
Posts: 463
Joined: Fri Nov 30, 2012 4:50 am

Re: Set the axes on BTGeneric6DofConstraint and lock/unlock

Post by Basroil »

Baune wrote:Hello

There are some things that are not really clear to me regarding axis in 6dofconstraints. In HingeJoint you specific set the axis in the constructor but not in 6Dof.
Are they inherited from the bodies rotation matrix or something ?
btGeneric6DofConstraint::btGeneric6DofConstraint(btRigidBody& rbA, btRigidBody& rbB, const btTransform& frameInA, const btTransform& frameInB, bool useLinearReferenceFrameA)
frameInA and B represent the local axis location and basis in the reference frame of rigid body rbA and rbB respectively. These frames represent the axis when the axis angle is zero (not necessarily what you intend, especially when making systems where two bodies have a starting angle other than zero). For more information you need to check the demo files included in Bullet.
Baune wrote:Also, when talking about only using specific axes, or "unlocking/locking them", how is that achieved ? by setting angularLiminits (for example, 0 and 0 as upper/lower limit in x axis would prevent the joint from moving along the x axis).
I'm using jbullet but it doesnt seem to be any different from the C++ version.
You can try using setLinearLimits and setAngularLimits with non-zero (unlock) or zero(lock) coefficients.
Baune
Posts: 20
Joined: Tue May 26, 2009 2:36 am

Re: Set the axes on BTGeneric6DofConstraint and lock/unlock

Post by Baune »

Thanks you for that. But what does "frameInA and B represent the local axis location and basis in the reference frame of rigid body rbA and rbB respectively." mean ?
c6burns
Posts: 149
Joined: Fri May 24, 2013 6:08 am

Re: Set the axes on BTGeneric6DofConstraint and lock/unlock

Post by c6burns »

It means if you want to swivel or offset the constraint on either end, you can do so in local coords. So, just for a moment, we can imagine the constraint as a rope between a tree branch and a tire swing ... not exactly relevant to a 6dof but oh well. Now you can offset the position or rotation (basis) of either the point where the rope attaches to the branch, or where it attaches to the tire (rbA vs rbB).

For example, let's say the local origin (0,0,0) of the branch is not where you want the rope attached. You use frameInA to provide an offset from rbA's origin. So (0,-1,0) would move it "down" a unit in a Y up coordinate space. In the same way, we probably don't want the rope attached to the origin of the tire as that wouldn't be realistic. So we would use frameInB to move that point up a bit depending on the tire's radius ... eg (0,1,0) for a tire with a 1 unit radius. We can also rotate the tire's resting position by altering the basis of frameInB. Does this make sense?

Seriously play around with the bullet demos. The constraint demo is set up to easily disable everything except the 1 constraint you are playing with. It's a great learning sandbox.
Baune
Posts: 20
Joined: Tue May 26, 2009 2:36 am

Re: Set the axes on BTGeneric6DofConstraint and lock/unlock

Post by Baune »

Maybe I will understand you later, right now I dont. Not a single word. im probably dumb...but I need 3 axis, three vectors to define them. And I cant see where they come from.
c6burns
Posts: 149
Joined: Fri May 24, 2013 6:08 am

Re: Set the axes on BTGeneric6DofConstraint and lock/unlock

Post by c6burns »

There's a constructor to build a btMatrix3x3 from 3 axes, if that's what you mean:

Code: Select all

	/** @brief Constructor with row major formatting */
	btMatrix3x3(const btScalar& xx, const btScalar& xy, const btScalar& xz,
		const btScalar& yx, const btScalar& yy, const btScalar& yz,
		const btScalar& zx, const btScalar& zy, const btScalar& zz)
	{ 
		setValue(xx, xy, xz, 
			yx, yy, yz, 
			zx, zy, zz);
	}
Then you can use btTransform::setBasis
Baune
Posts: 20
Joined: Tue May 26, 2009 2:36 am

Re: Set the axes on BTGeneric6DofConstraint and lock/unlock

Post by Baune »

As as I understand it now..if you set the limit of -10,10 degrees on X angular rotation, it means that body a and b X axis cant have a difference more than 10 degrees in their rotation in each direction.
When you attach the joint and there is more than that, bullet will compensate by rotating the bodies. I'd hoped that the rotation when attaching the joint would be the 0 angle, so to speak.
Edit: So I guess the axes are simply the objects rotation axes and you can't define your own.
Basroil
Posts: 463
Joined: Fri Nov 30, 2012 4:50 am

Re: Set the axes on BTGeneric6DofConstraint and lock/unlock

Post by Basroil »

Baune wrote:I'd hoped that the rotation when attaching the joint would be the 0 angle, so to speak.
Edit: So I guess the axes are simply the objects rotation axes and you can't define your own.
You really need to look at the included demos, mainly the joints one and maybe dynamic control demo. When you define the two axis pair which represents the same point (well, they don't need to, but it gets messy and your idea will be fine without defining separate points), at zero rotation from each other.

You can pick the rotation offset if you want. Lets say you have body a and body b be two spheres located at 0,0,0 and 0,0,2 and have no initial rotation. The pivot point will be at 0,0,1 in terms of world coordinates. The local position for the point is 0,0,1 for body a and 0,0,-1 for body b. If you want the joint to go to +-Pi/8 you simply set your limits for the rotation on two axis to 0 and the third to those values. If you want that initial position to actually be a value other than 0, you rotate one axis by the value you want in the direction you want (you might need to correct for direction by adding a negative sign).

You can define any rotation axis based on the body's center of gravity as the origin and body's rotation basis as the identity basis
bwelch
Posts: 48
Joined: Thu Dec 12, 2013 4:04 pm

Re: Set the axes on BTGeneric6DofConstraint and lock/unlock

Post by bwelch »

I was very confused when learning constraints as well due to the FrameInA and FrameInB stuff. If you do a forum search there are a few threads that go into detail about them, but really as these other guys have said, the ConstraintDemo is the best place to go to learn. I suggest starting with a hinge constraint (I think there's one in the demo that looks like a door; you can comment out all of the other ones) and playing with the values and observing the effects. You'll quickly grasp the angular limits, and you can learn how the frame works there since there's only one axis. Once you get the hinge, move on to the more complex 6DoF.

Good luck!
Baune
Posts: 20
Joined: Tue May 26, 2009 2:36 am

Re: Set the axes on BTGeneric6DofConstraint and lock/unlock

Post by Baune »

bwelch wrote:I was very confused when learning constraints as well due to the FrameInA and FrameInB stuff. If you do a forum search there are a few threads that go into detail about them, but really as these other guys have said, the ConstraintDemo is the best place to go to learn. I suggest starting with a hinge constraint (I think there's one in the demo that looks like a door; you can comment out all of the other ones) and playing with the values and observing the effects. You'll quickly grasp the angular limits, and you can learn how the frame works there since there's only one axis. Once you get the hinge, move on to the more complex 6DoF.

Good luck!
Thanks, I have no problem with the hinge though, or understanding physics engines in general. I've worked with ode, physx and box2d and never had any problem with their joints or anything else..in fact was super easy. Bullets 6DOF of joint is just really confusing to me. The whole frameA and frameB just seems so odd to me. A simple "anchor" would be enough, imho. But I guess I just need to get used to it. I'll check out the demo and hopefully that will clear up some things.
Baune
Posts: 20
Joined: Tue May 26, 2009 2:36 am

Re: Set the axes on BTGeneric6DofConstraint and lock/unlock

Post by Baune »

OK had time to look at it again. I think I get it but still, there are some strange issues when setting the angular limits. If I rotate the bodyA 30 degrees around the the X axis and set the limit to 0 degrees (or anything less than 30) the joint will align the two bodies. I thought the limit angle would be an offset at where the joint where attached, not the actual difference between the rotation.

To clarify: without setting any limits, this is the picture I get.
Image

With setting the limits (to 0 on all axes), the two bodies just align themselves and the initial rotation is ignored.

Image

And this is the code (scala and JME jbullet)

Code: Select all

  def testSixDofJoint() {
	  //create boxes 
	  var b1 = createBox(0, 0, 0)
	  var b2 = createBox(2, 0, 0)
          //rotate b1 30 degrees around x axis
	  var r = b1.getPhysicsRotation();
	  r.fromAngles(Math.toRadians(30).asInstanceOf[Float], 0, 0);
	  b1.setPhysicsRotation(r)
	  //pivots
	  var pivot1 = new Vector3f(1f, 0, 0);
	  var pivot2 = new Vector3f(-1f, 0, 0);
	  //make a joint
	  val joint = new SixDofJoint(b1, b2,pivot1, pivot2,true)
	  joint.setCollisionBetweenLinkedBodys(false)
	  //set limits
	  var a = Math.toRadians(0).asInstanceOf[Float];;
	  var lowerLimit = new Vector3f(-a, -a, -a) 
	  var upperLimit = new Vector3f(a, a, a)
	  joint.setAngularLowerLimit(lowerLimit);
	  joint.setAngularUpperLimit(upperLimit);
	  //add objects
	  
	  world.add(b1)
	  world.add(b2)
	  world.add(joint)
   }

   def createBox(x: Float, y: Float, z: Float): PhysicsRigidBody = {
    var shape = new BoxCollisionShape(new Vector3f(1, 1, 1));
    var actor = new PhysicsRigidBody(shape, 1);
    actor.setSleepingThresholds(0, 0)
    actor.setPhysicsLocation(new Vector3f(x, y, z))
    actor
  }
If anyone could explain this to me, would be greatly appreciated !
Basroil
Posts: 463
Joined: Fri Nov 30, 2012 4:50 am

Re: Set the axes on BTGeneric6DofConstraint and lock/unlock

Post by Basroil »

Try using SixDofJoint(BulletRigidBody nodeA, BulletRigidBody nodeB, Vector3f pivotA, Vector3f pivotB, Matrix3f rotA, Matrix3f rotB, boolean useLinearReferenceFrameA) rather than the one without rotations. jbullet joints seem to be completely different in setup code than their C/C++ counterparts, so it might be best to leave as little to jbullet defaults as possible.
Post Reply