<p>I am describing how this is done in the Marlin firmware.</p>

<p>The first step is to split a linear movement from (x, y, z) to (x', y', z') into many discrete segments. To this end, the amount of time the move would take at a given speed is calculated, and the value <em>delta_segments_per_second</em> is used to calculate the number of segments used.</p>

<p>This is done in the function <em>prepare_move_delta</em> in the file Marlin_main.cpp. The endpoints of each of these segments is then passed to the function <em>calculate_delta</em>:</p>

<pre><code>void calculate_delta(float cartesian[3]) {
    //reverse kinematics.
    // Perform reversed kinematics, and place results in delta[3]
    // The maths and first version has been done by QHARLEY . Integrated into masterbranch 06/2014 and slightly restructured by Joachim Cerny in June 2014

    float SCARA_pos[2];
    static float SCARA_C2, SCARA_S2, SCARA_K1, SCARA_K2, SCARA_theta, SCARA_psi;

    SCARA_pos[X_AXIS] = cartesian[X_AXIS] * axis_scaling[X_AXIS] - SCARA_offset_x;  //Translate SCARA to standard X Y
    SCARA_pos[Y_AXIS] = cartesian[Y_AXIS] * axis_scaling[Y_AXIS] - SCARA_offset_y;  // With scaling factor.

    #if (Linkage_1 == Linkage_2)
      SCARA_C2 = ((sq(SCARA_pos[X_AXIS]) + sq(SCARA_pos[Y_AXIS])) / (2 * (float)L1_2)) - 1;
    #else
      SCARA_C2 = (sq(SCARA_pos[X_AXIS]) + sq(SCARA_pos[Y_AXIS]) - (float)L1_2 - (float)L2_2) / 45000;
    #endif

    SCARA_S2 = sqrt(1 - sq(SCARA_C2));

    SCARA_K1 = Linkage_1 + Linkage_2 * SCARA_C2;
    SCARA_K2 = Linkage_2 * SCARA_S2;

    SCARA_theta = (atan2(SCARA_pos[X_AXIS], SCARA_pos[Y_AXIS]) - atan2(SCARA_K1, SCARA_K2)) * -1;
    SCARA_psi = atan2(SCARA_S2, SCARA_C2);

    delta[X_AXIS] = SCARA_theta * SCARA_RAD2DEG;  // Multiply by 180/Pi  -  theta is support arm angle
    delta[Y_AXIS] = (SCARA_theta + SCARA_psi) * SCARA_RAD2DEG;  //       -  equal to sub arm angle (inverted motor)
    delta[Z_AXIS] = cartesian[Z_AXIS];
}
</code></pre>

<p>This function takes care of the delta geometry and calculations needed to convert the (x,y,z) coordinates of the segment endpoints to corresponding positions for the carriages. The translated coordinates are then passed to <em>plan_buffer_line</em>, which calculates the steps needed for each stepper motor and actually makes these steps happen.</p>

<p>The exact kinematics used in this function are explained in much more detail at the <a href="https://github.com/MarlinFirmware/Marlin/wiki/Delta-kinematics" rel="nofollow">Marlin github</a>.</p>

<p>What is important to note is that plan_buffer_line moves the carriages linearly, and the printhead thus describes an arc and not a straight line. A straight line move is thus approximated by many small arcs.</p>

CC BY-SA 3.0
2016-02-25T18:47:50.853Z
The code is hard to read.What is SCARA? Could you describe the steps that the code implements?
Lars Pötter
CC BY-SA 3.0
2016-02-23T20:22:48.850Z
2016-02-23T20:22:48.850Z
Tom van der Zanden
<p>There are two main special steps to the technique used by most open-source 3d printer controllers:</p>

<ol>
<li>Divide each linear gcode segment into lots of very small subsegments ("Segmentation")</li>
<li>Use some basic trigonometry or the pythagorean theorem to tie extruder position to carriage height for each of the three towers ("Inverse Kinematics") 
to find the target position for each small segment</li>
</ol>

<p>The inverse kinematics are surprisingly simple. A virtual 90 degree triangle is constructed from two known lengths to solve for the unknown third length: </p>

<ul>
<li>The fixed delta arm length is the hypotenuse of the triangle</li>
<li>The horizontal distance between the column joints and end-effector joints is calculated from the XY coordinates of the nozzle and the fixed position of the column, to determine the length of the lower side of the triangle</li>
<li>The length of the upper side of the triangle is calculated from the previous two via the pythagorean theorem</li>
<li>The length of the upper side is added to the nozzle Z height to get the necessary carriage height</li>
</ul>

<p>I think the best open-source reference here is Steve Grave's Rostock Kinematics document, rev3 available for download here: <a href="https://groups.google.com/d/msg/deltabot/V6ATBdT43eU/jEORG_l3dTEJ" rel="noreferrer">https://groups.google.com/d/msg/deltabot/V6ATBdT43eU/jEORG_l3dTEJ</a>
Some relevant pictures:
<a href="https://i.sstatic.net/MxCMc.jpg" rel="noreferrer"><img src="https://i.sstatic.net/MxCMc.jpg" alt="enter image description here"></a>
<a href="https://i.sstatic.net/geOQI.jpg" rel="noreferrer"><img src="https://i.sstatic.net/geOQI.jpg" alt="enter image description here"></a></p>

<p>These inverse kinematics calculations are performed for each carriage to get a "carriage space" target position, and this is performed for every path sub-segment.</p>

<p>The results from these steps can then be reinserted back into the standard linear path interpolation techniques for the printer, in which it fires steps in the necessary ratios and at the necessary rates to produce the desired straight-line motion and acceleration/velocity profile. (How THAT is done is a different question.)</p>

<p>The net effect is that the printer will move through a series of small "linear" carriage movements (linear meaning constant* speed with respect to time) that collectively approximate the necessary curved (quadratic position with respect to time) carriage motions required to produce a straight-line end-effector move.</p>

<p>*(<em>Constant speed before acceleration slowdowns are applied in order to obey dynamics constraints, anyway. Again, that's the subject of a different question.)</em></p>

<p>Segmentation is very similar to the process of using a polygon to approximate a circle. If the facets are small enough, the polygon is a good approximation. Higher Segmentation rates produce less path-following error.  The primary conceptual difference between drawing circle arcs and Delta motion paths is that the so-called "faceted arc" with Delta Segmentation is constructed in height-vs-time coordinates instead of the X-vs-Y coordinates you'd use to draw a circle on a computer screen. </p>

<p>This system is used in large part because support for Delta style printers was originally bolted onto GRBL-based motion planners which were written exclusively for straight-line motion paths in Cartesian printers. It was a relatively minimal modification to the existing codebase compared to implementing full quadratic path interpolation.</p>

<p>Techniques have evolved over the years. And alternate approaches are often used: for example, the dc42 fork of RepRapFirmware performs exact path-following without segmentation, by recalculating the proper time for the next step <em>after every step</em>. This is functionally equivalent to approximating a circle with a polygon facet count <em>so high that every pixel on the screen gets its own facet</em>. So it is exactly as accurate as the positioning resolution of the motors allows. The downside is that this segmentation-free technique is fairly processor-intensive, so it only works on relatively fast controllers, not the older 8bit Atmega AVR that powers most existing consumer/hobbyist printers today. </p>

<p>Other techniques are possible. The academic parallel robotics control literature is a whole other world of mathematical techniques and complexity in order to produce generalized control algorithms that work for a wide range of robot mechanisms. The version we use in open-source 3d printers is quite simple and application-specific in comparison. </p>

CC BY-SA 3.0
2016-02-23T20:40:25.017Z
2016-02-25T21:10:01.643Z
2016-02-25T21:10:01.643Z
Ryan Carlyle
<p>On a Cartesian printer movements are really simple. If we assume the printer has 100 steps/mm on each axis, then a move of 10mm on a axis is just 1000 Steps on that axis.</p>

<p>Movements that are not aligned with one axis are also simple. Moving from x,y = 0,0 to 10,10 would be 1000 steps on x and y.</p>

<p>On deltas even for simple moves more than one motor has to move. And just calculating the amount of steps on each axis needed to reach the destination probably gives a curved move.</p>

<p>So what is the algorithm to calculate the steps for a given move for a delta printer?</p>

CC BY-SA 3.0
2016-02-23T20:34:36.217Z
This seems to be solely a theory question which might be more appropriate for a site that deals with programming and/or mathematics as how the firmware works internally is irrelevant to the use of a 3D printer. On the other hand, the question is specific to 3D printing and might be relevant to somebody trying to modify or tweak their printer's firmware.
Tom van der Zanden
<delta><algorithm>
How are delta movements calculated?
Lars Pötter
# How are delta movements calculated?

(Asked by: username_0 on 2016-02-23)

On a Cartesian printer movements are really simple. If we assume the printer has 100 steps/mm on each axis, then a move of 10mm on a axis is just 1000 Steps on that axis.

Movements that are not aligned with one axis are also simple. Moving from x,y = 0,0 to 10,10 would be 1000 steps on x and y.

On deltas even for simple moves more than one motor has to move. And just calculating the amount of steps on each axis needed to reach the destination probably gives a curved move.

So what is the algorithm to calculate the steps for a given move for a delta printer?

**Tags:** delta, algorithm
> **Comments:**
> **username_1**: This seems to be solely a theory question which might be more appropriate for a site that deals with programming and/or mathematics as how the firmware works internally is irrelevant to the use of a 3D printer. On the other hand, the question is specific to 3D printing and might be relevant to somebody trying to modify or tweak their printer's firmware.  

---

## 2 answers

### Answer by username_2 on 2016-02-23. Score: 9 | Accepted answer

There are two main special steps to the technique used by most open-source 3d printer controllers:

1. Divide each linear gcode segment into lots of very small subsegments ("Segmentation")
2. Use some basic trigonometry or the pythagorean theorem to tie extruder position to carriage height for each of the three towers ("Inverse Kinematics")
   to find the target position for each small segment

The inverse kinematics are surprisingly simple. A virtual 90 degree triangle is constructed from two known lengths to solve for the unknown third length:

* The fixed delta arm length is the hypotenuse of the triangle
* The horizontal distance between the column joints and end-effector joints is calculated from the XY coordinates of the nozzle and the fixed position of the column, to determine the length of the lower side of the triangle
* The length of the upper side of the triangle is calculated from the previous two via the pythagorean theorem
* The length of the upper side is added to the nozzle Z height to get the necessary carriage height

I think the best open-source reference here is Steve Grave's Rostock Kinematics document, rev3 available for download here: <https://groups.google.com/d/msg/deltabot/V6ATBdT43eU/jEORG_l3dTEJ>
Some relevant pictures:
[![enter image description here](https://i.sstatic.net/MxCMc.jpg)](https://i.sstatic.net/MxCMc.jpg)
[![enter image description here](https://i.sstatic.net/geOQI.jpg)](https://i.sstatic.net/geOQI.jpg)

These inverse kinematics calculations are performed for each carriage to get a "carriage space" target position, and this is performed for every path sub-segment.

The results from these steps can then be reinserted back into the standard linear path interpolation techniques for the printer, in which it fires steps in the necessary ratios and at the necessary rates to produce the desired straight-line motion and acceleration/velocity profile. (How THAT is done is a different question.)

The net effect is that the printer will move through a series of small "linear" carriage movements (linear meaning constant\* speed with respect to time) that collectively approximate the necessary curved (quadratic position with respect to time) carriage motions required to produce a straight-line end-effector move.

\*(*Constant speed before acceleration slowdowns are applied in order to obey dynamics constraints, anyway. Again, that's the subject of a different question.)*

Segmentation is very similar to the process of using a polygon to approximate a circle. If the facets are small enough, the polygon is a good approximation. Higher Segmentation rates produce less path-following error. The primary conceptual difference between drawing circle arcs and Delta motion paths is that the so-called "faceted arc" with Delta Segmentation is constructed in height-vs-time coordinates instead of the X-vs-Y coordinates you'd use to draw a circle on a computer screen.

This system is used in large part because support for Delta style printers was originally bolted onto GRBL-based motion planners which were written exclusively for straight-line motion paths in Cartesian printers. It was a relatively minimal modification to the existing codebase compared to implementing full quadratic path interpolation.

Techniques have evolved over the years. And alternate approaches are often used: for example, the dc42 fork of RepRapFirmware performs exact path-following without segmentation, by recalculating the proper time for the next step *after every step*. This is functionally equivalent to approximating a circle with a polygon facet count *so high that every pixel on the screen gets its own facet*. So it is exactly as accurate as the positioning resolution of the motors allows. The downside is that this segmentation-free technique is fairly processor-intensive, so it only works on relatively fast controllers, not the older 8bit Atmega AVR that powers most existing consumer/hobbyist printers today.

Other techniques are possible. The academic parallel robotics control literature is a whole other world of mathematical techniques and complexity in order to produce generalized control algorithms that work for a wide range of robot mechanisms. The version we use in open-source 3d printers is quite simple and application-specific in comparison.


---

### Answer by username_1 on 2016-02-23. Score: 2

I am describing how this is done in the Marlin firmware.
The first step is to split a linear movement from (x, y, z) to (x', y', z') into many discrete segments. To this end, the amount of time the move would take at a given speed is calculated, and the value delta_segments_per_second is used to calculate the number of segments used.
This is done in the function prepare_move_delta in the file Marlin_main.cpp. The endpoints of each of these segments is then passed to the function calculate_delta:
void calculate_delta(float cartesian[3]) {
    //reverse kinematics.
    // Perform reversed kinematics, and place results in delta[3]
    // The maths and first version has been done by QHARLEY . Integrated into masterbranch 06/2014 and slightly restructured by Joachim Cerny in June 2014

    float SCARA_pos[2];
    static float SCARA_C2, SCARA_S2, SCARA_K1, SCARA_K2, SCARA_theta, SCARA_psi;

    SCARA_pos[X_AXIS] = cartesian[X_AXIS] * axis_scaling[X_AXIS] - SCARA_offset_x;  //Translate SCARA to standard X Y
    SCARA_pos[Y_AXIS] = cartesian[Y_AXIS] * axis_scaling[Y_AXIS] - SCARA_offset_y;  // With scaling factor.

    #if (Linkage_1 == Linkage_2)
      SCARA_C2 = ((sq(SCARA_pos[X_AXIS]) + sq(SCARA_pos[Y_AXIS])) / (2 * (float)L1_2)) - 1;
    #else
      SCARA_C2 = (sq(SCARA_pos[X_AXIS]) + sq(SCARA_pos[Y_AXIS]) - (float)L1_2 - (float)L2_2) / 45000;
    #endif

    SCARA_S2 = sqrt(1 - sq(SCARA_C2));

    SCARA_K1 = Linkage_1 + Linkage_2 * SCARA_C2;
    SCARA_K2 = Linkage_2 * SCARA_S2;

    SCARA_theta = (atan2(SCARA_pos[X_AXIS], SCARA_pos[Y_AXIS]) - atan2(SCARA_K1, SCARA_K2)) * -1;
    SCARA_psi = atan2(SCARA_S2, SCARA_C2);

    delta[X_AXIS] = SCARA_theta * SCARA_RAD2DEG;  // Multiply by 180/Pi  -  theta is support arm angle
    delta[Y_AXIS] = (SCARA_theta + SCARA_psi) * SCARA_RAD2DEG;  //       -  equal to sub arm angle (inverted motor)
    delta[Z_AXIS] = cartesian[Z_AXIS];
}

This function takes care of the delta geometry and calculations needed to convert the (x,y,z) coordinates of the segment endpoints to corresponding positions for the carriages. The translated coordinates are then passed to plan_buffer_line, which calculates the steps needed for each stepper motor and actually makes these steps happen.
The exact kinematics used in this function are explained in much more detail at the Marlin github.
What is important to note is that plan_buffer_line moves the carriages linearly, and the printhead thus describes an arc and not a straight line. A straight line move is thus approximated by many small arcs.

> **Comments:**
> **username_0**: The code is hard to read.What is SCARA? Could you describe the steps that the code implements?  

---

