-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcalibration.py
executable file
·63 lines (51 loc) · 2.45 KB
/
calibration.py
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
#!/usr/bin/env python
import sys
import argparse
from decimal import Decimal
def formatFloat(precision, f):
d = (Decimal(f) / Decimal(precision)).quantize(1) * Decimal(precision)
return d.quantize(Decimal(1)) if d == d.to_integral() else d.normalize()
def main():
parser = argparse.ArgumentParser(description="""
Creates G-code to help in calibrating effective tool width.
""")
required = parser.add_argument_group('required arguments')
required.add_argument('--max', dest='max', required=True, type=float,
help='Maximum estimated tool width, in mm')
required.add_argument('--min', dest='min', required=True, type=float,
help='Minimum estimated tool width, in mm')
required.add_argument('--step', required=True, type=float,
help='Step size to probe tool width in, in mm')
required.add_argument('--output', required=True, dest='output', type=str, help="""
Output file name.
""")
parser.add_argument('--cutdepth', dest='cutdepth', default='2', type=float, help="""
Depth to cut, in mm.
""")
parser.add_argument('--zspace', dest='zspace', default='10', type=float, help="""
Z distance to hover above origin when moving to disconnected region, in mm
""")
args = parser.parse_args()
precision = Decimal(1)
while precision > args.min / 20:
precision = precision / Decimal(10)
width = args.max
x = 0
with open(args.output, "w") as out:
print("G90", file=out)
while width > args.min - 1e-6:
print("G0 Z%s" % formatFloat(precision, args.zspace), file=out)
print("G0 X%s Y0" % formatFloat(precision, x), file=out)
print("G1 Z%s" % formatFloat(precision, -args.cutdepth), file=out)
print("G0 Z%s" % formatFloat(precision, args.zspace), file=out)
print("G0 Y%s" % formatFloat(precision, width), file=out)
print("G1 Z%s" % formatFloat(precision, -args.cutdepth), file=out)
print("G0 Z%s" % formatFloat(precision, args.zspace), file=out)
print("G0 Y%s" % formatFloat(precision, -2 * width), file=out)
print("G1 Z%s" % formatFloat(precision, -args.cutdepth), file=out)
print("G1 Y%s" % formatFloat(precision, -width), file=out)
x += width * 3
width -= args.step
print("G0 Z%s" % formatFloat(precision, args.zspace), file=out)
if __name__ == '__main__':
main()