Objects are flown away when big angular impulse is applied

Discuss any questions about BEPUphysics or problems encountered.
Post Reply
DreamWeaver
Posts: 13
Joined: Wed Aug 31, 2011 9:47 pm

Objects are flown away when big angular impulse is applied

Post by DreamWeaver »

This problem also appear with "LineSliderJoint". I have a stick and boxes on it. Stick is bound to ground with "LineSliderJoint" and boxes are bound to stick with weld joint. If big angular impulse is applied to the stick, the stick can fly away in one direction and boxes in another direction. In described scenario it is expected to have a rotated stick with boxes on it.
Is it possible to have stick and boxes always on their places?
Perhaps there are some recommendations regarding weights of objects, or perhaps there are some modes of engine?
Thanks.
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Objects are flown away when big angular impulse is appli

Post by Norbo »

It could be something to do with the configuration of the joints. I could take a closer look if you provide the joint set up, possibly organized such that I can easily plop it into the BEPUphysicsDemos to see it run.

If the angular impulse is truly huge, then some amount of flying apart is expected. However, it should take massive impulses relative to the constrained system masses in order to violate the constraints by a significant amount.

Mass ratios are also a concern. If an object is very heavy relative to the thing it's attached to, the solver will have a hard time keeping things together.
DreamWeaver
Posts: 13
Joined: Wed Aug 31, 2011 9:47 pm

Re: Objects are flown away when big angular impulse is appli

Post by DreamWeaver »

You can find a static method below which represents this situation. I am making a project for Windows Phone 7.
It is just a cylinder which is bound to table with "LineSliderJoint" and 4-5 boxes on it which are bound to cylinder with a "WeldJoint" joint. I use a Motor in "Velocity" mode to rotate cylinder with boxes. And these boxes (at least 1 or two of them) can fly over the whole scene.
I have also noticed that it depends not only on angular velocity, but also on amount of boxes which are joined to cylinder.
With 4 boxes this situation can be represented with angular velocity 15. With 5 boxes this situation can be represented with angular velocity 2.
Will appreciate any solutions and advices.
Thanks for support.

Code: Select all

 private static void testScene(Space space)
        {
            //ground
            var ground = new Box(new Vector3(0, -1, 0), 137.5f, 2, 82.5f);
            space.Add(ground);

            var position = new Vector3(0, 50, 0);

            //cylinder
            var cylinder = new Cylinder(position, 120, 1.5f, 1f);
            cylinder.IsAlwaysActive = true;
            cylinder.OrientationMatrix = Matrix3X3.CreateFromAxisAngle(Vector3.UnitX, (float)(Math.PI / 2));

            var locLineSliderJoint = new LineSliderJoint(cylinder, ground, position, Vector3.Forward, position);
            locLineSliderJoint.Motor.IsActive = true;
            locLineSliderJoint.Motor.Settings.Mode = MotorMode.Servomechanism;
            locLineSliderJoint.Motor.Settings.MaximumForce = 2000;
            locLineSliderJoint.Motor.Settings.Servo.Goal = 0;

            var locRevoluteMotor = new RevoluteMotor(cylinder, ground, Vector3.Forward);
            locRevoluteMotor.IsActive = true;
            locRevoluteMotor.Settings.Mode = MotorMode.VelocityMotor;
            locRevoluteMotor.Settings.MaximumForce = 1000;
            locRevoluteMotor.Settings.VelocityMotor.GoalVelocity = 15f;

            space.Add(cylinder);
            space.Add(locLineSliderJoint);
            space.Add(locRevoluteMotor);

            //boxes on the cylinder
            var betweenBoxed = 10;

            position.Z = -(3 + betweenBoxed) * 4 / 2f;

            for (var i = 0; i < 4; i++)
            {
                var locBox = new Box(position, 2, 10, 3, 0.1f);
                locBox.IsAlwaysActive = true;

                var weldJoint = new WeldJoint(cylinder, locBox);

                CollisionRules.AddRule(cylinder, locBox, CollisionRule.NoBroadPhase);

                space.Add(locBox);
                space.Add(weldJoint);

                position.Z += betweenBoxed;
            }

        }
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Objects are flown away when big angular impulse is appli

Post by Norbo »

Here's a few things at a glance:

1) Is your time step duration 1/30f? Difficult simulations will be a lot less stable when using long time step durations. 1/60f should handle it a lot better. Note that updating the space twice at 1/60f covers the same game time as updating once at 1/30f, though with greater cost and robustness.
2) Increasing the Space.Solver.IterationLimit will increase robustness at the cost of performance as well. If you use 1/60f, you shouldn't have to increase the iterations at all.
3) The further out the objects are, the longer the lever arm is. It becomes harder for the solver to handle it. The WeldJoint is a convenience wrapper class over the top of a BallSocketJoint and NoRotationJoint. By default, it configures the ball socket joint's anchor to be at the midpoint of the two connections. You have information that could make this guess better. Putting the anchor right on top of the box makes it a lot more stable because the lever arm associated with the box is 0 length. Here's an example:

Code: Select all

                var weldJoint = new WeldJoint(cylinder, locBox); //This is the same as before.
                weldJoint.BallSocketJoint.OffsetA = locBox.Position - cylinder.Position; //The offset from the cylinder should cover the full distance.
                weldJoint.BallSocketJoint.OffsetB = Vector3.Zero; //The box's offset is zero length.
You could also create the constraints independently:

Code: Select all

                var ballSocketJoint = new BallSocketJoint(cylinder, locBox, locBox.Position);
                var noRotationJoint = new NoRotationJoint(cylinder, locBox);
With 1 and 3 combined, I have 20 boxes turning at 100 radians/second without issue. I'm sure it could go quite a bit higher, too :)
DreamWeaver
Posts: 13
Joined: Wed Aug 31, 2011 9:47 pm

Re: Objects are flown away when big angular impulse is appli

Post by DreamWeaver »

Thanks a lot. It works really fast. Just amazing.
Post Reply