Skip to content

Commit

Permalink
Merge pull request #21 from Willmac16/devel
Browse files Browse the repository at this point in the history
0.3.0 Added support for Prusa M555 Command
  • Loading branch information
Willmac16 committed Sep 29, 2023
2 parents 9e5abd1 + 7ca43da commit cc9c482
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 3 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@ or manually using this URL:
## Credits

* Thanks to KenLucke for the plugin suggestion and testing help.
* Thanks to AlexDashwood for the fix for a conflict with ContinuousPrint
* Thanks to AlexDashwood for the fix for a conflict with ContinuousPrint
* Thanks to ScottWell1 for adding support for Prusa's `M555` command
86 changes: 85 additions & 1 deletion octoprint_translatemodel/src/translate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,8 @@ std::string translate(double shifts[][2], int numShifts, std::string inPath,
std::regex start(startRegex);
std::regex end(stopRegex);

std::regex m555("^M555.*$"); //NEW PATTERN FOR PRUSA M555 "bed area to probe" COMMAND

bool absolute = true;

int afterStart = -1;
Expand Down Expand Up @@ -258,7 +260,89 @@ std::string translate(double shifts[][2], int numShifts, std::string inPath,

if (afterStart != 1)
{
if (std::regex_match(line, start))
if (std::regex_match(line, m555)) // THIS BLOCK IS FOR PRUSA M555, WHICH DEFINES "USED BED AREA" FOR G29 PROBING
{
// NEW CODE HERE FOR M555 AS FOLLOWS:
// - Decode existing line for original M555 X, Y, W, H values
std::istringstream iss(line);
char arg;
float origX = 0;
float origY = 0;
float origW = 0;
float origH = 0;
while (iss >> arg)
{
char upp = toupper(arg);
// if (iss >> num)
switch (upp)
{
case 'X':
origX = parseFloat(&iss);
break;
case 'Y':
origY = parseFloat(&iss);
break;
case 'W':
origW = parseFloat(&iss);
break;
case 'H':
origH = parseFloat(&iss);
break;
}
}
// - If multiple shifts:
// - iterate to find minimum and maximum X translation "minXoffset" and "maxXoffset"
// - iterate to find minimum and maximum Y translation "minYoffset" and "maxYoffset"
// - set minX = origX+minXoffset (new x origin of entire print, all shifts/copies)
// - set minY = origY+minYoffset (new y origin of entire print, all shifts/copies)
// else
// - set minX=maxX=origX+shift, minY=maxY=origY+shift (new origin is minX, minY)

float minX;
float minY;
float maxX;
float maxY;

if (numShifts > 1) // multiple shifts, find extents of build plate content
{
float minXshift = shifts[0][0];
float maxXshift = shifts[0][0];
float minYshift = shifts[0][1];
float maxYshift = shifts[0][1];

for (int i = 1; i < numShifts; i++)
{
double *shift = shifts[i];
if (shift[0] < minXshift)
minXshift = shift[0];
if (shift[0] > maxXshift)
maxXshift = shift[0];
if (shift[1] < minYshift)
minYshift = shift[1];
if (shift[1] > maxYshift)
maxYshift = shift[1];
}
minX = origX + minXshift;
minY = origY + minYshift;
maxX = origX + maxXshift;
maxY = origY + maxYshift;
}
else // only one shift
{
minX = origX + shifts[0][0];
maxX = minX;
minY = origY + shifts[0][1];
maxY = minY;
}
// - Calculate newW = (maxX+W)-minX
// - Calculate newH = (maxY+H)-minY
float newW = maxX + origW - minX;
float newH = maxY + origH - minY;

// - Write new M555 X<minX> Y<minY> W<newW> H<newH>
out << "M555 X" << roundTo(3, minX) << " Y" << roundTo(3, minY) << " W" << roundTo(3, newW) << " H" << roundTo(3, newH) << " ;TRANSLATE-MODEL_BED_AREA" << lineEnd;
}
else if (std::regex_match(line, start))
{
afterStart = true;
out << line << lineEnd << ";TRANSLATE-MODEL_LAYER_START" << lineEnd;
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
plugin_name = "OctoPrint-TranslateModel"

# The plugin's version. Can be overwritten within OctoPrint's internal data via __plugin_version__ in the plugin module
plugin_version = "0.2.2"
plugin_version = "0.3.0"

# The plugin's description. Can be overwritten within OctoPrint's internal data via __plugin_description__ in the plugin
# module
Expand Down

0 comments on commit cc9c482

Please sign in to comment.