diff --git a/fix/gcode_mod.go b/fix/gcode_mod.go index 4f27c96..ab6c24d 100644 --- a/fix/gcode_mod.go +++ b/fix/gcode_mod.go @@ -19,7 +19,9 @@ var ( reG4S0 = regexp.MustCompile(`^\s*G4\s+[SP]0.*`) // G1 for prime tower reG1 = regexp.MustCompile(`^\s*G1 .*(?P[EF][\d\.]+).+(?P[EF][\d\.]+).*`) - + // ;Z:height + reZ = regexp.MustCompile(`^;Z:(?P[\d\.]+)`) + // M104/109 S100 T1 reTemp = regexp.MustCompile(`^\s*(?PM10[49]) .*(?P[ST][\d]+).*(?P[ST][\d]+).*`) ) @@ -239,6 +241,7 @@ func GcodeReinforceTower(gcodes []string) (output []string) { e float64 f float64 cmd string + z float64 ) for _, line := range gcodes { if strings.HasPrefix(line, "; CP TOOLCHANGE WIPE") { @@ -246,24 +249,33 @@ func GcodeReinforceTower(gcodes []string) (output []string) { } if strings.HasPrefix(line, "; CP TOOLCHANGE END") { wiping = false + e = 0.0 + } + if strings.HasPrefix(line, ";Z:") { + zMatch := reZ.FindStringSubmatch(line) + if len(zMatch) > 0 { + z, _ = strconv.ParseFloat(zMatch[1], 64) + } } - if wiping { + if wiping && z > 0.3 { efMatch := reG1.FindStringSubmatch(line) if len(efMatch) > 0 { - if strings.HasPrefix(efMatch[1], "E") && strings.HasPrefix(efMatch[2], "F") { - e, _ = strconv.ParseFloat(efMatch[1][1:], 64) - f, _ = strconv.ParseFloat(efMatch[2][1:], 64) - } else { - f, _ = strconv.ParseFloat(efMatch[1][1:], 64) - e, _ = strconv.ParseFloat(efMatch[2][1:], 64) - } - if e > 0.0 { - e = e / 2.0 // half is enough for fusion - } - if f > 0.0 { - f = f / 3.0 * 2.0 + if e < 0.01 { + if strings.HasPrefix(efMatch[1], "E") && strings.HasPrefix(efMatch[2], "F") { + e, _ = strconv.ParseFloat(efMatch[1][1:], 64) + f, _ = strconv.ParseFloat(efMatch[2][1:], 64) + } else { + f, _ = strconv.ParseFloat(efMatch[1][1:], 64) + e, _ = strconv.ParseFloat(efMatch[2][1:], 64) + } + if e > 0.0 { + e = e * 0.45 + } + // if f > 0.0 { + // f = f * 0.7 + // } } - cmd = "G1 E" + strconv.FormatFloat(e, 'f', 4, 64) + " F" + strconv.FormatFloat(f, 'f', 0, 64) + " ; (Fixed: stabilization tower)" + cmd = "G1 E" + strconv.FormatFloat(e, 'f', 4, 64) + " F" + strconv.FormatFloat(f, 'f', 0, 64) + " ; (Fixed: reinforce tower)" output = append(output, cmd) } } diff --git a/fix/internal_test.go b/fix/internal_test.go index 199ea50..ca097fd 100644 --- a/fix/internal_test.go +++ b/fix/internal_test.go @@ -343,49 +343,51 @@ Line 5 func TestGcodeReinforceTower(t *testing.T) { gcodes := ` -G1 X176.579 E1.2970 F1584 +G1 X176.579 E4.2970 F1584 +;Z:0.3 ; CP TOOLCHANGE WIPE G1 X176.579 E1.2970 F1584 G1 Y31.500 E0.1900 G1 X142.329 E1.3017 F1800 -G1 Y36.500 E0.1900 -G1 X176.579 E1.3017 F2198 G1 F19200 G92 E0 ; CP TOOLCHANGE END +;Z:0.4 G1 X176.579 E1.2970 F1584 ; CP TOOLCHANGE WIPE M73 R80 -G1 X176.579 E1.2970 F1584 +G1 X176.579 E2.2970 F1584 G1 Y31.500 E0.1900 -G1 X176.579 E1.3017 F2198 +G1 X176.579 E4.3017 F2198 +G1 Y36.500 E0.1900 +G1 X176.579 E4.3017 F2198 G1 F19200 G92 E0 ; CP TOOLCHANGE END G1 X176.579 E1.2970 F1584 ` comp := ` -G1 X176.579 E1.2970 F1584 +G1 X176.579 E4.2970 F1584 +;Z:0.3 ; CP TOOLCHANGE WIPE -G1 E0.6485 F1056 ; (Fixed: stabilization tower) G1 X176.579 E1.2970 F1584 G1 Y31.500 E0.1900 -G1 E0.6509 F1200 ; (Fixed: stabilization tower) G1 X142.329 E1.3017 F1800 -G1 Y36.500 E0.1900 -G1 E0.6509 F1465 ; (Fixed: stabilization tower) -G1 X176.579 E1.3017 F2198 G1 F19200 G92 E0 ; CP TOOLCHANGE END +;Z:0.4 G1 X176.579 E1.2970 F1584 ; CP TOOLCHANGE WIPE M73 R80 -G1 E0.6485 F1056 ; (Fixed: stabilization tower) -G1 X176.579 E1.2970 F1584 +G1 E1.0337 F1584 ; (Fixed: reinforce tower) +G1 X176.579 E2.2970 F1584 G1 Y31.500 E0.1900 -G1 E0.6509 F1465 ; (Fixed: stabilization tower) -G1 X176.579 E1.3017 F2198 +G1 E1.0337 F1584 ; (Fixed: reinforce tower) +G1 X176.579 E4.3017 F2198 +G1 Y36.500 E0.1900 +G1 E1.0337 F1584 ; (Fixed: reinforce tower) +G1 X176.579 E4.3017 F2198 G1 F19200 G92 E0 ; CP TOOLCHANGE END