Rigid joint behaviour

Question about joint behaviour,

I'm trying to make a "rigid" feeling revolute joint that can be controlled by the user, so they can map keys to rotate it clockwise and counter-clockwise, and when they aren't pressing a key, the joint tries to stay exactly where it is.

Currently what I'm doing is whenever no keys are pressed, I set the motor speed to zero, and greatly increase the max motor torque. Then when a key is pressed, I set the max motor torque back to normal, and set the motor speed to some number.

The problem I'm encountering is that occasionally I run into the situation where if there's a strong force opposing the motor (such as gravity), the motor will rotate in the wrong direction when a key is pressed, but will remain rigid when no keys are pressed. Ideally I'd like it to be able to detect when this will happen, and just treat it as if no key is being pressed in this case.

So my question is, is there any way of detecting the forces acting on a joint? They must be computed at some point during the physics step, but is there an easy way of detecting them from outside a physics step? Or is there an easier way of going about this whole thing that I'm completely missing?
You should already know what the gravity force in your simulation is set to, right? If you don't want gravity to apply to the object that you're rotating, apply the reverse of the gravity vector (multiplied by the object's mass) at the object's center of mass as a force before every timestep. That will cancel out gravity.

Though if your motor isn't already strong enough to lift your object, then probably your motor is too weak or your object is too heavy. 😛
If you are trying to model a "servo" or some such type of motor which will actively apply a torque to keep itself at a certain position or angle, you may want to increase the max force/torque a bit and set the direction as a function of the position/angle. I would think that changing the max force/torque when no buttons are pressed is a rather bad way of simulating static friction, if that is what you're trying to do.

Could also maybe throw in some damping.

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