diff --git a/octoprint_CalibrationTools/PIDAutoTune.py b/octoprint_CalibrationTools/PIDAutoTune.py index 2de9b14..ca9726a 100644 --- a/octoprint_CalibrationTools/PIDAutoTune.py +++ b/octoprint_CalibrationTools/PIDAutoTune.py @@ -9,6 +9,8 @@ import octoprint.plugin CMD_PID_SAVE = "pid_save" CMD_PID_START = "pid_start" +CMD_PID_LOAD_CURRENT_VALUES = "pid_getCurrentValues" +CMD_PID_GET_VALUES = "pid_getValues" regexPID = "Kp:\s*(?P

\d{1,3}.\d{1,3})\s*Ki:\s*(?P\d{1,3}.\d{1,3})\s*Kd:\s*(?P\d{1,3}.\d{1,3})" regexGetPid = "\s*Kp:\s*(?P

\d{1,3}.\d{1,3})\s*Ki:\s*(?P\d{1,3}.\d{1,3})\s*Kd:\s*(?P\d{1,3}.\d{1,3})" @@ -19,40 +21,72 @@ PIDStopedI = "#define DEFAULT_Ki\s*(?P\d{1,3}.\d{1,3})" PIDStopedD = "#define DEFAULT_Kd\s*(?P\d{1,3}.\d{1,3})" regexFinished = "PID Autotune finished!.*\n#define DEFAULT_Kp\s*(?P

\d{1,3}.\d{1,3}).*\n#define DEFAULT_Ki\s*(?P\d{1,3}.\d{1,3})\n#define DEFAULT_Kd\s*(?P\d{1,3}.\d{1,3})" class API(octoprint.plugin.SimpleApiPlugin): - + pidHotEndCycles = [] + pidCurrentValues = {} @staticmethod def apiCommands(): return { + CMD_PID_LOAD_CURRENT_VALUES: [], CMD_PID_SAVE : [], + CMD_PID_GET_VALUES: [], CMD_PID_START: ["fanSpeed", "noCycles", "hotEndIndex", "targetTemp"] } def apiGateWay(self, command, data): self._logger.debug("DIPGateway") - if command == CMD_PID_START: - self.pidCycles = [] + if command == CMD_PID_LOAD_CURRENT_VALUES: + #catch for "echo: p:28.27 i:2.82 d:70.81" or "M301 P27.08 I2.51 D73.09" - for i in range(0,data['noCycles']): + getPid = re.compile(r".*p:??(?P

\d{1,3}.\d{1,3})\s*i:?(?P\d{1,3}.\d{1,3})\s*d:?(?P\d{1,3}.\d{1,3})", flags=re.IGNORECASE) + + hasResult301 = Event() + hasResult304 = Event() + self.registerRegexMsg(getPid, self.m301_m304CodeResponse, hasResult301, "hotEnd") + self.registerRegexMsg(getPid, self.m301_m304CodeResponse, hasResult304, "bed") + + self._printer.commands(["M301", "M304"]) + hasResult301.wait(5) + hasResult304.wait(5) + + return flask.jsonify({ + "data": self.pidCurrentValues + }) + + if command == CMD_PID_START: + self.pidHotEndCycles = [] + + #Two cycles are for tuning + for i in range(0, data['noCycles'] - 2): self.registerRegexMsg(regexGetPid, self.m106CodeResponse) self._printer.commands(["M106 S%(fanSpeed)s" % data, "M303 C%(noCycles)s E%(hotEndIndex)s S%(targetTemp)s U1" % data]) - self._logger.debug("cycles %s", self.pidCycles) + self._logger.debug("cycles %s", self.pidHotEndCycles) if command == CMD_PID_SAVE: self._logger.debug("DIPSave-") return flask.jsonify({ "data": self.pidCycles }) + if command == CMD_PID_GET_VALUES: + self._logger.debug("pid_getValues-") + return flask.jsonify({ + "data": self.pidCycles + }) + + @staticmethod + def m301_m304CodeResponse(self, line, regex, event, storingKey): + self._logger.debug("m301_m304CodeResponse: %s", line) + match = regex.match(line) + if match: + self.pidCurrentValues[storingKey] = { + "P": match.group("p"), + "I": match.group("i"), + "D": match.group("d") + } + if event: + event.set() @staticmethod def m106CodeResponse(self, line): self._logger.debug("m106CodeResponse: %s", line) - # isM106Response = re.compile(regexFinished).match(line) - # if isM106Response: - # p = isM106Response.group("P") - # i = isM106Response.group("I") - # d = isM106Response.group("D") - # self._logger.debug("P:%s, I:%s, d:%d", p, i, d) - # self._logger.debug("line: %s", line) - self.pidCycles.append(line) - self._logger.debug("cycles %s", self.pidCycles) + self.pidHotEndCycles.append(line) diff --git a/octoprint_CalibrationTools/hooks.py b/octoprint_CalibrationTools/hooks.py index dc47385..a993900 100644 --- a/octoprint_CalibrationTools/hooks.py +++ b/octoprint_CalibrationTools/hooks.py @@ -21,7 +21,7 @@ class Hooks(): reg = waiter["regex"] waiter["callCount"] = waiter["callCount"] + 1 if reg.match(line): - args = (line, *waiter["args"]) + args = (line, reg, *waiter["args"]) if isinstance(waiter["func"], types.FunctionType): args = (self, *args) threading.Thread(target=waiter["func"], args=args).start() diff --git a/octoprint_CalibrationTools/static/css/style.css b/octoprint_CalibrationTools/static/css/style.css index b8cf168..917ee43 100644 --- a/octoprint_CalibrationTools/static/css/style.css +++ b/octoprint_CalibrationTools/static/css/style.css @@ -55,6 +55,12 @@ text-align: left; max-width: 40px; } + +#tab_plugin_CalibrationTools span.numberDisplay { + min-width: 50px; + text-align: left; +} + /* diff --git a/octoprint_CalibrationTools/static/js/CalibrationTools.js b/octoprint_CalibrationTools/static/js/CalibrationTools.js index 9fc19bc..b674e58 100644 --- a/octoprint_CalibrationTools/static/js/CalibrationTools.js +++ b/octoprint_CalibrationTools/static/js/CalibrationTools.js @@ -57,7 +57,7 @@ $(function () { self.loadEStepsActive(true); }) } - self.startExtrusionActive = ko.observable(true) + self.startExtrusionActive = ko.observable(false) self.startExtrusion = function () { self.startExtrusionActive(true); OctoPrint.simpleApiCommand("CalibrationTools", "eSteps_startExtrusion", { @@ -79,7 +79,7 @@ $(function () { hide: false }); }).always(function (response) { - self.startExtrusionActive(true); + self.startExtrusionActive(false); }); } diff --git a/octoprint_CalibrationTools/static/js/PIDTuneViewModel.js b/octoprint_CalibrationTools/static/js/PIDTuneViewModel.js index e835267..8245c16 100644 --- a/octoprint_CalibrationTools/static/js/PIDTuneViewModel.js +++ b/octoprint_CalibrationTools/static/js/PIDTuneViewModel.js @@ -5,8 +5,19 @@ $(function () { self.settingsViewModel = parameters[1]; self.controlViewModel = parameters[2]; - self.bedCurrentTemp = ko.observable(0); - self.bedCurrentTarget = ko.observable(0); + self.pidCurrentValues = { + "hotEnd": { + "P": ko.observable(0), + "I": ko.observable(0), + "D": ko.observable(0) + }, + "bed": { + "P": ko.observable(0), + "I": ko.observable(0), + "D": ko.observable(0) + } + }; + self.isAdmin = ko.observable(false); self.pid = { fanSpeed: ko.observable(255), @@ -15,10 +26,26 @@ $(function () { targetTemp: ko.observable(200) }; - OctoPrint.printer.getBedState().done(function (bedState) { - self.bedCurrentTemp(bedState.bed.actual); - self.bedCurrentTarget(bedState.bed.target); - }); + /** + * Get current PIDs settings for bed and hotEnd + */ + self.getCurrentValues = function () { + OctoPrint.simpleApiCommand("CalibrationTools", "pid_getCurrentValues").done(function (response) { + self.pidCurrentValues.hotEnd.P(response.data.hotEnd.P); + self.pidCurrentValues.hotEnd.I(response.data.hotEnd.I); + self.pidCurrentValues.hotEnd.D(response.data.hotEnd.D); + self.pidCurrentValues.bed.P(response.data.bed.P); + self.pidCurrentValues.bed.I(response.data.bed.I); + self.pidCurrentValues.bed.D(response.data.bed.D); + }).fail(function (response) { + new PNotify({ + title: "Error on getting current PID values ", + text: response.responseJSON.error, + type: "error", + hide: false + }); + }); + }; self.onBeforeBinding = self.onUserLoggedIn = self.onUserLoggedOut = function () { self.pid.fanSpeed(self.settingsViewModel.settings.plugins.CalibrationTools.pid.fanSpeed()); @@ -43,7 +70,7 @@ $(function () { console.log(response); }).fail(function (response) { new PNotify({ - title: "Error on starting extrusion ", + title: "Error on starting PID autotune ", text: response.responseJSON.error, type: "error", hide: false diff --git a/octoprint_CalibrationTools/templates/tabs/tab-esteps.jinja2 b/octoprint_CalibrationTools/templates/tabs/tab-esteps.jinja2 index 485358b..68bc1db 100644 --- a/octoprint_CalibrationTools/templates/tabs/tab-esteps.jinja2 +++ b/octoprint_CalibrationTools/templates/tabs/tab-esteps.jinja2 @@ -43,7 +43,7 @@

diff --git a/octoprint_CalibrationTools/templates/tabs/tab-pid.jinja2 b/octoprint_CalibrationTools/templates/tabs/tab-pid.jinja2 index a4ff3b7..d98f3ee 100644 --- a/octoprint_CalibrationTools/templates/tabs/tab-pid.jinja2 +++ b/octoprint_CalibrationTools/templates/tabs/tab-pid.jinja2 @@ -1,12 +1,47 @@ {% import "macros.jinja2" as snipped %} -Current bed temperature: ° Bed target temperature ° -{{ snipped.subSection("Tool tuning", true) }} - +{{ snipped.subSection("Hot-end tuning", true) }} +
+
+ +
+
+
+ P + + I + + D + + +
+
+
+
+
+ +
+
+
+ P + + I + + D + +
+
+
-
@@ -50,9 +85,6 @@ Current bed temperature: ° Be
-Save M501 - - {{ snipped.subSection("Heated bed tuning", true) }}