mirror of https://github.com/Desuuuu/klipper.git
stepper: Query the stepper mcu position during startup
Try to keep the host mcu_position synchronized with the micro-controller by querying during startup and after every homing event. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
parent
33dcb38297
commit
24586f0c31
|
@ -424,11 +424,10 @@ Recv: // gcode homing: X:0.000000 Y:0.000000 Z:0.000000
|
||||||
The "mcu" position (`stepper.get_mcu_position()` in the code) is the
|
The "mcu" position (`stepper.get_mcu_position()` in the code) is the
|
||||||
total number of steps the micro-controller has issued in a positive
|
total number of steps the micro-controller has issued in a positive
|
||||||
direction minus the number of steps issued in a negative direction
|
direction minus the number of steps issued in a negative direction
|
||||||
since the micro-controller was last reset. The value reported is only
|
since the micro-controller was last reset. If the robot is in motion
|
||||||
valid after the stepper has been homed. If the robot is in motion when
|
when the query is issued then the reported value includes moves
|
||||||
the query is issued then the reported value includes moves buffered on
|
buffered on the micro-controller, but does not include moves on the
|
||||||
the micro-controller, but does not include moves on the look-ahead
|
look-ahead queue.
|
||||||
queue.
|
|
||||||
|
|
||||||
The "stepper" position (`stepper.get_commanded_position()`) is the
|
The "stepper" position (`stepper.get_commanded_position()`) is the
|
||||||
position of the given stepper as tracked by the kinematics code. This
|
position of the given stepper as tracked by the kinematics code. This
|
||||||
|
|
|
@ -122,7 +122,7 @@ class MCU_trsync:
|
||||||
params = self._trsync_query_cmd.send([self._oid,
|
params = self._trsync_query_cmd.send([self._oid,
|
||||||
self.REASON_HOST_REQUEST])
|
self.REASON_HOST_REQUEST])
|
||||||
for s in self._steppers:
|
for s in self._steppers:
|
||||||
s.note_homing_end(did_trigger=True) # XXX
|
s.note_homing_end()
|
||||||
return params['trigger_reason']
|
return params['trigger_reason']
|
||||||
|
|
||||||
class MCU_endstop:
|
class MCU_endstop:
|
||||||
|
|
|
@ -42,6 +42,8 @@ class MCU_stepper:
|
||||||
self._itersolve_generate_steps = ffi_lib.itersolve_generate_steps
|
self._itersolve_generate_steps = ffi_lib.itersolve_generate_steps
|
||||||
self._itersolve_check_active = ffi_lib.itersolve_check_active
|
self._itersolve_check_active = ffi_lib.itersolve_check_active
|
||||||
self._trapq = ffi_main.NULL
|
self._trapq = ffi_main.NULL
|
||||||
|
self._mcu.get_printer().register_event_handler('klippy:connect',
|
||||||
|
self._query_mcu_position)
|
||||||
def get_mcu(self):
|
def get_mcu(self):
|
||||||
return self._mcu
|
return self._mcu
|
||||||
def get_name(self, short=False):
|
def get_name(self, short=False):
|
||||||
|
@ -136,7 +138,7 @@ class MCU_stepper:
|
||||||
self.set_trapq(self._trapq)
|
self.set_trapq(self._trapq)
|
||||||
self._set_mcu_position(mcu_pos)
|
self._set_mcu_position(mcu_pos)
|
||||||
return old_sk
|
return old_sk
|
||||||
def note_homing_end(self, did_trigger=False):
|
def note_homing_end(self):
|
||||||
ffi_main, ffi_lib = chelper.get_ffi()
|
ffi_main, ffi_lib = chelper.get_ffi()
|
||||||
ret = ffi_lib.stepcompress_reset(self._stepqueue, 0)
|
ret = ffi_lib.stepcompress_reset(self._stepqueue, 0)
|
||||||
if ret:
|
if ret:
|
||||||
|
@ -145,7 +147,9 @@ class MCU_stepper:
|
||||||
ret = ffi_lib.stepcompress_queue_msg(self._stepqueue, data, len(data))
|
ret = ffi_lib.stepcompress_queue_msg(self._stepqueue, data, len(data))
|
||||||
if ret:
|
if ret:
|
||||||
raise error("Internal error in stepcompress")
|
raise error("Internal error in stepcompress")
|
||||||
if not did_trigger or self._mcu.is_fileoutput():
|
self._query_mcu_position()
|
||||||
|
def _query_mcu_position(self):
|
||||||
|
if self._mcu.is_fileoutput():
|
||||||
return
|
return
|
||||||
params = self._get_position_cmd.send([self._oid])
|
params = self._get_position_cmd.send([self._oid])
|
||||||
last_pos = params['pos']
|
last_pos = params['pos']
|
||||||
|
@ -153,6 +157,7 @@ class MCU_stepper:
|
||||||
last_pos = -last_pos
|
last_pos = -last_pos
|
||||||
print_time = self._mcu.estimated_print_time(params['#receive_time'])
|
print_time = self._mcu.estimated_print_time(params['#receive_time'])
|
||||||
clock = self._mcu.print_time_to_clock(print_time)
|
clock = self._mcu.print_time_to_clock(print_time)
|
||||||
|
ffi_main, ffi_lib = chelper.get_ffi()
|
||||||
ret = ffi_lib.stepcompress_set_last_position(self._stepqueue, clock,
|
ret = ffi_lib.stepcompress_set_last_position(self._stepqueue, clock,
|
||||||
last_pos)
|
last_pos)
|
||||||
if ret:
|
if ret:
|
||||||
|
|
Loading…
Reference in New Issue