I have the following code to detect when a motorized joint hits a limit, and reverse it:
The problem is, sometimes the joint doesn't make it all the way to the limit, but stops moving anyway. It can move up and down all day, and then at some point, it just doesn't make it, perhaps based on some minute force applied at just the right time. If I increase the maximum motor force, it seems to work even less often. It's not within the Linear Slop distance when it stops either (it's usually ~6x linear slop distance from the limit). I would think that it should continue moving upwards, but it just sits there.
Stepping through solveVelocityConstraints() in PrismaticJoint shows that the joint state is INACTIVE (that is, it never gets set to AT_UPPER/AT_LOWER), but the motor just stops moving.
So, is this a problem of simply fine-tuning the strength of the joint, or will I need to add in my own (somewhat larger) slop value? Or is there some other option I'm missing? If necessary I can come up with some specifics about how the joint and bodies are created.
Code: Select all
public void step() {
boolean wasAtLimit = atLimit();
world.step(1/60f, 10, 10);
if (!wasAtLimit && atLimit()) {
prismaticJoint.setMotorSpeed(-prismaticJoint.getMotorSpeed());
}
}
private boolean atLimit() {
float jointTranslation = prismaticJoint.getJointTranslation();
if (jointTranslation <= prismaticJoint.getLowerLimit()) {
return true;
} else if (jointTranslation >= joint.getUpperLimit()) {
return true;
} else {
return false;
}
}
The problem is, sometimes the joint doesn't make it all the way to the limit, but stops moving anyway. It can move up and down all day, and then at some point, it just doesn't make it, perhaps based on some minute force applied at just the right time. If I increase the maximum motor force, it seems to work even less often. It's not within the Linear Slop distance when it stops either (it's usually ~6x linear slop distance from the limit). I would think that it should continue moving upwards, but it just sits there.
Stepping through solveVelocityConstraints() in PrismaticJoint shows that the joint state is INACTIVE (that is, it never gets set to AT_UPPER/AT_LOWER), but the motor just stops moving.
So, is this a problem of simply fine-tuning the strength of the joint, or will I need to add in my own (somewhat larger) slop value? Or is there some other option I'm missing? If necessary I can come up with some specifics about how the joint and bodies are created.