function mcServo.AbsolutePositionRecovery(address)
local rError = 0
local ctsInch = mc.mcMotorGetCountsPerUnit(inst, address)
local sError, position = mcServo.GetPosition(address, ctsInch)
if sError ~= 0 then; rError = 1; return rError end
mc.mcAxisSetPos(inst, address, position)
mc.mcAxisHomeComplete(Inst, address);
return rError
end
---------------------------------------------------------------
-- Start-Up Script --
---------------------------------------------------------------
function startUpScript()
local welcomeBox = wx.wxMessageBox("Welcome to Mach 4. Do you wish to run the Start-Up Script?", "Welcome",2)
if welcomeBox == 2 then
local oilBox = wx.wxMessageBox("Apply Vactra No. 2 Oil to the Following Locations: \n \n-X Axis Ways \n-Y Axis Ways \n-Z Axis Ways \n\nVerify the air compressor is powered on and pressure is >100psi.", "Step 1/5 - Maintenance Reminder",4)
local configBox = wx.wxMessageBox("Do you wish to write the default configuration to the Servo Drives?", "Step 2/5 - Servo Configuration",2)
if configBox == 2 then
local xmtError = mcServo.writeStandardConfig() --Configure all axes
if xmtError == 0 then
wx.wxMessageBox("Configuration Successful", "Step 2/5 - Servo Configuration",4)
else
wx.wxMessageBox("Configuration Failed! \n \n Some parameters may be set incorrectly for use with Mach 4. Shut down Mach 4 and try again. \n If this issue persists, confirm connectivity and parameters using Ultraware. ", "WARNING",4)
end
end
local enableBox = wx.wxMessageBox("Do you wish to Reference Home? Choosing YES will enable the axes", "Step 3/5 - Homing",2)
if enableBox == 2 then
mc.mcAxisEnable(inst, 0, true);
mc.mcAxisEnable(inst, 1, true);
mc.mcAxisEnable(inst, 2, true);
mc.mcAxisEnable(inst, 5, true);
local HomeBox = wx.wxMessageBox("Do you wish to restore absolute position data from Servo Drives? \n \nChoose YES to restore homing data. \nChoose NO to Home to Limit Switches. \nChoose CANCEL to skip homing.", "Step 3/5 - Homing",18)
if HomeBox == 2 then
local e1 = mcServo.AbsolutePositionRecovery(0)
local e2 = mcServo.AbsolutePositionRecovery(1)
local e3 = mcServo.AbsolutePositionRecovery(2)
local e4 = mcServo.AbsolutePositionRecovery(5)
if e1 ~= 0 or e2 ~= 0 or e3 ~= 0 or e4 ~= 0 then
wx.wxMessageBox("Home Position Recovery Failed! \n \n Axes must be referenced to switch before operation.", "Homing Failed",4)
else
wx.wxMessageBox("Home Position successfully read from Servo Drives", "Step 3/5 - Homing",4)
end
elseif HomeBox == 8 then
wait = coroutine.create (RefAllHome) --This is the code from the ref all home button
--Figure out how to wait here unitl the coroutine is complete and homing has finished.
local hsBox = wx.wxMessageBox("Home to Switch completed Successfully. \n \nDo you wish to write the absolute home position to the Servo Drives?", "Step 3/5 - Homing",2)
if hsBox == 2 then
local a1 = mcServo.DefineHome("0x00")
local a2 = mcServo.DefineHome("0x01")
local a3 = mcServo.DefineHome("0x02")
local a4 = mcServo.DefineHome("0x05")
if a1 ~= 0 or a2 ~= 0 or a3 ~= 0 or a4 ~= 0 then
wx.wxMessageBox("Home Position Definition Failed! \n \n Absolute Position Recovery will be inaccurate until corrected.", "Homing Failed",4)
else
wx.wxMessageBox("Home Position successfully saved to Servo Drives.", "Step 3/5 - Homing",4)
end
else
wx.wxMessageBox("Home Position was not saved to Servo Drives.", "Step 3/5 - Homing",4)
end
end
end
local softBox = wx.wxMessageBox("Do you wish to enable Soft Limits?", "Step 4/5 - Soft Limits",2)
if softBox == 2 then
mc.mcSoftLimitSetState(inst,0,1)
mc.mcSoftLimitSetState(inst,1,1)
mc.mcSoftLimitSetState(inst,2,1)
wx.wxMessageBox("Soft Limits Enabled", "Step 4/5 - Soft Limits",4)
else
wx.wxMessageBox("Soft Limits are not enabled. Use Caution when jogging", "Step 4/5 - Soft Limits",4)
end
local spindleBox = wx.wxMessageBox("Do you wish to run the Spindle Warm-Up Routine? This will take approximately 5 minutes", "Step 5/5 - Spindle Warm-Up",2)
if spindleBox == 2 then
local cautionBox = wx.wxMessageBox("CAUTION! The Spindle is about to run. Verify no cutting tools are present. \n \nKeep Hands Clear!", "CAUTION!",16)
if cautionBox == 4 then
mc.mcCntlGcodeExecuteWait(inst,"M03 S500")
mc.mcCntlGcodeExecuteWait(inst,"G04 P30000")
mc.mcCntlGcodeExecuteWait(inst,"S1000")
mc.mcCntlGcodeExecuteWait(inst,"G04 P30000")
mc.mcCntlGcodeExecuteWait(inst,"S1500")
mc.mcCntlGcodeExecuteWait(inst,"G04 P30000")
mc.mcCntlGcodeExecuteWait(inst,"S2000")
mc.mcCntlGcodeExecuteWait(inst,"G04 P30000")
mc.mcCntlGcodeExecuteWait(inst,"S2500")
mc.mcCntlGcodeExecuteWait(inst,"G04 P30000")
mc.mcCntlGcodeExecuteWait(inst,"S3000")
mc.mcCntlGcodeExecuteWait(inst,"G04 P30000")
mc.mcCntlGcodeExecuteWait(inst,"S3500")
mc.mcCntlGcodeExecuteWait(inst,"G04 P30000")
mc.mcCntlGcodeExecuteWait(inst,"S4000")
mc.mcCntlGcodeExecuteWait(inst,"G04 P30000")
mc.mcCntlGcodeExecuteWait(inst,"S4500")
mc.mcCntlGcodeExecuteWait(inst,"G04 P30000")
mc.mcCntlGcodeExecuteWait(inst,"S5000")
mc.mcCntlGcodeExecuteWait(inst,"G04 P30000")
mc.mcCntlGcodeExecuteWait(inst,"M05")
wx.wxMessageBox("Spindle Warm-up Complete", "Step 5/5 - Spindle Warm-Up",4)
end
end
end
end