toolhead: Specify maximum acceleration and velocity in toolhead class

Change the config file so the maximum accel and velocity are specified
in the "printer" section instead of the individual "stepper" sections.
The underlying code limits the velocity and accel of the toolhead
relative to the print object, so it makes sense to configure the
system that was as well.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor 2016-12-01 15:29:26 -05:00
parent fcaf359e89
commit c49d3fdb17
8 changed files with 52 additions and 53 deletions

View File

@ -16,8 +16,6 @@ step_pin: ar54
dir_pin: ar55 dir_pin: ar55
enable_pin: !ar38 enable_pin: !ar38
step_distance: .01 step_distance: .01
max_velocity: 200
max_accel: 3000
endstop_pin: ^ar2 endstop_pin: ^ar2
homing_speed: 50.0 homing_speed: 50.0
position_endstop: 297.05 position_endstop: 297.05
@ -30,8 +28,6 @@ step_pin: ar60
dir_pin: ar61 dir_pin: ar61
enable_pin: !ar56 enable_pin: !ar56
step_distance: .01 step_distance: .01
max_velocity: 200
max_accel: 3000
endstop_pin: ^ar15 endstop_pin: ^ar15
position_endstop: 297.05 position_endstop: 297.05
@ -42,8 +38,6 @@ step_pin: ar46
dir_pin: ar48 dir_pin: ar48
enable_pin: !ar62 enable_pin: !ar62
step_distance: .01 step_distance: .01
max_velocity: 200
max_accel: 3000
endstop_pin: ^ar19 endstop_pin: ^ar19
position_endstop: 297.05 position_endstop: 297.05
@ -85,6 +79,8 @@ pin_map: arduino
[printer] [printer]
kinematics: delta kinematics: delta
# This option must be "delta" for linear delta printers # This option must be "delta" for linear delta printers
max_velocity: 200
max_accel: 3000
delta_arm_length: 333.0 delta_arm_length: 333.0
# Length (in mm) of the diagonal rods that connect the linear axes # Length (in mm) of the diagonal rods that connect the linear axes
# to the print head # to the print head

View File

@ -26,10 +26,6 @@ enable_pin: !ar25
# Enable pin (default is enable high; use ! to indicate enable low) # Enable pin (default is enable high; use ! to indicate enable low)
step_distance: .0225 step_distance: .0225
# Distance in mm that each step causes the axis to travel # Distance in mm that each step causes the axis to travel
max_velocity: 500
# Maximum velocity (in mm/s) of the stepper
max_accel: 3000
# Maximum acceleration (in mm/s^2) of the stepper
endstop_pin: ^ar0 endstop_pin: ^ar0
# Endstop switch detection pin # Endstop switch detection pin
homing_speed: 50.0 homing_speed: 50.0
@ -75,8 +71,6 @@ step_pin: ar27
dir_pin: ar26 dir_pin: ar26
enable_pin: !ar25 enable_pin: !ar25
step_distance: .0225 step_distance: .0225
max_velocity: 500
max_accel: 3000
endstop_pin: ^ar1 endstop_pin: ^ar1
position_min: -0.25 position_min: -0.25
position_endstop: 0 position_endstop: 0
@ -90,8 +84,6 @@ step_pin: ar23
dir_pin: !ar22 dir_pin: !ar22
enable_pin: !ar25 enable_pin: !ar25
step_distance: .005 step_distance: .005
max_velocity: 250
max_accel: 30
endstop_pin: ^ar2 endstop_pin: ^ar2
position_min: 0.1 position_min: 0.1
position_endstop: 0.5 position_endstop: 0.5
@ -108,7 +100,12 @@ dir_pin: ar18
enable_pin: !ar25 enable_pin: !ar25
step_distance: .004242 step_distance: .004242
max_velocity: 200000 max_velocity: 200000
# Maximum velocity (in mm/s) of the extruder motor for extrude only
# moves.
max_accel: 3000 max_accel: 3000
# Maximum acceleration (in mm/s^2) of the extruder motor for extrude
# only moves.
#
# The remaining variables describe the extruder heater # The remaining variables describe the extruder heater
pressure_advance: 0.0 pressure_advance: 0.0
# The amount of raw filament to push into the extruder during # The amount of raw filament to push into the extruder during
@ -191,6 +188,20 @@ custom:
[printer] [printer]
kinematics: cartesian kinematics: cartesian
# This option must be "cartesian" for cartesian printers # This option must be "cartesian" for cartesian printers
max_velocity: 500
# Maximum velocity (in mm/s) of the toolhead (relative to the
# print)
max_accel: 3000
# Maximum acceleration (in mm/s^2) of the toolhead (relative to the
# print)
max_z_velocity: 250
# For cartesian printers this sets the maximum velocity (in mm/s) of
# movement along the z axis. This setting can be used to restrict
# the maximum speed of the z stepper motor on cartesian printers.
max_z_accel: 30
# For cartesian printers this sets the maximum acceleration (in
# mm/s^2) of movement along the z axis. It limits the acceleration
# of the z stepper motor on cartesian printers.
motor_off_time: 60 motor_off_time: 60
# Time (in seconds) of idle time before the printer will try to # Time (in seconds) of idle time before the printer will try to
# disable active motors. # disable active motors.

View File

@ -8,8 +8,6 @@ step_pin: PC0
dir_pin: !PL1 dir_pin: !PL1
enable_pin: !PA7 enable_pin: !PA7
step_distance: .0225 step_distance: .0225
max_velocity: 500
max_accel: 3000
endstop_pin: ^!PB6 endstop_pin: ^!PB6
homing_speed: 50.0 homing_speed: 50.0
homing_stepper_phases: 32 homing_stepper_phases: 32
@ -23,8 +21,6 @@ step_pin: PC1
dir_pin: PL0 dir_pin: PL0
enable_pin: !PA6 enable_pin: !PA6
step_distance: .0225 step_distance: .0225
max_velocity: 500
max_accel: 3000
endstop_pin: ^!PB5 endstop_pin: ^!PB5
homing_speed: 50.0 homing_speed: 50.0
homing_stepper_phases: 32 homing_stepper_phases: 32
@ -38,8 +34,6 @@ step_pin: PC2
dir_pin: !PL2 dir_pin: !PL2
enable_pin: !PA5 enable_pin: !PA5
step_distance: .005 step_distance: .005
max_velocity: 250
max_accel: 30
endstop_pin: ^!PB4 endstop_pin: ^!PB4
homing_speed: 4.0 homing_speed: 4.0
homing_retract_dist: 2.0 homing_retract_dist: 2.0
@ -105,4 +99,8 @@ custom:
[printer] [printer]
kinematics: cartesian kinematics: cartesian
max_velocity: 500
max_accel: 3000
max_z_velocity: 250
max_z_accel: 30
motor_off_time: 600 motor_off_time: 600

View File

@ -13,21 +13,21 @@ class CartKinematics:
self.steppers = [stepper.PrinterStepper( self.steppers = [stepper.PrinterStepper(
printer, config.getsection('stepper_' + n), n) printer, config.getsection('stepper_' + n), n)
for n in ['x', 'y', 'z']] for n in ['x', 'y', 'z']]
self.max_z_velocity = config.getfloat('max_z_velocity', 9999999.9)
self.max_z_accel = config.getfloat('max_z_accel', 9999999.9)
self.need_motor_enable = True self.need_motor_enable = True
self.limits = [(1.0, -1.0)] * 3 self.limits = [(1.0, -1.0)] * 3
def set_max_jerk(self, max_xy_halt_velocity, 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)
def build_config(self): def build_config(self):
for stepper in self.steppers[:2]:
stepper.set_max_jerk(0.005 * stepper.max_accel) # XXX
for stepper in self.steppers: for stepper in self.steppers:
stepper.build_config() stepper.build_config()
def set_position(self, newpos): def set_position(self, newpos):
for i in StepList: for i in StepList:
s = self.steppers[i] s = self.steppers[i]
s.mcu_stepper.set_position(int(newpos[i]*s.inv_step_dist + 0.5)) s.mcu_stepper.set_position(int(newpos[i]*s.inv_step_dist + 0.5))
def get_max_speed(self):
max_xy_speed = min(s.max_velocity for s in self.steppers[:2])
max_xy_accel = min(s.max_accel for s in self.steppers[:2])
return max_xy_speed, max_xy_accel
def get_homed_position(self, homing_state): def get_homed_position(self, homing_state):
pos = [None]*3 pos = [None]*3
for axis in homing_state.get_axes(): for axis in homing_state.get_axes():
@ -99,13 +99,9 @@ class CartKinematics:
return return
# Move with Z - update velocity and accel for slower Z axis # Move with Z - update velocity and accel for slower Z axis
self.check_endstops(move) self.check_endstops(move)
axes_d = move.axes_d z_ratio = move.move_d / abs(move.axes_d[2])
move_d = move.move_d move.limit_speed(
velocity_factor = min([self.steppers[i].max_velocity / abs(axes_d[i]) self.max_z_velocity * z_ratio, self.max_z_accel * z_ratio)
for i in StepList if axes_d[i]])
accel_factor = min([self.steppers[i].max_accel / abs(axes_d[i])
for i in StepList if axes_d[i]])
move.limit_speed(velocity_factor * move_d, accel_factor * move_d)
def move(self, move_time, move): def move(self, move_time, move):
if self.need_motor_enable: if self.need_motor_enable:
self.check_motor_enable(move_time, move) self.check_motor_enable(move_time, move)

View File

@ -28,17 +28,14 @@ class DeltaKinematics:
(cos(210.)*radius, sin(210.)*radius), (cos(210.)*radius, sin(210.)*radius),
(cos(330.)*radius, sin(330.)*radius), (cos(330.)*radius, sin(330.)*radius),
(cos(90.)*radius, sin(90.)*radius)] (cos(90.)*radius, sin(90.)*radius)]
def build_config(self): def set_max_jerk(self, max_xy_halt_velocity, max_accel):
# XXX - this sets conservative values
for stepper in self.steppers: for stepper in self.steppers:
stepper.set_max_jerk(0.005 * stepper.max_accel) # XXX stepper.set_max_jerk(max_xy_halt_velocity, max_accel)
def build_config(self):
for stepper in self.steppers: for stepper in self.steppers:
stepper.build_config() stepper.build_config()
self.set_position([0., 0., 0.]) self.set_position([0., 0., 0.])
def get_max_speed(self):
# XXX - this returns conservative values
max_xy_speed = min(s.max_velocity for s in self.steppers)
max_xy_accel = min(s.max_accel for s in self.steppers)
return max_xy_speed, max_xy_accel
def cartesian_to_actuator(self, coord): def cartesian_to_actuator(self, coord):
return [int((math.sqrt(self.arm_length2 return [int((math.sqrt(self.arm_length2
- (self.towers[i][0] - coord[0])**2 - (self.towers[i][0] - coord[0])**2

View File

@ -11,11 +11,13 @@ class PrinterExtruder:
self.heater = heater.PrinterHeater(printer, config) self.heater = heater.PrinterHeater(printer, config)
self.stepper = stepper.PrinterStepper(printer, config, 'extruder') self.stepper = stepper.PrinterStepper(printer, config, 'extruder')
self.pressure_advance = config.getfloat('pressure_advance', 0.) self.pressure_advance = config.getfloat('pressure_advance', 0.)
self.max_e_velocity = config.getfloat('max_velocity')
self.max_e_accel = config.getfloat('max_accel')
self.need_motor_enable = True self.need_motor_enable = True
self.extrude_pos = 0. self.extrude_pos = 0.
def build_config(self): def build_config(self):
self.heater.build_config() self.heater.build_config()
self.stepper.set_max_jerk(9999999.9) self.stepper.set_max_jerk(9999999.9, 9999999.9)
self.stepper.build_config() self.stepper.build_config()
def motor_off(self, move_time): def motor_off(self, move_time):
self.stepper.motor_enable(move_time, 0) self.stepper.motor_enable(move_time, 0)
@ -28,7 +30,7 @@ class PrinterExtruder:
and not move.axes_d[0] and not move.axes_d[1] and not move.axes_d[0] and not move.axes_d[1]
and not move.axes_d[2]): and not move.axes_d[2]):
# Extrude only move - limit accel and velocity # Extrude only move - limit accel and velocity
move.limit_speed(self.stepper.max_velocity, self.stepper.max_accel) move.limit_speed(self.max_e_velocity, self.max_e_accel)
def move(self, move_time, move): def move(self, move_time, move):
if self.need_motor_enable: if self.need_motor_enable:
self.stepper.motor_enable(move_time, 1) self.stepper.motor_enable(move_time, 1)

View File

@ -15,9 +15,7 @@ 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
self.max_velocity = config.getfloat('max_velocity') self.min_stop_interval = 0.
self.max_accel = config.getfloat('max_accel')
self.max_jerk = 0.
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(
@ -47,17 +45,16 @@ class PrinterStepper:
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 set_max_jerk(self, max_jerk): def set_max_jerk(self, max_halt_velocity, max_accel):
self.max_jerk = max_jerk jc = max_halt_velocity / max_accel
inv_max_step_accel = self.step_dist / max_accel
self.min_stop_interval = (math.sqrt(3.*inv_max_step_accel + jc**2)
- math.sqrt(inv_max_step_accel + jc**2))
def build_config(self): def build_config(self):
max_error = self.config.getfloat('max_error', 0.000050) max_error = self.config.getfloat('max_error', 0.000050)
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 = self.max_jerk / self.max_accel min_stop_interval = max(0., self.min_stop_interval - max_error)
inv_max_step_accel = self.step_dist / self.max_accel
min_stop_interval = (math.sqrt(3.*inv_max_step_accel + jc**2)
- math.sqrt(inv_max_step_accel + jc**2)) - max_error
min_stop_interval = max(0., min_stop_interval)
mcu = self.printer.mcu mcu = self.printer.mcu
self.mcu_stepper = mcu.create_stepper( self.mcu_stepper = mcu.create_stepper(
step_pin, dir_pin, min_stop_interval, max_error) step_pin, dir_pin, min_stop_interval, max_error)

View File

@ -162,7 +162,8 @@ class ToolHead:
kintypes = {'cartesian': cartesian.CartKinematics, kintypes = {'cartesian': cartesian.CartKinematics,
'delta': delta.DeltaKinematics} 'delta': delta.DeltaKinematics}
self.kin = config.getchoice('kinematics', kintypes)(printer, config) self.kin = config.getchoice('kinematics', kintypes)(printer, config)
self.max_speed, self.max_accel = self.kin.get_max_speed() self.max_speed = config.getfloat('max_velocity')
self.max_accel = config.getfloat('max_accel')
self.junction_deviation = config.getfloat('junction_deviation', 0.02) self.junction_deviation = config.getfloat('junction_deviation', 0.02)
self.move_queue = MoveQueue() self.move_queue = MoveQueue()
self.commanded_pos = [0., 0., 0., 0.] self.commanded_pos = [0., 0., 0., 0.]
@ -176,6 +177,7 @@ class ToolHead:
self.motor_off_time = self.reactor.NEVER self.motor_off_time = self.reactor.NEVER
self.flush_timer = self.reactor.register_timer(self.flush_handler) self.flush_timer = self.reactor.register_timer(self.flush_handler)
def build_config(self): def build_config(self):
self.kin.set_max_jerk(0.005 * self.max_accel, self.max_accel) # XXX
self.kin.build_config() self.kin.build_config()
# Print time tracking # Print time tracking
def update_move_time(self, movetime): def update_move_time(self, movetime):