require("Common")

function M150() 
	if Is_THC_Mode() then
		PushCurrentDistanceMode()
		PushCurrentMotionMode()
		if  not IsProbingPinConfigured() then
			DisplayMessage(GetMessage(Messages.ProbeNotConfigured))
			Stop()
			return			
		end
		if not IsSpecificProbingPinConfigured(2) then
			DisplayMessage(GetMessage(Messages.SecondProbeNotConfigured))
			Stop()
			return
		end
		if (PinGetState(Inputs.Probing) or PinGetState(Inputs.Probing2)) then
			DisplayMessage(GetMessage(Messages.ProbeActive))
			Stop()
			return
		end
		
		GotoSafeZ()
		
		local max_probe = -1000
		local ProbeFeed = GetProbeFeed()
		ExecuteMDI("G90 G38.2 P1 Z"..max_probe.." F"..ProbeFeed)
		local pos_z1 = AxisGetMachinePos(Axis.Z)
		ExecuteMDI("G90 G38.2 P2 Z"..max_probe.." F"..ProbeFeed)
		local pos_z2 = AxisGetMachinePos(Axis.Z)
		---
		local dz = pos_z1 - pos_z2
		SetOmichSensorDelta(dz)
		GotoSafeZ()
		DisplayMessage("Расчет завершен, dz = "..dz)
	end
end