stepper: Store max_velocity/max_accel instead of max_step_velocity/accel

All users of max_step_velocity and max_step_accel end up multiplying
by step_dist anyway, so it's easier to store max_velocity and
max_accel.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor 2016-07-07 16:57:25 -04:00
parent 5829aa8bd7
commit 4a527a46ce
2 changed files with 11 additions and 18 deletions

View File

@ -21,25 +21,19 @@ class CartKinematics:
self.stepper_pos = [int(newpos[i]*self.steppers[i].inv_step_dist + 0.5) self.stepper_pos = [int(newpos[i]*self.steppers[i].inv_step_dist + 0.5)
for i in StepList] for i in StepList]
def get_max_xy_speed(self): def get_max_xy_speed(self):
max_xy_speed = min(s.max_step_velocity*s.step_dist max_xy_speed = min(s.max_velocity for s in self.steppers[:2])
for s in self.steppers[:2]) max_xy_accel = min(s.max_accel for s in self.steppers[:2])
max_xy_accel = min(s.max_step_accel*s.step_dist
for s in self.steppers[:2])
return max_xy_speed, max_xy_accel return max_xy_speed, max_xy_accel
def get_max_speed(self, axes_d, move_d): def get_max_speed(self, axes_d, move_d):
# Calculate max speed and accel for a given move # Calculate max speed and accel for a given move
velocity_factor = min( velocity_factor = min([self.steppers[i].max_velocity / abs(axes_d[i])
[self.steppers[i].max_step_velocity
* self.steppers[i].step_dist / abs(axes_d[i])
for i in StepList if axes_d[i]]) for i in StepList if axes_d[i]])
accel_factor = min( accel_factor = min([self.steppers[i].max_accel / abs(axes_d[i])
[self.steppers[i].max_step_accel
* self.steppers[i].step_dist / abs(axes_d[i])
for i in StepList if axes_d[i]]) for i in StepList if axes_d[i]])
return velocity_factor * move_d, accel_factor * move_d return velocity_factor * move_d, accel_factor * move_d
def get_max_e_speed(self): def get_max_e_speed(self):
s = self.steppers[3] s = self.steppers[3]
return s.max_step_velocity*s.step_dist, s.max_step_accel*s.step_dist return s.max_velocity, s.max_accel
def home(self, toolhead, axis): def home(self, toolhead, axis):
# Each axis is homed independently and in order # Each axis is homed independently and in order
homing_state = homing.Homing(toolhead, self.steppers) # XXX homing_state = homing.Homing(toolhead, self.steppers) # XXX

View File

@ -13,10 +13,8 @@ class PrinterStepper:
self.step_dist = config.getfloat('step_distance') self.step_dist = config.getfloat('step_distance')
self.inv_step_dist = 1. / self.step_dist self.inv_step_dist = 1. / self.step_dist
max_velocity = config.getfloat('max_velocity') self.max_velocity = config.getfloat('max_velocity')
self.max_step_velocity = max_velocity * self.inv_step_dist self.max_accel = config.getfloat('max_accel')
max_accel = config.getfloat('max_accel')
self.max_step_accel = max_accel * self.inv_step_dist
self.homing_speed = config.getfloat('homing_speed', 5.0) self.homing_speed = config.getfloat('homing_speed', 5.0)
self.homing_positive_dir = config.getboolean( self.homing_positive_dir = config.getboolean(
@ -36,7 +34,8 @@ class PrinterStepper:
step_pin = self.config.get('step_pin') step_pin = self.config.get('step_pin')
dir_pin = self.config.get('dir_pin') dir_pin = self.config.get('dir_pin')
jc = 0.005 # XXX jc = 0.005 # XXX
min_stop_interval = int((math.sqrt(1./self.max_step_accel + jc**2) - jc) inv_max_step_accel = self.step_dist / self.max_accel
min_stop_interval = int((math.sqrt(inv_max_step_accel + jc**2) - jc)
* self.clock_ticks) - max_error * self.clock_ticks) - max_error
min_stop_interval = max(0, min_stop_interval) min_stop_interval = max(0, min_stop_interval)
mcu = self.printer.mcu mcu = self.printer.mcu