How to set Haptic device parameters?

When add Haptic client to control rbd in scene. I want to know how to set the spring and damping coefficient.

        controller->setTranslationScaling(2.5);
	controller->setLinearKs(250000.0);
	controller->setLinearKd(1700.0);
	controller->setAngularKs(1000000000.0);
	controller->setAngularKd(10000000.0);
	controller->setForceScaling(0.000001);

im a little confuse about these parameters, please give me some suggestions. thanks

Confused on what they mean or having trouble tuning them for your application?


The rigid body controller works by applying a spring force & torque to the rigid body that moves it to the location & orientation of the tracker (physical position & orientation). This is known as virtual coupling, a very popular approach to haptics. Additionally the -force may be rendered back to the device to feel it.

It exists for contact. If you directly render forces back to the user they are often unsmooth because of discretized integration in the rigid body model. Not always, but virtual coupling is flexible. Additionally you the issue of infinite stiffness in static objects. With virtual coupling, the force grows from 0 until it reaches equilibrium, stopping your hand. It also allows virtual & physical locations to differ such that you can push your hand past a wall, but the hand stay at the wall.

It may also be used for smoothing. For instance, directly setting the haptic position & orientation to a camera will make it jittery & very jarring. With virtual coupling there is no jitter.


Integration & Forces:

The rigid body model uses a very basic semi implicit euler integration to apply a force:

velocity += force / mass * dt;
pos += velocity * dt;

The force for the spring is computed as

Force = Spring Force (fS) + Damper Force (fD)

Force is then applied to the rigid body & -Force rendered back to your hand (only spring and damping is applied, not other external forces the body may experience).


Spring Force:

This force is computed from the difference between the virtual (rigid body) and physical (haptic) position.

This exerts a force on the body in the direction of the haptic position causing it to move to that position.

fS = (haptic position - virtual position) * KS;

Where KS scales the spring. (Larger force, tighter spring)


Damping Force

This force is computed from the velocity.

This exerts a force on the body in the opposite direction of velocity. Creates a drag & is for stability.

fD = (-currVelocity) * KD;

Where KD scales the damping.


Stability

What’s largely important here is your force size which relates to your timestep (dt), body mass & inertia, & spring parameters. If ks or dt is too high, you get a large force & you will overshoot the haptic position resulting in an even larger force next time. It will explode instead of converge. It could also not explode & just take longer to converge. This is why damping exists!

Tuning Tips:

  • Start from zero. Set all scales to 0. Incrementally increase ks, & subsequently kd if you notice instability. kd will always be lower though.

  • Start with just linear. Set angular to 0 & scale the rigid body inertia tensor if you don’t want it to rotate while tuning linear.

  • If rendering forces back to the haptic device, start with a very small force scaling (this means a larger difference between virtual & physical position is required to stop your hand). Once you think the spring is tight and smooth enough you can increase the force scaling until the device becomes “stuttery”, if you hit the point of extremely small microstutters, you’re right at the limit.

  • If not rendering forces back to the device set force scaling to 0.

  • If it feels like you’re moving your hand through a viscous fluid, there is too much damping relative to stiffness (ks). Increase ks or decrease kd (which depends on if you hit your limit with ks).

  • For the timestep, 1000 physics updates a second is the standard for virtual coupling if you’re rendering the force back to the device (ie: 1ms, 0.001s). You can often go a bit lower, it largely depends on the kind of stiffness you want.

    • Use sceneManager->setDesiredDt(0.001);
    • This can be a big ask sometimes. Requiring extremely reduced models or models specifically made for performance (like our levelset bone cutting method, FemurCutExample).
    • Desired dt balances out render vs simulation frames. If you can’t hit the desired rate the rendering will start to lag behind. Hit ‘p’ in most iMSTK examples to check the visual and physics update rates.
  • Many devices don’t render torques. Sometimes this can be a major problem for stabilities. Currently all iMSTK examples are tuned for 3dof, forces only. But the model can provide a torque. Usually this means they use a large inertia tensor to prevent rotation of the body by contact. Then an even larger angular ks+kd, such that the users hand is the only thing that can rotate it.

  • Lastly translation scaling is multiplied with position if you want it smaller or larger.

Update on this for anyone who finds this in the future.

https://gitlab.kitware.com/iMSTK/iMSTK/-/merge_requests/764

Introduces critical damping, on by default, which should give good defaults for damping (kd).