Created
July 2, 2018 20:28
-
-
Save inkychris/e6e95b0c98583b3e20195844f266a606 to your computer and use it in GitHub Desktop.
3D Printing: Python script to generate a bed levelling gcode file for moving the print head sequentially around the build-plate to aid in bed levelling.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# All values are in mm | |
bed_x_max = 200 | |
bed_y_max = 200 | |
z_hop = 1 | |
inset = 40 # distance in from edges of buildplate to stop at | |
wait_time = 10 # seconds | |
repetitions = 5 # Number of times to visit each coordinate | |
bed_temp = 55 # Bed temperature in Degrees C | |
file_name = "bed-levelling-{}.gcode".format(inset) | |
corner_coordinates = [ | |
[0, 0], | |
[bed_x_max, bed_y_max], | |
[0, bed_y_max], | |
[bed_x_max, 0] | |
] | |
with open(file_name, "w") as gcode: | |
gcode.write( | |
"""\ | |
M140 S{bed_temp} ;Start heating the buildplate | |
G28 ;Home | |
M190 S{bed_temp} ;Wait for buildplate temp | |
G90 ;Absolute positioning | |
; Main loop | |
""".format(bed_temp=bed_temp) | |
) | |
for index in range(0, repetitions): | |
for coord_number, coord in enumerate(corner_coordinates): | |
# Inset x coordinates | |
if coord[0] < (bed_x_max / 2): | |
x_coord = inset | |
else: | |
x_coord = bed_x_max - inset | |
# Inset y coordinates | |
if coord[1] < (bed_y_max / 2): | |
y_coord = inset | |
else: | |
y_coord = bed_y_max - inset | |
with open(file_name, "a") as gcode: | |
gcode.write( | |
"""\ | |
G1 Z1 | |
G1 X{x} Y{y} | |
G28 Z0 | |
M117 {i_n}/{it} - {cn}/{ct} | |
G4 S{t} | |
""".format(x=x_coord, y=y_coord, t=wait_time, i_n=index + 1, it=repetitions, | |
cn=coord_number + 1, ct=corner_coordinates.__len__()) | |
) | |
with open(file_name, "a") as gcode: | |
gcode.write( | |
"""\ | |
; End | |
G1 Z1 | |
G28 | |
""" | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment