Tool_contact() URSCRIPT not accurate

Hello,

I use the tool_contact() function in URScript. I implemented it as it is in the exemple in the manual (14.1.49):

writer.appendLine("while True:");
writer.appendLine("step_back=tool_contact()");
writer.appendLine("if step_back <=0 :");
writer.appendLine("speedl([0,0,-0.005,0,0,0],0.05,t=get_steptime())");
writer.appendLine("else :");
writer.appendLine("stopl(3)");
writer.appendLine("break");
writer.appendLine("end");
writer.appendLine("end");

However, the object I get in contact can bend. Sometimes, the contact is detected very accurately but sometimes the cobot pushes really hard before detecting the contact.

Any idea why the results aren’t always the same?

Thanks.