stepper: Fix set_min_stop_interval() calculation
The previous calculation was only valid if the stepper is always commanded to a position that is an exact multiple of the step_distance. The safety check was programmed with a value too large for other commanded positions, which could result in "No next step" errors. Fix by changing the calculation to use the worst case scenario. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
parent
cbdc54843d
commit
df6d3107f2
|
@ -50,11 +50,17 @@ class PrinterStepper:
|
||||||
self.position_endstop = config.getfloat('position_endstop')
|
self.position_endstop = config.getfloat('position_endstop')
|
||||||
self.position_max = config.getfloat('position_max', 0.)
|
self.position_max = config.getfloat('position_max', 0.)
|
||||||
self.need_motor_enable = True
|
self.need_motor_enable = True
|
||||||
|
def _dist_to_time(self, dist, start_velocity, accel):
|
||||||
|
# Calculate the time it takes to travel a distance with constant accel
|
||||||
|
time_offset = start_velocity / accel
|
||||||
|
return math.sqrt(2. * dist / accel + time_offset**2) - time_offset
|
||||||
def set_max_jerk(self, max_halt_velocity, max_accel):
|
def set_max_jerk(self, max_halt_velocity, max_accel):
|
||||||
jc = max_halt_velocity / max_accel
|
# Calculate the firmware's maximum halt interval time
|
||||||
inv_max_step_accel = self.step_dist / max_accel
|
last_step_time = self._dist_to_time(
|
||||||
min_stop_interval = (math.sqrt(3.*inv_max_step_accel + jc**2)
|
self.step_dist, max_halt_velocity, max_accel)
|
||||||
- math.sqrt(inv_max_step_accel + jc**2))
|
second_last_step_time = self._dist_to_time(
|
||||||
|
2. * self.step_dist, max_halt_velocity, max_accel)
|
||||||
|
min_stop_interval = second_last_step_time - last_step_time
|
||||||
self.mcu_stepper.set_min_stop_interval(min_stop_interval)
|
self.mcu_stepper.set_min_stop_interval(min_stop_interval)
|
||||||
def motor_enable(self, move_time, enable=0):
|
def motor_enable(self, move_time, enable=0):
|
||||||
if enable and self.need_motor_enable:
|
if enable and self.need_motor_enable:
|
||||||
|
|
Loading…
Reference in New Issue