query_endstops: Move QUERY_ENDSTOP command to it own extras/ module

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor 2018-07-16 10:06:30 -04:00
parent 28fa954487
commit 89835940f7
5 changed files with 47 additions and 23 deletions

View File

@ -0,0 +1,34 @@
# Utility for querying the current state of all endstops
#
# Copyright (C) 2018 Kevin O'Connor <kevin@koconnor.net>
#
# This file may be distributed under the terms of the GNU GPLv3 license.
class QueryEndstops:
def __init__(self, config):
self.printer = config.get_printer()
self.endstops = []
gcode = self.printer.lookup_object('gcode')
gcode.register_command("QUERY_ENDSTOPS", self.cmd_QUERY_ENDSTOPS,
desc=self.cmd_QUERY_ENDSTOPS_help)
gcode.register_command("M119", self.cmd_QUERY_ENDSTOPS)
def register_endstop(self, mcu_endstop, name):
self.endstops.append((mcu_endstop, name))
cmd_QUERY_ENDSTOPS_help = "Report on the status of each endstop"
def cmd_QUERY_ENDSTOPS(self, params):
toolhead = self.printer.lookup_object('toolhead')
print_time = toolhead.get_last_move_time()
# Query the endstops
for mcu_endstop, name in self.endstops:
mcu_endstop.query_endstop(print_time)
out = []
for mcu_endstop, name in self.endstops:
out.append((name, mcu_endstop.query_endstop_wait()))
# Report results
msg = " ".join(["%s:%s" % (name, ["open", "TRIGGERED"][not not t])
for name, t in out])
gcode = self.printer.lookup_object('gcode')
gcode.respond(msg)
def load_config(config):
return QueryEndstops(config)

View File

@ -425,7 +425,7 @@ class GCodeParser:
'G20', 'M82', 'M83', 'G90', 'G91', 'G92', 'M114', 'M220', 'M221',
'SET_GCODE_OFFSET', 'M206',
'M105', 'M104', 'M109', 'M140', 'M190', 'M106', 'M107',
'M112', 'M115', 'IGNORE', 'QUERY_ENDSTOPS', 'GET_POSITION',
'M112', 'M115', 'IGNORE', 'GET_POSITION',
'RESTART', 'FIRMWARE_RESTART', 'ECHO', 'STATUS', 'HELP']
# G-Code movement commands
cmd_G1_aliases = ['G0']
@ -596,13 +596,6 @@ class GCodeParser:
def cmd_IGNORE(self, params):
# Commands that are just silently accepted
pass
cmd_QUERY_ENDSTOPS_help = "Report on the status of each endstop"
cmd_QUERY_ENDSTOPS_aliases = ["M119"]
def cmd_QUERY_ENDSTOPS(self, params):
# Get Endstop Status
res = homing.query_endstops(self.toolhead)
self.respond(" ".join(["%s:%s" % (name, ["open", "TRIGGERED"][not not t])
for name, t in res]))
cmd_GET_POSITION_when_not_ready = True
def cmd_GET_POSITION(self, params):
if self.toolhead is None:

View File

@ -116,18 +116,6 @@ class Homing:
self.toolhead.motor_off()
raise
def query_endstops(toolhead):
print_time = toolhead.get_last_move_time()
rails = toolhead.get_kinematics().get_rails()
out = []
for rail in rails:
for mcu_endstop, name in rail.get_endstops():
mcu_endstop.query_endstop(print_time)
for rail in rails:
for mcu_endstop, name in rail.get_endstops():
out.append((name, mcu_endstop.query_endstop_wait()))
return out
class EndstopError(Exception):
pass

View File

@ -112,7 +112,8 @@ class PrinterRail:
self.get_commanded_position = stepper.get_commanded_position
self.is_motor_enabled = stepper.is_motor_enabled
# Primary endstop and its position
ppins = config.get_printer().lookup_object('pins')
printer = config.get_printer()
ppins = printer.lookup_object('pins')
mcu_endstop = ppins.setup_pin('endstop', config.get('endstop_pin'))
self.endstops = [(mcu_endstop, self.name)]
stepper.add_to_endstop(mcu_endstop)
@ -121,6 +122,8 @@ class PrinterRail:
else:
self.position_endstop = config.getfloat(
'position_endstop', default_position_endstop)
query_endstops = printer.try_load_module(config, 'query_endstops')
query_endstops.register_endstop(mcu_endstop, self.name)
# Axis range
if need_position_minmax:
self.position_min = config.getfloat('position_min', 0.)
@ -225,9 +228,13 @@ class PrinterRail:
mcu_endstop = self.endstops[0][0]
endstop_pin = config.get('endstop_pin', None)
if endstop_pin is not None:
ppins = config.get_printer().lookup_object('pins')
printer = config.get_printer()
ppins = printer.lookup_object('pins')
mcu_endstop = ppins.setup_pin('endstop', endstop_pin)
self.endstops.append((mcu_endstop, stepper.get_name(short=True)))
name = stepper.get_name(short=True)
self.endstops.append((mcu_endstop, name))
query_endstops = printer.try_load_module(config, 'query_endstops')
query_endstops.register_endstop(mcu_endstop, name)
stepper.add_to_endstop(mcu_endstop)
def add_to_endstop(self, mcu_endstop):
for stepper in self.steppers:

View File

@ -27,6 +27,8 @@ G91
G1 X20 E.2
G90
QUERY_ENDSTOPS
# Servo tests
SET_SERVO servo=my_servo angle=160
SET_SERVO servo=my_servo angle=130