Due to differences in mcu clock vs system clock it's possible to
repeatedly underestimate a system delay needed to bring about a
sufficient mcu time - which just wastes cpu cycles retrying a pause.
It's okay to sleep a slightly longer time to avoid the issue.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Previously the code would always keep at least 2 items on the
lookahead queue after a "lazy" flush. In most cases it's okay to
leave only a single item. Update the code to better handle flushing
of items that are fully ready.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Replace "delayed" storage with a full pass through the queue. This
simplifies the lookahead processing logic.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Avoid using "smoothed" and "accel_to_decel" for variables associated
with minimum_cruise_ratio. Instead introduce the prefix "mcr" for use
with these variables.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Commit 7ea5f5d2 changed how the lookahead queue is flushed.
Previously, the main flush timer would always run while the toolhead
was considered in an active state (print_time). After that commit,
the flush timer could sleep if there were no steps generated (no call
to note_mcu_movequeue_activity() ). This could lead to a situation
where a G4 command (or series of commands) could cause the toolhead to
be considered in an active state while the flush timer was disabled.
The result was that a future command may not be properly flushed (the
toolhead would fail to transition to a "Priming" state).
Fix by ensuring that all dwell() requests fully flush the lookahead
queue.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Don't rely on an exact floating point number match to detect when a
forced lookahead flush is needed.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Don't tie the step generation logic to the toolhead lookahead logic.
Instead, use regular timers to generate steps with a goal of staying
500-750ms ahead of the micro-controllers.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Add a new is_runout parameter to _flush_lookahead() and use that in
places that could set check_stall_time.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Remove the toolhead note_step_generation_scan_time() code and
automatically detect the itersolve scan windows that are in use.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Move low-level step generation timing code to the motion_queing
module. This helps simplify the toolhead module. It also helps
centralize the step generation code into the motion_queing module.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Move the code that implements flushing in waves from
_advance_move_time() to _advance_flush_time(). This also separates
print_time tracking from the _advance_flush_time() implementation.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Automatically add kin_flush_delay to the requested flush time if
is_step_gen=True. This simplifies the callers.
Also, rename self.step_gen_time to self.need_step_gen_time.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Commit 3d3b87f9 renamed last_sg_flush_time to min_restart_time to
ensure that flush_step_generation() would fully flush out moves
generated from the force_move module. However, now that force_move
calls note_mcu_movequeue_activity() with is_step_gen=True, this is no
longer necessary.
Rework min_restart_time to last_step_gen_time.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Commit f8da8099 incorrectly changed the order of variables in the
log/response message of the SET_VELOCITY_LIMIT command. Restore the
correct order.
Reported by @berkakinci.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Move code from flush_steppersync() to existing flush_motion_queues()
and clean_motion_queues() functions.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Add an allocate_trapq() helper function to facilitate the creation of
a low-level C trapq object. Track all trapq objects and clear history
on them globally when the main motion queues are flushed.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Create a new module to assist with host management of motion queues.
Register all MCU_stepper objects with this module and use the module
for step generation.
All steppers will now automatically generate steps whenever
toolhead._advance_flush_time() is invoked. It is no longer necessary
for callers to individually call stepper.generate_steps().
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Change note_mcu_movequeue_activity() to default to setting the
step_gen_time (instead of the previous default to not set it).
Most users of the mcu "move queue" will be for stepper activity.
There is also little harm in incrementing the tracking of the last
possible step generation time, but accidentally generating a step
without incrementing the tracking can lead to very hard to debug
failures.
The two cases (output_pin.py and pwm_tool.py) where
note_mcu_movequeue_activity() is called and definitely not related to
step generation can explicitly pass 'is_step_gen=False'.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Move the g-code command handlers to a new class. This reduces the
size of the main Toolhead() class.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Add a new add_extra_axes() to support adding additional axes. Once
called, toolhead.get_position() will return a list object with more
than 4 items, and toolhead.move() requires the same size list.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
It's not valid to alter the extruder position from a call to
set_position(), so don't allow callers to attempt that.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Currently, `MANUAL_STEPPER STOP_ON_ENDSTOP=1` type commands will move
until hitting the endstop, but it will still always consume the total
amount of move time. That is, following moves can't be started until
the total possible time of the homing move is completed.
Implement "drip moves" so that the code only schedules the movement in
small segments. This allows following movements to be scheduled
without a significant delay.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Implement move checking and trapq loading directly from drip_move().
This simplifies the interactions between these components.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Avoid lookahead.flush() calling back into toolhead._process_moves().
Instead, rename toolhead._process_moves() to
toolhead._process_lookahead(), have it call lookahead.flush(), and
consistently use it when flushing the lookahead queue.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This significantly reduces the amount of data in the generation 2 garbage collection bucket from the initial startup of klipper.
Signed-off-by: Branden Cash <203336+ammmze@users.noreply.github.com>
Use strings such as "xyz" to specify which axes are to be considered
homing during a set_position() call. This makes the parameter a
little less cryptic.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This adds a new resonance test method that can help if a user has some mechanical problems with the printer.
Signed-off-by: Dmitry Butyugin <dmbutyugin@google.com>
When calculating the junction speed between two moves the code checked
for angles greater than 0.999999 or less than -0.999999 to avoid math
issues (sqrt of a negative number and/or divide by zero). However,
these arbitrary constants could unnecessarily pessimize junction
speeds when angles are close to 180 or 0 degrees.
Change the code to explicitly check for negative numbers during sqrt
and to explicilty check for zero values prior to division. This
simplifies the code and avoids unnecessarily reducing some junction
speeds.
Signed-off-by: Dmitry Butyugin <dmbutyugin@google.com>
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
As a minor math optimization, it's possible to calculate:
.5 * self.move_d * self.accel * tan_theta_d2
using:
self.delta_v2 * .25 * tan_theta_d2
because self.delta_v2 is "2. * self.move_d * self.accel".
Signed-off-by: Dmitry Butyugin <dmbutyugin@google.com>
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
The default minimum_cruise_ratio setting does not get populated to the
printer.configfile.settings information due to the way the
max_accel_to_decel backwards compatibility support was implemented.
Slightly rework the config reading so that the default for
minimum_cruise_ratio is populated there.
Reported by @ReXT3D.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
The user facing max_accel_to_decel setting is complicated and
confusing. Replace it with a new minimum_cruise_ratio parameter.
Internally this user-facing parameter will calculate the existing
low-level "accel_to_decel" mechanism.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
There is no harm in enabling flushing for a little longer than
necessary. In contrast, a slight rounding issue causing a message to
not get flushed properly could result in an error. So, extend the
flushing time slightly to avoid potential issues.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Commit b7b13588 made it possible that the kinematic code could be
restarted after a flush_step_generation() call without a sufficient
delay.
Rename last_sg_flush_time to min_restart_time and use that to ensure
_calc_print_time() always pauses kin_flush_delay time since the last
flush_step_generation() call.
Also, update force_move to invoke flush_step_generation() after any
movements. This is needed to ensure there is a sufficient delay
should force_move be called on a stepper motor that is part of the
toolhead kinematics and is using a step generation "scan time".
This fixes possible "internal error in stepcompress" reports when
using FORCE_MOVE.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>