diff --git a/AUTHORS.md b/AUTHORS.md index 483e6b722..09e51f9cf 100644 --- a/AUTHORS.md +++ b/AUTHORS.md @@ -91,6 +91,7 @@ date of first contribution): * [Ganey](https://github.com/ganey) * [Sven Lohrmann](https://github.com/malnvenshorn) * [Andy Castille](https://github.com/klikini) + * [Gaston Dombiak](https://github.com/gdombiak) OctoPrint started off as a fork of [Cura](https://github.com/daid/Cura) by [Daid Braam](https://github.com/daid). Parts of its communication layer and diff --git a/docs/api/printer.rst b/docs/api/printer.rst index 98f4ccbff..6ba04077e 100644 --- a/docs/api/printer.rst +++ b/docs/api/printer.rst @@ -362,6 +362,8 @@ Issue a tool command Extrudes the given amount of filament from the currently selected tool. Additional parameters: * ``amount``: The amount of filament to extrude in mm. May be negative to retract. + * ``speed``: Optional. Speed at which to extrude. If not provided, maximum speed for E axis from printer + profile will be used. Otherwise interpreted as an integer signifying the speed in mm/s, to append to the command. flowrate Changes the flow rate factor to apply to extrusion of the tool. diff --git a/src/octoprint/printer/__init__.py b/src/octoprint/printer/__init__.py index 67150b1b1..4ae7222e9 100644 --- a/src/octoprint/printer/__init__.py +++ b/src/octoprint/printer/__init__.py @@ -231,12 +231,14 @@ class PrinterInterface(object): """ raise NotImplementedError() - def extrude(self, amount, tags=None, *args, **kwargs): + def extrude(self, amount, speed=None, tags=None, *args, **kwargs): """ Extrude ``amount`` millimeters of material from the tool. Arguments: amount (int, float): The amount of material to extrude in mm + speed (int, None): Speed at which to extrude (F parameter). If set to ``None`` (or left out) + the maximum speed of E axis from the printer profile will be used. tags (set of str): An optional set of tags to attach to the command(s) throughout their lifecycle """ raise NotImplementedError() diff --git a/src/octoprint/printer/standard.py b/src/octoprint/printer/standard.py index 989b6095e..044e32cbc 100644 --- a/src/octoprint/printer/standard.py +++ b/src/octoprint/printer/standard.py @@ -361,12 +361,19 @@ class Printer(PrinterInterface, comm.MachineComPrintCallback): self.commands(["G91", "G28 %s" % " ".join(map(lambda x: "%s0" % x.upper(), validated_axes)), "G90"], tags=kwargs.get("tags", set) | {"trigger:printer.home"}) - def extrude(self, amount, *args, **kwargs): + def extrude(self, amount, speed=None, *args, **kwargs): if not isinstance(amount, (int, long, float)): raise ValueError("amount must be a valid number: {amount}".format(amount=amount)) printer_profile = self._printerProfileManager.get_current_or_default() - extrusion_speed = printer_profile["axes"]["e"]["speed"] + + # Use specified speed (if any) + extrusion_speed = speed + + if speed is None: + # No speed was specified so default to value configured in printer profile + extrusion_speed = printer_profile["axes"]["e"]["speed"] + self.commands(["G91", "G1 E%s F%d" % (amount, extrusion_speed), "G90"], tags=kwargs.get("tags", set()) | {"trigger:printer.extrude"}) diff --git a/src/octoprint/server/api/printer.py b/src/octoprint/server/api/printer.py index 0452e9e03..561efcfde 100644 --- a/src/octoprint/server/api/printer.py +++ b/src/octoprint/server/api/printer.py @@ -129,9 +129,10 @@ def printerToolCommand(): return make_response("Printer is currently printing", 409) amount = data["amount"] + speed = data.get("speed", None) if not isinstance(amount, (int, long, float)): return make_response("Not a number for extrusion amount: %r" % amount, 400) - printer.extrude(amount, tags=tags) + printer.extrude(amount, speed=speed, tags=tags) elif command == "flowrate": factor = data["factor"]