TryToSeparate controller

This commit is contained in:
sergiuToporjinschi
2022-02-01 16:16:09 +02:00
parent 1b212b00ba
commit 57b0c068eb
8 changed files with 207 additions and 22 deletions
+87
View File
@@ -0,0 +1,87 @@
from threading import Event
CMD_ESP_TEST = "TEST"
CMD_ESP_LOAD_STEPS = "eSteps_load"
CMD_ESP_START_EXTRUSION = "eSteps_startExtrusion"
CMD_ESP_SAVE = "eSteps_save"
class API(octoprint.plugin.SimpleApiPlugin):
@staticmethod
def apiCommands():
return {
CMD_ESP_SAVE: [],
CMD_ESP_LOAD_STEPS: [],
CMD_ESP_START_EXTRUSION: []
}
def apiGateWay(self, command, data):
self._logger.debug("api command [%s] received payload [%s]", command, data)
if command == CMD_ESP_LOAD_STEPS:
self._logger.debug("Load steps from EEPROM")
if not self._printer.is_ready():
self._logger.warning("Printer not ready, operation canceled")
return flask.abort(503, {
"msg": "Printer not ready, operation canceled"
})
# Register listener waiting response for M92 command
m92Event = Event()
self.registerGCodeWaiter("M92", self.m92GCodeResponse, m92Event)
# Issue M92 command
self._printer.commands("M92")
m92Event.wait()
return flask.jsonify({
"data": self.data["steps"]
})
if command == CMD_ESP_START_EXTRUSION:
self._logger.debug("Heating the extruder [%s]", data)
if not self._printer.is_ready():
self._logger.warning("Printer not ready, operation canceled")
return flask.abort(503, {
"msg": "Printer not ready, operation canceled"
})
# Register event to be trigger when temp is achieved
self.registerEventTemp("T0", int(data["extrudeTemp"]), self.startExtrusion, data["extrudeLength"], data["extrudeSpeed"])
# Heating the tool
self._printer.commands("M104 S%(extrudeTemp)s" % data)
return
if command == CMD_ESP_SAVE:
eStepsSettings = self._settings.get(['eSteps'])
userControlsTemp = eStepsSettings.get("userControlsTemp")
turnOffHotend = eStepsSettings.get("turnOffHotend")
self._printer.commands(["M92 E%(newESteps)s" % data, "M500"] + ["M104 S0"] if turnOffHotend and not userControlsTemp else [])
return
############## HANDLERS ##############
@staticmethod
def startExtrusion(self, temps, extrudeLength, extrudeSpeed, *args):
self._logger.debug("Temperature achieved, extrusion started [temps:%s, extrudeLength:%s, extrudeSpeed:%s, args:%s]",
temps, extrudeLength, extrudeSpeed, args)
# Extrude
self._printer.extrude(amount=int(extrudeLength), speed=int(extrudeSpeed))
@staticmethod
def m92GCodeResponse(self, line, event):
reg = re.compile("echo:\s*(?P<command>(?P<gCode>M\d{1,3}) X(?P<xVal>\d{1,3}.\d{1,3}) Y(?P<yVal>\d{1,3}.\d{1,3}) Z(?P<zVal>\d{1,3}.\d{1,3}) E(?P<eVal>\d{1,3}.\d{1,3}))")
isM92command = reg.match(line)
if isM92command:
command = isM92command.group("command")
if isM92command.group("gCode") == "M92":
self.data["steps"]["X"] = float(isM92command.group("xVal"))
self.data["steps"]["Y"] = float(isM92command.group("yVal"))
self.data["steps"]["Z"] = float(isM92command.group("zVal"))
self.data["steps"]["E"] = float(isM92command.group("eVal"))
# Send the new data to the UI to be reloaded
self._logger.debug("gCode: %s", command)
self._logger.debug("X: %s, Y:%s, Z:%s, E:%s", self.data["steps"]["X"], self.data["steps"]["Y"], self.data["steps"]["Z"], self.data["steps"]["E"])
self._logger.debug("Finished data collection")
self.collectCommand = False
if event:
event.set()
+1 -1
View File
@@ -7,7 +7,7 @@ from octoprint_CalibrationTools import api, hooks, models
defaultSettings = { defaultSettings = {
"eSteps": { "eSteps": {
"userControlsTemp": "checked", "userControlsTemp": "true",
"turnOffHotend": "", "turnOffHotend": "",
"extrudeTemp": 210, "extrudeTemp": 210,
"extrudeLength": 100, "extrudeLength": 100,
@@ -130,6 +130,6 @@ $(function () {
// instantiation via the parameters argument // instantiation via the parameters argument
dependencies: ["loginStateViewModel", "settingsViewModel", "controlViewModel", "terminalViewModel", "accessViewModel"], dependencies: ["loginStateViewModel", "settingsViewModel", "controlViewModel", "terminalViewModel", "accessViewModel"],
// Finally, this is the list of selectors for all elements we want this view model to be bound to. // Finally, this is the list of selectors for all elements we want this view model to be bound to.
elements: ["#tab_plugin_CalibrationTools"] elements: ["#calibration_eSteps"]
}); });
}); });
@@ -0,0 +1,23 @@
$(function () {
function CalibrationToolsPIDTuneViewModel(parameters) {
var self = this;
self.bedCurrentTemp = ko.observable(0);
self.bedCurrentTarget = ko.observable(0);
OctoPrint.printer.getBedState().done(function (bedState) {
self.bedCurrentTemp(bedState.bed.actual);
self.bedCurrentTarget(bedState.bed.target);
});
}
OCTOPRINT_VIEWMODELS.push({
// This is the constructor to call for instantiating the plugin
construct: CalibrationToolsPIDTuneViewModel,
// This is a list of dependencies to inject into the plugin, the order which you request
// here is the order in which the dependencies will be injected into your view model upon
// instantiation via the parameters argument
dependencies: ["loginStateViewModel", "settingsViewModel", "controlViewModel", "terminalViewModel", "accessViewModel"],
// Finally, this is the list of selectors for all elements we want this view model to be bound to.
elements: ["#calibration_pid"]
});
});
@@ -10,8 +10,7 @@
<button class="btn" data-bind="click: $root.tempRestart, visible: true"> <button class="btn" data-bind="click: $root.tempRestart, visible: true">
RESTART RESTART
</button> </button>
<button class="btn btn-primary" data-bind="click: $root.test, visible: true" <button class="btn btn-primary" data-bind="click: $root.test, visible: true" title="BTN for testing">
title="BTN for testing">
<i class="fas fa-save" data-color="#000000"></i>&nbsp&nbsp <i class="fas fa-save" data-color="#000000"></i>&nbsp&nbsp
TEST TEST
</button> </button>
@@ -37,7 +36,7 @@
<a data-toggle="tab" href="#calibration_x-y-z">X-Y-Z-Steps</a> <a data-toggle="tab" href="#calibration_x-y-z">X-Y-Z-Steps</a>
</li> </li>
<li> <li>
<a data-toggle="tab" href="#calibration_pid">PID</a> <a data-toggle="tab" href="#calibration_pid">PID Autotune</a>
</li> </li>
</ul> </ul>
</div> </div>
@@ -18,8 +18,10 @@
</blockquote> </blockquote>
{% endmacro %} {% endmacro %}
{% macro field(label, title, type, binding, enable, unit, step) %} {% macro field(label, title, type, binding, enable, unit, step, min, max) %}
{% set step = step|default('0.01') %} {% set step = step|default('0.01') %}
{% set min = min|default("") %}
{% set max = max|default("") %}
<div class="row-fluid"> <div class="row-fluid">
<div class="span6"> <div class="span6">
<label for="{{ label }}" class="pull-right" style="margin-top: 5px;" title="{{ title }}"> <label for="{{ label }}" class="pull-right" style="margin-top: 5px;" title="{{ title }}">
@@ -28,7 +30,28 @@
</div> </div>
<div class="span6"> <div class="span6">
<div class="input-append"> <div class="input-append">
<input type="{{ type }}" id="{{ label }}" title="{{ title }}" class="input-small" step="{{ step }}" data-bind="value: {{ binding }}, enable: {{ enable }}"> <input type="{{ type }}" id="{{ label }}" title="{{ title }}" class="input-small" step="{{ step }}" min="{{ min }}" max="{{ max }}" data-bind="value: {{ binding }}, enable: {{ enable }}">
<span class="add-on" title="{{ title }}">{{ _(unit) }}</span>
</div>
</div>
</div>
{% endmacro %}
{% macro labelField(label, title, type, binding, enable, unit, step, min, max) %}
{% set step = step|default('0.01') %}
{% set min = min|default("") %}
{% set max = max|default("") %}
<div class="row-fluid">
<div class="span6">
<label for="{{ label }}" class="pull-right" style="margin-top: 5px;" title="{{ title }}">
{{ _(label) }}
</label>
</div>
<div class="span6">
<div class="input-append input-prepend">
<span class="add-on" title="{{ title }}">{{ _(label) }}</span>
<input type="{{ type }}" id="{{ label }}" title="{{ title }}" class="input-small" step="{{ step }}" min="{{ min }}" max="{{ max }}" data-bind="value: {{ binding }}, enable: {{ enable }}">
<span class="add-on" title="{{ title }}">{{ _(unit) }}</span> <span class="add-on" title="{{ title }}">{{ _(unit) }}</span>
</div> </div>
</div> </div>
@@ -12,12 +12,11 @@
<div class="span6"> <div class="span6">
<div class="input-prepend input-append"> <div class="input-prepend input-append">
<span class="add-on" title="Command to preheat the tool before testing">M104&nbsp;&nbsp;&nbsp;S</span> <span class="add-on" title="Command to preheat the tool before testing">M104&nbsp;&nbsp;&nbsp;S</span>
<input type="number" id="temperature" title="The temperature used to extrude in testing (&#186;C)&#013;Is better to be a bit higher then usual for reducing the nuzzle pressure" class="input-mini" step="1" <input type="number" id="temperature" class="input-mini" step="1" min="0" max="280"
data-bind="value: $root.testParam.extrudeTemp"> title="The temperature used to extrude in testing (&#186;C)&#013;Is better to be a bit higher then usual for reducing the nuzzle pressure" data-bind="value: $root.testParam.extrudeTemp">
</div> </div>
</div> </div>
</div> </div>
<!-- G1 E100 F50 command --> <!-- G1 E100 F50 command -->
<div class="row-fluid"> <div class="row-fluid">
<div class="span6"> <div class="span6">
@@ -28,16 +27,15 @@
<div class="span6"> <div class="span6">
<div class="input-prepend input-append"> <div class="input-prepend input-append">
<span class="add-on" title="Command to extrude filament for testing">G1&nbsp;&nbsp;&nbsp;E</span> <span class="add-on" title="Command to extrude filament for testing">G1&nbsp;&nbsp;&nbsp;E</span>
<input type="number" id="extrusionLenSpeed" title="The length of filament to be extruded in testing (in millimeters)" class="input-mini" step="1" <input type="number" id="extrusionLenSpeed" class="input-mini" step="1" min="50" title="The length of filament to be extruded in testing (in millimeters)" data-bind="value: $root.testParam.extrudeLength">
data-bind="value: $root.testParam.extrudeLength">
<span class="add-on" title="Command to extrude filament for testing">&nbsp;&nbsp;&nbsp;F</span> <span class="add-on" title="Command to extrude filament for testing">&nbsp;&nbsp;&nbsp;F</span>
<input type="number" id="extrusionLenSpeed" title="The speed to extrude filament in testing&#013;Lowest possible (mm/s)" class="input-mini" step="1" <input type="number" id="extrusionLenSpeed" class="input-mini" step="1" min="10" max="400" title="The speed to extrude filament in testing&#013;Lowest possible (mm/s)"
data-bind="value: $root.testParam.extrudeSpeed"> data-bind="value: $root.testParam.extrudeSpeed">
</div> </div>
</div> </div>
</div> </div>
{{ snipped.field("Extrusion marking length", "The length marked on filament before extrusion. ", "number", "$root.testParam.markLength", "true", "mm") }} {{ snipped.field("Extrusion marking length", "The length marked on filament before extrusion. ", "number", "$root.testParam.markLength", "true", "mm", 0.01, 50) }}
<div class="row-fluid" style="margin-bottom: 5px;"> <div class="row-fluid" style="margin-bottom: 5px;">
<div class="span6"></div> <div class="span6"></div>
@@ -60,8 +58,7 @@
</div> </div>
<div class="span6"> <div class="span6">
<div class="input-append"> <div class="input-append">
<input type="number" id="eSteps" title="Current value for number of steps/mm for E axe in EEPROM" class="input-small" step="0.01" <input type="number" id="eSteps" title="Current value for number of steps/mm for E axe in EEPROM" class="input-small" step="0.01" data-bind="value: $root.steps.E, enable:false">
data-bind="value: $root.steps.E, enable:false">
<span class="add-on" title="Current value for number of steps/mm for E axe in EEPROM">steps/mm</span> <span class="add-on" title="Current value for number of steps/mm for E axe in EEPROM">steps/mm</span>
<button class="btn" data-bind="click: $root.loadESteps, enable: $root.controlViewModel.isOperational() && (!$root.controlViewModel.isPrinting())" <button class="btn" data-bind="click: $root.loadESteps, enable: $root.controlViewModel.isOperational() && (!$root.controlViewModel.isPrinting())"
title="Loads current value of steps/mm from EEPROM by calling M92"> title="Loads current value of steps/mm from EEPROM by calling M92">
@@ -1 +1,57 @@
Something in pid tab... {% import "macros.jinja2" as snipped %}
Current bed temperature: <span data-bind="text: bedCurrentTemp"></span>&#176; Bed target temperature <span data-bind="text: $root.bedCurrentTarget"></span>&#176;
{{ snipped.subSection("Tool tuning", true) }}
<div class="row-fluid">
<div class="span6">
<label for="fanSpeed" class="pull-right" style="margin-top: 5px;" title="x">
Turn fan to max
</label>
</div>
<div class="span6">
<div class="input-prepend input-append">
<span class="add-on" title="Command for turning the fan to 100%">M106&nbsp;&nbsp;&nbsp;S</span>
<input type="number" id="fanSpeed" title="Command for turning the fan to 100%" class="input-mini" step="1" min="0" max="255" data-bind="value: $root.pid.fanSpeed">
</div>
</div>
</div>
<div class="row-fluid">
<div class="span6">
<label for="tunningPIDTool" class="pull-right" style="margin-top: 5px;" title="x">
Tuning PID
</label>
</div>
<div class="span6">
<div class="input-prepend input-append">
<span class="add-on" title="Command for triggering tool PID tunning">M303&nbsp;&nbsp;&nbsp;E</span>
<input type="number" id="tunningPIDTool" class="input-mini" step="1" min="0" title="Tool number 0 for first hot end" data-bind="value: $root.pid.hotendNo">
<span class="add-on" title="">S</span>
<input type="number" id="tunningPIDToolTemp" class="input-mini" step="1" min="100" max="280" title="Temperature for tunning" data-bind="value: $root.pid.tunningTemp">
<span class="add-on" title="">U1</span>
</div>
</div>
</div>
<div class="row-fluid" style="margin-bottom: 5px;">
<div class="span6"></div>
<div class="span6">
<button class="btn btn-success" data-bind="click: $root.pidHotEndTune, enable: $root.controlViewModel.isOperational() && (!$root.controlViewModel.isPrinting())"
title="This will trigger PID auto tuning (M106 Sx; M303 Ex Sx U1; M501)">
<i class="fas fa-play" style="color:false" data-color="false"></i>&nbsp&nbsp
Start PID tunning
</button>
</div>
</div>
Save M501
{{ snipped.subSection("Heated bed tuning", true) }}
{{ snipped.subSection("Note", true) }}
{{ snipped.quote("It is recommended to run the tuning with conditions as close to printing as possible. This means filament loaded and the part cooling fan set to your normal speed. It is not essential, but you may
prefer to start this process with the hot end at room temperature.",
"<a href='https://teachingtechyt.github.io/calibration.html#pid' target='_blank'>teachingtechyt.github.io</a>", "text-warning") }}