2016-07-10 19:23:35 +03:00
|
|
|
# Code for handling printer nozzle extruders
|
|
|
|
#
|
|
|
|
# Copyright (C) 2016 Kevin O'Connor <kevin@koconnor.net>
|
|
|
|
#
|
|
|
|
# This file may be distributed under the terms of the GNU GPLv3 license.
|
|
|
|
import logging
|
2016-10-01 02:04:24 +03:00
|
|
|
import stepper, heater, homing
|
2016-07-10 19:23:35 +03:00
|
|
|
|
|
|
|
class PrinterExtruder:
|
|
|
|
def __init__(self, printer, config):
|
2016-10-01 01:49:38 +03:00
|
|
|
self.heater = heater.PrinterHeater(printer, config)
|
2016-11-18 01:24:03 +03:00
|
|
|
self.stepper = stepper.PrinterStepper(printer, config, 'extruder')
|
2016-07-17 02:58:41 +03:00
|
|
|
self.pressure_advance = config.getfloat('pressure_advance', 0.)
|
2016-12-01 23:29:26 +03:00
|
|
|
self.max_e_velocity = config.getfloat('max_velocity')
|
|
|
|
self.max_e_accel = config.getfloat('max_accel')
|
2016-11-14 21:40:35 +03:00
|
|
|
self.need_motor_enable = True
|
2016-07-17 02:58:41 +03:00
|
|
|
self.extrude_pos = 0.
|
2016-07-10 19:23:35 +03:00
|
|
|
def build_config(self):
|
|
|
|
self.heater.build_config()
|
2016-12-01 23:29:26 +03:00
|
|
|
self.stepper.set_max_jerk(9999999.9, 9999999.9)
|
2016-07-10 19:23:35 +03:00
|
|
|
self.stepper.build_config()
|
|
|
|
def motor_off(self, move_time):
|
|
|
|
self.stepper.motor_enable(move_time, 0)
|
2016-11-14 21:40:35 +03:00
|
|
|
self.need_motor_enable = True
|
2016-09-30 21:47:45 +03:00
|
|
|
def check_move(self, move):
|
2016-10-01 02:04:24 +03:00
|
|
|
if not self.heater.can_extrude:
|
2016-11-18 20:42:39 +03:00
|
|
|
raise homing.EndstopMoveError(
|
|
|
|
move.end_pos, "Extrude below minimum temp")
|
2016-12-28 19:48:40 +03:00
|
|
|
if not move.is_kinematic_move:
|
2016-09-30 21:47:45 +03:00
|
|
|
# Extrude only move - limit accel and velocity
|
2016-12-01 23:29:26 +03:00
|
|
|
move.limit_speed(self.max_e_velocity, self.max_e_accel)
|
2016-07-10 19:23:35 +03:00
|
|
|
def move(self, move_time, move):
|
2016-11-14 21:40:35 +03:00
|
|
|
if self.need_motor_enable:
|
|
|
|
self.stepper.motor_enable(move_time, 1)
|
|
|
|
self.need_motor_enable = False
|
2016-11-05 02:28:07 +03:00
|
|
|
axis_d = move.axes_d[3]
|
2016-12-02 01:37:13 +03:00
|
|
|
extrude_r = abs(axis_d) / move.move_d
|
2016-11-05 02:28:07 +03:00
|
|
|
inv_accel = 1. / (move.accel * extrude_r)
|
2016-07-17 02:58:41 +03:00
|
|
|
|
2016-11-05 02:28:07 +03:00
|
|
|
start_v = move.start_v * extrude_r
|
|
|
|
cruise_v = move.cruise_v * extrude_r
|
|
|
|
end_v = move.end_v * extrude_r
|
2016-07-17 02:58:41 +03:00
|
|
|
accel_t, cruise_t, decel_t = move.accel_t, move.cruise_t, move.decel_t
|
2016-11-05 02:28:07 +03:00
|
|
|
accel_d = move.accel_r * axis_d
|
|
|
|
cruise_d = move.cruise_r * axis_d
|
|
|
|
decel_d = move.decel_r * axis_d
|
2016-07-17 02:58:41 +03:00
|
|
|
|
|
|
|
retract_t = retract_d = retract_v = 0.
|
|
|
|
decel_v = cruise_v
|
|
|
|
|
|
|
|
# Update for pressure advance
|
2016-11-05 04:11:14 +03:00
|
|
|
start_pos = self.extrude_pos
|
2016-11-05 02:28:07 +03:00
|
|
|
if (axis_d >= 0. and (move.axes_d[0] or move.axes_d[1])
|
2016-07-17 02:58:41 +03:00
|
|
|
and self.pressure_advance):
|
|
|
|
# Increase accel_d and start_v when accelerating
|
2016-11-05 04:11:14 +03:00
|
|
|
move_extrude_r = move.extrude_r
|
|
|
|
prev_pressure_d = start_pos - move.start_pos[3]
|
2016-07-17 02:58:41 +03:00
|
|
|
if accel_t:
|
2016-11-05 04:11:14 +03:00
|
|
|
npd = move.cruise_v * move_extrude_r * self.pressure_advance
|
|
|
|
extra_accel_d = npd - prev_pressure_d
|
|
|
|
if extra_accel_d > 0.:
|
|
|
|
accel_d += extra_accel_d
|
|
|
|
start_v += extra_accel_d / accel_t
|
|
|
|
prev_pressure_d += extra_accel_d
|
2016-07-17 02:58:41 +03:00
|
|
|
# Update decel and retract parameters when decelerating
|
|
|
|
if decel_t:
|
2016-11-05 05:43:50 +03:00
|
|
|
if move.corner_min:
|
|
|
|
npd = move.corner_max*move_extrude_r * self.pressure_advance
|
|
|
|
extra_decel_d = prev_pressure_d - npd
|
|
|
|
if move.end_v > move.corner_min:
|
|
|
|
extra_decel_d *= ((move.cruise_v - move.end_v)
|
|
|
|
/ (move.cruise_v - move.corner_min))
|
|
|
|
else:
|
|
|
|
npd = move.end_v * move_extrude_r * self.pressure_advance
|
|
|
|
extra_decel_d = prev_pressure_d - npd
|
2016-11-05 04:11:14 +03:00
|
|
|
if extra_decel_d > 0.:
|
|
|
|
extra_decel_v = extra_decel_d / decel_t
|
|
|
|
decel_v -= extra_decel_v
|
|
|
|
end_v -= extra_decel_v
|
|
|
|
if decel_v <= 0.:
|
|
|
|
# The entire decel phase is replaced with retraction
|
|
|
|
retract_t = decel_t
|
|
|
|
retract_d = -(end_v + decel_v) * 0.5 * decel_t
|
|
|
|
retract_v = -decel_v
|
|
|
|
decel_t = decel_d = 0.
|
|
|
|
elif end_v < 0.:
|
|
|
|
# Split decel phase into decel and retraction
|
|
|
|
retract_t = -end_v * inv_accel
|
|
|
|
retract_d = -end_v * 0.5 * retract_t
|
|
|
|
decel_t -= retract_t
|
|
|
|
decel_d = decel_v * 0.5 * decel_t
|
|
|
|
else:
|
|
|
|
# There is still only a decel phase (no retraction)
|
|
|
|
decel_d -= extra_decel_d
|
2016-07-17 02:58:41 +03:00
|
|
|
|
2016-11-10 20:44:04 +03:00
|
|
|
# Prepare for steps
|
2016-10-26 04:06:20 +03:00
|
|
|
inv_step_dist = self.stepper.inv_step_dist
|
2016-11-10 20:44:04 +03:00
|
|
|
step_dist = self.stepper.step_dist
|
2016-11-14 21:40:35 +03:00
|
|
|
mcu_stepper = self.stepper.mcu_stepper
|
|
|
|
mcu_time = mcu_stepper.print_to_mcu_time(move_time)
|
2016-11-19 19:34:42 +03:00
|
|
|
step_pos = mcu_stepper.commanded_position
|
|
|
|
step_offset = step_pos - start_pos * inv_step_dist
|
2016-07-17 02:58:41 +03:00
|
|
|
|
2016-11-10 20:44:04 +03:00
|
|
|
# Acceleration steps
|
|
|
|
accel_multiplier = 2.0 * step_dist * inv_accel
|
|
|
|
if accel_d:
|
2016-07-17 02:58:41 +03:00
|
|
|
#t = sqrt(2*pos/accel + (start_v/accel)**2) - start_v/accel
|
2016-08-24 23:42:25 +03:00
|
|
|
accel_time_offset = start_v * inv_accel
|
|
|
|
accel_sqrt_offset = accel_time_offset**2
|
2016-11-10 20:44:04 +03:00
|
|
|
accel_steps = accel_d * inv_step_dist
|
2016-11-14 21:40:35 +03:00
|
|
|
count = mcu_stepper.step_sqrt(
|
2016-08-24 23:42:25 +03:00
|
|
|
mcu_time - accel_time_offset, accel_steps, step_offset
|
2016-07-17 02:58:41 +03:00
|
|
|
, accel_sqrt_offset, accel_multiplier)
|
2016-11-10 20:44:04 +03:00
|
|
|
step_offset += count - accel_steps
|
2016-08-24 23:42:25 +03:00
|
|
|
mcu_time += accel_t
|
2016-11-10 20:44:04 +03:00
|
|
|
# Cruising steps
|
|
|
|
if cruise_d:
|
2016-07-17 02:58:41 +03:00
|
|
|
#t = pos/cruise_v
|
2016-11-10 20:44:04 +03:00
|
|
|
cruise_multiplier = step_dist / cruise_v
|
|
|
|
cruise_steps = cruise_d * inv_step_dist
|
2016-11-14 21:40:35 +03:00
|
|
|
count = mcu_stepper.step_factor(
|
2016-08-24 23:42:25 +03:00
|
|
|
mcu_time, cruise_steps, step_offset, cruise_multiplier)
|
2016-11-10 20:44:04 +03:00
|
|
|
step_offset += count - cruise_steps
|
2016-08-24 23:42:25 +03:00
|
|
|
mcu_time += cruise_t
|
2016-11-10 20:44:04 +03:00
|
|
|
# Deceleration steps
|
|
|
|
if decel_d:
|
2016-07-17 02:58:41 +03:00
|
|
|
#t = cruise_v/accel - sqrt((cruise_v/accel)**2 - 2*pos/accel)
|
2016-08-24 23:42:25 +03:00
|
|
|
decel_time_offset = decel_v * inv_accel
|
|
|
|
decel_sqrt_offset = decel_time_offset**2
|
2016-11-10 20:44:04 +03:00
|
|
|
decel_steps = decel_d * inv_step_dist
|
2016-11-14 21:40:35 +03:00
|
|
|
count = mcu_stepper.step_sqrt(
|
2016-08-24 23:42:25 +03:00
|
|
|
mcu_time + decel_time_offset, decel_steps, step_offset
|
2016-07-17 02:58:41 +03:00
|
|
|
, decel_sqrt_offset, -accel_multiplier)
|
2016-11-10 20:44:04 +03:00
|
|
|
step_offset += count - decel_steps
|
|
|
|
mcu_time += decel_t
|
|
|
|
# Retraction steps
|
|
|
|
if retract_d:
|
2016-07-17 02:58:41 +03:00
|
|
|
#t = sqrt(2*pos/accel + (start_v/accel)**2) - start_v/accel
|
2016-08-24 23:42:25 +03:00
|
|
|
accel_time_offset = retract_v * inv_accel
|
|
|
|
accel_sqrt_offset = accel_time_offset**2
|
2016-11-10 20:44:04 +03:00
|
|
|
accel_steps = -retract_d * inv_step_dist
|
2016-11-14 21:40:35 +03:00
|
|
|
count = mcu_stepper.step_sqrt(
|
2016-11-10 20:44:04 +03:00
|
|
|
mcu_time - accel_time_offset, accel_steps, step_offset
|
|
|
|
, accel_sqrt_offset, accel_multiplier)
|
|
|
|
|
|
|
|
self.extrude_pos = start_pos + accel_d + cruise_d + decel_d - retract_d
|