summaryrefslogtreecommitdiff
path: root/trunk/users/metalab/python/imperial_gcode.py
blob: 11d5f7dc3bec3ce47a610364b247742c8a78a412 (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
65
66
67
68
69
70
#!/usr/bin/env python

frequencies = [
  196.00, #G2   0
  207.65, #G#2   1
  220.00, #A2    2
  233.08, #Bb2   3
  246.94, #B2    4
  261.63, #C3    5
  277.18, #C#3   6
  293.66, #D3    7
  311.13, #D#3   8
  329.63, #E3    9
  349.23, #F3    10
  369.99, #F#3   11
  392.00, #G3    12
  415.30, #G#3   13
  440.00, #A3    14
  466.16, #Bb3   15
  493.88, #B3    16
  523.25, #C4    17
  554.37, #C#4   18
  587.33, #D4    19
  622.25, #D#4   20
  659.26, #E4    21
  698.46, #F4    22
  739.99, #F#4   23
  783.99, #G4    24
  830.61, #G#4   25
  880.00  #A4    26
]


notes = [
  12,12,12, 8,15,12, 8,15,12,   # 9
  19,19,19,20,15,12, 8,15,12,   # 9
  24,12,12,24,23,22,21,20,21,   # 9
  13,18,17,16,15,14,15,         # 7
   8,11, 8,11,15,12,15,19,      # 8
  24,12,12,24,23,22,21,20,21,   # 9
  13,18,17,16,15,14,15,         # 7
   8,11, 8,15,12, 8,15,12       # 8
]

lengths = [
    4, 4, 4, 3, 1, 4, 3, 1, 8,
    4, 4, 4, 3, 1, 4, 3, 1, 8,
    4, 3, 1, 4, 3, 1, 1, 1, 4,
    2, 4, 3, 1, 1, 1, 4,
    2, 4, 3, 1, 4, 3, 1, 8,
    4, 3, 1, 4, 3, 1, 1, 1, 4,
    2, 4, 3, 1, 1, 1, 4,
    2, 4, 3, 1, 4, 3, 1, 8
]

assert(len(lengths) == len(notes))

feedrates = [60.0*f/320 for f in frequencies]

print "G21"
print "G90"
print "G92 X0 Y0 Z0"
print "G28"

print "(<layer> 0 )"
z = 0;
for (note,length) in zip(notes, lengths):
    z += 0.15 * length * feedrates[note] / 60
    print "G1 Z%(Z).2f F%(F).2f" % {'Z':z, 'F':feedrates[note]}
print "(</layer>)"