Skip to content
This repository has been archived by the owner on May 16, 2020. It is now read-only.

Added Klipper support #29

Open
wants to merge 55 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
ac33159
Added Klipper memes
mcm001 Sep 24, 2018
3afba8a
Added comments
mcm001 Sep 24, 2018
fdaec91
fixed indent
mcm001 Sep 24, 2018
18f7c26
whackamole
mcm001 Sep 24, 2018
33fbefa
oofOuchMyJson
mcm001 Sep 24, 2018
d055b88
maybe
mcm001 Sep 24, 2018
d8c79df
no me gusta Vim - rolled back indents
mcm001 Sep 24, 2018
5fed225
Update __init__.py
mcm001 Sep 24, 2018
2325e53
Update __init__.py
mcm001 Sep 24, 2018
834e90f
its working for me...
mcm001 Sep 24, 2018
3b13826
Confirmed working with Octoprint, test code commented out
mcm001 Sep 24, 2018
8926edb
Quotation mark
mcm001 Sep 24, 2018
9b8fa54
Fixed line 37 indentation
mcm001 Sep 25, 2018
e47cbab
Indentation fixed
mcm001 Sep 25, 2018
be276e1
Added MK52 Mode
mcm001 Sep 25, 2018
c6d9d0c
MK52 Mode support added
mcm001 Sep 25, 2018
fb0ee3b
MK52 Mode support maybe
mcm001 Sep 25, 2018
6165bc0
Update __init__.py
mcm001 Sep 25, 2018
7888aaf
Fixed syntax
mcm001 Sep 25, 2018
a123d43
Git commit for mk52 testing
mcm001 Sep 25, 2018
ef4424c
Fixed indentation errors
mcm001 Sep 25, 2018
cfcdfb6
Added standoffs
mcm001 Sep 25, 2018
019dd7c
Fixed variable names
mcm001 Sep 25, 2018
66c3e83
Removed unused variables
mcm001 Sep 25, 2018
427d538
Update __init__.py
mcm001 Sep 25, 2018
37c0a96
Update PrusaMeshMap_settings.jinja2
mcm001 Sep 25, 2018
ff02afa
Testing Mode
mcm001 Sep 28, 2018
9a1df7a
Updated test mode
mcm001 Sep 28, 2018
eb0660e
added an error
mcm001 Sep 29, 2018
fca6912
Fixed induced error
mcm001 Sep 29, 2018
87ab913
try clearing the screen after saving klipper fig to fix range bar glitch
mcm001 Oct 1, 2018
2f082a3
add more plt clears to fix glitch
mcm001 Oct 1, 2018
1956e2c
added 2nd subplot with contourf
mcm001 Oct 1, 2018
5f93b32
added 2nd color bar
mcm001 Oct 1, 2018
45f8b6e
Added moure features to contourf including mk52 sheet
mcm001 Oct 1, 2018
af4cd81
Added standoffs, tweaked contourf stuff
mcm001 Oct 1, 2018
9b695ba
inverted y axis
mcm001 Oct 1, 2018
72c6a77
Tight layout
mcm001 Oct 1, 2018
861fea5
Tight layout
mcm001 Oct 1, 2018
d49060f
remove tight lahyout
mcm001 Oct 1, 2018
6ab1de2
try tight layout
mcm001 Oct 1, 2018
a49b274
Merge branch 'master' of https://github.com/mcm001/OctoPrint-PrusaMes…
mcm001 Oct 4, 2018
23fd132
Disabled testing mode
mcm001 Oct 4, 2018
a4c9708
set default bed level gcode to Klipper bed_mesh_map
mcm001 Oct 4, 2018
445f934
Added switchable mode
mcm001 Oct 5, 2018
7b9f14e
added test mode switch
mcm001 Oct 5, 2018
ae3687b
fixed a typo
mcm001 Oct 5, 2018
0a5124d
more UI fixes
mcm001 Oct 5, 2018
25a7f6a
More changes to UI
mcm001 Oct 5, 2018
6608bcc
fixed function call
mcm001 Oct 5, 2018
379030c
Fixed self.get_current_settings()["pluginTestingMode"]
mcm001 Oct 5, 2018
bf95725
fixed typo with self
mcm001 Oct 5, 2018
4eedfd0
reversed array
mcm001 Oct 13, 2018
b31af29
fixed the silly flip, fixed bicubic/contourf reversal
mcm001 Nov 26, 2018
5fcee70
syntax error fixed
mcm001 Nov 26, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
its working for me...
  • Loading branch information
mcm001 committed Sep 24, 2018
commit 834e90f61cb42b60d2effa0a322675cdbd76b759
124 changes: 62 additions & 62 deletions octoprint_PrusaMeshMap/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,17 +87,17 @@ def get_update_information(self):

def mesh_level_check(self, comm, line, *args, **kwargs):
if re.match(r"^( -?\d+.\d+)+$", line):
self.mesh_level_responses.append(line)
self._logger.info("FOUND: " + line)\
self.mesh_level_generate()
return line
elif line.startswith("mesh_map_output"):
klipper_json_line = line
self._logger.info("Klipper meme aquired. Ready the matplotlibs: " + line)
self.generate_graph_klipper_mode(klipper_json_line)
return line
else:
return line
self.mesh_level_responses.append(line)
self._logger.info("FOUND: " + line)
self.mesh_level_generate() #meme
return line
elif line.startswith("mesh_map_output"):
klipper_json_line = line
self._logger.info("Klipper meme aquired. Ready the matplotlibs: " + line)
self.generate_graph_klipper_mode(klipper_json_line)
return line
else:
return line

# Klipper mode heatmap generation. Above brig's stuff because it's better :D

Expand Down Expand Up @@ -127,33 +127,33 @@ def generate_graph_klipper_mode(self,klipper_json_line):
BED_PRINT_ZERO_REF_Y = 9.4
SHEET_OFFS_X = 0
SHEET_OFFS_Y = 0
SHEET_MARGIN_LEFT = 0
SHEET_MARGIN_RIGHT = 0
SHEET_MARGIN_FRONT = 17
SHEET_MARGIN_BACK = 14
sheet_left_x = -(SHEET_MARGIN_LEFT + SHEET_OFFS_X)
sheet_right_x = sheet_left_x + BED_SIZE_X + SHEET_MARGIN_LEFT + SHEET_MARGIN_RIGHT
sheet_front_y = -(SHEET_MARGIN_FRONT + SHEET_OFFS_Y)
sheet_back_y = sheet_front_y + BED_SIZE_Y + SHEET_MARGIN_FRONT + SHEET_MARGIN_BACK
SHEET_MARGIN_LEFT = 0
SHEET_MARGIN_RIGHT = 0
SHEET_MARGIN_FRONT = 17
SHEET_MARGIN_BACK = 14
sheet_left_x = -(SHEET_MARGIN_LEFT + SHEET_OFFS_X)
sheet_right_x = sheet_left_x + BED_SIZE_X + SHEET_MARGIN_LEFT + SHEET_MARGIN_RIGHT
sheet_front_y = -(SHEET_MARGIN_FRONT + SHEET_OFFS_Y)
sheet_back_y = sheet_front_y + BED_SIZE_Y + SHEET_MARGIN_FRONT + SHEET_MARGIN_BACK

#Define probe points to plot and meshgridify them
x=np.linspace(minPoints[0],maxPoints[0],z_positions_shape[1],endpoint=True)
y=np.linspace(minPoints[1],maxPoints[1],z_positions_shape[0],endpoint=True)
x, y = np.meshgrid(x,y)
y=np.linspace(minPoints[1],maxPoints[1],z_positions_shape[0],endpoint=True)
x, y = np.meshgrid(x,y)

#Plot all of the things, including the mk52 back
img = mpimg.imread(r'C:\Users\matth\Documents\GitHub\OctoPrint-PrusaMeshMap\octoprint_PrusaMeshMap\static\img\mk52_steel_sheet.png')
plt.imshow(img, extent=[sheet_left_x, sheet_right_x, sheet_front_y, sheet_back_y], interpolation="lanczos", cmap=plt.cm.get_cmap('viridis'))

#plot the interpolated mesh, bar, and probed points
image = plt.imshow(z_positions,interpolation='bicubic',cmap='viridis',extent=minMax)#Plot the background
plt.colorbar(image,label="Measured Level (mm)")#Color bar on the side
plt.scatter(x,y,color='r')#Scatterplot of probed points
plt.colorbar(image,label="Measured Level (mm)")#Color bar on the side
plt.scatter(x,y,color='r')#Scatterplot of probed points

#Add fancy titles
plt.title("Mesh Level: " + datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"))
plt.xlabel("X Axis (mm)")
plt.ylabel("Y Axis (mm)")
plt.ylabel("Y Axis (mm)")

# Save our graph as an image in the current directory.
fig.savefig(self.get_asset_folder() + '/img/heatmap.png', bbox_inches="tight")
Expand Down Expand Up @@ -222,87 +222,87 @@ def mesh_level_generate(self):

# Accumulate response lines until we have all of them
if len(self.mesh_level_responses) == MESH_NUM_POINTS_Y:
self._logger.info("Generating heatmap")
self._logger.info("Generating heatmap")

# TODO: Validate each row has MESH_NUM_POINTS_X values
# TODO: Validate each row has MESH_NUM_POINTS_X values
mesh_values = []

# Parse response lines into a 2D array of floats in row-major order
for response in self.mesh_level_responses:
response = re.sub(r"^[ ]+", "", response)
response = re.sub(r"[ ]+", ",", response)
mesh_values.append([float(i) for i in response.split(",")])
mesh_values.append([float(i) for i in response.split(",")])

# Generate a 2D array of the Z values in column-major order
col_i = 0
mesh_z = np.zeros(shape=(7,7))
for col in mesh_values:
row_i = 0
for val in col:
mesh_z[col_i][row_i] = val
row_i = row_i + 1
col_i = col_i + 1
for col in mesh_values:
row_i = 0
for val in col:
mesh_z[col_i][row_i] = val
row_i = row_i + 1
col_i = col_i + 1

# Calculate the X and Y values of the mesh bed points, in print area coordinates
mesh_x = np.zeros(MESH_NUM_POINTS_X)
for i in range(0, MESH_NUM_POINTS_X):
mesh_x[i] = MESH_FRONT_LEFT_X + mesh_delta_x*i
mesh_x = np.zeros(MESH_NUM_POINTS_X)
for i in range(0, MESH_NUM_POINTS_X):
mesh_x[i] = MESH_FRONT_LEFT_X + mesh_delta_x*i

mesh_y = np.zeros(MESH_NUM_POINTS_Y)
for i in range(0, MESH_NUM_POINTS_Y):
mesh_y[i] = MESH_FRONT_LEFT_Y + mesh_delta_y*i
mesh_y = np.zeros(MESH_NUM_POINTS_Y)
for i in range(0, MESH_NUM_POINTS_Y):
mesh_y[i] = MESH_FRONT_LEFT_Y + mesh_delta_y*i

bed_variance = round(mesh_z.max() - mesh_z.min(), 3)
bed_variance = round(mesh_z.max() - mesh_z.min(), 3)

############
# Draw the heatmap
#fig = plt.figure(dpi=96, figsize=(12, 9))
fig = plt.figure(dpi=96, figsize=(10,8.3))
ax = plt.gca()
fig = plt.figure(dpi=96, figsize=(10,8.3))
ax = plt.gca()

# Plot all mesh points, including measured ones and the ones
# that are bogus (calculated). Indicate the actual measured
# points with a different marker.
for x_i in range(0, len(mesh_x)):
for y_i in range(0, len(mesh_y)):
if ((x_i % MESH_NUM_MEASURED_POINTS_X) == 0) and ((y_i % MESH_NUM_MEASURED_POINTS_Y) == 0):
plt.plot(mesh_x[x_i], mesh_y[y_i], 'o', color='m')
else:
plt.plot(mesh_x[x_i], mesh_y[y_i], '.', color='k')
for x_i in range(0, len(mesh_x)):
for y_i in range(0, len(mesh_y)):
if ((x_i % MESH_NUM_MEASURED_POINTS_X) == 0) and ((y_i % MESH_NUM_MEASURED_POINTS_Y) == 0):
plt.plot(mesh_x[x_i], mesh_y[y_i], 'o', color='m')
else:
plt.plot(mesh_x[x_i], mesh_y[y_i], '.', color='k')

# Draw the contour map. Y values are reversed to account for
# bottom-up orientation of plot library
contour = plt.contourf(mesh_x, mesh_y[::-1], mesh_z, alpha=.75, antialiased=True, cmap=plt.cm.get_cmap(self._settings.get(["matplotlib_heatmap_theme"])))
contour = plt.contourf(mesh_x, mesh_y[::-1], mesh_z, alpha=.75, antialiased=True, cmap=plt.cm.get_cmap(self._settings.get(["matplotlib_heatmap_theme"])))

# Insert the background image (currently an image of the MK3 PEI-coated steel sheet)
img = mpimg.imread(self.get_asset_folder() + '/img/mk52_steel_sheet.png')
plt.imshow(img, extent=[sheet_left_x, sheet_right_x, sheet_front_y, sheet_back_y], interpolation="lanczos", cmap=plt.cm.get_cmap(self._settings.get(["matplotlib_heatmap_theme"])))
img = mpimg.imread(self.get_asset_folder() + '/img/mk52_steel_sheet.png')
plt.imshow(img, extent=[sheet_left_x, sheet_right_x, sheet_front_y, sheet_back_y], interpolation="lanczos", cmap=plt.cm.get_cmap(self._settings.get(["matplotlib_heatmap_theme"])))

# Set axis ranges (although we don't currently show these...)
ax.set_xlim(left=sheet_left_x, right=sheet_right_x)
ax.set_ylim(bottom=sheet_front_y, top=sheet_back_y)
ax.set_xlim(left=sheet_left_x, right=sheet_right_x)
ax.set_ylim(bottom=sheet_front_y, top=sheet_back_y)

# Set various options about the graph image before
# we generate it. Things like labeling the axes and
# colorbar, and setting the X axis label/ticks to
# the top to better match the G81 output.
plt.title("Mesh Level: " + datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"))
plt.axis('image')
plt.title("Mesh Level: " + datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"))
plt.axis('image')
#ax.axes.get_xaxis().set_visible(True)
#ax.axes.get_yaxis().set_visible(True)
plt.xlabel("X Axis (mm)")
plt.ylabel("Y Axis (mm)")
plt.xlabel("X Axis (mm)")
plt.ylabel("Y Axis (mm)")

#plt.colorbar(label="Bed Variance: " + str(round(mesh_z.max() - mesh_z.min(), 3)) + "mm")
plt.colorbar(contour, label="Measured Level (mm)")
plt.colorbar(contour, label="Measured Level (mm)")

plt.text(0.5, 0.43, "Total Bed Variance: " + str(bed_variance) + " (mm)", fontsize=10, horizontalalignment='center', verticalalignment='center', transform=ax.transAxes, bbox=dict(facecolor='#eeefff', alpha=0.5))
plt.text(0.5, 0.43, "Total Bed Variance: " + str(bed_variance) + " (mm)", fontsize=10, horizontalalignment='center', verticalalignment='center', transform=ax.transAxes, bbox=dict(facecolor='#eeefff', alpha=0.5))

# Save our graph as an image in the current directory.
fig.savefig(self.get_asset_folder() + '/img/heatmap.png', bbox_inches="tight")
self._logger.info("Heatmap updated")
fig.savefig(self.get_asset_folder() + '/img/heatmap.png', bbox_inches="tight")
self._logger.info("Heatmap updated")

del self.mesh_level_responses[:]
del self.mesh_level_responses[:]


# If you want your plugin to be registered within OctoPrint under a different name than what you defined in setup.py
Expand Down