🚧 Implement temperature offset feature
This commit is contained in:
1 parent
70540ff51b
commit
c4978db302
5 files changed
+100
-63
No files matched your search
@@ -352,6 +352,7 @@ class ProtocolAlreadyConnectedError(Exception):
|
||||
class ProtocolNotConnectedError(Exception):
|
||||
pass
|
||||
|
||||
|
||||
class ThreeAxisProtocolMixin(object):
|
||||
def move(self, x=None, y=None, z=None, feedrate=None, relative=False, *args, **kwargs):
|
||||
pass
|
||||
@@ -359,31 +360,33 @@ class ThreeAxisProtocolMixin(object):
|
||||
def home(self, x=False, y=False, z=False, *args, **kwargs):
|
||||
pass
|
||||
|
||||
def set_feedrate_multiplier(self, multiplier, *args, **kwargs):
|
||||
pass
|
||||
|
||||
|
||||
class HeaterProtocolMixin(object):
|
||||
def set_temperature(self, heater, temperature, wait=False, *args, **kwargs):
|
||||
pass
|
||||
|
||||
def set_temperature_offset(self, heater, offset, *args, **kwargs):
|
||||
pass
|
||||
|
||||
def get_temperature_offsets(self):
|
||||
return dict()
|
||||
|
||||
|
||||
class MultiToolProtocolMixin(object):
|
||||
def change_tool(self, tool, *args, **kwargs):
|
||||
pass
|
||||
|
||||
|
||||
class ThreeDPrinterProtocolMixin(ThreeAxisProtocolMixin, MultiToolProtocolMixin):
|
||||
class Fdm3dPrinterProtocolMixin(ThreeAxisProtocolMixin, HeaterProtocolMixin, MultiToolProtocolMixin):
|
||||
def move(self, x=None, y=None, z=None, e=None, feedrate=None, relative=False, *args, **kwargs):
|
||||
pass
|
||||
|
||||
def set_feedrate_multiplier(self, multiplier, *args, **kwargs):
|
||||
pass
|
||||
|
||||
def set_extrusion_multiplier(self, multiplier, *args, **kwargs):
|
||||
pass
|
||||
|
||||
def set_extruder_temperature(self, temperature, tool=None, wait=False, *args, **kwargs):
|
||||
pass
|
||||
|
||||
def set_bed_temperature(self, temperature, wait=False, *args, **kwargs):
|
||||
pass
|
||||
|
||||
def set_chamber_temperature(self, temperature, wait=False, *args, **kwargs):
|
||||
pass
|
||||
|
||||
|
||||
class FanControlProtocolMixin(object):
|
||||
def set_fan_speed(self, speed, *args, **kwargs):
|
||||
|
||||
@@ -4,7 +4,7 @@ from __future__ import absolute_import, division, print_function, unicode_litera
|
||||
__license__ = 'GNU Affero General Public License http://www.gnu.org/licenses/agpl.html'
|
||||
__copyright__ = "Copyright (C) 2018 The OctoPrint Project - Released under terms of the AGPLv3 License"
|
||||
|
||||
from octoprint.comm.protocol import Protocol, ThreeDPrinterProtocolMixin, FileStreamingProtocolMixin, \
|
||||
from octoprint.comm.protocol import Protocol, Fdm3dPrinterProtocolMixin, FileStreamingProtocolMixin, \
|
||||
MotorControlProtocolMixin, FanControlProtocolMixin, ProtocolState
|
||||
from octoprint.comm.transport import Transport, LineAwareTransportWrapper, \
|
||||
PushingTransportWrapper, PushingTransportWrapperListener, TransportListener, TimeoutTransportException, \
|
||||
@@ -114,7 +114,7 @@ class BooleanCallbackValue(object):
|
||||
return bool(self.callback())
|
||||
|
||||
|
||||
class ReprapGcodeProtocol(Protocol, ThreeDPrinterProtocolMixin, MotorControlProtocolMixin,
|
||||
class ReprapGcodeProtocol(Protocol, Fdm3dPrinterProtocolMixin, MotorControlProtocolMixin,
|
||||
FanControlProtocolMixin, FileStreamingProtocolMixin,
|
||||
PushingTransportWrapperListener, TransportListener):
|
||||
name = "Reprap GCODE Protocol"
|
||||
@@ -403,6 +403,7 @@ class ReprapGcodeProtocol(Protocol, ThreeDPrinterProtocolMixin, MotorControlProt
|
||||
heating_lost=0,
|
||||
heating=False,
|
||||
temperature_autoreporting=False,
|
||||
temperature_offsets=dict(),
|
||||
|
||||
# current stuff
|
||||
current_tool=0,
|
||||
@@ -779,23 +780,31 @@ class ReprapGcodeProtocol(Protocol, ThreeDPrinterProtocolMixin, MotorControlProt
|
||||
tags=tags,
|
||||
**kwargs)
|
||||
|
||||
def set_extruder_temperature(self, temperature, tool=None, wait=False, *args, **kwargs):
|
||||
tags = kwargs.get("tags", set()) | {"trigger:protocol.set_extruder_temperature"}
|
||||
self.send_commands(self.flavor.command_set_extruder_temp(temperature, tool=tool, wait=wait),
|
||||
tags=tags,
|
||||
**kwargs)
|
||||
def set_temperature(self, heater, temperature, wait=False, *args, **kwargs):
|
||||
tags = kwargs.get("tags", set()) | {"trigger:protocol.set_temperature"}
|
||||
|
||||
def set_bed_temperature(self, temperature, wait=False, *args, **kwargs):
|
||||
tags = kwargs.get("tags", set()) | {"trigger:protocol.set_bed_temperature"}
|
||||
self.send_commands(self.flavor.command_set_bed_temp(temperature, wait=wait),
|
||||
tags=tags,
|
||||
**kwargs)
|
||||
if heater.startswith("tool"):
|
||||
try:
|
||||
tool = int(heater[len("tool"):])
|
||||
except ValueError:
|
||||
self._logger.error("Got invalid tool heater, expected tool<n>, got: {}".format(heater))
|
||||
return
|
||||
command = self.flavor.command_set_extruder_temp(temperature, tool=tool, wait=wait)
|
||||
elif heater == "bed":
|
||||
command = self.flavor.command_set_bed_temp(temperature, wait=wait)
|
||||
elif heater == "chamber":
|
||||
command = self.flavor.command_set_chamber_temp(temperature, wait=wait)
|
||||
else:
|
||||
self._logger.warn("Got unknown heater identifier to set temperature on: {}".format(heater))
|
||||
return
|
||||
|
||||
def set_chamber_temperature(self, temperature, wait=False, *args, **kwargs):
|
||||
tags = kwargs.get("tags", set()) | {"trigger:protocol.set_chamber_temperature"}
|
||||
self.send_commands(self.flavor.command_set_bed_temp(temperature, wait=wait),
|
||||
tags=tags,
|
||||
**kwargs)
|
||||
self.send_commands(command, tags=tags, **kwargs)
|
||||
|
||||
def set_temperature_offset(self, heater, offset, *args, **kwargs):
|
||||
self._internal_flags["temperature_offsets"][heater] = offset
|
||||
|
||||
def get_temperature_offsets(self):
|
||||
return copy.copy(self._internal_flags["temperature_offsets"])
|
||||
|
||||
##~~ MotorControlProtocolMixin
|
||||
|
||||
@@ -2431,6 +2440,42 @@ class ReprapGcodeProtocol(Protocol, ThreeDPrinterProtocolMixin, MotorControlProt
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
def _apply_temperature_offset(self, heater, command, support_r=False):
|
||||
offset = self._internal_flags["temperature_offsets"].get(heater, 0)
|
||||
if offset == 0 or not "source:file" in command.tags:
|
||||
return
|
||||
|
||||
try:
|
||||
if command.s is not None:
|
||||
return command.with_args(s=float(command.s) + offset)
|
||||
elif command.r is not None and support_r:
|
||||
return command.with_args(r=float(command.r) + offset)
|
||||
except Exception:
|
||||
self._logger.exception("Error applying temperature offset")
|
||||
|
||||
def _gcode_M104_sending(self, command, support_r=False):
|
||||
if command.t:
|
||||
tool_num = command.t
|
||||
else:
|
||||
tool_num = self._internal_flags["current_tool"]
|
||||
|
||||
return self._apply_temperature_offset("tool{}".format(tool_num), command, support_r=support_r)
|
||||
|
||||
def _gcode_M109_sending(self, command):
|
||||
return self._gcode_M104_sending(command, support_r=True)
|
||||
|
||||
def _gcode_M140_sending(self, command):
|
||||
return self._apply_temperature_offset("bed", command, support_r=False)
|
||||
|
||||
def _gcode_M190_sending(self, command):
|
||||
return self._apply_temperature_offset("bed", command, support_r=True)
|
||||
|
||||
def _gcode_M141_sending(self, command):
|
||||
return self._apply_temperature_offset("chamber", command, support_r=False)
|
||||
|
||||
def _gcode_M191_sending(self, command):
|
||||
return self._apply_temperature_offset("chamber", command, support_r=True)
|
||||
|
||||
def _gcode_M104_sent(self, command, wait=False, support_r=False):
|
||||
tool_num = self._internal_flags["current_tool"]
|
||||
if command.t:
|
||||
|
||||
@@ -105,6 +105,19 @@ class GcodeCommand(Command):
|
||||
|
||||
self._repr = self._to_repr()
|
||||
|
||||
def with_args(self, **kwargs):
|
||||
args = dict(subcode=self.subcode,
|
||||
tool=self.tool,
|
||||
feedrate=self.feedrate,
|
||||
param=self.param,
|
||||
type=self.type,
|
||||
tags=self.tags)
|
||||
args.update(self.args)
|
||||
|
||||
args.update(kwargs)
|
||||
|
||||
return GcodeCommand(self.code, **args)
|
||||
|
||||
def __getattr__(self, item):
|
||||
if len(item) == 1:
|
||||
return self.args.get(item, None)
|
||||
|
||||
@@ -328,7 +328,7 @@ class TemperatureRecord(object):
|
||||
self._bed = self._to_new_tuple(current, actual, target)
|
||||
|
||||
def set_chamber(self, actual=None, target=None):
|
||||
current = self._chamber()
|
||||
current = self._chamber
|
||||
self._chamber = self._to_new_tuple(current, actual, target)
|
||||
|
||||
@property
|
||||
|
||||
@@ -541,26 +541,7 @@ class Printer(PrinterInterface,
|
||||
raise ValueError("value must be a valid number >= 0: {value}".format(value=value))
|
||||
|
||||
tags = kwargs.get("tags", set()) | {"trigger:printer.set_temperature"}
|
||||
|
||||
if heater.startswith("tool"):
|
||||
printer_profile = self._printer_profile_manager.get_current_or_default()
|
||||
extruder_count = printer_profile["extruder"]["count"]
|
||||
shared_nozzle = printer_profile["extruder"]["sharedNozzle"]
|
||||
if extruder_count > 1 and not shared_nozzle:
|
||||
toolNum = int(heater[len("tool"):])
|
||||
self._protocol.set_extruder_temperature(value,
|
||||
tool=toolNum,
|
||||
wait=False,
|
||||
tags=tags)
|
||||
else:
|
||||
self._protocol.set_extruder_temperature(value,
|
||||
wait=False,
|
||||
tags=tags)
|
||||
|
||||
elif heater == "bed":
|
||||
self._protocol.set_bed_temperature(value,
|
||||
wait=False,
|
||||
tags=tags)
|
||||
self._protocol.set_temperature(heater, value, wait=False, tags=tags)
|
||||
|
||||
def set_temperature_offset(self, offsets=None, *args, **kwargs):
|
||||
if offsets is None:
|
||||
@@ -580,9 +561,9 @@ class Printer(PrinterInterface,
|
||||
if self._protocol is None:
|
||||
return
|
||||
|
||||
# TODO
|
||||
#self._comm.setTemperatureOffset(offsets)
|
||||
#self._setOffsets(self._comm.getOffsets())
|
||||
for heater, offset in offsets.items():
|
||||
self._protocol.set_temperature_offset(heater, offset)
|
||||
self._set_offsets(self._protocol.get_temperature_offsets())
|
||||
|
||||
def _convert_rate_value(self, factor, min=0, max=200):
|
||||
if not isinstance(factor, (int, float, long)):
|
||||
@@ -770,12 +751,10 @@ class Printer(PrinterInterface,
|
||||
return util.thaw_frozendict(data["job"])
|
||||
|
||||
def get_current_temperatures(self, *args, **kwargs):
|
||||
# TODO temperature offsets
|
||||
#if self._comm is not None:
|
||||
# offsets = self._comm.getOffsets()
|
||||
#else:
|
||||
# offsets = dict()
|
||||
offsets = dict()
|
||||
if self._protocol is not None:
|
||||
offsets = self._protocol.get_temperature_offsets()
|
||||
else:
|
||||
offsets = dict()
|
||||
|
||||
result = dict()
|
||||
if not len(self._temperature_history):
|
||||
@@ -783,9 +762,6 @@ class Printer(PrinterInterface,
|
||||
|
||||
latest_temperature = self._temperature_history[-1]
|
||||
for key, value in latest_temperature.items():
|
||||
if not key.startswith("tool") and not key == "bed":
|
||||
continue
|
||||
|
||||
result[key] = dict(actual=value["actual"],
|
||||
target=value["target"],
|
||||
offset=offsets.get(key, 0))
|
||||
|
||||
Reference in new issue
Block a user