from fairino import Robot
import time
START_POS = [29.74836540222168, -134.0897674560547, -89.1602554321289, -46.7747802734375, 89.99434661865234, 29.713558197021484]
START_CART = [459.6044006347656, 145.47499084472656, -23.17245864868164, 179.98126220703125, -0.017205478623509407, -89.9651870727539]
length = 200 # Length/width of a square grid in mm
def get_z_force(robot: Robot.RPC):
e, ft = robot.FT_GetForceTorqueRCS()
if e != 0:
print("Error getting force/torque:", e)
return False
return ft[2] # Z-axis force
def make_grid(robot: Robot.RPC, loops=20):
file_object = open(f"{loops}x{loops}_data.txt", "w") # open graph data file
robot.SetSpeed(40) # Set speed to 40%
# Loop over specified grid size and probe for depth
for i in range(loops):
for j in range(loops):
robot.MoveL(START_CART, tool=1, user=0, vel=100, offset_flag=1, offset_pos=[(i * -(length / loops)), (j * -(length / loops)), 0, 0, 0, 0]) # Go to probe prep
time.sleep(0.5)
# Use servo cart to slowly lower the tool until force is detected
for _ in range(400):
robot.ServoCart(1, [0, 0,-0.15, 0, 0, 0], vel=100)
time.sleep(0.008)
fz = get_z_force(robot)
if( fz is not False):
if(abs(fz) > 0.5):
coord = robot.GetActualTCPPose()[1][:3] # Get current TCP position of contact point
file_object.write(f"{[i for i in coord]} \n".replace('[', '').replace(']', '')) # Write to file
print(f"Force detected: {fz} at position {coord}")
break
else:
return False
robot.MoveL(robot.GetActualTCPPose()[1], tool=1, user=0, vel=100, offset_flag=1, offset_pos=[0, 0, 50, 0, 0, 0]) # Retract 50mm
def main():
robot = Robot.RPC('192.168.58.2')
robot.SetSpeed(20) # Set speed to 20%
robot.FT_SetZero(1) # Set force/torque sensor zero
robot.MoveJ(START_POS, tool=0, user=0, vel=50) # Move to start position
make_grid(robot, loops=10)
if __name__ == "__main__":
main()