-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpre_probe_cylinder.py
107 lines (90 loc) · 3.68 KB
/
pre_probe_cylinder.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#!/usr/bin/env python
import sys
import os
import math
import rotary_axis_cam
# Script assumes:
# 1) The center of the cylinder is along the Y=0, Z=0 axis
# 2) X = 0 is the start of the cylinder
script_inputs_file = './pre_probe_cylinder.inputs'
pre_probe_inputs = {
'outer_diameter' : None,
'num_x_points' : None,
'num_a_points' : None,
'start_x' : None,
'end_x' : None,
'safe_clearance': 0.1,
'min_probe_depth': -0.1,
'probe_feedrate': 1.0,
'output_file': None,
}
if os.path.isfile(script_inputs_file):
print('Input file exists, loading inputs file\n')
exec(open(script_inputs_file).read())
else:
# Write inputs file
try:
outputfile = open(script_inputs_file, 'w')
except IOError:
print('Cannot open', script_inputs_file, '\nExiting!')
print('Writing input values to:', script_inputs_file)
outputfile.write('pre_probe_inputs = {\n')
rotary_axis_cam.write_dict(outputfile, pre_probe_inputs)
outputfile.close()
print('Update pre_probe_cylinder.inputs and re-run')
sys.exit()
print('Creating pre-probe G-code file')
total_points = pre_probe_inputs['num_a_points']*pre_probe_inputs['num_x_points']
outer_radius = pre_probe_inputs['outer_diameter']/2.0
safe_z_height = outer_radius + pre_probe_inputs['safe_clearance']
probe_min_z = outer_radius + pre_probe_inputs['min_probe_depth']
if pre_probe_inputs['num_x_points'] < 1:
print('\nInvalid number of X points\nExiting!')
sys.exit(1)
if pre_probe_inputs['num_x_points'] == 1:
delta_x = 0
else:
delta_x = (pre_probe_inputs['end_x'] - pre_probe_inputs['start_x'])/(pre_probe_inputs['num_x_points']-1)
delta_a = 360.0/pre_probe_inputs['num_a_points']
print('Number of X Points: {:3d}'.format(pre_probe_inputs['num_x_points']))
print('Number of A Points: {:3d}'.format(pre_probe_inputs['num_a_points']))
print('Total Number of Points {:3d}'.format(total_points))
# Open Output File
if pre_probe_inputs['output_file'] is None:
# Autocreate filename
output_filename = 'pre_probe_'
output_filename += str(pre_probe_inputs['outer_diameter']) + '_od'
output_filename += '.nc'
else:
output_filename = pre_probe_inputs['output_file']
print('\nWriting Gcode to:', output_filename)
output_file = open(output_filename,'w')
# Write Header
output_file.write('(G-code automatically written using pre_probe_cylinder.py)\n')
output_file.write('(Outer Diameter: {:4.2f})\n'.format(pre_probe_inputs['outer_diameter']))
output_file.write('(Total Number of points to Probe: {:4d})\n'.format(total_points))
output_file.write('G90 (set absolute distance mode)\n')
output_file.write('G90.1 (set absolute distance mode for arc centers)\n')
output_file.write('G17 (set active plane to XY)\n')
output_file.write('G20 (set units to inches)\n')
output_file.write('\n')
output_file.write('M0 (Attach probe wires and clips that need attaching)\n')
output_file.write('M40 (Open probe file)\n')
output_file.write('\n')
# Position at Start
output_file.write('G0 Z {:5.4f} (Safe Z height)\n'.format(safe_z_height))
output_file.write('G0 Y 0.0000\n')
for i in range(pre_probe_inputs['num_x_points']):
x = pre_probe_inputs['start_x'] + i*delta_x
output_file.write('(X={:5.4f})\n'.format(x))
for j in range(pre_probe_inputs['num_a_points']):
a = j*delta_a
x = pre_probe_inputs['start_x'] + i*delta_x
output_file.write('G0 X {:5.4f} A {:5.3f}\n'.format(x,a))
output_file.write('G31 Z {:5.4f} F {:2.1f}\n'.format(probe_min_z,pre_probe_inputs['probe_feedrate']))
output_file.write('G0 Z {:5.4f}\n'.format(safe_z_height))
# Complete File
output_file.write('\nM41 (Closes the opened log file)\n')
output_file.write('M30\n')
# Close File
output_file.close()