Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

basic A and B rotational support #107

Merged
merged 16 commits into from
Jan 6, 2023
20 changes: 20 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"MicroPython.executeButton": [
{
"text": "▶",
"tooltip": "Run",
"alignment": "left",
"command": "extension.executeFile",
"priority": 3.5
}
],
"MicroPython.syncButton": [
{
"text": "$(sync)",
"tooltip": "sync",
"alignment": "left",
"command": "extension.execute",
"priority": 4
}
]
}
31 changes: 30 additions & 1 deletion octoprint_bettergrblsupport/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ def __init__(self):
self.grblX = float(0)
self.grblY = float(0)
self.grblZ = float(0)
self.grblA = float(0)
self.grblB = float(0)
self.grblActivePins = ""
self.grblSpeed = float(0)
self.grblPowerLevel = float(0)
Expand Down Expand Up @@ -260,7 +262,9 @@ def get_settings_defaults(self):
bgsFilters = self.bgs_filters,
activeFilters = [],
fluidYaml = None,
fluidSettings = {}
fluidSettings = {},
hasA = False,
hasB = False
)


Expand Down Expand Up @@ -947,6 +951,17 @@ def hook_gcode_sending(self, comm_instance, phase, cmd, cmd_type, gcode, *args,
found = True
foundZ = True

#ADD A and B here
match = re.search(r".*[Aa]\ *(-?[\d.]+).*", cmd)
if not match is None:
self.grblA = float(match.groups(1)[0]) if self.positioning == 0 else self.grblA + float(match.groups(1)[0])
found = True

match = re.search(r".*[Bb]\ *(-?[\d.]+).*", cmd)
if not match is None:
self.grblB = float(match.groups(1)[0]) if self.positioning == 0 else self.grblB + float(match.groups(1)[0])
found = True

# match = re.search(r"^[GM]([0][01234]|[01234])(\D.*[Ff]|[Ff])\ *(-?[\d.]+).*", command)
match = re.search(r".*[Ff]\ *(-?[\d.]+).*", cmd)
if not match is None:
Expand Down Expand Up @@ -1002,6 +1017,8 @@ def hook_gcode_sending(self, comm_instance, phase, cmd, cmd_type, gcode, *args,
x=self.grblX,
y=self.grblY,
z=self.grblZ,
a=self.grblA,
b=self.grblB,
speed=self.grblSpeed,
power=self.grblPowerLevel,
positioning=self.positioning,
Expand Down Expand Up @@ -1390,6 +1407,18 @@ def on_api_command(self, command, data):

if direction == "down":
self._printer.commands("{}G91 G21 Z{:f} F{}".format("$J=" if _bgs.is_grbl_one_dot_one(self) else "G1 ", distance * -1 * self.invertZ, zf))

if direction == "a-right":
self._printer.commands("{}G91 G21 A{:f} F{}".format("$J=" if _bgs.is_grbl_one_dot_one(self) else "G1 ", distance, zf))

if direction == "a-left":
self._printer.commands("{}G91 G21 A{:f} F{}".format("$J=" if _bgs.is_grbl_one_dot_one(self) else "G1 ", distance * -1, zf))

if direction == "b-right":
self._printer.commands("{}G91 G21 B{:f} F{}".format("$J=" if _bgs.is_grbl_one_dot_one(self) else "G1 ", distance, zf))

if direction == "b-left":
self._printer.commands("{}G91 G21 B{:f} F{}".format("$J=" if _bgs.is_grbl_one_dot_one(self) else "G1 ", distance * -1, zf))

return

Expand Down
35 changes: 28 additions & 7 deletions octoprint_bettergrblsupport/_bgs.py
Original file line number Diff line number Diff line change
Expand Up @@ -587,20 +587,39 @@ def toggle_weak(_plugin):


def process_grbl_status_msg(_plugin, msg):
match = re.search(r'<(-?[^,]+)[,|][WM]Pos:(-?[\d\.]+),(-?[\d\.]+),(-?[\d\.]+)', msg)
if match is None:
_plugin._logger.warning('Bad data %s', msg.rstrip())
return None

#need to redefine much of this if we have more axes
hasA = _plugin._settings.get(["hasA"])
hasB = _plugin._settings.get(["hasB"])
match = re.search(r'<(-?[^,]+)[,|][WM]Pos:(-?[\d\.]+),(-?[\d\.]+),(-?[\d\.]+),?(-?[\d\.]+)?,?(-?[\d\.]+)?', msg)
response = 'X:{1} Y:{2} Z:{3} E:0 {original}'.format(*match.groups(), original=msg)

_plugin.grblMode = "MPos" if "MPos" in msg else "WPos" if "WPos" in msg else "N/A"
_plugin.grblState = str(match.groups(1)[0])
_plugin.grblX = float(match.groups(1)[1])
_plugin.grblY = float(match.groups(1)[2])
_plugin.grblZ = float(match.groups(1)[3])

match = re.search(r'.*\|Pn:([XYZPDHRS]+)', msg)
if match.groups(1)[5]:
_plugin.grblA = float(match.groups(1)[4])
_plugin.grblB = float(match.groups(1)[5])

if match.groups(1)[4] and not match.groups(1)[5] and hasB:
_plugin.grblB = float(match.groups(1)[4])
else:
_plugin.grblA = float(match.groups(1)[4])

'''
if hasA and hasB:
match = re.search(r'<(-?[^,]+)[,|][WM]Pos:(-?[\d\.]+),(-?[\d\.]+),(-?[\d\.]+),(-?[\d\.]+),(-?[\d\.]+)', msg)
response = 'X:{1} Y:{2} Z:{3} A:{4} B:{5} E:0 {original}'.format(*match.groups(), original=msg)
_plugin.grblMode = "MPos" if "MPos" in msg else "WPos" if "WPos" in msg else "N/A"
_plugin.grblState = str(match.groups(1)[0])
_plugin.grblX = float(match.groups(1)[1])
_plugin.grblY = float(match.groups(1)[2])
_plugin.grblZ = float(match.groups(1)[3])
_plugin.grblA = float(match.groups(1)[4])
_plugin.grblB = float(match.groups(1)[5])
'''
match = re.search(r'.*\|Pn:([XYZABPDHRS]+)', msg)
if not match is None:
_plugin.grblActivePins = match.groups(1)[0]
else:
Expand All @@ -617,6 +636,8 @@ def process_grbl_status_msg(_plugin, msg):
x=_plugin.grblX,
y=_plugin.grblY,
z=_plugin.grblZ,
a=_plugin.grblA,
b=_plugin.grblB,
pins=_plugin.grblActivePins,
speed=_plugin.grblSpeed,
power=_plugin.grblPowerLevel,
Expand Down
7 changes: 7 additions & 0 deletions octoprint_bettergrblsupport/static/js/bettergrblsupport.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ $(function() {
self.webcamError = ko.observable(false);

self.origin_axes = ko.observableArray(["Z", "Y", "X", "XY", "ALL"]);
if (self.settings.hasA() == true) { self.origin_axes.push("A"); }
if (self.settings.hasB() == true) { self.origin_axes.push("B"); }
self.origin_axis = ko.observable("XY");

self.coordinate_systems = ko.observableArray(["G54", "G55", "G56", "G57", "G58", "G59"]);
Expand All @@ -50,6 +52,8 @@ $(function() {
self.xPos = ko.observable("N/A");
self.yPos = ko.observable("N/A");
self.zPos = ko.observable("N/A");
self.aPos = ko.observable("N/A");
self.bPos = ko.observable("N/A");
self.power = ko.observable("N/A");
self.speed = ko.observable("N/A");
self.pins = ko.observable("N/A")
Expand Down Expand Up @@ -496,6 +500,9 @@ $(function() {
if (data.x != undefined) self.xPos(Number.parseFloat(data.x).toFixed(2));
if (data.y != undefined) self.yPos(Number.parseFloat(data.y).toFixed(2));
if (data.z != undefined) self.zPos(Number.parseFloat(data.z).toFixed(2));
if (data.a != undefined) self.aPos(Number.parseFloat(data.a).toFixed(2));
if (data.b != undefined) self.bPos(Number.parseFloat(data.b).toFixed(2));

if (data.speed != undefined) self.speed(Number.parseFloat(data.speed).toFixed(2));
if (data.pins != undefined) self.pins(data.pins);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,12 @@
<label class="checkbox">
<input type="checkbox" data-bind="checked: settings.plugins.bettergrblsupport.invertZ"> Invert Z Axis (jogging / probing)
</label>
<label class="checkbox">
<input type="checkbox" data-bind="checked: settings.plugins.bettergrblsupport.hasA"> Has A Axis
</label>
<label class="checkbox">
<input type="checkbox" data-bind="checked: settings.plugins.bettergrblsupport.hasB"> Has B Axis
</label>

<br>

Expand Down
46 changes: 46 additions & 0 deletions octoprint_bettergrblsupport/templates/bettergrblsupport_tab.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,18 @@
<td style="padding: 3px 10px 0px 5px;" align="right" valign="middle">Z</td>
<td style="padding: 3px 5px 0px 5px;" align="right" valign="middle"><strong data-bind="text: zPos()"></strong></td>
</tr>
<!-- ko if: settings.settings.plugins.bettergrblsupport.hasA -->
<tr>
<td style="padding: 3px 10px 0px 5px;" align="right" valign="middle">A</td>
<td style="padding: 3px 5px 0px 5px;" align="right" valign="middle"><strong data-bind="text: aPos()"></strong></td>
</tr>
<!-- /ko -->
<!-- ko if: settings.settings.plugins.bettergrblsupport.hasB -->
<tr>
<td style="padding: 3px 10px 0px 5px;" align="right" valign="middle">B</td>
<td style="padding: 3px 5px 0px 5px;" align="right" valign="middle"><strong data-bind="text: bPos()"></strong></td>
</tr>
<!-- /ko -->
<tr>
<!-- ko if: settings.settings.plugins.bettergrblsupport.laserMode -->
<td style="padding: 3px 10px 0px 5px;" align="right" valign="middle">Power</td>
Expand Down Expand Up @@ -164,6 +176,40 @@
</button>
</td>
</tr>
<tr>
<!-- ko if: settings.settings.plugins.bettergrblsupport.hasA -->
<td style="padding: 0px 0px 10px 0px;">
<label>A axis:</label>
</td>
<!-- /ko -->
<!-- ko if: settings.settings.plugins.bettergrblsupport.hasB -->
<td style="padding: 0px 0px 10px 0px;">
<label>B axis:</label>
</td>
<!-- /ko -->
</tr>
<tr>
<!-- ko if: settings.settings.plugins.bettergrblsupport.hasA -->
<td style="padding: 0px 0px 10px 0px;">
<button class="btn box" style="border: 1px solid; width: 40px; height: 40px" data-bind="enable: isIdleOrJogging() && operator() != 'J', click: function() {moveHead('a-right')}">
<i class="fa fa-rotate-right"></i>
</button>
<button class="btn box" style="border: 1px solid; width: 40px; height: 40px" data-bind="enable: isIdleOrJogging() && operator() != 'J', click: function() {moveHead('a-left')}">
<i class="fa fa-rotate-left"></i>
</button>
</td>
<!-- /ko -->
<!-- ko if: settings.settings.plugins.bettergrblsupport.hasB -->
<td style="padding: 0px 0px 10px 0px;">
<button class="btn box" style="border: 1px solid; width: 40px; height: 40px" data-bind="enable: isIdleOrJogging() && operator() != 'J', click: function() {moveHead('b-right')}">
<i class="fa fa-rotate-right"></i>
</button>
<button class="btn box" style="border: 1px solid; width: 40px; height: 40px" data-bind="enable: isIdleOrJogging() && operator() != 'J', click: function() {moveHead('b-left')}">
<i class="fa fa-rotate-left"></i>
</button>
</td>
<!-- /ko -->
</tr>
<tr>
<td colspan=3 align="center" class="distance">
<span>
Expand Down