171 Commits

Author SHA1 Message Date
Kevin O'Connor
7a723bdc1c serialqueue: Revert recent serialqueue locking changes
This reverts commit aea8d8e0a1.
This reverts commit 493271697f.
This reverts commit d7da45e152.

There are reports of a regression since making this change.  Revert
for now until the root cause can be found.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2025-10-18 19:47:53 -04:00
Timofey Titovets
aea8d8e0a1 serialqueue: decouple transmit requests
Signed-off-by: Timofey Titovets <nefelim4ag@gmail.com>
2025-10-18 13:20:58 -04:00
Timofey Titovets
493271697f serialqueue: decouple serialhdl receive lock
Signed-off-by: Timofey Titovets <nefelim4ag@gmail.com>
2025-10-18 13:20:58 -04:00
Timofey Titovets
d7da45e152 serialqueue: decouple pending & ready queues
Simply describe how the cmdqueue is moved between states.

Signed-off-by: Timofey Titovets <nefelim4ag@gmail.com>
2025-10-18 13:20:58 -04:00
Kevin O'Connor
cba7a285e4 trapq: Extend trapq_extract_old() to also check active moves
Support extracting moves from both the "live" trapq->moves as well as
the "history" from trapq->history storage.  Now that moves are flushed
separately from the lookahead queue, there is a good chance that the
current move being processed on the mcus will still be in the active
trapq list.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2025-10-09 13:22:32 -04:00
Dmitry Butyugin
b7602ff969 input_shaper: Fixed initialization for dual_carriage
Signed-off-by: Dmitry Butyugin <dmbutyugin@google.com>
2025-10-06 15:41:22 -04:00
Dmitry Butyugin
caf7accf2d input_shaper: Z-axis input shaper
Signed-off-by: Dmitry Butyugin <dmbutyugin@google.com>
2025-10-04 19:50:34 -04:00
Kevin O'Connor
c49dbb5a87 trapq: Fix bug that broke numerical stability workaround for initial movement
Commit b60804bb changed the trapq head sentinel to store
print_time=-1.  However, it failed to update trapq_add_move() that
relied on that value to detect the head sentinel.  As a result,
numerical stability issues could lead to stepcompress errors.

Fix by changing trapq_add_move() to detect the head sentinel even with
a negative print_time.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2025-10-04 19:35:41 -04:00
Kevin O'Connor
3c01f71d9e itersolve: Don't call trapq_check_sentinels() from itersolve_generate_steps()
Commit a89694ac changed the code to run itersolve_generate_steps()
from multiple threads simultaneously.  However,
trapq_check_sentinels() can modify the shared trapq object.  So,
calling it from multiple threads could introduce a race condition.

Move the call to trapq_check_sentinels() to steppersyncmgr_gen_steps()
to avoid the issue.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2025-09-24 18:58:31 -04:00
Kevin O'Connor
dfa666d9c1 stepcompress: Remove stepcompress_queue_msg()
Callers can use syncemitter_queue_msg() instead.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2025-09-24 15:07:25 -04:00
Kevin O'Connor
546976b1fe steppersync: Print the thread name on a stepcompress error
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2025-09-24 15:07:25 -04:00
Kevin O'Connor
414679ac99 steppersync: Move history clearing to background thread
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2025-09-24 15:07:25 -04:00
Kevin O'Connor
3ef4702e06 steppersync: Move step generation thread from stepcompress.c to steppersync.c
Implement step generation from 'struct syncemitter' instead of in the
stepcompress code.  This simplifies the stepcompress code and
simplifies the overall interface.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2025-09-24 15:07:25 -04:00
Kevin O'Connor
e78d11bc6f steppersync: Support sending messages directly from syncemitter
Move msg_queue allocation from stepcompress to syncemitter.  With this
change the pwm_tool module does not need to allocate a stepcompress
object.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2025-09-24 15:07:25 -04:00
Kevin O'Connor
d831d66c11 steppersync: Introduce new 'struct syncemitter'
Create a new 'struct syncemitter' for each object that can generate
messages for a 'struct steppersync' and store in a regular linked
list.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2025-09-24 15:07:25 -04:00
Kevin O'Connor
a29cfc1701 stepcompress: Pass oid in stepcompress_fill() instead of stepcompress_alloc()
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2025-09-24 14:51:34 -04:00
Kevin O'Connor
f21cca049f steppersync: Add new steppersyncmgr_gen_steps() function
Generate and flush all the steppersync instances from a single
steppersyncmgr_gen_steps() call.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2025-09-24 14:51:34 -04:00
Kevin O'Connor
bd747872c3 steppersync: Add new 'struct steppersyncmgr'
Add a new C based mechanism for tracking all the 'struct steppersync'
instances.  This simplifies memory management.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2025-09-24 14:51:34 -04:00
Kevin O'Connor
a66f5cec52 msgblock: Add new clock_fill() function
Add a new function for filling the fields of 'struct clock_estimate'.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2025-09-24 14:51:34 -04:00
Kevin O'Connor
b60804bb66 trapq: Set the head sentinel to a negative print_time
If a stepper kinematics has a "scan window" defined during its first
flush then the iterative solver may walk past the head sentinel.  Set
a small negative print_time for the head sentinel to avoid this corner
case.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2025-09-12 22:41:30 -04:00
Kevin O'Connor
a89694ac68 stepcompress: Generate steps in a per-stepper background thread
Create a thread for each stepper and use it for step generation and
step compression.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2025-09-07 20:50:41 -04:00
Kevin O'Connor
5426943501 motion_queuing: Automatically detect changes to kin_flush_delay
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>
2025-09-03 12:00:31 -04:00
Timofey Titovets
77d4cdbae4 pyhelper: drop linux/prctl header for compability with musl
Signed-off-by: Timofey Titovets <nefelim4ag@gmail.com>
2025-09-03 11:44:10 -04:00
Kevin O'Connor
ae010215e7 chelper: Build library first in temporary file and then rename
Try to avoid cases where an incomplete library build causes confusing
future failures.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2025-08-22 16:34:45 -04:00
Kevin O'Connor
2919f37343 stepcompress: Store a reference to 'struct stepper_kinematics'
Support storing a reference to 'struct stepper_kinematics' in 'struct
stepcompress' and support globally generating steps via the
steppersync mechanism.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2025-08-11 19:43:35 -04:00
Kevin O'Connor
dd4cc8eb4c itersolve: Do not store a reference to 'struct stepcompress'
Pass in the 'struct stepcompress' reference to each call of
itersolve_generate_steps().

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2025-08-11 19:43:35 -04:00
Kevin O'Connor
c520bf981d steppersync: Split steppersync code from stepcompress.c to new file
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2025-08-11 19:43:35 -04:00
Kevin O'Connor
7b25d1c06f stepcompress: Export steppersync_history_expire()
Don't implement history expiration from the main steppersync_flush()
code.  Instead, have callers directly invoke
steppersync_history_expire().

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2025-08-11 19:43:35 -04:00
Kevin O'Connor
0df40b43e8 serialqueue: Be sure sq->name is null terminated
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2025-08-01 12:46:32 -04:00
Timofey Titovets
17ce45d212 serialqueue: name the threads per mcu
Signed-off-by: Timofey Titovets <nefelim4ag@gmail.com>
2025-08-01 12:42:53 -04:00
Timofey Titovets
c78dd6a00a pyhelper: define set_thread_name() helper
Signed-off-by: Timofey Titovets <nefelim4ag@gmail.com>
2025-08-01 12:42:53 -04:00
Thijs Triemstra
60879fd298 klippy: fix typos in python code (#6989)
Signed-off-by: Thijs Triemstra <info@collab.nl>
2025-07-25 12:31:19 -04:00
Dmitry Butyugin
4d4b9684a5 input_shaper: Track kinematics updates by dual_carriage
Signed-off-by: Dmitry Butyugin <dmbutyugin@google.com>
2025-06-04 13:40:58 -04:00
Dmitry Butyugin
cc6736c3e3 kinematics: Generic Cartesian kinematics implementation (#6815)
* tests: Added a regression test for generic_cartesian kinematics

* kinematics: An intial implementation of generic_cartesian kinematics

* generic_cartesian: Refactored kinematics configuration API

* generic_cartesian: Use stepper instead of kinematic_stepper in configs

* generic_cartesian: Added SET_STEPPER_KINEMATICS command

* generic_cartesian: Fixed parsing of section names

* docs: Generic Caretsian kinematics documentation and config samples

* generic_cartesian: Implemented multi-mcu homing validation

* generic_cartesian: Fixed typos in docs, minor fixes

* generic_cartesian: Renamed `kinematics` option to `carriages`

* generic_cartesian: Moved kinematic_stepper.py file

* idex_modes: Internal refactoring of handling dual carriages

* stepper: Refactored the code to not store a reference to config object

* config: Updated example-generic-cartesian config

* generic_cartesian: Restricted SET_STEPPER_CARRIAGES and exported status

* idex_modes: Fixed handling stepper kinematics with input shaper enabled

* config: Updated configs and tests for SET_DUAL_CARRIAGE new params

* generic_cartesian: Avoid inheritance in the added classes

Signed-off-by: Dmitry Butyugin <dmbutyugin@google.com>
2025-05-06 18:06:36 -04:00
Dmitry Butyugin
47aa28e530 input_shaper: Fix for polar kinematics
Forward post_cb calls from itersolve to the original kinematics.

Signed-off-by: Dmitry Butyugin <dmbutyugin@google.com>
2025-03-11 19:15:23 -04:00
Dmitry Butyugin
c84d78f3f1 extruder: Allow dynamic adjustment of pressure advance (#6635)
Signed-off-by: Dmitry Butyugin <dmbutyugin@google.com>
2024-07-11 14:43:21 -04:00
Francois Chagnon
d7f6348ae6 toolhead: Keep stepcompress move history relative to current time (#6439)
Expire history relative to current time rather than last move in history queue

Signed-off-by: Francois Chagnon <fc@francoischagnon.net>
2023-12-30 11:34:21 -05:00
Kevin O'Connor
62bf52bfcf serialqueue: Simplify sequence number upconversion
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2023-12-07 17:52:06 -05:00
Kevin O'Connor
48a05eaa54 stepcompress: Add support for queuing messages that consume move queue space
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2023-11-16 22:07:15 -05:00
Kevin O'Connor
447125faae serialqueue: Eventually time out if unable to write CANbus messages
Klipper logs an error on a failed CANbus write.  Unfortunately, if the
bus becomes permanently disabled (eg, due to a user removing power to
devices on the CANbus) then it can result in the logs filling with
error messages.

Permanently disable the low-level processing of messages if CANbus
writes continually fail for at least 10 seconds.  This avoids filling
the log with redundant messages.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2023-10-04 22:42:14 -04:00
Dmitry Butyugin
36be1cfc51 idex_modes: COPY and MIRROR mode implementation (#6297)
COPY and MIRROR mode implementation

Correctly apply input shaper params to new dual_carriage

Added SAVE_/RESTORE_IDEX_STATE commands

Documentation updates for the new IDEX modes

Signed-off-by: Dmitry Butyugin <dmbutyugin@google.com>
2023-08-01 12:23:52 -04:00
Dmitry Butyugin
a3c00d0bed input_shaper: Correctly initialize input shaper stepper_kinematics
If the stepper already executed some steps with the basic
stepper_kinematics, subsequent creation of a new one for input_shaper
would result in stepcompress errors unless position and time tracking
flags are also copied over.

Signed-off-by: Dmitry Butyugin <dmbutyugin@google.com>
2023-06-06 20:17:49 -04:00
Dmitry Butyugin
e15bad4844 input_shaper: Fixed tracking of step_generation_scan_time
Signed-off-by: Dmitry Butyugin <dmbutyugin@google.com>
2023-06-06 20:17:49 -04:00
Kevin O'Connor
22ee889f41 serialqueue: Rename stalled_bytes stat to upcoming_bytes
The stalled_bytes counter refers to the number of bytes that are not
yet eligible for transmission.  However, the naming leads to confusion
as it could be interpretted as an inability to transmit data.  Rename
to upcoming_bytes to try to avoid that confusion.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2023-04-07 15:17:43 -04:00
Kevin O'Connor
f1203d56f6 chelper: Minor declaration movement in __init__.py
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2023-01-07 23:17:37 -05:00
Kevin O'Connor
4ea11dbb4f trapq: Minor code movement in trapq.c
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2023-01-07 14:13:00 -05:00
Kevin O'Connor
a564824009 serialqueue: Add comment to do_write()
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2023-01-05 03:09:43 -05:00
Tircown
354915d2ad kinematics: Add deltesian printers (#5743)
Initial push of the working deltesian kinematics after some successful tests.

Signed-off-by: Fabrice GALLET <tircown@gmail.com>
2022-09-01 15:56:31 -04:00
Kevin O'Connor
db6346e7e5 serialqueue: Improve canbus timing
Adjust timing based on the minimum transmission time of canbus
messages.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2022-07-29 11:40:54 -04:00
Kevin O'Connor
9ec9742484 extruder: Add support for reversing the direction of extruder stepper movement
Extend SET_EXTRUDER_ROTATION_DISTANCE to support reversing the
direction of extruder movement.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2022-02-10 13:24:21 -05:00