-
-
Notifications
You must be signed in to change notification settings - Fork 5.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WIP: Queue PWM Commands to enable #133 #3338
Conversation
Todo: actually use queue, also maybe add generic queue to minimize code duplication
Todo: Determine queue elements dynamically.
Signed-off-by: Pascal Pieper <[email protected]>
Laser Raster works "alright" in a slow setting (10mm/s) with my GeeeTeach A10 (atmega2560). |
Hi, As you've found, it's a bit of work to get pwm queuing to work properly. Some high-level comments:
Cheers, |
Signed-off-by: Pascal Pieper <[email protected]>
Signed-off-by: Pascal Pieper <[email protected]>
Signed-off-by: Pascal Pieper <[email protected]>
Signed-off-by: Pascal Pieper <[email protected]>
Signed-off-by: Pascal Pieper <[email protected]>
Interesting. Does it work well? -Kevin |
Currently I am struggling with the fact that queued PWM-Commands seem to be held back and sent when queue gets filled a bit more. If I manually set Fan Speed to full, Zero and full, the first message is sent only when the third was composed, thus giving a
Could you explain the second meaning of the overloaded |
I'm not sure why that would be. Note that the steppersync code needs to be flushed (
The min_clock should be set to the time that the micro-controller will free up the space in the move_queue that was allocated for the given command. I think that should be the same as req_clock for PWM updates. -Kevin |
Ok, thanks for your comment. I don't actively command a steppersync flush ( |
Signed-off-by: Pascal Pieper <[email protected]>
Signed-off-by: Pascal Pieper <[email protected]>
Signed-off-by: Pascal Pieper <[email protected]>
…commands from setting at the same time opposed to queue flush frequency Signed-off-by: Pascal Pieper <[email protected]>
Signed-off-by: Pascal Pieper <[email protected]>
Signed-off-by: Pascal Pieper <[email protected]>
Signed-off-by: Pascal Pieper <[email protected]>
Signed-off-by: Pascal Pieper <[email protected]>
We could make separate classes for soft-pwm and hard-pwm. However, if we are to queue pin updates on the micro-controller I think we should do the work to queue digital pin updates, soft pwm updates, and hard pwm updates. That is, once the main work of getting the logic correct is implemented, it would make sense to leverage that work for all pins.
That makes sense to me. Cheers, |
b00ca44
to
0fbd19e
Compare
So you suggest queueing soft-pwm and gpio as well? This is possible, would only need a way to minimize code duplication (especially the list operations).
I am on a level where the setup works for me. How would you suggest proper testing to validate correctness? What kind of completeness needs this PR to be accepted? E.g. the If you could give feedback for where you see hot spots for work to do on the functional logic, I can finalize this and "copy" the functionality to s-pwm and gpio. |
Signed-off-by: Pascal Pieper <[email protected]>
Signed-off-by: Pascal Pieper <[email protected]>
Signed-off-by: Pascal Pieper <[email protected]>
…when queue is populated? Kill queue? Signed-off-by: Pascal Pieper <[email protected]>
823e262
to
2a7b65c
Compare
Signed-off-by: Pascal Pieper <[email protected]>
Signed-off-by: Pascal Pieper <[email protected]>
Signed-off-by: Pascal Pieper <[email protected]>
Signed-off-by: Pascal Pieper <[email protected]>
PWM-Updates do not force-flush the stepper's move queue anymore. In toolhead.py: def note_synchronous_command(self, kin_time):
self.note_kinematic_activity(kin_time)
self._update_move_time(kin_time)
# timer will call _flush_handler to check if
# Batch should be sent. if not, reschedule.
self.reactor.update_timer(self.flush_timer, self.reactor.NOW) The This way, I could further increase my benchmark speed to 80mm/s with 10 pwm changes per millimeter -> 800 updates per second for pwm alone. Higher speeds were possible but not stable for burst changes. About the inclusion of soft-pwm into the move queues: soft-pwm requires more info per scheduling (three |
Signed-off-by: Pascal Pieper <[email protected]>
c3da883
to
1233ee3
Compare
Signed-off-by: Pascal Pieper <[email protected]>
7a7e10b
to
b9b951d
Compare
My high-level feedback is that I think we would need to be careful here, as the max_duration and shutdown checks are important. That would mean manually testing that each of these checks fires correctly (I can't think of a good way to automate these types of tests.) Also, all the "unknowns" causing scheduling errors would need to be tracked down. I'd also say we would want to break up the changes into a series of small changes that can be independently reviewed for correctness.
Yeah - that would be an issue. It is possible to shrink the soft-pwm update though - we could send changes to cycle time as a separate command that uses its own queue entry - which would shrink it to the same 11 bytes (on AVR; 16 on ARM) that the That said, I don't think you need to make any of these changes - if you want to focus on hard_pwm, I think that's fine. -Kevin |
Yes, I agree. My suggestion is:
Is that OK with you? |
Yes - if it's possible to convert the mcu code while keeping the host code mostly unchanged, then I think that would be a good first step. I'd implement the hard_pwm changes as a set of commits separately from the digital_out commit(s).
Agreed. Note, though, that the code could use some refactoring. The steppers could be treated just like any other command queue that needs access to the move queue. I can do this work.
I don't know much about lasers, but it sounds good to me. Thanks, |
First of all: I like Klipper, thanks!
To enable using klipper for laser cutting as well (see #133), I tried to copy the move_queue functions of
basecmd.c
to a new pwm_queue in the MCU firmware.This is still a work in progress, mainly because sometimes the host sends
schedule_pwm
commands too late for the actual requested clock.Known issues:
move
andpwm
commands?)FAN_MIN_TIME
is set per guess. Host should know of the serial latency (but stepper moves work flawlessly..?)I would love to see someone else's thoughts about the host side implementation.
Here I have two logfiles of my tests wit simulavr:
timer_too_close_1ms.zip
ok_5ms.zip
If the
schedule_pwm
-commands are too close together (1msFAN_MIN_TIME
)it passes a lot of time until the command for the second pwm value is sent to the MCU, and then it is too late (zoomed):
With a guessed
FAN_MIN_TIME
of 5ms, the sequence works already appropriately:But the queue is used very sparingly due to the slow drip of commands.