toolhead: Eliminate set_max_jerk() from kinematic classes
Allow the kinematic classes to query the max velocity, max accel, and max halt velocity from the toolhead class instead of having the toolhead class call into the kinematic classes with those values. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
parent
0d13834293
commit
7a81bfc4a4
|
@ -9,20 +9,23 @@ import stepper, homing
|
|||
StepList = (0, 1, 2)
|
||||
|
||||
class CartKinematics:
|
||||
def __init__(self, printer, config):
|
||||
def __init__(self, toolhead, printer, config):
|
||||
self.steppers = [stepper.PrinterHomingStepper(
|
||||
printer, config.getsection('stepper_' + n), n)
|
||||
for n in ['x', 'y', 'z']]
|
||||
max_velocity, max_accel = toolhead.get_max_velocity()
|
||||
self.max_z_velocity = config.getfloat(
|
||||
'max_z_velocity', 9999999.9, above=0.)
|
||||
'max_z_velocity', max_velocity, above=0., maxval=max_velocity)
|
||||
self.max_z_accel = config.getfloat(
|
||||
'max_z_accel', 9999999.9, above=0.)
|
||||
'max_z_accel', max_accel, above=0., maxval=max_accel)
|
||||
self.need_motor_enable = True
|
||||
self.limits = [(1.0, -1.0)] * 3
|
||||
def set_max_jerk(self, max_xy_halt_velocity, max_velocity, max_accel):
|
||||
# Setup stepper max halt velocity
|
||||
max_xy_halt_velocity = toolhead.get_max_axis_halt(max_accel)
|
||||
self.steppers[0].set_max_jerk(max_xy_halt_velocity, max_accel)
|
||||
self.steppers[1].set_max_jerk(max_xy_halt_velocity, max_accel)
|
||||
self.steppers[2].set_max_jerk(0., self.max_z_accel)
|
||||
max_z_halt_velocity = toolhead.get_max_axis_halt(self.max_z_accel)
|
||||
self.steppers[2].set_max_jerk(max_z_halt_velocity, self.max_z_accel)
|
||||
def set_position(self, newpos):
|
||||
for i in StepList:
|
||||
self.steppers[i].mcu_stepper.set_position(newpos[i])
|
||||
|
|
|
@ -9,22 +9,25 @@ import stepper, homing
|
|||
StepList = (0, 1, 2)
|
||||
|
||||
class CoreXYKinematics:
|
||||
def __init__(self, printer, config):
|
||||
def __init__(self, toolhead, printer, config):
|
||||
self.steppers = [stepper.PrinterHomingStepper(
|
||||
printer, config.getsection('stepper_' + n), n)
|
||||
for n in ['x', 'y', 'z']]
|
||||
self.steppers[0].mcu_endstop.add_stepper(self.steppers[1].mcu_stepper)
|
||||
self.steppers[1].mcu_endstop.add_stepper(self.steppers[0].mcu_stepper)
|
||||
max_velocity, max_accel = toolhead.get_max_velocity()
|
||||
self.max_z_velocity = config.getfloat(
|
||||
'max_z_velocity', 9999999.9, above=0.)
|
||||
'max_z_velocity', max_velocity, above=0., maxval=max_velocity)
|
||||
self.max_z_accel = config.getfloat(
|
||||
'max_z_accel', 9999999.9, above=0.)
|
||||
'max_z_accel', max_accel, above=0., maxval=max_accel)
|
||||
self.need_motor_enable = True
|
||||
self.limits = [(1.0, -1.0)] * 3
|
||||
def set_max_jerk(self, max_xy_halt_velocity, max_velocity, max_accel):
|
||||
# Setup stepper max halt velocity
|
||||
max_xy_halt_velocity = toolhead.get_max_axis_halt(max_accel)
|
||||
self.steppers[0].set_max_jerk(max_xy_halt_velocity, max_accel)
|
||||
self.steppers[1].set_max_jerk(max_xy_halt_velocity, max_accel)
|
||||
self.steppers[2].set_max_jerk(0., self.max_z_accel)
|
||||
max_z_halt_velocity = toolhead.get_max_axis_halt(self.max_z_accel)
|
||||
self.steppers[2].set_max_jerk(max_z_halt_velocity, self.max_z_accel)
|
||||
def set_position(self, newpos):
|
||||
pos = (newpos[0] + newpos[1], newpos[0] - newpos[1], newpos[2])
|
||||
for i in StepList:
|
||||
|
|
|
@ -12,13 +12,11 @@ StepList = (0, 1, 2)
|
|||
SLOW_RATIO = 3.
|
||||
|
||||
class DeltaKinematics:
|
||||
def __init__(self, printer, config):
|
||||
self.config = config
|
||||
def __init__(self, toolhead, printer, config):
|
||||
self.steppers = [stepper.PrinterHomingStepper(
|
||||
printer, config.getsection('stepper_' + n), n)
|
||||
for n in ['a', 'b', 'c']]
|
||||
self.need_motor_enable = self.need_home = True
|
||||
self.max_velocity = self.max_z_velocity = self.max_accel = 0.
|
||||
radius = config.getfloat('delta_radius', above=0.)
|
||||
arm_length = config.getfloat('delta_arm_length', above=radius)
|
||||
self.arm_length2 = arm_length**2
|
||||
|
@ -29,6 +27,14 @@ class DeltaKinematics:
|
|||
logging.info(
|
||||
"Delta max build height %.2fmm (radius tapered above %.2fmm)" % (
|
||||
self.max_z, self.limit_z))
|
||||
# Setup stepper max halt velocity
|
||||
self.max_velocity, self.max_accel = toolhead.get_max_velocity()
|
||||
self.max_z_velocity = config.getfloat(
|
||||
'max_z_velocity', self.max_velocity,
|
||||
above=0., maxval=self.max_velocity)
|
||||
max_xy_halt_velocity = toolhead.get_max_axis_halt(self.max_accel)
|
||||
for s in self.steppers:
|
||||
s.set_max_jerk(max_xy_halt_velocity, self.max_accel)
|
||||
# Determine tower locations in cartesian space
|
||||
angles = [config.getsection('stepper_a').getfloat('angle', 210.),
|
||||
config.getsection('stepper_b').getfloat('angle', 330.),
|
||||
|
@ -52,14 +58,6 @@ class DeltaKinematics:
|
|||
% (math.sqrt(self.max_xy2), math.sqrt(self.slow_xy2),
|
||||
math.sqrt(self.very_slow_xy2)))
|
||||
self.set_position([0., 0., 0.])
|
||||
def set_max_jerk(self, max_xy_halt_velocity, max_velocity, max_accel):
|
||||
self.max_velocity = max_velocity
|
||||
max_z_velocity = self.config.getfloat(
|
||||
'max_z_velocity', max_velocity, above=0.)
|
||||
self.max_z_velocity = min(max_velocity, max_z_velocity)
|
||||
self.max_accel = max_accel
|
||||
for stepper in self.steppers:
|
||||
stepper.set_max_jerk(max_xy_halt_velocity, max_accel)
|
||||
def _cartesian_to_actuator(self, coord):
|
||||
return [math.sqrt(self.arm_length2
|
||||
- (self.towers[i][0] - coord[0])**2
|
||||
|
|
|
@ -21,6 +21,15 @@ class PrinterExtruder:
|
|||
'max_extrude_cross_section', 4. * self.nozzle_diameter**2
|
||||
, above=0.)
|
||||
self.max_extrude_ratio = max_cross_section / filament_area
|
||||
toolhead = printer.objects['toolhead']
|
||||
max_velocity, max_accel = toolhead.get_max_velocity()
|
||||
self.max_e_velocity = self.config.getfloat(
|
||||
'max_extrude_only_velocity', max_velocity * self.max_extrude_ratio
|
||||
, above=0.)
|
||||
self.max_e_accel = self.config.getfloat(
|
||||
'max_extrude_only_accel', max_accel * self.max_extrude_ratio
|
||||
, above=0.)
|
||||
self.stepper.set_max_jerk(9999999.9, 9999999.9)
|
||||
self.max_e_dist = config.getfloat(
|
||||
'max_extrude_only_distance', 50., minval=0.)
|
||||
self.max_e_velocity = self.max_e_accel = None
|
||||
|
@ -34,14 +43,6 @@ class PrinterExtruder:
|
|||
'pressure_advance_lookahead_time', 0.010, minval=0.)
|
||||
self.need_motor_enable = True
|
||||
self.extrude_pos = 0.
|
||||
def set_max_jerk(self, max_xy_halt_velocity, max_velocity, max_accel):
|
||||
self.max_e_velocity = self.config.getfloat(
|
||||
'max_extrude_only_velocity', max_velocity * self.max_extrude_ratio
|
||||
, above=0.)
|
||||
self.max_e_accel = self.config.getfloat(
|
||||
'max_extrude_only_accel', max_accel * self.max_extrude_ratio
|
||||
, above=0.)
|
||||
self.stepper.set_max_jerk(9999999.9, 9999999.9)
|
||||
def get_heater(self):
|
||||
return self.heater
|
||||
def set_active(self, print_time, is_active):
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
# This file may be distributed under the terms of the GNU GPLv3 license.
|
||||
import sys, optparse, ConfigParser, logging, time, threading
|
||||
import util, reactor, queuelogger, msgproto, gcode
|
||||
import pins, mcu, chipmisc, extruder, fan, heater, toolhead
|
||||
import pins, mcu, chipmisc, toolhead, extruder, fan, heater
|
||||
|
||||
message_ready = "Printer is ready"
|
||||
|
||||
|
@ -172,7 +172,7 @@ class Printer:
|
|||
ConfigLogger(self.fileconfig, self.bglogger)
|
||||
# Create printer components
|
||||
config = ConfigWrapper(self, 'printer')
|
||||
for m in [pins, mcu, chipmisc, extruder, fan, heater, toolhead]:
|
||||
for m in [pins, mcu, chipmisc, toolhead, extruder, fan, heater]:
|
||||
m.add_printer_objects(self, config)
|
||||
self.mcu = self.objects['mcu']
|
||||
# Validate that there are no undefined parameters in the config file
|
||||
|
|
|
@ -184,12 +184,7 @@ class ToolHead:
|
|||
self.printer = printer
|
||||
self.reactor = printer.reactor
|
||||
self.mcu = printer.objects['mcu']
|
||||
self.extruder = extruder.DummyExtruder()
|
||||
kintypes = {'cartesian': cartesian.CartKinematics,
|
||||
'corexy': corexy.CoreXYKinematics,
|
||||
'delta': delta.DeltaKinematics}
|
||||
self.kin = config.getchoice('kinematics', kintypes)(printer, config)
|
||||
self.max_speed = config.getfloat('max_velocity', above=0.)
|
||||
self.max_velocity = config.getfloat('max_velocity', above=0.)
|
||||
self.max_accel = config.getfloat('max_accel', above=0.)
|
||||
self.max_accel_to_decel = config.getfloat(
|
||||
'max_accel_to_decel', self.max_accel * 0.5
|
||||
|
@ -197,7 +192,6 @@ class ToolHead:
|
|||
self.junction_deviation = config.getfloat(
|
||||
'junction_deviation', 0.02, above=0.)
|
||||
self.move_queue = MoveQueue()
|
||||
self.move_queue.set_extruder(self.extruder)
|
||||
self.commanded_pos = [0., 0., 0., 0.]
|
||||
# Print time tracking
|
||||
self.buffer_time_low = config.getfloat(
|
||||
|
@ -221,12 +215,14 @@ class ToolHead:
|
|||
'motor_off_time', 600.000, minval=0.)
|
||||
self.motor_off_timer = self.reactor.register_timer(
|
||||
self._motor_off_handler)
|
||||
# Determine the maximum velocity a cartesian axis could have
|
||||
# before cornering. The 8. was determined experimentally.
|
||||
xy_halt = math.sqrt(8. * self.junction_deviation * self.max_accel)
|
||||
self.kin.set_max_jerk(xy_halt, self.max_speed, self.max_accel)
|
||||
for e in extruder.get_printer_extruders(printer):
|
||||
e.set_max_jerk(xy_halt, self.max_speed, self.max_accel)
|
||||
# Create kinematics class
|
||||
self.extruder = extruder.DummyExtruder()
|
||||
self.move_queue.set_extruder(self.extruder)
|
||||
kintypes = {'cartesian': cartesian.CartKinematics,
|
||||
'corexy': corexy.CoreXYKinematics,
|
||||
'delta': delta.DeltaKinematics}
|
||||
self.kin = config.getchoice('kinematics', kintypes)(
|
||||
self, printer, config)
|
||||
# Print time tracking
|
||||
def update_move_time(self, movetime):
|
||||
self.print_time += movetime
|
||||
|
@ -332,7 +328,7 @@ class ToolHead:
|
|||
self.commanded_pos[:] = newpos
|
||||
self.kin.set_position(newpos)
|
||||
def move(self, newpos, speed):
|
||||
speed = min(speed, self.max_speed)
|
||||
speed = min(speed, self.max_velocity)
|
||||
move = Move(self, self.commanded_pos, newpos, speed)
|
||||
if not move.move_d:
|
||||
return
|
||||
|
@ -396,6 +392,13 @@ class ToolHead:
|
|||
self.reset_print_time()
|
||||
except:
|
||||
logging.exception("Exception in force_shutdown")
|
||||
def get_max_velocity(self):
|
||||
return self.max_velocity, self.max_accel
|
||||
def get_max_axis_halt(self, max_accel):
|
||||
# Determine the maximum velocity a cartesian axis could halt
|
||||
# at due to the junction_deviation setting. The 8.0 was
|
||||
# determined experimentally.
|
||||
return math.sqrt(8. * self.junction_deviation * max_accel)
|
||||
|
||||
def add_printer_objects(printer, config):
|
||||
printer.add_object('toolhead', ToolHead(printer, config))
|
||||
|
|
Loading…
Reference in New Issue