revolute joint limits not working

hey there,

I'm having some issues with using limits of revolute joints

the set-up is basically my swingarm is connected to the chassis with a revolute joint and a limit at -30 and 20 degrees. The rearwheel then is connected to the swingarm via a revolute joint to act as the motor that powers my motorbike

my problem is that the limits don't seem to do anything.

References:

SWF
pressing control (reverse) will swing the swing arm around so you'll see how its not working


my code for the swingarm (simplified):
Code:
var rearMotorDef:b2RevoluteJointDef = new b2RevoluteJointDef ()
rearMotorDef.Initialize (chassis, swingArm, new b2Vec2 (20 / Vals.RATIO, 6/ Vals.RATIO))
rearMotorDef.enableMotor = true
rearMotorDef.maxMotorTorque = 20
         
rearMotorDef.enableLimit = true
rearMotorDef.lowerAngle = -30 / (Math.PI/180)
rearMotorDef.upperAngle = 20 / (Math.PI/180)

var motor:b2RevoluteJoint = Vals._world.CreateJoint (rearMotorDef) as b2RevoluteJoint


thanks for the read.
I'm having this exact same problem with revolute joint limits not working in the flash port of Box2D. I'm trying to build something which has several segments where there's a limit on how much rotation can happen between them and as soon as there's even a moderate force, the joint goes right outside the limit. I double checked my joints to make sure there wasn't some subtlety I was missing and my debugging output wound up looking like this:
Limit is enabled: true
The max Angle is: 0.5235987755982988
The min Angle is: -0.5235987755982988
The current Angle is: -1.9287966261299396

I don't see any response to the initial poster. Is this a known issue? I don't see it listed on the Google Code page. All the documentation seems to suggest that it's impossible for angles to exceed their constraints, and yet it's plainly happening in my simulation. (And not even in weird, tricky situations. I can't get it to not happen). Are there situations where these angle limits would fail?

Essentially, it looks like a pretty small force can break the limits on angle in Revolute joints. That doesn't seem like correct behavior. Can someone else confirm that this is incorrect behavior or explain why it's correct behavior? I'd be glad to post my example, but I do think that I'm seeing the same problem as the previous poster, so if someone can explain why that's happening in his example, I think that would suffice.

Thanks a lot,
Keith
I observed pretty much identical behavior when I tried using limits on a revolutejoint - I tried to add a 180 degree limit to how far the player could swing around, but it made absolutely no difference and it could still spin 360 degrees around a point.
samehere...

happy that the fault does not seem to lie in my code...

any ideas on how whe can solve this?
I had the same issue and came to the same conclusion as Keith above. I.e. that the limits are "working", but they're easily breakable by applied forces (even if those forces aren't particularly strong).

To work around it, I had to juggle carefully the forces involved as well as the density/masses of the bodies involved (effectively keeping the force under whatever threshold is in place that is causing the limits to be broken), but it's a far from ideal situation.

Not sure if it's related to this issue, though it seems like it probably is (and I'm not sure if it's intended design either), but I have had difficulties with joints not being "strong" enough. Eg. if you have two bodies connected with a joint and one body gets stuck, then the other body becomes separated. Logically, I would have thought binding two bodies together with a joint (particularly a revolute one) would effectively bond them together into one body, but it doesn't appear so.
yes juggling forces was my way too.
i used motor-speeds and torques on the joints of a ragdoll in order to make it ride a vehicle correctly.
however: there is always one situation where this leads to problems...

is this whole issue a bug in the flash port?
or is it a feature in the box2d system?
Easiest way to find out is to ask Erin himself. He rarely frequents the flash forum so a question in the general forum( labeled as coming from the flash side ) would probably draw him out. From what I remember though, it is a feature in Box2D. Joints are not perfectly rigid and are just one a many constraints that have to be solved. I have heard that upping the velocity iterations can improve joint stability and that may be one avenue you could explore. Additionally, I've heard that different densities can have an effect on the joints stability as well.

I'll see if I can dig up the old posts on this and link them.
Instead of:

Code:
rearMotorDef.lowerAngle = -30 / (Math.PI/180)
rearMotorDef.upperAngle = 20 / (Math.PI/180)


Try:

Code:
rearMotorDef.lowerAngle = -30 * Math. PI / 180
rearMotorDef.upperAngle = 20 * Math.PI / 180


The joint limits can go beyond 360 degrees, so you are likely never hitting it (due to the math error).
Erin Catto wrote:
Instead of:
Code:
rearMotorDef.lowerAngle = -30 / (Math.PI/180)
rearMotorDef.upperAngle = 20 / (Math.PI/180)

Try:
Code:
rearMotorDef.lowerAngle = -30 * Math. PI / 180
rearMotorDef.upperAngle = 20 * Math.PI / 180

The joint limits can go beyond 360 degrees, so you are likely never hitting it (due to the math error).


Thanks, Erin, that's definitely a serious problem in his code. Unfortunately, mine doesn't look like that, it looks like this:
Code:
            var tieRodAttachDef:b2RevoluteJointDef = new b2RevoluteJointDef();
            tieRodAttachDef.upperAngle = Math.PI/6;  // 30 degrees                 
            tieRodAttachDef.lowerAngle = -tieRodAttachDef.upperAngle;
            tieRodAttachDef.enableLimit = true;


And I'm also not having the limits have any effect. Clearly, I'm not actually having exactly the same problem he was, so I was incorrect to say so.

Since my last post, to check to see if there was too much force, I tried scaling down the force and the density (so that the acceleration on the bodies would still be the same). Multiplying my previous forces (in about the 10 N range) by 0.000001 still results in the problem happening, so it doesn't seem likely to be overwhelming force.

Tomorrow I'll build some small examples to try to figure out exactly when this does and does not happen. If I can, I'll do C++ versions, but currently my C++ Testbed program produces a bus error when I run it, so I may have to do it in actionscript if I can't get the C++ building correctly.

Keith
Keith,

A few things to try:
- try setting the density of all your dynamic bodies to be equal
- try disabling continuous simulation
- try enabling the motor with a modest torque and velocity. Does the limit engage?

If none of those work, there might be a problem in the Flash code. Try stepping through the code to see if the revolute joint hits the limit.

Original thread: https://box2d.org/forum/viewtopic.php?t=4778