Browse Source

allow negative values

and some more comments
Wurstnase 9 years ago
parent
commit
14f0250853
1 changed files with 25 additions and 12 deletions
  1. 25
    12
      Marlin/scripts/g29_auto.py

+ 25
- 12
Marlin/scripts/g29_auto.py View File

12
 # this is the minimum of G1 instructions which should be between 2 different heights
12
 # this is the minimum of G1 instructions which should be between 2 different heights
13
 min_g1 = 3
13
 min_g1 = 3
14
 
14
 
15
-#  maximum number of lines to parse, I don't want to parse the complete file
15
+# maximum number of lines to parse, I don't want to parse the complete file
16
 # only the first plane is we are interested in
16
 # only the first plane is we are interested in
17
 max_g1 = 1000
17
 max_g1 = 1000
18
 
18
 
19
 # g29 keyword
19
 # g29 keyword
20
-g29_keyword = ';MarlinG29Script'
20
+g29_keyword = 'g29'
21
+g29_keyword = g29_keyword.upper()
21
 
22
 
22
 # output filename
23
 # output filename
23
 output_file = folder + 'g29_' + my_file
24
 output_file = folder + 'g29_' + my_file
25
+# input filename
26
+input_file = folder + my_file
24
 
27
 
25
 # offset makes the plane a little bit bigger
28
 # offset makes the plane a little bit bigger
26
 offset_x = 10
29
 offset_x = 10
40
 gcode = []
43
 gcode = []
41
 
44
 
42
 
45
 
46
+# return only g1-lines
43
 def has_g1(line):
47
 def has_g1(line):
44
     return line[:2].upper() == "G1"
48
     return line[:2].upper() == "G1"
45
 
49
 
46
 
50
 
51
+# find position in g1 (x,y,z)
47
 def find_axis(line, axis):
52
 def find_axis(line, axis):
48
     found = False
53
     found = False
49
     number = ""
54
     number = ""
51
         if found:
56
         if found:
52
             if char == ".":
57
             if char == ".":
53
                 number += char
58
                 number += char
59
+            elif char == "-":
60
+                number += char
54
             else:
61
             else:
55
                 try:
62
                 try:
56
                     int(char)
63
                     int(char)
65
         return None
72
         return None
66
 
73
 
67
 
74
 
75
+# save the min or max-values for each axis
68
 def set_mima(line):
76
 def set_mima(line):
69
     global min_x, max_x, min_y, max_y, last_z
77
     global min_x, max_x, min_y, max_y, last_z
70
 
78
 
81
     return min_x, max_x, min_y, max_y
89
     return min_x, max_x, min_y, max_y
82
 
90
 
83
 
91
 
92
+# find z in the code and return it
84
 def find_z(gcode, start_at_line=0):
93
 def find_z(gcode, start_at_line=0):
85
     for i in range(start_at_line, len(gcode)):
94
     for i in range(start_at_line, len(gcode)):
86
         my_z = find_axis(gcode[i], 'Z')
95
         my_z = find_axis(gcode[i], 'Z')
104
 
113
 
105
         all_z.append(z)
114
         all_z.append(z)
106
         z_at_line.append(i)
115
         z_at_line.append(i)
116
+        temp_line = i - last_i -1
107
         line_between_z.append(i - last_i - 1)
117
         line_between_z.append(i - last_i - 1)
108
         # last_z = z
118
         # last_z = z
109
         last_i = i
119
         last_i = i
110
-        if 0 < end_at_line <= i:
120
+        if 0 < end_at_line <= i or temp_line >= min_g1:
121
+            # print('break at line {} at heigth {}'.format(i, z))
111
             break
122
             break
112
-            # print('{}:{}'.format(last_z, last_i))
113
 
123
 
114
     line_between_z = line_between_z[1:]
124
     line_between_z = line_between_z[1:]
115
     return all_z, line_between_z, z_at_line
125
     return all_z, line_between_z, z_at_line
116
 
126
 
117
 
127
 
128
+# get the lines which should be the first layer
118
 def get_lines(gcode, minimum):
129
 def get_lines(gcode, minimum):
119
     i = 0
130
     i = 0
120
     all_z, line_between_z, z_at_line = z_parse(gcode, end_at_line=max_g1)
131
     all_z, line_between_z, z_at_line = z_parse(gcode, end_at_line=max_g1)
121
     for count in line_between_z:
132
     for count in line_between_z:
122
         i += 1
133
         i += 1
123
         if count > minimum:
134
         if count > minimum:
135
+            # print('layer: {}:{}'.format(z_at_line[i-1], z_at_line[i]))
124
             return z_at_line[i - 1], z_at_line[i]
136
             return z_at_line[i - 1], z_at_line[i]
125
 
137
 
126
 
138
 
127
-with open(folder+my_file, 'r') as file:
139
+with open(input_file, 'r') as file:
128
     lines = 0
140
     lines = 0
129
     for line in file:
141
     for line in file:
130
         lines += 1
142
         lines += 1
138
 for i in range(start, end):
150
 for i in range(start, end):
139
     set_mima(gcode[i])
151
     set_mima(gcode[i])
140
 
152
 
153
+print('x_min:{} x_max:{}\ny_min:{} y_max:{}'.format(min_x, max_x, min_y, max_y))
154
+
141
 min_x = int(min_x) - offset_x
155
 min_x = int(min_x) - offset_x
142
 max_x = int(max_x) + offset_x
156
 max_x = int(max_x) + offset_x
143
 min_y = int(min_y) - offset_y
157
 min_y = int(min_y) - offset_y
149
                                                       max_y,
163
                                                       max_y,
150
                                                       probing_points)
164
                                                       probing_points)
151
 
165
 
152
-
153
 out_file = open(output_file, 'w')
166
 out_file = open(output_file, 'w')
154
-print('out_file open')
155
-input_file = open(my_file, 'r')
156
-print('input_file open')
167
+in_file = open(input_file, 'r')
157
 
168
 
158
-for line in input_file:
159
-    if line[:len(g29_keyword)] == g29_keyword:
169
+for line in in_file:
170
+    if line[:len(g29_keyword)].upper() == g29_keyword:
160
         out_file.write(new_command)
171
         out_file.write(new_command)
161
-        print('write new_command')
172
+        print('write G29')
162
     else:
173
     else:
163
         out_file.write(line)
174
         out_file.write(line)
164
 
175
 
165
 file.close()
176
 file.close()
166
 out_file.close()
177
 out_file.close()
178
+
179
+print('auto G29 finished')

Loading…
Cancel
Save