From 3ddfc93c1bc3756825a91fcd124118c4fc3732c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Sun, 24 Nov 2013 13:12:02 +0100 Subject: [PATCH] Use G28 for homing (G1 was a copy-paste-error) Fixes #314 (cherry picked from commit 5b8126a) --- src/octoprint/server/ajax/control.py | 32 ++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/octoprint/server/ajax/control.py b/src/octoprint/server/ajax/control.py index efc7e99e..2b38835f 100644 --- a/src/octoprint/server/ajax/control.py +++ b/src/octoprint/server/ajax/control.py @@ -145,6 +145,38 @@ def jog(): length = request.values["extrude"] printer.commands(["G91", "G1 E%s F%d" % (length, movementSpeedE), "G90"]) + movementSpeed = settings().get(["printerParameters", "movementSpeed", ["x", "y", "z"]], asdict=True) + + valid_axes = ["x", "y", "z"] + ##~~ jog command + if command == "jog": + # validate all jog instructions, make sure that the values are numbers + validated_values = {} + for axis in valid_axes: + if axis in data: + value = data[axis] + if not isinstance(value, (int, long, float)): + return make_response("Not a number for axis %s: %r" % (axis, value), 400) + validated_values[axis] = value + + # execute the jog commands + for axis, value in validated_values.iteritems(): + # TODO make this a generic method call (printer.jog(axis, value)) to get rid of gcode here + printer.commands(["G91", "G1 %s%.4f F%d" % (axis.upper(), value, movementSpeed[axis]), "G90"]) + + ##~~ home command + elif command == "home": + validated_values = [] + axes = data["axes"] + for axis in axes: + if not axis in valid_axes: + return make_response("Invalid axis: %s" % axis, 400) + validated_values.append(axis) + + # execute the home command + # TODO make this a generic method call (printer.home(axis, ...)) to get rid of gcode here + printer.commands(["G91", "G28 %s" % " ".join(map(lambda x: "%s0" % x.upper(), validated_values)), "G90"]) + return jsonify(SUCCESS)