Add a new variant of timer_dispatch_many() for chips that do not
support hardware irqs, or do not support hardware irqs being enabled
during timer dispatch. This new variant allows the boards to poll for
events if many timers are run back to back.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
If there is no entry in the trapq at the requested time then the
velocity is zero. However, the current code would report the previous
velocity, which could be non-zero in cases with instantaneous velocity
changes. Check for that case and return a velocity of zero if no move
found.
Reported by @pedrolamas.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Commit cba7a285 updated trapq_extract_old() to check the list of
active trapq entries. However, that change could get confused if the
tail sentinel wasn't pristine. Change the code to always skip the
tail sentinel to avoid that issue.
Reported by @pedrolamas.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Commit cab2f004 introduced a "statement after label" which some
versions of gcc don't like. Add a semicolon to fix it.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
The abs() function on AVR only handles 16-bit integers. Implement
it manually.
Reported by @kmatzen.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
When performing batch mode debugging it is possible for the input file
to complete before all background work has completed. Add a new
'gcode:debuginput_exit' event so that other modules can signal when
they have finished.
Add code to virtual_sdcard module to catch this event and use it to
wait for any sdcard processing to complete. This fixes the
sdcard_loop.test regression test case.
Signed-off-by: Timofey Titovets <nefelim4ag@gmail.com>
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Add a start_busy_time parameter to the idle notifier. This makes it
possible for the idle notifier to track how long it takes for the
reactor to clear all pending events.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
The internal reactor code uses internal timers for callbacks and to
resume "pause" operations. Support reporting the underlying callback
from these timers during high latency reports. This should make the
high latency debugging reports more useful.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Add support to the reactor for reporting if a set of callbacks take a
long time before returning to the main reactor loop.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Support setting a callback just prior to the reactor invoking a
select() call that will sleep.
Move the Python garbage collection code from the main reactor.py and
klippy.py code to the garbage_collection.py module.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Introduce a new _check_fd_activity() method and add it to
SelectReactor, PollReacator, and EPollReactor. This avoids needing to
duplicate _dispatch_loop() in each of those variants.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Break up the _handle_clock() function into multiple functions. This
is intended to make it more clear there are several distinct processes
that _handle_clock() implements (64bit clock conversion,
sent_time/clock regression, serialqueue release handling,
round-trip-time tracking, and multi-mcu synchronization).
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
The clock 32bit conversion code is distinct from the clock to time
conversion code. It is also only needed in the trdispatch.c code,
which can calculate a sufficient value for last_clock on its own.
This simplifies the serialqueue code. It also reduces the chance of a
failure in the trdispatch code if last_clock isn't explicitly updated.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Commit 4f178df8 moved the force_axes variable to
_set_start_position(), but failed to remove all uses of that variable
in home_rails().
Reported by "Crestless0166".
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Setup HomingViaProbeHelper() from the main printer probe class and not
from the low-level DescendToEndstopHelper() class.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Enhance the analyze shutdown code to also dump out stepper information
on an "Internal error in stepcompress" error raised from the
motion_queuing module.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
If steppersyncmgr_gen_steps() reports an error then directly call
printer.invoke_shutdown() and include extra details in the shutdown.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
If steppersyncmgr_gen_steps() fails (an "Internal error in
stepcompress") then report the underlying syncemitter raising the
error to the motion_queuing module. This can improve debugging.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Increase the buffer size from 96 bytes to 192 bytes. This reduces the
chance of dropped messages during high bus traffic.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Pass a maximum buffer size parameter to command_encode_and_frame() and
support encoding messages even if there may not be enough space for
the largest possible message. In practice, most messages will encode
to a size notably smaller than their maximum so this improves buffer
utilization during heavy message traffic.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Convert the low-level probing classes to use the standard probing
interface and have them instantiate DescendToEndstopHelper as a helper
class. This simplifies the internal interfaces as the low-level
classes no longer need to emulate an "mcu_endstop" and there is no
longer a unique "mcu probe" interface.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
The BLTouchProbe class has a mixture of exported functions and
internal functions. Mark the internal ones with a leading underscore
to document which functions are exported.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Introduce a new PrinterBLTouch class to separate out the high level
printer probe interface code from the low-level code.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Introduce a new PrinterSmartEffector class to separate out the high
level printer probe interface code from the low-level code.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
There is no longer a need for the correction macros now that the G28
code uses the standard probing interface.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
The HomingViaProbeHelper emulates an mcu_endstop, but that emulation
doesn't need to actually do anything.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Restore the previous behavior of only checking for toolhead movement
on the second home attempt when utilizing "probe:z_virtual_endstop".
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Create a new DescendToEndstopHelper that calls phoming.probing_move()
and manages the probing session. Have HomingViaProbeHelper implement
just the "probe:z_virtual_endstop" logic.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Now that the homing code does not treat the probe object as an
mcu_endstop object, there is no reason to handle the homing module
events.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Change the homing code to detect if a home request is using a virtual
"probe:z_virtual_offset" endstop. In that case, the code will perform
probing attempts using the main probe code (instead of treating the
probe hardware as a kind of mcu_endstop object).
This change will simplify the probing code (as it will no longer need
to emulate mcu_endstop objects), and allow Z homing with probes that
can't easily emulate an mcu_endstop.
There are some known behaviour differences introduced by this change:
* All probing actions currently verify that the toolhead has moved
some amount of distance, while this is not required on the first
home attempt with the current homing behavior.
* This exposes the temporary kinematic positions to the
"homing:homing_move_end" event (which could be seen by probe
deactivate_gcode macros). However, the "homing:homing_move_begin"
(and activate_gcode macros) were already exposed to these temporary
positions.
* Z home attempts with the probe were previously always rounded to a Z
microstep. This behaviour may change with the new code.
* The internal "homing:home_rails_begin" and "homing:home_rails_end"
events are no longer invoked for these Z home attempts. It is no
longer possible to use endstop_phases with a virtual Z home (though
this functionality wasn't useful).
* It is no longer possible to simultaneously home some Z steppers with
"probe:z_virtual_offset" while other Z steppers used a traditional
endstop (however, this functionality wasn't useful).
The first difference (need to move some distance on first home
attempt) will be addressed in a future commit. The remaining
differences are considered minor.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Change HomingViaProbeHelper class to be the main interface to the rail
homing code in homing.py . This will make it easier to change that
interface in future commits.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Create two ProbeSessionHelper wrappers - one for EddyDescend and one
for EddyTap. This simplifies the main start_probe_session() code.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Python is faster with list comprehensions than generators (prefer
`sum([x for x in c])` over `sum(x for x in c)` ).
Python2 is faster if lists are built with list comprehensions instead
of appending.
Optimize the common `mat_mat_mul(mat_transp(a), a)` as only roughly
half the results are unique.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Increase the sample rate so that more samples are available during
"tap" analysis.
Further increases to the sample rate will likely provide diminishing
returns. The ldc1612 sensor seems to exhibit internal quantization
(that is, repeat identical values are frequently observed). So, it
seems increasing above 250sps can provide some additional information,
but going much higher is unlikely to provide significant benefit.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Rework the tap_threshold to use units of hz/mm (instead of hz). This
will make it easier to implement tap calibration based on results of
PROBE_EDDY_CURRENT_CALIBRATE and previous tap attempts. It can also
make the tap_threshold more stable with different probe speeds and
sensor rates.
As a result of this change, existing user configurations will need to
be updated. It is hoped that existing configurations will have a
value that is sufficiently low that they will reliably get an error
until they can recalibrate.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Now that "tap" support does not require the scipy package to be
installed it is reasonable to activate "tap" for all configurations.
This can make the initial calibration easier.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Due to recent changes, a shutdown log line may not have a description.
Update the logextract.py script accordingly.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Scale the internal mcu values to units of milli-hz to reduce the
chance of roundoff error in the internal calculations.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
The coeff_frac_bits and scale_frac_bits can be automatically
calculated, so there's no need for the callers to specify this
information.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Have the callers convert convert the trigger_value from a float to an
integer (if necessary). This is in preparation for implementing
rounding in to_fixed_32().
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
There have been some reports of the sanity check throwing an error
when the bed is depressed just under 50um. For now, increase the
valid depress range to avoid unnecessary errors.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Implement some basic checks on the tap results and report an error if
the results look obviously incorrect.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Continue to run least squares evaluations until the uncertainty range
is within 50 nanometers (reduced from 250nm).
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Directly calculate the evaluated matrices instead of using
mat_mat_mult() and mat_transp().
Cache the intermediate summations to improve processing when using
similar z guesses.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Use the least squares solution code in the local mathutil.py module
instead of using the numpy package. This allows users to utilize the
"tap" functionality without requiring additional package installation.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Use a different base frequency and base z value for the internal "tap"
least squares analysis to improve the numerical stability of the
calculations.
Rework the formulas being solved so that only the depressed slope
calculation is relative to the estimated z contact point. This
results in less variables that are dependent on the z contact.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Store the 12 constants needed for the common probe_eddy_current "tap"
filter in trigger_analog.py code. This avoids requiring "tap" users
to have the scipy python package installed.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Support exporting the current SOS filter size from the DigitalFilter()
class. Pass that value to the MCU_SosFilter() class to avoid
allocating unneccessary MCU memory (previously 5 entries were
allocated while only 3 are currently needed).
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Add new add_lowpass(), add_highpass(), add_notch(), and
setup_initial_state() methods to DigitalFilter. Use these instead of
creating the filters from the constructor.
Also remove the unused filtfilt() method.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Don't calculate the nozzle/bed contact position from the descent
movement. Instead, obtain the data during the lifting movement and
determine the contact point by analyzing where the nozzle separates
from the bed.
This improves the precision and repeatability of the "tap" results.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Perform lifting at the end of EddyTap.run_probe(). This is in
preparation for performing tap analysis during retraction.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Add a new EddyParameterHelper to override ProbeParameterHelper.
Only use the printer.cfg lift_speed, samples, sample_retract_dist,
samples_result, samples_tolerance, and samples_tolerance_retries
settings for normal probe operations. Don't use these defaults when
using a "METHOD" set to "scan", "rapid_scan", or "tap". Each of these
probing mechanisms is distinct and it's unlikely a user could
meaningfully set a default for all of them.
Don't set sample_retract_dist when using "scan" and "rapid_scan"
modes.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Theoretically a "tap" probe should detect the exact point that the
nozzle contacts the bed. In practice, however, there can be a
systemic bias that one may wish to account for. This bias may be due
to backlash, thermal expansion, a detection bias, or similar issues.
Add a new tap_z_offset config parameter to allow users to specify an
offset.
Also, update the Z_OFFSET_APPLY_PROBE command to support modifying
this value.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
The config option 'z_offset' name is confusing as its behavior is
notably different from how other probe hardware uses 'z_offset'.
Rename to 'descend_z' to make its behavior more clear.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Add a new create_probe_result() helper function that can generate a
ProbeResult using a toolhead position and a set of probe offsets.
Use this helper in other modules.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Use a different method of setting the hardware pwm registers so that
the actual cycle_time is much closer to the requested cycle_time.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>