Jump to content
Sign in to follow this  
blahblahblah5038

script for CNC code for CNC mill

Recommended Posts

I have a wood project at school, which as part of my design needs to be cut on a cnc mill. Beacuse of the thickness required by the design, I glued several pieces of wood together, but needed to take material off the top. The pieces were too short for the planer, so I decide to head to the mill early and cut down the pieces on the mill. The mill software is a pain in the butt, so no one can reall figure out how to get it to consistantly work. I was told by the teacher to manualy write the code. Yeah right! Instead, I wrote a script to write the several hundred boring lines of code for me. Please excuse the messiness of my work, I had not origonally intended to post this on the forum.

;Created by Blahblahblah5038 
;for the purpose of generating CNC code to control a CNC Router and Face a Block

#include <math.au3>
;before using this program on the CNC Mill I need to zero the x and y to be approxametly the left front(nearest side to the oporator) corner of the work piece
;as well as the z exactly to the bottom of the piece.
;This portion asks questions pertinent to the program
$startthickness = InputBox("Machining", "What is the current thickness of the material?") ;starting thickness of the work piece, does not need to be exact, but it is better to overestimate
$endthickness = InputBox("Machining", "What is the final thickness of the material?");if you zero the machine correctly, this will be exact
$buffer = InputBox("Machining", "How many inches would you like as a buffer");increases cutting area, don't need accuracy in the X and Y directions
$length = InputBox("Machining", "What is the piece's length (Y)?") + $buffer ;however your machine measures Y
$width = InputBox("Machining", "What is the piece's Width (X)?") + $buffer ;however your machine measures X
$passno = InputBox("Machining", "How many passes other than the Last should the drill make?") ;number of rough cut passes
$intCount = 0;counters
$intCount2 = 0
$N = 4 ;keep track of line number, in case the computer doesn't do it for you, our equipment doesn't
$bitDia = InputBox("Machining", "What is the Bit's Diameter?") 
$intLR = Int(($length/ (2 * $bitDia))) ;number of passes left to right per height
$A = - ($startthickness + .5) ; a distance from the work piece
$increment = ($startthickness - $endthickness - .01) / $passno ;how quickly the bit approaches the work piece, .01 is left for finish cut
$Z = $startthickness - $increment ;distance in Z from bottom
Run("notepad.exe") ;cnc code will be sent here
WinWaitActive("Untitled - Notepad")
Send("{Enter}");N = line number, G9=absolute coordinates, G0=rapid movement, XYZ are directional
Send("N1G9G0X0YZ" & $A & "{ENTER}") ;move bit away from piece
Send("N2M3"); M3 = turn on mill 
Send("{ENTER}")
Send("N3G1Z" & $startthickness & "F4" & "{ENTER}") ;move to start thickness as provided by user
if _MathCheckDiv ($intLR, 2) then $intLR = $intLR+1  
For $intCount = 1 To $passno   ;makes rough cuts
    Send("N" & $N & "G0X0Y0Z" & $startthickness & "{Enter}")
    $N = $N + 1
    Send("N" & $N & ";Rough cut " & $intCount & "{ENTER}")
    $N = $N + 1
    Send("N" & $N & "G1Z" & $Z & "{Enter}")
    $N = $N + 1
    For $intCount2 = 1 To $intLR + 5 step 2
    $X =$bitDia * $intCount2
        $X2 = $bitDia * ($intCount2 +1)
    Send("N" & $N & "X" & $X & "{Enter}")
    $N = ($N + 1)
    Send("N" & $N & "Y" & $width & "{Enter}")
    $N = ($N + 1)
    Send("N" & $N & "X" & $X2 & "{Enter}")
    $N = ($N + 1)
    Send("N" & $N & "Y0" & "{Enter}")
    $N = ($N + 1)
    Next
    $Z = $Z - $increment
Next
;makes final cut
Send("N" & $N & ";Final Cut" & "{ENTER}")
$N = $N + 1
$FinalLR = $intLR * 2
Send("N" & $N & "G0X0Y0Z" & $startthickness & "{Enter}")
$N = $N + 1
Send("N" & $N & "G1Z" & $endthickness & "{Enter}")
$N = $N + 1
if _MathCheckDiv ($FinalLR, 2) then $FinalLR = $FinalLR+1
For $intCount2 = 1 To $FinalLR + 5 step 2
    $X = .5 * $bitDia * $intCount2
        $X2 = .5 * $bitDia * ($intCount2 +1)
    Send("N" & $N & "X" & $X & "{Enter}")
    $N = ($N + 1)
    Send("N" & $N & "Y" & $width & "{Enter}")
    $N = ($N + 1)
    Send("N" & $N & "X" & $X2 & "{Enter}")
    $N = ($N + 1)
    Send("N" & $N & "Y0" & "{Enter}")
    $N = ($N + 1)
Next
;return to origional position
Send("N" & $N & "G0Z" & $startthickness & "{Enter}")
$N = $N + 1
;M2 ends program
Send("N" & $N & "M2")

Noteworthy works:Fast Pixel SearchSigned: WG

Share this post


Link to post
Share on other sites

Cool idea, too bad you can't write a GUI that connects directly to the mill.

Nice job though


[center]AutoIT + Finger Print Reader/Scanner = COOL STUFF -> Check Out Topic![/center][center][font=Arial Black]Check out ConsultingJoe.com[/font][/center][center]My Scripts~~~~~~~~~~~~~~Web Protocol Managing - Simple WiFi Scanner - AutoTunes - Remote PC Control V2 - Audio SpectrascopePie Chart UDF - At&t's TTS - Custom Progress Bar - Windows Media Player Embed[/center]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...