I am trying to get my tool changer to work on our Mach4 lathe.
I have space for 6 tools, each spaced 60 degrees apart.
However, I can't get motor A to activate when I call for a tool change.
I have tried using this M6 macro, but nothing happens when I request a change. It seems like I am missing something?
function m6()
  inst = mc.mcGetInstance()
  if not inst then
    mc.mcCntlSetLastError(inst, "Failed to get Mach4 instance.")
    return
  end
  --... (previous code)
  if selectedtool == currenttool then
    mc.mcCntlSetLastError(inst, "No tool change needed.")
    return
  end
  -- Enable motor A before performing the tool change
  mach.MotorEnable(1, true)
  mc.mcCntlSetLastError(inst, "Enabled Motor A")
  local moves = math.abs(selectedtool - currenttool)
  local direction = selectedtool > currenttool and 1 or -1
  if moves == 0 then
    mc.mcCntlSetLastError(inst, "No tool change needed.")
    return
  end
  mc.mcCntlSetLastError(inst, "Moving to Tool ".. selectedtool)
  local max_tool_pockets = 6 -- Set the maximum number of tool pockets supported by your machine
  local move_value = math.min(math.abs((direction * moves) * 60), max_tool_pockets)
  mc.mcCntlSetLastError(inst, "G0 A".. move_value)
  mc.mcCntlGcodeExecuteWait(inst, "G0 A".. move_value.. " G52")
  if (move_value == max_tool_pockets) and (direction > 0) then
    mc.mcCntlSetLastError(inst, "Tool change completed. Maximum tool pocket reached.")
  elseif (move_value == max_tool_pockets) and (direction < 0) then
    mc.mcCntlSetLastError(inst, "Tool change completed. Minimum tool pocket reached.")
  else
    mc.mcCntlSetLastError(inst, "Tool change completed.")
  end
  -- Disable motor A after the tool change is complete
  mach.MotorEnable(1, false)
  mc.mcCntlSetLastError(inst, "Disabled Motor A")
  mc.mcToolSetCurrent(inst, selectedtool)
  mc.mcCntlSetLastError(inst, "Tool Loaded")
  if mc.mcInEditor() == 1 then
    m6()
  end
end