toolhead: Replace junction_deviation with square_corner_velocity

The junction_deviation configuration parameter has a number of quirks
that make it difficult to configure.  Replace it with a
"square_corner_velocity" configuration parameter.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor 2018-07-08 14:08:21 -04:00
parent ca505bf4ac
commit 0025fbf10d
5 changed files with 34 additions and 21 deletions

View file

@ -198,19 +198,22 @@ class ToolHead:
self.reactor = self.printer.get_reactor()
self.all_mcus = self.printer.lookup_module_objects('mcu')
self.mcu = self.all_mcus[0]
self.move_queue = MoveQueue()
self.commanded_pos = [0., 0., 0., 0.]
# Velocity and acceleration control
self.max_velocity = config.getfloat('max_velocity', above=0.)
self.max_accel = config.getfloat('max_accel', above=0.)
self.requested_accel_to_decel = config.getfloat(
'max_accel_to_decel', self.max_accel * 0.5, above=0.)
self.max_accel_to_decel = min(self.requested_accel_to_decel,
self.max_accel)
self.junction_deviation = config.getfloat(
'junction_deviation', 0.02, minval=0.)
self.square_corner_velocity = config.getfloat(
'square_corner_velocity', 5., minval=0.)
self.config_max_velocity = self.max_velocity
self.config_max_accel = self.max_accel
self.config_junction_deviation = self.junction_deviation
self.move_queue = MoveQueue()
self.commanded_pos = [0., 0., 0., 0.]
self.config_square_corner_velocity = self.square_corner_velocity
self.junction_deviation = 0.
self._calc_junction_deviation()
# Print time tracking
self.buffer_time_low = config.getfloat(
'buffer_time_low', 1.000, above=0.)
@ -425,6 +428,9 @@ class ToolHead:
# determined experimentally.
return min(self.max_velocity,
math.sqrt(8. * self.junction_deviation * self.max_accel))
def _calc_junction_deviation(self):
scv2 = self.square_corner_velocity**2
self.junction_deviation = scv2 * (math.sqrt(2.) - 1.) / self.max_accel
cmd_SET_VELOCITY_LIMIT_help = "Set printer velocity limits"
def cmd_SET_VELOCITY_LIMIT(self, params):
print_time = self.get_last_move_time()
@ -435,27 +441,29 @@ class ToolHead:
max_accel = gcode.get_float(
'ACCEL', params, self.max_accel,
above=0., maxval=self.config_max_accel)
junction_deviation = gcode.get_float(
'JUNCTION_DEVIATION', params, self.junction_deviation,
minval=0., maxval=self.config_junction_deviation)
square_corner_velocity = gcode.get_float(
'SQUARE_CORNER_VELOCITY', params, self.square_corner_velocity,
minval=0., maxval=self.config_square_corner_velocity)
self.requested_accel_to_decel = gcode.get_float(
'ACCEL_TO_DECEL', params, self.requested_accel_to_decel, above=0.)
self.max_velocity = max_velocity
self.max_accel = max_accel
self.max_accel_to_decel = min(self.requested_accel_to_decel, max_accel)
self.junction_deviation = junction_deviation
self.square_corner_velocity = square_corner_velocity
self._calc_junction_deviation()
msg = ("max_velocity: %.6f\n"
"max_accel: %.6f\n"
"max_accel_to_decel: %.6f\n"
"junction_deviation: %.6f"% (
"square_corner_velocity: %.6f"% (
max_velocity, max_accel, self.requested_accel_to_decel,
junction_deviation))
square_corner_velocity))
self.printer.set_rollover_info("toolhead", "toolhead: %s" % (msg,))
gcode.respond_info(msg)
def cmd_M204(self, params):
gcode = self.printer.lookup_object('gcode')
accel = gcode.get_float('S', params, above=0.)
self.max_accel = min(accel, self.config_max_accel)
self._calc_junction_deviation()
def add_printer_objects(config):
config.get_printer().add_object('toolhead', ToolHead(config))