Motor(RevoluteJoint) parameters

Sep 26, 2010 at 1:00 PM

I want to create a box and ball character with a RevoluteJoint as motor. I need some default values to start with so, what should these parameters be set to for a normal character, say height 2m and weight 90kg?

Friction on wheel

Friction on ground

MotorSpeed(when

MaxMotorTorque

Is there any other parameters that are important? (I know the motor should be enabled)

Thnx in advance

Alfons

Sep 26, 2010 at 5:53 PM

this is the code I am using, and the motor doesn't move. Must be missing something really simple. ;)

 public void CreateBodyWithMotor()
        {
            _collidesWith = CollisionCategory.All;
            _collisionCategories = CollisionCategory.All;

            _characterBody = BodyFactory.CreateBody(world, new Vector2(position.X / ScreenManager.kf_PixelsMeter, position.Y / ScreenManager.kf_PixelsMeter));
            _characterBody.BodyType = BodyType.Dynamic;

            _wheelBody = BodyFactory.CreateBody(world, new Vector2(position.X / ScreenManager.kf_PixelsMeter, position.Y / ScreenManager.kf_PixelsMeter));
            _wheelBody.BodyType = BodyType.Dynamic;

            _characterFixture = new Fixture;
            _characterFixture = FixtureFactory.CreateRectangle(128 / ScreenManager.kf_PixelsMeter, 120 / ScreenManager.kf_PixelsMeter, 1, _characterBody, new Vector2(0, 128 / ScreenManager.kf_PixelsMeter));
            _characterFixture.Restitution = 0.2f;
            _characterFixture.Friction = 5f;
            _characterFixture.CollisionCategories = _collisionCategories;
            _characterFixture.CollidesWith = _collidesWith;

            joint = JointFactory.CreateFixedAngleJoint(world, _characterBody);
            joint.TargetAngle = 0;

            _wheelFixture = FixtureFactory.CreateCircle(world, 64 / ScreenManager.kf_PixelsMeter, 1, new Vector2(0, 250 / ScreenManager.kf_PixelsMeter), _characterBody);
            _wheelFixture.Restitution = 0.2f;
            _wheelFixture.Friction = 5f;
            _wheelFixture.CollisionCategories = _collisionCategories;
            _wheelFixture.CollidesWith = _collidesWith;

            _motorJoint = JointFactory.CreateRevoluteJoint(_characterBody, _wheelBody, _wheelBody.WorldCenter);
            _motorJoint.MotorEnabled = true;
            _motorJoint.MaxMotorTorque = 180f;
            _motorJoint.MotorSpeed = 0;
	}
To move the motor I am trying this
_motorJoint.MotorSpeed = -90;
_motorJoint.MotorSpeed = 90;                                        
            

Sep 27, 2010 at 9:51 PM

I feel like talking to myself here. I found out what was wrong, I never added the joint to the world

world.AddJoint(_motorJoint);

and I also needed to set MotorTorque to > 0.

Should research how the parameters relate to each other and find out what values works for me. 

One thing I also notice is that the FixedAngleJoint doesn't work so well now with the motor running. If I set the Bias to 1 it seems to work a little better but it stills rotate. Any ideas? 

Cheers

Sep 28, 2010 at 2:28 AM

What about ditching the FixedAngleJoint and instead using the FixedRotation body property?

I guess the FixedAngleJoint still exists for backwards compatability, and also so you can break it based on forces in the simulation.

Sep 29, 2010 at 8:48 PM

I tried to set the fixedRotation to true on the _characterBody but it triggered this Assertion Failure

if (_enableMotor || _enableLimit)          

 {                // You cannot create a rotation limit between bodies that

                // both have fixed rotation.                

Debug.Assert(b1.InvI > 0.0f || b2.InvI > 0.0f);          

 }

And the motor doesn't work.

 

Sep 30, 2010 at 1:49 AM
Edited Sep 30, 2010 at 1:53 AM

how are you declairing your "_motorJoint" object?

Sep 30, 2010 at 3:15 AM

That looks like a bug!

I'll try fix the source control later, but in the meantime you can change it yourself: Try changing:

Debug.Assert(b1.InvI > 0.0f || b2.InvI > 0.0f);

To:

Debug.Assert(b1.InvI > 0.0f && b2.InvI > 0.0f);

That will let you use fixed rotation.

And thanks for posting the code, or nobody would have noticed it! :D

 

Coordinator
Sep 30, 2010 at 7:03 AM

Does not look like a bug to me. You set FixedRotation to true and then try to rotate it using a motor? That is not possible :) or am I missing something?

Sep 30, 2010 at 6:31 PM

Hi Genbox,

I only want to rotate the wheel not the torso(box) of the character. If I use a FixedAngleJoint it works, but the rotation of the torso it's not 100% still. I think I can live with it, but it would be nice to have it fixed.

roberdodd changing it to 

Debug.Assert(b1.InvI > 0.0f && b2.InvI > 0.0f);

 didn't work. I tried to comment it out before but the motor doesn't move anyways.

Sep 30, 2010 at 9:49 PM

Sorry, I read that quickly and in my haste I got confused! Oops, definitely not a bug! XD Sorry!

Sep 30, 2010 at 9:54 PM

@AlfonsA: If that Assert triggers, you must have both bodies with fixed rotation. Your code looks OK in the first post but have you changed it since then?

Make sure you are still doing this: 

_wheelbody.BodyType = BodyType.Dynamic;
Oct 13, 2010 at 8:33 PM

I finally realized what Genbox noticed days ago. I was using the _characterBody when creating the wheelFixture instead of the _wheelBody. So now it works beautifully.

I now have another problem. When the character lands the box is forced downward. It's like there is a spring in the RevolutionJoint.

Is there something I can do to stiffen that up?

I tried a weldJoint but that didn't work, it messed up the motor.

 

Oct 17, 2010 at 10:58 AM

Increasing the number of iterations might help. You do that by changing Settings.VelocityIterations and Settings.PositionIterations (I'm not sure which one will help in this case, but try both). A higher value means more accuracy but a slower speed, and the opposite for a lower value.