Skip to content

Commit

Permalink
Marlin 2 support.
Browse files Browse the repository at this point in the history
  • Loading branch information
arekm committed Oct 9, 2022
1 parent d46ade7 commit 3bd90d6
Show file tree
Hide file tree
Showing 4 changed files with 142 additions and 19 deletions.
64 changes: 54 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,29 +1,73 @@
# Prusa ETA Override
# ETA Override

The best ETA in 3d printing is ETA comming from slicer software. Slicer adds M73 commands
with estimations of print progress, time, time until next pause etc.

This plugin uses firmware reports issued to serial output and comming from M73 g-code commands.
Supported firmware issues M73 Reports for SD-card and USB printing.

Data used by plugin:
* time until end of printing
* time progress reflected in OctoPrint web UI progress bar
(but due to OctoPrint limitations not in API, see https://github.com/OctoPrint/OctoPrint/issues/4663)

Also this plugin queries for position (M114) when every M73 command parsing happens and fires z-change event
(to support sending status message every X milimeters via telegram).

## Supported firmware

Supported firmware list and recognized messages.

* [Prusa Firmware](https://github.com/prusa3d/Prusa-Firmware) (v3.3.0+)

```
NORMAL MODE: Percent done: 21; print time remaining in mins: 33
SILENT MODE: Percent done: 21; print time remaining in mins: 34
```

```
NORMAL MODE: Percent done: 21; print time remaining in mins: 33; Change in mins: -1
SILENT MODE: Percent done: 21; print time remaining in mins: 34; Change in mins: -1
```

* [Marlin 2](https://github.com/MarlinFirmware/Marlin) (v2.1.2+)

```
echo: M73 Percent done: 10; Print time remaining in mins: 20; Change in mins: 7;
```

but also other variant (when default M73_REPORT_PRUSA option is disabled)

```
echo: M73 Progress: 10%; Time left: 20.0m; Change: 7m
```

(each part of report is optional and configurable in Marlin 2)

Prusa "NORMAL MODE: Percent done:" messages ETA override for OctoPrint allowing to get exact ETA in case of printing from SD. Also this plugin queries for position every minute (M114) and also fires z-change event (to support sending status message every X milimeters via telegram :) )

## Setup

Install via the bundled [Plugin Manager](https://github.com/foosel/OctoPrint/wiki/Plugin:-Plugin-Manager)
or manually using this URL:
Install via the bundled Plugin Manager or manually using this URL:

https://github.com/kanocz/octopi_eta_override/archive/master.zip
https://github.com/arekm/octopi_eta_override/archive/master.zip

## Develop

Setup environment the same way as for OctoPrint development:

https://docs.octoprint.org/en/master/development/environment.html

and use pre-commit hook for checking:

(once)
(installation; once)
```
pre-commit install
```

and then

(formatting checking)
```
pre-commit run --hook-stage manual --all-files
```

(run tests)
```
pytest
```
32 changes: 24 additions & 8 deletions octoprint_PrusaETAOverride/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,20 @@ def __init__(self):
self._estimator = None
self.m73_mode = None

self.m73_pattern = re.compile(
r"(?P<mode>\w+) MODE: Percent done: (?P<progress>-?\d+); print time remaining in mins: (?P<eta>-?\d+)(?:; Change in mins: (?P<eta_interaction>-?\d+))?"
)
self.m73_patterns = [
# Prusa Firmware 3.3.0+
re.compile(
r"(?P<mode>\w+) MODE: Percent done: (?P<progress>-?\d+); print time remaining in mins: (?P<eta>-?\d+)(?:; Change in mins: (?P<eta_interaction>-?\d+))?"
),
# Marlin 2.1.2+ with M73_REPORT_PRUSA option
re.compile(
r"M73 Percent done:\s+(?P<progress>\d+(?:\.\d+)?);(?: Print time remaining in mins:\s+(?P<eta>\d+(?:\.\d+)?);)?(?: Change in mins:\s+(?P<eta_interaction>\d+(?:\.\d+)?);)?"
),
# Marlin 2.1.2+ without M73_REPORT_PRUSA option
re.compile(
r"M73 Progress:\s+(?P<progress>\d+(?:\.\d+)?)%{0,1};{0,1}(?: Time left:\s+(?P<eta>\d+(?:\.\d+)?)m;{0,1})?(?: Change:\s+(?P<eta_interaction>\d+(?:\.\d+)?)m)?"
),
]
self.m114_pattern = re.compile(r"^X:\d+\.\d+ Y:\d+\.\d+ Z:(?P<z>\d+\.\d+) ")

def get_assets(self):
Expand All @@ -55,8 +66,13 @@ def set_progress(self, progress):
)

def parse_line_m73(self, line):
m = self.m73_pattern.search(line)
return m.groupdict() if m else None
for r in self.m73_patterns:
m = r.search(line)
if m:
return dict(
filter(lambda item: item[1] is not None, m.groupdict().items())
)
return None

def parse_line_m114(self, line):
m = self.m114_pattern.search(line)
Expand Down Expand Up @@ -129,15 +145,15 @@ def factory(*args, **kwargs):
def get_update_information(self):
return dict(
PrusaETAOverride=dict(
displayName="Prusa ETA override Plugin",
displayName="Slicer M73 ETA override Plugin (Prusa; Marlin 2)",
displayVersion=self._plugin_version,
# version check: github repository
type="github_release",
user="kanocz",
user="arekm",
repo="octopi_eta_override",
current=self._plugin_version,
# update method: pip
pip="https://github.com/kanocz/octopi_eta_override/archive/{target_version}.zip",
pip="https://github.com/arekm/octopi_eta_override/archive/{target_version}.zip",
)
)

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

# The plugin's description. Can be overwritten within OctoPrint's internal data via __plugin_description__ in the plugin
# module
plugin_description = """ETA override from "NORMAL MODE: Percent done: XX; print time remaining in mins: YY" message"""
plugin_description = """Slicer M73 reports as ETA override for OctoPrint (Prusa; Marlin 2)"""

# The plugin's author. Can be overwritten within OctoPrint's internal data via __plugin_author__ in the plugin module
plugin_author = "Anton Skorochod"
Expand Down
63 changes: 63 additions & 0 deletions tests/test_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ def test_mode(plugin):
@pytest.mark.parametrize(
"val,expected",
[
# Prusa
(
"NORMAL MODE: Percent done: 100; print time remaining in mins: 0; Change in mins: -1",
{"mode": "NORMAL", "progress": "100", "eta": "0", "eta_interaction": "-1"},
Expand All @@ -57,6 +58,68 @@ def test_mode(plugin):
"SILENT MODE: Percent done: -1; print time remaining in mins: -1; Change in mins: -1",
{"mode": "SILENT", "progress": "-1", "eta": "-1", "eta_interaction": "-1"},
),
(
"SILENT MODE: Percent done: -1; print time remaining in mins: -1",
{"mode": "SILENT", "progress": "-1", "eta": "-1"},
),
# Marlin, with M73_REPORT_PRUSA
(
"echo: M73 Percent done: 10; Print time remaining in mins: 20; Change in mins: 7;",
{"progress": "10", "eta": "20", "eta_interaction": "7"},
),
(
"echo: M73 Percent done: 10; Print time remaining in mins: 20;",
{"progress": "10", "eta": "20"},
),
(
"echo: M73 Percent done: 10; Change in mins: 7;",
{"progress": "10", "eta_interaction": "7"},
),
(
"echo: M73 Percent done: 10;",
{"progress": "10"},
),
(
"echo: M73 Percent done: 5; Print time remaining in mins: 10; Change in mins: 3;",
{"progress": "5", "eta": "10", "eta_interaction": "3"},
),
(
"echo: M73 Percent done: 7.0; Print time remaining in mins: 10; Change in mins: 3;",
{"progress": "7.0", "eta": "10", "eta_interaction": "3"},
),
(
"echo: M73 Percent done: 7.0; Print time remaining in mins: 10.0; Change in mins: 3.0;",
{"progress": "7.0", "eta": "10.0", "eta_interaction": "3.0"},
),
# Marlin, without M73_REPORT_PRUSA
(
"echo: M73 Progress: 10%; Time left: 20m; Change: 7m",
{"progress": "10", "eta": "20", "eta_interaction": "7"},
),
(
"echo: M73 Progress: 10%; Time left: 20m",
{"progress": "10", "eta": "20"},
),
(
"echo: M73 Progress: 10%; Change: 7m",
{"progress": "10", "eta_interaction": "7"},
),
(
"echo: M73 Progress: 10%;",
{"progress": "10"},
),
(
"echo: M73 Progress: 5%; Time left: 10m; Change: 3m",
{"progress": "5", "eta": "10", "eta_interaction": "3"},
),
(
"echo: M73 Progress: 7.0%; Time left: 10m; Change: 3m",
{"progress": "7.0", "eta": "10", "eta_interaction": "3"},
),
(
"echo: M73 Progress: 7.0%; Time left: 10.0m; Change: 3.0m",
{"progress": "7.0", "eta": "10.0", "eta_interaction": "3.0"},
),
],
)
def test_parse_line_m73(plugin, val, expected):
Expand Down

0 comments on commit 3bd90d6

Please sign in to comment.