Рет қаралды 1,288
video chia sẻ ngắn mong giúp được các bạn
code Macro
'Macro M7781
'Find the center of circle
'Mach3 OEMDRO x=800; y=801
x0= GetOEMDRO(800)
y0= GetOEMDRO(801)
move_back=2
SLOW_FEED="F25"
MAX_RADIUS=100
'move along X axis to positive direction
x=x0
Code "G31 X" & (x+MAX_RADIUS) & " F400" 'do nhanh
While IsMoving() 'wait while it happens
Wend
'get touch position
x= GetOEMDRO(800)
'slow moving
Code "G01 X" & (x-move_back) &"F100"
While IsMoving() 'wait while it happens
Wend
Code "G31 X" & (x+move_back) & SLOW_FEED 'do cham
While IsMoving()
Wend
x2= GetOEMDRO(800) 'get x2
'ans= MachMsg("x2=" & x2,"M7781", 0)
Code "G4 P1"
x= x0
'move along X axis to negative direction
Code "G00 X" & (x) 'quay ve vi tri
While IsMoving() '
Wend
Code "G31 X" & (x-MAX_RADIUS) & " F400" 'do nhanh
While IsMoving() '
Wend
'di toi vi tri cham
x= GetOEMDRO(800)
'do cham
Code "G01 X" & (x+move_back) &"F100"
While IsMoving() '
Wend
Code "G31 X" & (x-move_back) & SLOW_FEED 'do cham
While IsMoving() '
Wend
x1= GetOEMDRO(800) 'get x1
Code "G4 P1"
'move to x center
x = (x2+x1)/2.0
Code "G00 X" & x
While IsMoving() '
Wend
'set x zero
'SetOEMDRO(800, 0)
'****************
'tim tren truc Y
y=y0
Code "G31 Y" & (y+MAX_RADIUS) & " F400" 'do nhanh
While IsMoving() '
Wend
'get touch position
y= GetOEMDRO(801)
'slow moving
Code "G01 Y" & (y-move_back) &"F100"
While IsMoving() '
Wend
Code "G31 Y" & (y+move_back) & SLOW_FEED 'do chma
While IsMoving() '
Wend
y2= GetOEMDRO(801) 'set y2
Code "G4 P1"
y= y0
'di chuyen Y chieu nguoc
Code "G00 Y" & (y) 'back to initial pos
While IsMoving() '
Wend
Code "G31 Y" & (y-MAX_RADIUS) & " F400" 'do nhanh
While IsMoving() '
Wend
'get touch position
y= GetOEMDRO(801)
'slow moving
Code "G01 Y" & (y+move_back) &"F100"
While IsMoving() '
Wend
Code "G31 Y" & (y-move_back) & SLOW_FEED 'do cham
While IsMoving() '
Wend
y1= GetOEMDRO(801) 'set y1
Code "G4 P1"
'move to y center
y = (y2+y1)/2.0
Code "G00 Y" & y
While IsMoving() '
Wend
'set y zero
'SetOEMDRO(801, 0)
ans = MachMsg("Co thay doi toa do XY?", "Tam cung tron", 4) 'yesno
If (ans = 6) Then 'co
x = (x2+x1)/2.0
Code "G00 X" & x
While IsMoving() '
Wend
'set x zero
SetOEMDRO(800, 0)
y = (y2+y1)/2.0
Code "G00 Y" & y
While IsMoving() '
Wend
'set y zero
SetOEMDRO(801, 0)
End If
'End Sub