<p>You appear to be asking about rate-limiting the stream of G-code provided by the computer, but some more context in your question will help if this is not the case.</p>

<p>Printers tend to work in two ways.</p>

<ol>
<li><p>Read G-code from local storage as a text file. Here, the parser/control engine is in full control.</p></li>
<li><p>Stream G-code over a serial port using an 'ack' handshake.</p></li>
</ol>

<p>The reference for G-code used in 3D printing is the <a href="https://reprap.org/wiki/G-code#Replies_from_the_RepRap_machine_to_the_host_computer" rel="nofollow noreferrer">RepRap Wiki</a>. Here you will find responses such as <code>ok</code> <code>resend</code> and <code>fatal</code>, these indicate when a previous command is processed and something else can be sent, if the previous message was identified as corrupt, or if recovery is impossible.</p>

<p>The basic rule for this style of handshake is that after every host to slave transaction, the host <strong>must</strong> wait for some response before sending another transaction. The slave could send either ACK responses, or other asynchronous transactions if you can design the system to avoid or not care about overrun in the slave to host direction.</p>

<p>When designing a handshake like this, you can consider all possible ways for something to go wrong (assume the interface is imperfect). How can you handle a request being missed and no ACK ever? When there is a timeout, can you make a 'benign' request to see if the printer is still connected, etc.</p>

CC BY-SA 4.0
2019-01-11T10:47:32.477Z
Nicely answered! It is exactly the responses of the machine which can bug up other software, see e.g. [this answer](https://3dprinting.stackexchange.com/a/7287/).
0scar
CC BY-SA 4.0
2019-01-11T09:48:58.827Z
2019-01-11T09:48:58.827Z
Sean Houlihane
<p>3D printer firmware use gcode that is derived from CNC and no acknowledgment. They send movement commands to the stepper motors like <code>G1 X10 Y10</code> to move the printhead 10 mm along the X and Y.</p>

<p>You could use a ready 3D printer firmware like Marlin on a 3d printer board and use the X-axis or extruder output to couple to your solenoid, sending a <code>G1 Z0.1</code> or <code>G1 E0.1</code>, which will actuate it for a short time. You might even use E and Z on different solenoids.</p>

CC BY-SA 4.0
2019-01-11T05:15:03.767Z
2019-01-11T05:15:03.767Z
Trish
<p>Are you interested in receiving the instructions correctly, or interested in how the instructions are executed by the hardware? This answer doesn't go into the software communication between controller board and software that sends the instruction from another software/hardware platform  (see <a href="https://3dprinting.stackexchange.com/a/7947/">this answer</a>), this answer addresses the positioning/movement. </p>

<p>Most of current 3D printers do not track the position of the print head. The software instructs the head to go somewhere, but it never checks if it actually arrives at that exact position. Problems like missing steps of the stepper or skipping notches on the belt are not detected and the printer will continue thinking it has reached the position.</p>

<p>Skipping of belts is a mechanical issue and should not occur (nor can be detected unless there are stepper steps missed), but skipping of steps is something that can be detected by certain type of stepper drivers (trinamic). Steppers do not use a feedback loop to check the final position. Servos, opposed to steppers, use a feedback loop, and as such are able to reach the position as instructed, but this comes a an increased cost, servo's are more expensive and hence not found in most of the "cheaper" 3D printing machines.</p>

<p>It is up to the designer of a 3D machine to choose the motors for the positioning system, if it is not highly loaded, you go for steppers without a feedback loop, or in higher loaded machines for servo's (basically steppers with some positioning electronics for the feedback). In case of a stepper you hope that it reaches the destination you tell it to go to, for a servo, you known that it reaches that exact position. </p>

<p>To get back on topic of your question, there is no feedback on reaching the position (you call this acknowledgement), you just send the G-codes sequentially or in a buffer to the printer electronics which executes the statements one at the time (this is done by the firmware, this <a href="https://3dprinting.stackexchange.com/a/7947/5740">this answer</a> for replies of the machine on the code it receives). It is your choice of the hardware that actually determines whether this is executed like instructed. Do note that most machines are not highly loaded (the 3D printhead is not very heavy and <em>normally</em> does not hit any obstruction in its path as Z advances) justifying the use of steppers without the need for feedback. CNC machines, certainly the larger ones, that position a highly loaded cutting tool need such a feedback loop as the positioning needs to be very exact. You need to consider the forces at play in your paper punch machine, but from my point of view, your machine does not seem to be highly loaded. In such a case you are not in need for a more expensive positioning system, nor the need for the processing of a return/feedback signal in your custom software.</p>

CC BY-SA 4.0
2020-04-29T07:28:50.377Z
Note: detecting belt skipping can be detected equally: you just need a feedback sensor which include the belt in the loop. However I agree that poor quality 3D printer who usually use belts will not have this feedback. Considering ball-screw mechanisms, they just cannot skip, and also provide more rigidity.
Adrian Maire
CC BY-SA 4.0
2019-01-11T08:07:08.310Z
2019-01-11T12:22:17.847Z
2019-01-11T12:22:17.847Z
0scar
<p>The CNC system, and simplifying intentionally, is divided into several steps:</p>

<ol>
<li><strong>Acquisition of the g-code</strong>: This depends on the platform, whether is a file from an USB flash-memory, network or direct input from the operator. G-code operations needs to be buffered in a quantity enough to allow some "look-ahead" in the program.</li>
<li><strong>Parsing of the g-code</strong>: Parsing of any formal language is based on "formal grammars" theory <a href="https://en.wikipedia.org/wiki/Formal_grammar" rel="nofollow noreferrer">https://en.wikipedia.org/wiki/Formal_grammar</a>. Fortunately, g-code is one of the simplest grammar of the Chomsky hierarchy. Language parsing is a full topic in itself, and it follows lexical, syntactical and semantical analysis.</li>
<li><p><strong>Driving</strong>: It exists several different strategies:</p>

<ul>
<li><strong>Open-loop vs closed loop</strong>: In closed-loop CNC, sensors provide a feedback from the movement, allowing the driver to fix deviations (e.g. no step lots). Those systems are more expensive and usually not available in cheap 3D printers. In open-loop CNC, the driver send signals and "hope" the machine will follow, this is the case of most cheap 3D-printers, where if you block the head, it will lose steps.</li>
<li><strong>Synchronous vs asynchronous</strong> (not sure about this naming): In synchronous systems, the driver send a single step for each axis each loop (one step forward, no step, or one step backward for each of the x, y, z, a... axis). In each iteration, the driver establish which steps need to be activated and send it; the speed of the movement depends on how fast this loop is performed. In Asynchronous driving, the loop run at a specific speed and apply steps as needed to correct the distance between the previous/detected position and the expected position.</li>
</ul></li>
</ol>

<p>Acquisition and parsing of g-code can be performed in soft real-time, however the driving needs hard real-time, which precision determine the maximum speed that your CNC can manage.</p>

<p>The servos/steppers usually cannot manage infinite acceleration, this is why the system needs to read g-code instructions ahead to anticipate closed angles or changes in direction. It should then reduce the indicated speed down to something which allows the next instruction.</p>

<p>I hope this give a quick introduction to the topic, obviously, each aspect needs further reading.</p>

CC BY-SA 4.0
2020-04-29T07:22:32.673Z
2020-04-29T07:22:32.673Z
Adrian Maire
<p>I have been working on a printer project that basically is a 2D printer (dot matrix type). We are using solenoids as actuators to make impressions on the paper. We are now in the process of designing custom software. But a problem that we have encountered is that we have no idea how to design software as we are a bunch of beginners in this field.</p>

<p>An idea we are working on is based on position-acknowledge technique. In this technique the computer sends G-code to the controller. The controller after reaching the position defined in code sends an acknowledgement and the computer then sends the next signal. This is the model we are currently working on. </p>

<ul>
<li>Can anyone suggest any other ideas to make this work? </li>
<li>Is Our approach right? </li>
<li>Do 3D printers work using same technique?</li>
</ul>

CC BY-SA 4.0
2019-01-11T10:14:58.387Z
See also https://electronics.stackexchange.com/questions/26723/does-gcode-require-a-response-code-from-the-interpreter
Sean Houlihane
<marlin><diy-3d-printer><firmware><software>
How does a 3D printer software/firmware work
jesvin palatty
# How does a 3D printer software/firmware work

(Asked by: username_0 on 2019-01-11)

I have been working on a printer project that basically is a 2D printer (dot matrix type). We are using solenoids as actuators to make impressions on the paper. We are now in the process of designing custom software. But a problem that we have encountered is that we have no idea how to design software as we are a bunch of beginners in this field.

An idea we are working on is based on position-acknowledge technique. In this technique the computer sends G-code to the controller. The controller after reaching the position defined in code sends an acknowledgement and the computer then sends the next signal. This is the model we are currently working on.

* Can anyone suggest any other ideas to make this work?
* Is Our approach right?
* Do 3D printers work using same technique?

**Tags:** marlin, diy-3d-printer, firmware, software
> **Comments:**
> **username_1**: See also https://electronics.stackexchange.com/questions/26723/does-gcode-require-a-response-code-from-the-interpreter  

---

## 4 answers

### Answer by username_1 on 2019-01-11. Score: 3

You appear to be asking about rate-limiting the stream of G-code provided by the computer, but some more context in your question will help if this is not the case.

Printers tend to work in two ways.

1. Read G-code from local storage as a text file. Here, the parser/control engine is in full control.
2. Stream G-code over a serial port using an 'ack' handshake.

The reference for G-code used in 3D printing is the [RepRap Wiki](https://reprap.org/wiki/G-code#Replies_from_the_RepRap_machine_to_the_host_computer). Here you will find responses such as `ok` `resend` and `fatal`, these indicate when a previous command is processed and something else can be sent, if the previous message was identified as corrupt, or if recovery is impossible.

The basic rule for this style of handshake is that after every host to slave transaction, the host **must** wait for some response before sending another transaction. The slave could send either ACK responses, or other asynchronous transactions if you can design the system to avoid or not care about overrun in the slave to host direction.

When designing a handshake like this, you can consider all possible ways for something to go wrong (assume the interface is imperfect). How can you handle a request being missed and no ACK ever? When there is a timeout, can you make a 'benign' request to see if the printer is still connected, etc.

> **Comments:**
> **username_2**: Nicely answered! It is exactly the responses of the machine which can bug up other software, see e.g. [this answer](https://3dprinting.stackexchange.com/a/7287/).  

---

### Answer by username_3 on 2019-01-11. Score: 2

3D printer firmware use gcode that is derived from CNC and no acknowledgment. They send movement commands to the stepper motors like `G1 X10 Y10` to move the printhead 10 mm along the X and Y.

You could use a ready 3D printer firmware like Marlin on a 3d printer board and use the X-axis or extruder output to couple to your solenoid, sending a `G1 Z0.1` or `G1 E0.1`, which will actuate it for a short time. You might even use E and Z on different solenoids.


---

### Answer by username_2 on 2019-01-11. Score: 1

Are you interested in receiving the instructions correctly, or interested in how the instructions are executed by the hardware? This answer doesn't go into the software communication between controller board and software that sends the instruction from another software/hardware platform (see [this answer](https://3dprinting.stackexchange.com/a/7947/)), this answer addresses the positioning/movement.

Most of current 3D printers do not track the position of the print head. The software instructs the head to go somewhere, but it never checks if it actually arrives at that exact position. Problems like missing steps of the stepper or skipping notches on the belt are not detected and the printer will continue thinking it has reached the position.

Skipping of belts is a mechanical issue and should not occur (nor can be detected unless there are stepper steps missed), but skipping of steps is something that can be detected by certain type of stepper drivers (trinamic). Steppers do not use a feedback loop to check the final position. Servos, opposed to steppers, use a feedback loop, and as such are able to reach the position as instructed, but this comes a an increased cost, servo's are more expensive and hence not found in most of the "cheaper" 3D printing machines.

It is up to the designer of a 3D machine to choose the motors for the positioning system, if it is not highly loaded, you go for steppers without a feedback loop, or in higher loaded machines for servo's (basically steppers with some positioning electronics for the feedback). In case of a stepper you hope that it reaches the destination you tell it to go to, for a servo, you known that it reaches that exact position.

To get back on topic of your question, there is no feedback on reaching the position (you call this acknowledgement), you just send the G-codes sequentially or in a buffer to the printer electronics which executes the statements one at the time (this is done by the firmware, this [this answer](https://3dprinting.stackexchange.com/a/7947/5740) for replies of the machine on the code it receives). It is your choice of the hardware that actually determines whether this is executed like instructed. Do note that most machines are not highly loaded (the 3D printhead is not very heavy and *normally* does not hit any obstruction in its path as Z advances) justifying the use of steppers without the need for feedback. CNC machines, certainly the larger ones, that position a highly loaded cutting tool need such a feedback loop as the positioning needs to be very exact. You need to consider the forces at play in your paper punch machine, but from my point of view, your machine does not seem to be highly loaded. In such a case you are not in need for a more expensive positioning system, nor the need for the processing of a return/feedback signal in your custom software.

> **Comments:**
> **username_4**: Note: detecting belt skipping can be detected equally: you just need a feedback sensor which include the belt in the loop. However I agree that poor quality 3D printer who usually use belts will not have this feedback. Considering ball-screw mechanisms, they just cannot skip, and also provide more rigidity.  

---

### Answer by username_4 on 2020-04-29. Score: 0

The CNC system, and simplifying intentionally, is divided into several steps:

1. **Acquisition of the g-code**: This depends on the platform, whether is a file from an USB flash-memory, network or direct input from the operator. G-code operations needs to be buffered in a quantity enough to allow some "look-ahead" in the program.
2. **Parsing of the g-code**: Parsing of any formal language is based on "formal grammars" theory <https://en.wikipedia.org/wiki/Formal_grammar>. Fortunately, g-code is one of the simplest grammar of the Chomsky hierarchy. Language parsing is a full topic in itself, and it follows lexical, syntactical and semantical analysis.
3. **Driving**: It exists several different strategies:

   * **Open-loop vs closed loop**: In closed-loop CNC, sensors provide a feedback from the movement, allowing the driver to fix deviations (e.g. no step lots). Those systems are more expensive and usually not available in cheap 3D printers. In open-loop CNC, the driver send signals and "hope" the machine will follow, this is the case of most cheap 3D-printers, where if you block the head, it will lose steps.
   * **Synchronous vs asynchronous** (not sure about this naming): In synchronous systems, the driver send a single step for each axis each loop (one step forward, no step, or one step backward for each of the x, y, z, a... axis). In each iteration, the driver establish which steps need to be activated and send it; the speed of the movement depends on how fast this loop is performed. In Asynchronous driving, the loop run at a specific speed and apply steps as needed to correct the distance between the previous/detected position and the expected position.

Acquisition and parsing of g-code can be performed in soft real-time, however the driving needs hard real-time, which precision determine the maximum speed that your CNC can manage.

The servos/steppers usually cannot manage infinite acceleration, this is why the system needs to read g-code instructions ahead to anticipate closed angles or changes in direction. It should then reduce the indicated speed down to something which allows the next instruction.

I hope this give a quick introduction to the topic, obviously, each aspect needs further reading.


---

