homing: Implement second home from homing.py
Move the logic for performing the second home from the kinematics classes to the generic homing code. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
parent
3db483e270
commit
d4bf51231a
|
@ -50,8 +50,10 @@ class PrinterProbe:
|
||||||
homing_state = homing.Homing(toolhead)
|
homing_state = homing.Homing(toolhead)
|
||||||
pos = toolhead.get_position()
|
pos = toolhead.get_position()
|
||||||
pos[2] = self.z_position
|
pos[2] = self.z_position
|
||||||
|
endstops = [(self.mcu_probe, "probe")]
|
||||||
try:
|
try:
|
||||||
homing_state.probing_move(pos, self.mcu_probe, self.speed)
|
homing_state.homing_move(pos, endstops, self.speed,
|
||||||
|
probe_pos=True, verify_movement=True)
|
||||||
except homing.EndstopError as e:
|
except homing.EndstopError as e:
|
||||||
reason = str(e)
|
reason = str(e)
|
||||||
if "Timeout during endstop homing" in reason:
|
if "Timeout during endstop homing" in reason:
|
||||||
|
|
|
@ -27,21 +27,23 @@ class Homing:
|
||||||
if coord[i] is not None:
|
if coord[i] is not None:
|
||||||
thcoord[i] = coord[i]
|
thcoord[i] = coord[i]
|
||||||
return thcoord
|
return thcoord
|
||||||
def retract(self, newpos, speed):
|
|
||||||
self.toolhead.move(self._fill_coord(newpos), speed)
|
|
||||||
def set_homed_position(self, pos):
|
def set_homed_position(self, pos):
|
||||||
self.toolhead.set_position(self._fill_coord(pos))
|
self.toolhead.set_position(self._fill_coord(pos))
|
||||||
def _get_homing_speed(self, speed, endstops):
|
def _get_homing_speed(self, speed, endstops):
|
||||||
# Round the requested homing speed so that it is an even
|
# Round the requested homing speed so that it is an even
|
||||||
# number of ticks per step.
|
# number of ticks per step.
|
||||||
speed = min(speed, self.toolhead.get_max_velocity()[0])
|
|
||||||
mcu_stepper = endstops[0][0].get_steppers()[0]
|
mcu_stepper = endstops[0][0].get_steppers()[0]
|
||||||
adjusted_freq = mcu_stepper.get_mcu().get_adjusted_freq()
|
adjusted_freq = mcu_stepper.get_mcu().get_adjusted_freq()
|
||||||
dist_ticks = adjusted_freq * mcu_stepper.get_step_dist()
|
dist_ticks = adjusted_freq * mcu_stepper.get_step_dist()
|
||||||
ticks_per_step = math.ceil(dist_ticks / speed)
|
ticks_per_step = math.ceil(dist_ticks / speed)
|
||||||
return dist_ticks / ticks_per_step
|
return dist_ticks / ticks_per_step
|
||||||
def _homing_move(self, movepos, endstops, speed,
|
def homing_move(self, movepos, endstops, speed, dwell_t=0.,
|
||||||
probe_pos=False, verify_movement=False):
|
probe_pos=False, verify_movement=False):
|
||||||
|
# Notify endstops of upcoming home
|
||||||
|
for mcu_endstop, name in endstops:
|
||||||
|
mcu_endstop.home_prepare()
|
||||||
|
if dwell_t:
|
||||||
|
self.toolhead.dwell(dwell_t, check_stall=False)
|
||||||
# Start endstop checking
|
# Start endstop checking
|
||||||
print_time = self.toolhead.get_last_move_time()
|
print_time = self.toolhead.get_last_move_time()
|
||||||
start_mcu_pos = [(s, name, s.get_mcu_position())
|
start_mcu_pos = [(s, name, s.get_mcu_position())
|
||||||
|
@ -53,7 +55,6 @@ class Homing:
|
||||||
print_time, ENDSTOP_SAMPLE_TIME, ENDSTOP_SAMPLE_COUNT,
|
print_time, ENDSTOP_SAMPLE_TIME, ENDSTOP_SAMPLE_COUNT,
|
||||||
min_step_dist / speed)
|
min_step_dist / speed)
|
||||||
# Issue move
|
# Issue move
|
||||||
movepos = self._fill_coord(movepos)
|
|
||||||
error = None
|
error = None
|
||||||
try:
|
try:
|
||||||
self.toolhead.move(movepos, speed)
|
self.toolhead.move(movepos, speed)
|
||||||
|
@ -85,31 +86,43 @@ class Homing:
|
||||||
raise EndstopError("Probe triggered prior to movement")
|
raise EndstopError("Probe triggered prior to movement")
|
||||||
raise EndstopError(
|
raise EndstopError(
|
||||||
"Endstop %s still triggered after retract" % (name,))
|
"Endstop %s still triggered after retract" % (name,))
|
||||||
def probing_move(self, movepos, mcu_probe, speed):
|
def home_rails(self, rails, forcepos, movepos, limit_speed=None):
|
||||||
mcu_probe.home_prepare()
|
|
||||||
self._homing_move(movepos, [(mcu_probe, "probe")], speed,
|
|
||||||
probe_pos=True, verify_movement=True)
|
|
||||||
def home(self, forcepos, movepos, endstops, speed, second_home=False):
|
|
||||||
if second_home and forcepos == movepos:
|
|
||||||
return
|
|
||||||
# Alter kinematics class to think printer is at forcepos
|
# Alter kinematics class to think printer is at forcepos
|
||||||
homing_axes = [axis for axis in range(3) if forcepos[axis] is not None]
|
homing_axes = [axis for axis in range(3) if forcepos[axis] is not None]
|
||||||
self.toolhead.set_position(
|
forcepos = self._fill_coord(forcepos)
|
||||||
self._fill_coord(forcepos), homing_axes=homing_axes)
|
movepos = self._fill_coord(movepos)
|
||||||
# Notify endstops of upcoming home
|
self.toolhead.set_position(forcepos, homing_axes=homing_axes)
|
||||||
for mcu_endstop, name in endstops:
|
# Determine homing speed
|
||||||
mcu_endstop.home_prepare()
|
endstops = [es for rail in rails for es in rail.get_endstops()]
|
||||||
# Add a CPU delay when homing a large axis
|
hi = rails[0].get_homing_info()
|
||||||
if not second_home:
|
max_velocity = self.toolhead.get_max_velocity()[0]
|
||||||
est_move_d = sum([abs(forcepos[i]-movepos[i])
|
if limit_speed is not None and limit_speed < max_velocity:
|
||||||
for i in range(3) if movepos[i] is not None])
|
max_velocity = limit_speed
|
||||||
|
homing_speed = min(hi.speed, max_velocity)
|
||||||
|
homing_speed = self._get_homing_speed(homing_speed, endstops)
|
||||||
|
second_homing_speed = min(hi.second_homing_speed, max_velocity)
|
||||||
|
# Calculate a CPU delay when homing a large axis
|
||||||
|
axes_d = [mp - fp for mp, fp in zip(movepos, forcepos)]
|
||||||
|
est_move_d = abs(axes_d[0]) + abs(axes_d[1]) + abs(axes_d[2])
|
||||||
est_steps = sum([est_move_d / s.get_step_dist()
|
est_steps = sum([est_move_d / s.get_step_dist()
|
||||||
for es, n in endstops for s in es.get_steppers()])
|
for es, n in endstops for s in es.get_steppers()])
|
||||||
self.toolhead.dwell(est_steps * HOMING_STEP_DELAY, check_stall=False)
|
dwell_t = est_steps * HOMING_STEP_DELAY
|
||||||
speed = self._get_homing_speed(speed, endstops)
|
# Perform first home
|
||||||
# Issue homing move
|
self.homing_move(movepos, endstops, homing_speed, dwell_t=dwell_t)
|
||||||
self._homing_move(movepos, endstops, speed,
|
# Perform second home
|
||||||
verify_movement=second_home and self.verify_retract)
|
if hi.retract_dist:
|
||||||
|
# Retract
|
||||||
|
move_d = math.sqrt(sum([d*d for d in axes_d[:3]]))
|
||||||
|
retract_r = min(1., hi.retract_dist / move_d)
|
||||||
|
retractpos = [mp - ad * retract_r
|
||||||
|
for mp, ad in zip(movepos, axes_d)]
|
||||||
|
self.toolhead.move(retractpos, homing_speed)
|
||||||
|
# Home again
|
||||||
|
forcepos = [rp - ad * retract_r
|
||||||
|
for rp, ad in zip(retractpos, axes_d)]
|
||||||
|
self.toolhead.set_position(forcepos)
|
||||||
|
self.homing_move(movepos, endstops, second_homing_speed,
|
||||||
|
verify_movement=self.verify_retract)
|
||||||
def home_axes(self, axes):
|
def home_axes(self, axes):
|
||||||
self.changed_axes = axes
|
self.changed_axes = axes
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -55,38 +55,24 @@ class CartKinematics:
|
||||||
if i in homing_axes:
|
if i in homing_axes:
|
||||||
self.limits[i] = rail.get_range()
|
self.limits[i] = rail.get_range()
|
||||||
def _home_axis(self, homing_state, axis, rail):
|
def _home_axis(self, homing_state, axis, rail):
|
||||||
# Determine moves
|
# Determine movement
|
||||||
position_min, position_max = rail.get_range()
|
position_min, position_max = rail.get_range()
|
||||||
hi = rail.get_homing_info()
|
hi = rail.get_homing_info()
|
||||||
if hi.positive_dir:
|
|
||||||
pos = hi.position_endstop - 1.5*(hi.position_endstop - position_min)
|
|
||||||
rpos = hi.position_endstop - hi.retract_dist
|
|
||||||
r2pos = rpos - hi.retract_dist
|
|
||||||
else:
|
|
||||||
pos = hi.position_endstop + 1.5*(position_max - hi.position_endstop)
|
|
||||||
rpos = hi.position_endstop + hi.retract_dist
|
|
||||||
r2pos = rpos + hi.retract_dist
|
|
||||||
# Initial homing
|
|
||||||
homing_speed = hi.speed
|
|
||||||
second_homing_speed = hi.second_homing_speed
|
|
||||||
if axis == 2:
|
|
||||||
homing_speed = min(homing_speed, self.max_z_velocity)
|
|
||||||
second_homing_speed = min(second_homing_speed, self.max_z_velocity)
|
|
||||||
homepos = [None, None, None, None]
|
homepos = [None, None, None, None]
|
||||||
homepos[axis] = hi.position_endstop
|
homepos[axis] = hi.position_endstop
|
||||||
coord = [None, None, None, None]
|
forcepos = list(homepos)
|
||||||
coord[axis] = pos
|
if hi.positive_dir:
|
||||||
homing_state.home(coord, homepos, rail.get_endstops(), homing_speed)
|
forcepos[axis] -= 1.5 * (hi.position_endstop - position_min)
|
||||||
# Retract
|
else:
|
||||||
coord[axis] = rpos
|
forcepos[axis] += 1.5 * (position_max - hi.position_endstop)
|
||||||
homing_state.retract(coord, homing_speed)
|
# Perform homing
|
||||||
# Home again
|
limit_speed = None
|
||||||
coord[axis] = r2pos
|
if axis == 2:
|
||||||
homing_state.home(coord, homepos, rail.get_endstops(),
|
limit_speed = self.max_z_velocity
|
||||||
second_homing_speed, second_home=True)
|
homing_state.home_rails([rail], forcepos, homepos, limit_speed)
|
||||||
# Set final homed position
|
# Set final homed position
|
||||||
coord[axis] = hi.position_endstop + rail.get_homed_offset()
|
forcepos[axis] = hi.position_endstop + rail.get_homed_offset()
|
||||||
homing_state.set_homed_position(coord)
|
homing_state.set_homed_position(forcepos)
|
||||||
def home(self, homing_state):
|
def home(self, homing_state):
|
||||||
# Each axis is homed independently and in order
|
# Each axis is homed independently and in order
|
||||||
for axis in homing_state.get_axes():
|
for axis in homing_state.get_axes():
|
||||||
|
|
|
@ -48,42 +48,25 @@ class CoreXYKinematics:
|
||||||
# Each axis is homed independently and in order
|
# Each axis is homed independently and in order
|
||||||
for axis in homing_state.get_axes():
|
for axis in homing_state.get_axes():
|
||||||
rail = self.rails[axis]
|
rail = self.rails[axis]
|
||||||
# Determine moves
|
# Determine movement
|
||||||
position_min, position_max = rail.get_range()
|
position_min, position_max = rail.get_range()
|
||||||
hi = rail.get_homing_info()
|
hi = rail.get_homing_info()
|
||||||
if hi.positive_dir:
|
|
||||||
pos = hi.position_endstop - 1.5*(
|
|
||||||
hi.position_endstop - position_min)
|
|
||||||
rpos = hi.position_endstop - hi.retract_dist
|
|
||||||
r2pos = rpos - hi.retract_dist
|
|
||||||
else:
|
|
||||||
pos = hi.position_endstop + 1.5*(
|
|
||||||
position_max - hi.position_endstop)
|
|
||||||
rpos = hi.position_endstop + hi.retract_dist
|
|
||||||
r2pos = rpos + hi.retract_dist
|
|
||||||
# Initial homing
|
|
||||||
homing_speed = hi.speed
|
|
||||||
second_homing_speed = hi.second_homing_speed
|
|
||||||
if axis == 2:
|
|
||||||
homing_speed = min(homing_speed, self.max_z_velocity)
|
|
||||||
second_homing_speed = min(second_homing_speed,
|
|
||||||
self.max_z_velocity)
|
|
||||||
homepos = [None, None, None, None]
|
homepos = [None, None, None, None]
|
||||||
homepos[axis] = hi.position_endstop
|
homepos[axis] = hi.position_endstop
|
||||||
coord = [None, None, None, None]
|
forcepos = list(homepos)
|
||||||
coord[axis] = pos
|
if hi.positive_dir:
|
||||||
homing_state.home(coord, homepos, rail.get_endstops(), homing_speed)
|
forcepos[axis] -= 1.5 * (hi.position_endstop - position_min)
|
||||||
# Retract
|
else:
|
||||||
coord[axis] = rpos
|
forcepos[axis] += 1.5 * (position_max - hi.position_endstop)
|
||||||
homing_state.retract(coord, homing_speed)
|
# Perform homing
|
||||||
# Home again
|
limit_speed = None
|
||||||
coord[axis] = r2pos
|
if axis == 2:
|
||||||
homing_state.home(coord, homepos, rail.get_endstops(),
|
limit_speed = self.max_z_velocity
|
||||||
second_homing_speed, second_home=True)
|
homing_state.home_rails([rail], forcepos, homepos, limit_speed)
|
||||||
if axis == 2:
|
if axis == 2:
|
||||||
# Support endstop phase detection on Z axis
|
# Support endstop phase detection on Z axis
|
||||||
coord[axis] = hi.position_endstop + rail.get_homed_offset()
|
forcepos[axis] = hi.position_endstop + rail.get_homed_offset()
|
||||||
homing_state.set_homed_position(coord)
|
homing_state.set_homed_position(forcepos)
|
||||||
def motor_off(self, print_time):
|
def motor_off(self, print_time):
|
||||||
self.limits = [(1.0, -1.0)] * 3
|
self.limits = [(1.0, -1.0)] * 3
|
||||||
for rail in self.rails:
|
for rail in self.rails:
|
||||||
|
|
|
@ -97,22 +97,11 @@ class DeltaKinematics:
|
||||||
def home(self, homing_state):
|
def home(self, homing_state):
|
||||||
# All axes are homed simultaneously
|
# All axes are homed simultaneously
|
||||||
homing_state.set_axes([0, 1, 2])
|
homing_state.set_axes([0, 1, 2])
|
||||||
endstops = [es for rail in self.rails for es in rail.get_endstops()]
|
|
||||||
# Initial homing - assume homing speed same for all steppers
|
|
||||||
hi = self.rails[0].get_homing_info()
|
|
||||||
homing_speed = min(hi.speed, self.max_z_velocity)
|
|
||||||
second_homing_speed = min(hi.second_homing_speed, self.max_z_velocity)
|
|
||||||
homepos = [0., 0., self.max_z, None]
|
homepos = [0., 0., self.max_z, None]
|
||||||
coord = list(homepos)
|
forcepos = list(homepos)
|
||||||
coord[2] = -1.5 * math.sqrt(max(self.arm2)-self.max_xy2)
|
forcepos[2] = -1.5 * math.sqrt(max(self.arm2)-self.max_xy2)
|
||||||
homing_state.home(coord, homepos, endstops, homing_speed)
|
homing_state.home_rails(self.rails, forcepos, homepos,
|
||||||
# Retract
|
limit_speed=self.max_z_velocity)
|
||||||
coord[2] = homepos[2] - hi.retract_dist
|
|
||||||
homing_state.retract(coord, homing_speed)
|
|
||||||
# Home again
|
|
||||||
coord[2] -= hi.retract_dist
|
|
||||||
homing_state.home(coord, homepos, endstops,
|
|
||||||
second_homing_speed, second_home=True)
|
|
||||||
# Set final homed position
|
# Set final homed position
|
||||||
spos = [ep + rail.get_homed_offset()
|
spos = [ep + rail.get_homed_offset()
|
||||||
for ep, rail in zip(self.abs_endstops, self.rails)]
|
for ep, rail in zip(self.abs_endstops, self.rails)]
|
||||||
|
|
Loading…
Reference in New Issue