diff options
Diffstat (limited to 'klippy/extras/bed_screws.py')
-rw-r--r-- | klippy/extras/bed_screws.py | 81 |
1 files changed, 51 insertions, 30 deletions
diff --git a/klippy/extras/bed_screws.py b/klippy/extras/bed_screws.py index c3446191..28be0e16 100644 --- a/klippy/extras/bed_screws.py +++ b/klippy/extras/bed_screws.py @@ -4,6 +4,7 @@ # # This file may be distributed under the terms of the GNU GPLv3 license. + class BedScrews: def __init__(self, config): self.printer = config.get_printer() @@ -27,27 +28,32 @@ class BedScrews: if len(screws) < 3: raise config.error("bed_screws: Must have at least three screws") self.number_of_screws = len(screws) - self.states = {'adjust': screws, 'fine': fine_adjust} - self.speed = config.getfloat('speed', 50., above=0.) - self.lift_speed = config.getfloat('probe_speed', 5., above=0.) - self.horizontal_move_z = config.getfloat('horizontal_move_z', 5.) - self.probe_z = config.getfloat('probe_height', 0.) + self.states = {"adjust": screws, "fine": fine_adjust} + self.speed = config.getfloat("speed", 50.0, above=0.0) + self.lift_speed = config.getfloat("probe_speed", 5.0, above=0.0) + self.horizontal_move_z = config.getfloat("horizontal_move_z", 5.0) + self.probe_z = config.getfloat("probe_height", 0.0) # Register command - self.gcode = self.printer.lookup_object('gcode') - self.gcode.register_command("BED_SCREWS_ADJUST", - self.cmd_BED_SCREWS_ADJUST, - desc=self.cmd_BED_SCREWS_ADJUST_help) + self.gcode = self.printer.lookup_object("gcode") + self.gcode.register_command( + "BED_SCREWS_ADJUST", + self.cmd_BED_SCREWS_ADJUST, + desc=self.cmd_BED_SCREWS_ADJUST_help, + ) + def reset(self): self.state = None self.current_screw = 0 self.accepted_screws = 0 + def move(self, coord, speed): try: - self.printer.lookup_object('toolhead').manual_move(coord, speed) + self.printer.lookup_object("toolhead").manual_move(coord, speed) except self.printer.command_error as e: self.unregister_commands() self.reset() raise + def move_to_screw(self, state, screw): # Move up, over, and then down self.move((None, None, self.horizontal_move_z), self.lift_speed) @@ -60,64 +66,79 @@ class BedScrews: # Register commands self.gcode.respond_info( "Adjust %s. Then run ACCEPT, ADJUSTED, or ABORT\n" - "Use ADJUSTED if a significant screw adjustment is made" % (name,)) - self.gcode.register_command('ACCEPT', self.cmd_ACCEPT, - desc=self.cmd_ACCEPT_help) - self.gcode.register_command('ADJUSTED', self.cmd_ADJUSTED, - desc=self.cmd_ADJUSTED_help) - self.gcode.register_command('ABORT', self.cmd_ABORT, - desc=self.cmd_ABORT_help) + "Use ADJUSTED if a significant screw adjustment is made" % (name,) + ) + self.gcode.register_command( + "ACCEPT", self.cmd_ACCEPT, desc=self.cmd_ACCEPT_help + ) + self.gcode.register_command( + "ADJUSTED", self.cmd_ADJUSTED, desc=self.cmd_ADJUSTED_help + ) + self.gcode.register_command("ABORT", self.cmd_ABORT, desc=self.cmd_ABORT_help) + def unregister_commands(self): - self.gcode.register_command('ACCEPT', None) - self.gcode.register_command('ADJUSTED', None) - self.gcode.register_command('ABORT', None) + self.gcode.register_command("ACCEPT", None) + self.gcode.register_command("ADJUSTED", None) + self.gcode.register_command("ABORT", None) + def get_status(self, eventtime): return { - 'is_active': self.state is not None, - 'state': self.state, - 'current_screw': self.current_screw, - 'accepted_screws': self.accepted_screws + "is_active": self.state is not None, + "state": self.state, + "current_screw": self.current_screw, + "accepted_screws": self.accepted_screws, } + cmd_BED_SCREWS_ADJUST_help = "Tool to help adjust bed leveling screws" + def cmd_BED_SCREWS_ADJUST(self, gcmd): if self.state is not None: raise gcmd.error("Already in bed_screws helper; use ABORT to exit") # reset accepted screws self.accepted_screws = 0 self.move((None, None, self.horizontal_move_z), self.speed) - self.move_to_screw('adjust', 0) + self.move_to_screw("adjust", 0) + cmd_ACCEPT_help = "Accept bed screw position" + def cmd_ACCEPT(self, gcmd): self.unregister_commands() self.accepted_screws = self.accepted_screws + 1 - if self.current_screw + 1 < len(self.states[self.state]) \ - and self.accepted_screws < self.number_of_screws: + if ( + self.current_screw + 1 < len(self.states[self.state]) + and self.accepted_screws < self.number_of_screws + ): # Continue with next screw self.move_to_screw(self.state, self.current_screw + 1) return if self.accepted_screws < self.number_of_screws: # Retry coarse adjustments - self.move_to_screw('adjust', 0) + self.move_to_screw("adjust", 0) return - if self.state == 'adjust' and self.states['fine']: + if self.state == "adjust" and self.states["fine"]: # Reset accepted screws for fine adjustment self.accepted_screws = 0 # Perform fine screw adjustments - self.move_to_screw('fine', 0) + self.move_to_screw("fine", 0) return # Done self.reset() self.move((None, None, self.horizontal_move_z), self.lift_speed) gcmd.respond_info("Bed screws tool completed successfully") + cmd_ADJUSTED_help = "Accept bed screw position after notable adjustment" + def cmd_ADJUSTED(self, gcmd): self.unregister_commands() self.accepted_screws = -1 self.cmd_ACCEPT(gcmd) + cmd_ABORT_help = "Abort bed screws tool" + def cmd_ABORT(self, gcmd): self.unregister_commands() self.reset() + def load_config(config): return BedScrews(config) |