I am building a machine that consists of a fixed gantry with a head that moves in the X direction. The material underneath needs to be moved forward in one direction (and can only go one direction) manually. The goal is to have Mach3 print one line on the material when the material moves forward and stops at a location that will be picked up by a microswitch connected to one of the inputs.
Actually the Microswitch triggers ever mm of movement and the forward movement is quite slow so I dont really see the need to add an encoder to this.
I have altered the Post to output an M code and pass a P variable to Mach3 with the distance required to move. For instance the first movement would be a say 2mm giving Mach3 2 clicks on the input, at that stage it should print one line.
G0 X0 M666 P2
G1 Z1 F600
G1 X20 F1800
G0 Z0
G0 M666 P4
G1 Z1 F600
G1 X0 F1800
G0 Z0
Would tell the gantry to Start at X0 wait for the microswitch to click 2 times then Print one line 20mm long
Wait for 2 more clicks (making essentially a 4 mm movement from 0) then print the next line from 20 to 0 in the X
My Macro consists of this, however as I am testing this on a machine that has a powered Y i have added some code to allow for this however at present the thing is triggering on every click rather than waiting for the stipulated clicks.
Any assistance or suggestions would be greatly appreciated.
Code:
TvlDistance = 0
'Location to do the next line passed by the P
FwdDistance = roun(Param1())
'The current position of the Y axis
CurrentYPos = roun(GetParam("YMachine"))
'How many Clicks from input required per mm of travel
Steps = 1
'If the current position is 0 or a negative number as will be the
'case on the first and secont pass do not work out the distance to move.
If (FwdDistance-CurrentYPos) <= 0 Then
ToMove = FwdDistance
Else
ToMove = FwdDistance-CurrentYPos
End If
'Do not wait for input while the file is loading
If IsLoading() Then
'File is loading so dont do anything
Else
'File has loaded now we can start work
'Message "spool:" & ToMove & " mm " & "From:" & CurrentYPos
1:
'when the machine is moving wait for it to stop
While IsMoving()
sleep(100)
Wend
'wait until there is input
While Not isActive(INPUT2)
Message "Move Material:" & ToMove & "mm"
activateSignal(ENABLE1)
sleep 50
Wend
If TvlDistance < ToMove Then
'wait for the next click
TvlDistance = TvlDistance + Steps
GoTo 1
End If
'Test Code for CNC with Stepper on Y
'If TvlDistance = ToMove Then
Message "Moving to Position for X pass:" & FwdDistance
'y is in position (test code only for powered cnc)
Code "G1 Y" & FwdDistance
sleep 100
'End If
deactivateSignal(ENABLE1)
End If