fix: onderkant van het A4 10 mm omhoog
De onderrand van het papier valt samen met Y=-297. Een geweigerd $-commando tijdens het tekenen wordt opnieuw gestuurd zodra de machine stilstaat.
@@ -1,8 +1,8 @@
1
1
const PAPER_LEFT = -10;
2
2
const PAPER_TOP = 4;
3
const PAPER_BOTTOM = -307;
3
const PAPER_BOTTOM = -297;
4
4
const A4W = 210;
5
const A4H = 311;
5
const A4H = PAPER_TOP - PAPER_BOTTOM;
6
6
const PEN_MM = 0.4;
7
7
8
8
const $ = (id) => document.getElementById(id);
@@ -1,8 +1,8 @@1
const PAPER_LEFT = -10;1
const PAPER_LEFT = -10;2
const PAPER_TOP = 4;2
const PAPER_TOP = 4;3
const PAPER_BOTTOM = -307;3
const PAPER_BOTTOM = -297;4
const A4W = 210;4
const A4W = 210;5
const A4H = 311;5
const A4H = PAPER_TOP - PAPER_BOTTOM;6
const PEN_MM = 0.4;6
const PEN_MM = 0.4;7
7
8
const $ = (id) => document.getElementById(id);8
const $ = (id) => document.getElementById(id);@@ -9,11 +9,11 @@ Polyline = list[Point]
9
9
10
10
# Fysiek papier t.o.v. machinehome. Y omhoog is positief.
11
11
# De linkerrand ligt 10 mm links van X=0, de bovenrand 4 mm boven Y=0.
12
# X=200 valt op de rechterrand. Y=-297 valt 10 mm boven de onderrand.
12
# X=200 valt op de rechterrand. Y=-297 valt op de onderrand.
13
13
PAPER_LEFT = -10.0
14
14
PAPER_TOP = 4.0
15
15
PAPER_RIGHT = 200.0
16
PAPER_BOTTOM = -307.0
16
PAPER_BOTTOM = -297.0
17
17
A4_W = PAPER_RIGHT - PAPER_LEFT
18
18
A4_H = PAPER_TOP - PAPER_BOTTOM
19
19
@@ -9,11 +9,11 @@ Polyline = list[Point]9
9
10
# Fysiek papier t.o.v. machinehome. Y omhoog is positief.10
# Fysiek papier t.o.v. machinehome. Y omhoog is positief.11
# De linkerrand ligt 10 mm links van X=0, de bovenrand 4 mm boven Y=0.11
# De linkerrand ligt 10 mm links van X=0, de bovenrand 4 mm boven Y=0.12
# X=200 valt op de rechterrand. Y=-297 valt 10 mm boven de onderrand.12
# X=200 valt op de rechterrand. Y=-297 valt op de onderrand.13
PAPER_LEFT = -10.013
PAPER_LEFT = -10.014
PAPER_TOP = 4.014
PAPER_TOP = 4.015
PAPER_RIGHT = 200.015
PAPER_RIGHT = 200.016
PAPER_BOTTOM = -307.016
PAPER_BOTTOM = -297.017
A4_W = PAPER_RIGHT - PAPER_LEFT17
A4_W = PAPER_RIGHT - PAPER_LEFT18
A4_H = PAPER_TOP - PAPER_BOTTOM18
A4_H = PAPER_TOP - PAPER_BOTTOM19
19
@@ -25,6 +25,12 @@ except ImportError: # pragma: no cover
25
25
_STATE = Path.home() / ".config" / "timdraw" / "last-device.json"
26
26
27
27
28
def grbl_error_code(ack: str) -> str:
29
if not ack.startswith("error:"):
30
return ""
31
return ack[6:].strip()
32
33
28
34
def chord_for_arc(line: str) -> str:
29
35
"""Rechte lijn naar hetzelfde eindpunt, als GRBL een boog met error 33 weigert."""
30
36
words = dict(re.findall(r"([XYF])([+-]?(?:\d+\.\d*|\.\d+|\d+))", line))
@@ -658,13 +664,25 @@ class Machine:
658
664
return
659
665
self._write_raw((line + "\n").encode())
660
666
ack = self._wait_ack(timeout)
661
if ack.startswith("error:33") and line.startswith(("G2 ", "G3 ")):
667
retries = 0
668
while grbl_error_code(ack) == "8" and line.startswith("$") and retries < 8 and not self._stop.is_set():
669
# $ mag alleen in Idle. De beweging was nog bezig; even wachten en opnieuw.
670
retries += 1
671
with self._state_lock:
672
if grbl_error_code(self.error) == "8":
673
self.error = ""
674
self._wait_until_idle(30)
675
if self._stop.is_set():
676
return
677
self._write_raw((line + "\n").encode())
678
ack = self._wait_ack(timeout)
679
if grbl_error_code(ack) == "33" and line.startswith(("G2 ", "G3 ")):
662
680
self._arc_fallbacks += 1
663
681
self._write_raw((chord_for_arc(line) + "\n").encode())
664
682
ack = self._wait_ack(timeout)
665
683
if not ack.startswith("error"):
666
684
with self._state_lock:
667
if self.error.startswith("error:33"):
685
if grbl_error_code(self.error) == "33":
668
686
self.error = ""
669
687
if ack.startswith("error"):
670
688
raise RuntimeError(ack)
@@ -25,6 +25,12 @@ except ImportError: # pragma: no cover25
_STATE = Path.home() / ".config" / "timdraw" / "last-device.json"25
_STATE = Path.home() / ".config" / "timdraw" / "last-device.json"26
26
27
27
28
def grbl_error_code(ack: str) -> str:29
if not ack.startswith("error:"):30
return ""31
return ack[6:].strip()32
33
28
def chord_for_arc(line: str) -> str:34
def chord_for_arc(line: str) -> str:29
"""Rechte lijn naar hetzelfde eindpunt, als GRBL een boog met error 33 weigert."""35
"""Rechte lijn naar hetzelfde eindpunt, als GRBL een boog met error 33 weigert."""30
words = dict(re.findall(r"([XYF])([+-]?(?:\d+\.\d*|\.\d+|\d+))", line))36
words = dict(re.findall(r"([XYF])([+-]?(?:\d+\.\d*|\.\d+|\d+))", line))@@ -658,13 +664,25 @@ class Machine:658
return664
return659
self._write_raw((line + "\n").encode())665
self._write_raw((line + "\n").encode())660
ack = self._wait_ack(timeout)666
ack = self._wait_ack(timeout)661
if ack.startswith("error:33") and line.startswith(("G2 ", "G3 ")):667
retries = 0668
while grbl_error_code(ack) == "8" and line.startswith("$") and retries < 8 and not self._stop.is_set():669
# $ mag alleen in Idle. De beweging was nog bezig; even wachten en opnieuw.670
retries += 1671
with self._state_lock:672
if grbl_error_code(self.error) == "8":673
self.error = ""674
self._wait_until_idle(30)675
if self._stop.is_set():676
return677
self._write_raw((line + "\n").encode())678
ack = self._wait_ack(timeout)679
if grbl_error_code(ack) == "33" and line.startswith(("G2 ", "G3 ")):662
self._arc_fallbacks += 1680
self._arc_fallbacks += 1663
self._write_raw((chord_for_arc(line) + "\n").encode())681
self._write_raw((chord_for_arc(line) + "\n").encode())664
ack = self._wait_ack(timeout)682
ack = self._wait_ack(timeout)665
if not ack.startswith("error"):683
if not ack.startswith("error"):666
with self._state_lock:684
with self._state_lock:667
if self.error.startswith("error:33"):685
if grbl_error_code(self.error) == "33":668
self.error = ""686
self.error = ""669
if ack.startswith("error"):687
if ack.startswith("error"):670
raise RuntimeError(ack)688
raise RuntimeError(ack)@@ -81,7 +81,7 @@ def test_text_and_gcode() -> None:
81
81
check("grijswaarden tekenen", gray_job["stats"]["drawMm"] > 100, str(gray_job["stats"]))
82
82
corner = plan([{
83
83
"x": 0, "y": 0, "scale": 1, "rotation": 0, "drawLine": True, "drawFill": False,
84
"strokes": [{"pts": [(10, 307), (30, 287)]}],
84
"strokes": [{"pts": [(10, 297), (30, 277)]}],
85
85
}], {"origin": "top-left"})
86
86
check("homehoek blijft X0 Y0", "X0.000 Y0.000" in corner["gcode"], corner["gcode"])
87
87
check("blad ligt rechts en onder het nulpunt", "X20.000 Y-20.000" in corner["gcode"])
@@ -92,8 +92,8 @@ def test_text_and_gcode() -> None:
92
92
"x": 0, "y": 0, "scale": 1, "rotation": 0, "drawLine": True, "drawFill": False,
93
93
"strokes": [
94
94
{"pts": [(110, 110), (130, 110)]},
95
{"pts": [(20, 307), (10, 307)]},
96
{"pts": [(20, 297), (20, 307)]},
95
{"pts": [(20, 297), (10, 297)]},
96
{"pts": [(20, 287), (20, 297)]},
97
97
],
98
98
}], {"origin": "top-left", "returnHome": False, "travelSpeed": 4000})
99
99
moves = [line for line in linked["gcode"].splitlines() if line.startswith("G1 X")]
@@ -105,7 +105,7 @@ def test_text_and_gcode() -> None:
105
105
{"x": 0, "y": 0, "scale": 1, "rotation": 0, "drawLine": True, "drawFill": False,
106
106
"strokes": [{"pts": [(110, 110), (130, 110)]}]},
107
107
{"x": 0, "y": 0, "scale": 1, "rotation": 0, "drawLine": True, "drawFill": False,
108
"strokes": [{"pts": [(10, 307), (30, 307)]}]},
108
"strokes": [{"pts": [(10, 297), (30, 297)]}]},
109
109
], {"origin": "top-left", "perObject": True, "returnHome": False, "travelSpeed": 4000})
110
110
grouped_moves = [line for line in grouped["gcode"].splitlines() if line.startswith("G1 X")]
111
111
check("eerst het eerste object", "X100.000" in grouped_moves[0], " | ".join(grouped_moves[:3]))
@@ -113,7 +113,7 @@ def test_text_and_gcode() -> None:
113
113
{"x": 0, "y": 0, "scale": 1, "rotation": 0, "drawLine": True, "drawFill": False,
114
114
"strokes": [{"pts": [(110, 110), (130, 110)]}]},
115
115
{"x": 0, "y": 0, "scale": 1, "rotation": 0, "drawLine": True, "drawFill": False,
116
"strokes": [{"pts": [(10, 307), (30, 307)]}]},
116
"strokes": [{"pts": [(10, 297), (30, 297)]}]},
117
117
], {"origin": "top-left", "returnHome": False, "travelSpeed": 4000})
118
118
mixed_moves = [line for line in mixed["gcode"].splitlines() if line.startswith("G1 X")]
119
119
check("zonder groeperen de dichtstbijzijnde", mixed_moves[0].startswith("G1 X0.000 Y0.000"), " | ".join(mixed_moves[:2]))
@@ -279,11 +279,24 @@ def test_virtual_machine() -> None:
279
279
finally:
280
280
machine.disconnect()
281
281
282
machine, grbl = connect(0, 0)
283
try:
284
before = grbl.commands.count("$1=255")
285
grbl.reject_dollar = 1
286
machine._job_line("$1=255", 5)
287
check(
288
"error 8 wordt opnieuw gestuurd",
289
grbl.commands.count("$1=255") == before + 2 and machine.error == "",
290
machine.error,
291
)
292
finally:
293
machine.disconnect()
294
282
295
machine, grbl = connect(0, 0)
283
296
try:
284
297
corner = plan([{
285
298
"x": 0, "y": 0, "scale": 1, "rotation": 0, "drawLine": True, "drawFill": False,
286
"strokes": [{"pts": [(10, 307), (30, 287)]}],
299
"strokes": [{"pts": [(10, 297), (30, 277)]}],
287
300
}], {"origin": "top-left"})
288
301
gcode = corner["gcode"] + "\nG3 X30.000 Y-20.000 I0.000 J10.000 F3000\n"
289
302
machine.start_job(gcode)
@@ -81,7 +81,7 @@ def test_text_and_gcode() -> None:81
check("grijswaarden tekenen", gray_job["stats"]["drawMm"] > 100, str(gray_job["stats"]))81
check("grijswaarden tekenen", gray_job["stats"]["drawMm"] > 100, str(gray_job["stats"]))82
corner = plan([{82
corner = plan([{83
"x": 0, "y": 0, "scale": 1, "rotation": 0, "drawLine": True, "drawFill": False,83
"x": 0, "y": 0, "scale": 1, "rotation": 0, "drawLine": True, "drawFill": False,84
"strokes": [{"pts": [(10, 307), (30, 287)]}],84
"strokes": [{"pts": [(10, 297), (30, 277)]}],85
}], {"origin": "top-left"})85
}], {"origin": "top-left"})86
check("homehoek blijft X0 Y0", "X0.000 Y0.000" in corner["gcode"], corner["gcode"])86
check("homehoek blijft X0 Y0", "X0.000 Y0.000" in corner["gcode"], corner["gcode"])87
check("blad ligt rechts en onder het nulpunt", "X20.000 Y-20.000" in corner["gcode"])87
check("blad ligt rechts en onder het nulpunt", "X20.000 Y-20.000" in corner["gcode"])@@ -92,8 +92,8 @@ def test_text_and_gcode() -> None:92
"x": 0, "y": 0, "scale": 1, "rotation": 0, "drawLine": True, "drawFill": False,92
"x": 0, "y": 0, "scale": 1, "rotation": 0, "drawLine": True, "drawFill": False,93
"strokes": [93
"strokes": [94
{"pts": [(110, 110), (130, 110)]},94
{"pts": [(110, 110), (130, 110)]},95
{"pts": [(20, 307), (10, 307)]},95
{"pts": [(20, 297), (10, 297)]},96
{"pts": [(20, 297), (20, 307)]},96
{"pts": [(20, 287), (20, 297)]},97
],97
],98
}], {"origin": "top-left", "returnHome": False, "travelSpeed": 4000})98
}], {"origin": "top-left", "returnHome": False, "travelSpeed": 4000})99
moves = [line for line in linked["gcode"].splitlines() if line.startswith("G1 X")]99
moves = [line for line in linked["gcode"].splitlines() if line.startswith("G1 X")]@@ -105,7 +105,7 @@ def test_text_and_gcode() -> None:105
{"x": 0, "y": 0, "scale": 1, "rotation": 0, "drawLine": True, "drawFill": False,105
{"x": 0, "y": 0, "scale": 1, "rotation": 0, "drawLine": True, "drawFill": False,106
"strokes": [{"pts": [(110, 110), (130, 110)]}]},106
"strokes": [{"pts": [(110, 110), (130, 110)]}]},107
{"x": 0, "y": 0, "scale": 1, "rotation": 0, "drawLine": True, "drawFill": False,107
{"x": 0, "y": 0, "scale": 1, "rotation": 0, "drawLine": True, "drawFill": False,108
"strokes": [{"pts": [(10, 307), (30, 307)]}]},108
"strokes": [{"pts": [(10, 297), (30, 297)]}]},109
], {"origin": "top-left", "perObject": True, "returnHome": False, "travelSpeed": 4000})109
], {"origin": "top-left", "perObject": True, "returnHome": False, "travelSpeed": 4000})110
grouped_moves = [line for line in grouped["gcode"].splitlines() if line.startswith("G1 X")]110
grouped_moves = [line for line in grouped["gcode"].splitlines() if line.startswith("G1 X")]111
check("eerst het eerste object", "X100.000" in grouped_moves[0], " | ".join(grouped_moves[:3]))111
check("eerst het eerste object", "X100.000" in grouped_moves[0], " | ".join(grouped_moves[:3]))@@ -113,7 +113,7 @@ def test_text_and_gcode() -> None:113
{"x": 0, "y": 0, "scale": 1, "rotation": 0, "drawLine": True, "drawFill": False,113
{"x": 0, "y": 0, "scale": 1, "rotation": 0, "drawLine": True, "drawFill": False,114
"strokes": [{"pts": [(110, 110), (130, 110)]}]},114
"strokes": [{"pts": [(110, 110), (130, 110)]}]},115
{"x": 0, "y": 0, "scale": 1, "rotation": 0, "drawLine": True, "drawFill": False,115
{"x": 0, "y": 0, "scale": 1, "rotation": 0, "drawLine": True, "drawFill": False,116
"strokes": [{"pts": [(10, 307), (30, 307)]}]},116
"strokes": [{"pts": [(10, 297), (30, 297)]}]},117
], {"origin": "top-left", "returnHome": False, "travelSpeed": 4000})117
], {"origin": "top-left", "returnHome": False, "travelSpeed": 4000})118
mixed_moves = [line for line in mixed["gcode"].splitlines() if line.startswith("G1 X")]118
mixed_moves = [line for line in mixed["gcode"].splitlines() if line.startswith("G1 X")]119
check("zonder groeperen de dichtstbijzijnde", mixed_moves[0].startswith("G1 X0.000 Y0.000"), " | ".join(mixed_moves[:2]))119
check("zonder groeperen de dichtstbijzijnde", mixed_moves[0].startswith("G1 X0.000 Y0.000"), " | ".join(mixed_moves[:2]))@@ -279,11 +279,24 @@ def test_virtual_machine() -> None:279
finally:279
finally:280
machine.disconnect()280
machine.disconnect()281
281
282
machine, grbl = connect(0, 0)283
try:284
before = grbl.commands.count("$1=255")285
grbl.reject_dollar = 1286
machine._job_line("$1=255", 5)287
check(288
"error 8 wordt opnieuw gestuurd",289
grbl.commands.count("$1=255") == before + 2 and machine.error == "",290
machine.error,291
)292
finally:293
machine.disconnect()294
282
machine, grbl = connect(0, 0)295
machine, grbl = connect(0, 0)283
try:296
try:284
corner = plan([{297
corner = plan([{285
"x": 0, "y": 0, "scale": 1, "rotation": 0, "drawLine": True, "drawFill": False,298
"x": 0, "y": 0, "scale": 1, "rotation": 0, "drawLine": True, "drawFill": False,286
"strokes": [{"pts": [(10, 307), (30, 287)]}],299
"strokes": [{"pts": [(10, 297), (30, 277)]}],287
}], {"origin": "top-left"})300
}], {"origin": "top-left"})288
gcode = corner["gcode"] + "\nG3 X30.000 Y-20.000 I0.000 J10.000 F3000\n"301
gcode = corner["gcode"] + "\nG3 X30.000 Y-20.000 I0.000 J10.000 F3000\n"289
machine.start_job(gcode)302
machine.start_job(gcode)@@ -31,6 +31,7 @@ class VirtualGrbl:
31
31
self.jog_queue: list[tuple[float, float]] = []
32
32
self.drawn: list[tuple[float, float]] = []
33
33
self.commands: list[str] = []
34
self.reject_dollar = 0
34
35
self._polls = 0
35
36
self._line = ""
36
37
@@ -111,6 +112,9 @@ class VirtualGrbl:
111
112
if line.startswith("$$"):
112
113
return ["$110=6000", "$111=6000", "ok"]
113
114
if line.startswith("$"):
115
if self.reject_dollar > 0:
116
self.reject_dollar -= 1
117
return ["error:8"]
114
118
return ["ok"]
115
119
return self._motion(line)
116
120
@@ -31,6 +31,7 @@ class VirtualGrbl:31
self.jog_queue: list[tuple[float, float]] = []31
self.jog_queue: list[tuple[float, float]] = []32
self.drawn: list[tuple[float, float]] = []32
self.drawn: list[tuple[float, float]] = []33
self.commands: list[str] = []33
self.commands: list[str] = []34
self.reject_dollar = 034
self._polls = 035
self._polls = 035
self._line = ""36
self._line = ""36
37
@@ -111,6 +112,9 @@ class VirtualGrbl:111
if line.startswith("$$"):112
if line.startswith("$$"):112
return ["$110=6000", "$111=6000", "ok"]113
return ["$110=6000", "$111=6000", "ok"]113
if line.startswith("$"):114
if line.startswith("$"):115
if self.reject_dollar > 0:116
self.reject_dollar -= 1117
return ["error:8"]114
return ["ok"]118
return ["ok"]115
return self._motion(line)119
return self._motion(line)116
120