Skip to content

Commit

Permalink
Added custom trigger gcode for abl. Added compatibility with prusa bu…
Browse files Browse the repository at this point in the history
…ddy. Fixed SemVer for 0.5.x
  • Loading branch information
scmanjarrez committed Apr 5, 2023
1 parent 6fc97f6 commit 8bdf2dc
Show file tree
Hide file tree
Showing 9 changed files with 150 additions and 80 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
SmartABL-stats
smartabldash
.flake8
*.pyc
*.swp
Expand Down
52 changes: 28 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,28 +1,25 @@
# SmartABL

Simple plugin to improve auto bed leveling, adding some conditions
in order to minimize the number of ABLs triggered.
Simple plugin to reduce the number of ABLs triggered.

## How it works?

The plugin reads `ABL_CMD`<sup>1</sup> from ***.gcode** and check the bed mesh
The plugin reads `ABL_CMD`<sup>1</sup> from your print file and check the bed mesh
in memory<sup>M</sup>.
- If mesh is updated, `M420 S1`<sup>M</sup> is sent in order to load bed mesh from memory.
- If mesh is outdated or doesn't exist, `ABL_CMD` is sent in order to generate a new mesh.
On Marlin, `M500` is also sent to save the mesh on the eeprom.

> <sup>1</sup>: ABL_CMD can be `G29` (Marlin), `G80` (Prusa) or `BED_MESH_CALIBRATE` (Klipper).
> <sup>1</sup>: `ABL_CMD` can be `G29` (Marlin/Prusa-buddy), `G80` (Prusa)
> or `BED_MESH_CALIBRATE` (Klipper). This can be customized in SmartABL settings.
> <sup>M</sup>: Marlin-only compatible.
> Warning: Prusa and Klipper require at least 1 ABL to track the state.
> Note: Prusa and Klipper require at least 1 ABL to track the state.
> Note: By default, the same ABL command read from your file is sent to the printer, but
> can be customized in SmartABL settings.
> Note: By default, the standard ABL command for each firmware triggers SmartABL algorithm,
> however, you can customize this behaviour in settings: the command that triggers the algorithm, the command sent
> to the printer or even ignore commands.
References:
- [G29<sup>M</sup>](https://marlinfw.org/docs/gcode/G029.html)
- [M420<sup>M</sup>](https://marlinfw.org/docs/gcode/M420.html)
- [G29<sup>M,B</sup>](https://marlinfw.org/docs/gcode/G029.html)
- [M420<sup>M,B</sup>](https://marlinfw.org/docs/gcode/M420.html)
- [M500<sup>M</sup>](https://marlinfw.org/docs/gcode/M500.html)
- [G80<sup>P</sup>](https://reprap.org/wiki/G-code#G80:_Mesh-based_Z_probe)
- [G81<sup>P</sup>](https://reprap.org/wiki/G-code#G81:_Mesh_bed_leveling_status)
Expand All @@ -34,28 +31,37 @@ Credits to [Oscar](https://3dprinting.stackexchange.com/a/15953/27154)
for the idea.

## Compatibility
- Marlin
- Prusa
- Klipper
- Marlin (M)
- Prusa (P)
- Prusa-buddy (B)
- Klipper (K)

> Want your firmware to be compatible? Open an Issue on github so we can add compatibility 😊
> Want your firmware to be compatible? Open an Issue on github so we can add it 🙂
>
> Don't forget to upload plugin_SmartABL.log!!
## Setup

Install via the bundled [Plugin Manager](https://docs.octoprint.org/en/master/bundledplugins/pluginmanager.html)
or manually using this URL:

https://github.com/scmanjarrez/OctoPrint-SmartABL/archive/master.zip

## Configuration
### Settings panel
**GCODES**
- Trigger custom gcode(s): By default, SmartABL only triggers with the standard ABL
commands, i.e. `G29/G80/BED_MESH_CALIBRATE`. However, you can define here
a list of gcodes that can trigger SmartABl, e.g. macros or non-standard commands.
Default: disabled (G29).

**Leveling command**
- Ignore gcode read from files and send a custom gcode instead.
- ABL custom gcode(s): By default, SmartABL sends the standard ABL
commands, i.e. `G29/G80/BED_MESH_CALIBRATE`. However, you can define here
a list of gcodes that will be sent instead, e.g. macros or non-standard commands.
Default: disabled (G29).

**Ignore gcodes**
- Skip gcodes listed here.
- Ignore gcode(s): Define here if you want to skip gcodes. The commands defined here
won't be sent to the printer.
Default: disabled.

**Force bed leveling**
- After `#` days. Default: enabled (1).
Expand All @@ -74,7 +80,6 @@ Default: disabled (only successful prints increase the counter).
</div>

### Side panel

- **ABL Restricted**: Normal behaviour, the plugin chooses when to trigger ABL
based on your settings.

Expand All @@ -99,7 +104,6 @@ Thank you [jneilliii](https://github.com/jneilliii) and [foosel](https://github.
for your continuous help!

## License

OctoPrint-SmartABL Copyright (C) 2022-2023 scmanjarrez.
This program comes with ABSOLUTELY NO WARRANTY; for details check below.
This is free software, and you are welcome to redistribute it
Expand Down
60 changes: 42 additions & 18 deletions octoprint_SmartABL/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,10 @@ def get_assets(self):
# SettingsPlugin
def get_settings_defaults(self):
return dict(
cmd_custom=False,
custom_gcode="G29",
trigger_custom=False,
trigger_gcode="G29",
abl_custom=False,
abl_gcode="G29",
cmd_ignore=False,
ignore_gcode="",
force_days=True,
Expand Down Expand Up @@ -238,7 +240,7 @@ def at_command(
cmds = [self.fw_metadata[self.firmware]["abl"]]
else:
cmds = [self.last_cmd]
if self._get("cmd_custom"):
if self._get("abl_custom"):
cmds = self._gcodes_custom()
if self.save_allowed:
self.cache.add(self.fw_metadata[self.firmware]["save"])
Expand Down Expand Up @@ -273,16 +275,27 @@ def process_line(self, comm_instance, line, *args, **kwargs):
)
idx = line.find("FIRMWARE_NAME")
for fw_n in self.fw_metadata:
# Workaround to detect Prusa and not Marlin
if fw_n in line[idx : idx + 30].lower():
self.firmware = fw_n
if self.firmware != "marlin":
pattern = line[idx : idx + 40].lower()
if fw_n in pattern:
buddy = False
if "buddy" in pattern:
self.firmware = "marlin"
buddy = True
else:
self.firmware = fw_n
if self.firmware != "marlin" or buddy:
self.save_allowed = False
self.probe_required = True
self._smartabl_logger.debug(
f"@process_line:detected_firmware >> {fw_n} > "
f"{self._dbginternal()}"
)
if buddy:
self._smartabl_logger.debug(
f"@process_line:detected_firmware >> "
f"prusa-buddy > {self._dbginternal()}"
)
else:
self._smartabl_logger.debug(
f"@process_line:detected_firmware >> "
f"{fw_n} > {self._dbginternal()}"
)
break
else:
self._smartabl_logger.debug(
Expand Down Expand Up @@ -387,15 +400,24 @@ def _diff_days(self):
).days

def _gcodes_abl(self):
return [fw["abl"] for fw in self.fw_metadata.values()] + [
self.fw_metadata["marlin"]["load"].split()[0]
]
if self._get("trigger_custom"):
return [
gc.strip() for gc in self._get("trigger_gcode", "s").split(",")
]
else:
if self.firmware != "marlin":
return [self.fw_metadata[self.firmware]["abl"]]
else:
return [
self.fw_metadata[self.firmware]["abl"],
self.fw_metadata[self.firmware]["load"].split()[0],
]

def _gcodes_temp(self):
return [self.temp[tmp] for tmp in self.temp]

def _gcodes_custom(self):
return [gc.strip() for gc in self._get("custom_gcode", "s").split(",")]
return [gc.strip() for gc in self._get("abl_gcode", "s").split(",")]

def _gcodes_ignore(self):
return [gc.strip() for gc in self._get("ignore_gcode", "s").split(",")]
Expand All @@ -417,9 +439,11 @@ def _dbg(self):
def _dbgsettings(self):
return (
f"Settings("
f"cmd_custom={self._get('cmd_custom')}, "
f"custom_gcode={self._get('custom_gcode', 's')}, "
f"cmd_ignore={self._get('cmd_custom')}, "
f"trigger_custom={self._get('trigger_custom')}, "
f"trigger_gcode={self._get('trigger_gcode', 's')}, "
f"abl_custom={self._get('abl_custom')}, "
f"abl_gcode={self._get('abl_gcode', 's')}, "
f"cmd_ignore={self._get('abl_custom')}, "
f"ignore_gcode={self._get('ignore_gcode', 's')}, "
f"force_days={self._get('force_days')}, "
f"days={self._get('days', 'i')}, "
Expand Down
4 changes: 4 additions & 0 deletions octoprint_SmartABL/static/css/SmartABL.css
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
width: 44.8%;
}

.smartabl-counter {
width: 10.4%;
}

.smartabl-addon {
width: 50px !important;
}
Expand Down
2 changes: 1 addition & 1 deletion octoprint_SmartABL/static/js/SmartABL.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ $(function() {
$(function() {
var btnGroupSmartABL = `<div id='job_smartABL' class='btn-group smartabl' data-toggle='buttons-radio'>
<button id='smartABL_restricted' type='button' class='btn smartabl-radio'><i class='fa fa-crosshairs'></i><span> ABL Restricted</span></button>
<button id='smartABL_counter' class='btn btn-info disabled'>?</button>
<button id='smartABL_counter' class='btn btn-info smartabl-counter disabled'>?</button>
<button id='smartABL_always' type='button' class='btn smartabl-radio'><i class='fa fa-crosshairs'></i><span> ABL Always</span></button>
</div>`;
var btn_last_job = $('#job_print').parent().children().last();
Expand Down
33 changes: 20 additions & 13 deletions octoprint_SmartABL/templates/SmartABL_settings.jinja2
Original file line number Diff line number Diff line change
@@ -1,36 +1,43 @@
<form class="form-horizontal">
<h4>SmartABL Settings <small>Version {{ plugin_SmartABL_version }}</small></h4>
<h4>SmartABL settings <small>Version {{ plugin_SmartABL_version }}</small></h4>

<div class="control-group">
<h5>Leveling commands</h5>
<h5>GCODES</h5>

<label class="control-label"></label>
<div class="controls">
<label class="checkbox">
<input type="checkbox" style="margin-top: 5px;" data-bind="checked: settings.plugins.SmartABL.cmd_custom"/>
Custom
<input type="checkbox" style="margin-top: 5px;" data-bind="checked: settings.plugins.SmartABL.trigger_custom"/>
Trigger custom gcode(s)
<div class="input-append">
<input class="input-xlarge" data-bind="value: settings.plugins.SmartABL.custom_gcode, enable: settings.plugins.SmartABL.cmd_custom"/>
<input class="input-xlarge" data-bind="value: settings.plugins.SmartABL.trigger_gcode, enable: settings.plugins.SmartABL.trigger_custom"/>
</div>
<br>
<small>Multiple commands allowed, separate them with commas. Do not use semicolons</small>
<small>These commands will trigger SmartABL algorithm. Useful if you use macros instead of G29/G80/BED_MESH_CALIBRATE. Multiple commands allowed, separate them with commas. Don't use semicolons</small>
</label>
</div>
<label class="control-label"></label>
<div class="controls">
<label class="checkbox">
<input type="checkbox" style="margin-top: 5px;" data-bind="checked: settings.plugins.SmartABL.abl_custom"/>
ABL custom gcode(s)
<div class="input-append">
<input class="input-xlarge" data-bind="value: settings.plugins.SmartABL.abl_gcode, enable: settings.plugins.SmartABL.abl_custom"/>
</div>
<br>
<small>These commands will be sent instead of G29/G80/BED_MESH_CALIBRATE. Multiple commands allowed, separate them with commas. Do not use semicolons</small>
</label>
</div>
</div>

<div class="control-group">
<h5>Ignore gcodes</h5>

<label class="control-label"></label>
<div class="controls">
<label class="checkbox">
<input type="checkbox" style="margin-top: 5px;" data-bind="checked: settings.plugins.SmartABL.cmd_ignore"/>
Ignore
Ignore gcode(s)
<div class="input-append">
<input class="input-xlarge" data-bind="value: settings.plugins.SmartABL.ignore_gcode, enable: settings.plugins.SmartABL.cmd_ignore"/>
</div>
<br>
<small>Separate commands with a comma</small>
<small>These commands will be ignored and not be sent to the printer. Multiple commands allowed, separate them with commas. Do not use semicolons</small>
</label>
</div>
</div>
Expand Down
Loading

0 comments on commit 8bdf2dc

Please sign in to comment.