Programming CNC machines in Haskell
|
|
|
|||||||||||||||||||||||||||||||||
|
Recent advances in Computerized Numeric
Control (CNC) have allowed the manufacturing of products with high quality
standards. Since CNC programs consist of a series of assembler-like instructions,
several high-level languages, such as AutoLISP,
have been proposed in order to raise the programming abstraction level. Unfortunately,
the lack of formality in these languages prevents the verification of
programs. In this work, we propose the use of Haskell in CNC programming. Haskell
is a modern pure functional language permitting formal verification and
presenting advanced features such as lazy evaluation, higher order, etc. These
features will allow us to cope with infinite data structures, to apply heuristics
to CNC programs in order to optimize them, etc. |
|
|||||||||||||||||||||||||||||||||
|
|
|
|||||||||||||||||||||||||||||||||
|
US Air Force commissioned MIT to develop the first "numerically controlled" machine in 1949. It was demonstrated in 1952. Motivation: To manufacture complex curved geometries in 2D or 3D was extremely expensive by mechanical means (which usually would require complex jigs to control the cutter motions). Most modern machine tool companies manufacture only NC or CNC machine tools. The dominant advantages of NC machines are: - Easier to program; easy storage of existing programs;
System M3X-3S 3-Axis Control and Machine Having the computer control the machine is accomplished by a program that is written using NC code. A CNC program is a series of instructions written in sentence-like format. These statements are executed in sequential order, step by step. A special series of CNC words are used to communicate what the machine is intended to do. CNC words begin with letter addresses (like F for feedrate, S for spindle speed, and X, Y and Z for axis motion). When placed together in a logical method, a group of CNC words make up a command that resemble a sentence. For any given CNC machine type, there will only be about 40-50 words used on a regular basis. |
|
|||||||||||||||||||||||||||||||||
|
|
|
|||||||||||||||||||||||||||||||||
|
The International Organization for Standardization proposes the ISO 6983 which contains the G-codes for CNC programming. It s pecifies requirements and gives recommendations for the data format for control systems used in the numerical control of machines. Improves the co-ordination of system design in order to minimize the variety of program manuscripts required. Is not intended for use in flame cutting machines and drafting machines used specifically and exclusively in the shipuilding industry.
More information about
G-codes and the standard ISO6983 can be found in:
|
|
|||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||
We propose to cope with CNC programming using the pure functional language Haskell. Haskell provides many advantadges over existing tools:
Small example of a program using Haskell: CNC program using G-codes A program which perform two holes on the positions (10,10) and (15,15): N0010 (two-hole drilling) data CNCprogram = Header Body Some Haskell functions from the Haskell-CNC library used to implement CNC programs -- creates a [Block] containing the CNC instructions for-- making n holes in a straight line nHolesLine :: Int -> Int -> Int -> Int -> Int -> [Block] where line = createLine x y incX incY nLine = finiteLine n line -- creates an infinite list of absolute coordinates createLine x y incX incY = (x,y) : createLine (x + incX) (y + incY) incX incY --takes an list and returns a sublist containing the first n elements finiteLine :: Int -> [a] -> [a] finiteLine _ [] = [] finiteLine n (x:xs) = x : finiteLine (n-1) xs -- takes a XY coordinate and return a block containing -- all instructions needeed to make a hole at such position makeHole :: (Int,Int) -> [Block] makeHole (x,y) = where -- and print them through the output console printBlocks :: Int -> [Block] -> IO () do printBlock numBlock x printBlocks (numBlock+10) xs -- takes a number and a block and block and prints it printBlock :: Int -> Block -> IO () blockToStr :: Block -> String blockToStr (BComment c) = "("++c++")" blockToStr (Code []) = "" blockToStr (Code (x:xs)) = (instrToStr x) ++ " " ++ (blockToStr (Code xs)) instrToStr (X n) = "X"++(show n) instrToStr (Y n) = "Y"++(show n) CNC program written in Haskell equivalent to the previous written in G-codes A program which perform two holes on the positions (10,10) and (15,15):main = printBlocks 10 (nHolesLine 2 10 10 5 5) |
|||||||||||||||||||||||||||||||||||
|
Implementation |
|
|||||||||||||||||||||||||||||||||
|
Here you can download some files with the current implementation of our Haskell library for CNC programming. Our library currently contains:
Cutting path plane for a CNC machine
|
|