Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function m6()
- --Tool Change
- --get newtool/oldtool numbers and return them as selectedtool for newtool and currenttool for oldtool
- --if newtool is the same, end
- --toolchange_checksensors_s1s4()
- local inst = mc.mcGetInstance()
- if(toolchange_getspindlestatus()==2) then
- print("Tool attached incorrectly, Tool change will not start")
- mc.mcCntlEnable(inst, false)
- do return end
- end
- if (toolchange_machine_homed()==false) then
- --the machine has not been homed, which might result in a crash while trying to go to any of the tools' locations
- print("Machine not homed, Tool change will not start")
- mc.mcCntlEnable(inst, false)
- do return end
- end
- if (toolchange_machine_coords_allowed()==false) then
- --the machine is in an unallowed location (next to the tool rack). A crash is likely.
- print("Y axis too close to the tool rack, Tool change will not start")
- mc.mcCntlEnable(inst, false)
- do return end
- end
- local selectedtool = mc.mcToolGetSelected(inst) --get the n. of the new tool
- local currenttool = mc.mcToolGetCurrent(inst) --get the n. of the tool already selected
- if (selectedtool == currenttool) then --if the to-be-selected tool is the same as the current one, no tool change is necessary
- print("No tool change necessary")
- do return end
- end
- if (selectedtool<1) then
- print("Selected tool number out of range. Allowed values 1-21")
- mc.mcCntlEnable(inst, false)
- do return end
- elseif (selectedtool>21) then
- print("Selected tool number out of range. Allowed values 1-21")
- mc.mcCntlEnable(inst, false)
- do return end
- end
- if (currenttool<1) then
- print("Current tool number out of range. Allowed values 1-21")
- mc.mcCntlEnable(inst, false)
- do return end
- elseif (currenttool21) then
- print("Current tool number out of range. Allowed values 1-21")
- mc.mcCntlEnable(inst, false)
- do return end
- end
- if (currenttool>9) then
- if (toolchange_checksensors_s2()==0) then
- --there's a tool in the tool holder, even though there shouldn't be one there. The tool holder in a state where a tool would be there also counts as if there was a tool attached.
- print("Tool number incorrect. Remove the tool from the main spindle or correct the tool number")
- do return end
- end
- end
- --get the machine's state to return to it back later. Absolute vs Incremental, etc.
- --Var# is the PoundVar number for the register holding the value of the attribute.
- --Var# Gcode Description
- --4002 G17 set XY plane
- --4003 G90 set absolute mode
- --4005 G95 set feed as units per minute
- --4006 G21 set units to mm
- --4015 G61 set to exact stop mode, as to avoid taking shortcuts around corners and move predictably
- local CurFeed = mc.mcCntlGetPoundVar(inst, 2134)
- local CurFeedMode = mc.mcCntlGetPoundVar(inst, 4001)
- local CurPlaneMode = mc.mcCntlGetPoundVar(inst, 4002)
- local CurAbsMode = mc.mcCntlGetPoundVar(inst, 4003)
- local CurSpeedMode = mc.mcCntlGetPoundVar(inst, 4005)
- local CurUnit = mc.mcCntlGetPoundVar(inst, 4006)
- local CurMotionMode = mc.mcCntlGetPoundVar(inst, 4015)
- --initialise (Safe start G codes)
- mc.mcCntlGcodeExecuteWait(inst, "G21 G40 G61")
- --mc.mcCntlGcodeExecuteWait(inst, "G17 G90 G95 G21 G40 G61")
- --mc.mcCntlSetLastError(inst, "TC initialised")
- toolchange_zup() --Rise the Z axis up in order to avoid crashes while moving around the table. This will not happen in the tool rack since the toolchange will not start there.
- --toolchange_spindlecover_up()
- if (currenttool>8) then --The current tool is in the boring head
- if (selectedtool>8) then --The selected tool is in the boring head
- toolchange_boringhead_allin()
- toolchange_gotosafe()
- toolchange_boringhead_toolout(selectedtool)
- toolchange_boringhead_down()
- toolchange_setoffsets(selectedtool)
- elseif (selectedtool<9) then --The to-be-selected tool is goes in the main spindle
- toolchange_boringhead_up()
- toolchange_boringhead_allin()
- toolchange_boringhead_motorOFF()
- toolchange_goto_take_tool(selectedtool)
- toolchange_spindle_grabtool()
- if(toolchange_getspindlestatus()==2) then --ERROR within the tool attachment system, STOP
- mc.mcCntlSetLastError(inst, "Tool attached incorrectly, remove it manually")
- mc.mcToolSetCurrent(inst, selectedtool)
- mc.mcCntlSetLastError(inst, string.format("New tool %.0f", selectedtool))
- do return end
- end
- toolchange_goto_slide_out_tool()
- end
- end
- --The current tool is goes in the main spindle, put it back first
- if(currenttool<9) then
- --just in case
- toolchange_boringhead_up()
- toolchange_boringhead_allin()
- toolchange_spindle_spindleOFF()
- if(toolchange_getspindlestatus()==1) then
- toolchange_goto_remove_tool(currenttool)
- toolchange_spindle_releasetool()
- if(toolchange_getspindlestatus()>0) then
- mc.mcCntlSetLastError(inst, "Tool didn't release correctly")
- do return end
- end
- toolchange_zup()
- end
- if(toolchange_getspindlestatus()==2) then
- mc.mcCntlSetLastError(inst, "Tool attached incorrectly, remove it manually")
- mc.mcToolSetCurrent(inst, selectedtool)
- mc.mcCntlSetLastError(inst, string.format("New tool %.0f", selectedtool))
- do return end
- end
- if(selectedtool<9) then --The to-be-selected tool is goes in the main spindle
- toolchange_goto_take_tool(selectedtool)
- toolchange_spindle_grabtool()
- if(toolchange_getspindlestatus()==2) then --ERROR within the tool attachment system, STOP
- mc.mcCntlSetLastError(inst, "Tool attached incorrectly, remove it manually")
- mc.mcToolSetCurrent(inst, selectedtool)
- mc.mcCntlSetLastError(inst, string.format("New tool %.0f", selectedtool))
- do return end
- end
- toolchange_goto_slide_out_tool()
- elseif (selectedtool>8) then --The to-be-selected tool is in the boring head
- toolchange_gotosafe()
- --toolchange_boringhead_motorON()
- toolchange_boringhead_toolout(selectedtool)
- toolchange_boringhead_down()
- toolchange_setoffsets(selectedtool)
- end
- end
- --return the machine's state to the one it was in before, recorded at the start of this function
- --There is a bug that causes set #4xxx variables to be of size ten times smaller,
- --i.e 17 becomes 1.7.
- --In order to account for this, they have to be multiplied by 10
- mc.mcCntlSetPoundVar(inst, 2134, CurFeed)
- mc.mcCntlSetPoundVar(inst, 4001, CurFeedMode*10)
- mc.mcCntlSetPoundVar(inst, 4002, CurPlaneMode*10)
- mc.mcCntlSetPoundVar(inst, 4003, CurAbsMode*10)
- mc.mcCntlSetPoundVar(inst, 4005, CurSpeedMode*10)
- mc.mcCntlSetPoundVar(inst, 4006, CurUnit*10)
- mc.mcCntlSetPoundVar(inst, 4015, CurMotionMode*10)
- --set a new tool number, since the tool is now attached
- if toolchange_machine_enabled()==true then
- toolchange_setoffsets(selectedtool)
- mc.mcToolSetCurrent(inst, selectedtool)
- mc.mcCntlSetLastError(inst, string.format("New tool %.0f", selectedtool))
- end
- end
- function toolchange_boringhead_toolout(tool_n) --this function pushes a specific tool out from the boring head. Range tool n. 9-21 (total 13)
- local inst = mc.mcGetInstance()
- local hsig = nil
- if toolchange_machine_enabled()==true then
- if tool_n==9 then
- hsig = mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT6)
- elseif tool_n==10 then
- hsig = mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT5)
- elseif tool_n==11 then
- hsig = mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT16)
- elseif tool_n==12 then
- hsig = mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT15)
- elseif tool_n==13 then
- hsig = mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT14)
- elseif tool_n==14 then
- hsig = mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT13)
- elseif tool_n==15 then
- hsig = mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT12)
- elseif tool_n==16 then
- hsig = mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT11)
- elseif tool_n==17 then
- hsig = mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT10)
- elseif tool_n==18 then
- hsig = mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT9)
- elseif tool_n==19 then
- hsig = mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT8)
- elseif tool_n==20 then
- hsig = mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT7)
- elseif tool_n==21 then
- hsig = mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT17)
- end
- mc.mcSignalSetState(hsig, true)
- end
- end
- function toolchange_boringhead_toolin(tool_n) --this function pulls a specific tool in to the boring head. Range tool n. 9-21 (total 13)
- local inst = mc.mcGetInstance()
- local hsig = nil
- if toolchange_machine_enabled()==true then
- if tool_n==9 then
- hsig = mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT6)
- elseif tool_n==10 then
- hsig = mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT5)
- elseif tool_n==11 then
- hsig = mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT16)
- elseif tool_n==12 then
- hsig = mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT15)
- elseif tool_n==13 then
- hsig = mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT14)
- elseif tool_n==14 then
- hsig = mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT13)
- elseif tool_n==15 then
- hsig = mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT12)
- elseif tool_n==16 then
- hsig = mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT11)
- elseif tool_n==17 then
- hsig = mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT10)
- elseif tool_n==18 then
- hsig = mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT9)
- elseif tool_n==19 then
- hsig = mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT8)
- elseif tool_n==20 then
- hsig = mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT7)
- elseif tool_n==21 then
- hsig = mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT17)
- end
- mc.mcSignalSetState(hsig, false)
- end
- end
- function toolchange_boringhead_allin() --this function pulls all the tools in to the boring head. Range total 13
- local inst = mc.mcGetInstance()
- if toolchange_machine_enabled()==true then
- mc.mcSignalSetState(mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT5), false)
- mc.mcSignalSetState(mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT6), false)
- mc.mcSignalSetState(mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT7), false)
- mc.mcSignalSetState(mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT8), false)
- mc.mcSignalSetState(mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT9), false)
- mc.mcSignalSetState(mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT10), false)
- mc.mcSignalSetState(mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT11), false)
- mc.mcSignalSetState(mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT12), false)
- mc.mcSignalSetState(mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT13), false)
- mc.mcSignalSetState(mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT14), false)
- mc.mcSignalSetState(mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT15), false)
- mc.mcSignalSetState(mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT16), false)
- mc.mcSignalSetState(mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT17), false)
- end
- end
- function toolchange_boringhead_up() --this function operates the pneumatic cylinder, pulling the boring head complex up, checking (and waiting until) the success and DISABLING the machine if it fails.
- local inst = mc.mcGetInstance()
- if toolchange_machine_enabled()==true then
- mc.mcSignalSetState(mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT2), 0)
- counter=0
- while (mc.mcSignalGetState(mc.mcSignalGetHandle(inst, mc.ISIG_INPUT2))==0) and (counter<20) do
- counter=counter+1
- mc.mcCntlGcodeExecuteWait(inst, "G4 P0.1")
- end
- if (counter>=20) then
- mc.mcCntlEnable(inst, false)
- mc.mcCntlSetLastError(inst, "Unable to lift the boring head. Tool change will not start. Check air pressure.")
- end
- end
- end
- function toolchange_spindlecover_up() --this function operates the pneumatic cylinder, pulling the spindle cover up, checking (and waiting until) the success and DISABLING the machine if it fails.
- local inst = mc.mcGetInstance()
- if toolchange_machine_enabled()==true then
- mc.mcSignalSetState(mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT3), 0)
- counter=0
- while (mc.mcSignalGetState(mc.mcSignalGetHandle(inst, mc.ISIG_INPUT0))== 1) and (counter<20) do
- counter=counter+1
- mc.mcCntlGcodeExecuteWait(inst, "G4 P0.1")
- end
- if (counter>=20) then
- mc.mcCntlEnable(inst, false)
- mc.mcCntlSetLastError(inst, "Unable to lift the spindle cover. Tool change will not start. Check air pressure.")
- end
- end
- end
- function toolchange_boringhead_down() --this function operates the pneumatic cylinder, pulling the boring head complex up, checking (and waiting until) the success and DISABLING the machine if it fails.
- local inst = mc.mcGetInstance()
- if toolchange_machine_enabled()==true then
- mc.mcSignalSetState(mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT2), 1)
- counter=0
- while (mc.mcSignalGetState(mc.mcSignalGetHandle(inst, mc.ISIG_INPUT1))==0) and (counter<20) do
- counter=counter+1
- mc.mcCntlGcodeExecuteWait(inst, "G4 P0.1")
- end
- if (counter>=20) then
- mc.mcCntlEnable(inst, false)
- mc.mcCntlSetLastError(inst, "Unable to lower the boring head. Tool change will not start. Check air pressure.")
- end
- end
- end
- function toolchange_boringhead_motorON()
- if toolchange_machine_enabled()==true then
- local inst = mc.mcGetInstance()
- mc.mcCntlGcodeExecuteWait(inst, "M103")
- end
- end
- function toolchange_boringhead_motorOFF()
- if toolchange_machine_enabled()==true then
- local inst = mc.mcGetInstance()
- mc.mcCntlGcodeExecuteWait(inst, "M105")
- end
- end
- function toolchange_spindle_spindleOFF()
- if toolchange_machine_enabled()==true then
- local inst = mc.mcGetInstance()
- mc.mcCntlGcodeExecuteWait(inst, "M5")
- end
- end
- function toolchange_spindle_grabtool() --this function operates the main spindle's pneumatic tool attacher, grabbing a tool
- toolchange_checksensors_s2()
- local inst = mc.mcGetInstance()
- mc.mcCntlGcodeExecuteWait(inst, "G04 P1")
- if toolchange_machine_enabled()==true then
- mc.mcSignalSetState(mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT1), false)
- end
- mc.mcCntlGcodeExecuteWait(inst, "G04 P1")
- toolchange_checksensors_s2()
- end
- function toolchange_spindle_releasetool() --this function operates the main spindle's pneumatic tool attacher, releasing a tool
- toolchange_checksensors_s2()
- local inst = mc.mcGetInstance()
- mc.mcCntlGcodeExecuteWait(inst, "G04 P1")
- if toolchange_machine_enabled()==true then
- mc.mcSignalSetState(mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT1), true)
- end
- mc.mcCntlGcodeExecuteWait(inst, "G04 P1")
- toolchange_checksensors_s2()
- end
- function toolchange_gotosafe() --this function moves the X axis to the side of the machine, in order to avoid any crashes from pushing out a tool from the boring head
- if toolchange_machine_enabled()==true then
- local inst = mc.mcGetInstance()
- mc.mcCntlGcodeExecuteWait(inst, "G90 G21\n G01 G53 Z0 F3000\n G01 G53 X200 F3000")
- end
- end
- function toolchange_zup() --this function rises up the Z axis
- if toolchange_machine_enabled()==true then
- local inst = mc.mcGetInstance()
- mc.mcCntlGcodeExecuteWait(inst, "G90 G21\n G01 G53 Z0 F3000")
- end
- end
- function toolchange_goto_remove_tool(tool_n) --this function moves to a specific tool's XY location in front of the rack, for it to be slid in, and then slides it in. Range tool n. 1-8 (total 8)
- if toolchange_machine_enabled()==true then
- --setup\n Z up\n go in front of the holder in XY\n Z down \n Y slide in
- local inst = mc.mcGetInstance()
- if (tool_n==8) then
- mc.mcCntlGcodeExecuteWait(inst, "G90 G21\n G01 G53 Z0 F3000\n G01 G53 X328 Y-54 F3000\n G01 G53 Z-84.9 F1000\n G01 F500 G53 Y29")
- elseif (tool_n==7) then
- mc.mcCntlGcodeExecuteWait(inst, "G90 G21\n G01 G53 Z0 F3000\n G01 G53 X448 Y-54 F3000\n G01 G53 Z-84.7 F1000\n G01 F500 G53 Y32")
- elseif (tool_n==6) then
- mc.mcCntlGcodeExecuteWait(inst, "G90 G21\n G01 G53 Z0 F3000\n G01 G53 X568 Y-54 F3000\n G01 G53 Z-84.7 F1000\n G01 F500 G53 Y32")
- elseif (tool_n==5) then
- mc.mcCntlGcodeExecuteWait(inst, "G90 G21\n G01 G53 Z0 F3000\n G01 G53 X688 Y-54 F3000\n G01 G53 Z-84.5 F1000\n G01 F500 G53 Y32")
- elseif (tool_n==4) then
- mc.mcCntlGcodeExecuteWait(inst, "G90 G21\n G01 G53 Z0 F3000\n G01 G53 X807.6 Y-54 F3000\n G01 G53 Z-83.7 F1000\n G01 F500 G53 Y32")
- elseif (tool_n==3) then
- mc.mcCntlGcodeExecuteWait(inst, "G90 G21\n G01 G53 Z0 F3000\n G01 G53 X929 Y-54 F3000\n G01 G53 Z-84 F1000\n G01 F500 G53 Y32")
- elseif (tool_n==2) then
- mc.mcCntlGcodeExecuteWait(inst, "G90 G21\n G01 G53 Z0 F3000\n G01 G53 X1048 Y-54 F3000\n G01 G53 Z-82.3 F1000\n G01 F500 G53 Y32")
- elseif (tool_n==1) then
- mc.mcCntlGcodeExecuteWait(inst, "G90 G21\n G01 G53 Z0 F3000\n G01 G53 X1168 Y-54 F3000\n G01 G53 Z-82.3 F1000\n G01 F500 G53 Y32")
- end
- end
- end
- function toolchange_goto_take_tool(tool_n) --this function moves to a specific tool's XY location on top of the rack for it to be grabbed, and the moves exactly on the position where the tool can be properly attached. IT DOES NOT SLIDE IT OUT. Range tool n. 1-8 (total 8)
- if toolchange_machine_enabled()==true then
- --setup\n Z up\n go on top of the holder XY\n Z down
- local inst = mc.mcGetInstance()
- if (tool_n==8) then
- mc.mcCntlGcodeExecuteWait(inst, "G90 G21\n G01 G53 Z0 F3000\n G01 G53 X328 Y29 F3000\n G01 G53 Z-84.9 F500")
- elseif (tool_n==7) then
- mc.mcCntlGcodeExecuteWait(inst, "G90 G21\n G01 G53 Z0 F3000\n G01 G53 X448 Y32 F3000\n G01 G53 Z-84.7 F500")
- elseif (tool_n==6) then
- mc.mcCntlGcodeExecuteWait(inst, "G90 G21\n G01 G53 Z0 F3000\n G01 G53 X568 Y32 F3000\n G01 G53 Z-84.7 F500")
- elseif (tool_n==5) then
- mc.mcCntlGcodeExecuteWait(inst, "G90 G21\n G01 G53 Z0 F3000\n G01 G53 X688 Y32 F3000\n G01 G53 Z-84.5 F500")
- elseif (tool_n==4) then
- mc.mcCntlGcodeExecuteWait(inst, "G90 G21\n G01 G53 Z0 F3000\n G01 G53 X807.6 Y32 F3000\n G01 G53 Z-83.7 F500")
- elseif (tool_n==3) then
- mc.mcCntlGcodeExecuteWait(inst, "G90 G21\n G01 G53 Z0 F3000\n G01 G53 X929 Y32 F3000\n G01 G53 Z-84 F500")
- elseif (tool_n==2) then
- mc.mcCntlGcodeExecuteWait(inst, "G90 G21\n G01 G53 Z0 F3000\n G01 G53 X1048 Y32 F3000\n G01 G53 Z-82.3 F500")
- elseif (tool_n==1) then
- mc.mcCntlGcodeExecuteWait(inst, "G90 G21\n G01 G53 Z0 F3000\n G01 G53 X1168 Y32 F3000\n G01 G53 Z-82.3 F500")
- end
- end
- end
- function toolchange_goto_slide_out_tool() --this function slides out a tool from the tool rack, only moving the Y axis. Then it rises the Z-axis up, only moving the Z axis.
- if toolchange_machine_enabled()==true then
- --slide out Y\n Z up
- local inst = mc.mcGetInstance()
- mc.mcCntlGcodeExecuteWait(inst, "G90 G21\n G01 G53 Y-54 F1000\n G01 G53 Z0 F3000")
- end
- end
- function toolchange_setoffsets(tool_n) --this function sets a specific tool's offset value on the boring head. Range tool n. 9-21 (total 13)
- local inst = mc.mcGetInstance()
- if (tool_n<9) then
- mc.mcCntlGcodeExecuteWait(inst, "G90 G10 L20 P0 X0 Y0")
- elseif (tool_n==21) then
- mc.mcCntlGcodeExecuteWait(inst, "G90 G10 L20 P0 X180.3 Y62.6")
- elseif (tool_n==20) then
- mc.mcCntlGcodeExecuteWait(inst, "G90 G10 L20 P0 X267.3 Y62.6")
- elseif (tool_n==19) then
- mc.mcCntlGcodeExecuteWait(inst, "G90 G10 L20 P0 X299.3 Y62.6")
- elseif (tool_n==18) then
- mc.mcCntlGcodeExecuteWait(inst, "G90 G10 L20 P0 X331.3 Y62.6")
- elseif (tool_n==17) then
- mc.mcCntlGcodeExecuteWait(inst, "G90 G10 L20 P0 X363.3 Y62.6")
- elseif (tool_n==16) then
- mc.mcCntlGcodeExecuteWait(inst, "G90 G10 L20 P0 X395.3 Y62.6")
- elseif (tool_n==15) then
- mc.mcCntlGcodeExecuteWait(inst, "G90 G10 L20 P0 X427.3 Y62.6")
- elseif (tool_n==14) then
- mc.mcCntlGcodeExecuteWait(inst, "G90 G10 L20 P0 X427.3 Y94.6")
- elseif (tool_n==13) then
- mc.mcCntlGcodeExecuteWait(inst, "G90 G10 L20 P0 X427.3 Y126.6")
- elseif (tool_n==12) then
- mc.mcCntlGcodeExecuteWait(inst, "G90 G10 L20 P0 X427.3 Y158.6")
- elseif (tool_n==11) then
- mc.mcCntlGcodeExecuteWait(inst, "G90 G10 L20 P0 X427.3 Y190.6")
- elseif (tool_n==10) then
- mc.mcCntlGcodeExecuteWait(inst, "G90 G10 L20 P0 X427.3 Y222.6")
- elseif (tool_n==9) then
- mc.mcCntlGcodeExecuteWait(inst, "G90 G10 L20 P0 X427.3 Y309.6")
- end
- end
- function toolchange_checksensors_s1s4() --this function checks the main spindle's S1S4 sensor values and returns a state
- local inst = mc.mcGetInstance()
- local hsig=mc.mcSignalGetHandle(inst, mc.ISIG_INPUT5)
- local val=mc.mcSignalGetState(hsig)
- return val
- end
- function toolchange_checksensors_s2() --this function checks the main spindle's S2 sensor values and returns a state
- local inst = mc.mcGetInstance()
- local hsig=mc.mcSignalGetHandle(inst, mc.ISIG_INPUT4)
- local val=mc.mcSignalGetState(hsig)
- --0: tool holde blocked (maybe there's a tool attached to it)
- --1: tool holde open (there's no tool attached to it)
- return val
- end
- function toolchange_getspindlestatus() --this function compiles the main spindle's sensor values and returns a state of the tool.
- local inst = mc.mcGetInstance()
- if (toolchange_checksensors_s2()==1) then
- return 0
- elseif (toolchange_checksensors_s2()==0) then
- local s1s4=toolchange_checksensors_s1s4()
- if(s1s4==1) then
- return 1 --Tool OK
- else
- return 2 --Tool NOT OK
- end
- end
- end
- function toolchange_machine_enabled()
- local inst = mc.mcGetInstance()
- local hsig=mc.mcSignalGetHandle(inst, mc.OSIG_MACHINE_ENABLED)
- local isRunning=mc.mcCntlIsInCycle(inst)
- local val=mc.mcSignalGetState(hsig)
- if val==1 then
- --if isRunning==true then
- return true
- --else
- -- return false
- --end
- else
- return false
- end
- end
- function toolchange_machine_homed()
- local inst = mc.mcGetInstance()
- if (mc.mcAxisIsHomed(inst, 0)==1 and mc.mcAxisIsHomed(inst, 1)==1 and mc.mcAxisIsHomed(inst, 2)==1) then
- return true
- else
- return false
- end
- end
- function toolchange_machine_coords_allowed() --this function checks if the current Y axis location value is accepted, in order to avoid a Z rise in the tool's location holder, or any other crashes
- --Get the Y axis coords
- local inst = mc.mcGetInstance()
- local loc_Y=0
- loc_Y= mc.mcAxisGetMachinePos(inst, 1)
- --Compare them to unallowed values
- if (loc_Y>-50) then
- --Y not allowed, and so return that the coords are not allowed (false)
- return false
- elseif (loc_Y<-50) then
- --Y is allowed
- return true
- else
- --error, (no further motion by caller allowed). It is up to the caller to stop, however.
- return false
- end
- end
- if (mc.mcInEditor() == 1) then --debugging
- m6()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement