Implementing a scissor model using constraints

Post Reply
jhasketan
Posts: 5
Joined: Sat Sep 14, 2019 7:24 am

Implementing a scissor model using constraints

Post by jhasketan »

Dear All,

I am building a surgery scissor simulator. I have implemented a scissor using bullet physics. Basically this scissor is consist of 4 meshes 1) base, 2) connector, 3) left tip and 4) right tip. Scissor can move left or right or top or bottom. Also both tip can open and close. So, I have a hinge constraint between base and connector and implemented two other hinge constraints(using generic6DOFConstraints) between left tip and connector, right tip and connector. I am manipulating scissor tip position using a touch 3D device and constraint shall apply inverse kinematics to move to position. All meshes dynamic rigid body. My problem is when I move the tip slowly it is somewhat working but when I move tip very fast, constraints and rigid bodies are falling apart. Both code and video are attached. I checked RoggDoll implementation and my implementation is very similar. But don't know why it is not behaving same. Any help would be greatly appreciated.

Below is the dropbox link for the video :

https://www.dropbox.com/sh/rcsltxk08101 ... z6W6a?dl=0
Attachments
ScissorSimulator.cpp
Class Implementation
(20.22 KiB) Downloaded 213 times
ScissorSimulator.h
Class header
(4.3 KiB) Downloaded 225 times
User avatar
drleviathan
Posts: 849
Joined: Tue Sep 30, 2014 6:03 pm
Location: San Francisco

Re: Implementing a scissor model using constraints

Post by drleviathan »

First thing to try would be to use smaller substeps. Your code does this:

Code: Select all

    _bWorld->stepSimulation(_timeline.previousFrameDuration(), 1);
 //_bWorld->stepSimulation(0.016);   
Which uses the default substep duration: one 1/60th of a second, and you only take one substep per step. What I would recommend is to try this:

Code: Select all

    const btScalar substepFrequency = 240.0;
    const btScalar substepDuration = 1.0 / substepFrequency;
    const btScalar expectedMaximumFrameDuration = 0.05; // 20Hz
    const int32_t maxSubsteps = (int32_t)(expectedMaximumFrameDuration / substepDuration);
    _bWorld->stepSimulation(_timeline.previousFrameDuration(), maxSubsteps, substepDuration);
Play around with the substepFrequency to see how that changes the accuracy of the constraint solver. Note: there have been reports of misbehaviour when the substeps get too small (~ 0.001 sec) but I have not tried it.
Post Reply