Generating CNC code from a domain specific language


 

 


Abstract

 

 

 

Computerized Numeric Control (CNC) is an industrial language for the manufacturing of products. CNC programs are series of code that consist of assembler-like instructions, consequently they are low-level programs that require specialized developers in order to gain productivity in programs writing. In this work we introduce a domain specific language for the generation of CNC programs. The DSL itself has been developed in Curry, a declarative multi-paradigm functional-logic language. Our DSL includes a set of functions that encapsulate CNC instructions raising the abstraction level, and therefore, improving productivity. It is designed in such a way that non expert users can write CNC programs. We show how the use of a DSL allows us to perform the requirements capture and to reduce the gap between the requirements and the prototype. Finally, from our domain specific language we generate real CNC code in order to produce real world applications.

 

 


A
CNC programming example

 

 

We consider a simple CNC milling machine which can move the turret chuck in the X, Y and Z axes. The machine also handles absolute and incremental positioning of the turret chuck..

 

EMCO
VMC-200

EMCO
VMC-200

A CNC program for cutting a circular arc from (1,1) to (3,3) with center in (2,2) is as follows:

More information about G-codes and the standard ISO6983 can be found in:

 

 


A DSL for CNC programming embedded in Curry

 

 

We have developed the following DSL function programmed in Curry:

An example of a Circular canned:

Circular canned

DSL function

DrawCylinder (i, j, k, Height, Radius, dx)

Curry program for the DSL function

--------------------------------------------------------------------------------
------------- CAJEADO CIRCULAR ----------------------------------------
--------------------------------------------------------------------------------

{--
La siguiente es una funcion auxiliar para hacer cortes circulares de
forma iterativa
--}

FAUX_DrawCylinder :: (Float, Float, Float, Float, Float, Float, Float) -> IO()
FAUX_DrawCylinder (Endx, i, j, k, Radius, dx, Control) = do Draw

where
Draw = if (Control <= Radius)
then do writefile([Spin("CCW"), X Endx, I i, J j, K k, F 120.0])
writefile([G "01", X (Endx+.dx), F 120.0])
FAUX_DrawCylinder(Endx+.dx, i, j, k, Radius, dx, Control+.dx)
else done

{-- La siguiente funcion es propiamente el cajeado circular --}

DrawCylinder :: (Float, Float, Float, Float, Float, Float) -> IO()
DrawCylinder (i, j, k, Height, Radius, dx) = do InitPOS
Perforate
Draw
Restore
where
InitPOS = writefile(GotoXYZ(i, j, k))
Perforate = do writefile(DrawZ(Height+.k, 40.0))
writefile([G "01", X (i+.dx), F 120.0])
Draw = FAUX_DrawCylinder (i+.dx, i, j, k, Radius, dx, dx)
Restore = writefile(GotoXYZ(i, j, k))

 

example figure

 

 

 

 

Implementation

 

 

Here you can download the complete DSL Curry library:


 _________________Curry Library_________________

DSL for CNC programming library Implementation

Haskell Library