🐛 GCode analysis & viewer: Assume bed at Z 0.0

People might not actually always have a home command in their GCODE
files, so let's just depend on the so far pretty universal truth that
printers have a bed at z=0 and that is just always the lowest Z of a
printed object. And just in case, let's make this value configurable
because the printer gods only know what some people might come up with
in terms of experimental printer mechanics that end up with negative z
coordinates or a bed at z=100.

Closes #4036
This commit is contained in:
Gina Häußge committed 2021-03-04 12:49:13 +01:00
1 parent ffea45ce54
commit 4c4570e2e1
9 files changed
+58 -18

No files matched your search

+3
View File
@@ -69,6 +69,7 @@ def util():
@click.option("--offset", "offset", type=(float, float), multiple=True)
@click.option("--max-t", "maxt", type=int, default=10)
@click.option("--g90-extruder", "g90_extruder", is_flag=True)
@click.option("--bed-z", "bedz", type=float, default=0)
@click.option("--progress", "progress", is_flag=True)
@click.argument("path", type=click.Path())
def gcode_command(
@@ -81,6 +82,7 @@ def gcode_command(
throttle,
throttle_lines,
g90_extruder,
bedz,
progress,
):
"""Runs a GCODE file analysis."""
@@ -127,6 +129,7 @@ def gcode_command(
throttle=throttle_callback,
max_extruders=maxt,
g90_extruder=g90_extruder,
bed_z=bedz,
)
click.echo("DONE:{}s".format(monotonic_time() - start_time))
+2
View File
@@ -419,6 +419,7 @@ class GcodeAnalysisQueue(AbstractAnalysisQueue):
throttle_lines = settings().getInt(["gcodeAnalysis", "throttle_lines"])
max_extruders = settings().getInt(["gcodeAnalysis", "maxExtruders"])
g90_extruder = settings().getBoolean(["feature", "g90InfluencesExtruder"])
bed_z = settings().getFloat(["gcodeAnalysis", "bedZ"])
speedx = self._current.printer_profile["axes"]["x"]["speed"]
speedy = self._current.printer_profile["axes"]["y"]["speed"]
offsets = self._current.printer_profile["extruder"]["offsets"]
@@ -434,6 +435,7 @@ class GcodeAnalysisQueue(AbstractAnalysisQueue):
"--max-t={}".format(max_extruders),
"--throttle={}".format(throttle),
"--throttle-lines={}".format(throttle_lines),
"--bed-z={}".format(bed_z),
]
for offset in offsets[1:]:
command += ["--offset", str(offset[0]), str(offset[1])]
@@ -365,7 +365,8 @@ $(function () {
onLayerSelected: self._onLayerSelected,
bed: self._retrieveBedDimensions(),
toolOffsets: self._retrieveToolOffsets(),
invertAxes: self._retrieveAxesConfiguration()
invertAxes: self._retrieveAxesConfiguration(),
bedZ: self.settings.settings.gcodeAnalysis.bedZ()
});
if (!initResult) {
@@ -39,7 +39,8 @@ GCODE.gCodeReader = (function () {
centeredOrigin: undefined
},
ignoreOutsideBed: false,
g90InfluencesExtruder: false
g90InfluencesExtruder: false,
bedZ: 0
};
var percentageTree = undefined;
@@ -166,7 +167,8 @@ GCODE.gCodeReader = (function () {
toolOffsets: gCodeOptions["toolOffsets"],
bed: gCodeOptions["bed"],
ignoreOutsideBed: gCodeOptions["ignoreOutsideBed"],
g90InfluencesExtruder: gCodeOptions["g90InfluencesExtruder"]
g90InfluencesExtruder: gCodeOptions["g90InfluencesExtruder"],
bedZ: gCodeOptions["bedZ"]
}
}
});
@@ -174,11 +176,11 @@ GCODE.gCodeReader = (function () {
setOption: function (options) {
var dirty = false;
for (var opt in options) {
if (options[opt] === undefined) continue;
dirty = dirty || gCodeOptions[opt] != options[opt];
gCodeOptions[opt] = options[opt];
}
_.forOwn(options, function (value, key) {
if (value === undefined) return;
dirty = dirty || gCodeOptions[key] !== value;
gCodeOptions[key] = value;
});
if (dirty) {
if (model && model.length > 0) this.passDataToRenderer();
}
@@ -156,7 +156,8 @@ GCODE.ui = (function () {
});
GCODE.gCodeReader.setOption({
toolOffsets: options.toolOffsets,
bed: options.bed
bed: options.bed,
bedZ: options.bedZ
});
GCODE.renderer.render(0, 0);
@@ -715,6 +715,7 @@ var parseGCode = function (message) {
bed = message.options.bed;
ignoreOutsideBed = message.options.ignoreOutsideBed;
g90InfluencesExtruder = message.options.g90InfluencesExtruder;
boundingBox.minZ = min.z = message.options.bedZ;
doParse();
gcode = [];
+6 -1
View File
@@ -153,7 +153,10 @@ def getSettings():
"g90InfluencesExtruder": s.getBoolean(["feature", "g90InfluencesExtruder"]),
"autoUppercaseBlacklist": s.get(["feature", "autoUppercaseBlacklist"]),
},
"gcodeAnalysis": {"runAt": s.get(["gcodeAnalysis", "runAt"])},
"gcodeAnalysis": {
"runAt": s.get(["gcodeAnalysis", "runAt"]),
"bedZ": s.getFloat(["gcodeAnalysis", "bedZ"]),
},
"serial": {
"port": connectionOptions["portPreference"],
"baudrate": connectionOptions["baudratePreference"],
@@ -614,6 +617,8 @@ def _saveSettings(data):
if "gcodeAnalysis" in data:
if "runAt" in data["gcodeAnalysis"]:
s.set(["gcodeAnalysis", "runAt"], data["gcodeAnalysis"]["runAt"])
if "bedZ" in data["gcodeAnalysis"]:
s.setBoolean(["gcodeAnalysis", "bedZ"], data["gcodeAnalysis"]["bedZ"])
if "serial" in data:
if "autoconnect" in data["serial"]:
+1
View File
@@ -270,6 +270,7 @@ default_settings = {
"throttle_highprio": 0.0,
"throttle_lines": 100,
"runAt": "idle", # 'never', 'idle', 'always'
"bedZ": 0.0,
},
"feature": {
"temperatureGraph": True,
+32 -8
View File
@@ -146,11 +146,33 @@ class MinMax3D(object):
>>> empty = MinMax3D()
>>> empty.size == Vector3D(0.0, 0.0, 0.0)
True
>>> weird = MinMax3D(min_z=-1.0)
>>> weird.record(Vector3D(2.0, 2.0, 2.0))
>>> weird.record(Vector3D(1.0, 2.0, 3.0))
>>> weird.min.z == -1.0
True
>>> weird.size == Vector3D(1.0, 0.0, 4.0)
True
"""
def __init__(self):
self.min = Vector3D(float("inf"), float("inf"), float("inf"))
self.max = Vector3D(-float("inf"), -float("inf"), -float("inf"))
def __init__(
self,
min_x=None,
min_y=None,
min_z=None,
max_x=None,
max_y=None,
max_z=None,
):
min_x = min_x if min_x is not None else float("inf")
min_y = min_y if min_y is not None else float("inf")
min_z = min_z if min_z is not None else float("inf")
max_x = max_x if max_x is not None else -float("inf")
max_y = max_y if max_y is not None else -float("inf")
max_z = max_z if max_z is not None else -float("inf")
self.min = Vector3D(min_x, min_y, min_z)
self.max = Vector3D(max_x, max_y, max_z)
def record(self, coordinate):
"""
@@ -227,7 +249,9 @@ class gcode(object):
offsets=None,
max_extruders=10,
g90_extruder=False,
bed_z=0.0,
):
self._minMax.min.z = bed_z
if os.path.isfile(filename):
self.filename = filename
self._fileSize = os.stat(filename).st_size
@@ -448,17 +472,17 @@ class gcode(object):
x = getCodeFloat(line, "X")
y = getCodeFloat(line, "Y")
z = getCodeFloat(line, "Z")
center = Vector3D(0.0, 0.0, 0.0)
origin = Vector3D(0.0, 0.0, 0.0)
if x is None and y is None and z is None:
pos = center
pos = origin
else:
pos = Vector3D(pos)
if x is not None:
pos.x = center.x
pos.x = origin.x
if y is not None:
pos.y = center.y
pos.y = origin.y
if z is not None:
pos.z = center.z
pos.z = origin.z
elif gcode == "G90": # Absolute position
relativeMode = False
if g90_extruder: