Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
macdylan committed Aug 11, 2023
1 parent 634adba commit 930d310
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 30 deletions.
42 changes: 27 additions & 15 deletions fix/gcode_mod.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ var (
reG4S0 = regexp.MustCompile(`^\s*G4\s+[SP]0.*`)
// G1 for prime tower
reG1 = regexp.MustCompile(`^\s*G1 .*(?P<arg1>[EF][\d\.]+).+(?P<arg2>[EF][\d\.]+).*`)

// ;Z:height
reZ = regexp.MustCompile(`^;Z:(?P<height>[\d\.]+)`)
// M104/109 S100 T1
reTemp = regexp.MustCompile(`^\s*(?P<cmd>M10[49]) .*(?P<arg1>[ST][\d]+).*(?P<arg2>[ST][\d]+).*`)
)

Expand Down Expand Up @@ -239,31 +241,41 @@ 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") {
wiping = true
}
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)
}
}
Expand Down
32 changes: 17 additions & 15 deletions fix/internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 930d310

Please sign in to comment.