Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
0xD34D committed Mar 16, 2024
2 parents de89acf + bfb71bc commit 2577877
Show file tree
Hide file tree
Showing 20 changed files with 140 additions and 67 deletions.
1 change: 0 additions & 1 deletion config/printer-anycubic-4maxpro-2.0-2021.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@ restart_method: arduino
kinematics: cartesian
max_velocity: 150
max_accel: 3000
max_accel_to_decel: 1500
max_z_velocity: 7
max_z_accel: 50
square_corner_velocity: 5
Expand Down
2 changes: 1 addition & 1 deletion config/printer-anycubic-kobra-go-2022.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ cycle_time: 0.00005 #20kHz

[output_pin enable_pin]
pin: PB6
static_value: 1
value: 1
#This pin enables the bed, hotend, extruder fan, part fan.

[mcu]
Expand Down
4 changes: 2 additions & 2 deletions config/printer-anycubic-kobra-plus-2022.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
# To build the firmware, use the following configuration:
# - Micro-controller: Huada Semiconductor HC32F460
# - Communication interface: Serial (PA3 & PA2) - Anycube
# - Clock Speed: 200 MHz
#
# Installation:
# 1. Rename the klipper bin to `firmware.bin` and copy it to an SD Card.
Expand Down Expand Up @@ -144,10 +145,9 @@ max_temp: 120
pause_on_runout: True
switch_pin: !PC13

[heater_fan controller_fan]
[controller_fan controller_fan]
pin: PA14
heater: heater_bed
heater_temp: 45.0

[heater_fan hotend_fan]
pin: PA13
Expand Down
2 changes: 1 addition & 1 deletion config/printer-sovol-sv05-2022.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ restart_method: command
kinematics: cartesian
max_velocity: 300
max_accel: 1000
max_accel_to_decel: 1000
minimum_cruise_ratio: 0.0
max_z_velocity: 5
max_z_accel: 100

Expand Down
8 changes: 8 additions & 0 deletions docs/Config_Changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@ All dates in this document are approximate.

## Changes

20240313: The `max_accel_to_decel` parameter in the `[printer]` config
section has been deprecated. The `ACCEL_TO_DECEL` parameter of the
`SET_VELOCITY_LIMIT` command has been deprecated. The
`printer.toolhead.max_accel_to_decel` status has been removed. Use the
[minimum_cruise_ratio parameter](./Config_Reference.md#printer)
instead. The deprecated features will be removed in the near future,
and using them in the interim may result in subtly different behavior.

20240215: Several deprecated features have been removed. Using "NTC
100K beta 3950" as a thermistor name has been removed (deprecated on
20211110). The `SYNC_STEPPER_TO_EXTRUDER` and
Expand Down
25 changes: 18 additions & 7 deletions docs/Config_Reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,22 @@ max_accel:
# will do so at the rate specified here. The value specified here
# may be changed at runtime using the SET_VELOCITY_LIMIT command.
# This parameter must be specified.
#max_accel_to_decel:
# A pseudo acceleration (in mm/s^2) controlling how fast the
# toolhead may go from acceleration to deceleration. It is used to
# reduce the top speed of short zig-zag moves (and thus reduce
# printer vibration from these moves). The value specified here may
# be changed at runtime using the SET_VELOCITY_LIMIT command. The
# default is half of max_accel.
#minimum_cruise_ratio: 0.5
# Most moves will accelerate to a cruising speed, travel at that
# cruising speed, and then decelerate. However, some moves that
# travel a short distance could nominally accelerate and then
# immediately decelerate. This option reduces the top speed of these
# moves to ensure there is always a minimum distance traveled at a
# cruising speed. That is, it enforces a minimum distance traveled
# at cruising speed relative to the total distance traveled. It is
# intended to reduce the top speed of short zigzag moves (and thus
# reduce printer vibration from these moves). For example, a
# minimum_cruise_ratio of 0.5 would ensure that a standalone 1.5mm
# move would have a minimum cruising distance of 0.75mm. Specify a
# ratio of 0.0 to disable this feature (there would be no minimum
# cruising distance enforced between acceleration and deceleration).
# The value specified here may be changed at runtime using the
# SET_VELOCITY_LIMIT command. The default is 0.5.
#square_corner_velocity: 5.0
# The maximum velocity (in mm/s) that the toolhead may travel a 90
# degree corner at. A non-zero value can reduce changes in extruder
Expand All @@ -116,6 +125,8 @@ max_accel:
# decelerate to zero at each corner. The value specified here may be
# changed at runtime using the SET_VELOCITY_LIMIT command. The
# default is 5mm/s.
#max_accel_to_decel:
# This parameter is deprecated and should no longer be used.
```

### [stepper]
Expand Down
2 changes: 1 addition & 1 deletion docs/G-Codes.md
Original file line number Diff line number Diff line change
Expand Up @@ -1291,7 +1291,7 @@ The toolhead module is automatically loaded.

#### SET_VELOCITY_LIMIT
`SET_VELOCITY_LIMIT [VELOCITY=<value>] [ACCEL=<value>]
[ACCEL_TO_DECEL=<value>] [SQUARE_CORNER_VELOCITY=<value>]`: This
[MINIMUM_CRUISE_RATIO=<value>] [SQUARE_CORNER_VELOCITY=<value>]`: This
command can alter the velocity limits that were specified in the
printer config file. See the
[printer config section](Config_Reference.md#printer) for a
Expand Down
28 changes: 17 additions & 11 deletions docs/Kinematics.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ Key formula for look-ahead:
end_velocity^2 = start_velocity^2 + 2*accel*move_distance
```

### Smoothed look-ahead
### Minimum cruise ratio

Klipper also implements a mechanism for smoothing out the motions of
short "zigzag" moves. Consider the following moves:
Expand All @@ -105,21 +105,27 @@ short "zigzag" moves. Consider the following moves:

In the above, the frequent changes from acceleration to deceleration
can cause the machine to vibrate which causes stress on the machine
and increases the noise. To reduce this, Klipper tracks both regular
move acceleration as well as a virtual "acceleration to deceleration"
rate. Using this system, the top speed of these short "zigzag" moves
are limited to smooth out the printer motion:
and increases the noise. Klipper implements a mechanism to ensure
there is always some movement at a cruising speed between acceleration
and deceleration. This is done by reducing the top speed of some moves
(or sequence of moves) to ensure there is a minimum distance traveled
at cruising speed relative to the distance traveled during
acceleration and deceleration.

Klipper implements this feature by tracking both a regular move
acceleration as well as a virtual "acceleration to deceleration" rate:

![smoothed](img/smoothed.svg.png)

Specifically, the code calculates what the velocity of each move would
be if it were limited to this virtual "acceleration to deceleration"
rate (half the normal acceleration rate by default). In the above
picture the dashed gray lines represent this virtual acceleration rate
for the first move. If a move can not reach its full cruising speed
using this virtual acceleration rate then its top speed is reduced to
the maximum speed it could obtain at this virtual acceleration
rate. For most moves the limit will be at or above the move's existing
rate. In the above picture the dashed gray lines represent this
virtual acceleration rate for the first move. If a move can not reach
its full cruising speed using this virtual acceleration rate then its
top speed is reduced to the maximum speed it could obtain at this
virtual acceleration rate.

For most moves the limit will be at or above the move's existing
limits and no change in behavior is induced. For short zigzag moves,
however, this limit reduces the top speed. Note that it does not
change the actual acceleration within the move - the move continues to
Expand Down
10 changes: 5 additions & 5 deletions docs/Resonance_Compensation.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ First, measure the **ringing frequency**.
to 5.0. It is not advised to increase it when using input shaper
because it can cause more smoothing in parts - it is better to use
higher acceleration value instead.
2. Increase `max_accel_to_decel` by issuing the following command:
`SET_VELOCITY_LIMIT ACCEL_TO_DECEL=7000`
2. Disable the `miminum_cruise_ratio` feature by issuing the following
command: `SET_VELOCITY_LIMIT MINIMUM_CRUISE_RATIO=0`
3. Disable Pressure Advance: `SET_PRESSURE_ADVANCE ADVANCE=0`
4. If you have already added `[input_shaper]` section to the printer.cfg,
execute `SET_INPUT_SHAPER SHAPER_FREQ_X=0 SHAPER_FREQ_Y=0` command. If you
Expand Down Expand Up @@ -149,7 +149,7 @@ a few other related parameters.
Print the ringing test model as follows:

1. Restart the firmware: `RESTART`
2. Prepare for test: `SET_VELOCITY_LIMIT ACCEL_TO_DECEL=7000`
2. Prepare for test: `SET_VELOCITY_LIMIT MINIMUM_CRUISE_RATIO=0`
3. Disable Pressure Advance: `SET_PRESSURE_ADVANCE ADVANCE=0`
4. Execute: `SET_INPUT_SHAPER SHAPER_TYPE=MZV`
5. Execute the command:
Expand Down Expand Up @@ -270,7 +270,7 @@ frequencies after enabling [input_shaper], this section will not help with that.
Assuming that you have sliced the ringing model with suggested
parameters, complete the following steps for each of the axes X and Y:

1. Prepare for test: `SET_VELOCITY_LIMIT ACCEL_TO_DECEL=7000`
1. Prepare for test: `SET_VELOCITY_LIMIT MINIMUM_CRUISE_RATIO=0`
2. Make sure Pressure Advance is disabled: `SET_PRESSURE_ADVANCE ADVANCE=0`
3. Execute: `SET_INPUT_SHAPER SHAPER_TYPE=ZV`
4. From the existing ringing test model with your chosen input shaper select
Expand Down Expand Up @@ -331,7 +331,7 @@ with suggested parameters, print the test model 3 times as
follows. First time, prior to printing, run

1. `RESTART`
2. `SET_VELOCITY_LIMIT ACCEL_TO_DECEL=7000`
2. `SET_VELOCITY_LIMIT MINIMUM_CRUISE_RATIO=0`
3. `SET_PRESSURE_ADVANCE ADVANCE=0`
4. `SET_INPUT_SHAPER SHAPER_TYPE=2HUMP_EI SHAPER_FREQ_X=60 SHAPER_FREQ_Y=60`
5. `TUNING_TOWER COMMAND=SET_VELOCITY_LIMIT PARAMETER=ACCEL START=1500 STEP_DELTA=500 STEP_HEIGHT=5`
Expand Down
2 changes: 1 addition & 1 deletion docs/Status_Reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,7 @@ The following information is available in the `toolhead` object
limit value (eg, `axis_minimum.x`, `axis_maximum.z`).
- For Delta printers the `cone_start_z` is the max z height at
maximum radius (`printer.toolhead.cone_start_z`).
- `max_velocity`, `max_accel`, `max_accel_to_decel`,
- `max_velocity`, `max_accel`, `minimum_cruise_ratio`,
`square_corner_velocity`: The current printing limits that are in
effect. This may differ from the config file settings if a
`SET_VELOCITY_LIMIT` (or `M204`) command alters them at run-time.
Expand Down
12 changes: 10 additions & 2 deletions klippy/configfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@ def __init__(self, printer):
self.printer = printer
self.autosave = None
self.deprecated = {}
self.runtime_warnings = []
self.deprecate_warnings = []
self.status_raw_config = {}
self.status_save_pending = {}
self.status_settings = {}
Expand Down Expand Up @@ -314,6 +316,11 @@ def log_config(self, config):
"======================="]
self.printer.set_rollover_info("config", "\n".join(lines))
# Status reporting
def runtime_warning(self, msg):
logging.warn(msg)
res = {'type': 'runtime_warning', 'message': msg}
self.runtime_warnings.append(res)
self.status_warnings = self.runtime_warnings + self.deprecate_warnings
def deprecate(self, section, option, value=None, msg=None):
self.deprecated[(section, option, value)] = msg
def _build_status(self, config):
Expand All @@ -325,7 +332,7 @@ def _build_status(self, config):
self.status_settings = {}
for (section, option), value in config.access_tracking.items():
self.status_settings.setdefault(section, {})[option] = value
self.status_warnings = []
self.deprecate_warnings = []
for (section, option, value), msg in self.deprecated.items():
if value is None:
res = {'type': 'deprecated_option'}
Expand All @@ -334,7 +341,8 @@ def _build_status(self, config):
res['message'] = msg
res['section'] = section
res['option'] = option
self.status_warnings.append(res)
self.deprecate_warnings.append(res)
self.status_warnings = self.runtime_warnings + self.deprecate_warnings
def get_status(self, eventtime):
return {'config': self.status_raw_config,
'settings': self.status_settings,
Expand Down
18 changes: 13 additions & 5 deletions klippy/extras/heaters.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
class Heater:
def __init__(self, config, sensor):
self.printer = config.get_printer()
self.name = config.get_name().split()[-1]
self.name = config.get_name()
self.short_name = short_name = self.name.split()[-1]
# Setup sensor
self.sensor = sensor
self.min_temp = config.getfloat('min_temp', minval=KELVIN_TO_CELSIUS)
Expand All @@ -36,6 +37,7 @@ def __init__(self, config, sensor):
self.max_power = config.getfloat('max_power', 1., above=0., maxval=1.)
self.smooth_time = config.getfloat('smooth_time', 1., above=0.)
self.inv_smooth_time = 1. / self.smooth_time
self.is_shutdown = False
self.lock = threading.Lock()
self.last_temp = self.smoothed_temp = self.target_temp = 0.
self.last_temp_time = 0.
Expand All @@ -55,14 +57,16 @@ def __init__(self, config, sensor):
self.mcu_pwm.setup_cycle_time(pwm_cycle_time)
self.mcu_pwm.setup_max_duration(MAX_HEAT_TIME)
# Load additional modules
self.printer.load_object(config, "verify_heater %s" % (self.name,))
self.printer.load_object(config, "verify_heater %s" % (short_name,))
self.printer.load_object(config, "pid_calibrate")
gcode = self.printer.lookup_object("gcode")
gcode.register_mux_command("SET_HEATER_TEMPERATURE", "HEATER",
self.name, self.cmd_SET_HEATER_TEMPERATURE,
short_name, self.cmd_SET_HEATER_TEMPERATURE,
desc=self.cmd_SET_HEATER_TEMPERATURE_help)
self.printer.register_event_handler("klippy:shutdown",
self._handle_shutdown)
def set_pwm(self, read_time, value):
if self.target_temp <= 0.:
if self.target_temp <= 0. or self.is_shutdown:
value = 0.
if ((read_time < self.next_pwm_time or not self.last_pwm_value)
and abs(value - self.last_pwm_value) < 0.05):
Expand All @@ -86,7 +90,11 @@ def temperature_callback(self, read_time, temp):
self.smoothed_temp += temp_diff * adj_time
self.can_extrude = (self.smoothed_temp >= self.min_extrude_temp)
#logging.debug("temp: %.3f %f = %f", read_time, temp)
def _handle_shutdown(self):
self.is_shutdown = True
# External commands
def get_name(self):
return self.name
def get_pwm_delay(self):
return self.pwm_delay
def get_max_power(self):
Expand Down Expand Up @@ -127,7 +135,7 @@ def stats(self, eventtime):
last_pwm_value = self.last_pwm_value
is_active = target_temp or last_temp > 50.
return is_active, '%s: target=%.0f temp=%.1f pwm=%.3f' % (
self.name, target_temp, last_temp, last_pwm_value)
self.short_name, target_temp, last_temp, last_pwm_value)
def get_status(self, eventtime):
with self.lock:
target_temp = self.target_temp
Expand Down
9 changes: 5 additions & 4 deletions klippy/extras/pid_calibrate.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,12 @@ def cmd_PID_CALIBRATE(self, gcmd):
"The SAVE_CONFIG command will update the printer config file\n"
"with these parameters and restart the printer." % (Kp, Ki, Kd))
# Store results for SAVE_CONFIG
cfgname = heater.get_name()
configfile = self.printer.lookup_object('configfile')
configfile.set(heater_name, 'control', 'pid')
configfile.set(heater_name, 'pid_Kp', "%.3f" % (Kp,))
configfile.set(heater_name, 'pid_Ki', "%.3f" % (Ki,))
configfile.set(heater_name, 'pid_Kd', "%.3f" % (Kd,))
configfile.set(cfgname, 'control', 'pid')
configfile.set(cfgname, 'pid_Kp', "%.3f" % (Kp,))
configfile.set(cfgname, 'pid_Ki', "%.3f" % (Ki,))
configfile.set(cfgname, 'pid_Kd', "%.3f" % (Kd,))

TUNE_PID_DELTA = 5.0

Expand Down
10 changes: 5 additions & 5 deletions klippy/extras/resonance_tester.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,11 @@ def run_test(self, axis, gcmd):
systime = self.printer.get_reactor().monotonic()
toolhead_info = toolhead.get_status(systime)
old_max_accel = toolhead_info['max_accel']
old_max_accel_to_decel = toolhead_info['max_accel_to_decel']
old_minimum_cruise_ratio = toolhead_info['minimum_cruise_ratio']
max_accel = self.freq_end * self.accel_per_hz
self.gcode.run_script_from_command(
"SET_VELOCITY_LIMIT ACCEL=%.3f ACCEL_TO_DECEL=%.3f" % (
max_accel, max_accel))
"SET_VELOCITY_LIMIT ACCEL=%.3f MINIMUM_CRUISE_RATIO=0"
% (max_accel,))
input_shaper = self.printer.lookup_object('input_shaper', None)
if input_shaper is not None and not gcmd.get_int('INPUT_SHAPING', 0):
input_shaper.disable_shaping()
Expand All @@ -108,8 +108,8 @@ def run_test(self, axis, gcmd):
gcmd.respond_info("Testing frequency %.0f Hz" % (freq,))
# Restore the original acceleration values
self.gcode.run_script_from_command(
"SET_VELOCITY_LIMIT ACCEL=%.3f ACCEL_TO_DECEL=%.3f" % (
old_max_accel, old_max_accel_to_decel))
"SET_VELOCITY_LIMIT ACCEL=%.3f MINIMUM_CRUISE_RATIO=%.3f"
% (old_max_accel, old_minimum_cruise_ratio))
# Restore input shaper if it was disabled for resonance testing
if input_shaper is not None:
input_shaper.enable_shaping()
Expand Down
16 changes: 16 additions & 0 deletions klippy/mcu.py
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,7 @@ def __init__(self, config, clocksync):
printer.register_event_handler("klippy:connect", self._connect)
printer.register_event_handler("klippy:shutdown", self._shutdown)
printer.register_event_handler("klippy:disconnect", self._disconnect)
printer.register_event_handler("klippy:ready", self._ready)
# Serial callbacks
def _handle_mcu_stats(self, params):
count = params['count']
Expand Down Expand Up @@ -799,6 +800,21 @@ def _mcu_identify(self):
self.register_response(self._handle_shutdown, 'shutdown')
self.register_response(self._handle_shutdown, 'is_shutdown')
self.register_response(self._handle_mcu_stats, 'stats')
def _ready(self):
if self.is_fileoutput():
return
# Check that reported mcu frequency is in range
mcu_freq = self._mcu_freq
systime = self._reactor.monotonic()
get_clock = self._clocksync.get_clock
calc_freq = get_clock(systime + 1) - get_clock(systime)
mcu_freq_mhz = int(mcu_freq / 1000000. + 0.5)
calc_freq_mhz = int(calc_freq / 1000000. + 0.5)
if mcu_freq_mhz != calc_freq_mhz:
pconfig = self._printer.lookup_object('configfile')
msg = ("MCU '%s' configured for %dMhz but running at %dMhz!"
% (self._name, mcu_freq_mhz, calc_freq_mhz))
pconfig.runtime_warning(msg)
# Config creation helpers
def setup_pin(self, pin_type, pin_params):
pcs = {'endstop': MCU_endstop,
Expand Down
Loading

0 comments on commit 2577877

Please sign in to comment.