Detection of contact between tool and workpiece