Skip to content

Commit

Permalink
adding Bézier Movement support
Browse files Browse the repository at this point in the history
  • Loading branch information
jgphilpott committed Mar 29, 2024
1 parent 79ac47b commit f488f81
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 24 deletions.
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"cSpell.language": "en-US",
"cSpell.words": [
"autohome",
"bézier",
"cura",
"forkme",
"gcode",
Expand Down
65 changes: 53 additions & 12 deletions src/polyslice.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -54,27 +54,27 @@ class Polyslice

gcode = ""

if x isnt null and typeof x is "number"
if typeof x is "number"

gcode += " X" + x

if y isnt null and typeof y is "number"
if typeof y is "number"

gcode += " Y" + y

if z isnt null and typeof z is "number"
if typeof z is "number"

gcode += " Z" + z

if e isnt null and typeof e is "number"
if typeof e is "number"

gcode += " E" + e

if f isnt null and typeof f is "number"
if typeof f is "number"

gcode += " F" + f

if s isnt null and typeof s is "number"
if typeof s is "number"

gcode += " S" + s

Expand All @@ -98,27 +98,27 @@ class Polyslice

gcode += this.codeMovement x, y, z, e, f, s

if i isnt null and typeof i is "number"
if typeof i is "number"

gcode += " I" + i

if j isnt null and typeof j is "number"
if typeof j is "number"

gcode += " J" + j

if p isnt null and typeof p is "number"
if typeof p is "number"

gcode += " P" + p

else if i is null and j is null and r isnt null and x isnt null and y isnt null

gcode += this.codeMovement x, y, z, e, f, s

if r isnt null and typeof r is "number"
if typeof r is "number"

gcode += " R" + r

if p isnt null and typeof p is "number"
if typeof p is "number"

gcode += " P" + p

Expand All @@ -128,13 +128,54 @@ class Polyslice

return gcode + this.newline

# https://marlinfw.org/docs/gcode/G005.html
codeBézierMovement: (controlPoints = []) ->

gcode = ""

for controlPoint, index in controlPoints

if typeof controlPoint.p is "number" and typeof controlPoint.q is "number"

if index is 0 and (typeof controlPoint.i isnt "number" or typeof controlPoint.j isnt "number")

console.error "Invalid Bézier Movement Parameters"

else

gcode += "G5"

x = controlPoint.x
y = controlPoint.y
e = controlPoint.e
f = controlPoint.f
s = controlPoint.s

gcode += this.codeMovement x, y, null, e, f, s

if typeof controlPoint.i is "number" and typeof controlPoint.j is "number"

gcode += " I" + controlPoint.i
gcode += " J" + controlPoint.j

gcode += " P" + controlPoint.p
gcode += " Q" + controlPoint.q

gcode += this.newline

else

console.error "Invalid Bézier Movement Parameters"

return gcode

# https://marlinfw.org/docs/gcode/G004.html
# https://marlinfw.org/docs/gcode/M000-M001.html
codeDwell: (time = null, interruptible = true, message = "") ->

if interruptible then gcode = "M0" else gcode = "G4"

if time isnt null and typeof time is "number" and time > 0
if typeof time is "number" and time > 0

gcode += " P" + time

Expand Down
56 changes: 44 additions & 12 deletions src/polyslice.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit f488f81

Please sign in to comment.