https://www.zhihu.com/people/zhang-xuan-chen-76/posts
Learning Robotics by Playing with V-REP
The right way to use force sensor in V-REP (4 steps totally, the step 3 is crucial to guarantee the validity of force/torque data)
[res,forcesensor] = vrep.simxGetObjectHandle(id,'Force_sensor',vrep.simx_opmode_oneshot_wait);
vrep.simxReadForceSensor(id,forcesensor,vrep.simx_opmode_streaming);
while (1)
[res,state,f,tau] = vrep.simxReadForceSensor(id,forcesensor,vrep.simx_opmode_buffer);
if res == vrep.simx_return_ok && state == 1
break;
else
disp('force sensor data is not available!');
pause(0.1);
end
end
while vrep.simxGetConnectionId(id)~=-1
[res,state,f,tau] = vrep.simxReadForceSensor(id,forcesensor,vrep.simx_opmode_buffer);
end