stepper: Store pointers to step_const and step_delta in PrinterStepper

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor 2017-11-07 12:12:28 -05:00
parent fc1d690d75
commit eecf3b6ea8
5 changed files with 28 additions and 35 deletions

View File

@ -107,7 +107,7 @@ class CartKinematics:
axis_d = move.axes_d[i]
if not axis_d:
continue
mcu_stepper = self.steppers[i].mcu_stepper
step_const = self.steppers[i].step_const
move_time = print_time
start_pos = move.start_pos[i]
axis_r = abs(axis_d) / move.move_d
@ -117,19 +117,17 @@ class CartKinematics:
# Acceleration steps
if move.accel_r:
accel_d = move.accel_r * axis_d
mcu_stepper.step_const(
move_time, start_pos, accel_d, move.start_v * axis_r, accel)
step_const(move_time, start_pos, accel_d,
move.start_v * axis_r, accel)
start_pos += accel_d
move_time += move.accel_t
# Cruising steps
if move.cruise_r:
cruise_d = move.cruise_r * axis_d
mcu_stepper.step_const(
move_time, start_pos, cruise_d, cruise_v, 0.)
step_const(move_time, start_pos, cruise_d, cruise_v, 0.)
start_pos += cruise_d
move_time += move.cruise_t
# Deceleration steps
if move.decel_r:
decel_d = move.decel_r * axis_d
mcu_stepper.step_const(
move_time, start_pos, decel_d, cruise_v, -accel)
step_const(move_time, start_pos, decel_d, cruise_v, -accel)

View File

@ -122,7 +122,7 @@ class CoreXYKinematics:
axis_d = axes_d[i]
if not axis_d:
continue
mcu_stepper = self.steppers[i].mcu_stepper
step_const = self.steppers[i].step_const
move_time = print_time
start_pos = move_start_pos[i]
axis_r = abs(axis_d) / move.move_d
@ -132,19 +132,17 @@ class CoreXYKinematics:
# Acceleration steps
if move.accel_r:
accel_d = move.accel_r * axis_d
mcu_stepper.step_const(
move_time, start_pos, accel_d, move.start_v * axis_r, accel)
step_const(move_time, start_pos, accel_d,
move.start_v * axis_r, accel)
start_pos += accel_d
move_time += move.accel_t
# Cruising steps
if move.cruise_r:
cruise_d = move.cruise_r * axis_d
mcu_stepper.step_const(
move_time, start_pos, cruise_d, cruise_v, 0.)
step_const(move_time, start_pos, cruise_d, cruise_v, 0.)
start_pos += cruise_d
move_time += move.cruise_t
# Deceleration steps
if move.decel_r:
decel_d = move.decel_r * axis_d
mcu_stepper.step_const(
move_time, start_pos, decel_d, cruise_v, -accel)
step_const(move_time, start_pos, decel_d, cruise_v, -accel)

View File

@ -201,26 +201,23 @@ class DeltaKinematics:
vt_startz = origz
# Generate steps
mcu_stepper = self.steppers[i].mcu_stepper
step_delta = self.steppers[i].step_delta
move_time = print_time
if accel_d:
mcu_stepper.step_delta(
move_time, accel_d, move.start_v, accel,
vt_startz, vt_startxy_d, vt_arm_d, movez_r)
step_delta(move_time, accel_d, move.start_v, accel,
vt_startz, vt_startxy_d, vt_arm_d, movez_r)
vt_startz += accel_d * movez_r
vt_startxy_d -= accel_d * movexy_r
move_time += move.accel_t
if cruise_d:
mcu_stepper.step_delta(
move_time, cruise_d, cruise_v, 0.,
vt_startz, vt_startxy_d, vt_arm_d, movez_r)
step_delta(move_time, cruise_d, cruise_v, 0.,
vt_startz, vt_startxy_d, vt_arm_d, movez_r)
vt_startz += cruise_d * movez_r
vt_startxy_d -= cruise_d * movexy_r
move_time += move.cruise_t
if decel_d:
mcu_stepper.step_delta(
move_time, decel_d, cruise_v, -accel,
vt_startz, vt_startxy_d, vt_arm_d, movez_r)
step_delta(move_time, decel_d, cruise_v, -accel,
vt_startz, vt_startxy_d, vt_arm_d, movez_r)
######################################################################

View File

@ -189,29 +189,27 @@ class PrinterExtruder:
decel_d -= extra_decel_d
# Prepare for steps
mcu_stepper = self.stepper.mcu_stepper
step_const = self.stepper.step_const
move_time = print_time
# Acceleration steps
if accel_d:
mcu_stepper.step_const(move_time, start_pos, accel_d, start_v, accel)
step_const(move_time, start_pos, accel_d, start_v, accel)
start_pos += accel_d
move_time += accel_t
# Cruising steps
if cruise_d:
mcu_stepper.step_const(move_time, start_pos, cruise_d, cruise_v, 0.)
step_const(move_time, start_pos, cruise_d, cruise_v, 0.)
start_pos += cruise_d
move_time += cruise_t
# Deceleration steps
if decel_d:
mcu_stepper.step_const(
move_time, start_pos, decel_d, decel_v, -accel)
step_const(move_time, start_pos, decel_d, decel_v, -accel)
start_pos += decel_d
move_time += decel_t
# Retraction steps
if retract_d:
mcu_stepper.step_const(
move_time, start_pos, -retract_d, retract_v, accel)
step_const(move_time, start_pos, -retract_d, retract_v, accel)
start_pos -= retract_d
self.extrude_pos = start_pos

View File

@ -12,21 +12,23 @@ class PrinterStepper:
self.name = config.section
if self.name.startswith('stepper_'):
self.name = self.name[8:]
self.step_dist = config.getfloat('step_distance', above=0.)
self.need_motor_enable = True
# Stepper definition
self.mcu_stepper = pins.setup_pin(
printer, 'stepper', config.get('step_pin'))
dir_pin_params = pins.get_printer_pins(printer).parse_pin_desc(
config.get('dir_pin'), can_invert=True)
self.mcu_stepper.setup_dir_pin(dir_pin_params)
self.step_dist = config.getfloat('step_distance', above=0.)
self.mcu_stepper.setup_step_distance(self.step_dist)
self.step_const = self.mcu_stepper.step_const
self.step_delta = self.mcu_stepper.step_delta
# Enable pin
enable_pin = config.get('enable_pin', None)
self.mcu_enable = None
if enable_pin is not None:
self.mcu_enable = pins.setup_pin(printer, 'digital_out', enable_pin)
self.mcu_enable.setup_max_duration(0.)
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