Buffered G-code streaming from Python

More
17 Mar 2026 09:47 #344396 by Alfapro
Buffered G-code streaming from Python was created by Alfapro
Hi, I’m working with LinuxCNC and trying to control motion from Python , similar to MDI.

The goal is to stream G-code commands dynamically (generated in Python), but still preserve trajectory planner behavior such as:
* continuous motion
* G64 blending (no full stops between segments)

The problem I see is that standard MDI execution appears to process commands one-by-one, so the planner does not have enough future segments to perform blending. This results in stop-and-go motion.

What I would like to achieve is something like:

* sending multiple G-code commands ahead of time (buffered)
* without waiting for each command to complete
* so the trajectory planner can see upcoming segments

Questions:

1. Is there any supported way to stream G-code from Python into a buffer (not strictly MDI) so that  G64 still work?
2. Does LinuxCNC provide any interface to feed the interpreter continuously (like a queue or pipe) instead of executing discrete MDI commands?
Any pointers or best practices would be greatly appreciated.
Thanks!

Please Log in or Create an account to join the conversation.

More
17 Mar 2026 11:57 #344400 by andrax
Replied by andrax on topic Buffered G-code streaming from Python
Why?

This method was used on older NC machines because there wasn't enough memory. But nowadays, transferring data block by block no longer makes sense.

Please Log in or Create an account to join the conversation.

More
17 Mar 2026 13:06 #344403 by Alfapro
Replied by Alfapro on topic Buffered G-code streaming from Python
I was planning to write a simple DSL for generating motion.

The idea is to have my own commands and then translate them into G-code. If I don’t want to modify the existing interpreter, the obvious way is to just convert everything into standard G-code but then I’m limited by what G-code can express.

Another idea I had was to keep most of the logic in Python and send something like a stream or batch of motion instructions to LinuxCNC, so it could still handle them with proper blending (G64) and without stopping at every segment.

I realize this sounds a bit hacky, but I’m trying to find a balance between flexibility and still using the built-in trajectory planner instead of reinventing it.

Please Log in or Create an account to join the conversation.

More
17 Mar 2026 13:10 #344404 by Aciera
Replied by Aciera on topic Buffered G-code streaming from Python


The problem I see is that standard MDI execution appears to process commands one-by-one, so the planner does not have enough future segments to perform blending. This results in stop-and-go motion.


That is not correct. Linuxcnc supports stacking (blending) of MDI commands.

Please Log in or Create an account to join the conversation.

More
17 Mar 2026 13:23 #344405 by Alfapro
Replied by Alfapro on topic Buffered G-code streaming from Python
Could someone provide an example of how this works? I’m having trouble understanding how MDI blending is supposed to behave and how to implement it correctly.

Please Log in or Create an account to join the conversation.

Time to create page: 0.096 seconds
Powered by Kunena Forum