summaryrefslogtreecommitdiff
path: root/nc_files/ngcgui_lib/gosper.ngc
blob: d9be7433b2458b670047c55cba729794ea35cb87 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
(Adapted from Program to mill a flowsnake.ngc by K. Lerman)
(info: gosper -- recursion demo -- line is x1,y1 to x2,y2)
o<gosper> sub

#<rpm>      =  #1 (=2000)
#<zcut>     =  #2 (=.010 depth of cut)
#<feedrate> =  #3 (=10)
#<zsafe>    =  #4 (=0.5  safety height)
#<x1>       =  #5 (=-0.866 line x1)
#<y1>       =  #6 (=-0.5   line y1)
#<x2>       =  #7 (= 0.866 line x2)
#<y2>       =  #8 (=-0.5   line y2)
#<level>    =  #9 (=3 recursion lvl)
#<scale>    = #10 (=1)
#<rotate>   = #11 (=0)
#<xoff>     = #12 (=-3)
#<yoff>     = #13 (=-3)

o<i0> if [#<scale> EQ 0]
        #<scale> = 1.0
        (debug, scale was 0, setting #<scale>)
o<i0> endif

o<t1>   if [#<level> LT 0]
           #<level> = 0
           (debug, level set to #<level>)
o<t1>   endif
o<t2>   if [#<level> GT 4]
           #<level> = 4
           (debug, level reduced to #<level>)
o<t2>   endif

o<move> call [#<x1>][#<y1>][#<rotate>][#<scale>][#<xoff>][#<yoff>]
#<x1>      = #<_move:x>
#<y1>      = #<_move:y>
#<len1>    = #<_move:len>
#<phi1>    = #<_move:phi>
o<move> call [#<x2>][#<y2>][#<rotate>][#<scale>][#<xoff>][#<yoff>]
#<x2>      = #<_move:x>
#<y2>      = #<_move:y>
#<len2>    = #<_move:len>
#<phi2>    = #<_move:phi>
#<fr> = #<feedrate>

        s#<rpm> M3 (spindle on)
o<spin> call [#<rpm>]

        g0 z #<zsafe>
        g0 x #<x1>  y  #<y1>
        f #<feedrate>
        g1 z [0 - #<zcut>]
        #<dely>  = [#<y2> - #<y1>]
        #<delx>  = [#<x2> - #<x1>]
        #<len>   = [SQRT[#<delx>*#<delx> + #<dely>*#<dely>]]
        #<theta> = ATAN [#<dely>]/[#<delx>]  (degrees)
        (compute p3 for equilateral triangle)
        #<p3x>   = [#<x1> + #<len> * COS[#<theta> + 60]]
        #<p3y>   = [#<y1> + #<len> * SIN[#<theta> + 60]]
        (threee sides of equilateral triangle)
        o<gosper_sub> call [#<level>][#<x1>] [#<y1>] [#<x2>] [#<y2>] [#<fr>]
        o<gosper_sub> call [#<level>][#<x2>] [#<y2>] [#<p3x>][#<p3y>][#<fr>]
        o<gosper_sub> call [#<level>][#<p3x>][#<p3y>][#<x1>] [#<y1>] [#<fr>]
        g0 z #<zsafe>
o<gosper> endsub