tmc: Fix stepper enable time for tmc virtual enable#7245
tmc: Fix stepper enable time for tmc virtual enable#7245MRX8024 wants to merge 1 commit intoKlipper3d:masterfrom
Conversation
Signed-off-by: Maksim Bolgov <maksim8024@gmail.com>
|
Thanks. However, sending the motor enable well in advance of the command is the intended behavior. We want to make sure the motor is enabled prior to any upcoming movement commands. Applying a Is there some problem resulting from turning on the motor power slightly in advance? -Kevin |
|
Honestly, I don't know where the typical user might encounter problems with this. I'm supporting a project for Klipper that helps AWD printer users synchronize their motors; the algorithm works with motor enable and requires relatively precise timings. Unfortunately, the current behavior of virtual enable breaks it, and I thought it would be more appropriate to try to improve it here. I understand that Any thoughts? |
That sounds challenging. Out of curiosity, could you explain why the enable timing is critical to the calibration? Maybe there is an alternative. Not sure. For what it is worth, I'm not sure how one would go about ensuring precise timing of TMC messages in general. For example, the TMC UART code is not very fast, there could be host<->mcu message retransmits, and line noise could result in mcu<->driver retransmits. So, having confidence in even a 200ms time window would seem challenging. I suppose one could try for a time, check afterwards if the goal was met, and cancel the test otherwise. Not sure. -Kevin |
Without going into too much detail, the algorithm measures the impact value created by the motor upon activation using an accelerometer/encoder. The analyzed range is quite large, 200 ms, with the spike occurring near the center of range. However, given the current behavior with virual-en, the motor activates outside (before) the measured range. I can actually find various hacks to make it work, but I was interested in a mainline solution. I would suggest adding a pause before/after activating the motor, but it seems like turn-on callback is already a post-factum of steps flush, so we can't just add a time offset to next moves. |
When using the "Enabling TMC virtual enable for ..." function, motor activation is controlled by the toff register. On motor enable, the toff register value is sent to the tmc via
_do_enable()-->_init_registers(), which occurs withprint_time=None. Because of this, actual motor activation may occur earlier, up to ~1 second earlier.For example:
Which will cause the motor to turn on immediately.
The change consists of moving the sending of the toff register to the required print_time, while the other registers continue to be initialized in advance. Since every on/off operation happens with mutex, everything should be fine.