implementing static friction

Cheers,

In my attempt to physically simulate a simple pedulum connected to the ground with a simple motor (not for a game but for robotics), I'm trying to improve on the friction box2d can simulate. As it seems, the only way to have a revolute joint have friction is to enable the motor and set a maximum torque, which is basically dry friction. Now, for a fluid friction component, it is easy to just take the current velocity times some constant and apply that torque against the current direction (even though that comes a step too late). My problem lies with static friction, i.e. a force dependent component which holds against a certain maximum torque while the velocity is zero. From what I have read so far, it seems not possible to determine the resultant force/torque on a body and even if, I would need to set impulse and velocity to 0 in the same time step the force occurs. What else can I do to simulate static friction that ideally does not introduce oscillations? (Overriding box2d methods seems a bit tricky but might be a way to go)

Thanks a lot,
Stefan
I may be wrong about this, but I think that I once simulated this by using a very high drag for the object when it wasn't moving, and as soon as it was moving over a very small threshhold, changed the drag. If you do happen to solve the problem properly, I'd like to know a little about what you found.
As I said, this is not for a game, so simulating things so they look like something in that direction is not enough. Static friction is not dependent on velocity, i.e. it happens before anything moves. After movement has started, the friction is a different one, so even very small movement is not small enough. (I did try a velocity based solution before but by it's nature that has time dependent behaviour, so it can get into oscillations).
I'm considering to not follow this path with box2d anymore as it seems too much centered on games.
Performance is more important than correctness for the rest of us.
fair enough, even though I don't think it is so much a question of performance rather than design in this case.
You can achieve static joint friction by using a revolute joint and setting the max torque positive and the target velocity to zero. You can increase the velocity iterations to improve the accuracy.

The joint friction does not consider the joint load. In other words you might want the joint friction to get stronger if there is a large load placed on the joint. You can approximate this by updating the max torque every frame according to the current reaction force in the joint.
Thanks Erin.
Since what you suggest is the same that the manual suggests to get "joint friction", what exactly does this give me?
I assume that what using the motor like this results in is that as long as the applied forces don't get over the max value, the motor will control the velocity to stay at 0. That would be static friction. When the forces get larger, the motor still tries to stay at zero velocity, so it will constantly apply the max force opposing the direction of movement, so we have dry friction as well. Ok, and velocity dependent friction if I change the max torque with the angular speed. Is the way I understand it correct?
Now I wonder how to make the joint move though. Actually, I need to apply a moment to the joint (not the body) which seems completely impossible now.
(I would be fine with adding code to the RevoluteJoint class in my local box2d copy, so maybe it makes sense to have an ApplyTorque method in the joint.)

Thanks a lot,
Stefan
Alright, I looked a bit at the routines to calculate the revolute joint motor and added a few lines that add impulses for an applied torque.
It would be very helpful if you can say if that looks reasonable (they seem to work ok) or if I missed something important.
They look like this (language is javascript):

Code:
Box2D.Dynamics.Joints.b2RevoluteJoint.prototype.SolveVelocityConstraints = function (step) {
      (...)
      // Solve motor constraint.
      if (this.m_enableMotor && this.m_limitState != b2Joint.e_equalLimits) {
         var Cdot = w2 - w1 - this.m_motorSpeed;
         var impulse = this.m_motorMass * ((-Cdot));
         var oldImpulse = this.m_motorImpulse;
         var maxImpulse = step.dt * this.m_maxMotorTorque;
         this.m_motorImpulse = b2Math.Clamp(this.m_motorImpulse + impulse, (-maxImpulse), maxImpulse);
         impulse = this.m_motorImpulse - oldImpulse;
         w1 -= i1 * impulse;
         w2 += i2 * impulse;
      }

      //apply torque
      if (this.m_applyTorque){
          impulse = this.m_applyTorque * step.dt
          w1 += i1 * impulse
          w2 -= i2 * impulse
          this.m_applyTorque = 0
      }
     
      (...)


The new variable is initialized further up.
This way I can set a torque to be applied in every time step, could be more beautiful but good for now.

Cheers and thanks,
Stefan

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