Browse Source

forwardKinematics for Delta printers

AnHardt 9 years ago
parent
commit
499e404fbf
1 changed files with 70 additions and 0 deletions
  1. 70
    0
      Marlin/Marlin_main.cpp

+ 70
- 0
Marlin/Marlin_main.cpp View File

@@ -7780,6 +7780,76 @@ void clamp_to_software_endstops(float target[3]) {
7780 7780
     return abs(distance - delta[TOWER_3]);
7781 7781
   }
7782 7782
 
7783
+  float cartesian[3]; // result
7784
+  void forwardKinematics(float z1, float z2, float z3) {
7785
+    //As discussed in Wikipedia "Trilateration"
7786
+    //we are establishing a new coordinate
7787
+    //system in the plane of the three carriage points.
7788
+    //This system will have the origin at tower1 and
7789
+    //tower2 is on the x axis. tower3 is in the X-Y
7790
+    //plane with a Z component of zero. We will define unit
7791
+    //vectors in this coordinate system in our original
7792
+    //coordinate system. Then when we calculate the
7793
+    //Xnew, Ynew and Znew values, we can translate back into
7794
+    //the original system by moving along those unit vectors
7795
+    //by the corresponding values.
7796
+    // https://en.wikipedia.org/wiki/Trilateration
7797
+
7798
+    // Variable names matched to Marlin, c-version
7799
+    // and avoiding a vector library
7800
+    // by Andreas Hardtung 2016-06-7
7801
+    // based on a Java function from
7802
+    // "Delta Robot Kinematics by Steve Graves" V3
7803
+
7804
+    // Result is in cartesian[].
7805
+
7806
+    //Create a vector in old coords along x axis of new coord
7807
+    float p12[3] = { delta_tower2_x - delta_tower1_x, delta_tower2_y - delta_tower1_y, z2 - z1 };
7808
+
7809
+    //Get the Magnitude of vector.
7810
+    float d = sqrt( p12[0]*p12[0] + p12[1]*p12[1] + p12[2]*p12[2] );
7811
+
7812
+    //Create unit vector by dividing by magnitude.
7813
+    float ex[3] = { p12[0]/d, p12[1]/d, p12[2]/d };
7814
+
7815
+    //Now find vector from the origin of the new system to the third point.
7816
+    float p13[3] = { delta_tower3_x - delta_tower1_x, delta_tower3_y - delta_tower1_y, z3 - z1 };
7817
+
7818
+    //Now use dot product to find the component of this vector on the X axis.
7819
+    float i = ex[0]*p13[0] + ex[1]*p13[1] + ex[2]*p13[2];
7820
+
7821
+    //Now create a vector along the x axis that represents the x component of p13.
7822
+    float iex[3] = { ex[0]*i,  ex[1]*i,  ex[2]*i  };
7823
+
7824
+    //Now subtract the X component away from the original vector leaving only the Y component. We use the
7825
+    //variable that will be the unit vector after we scale it.
7826
+    float ey[3] = { p13[0] - iex[0], p13[1] - iex[1], p13[2] - iex[2]};
7827
+
7828
+    //The magnitude of Y component
7829
+    float j = sqrt(sq(ey[0]) + sq(ey[1]) + sq(ey[2]));
7830
+
7831
+    //Now make vector a unit vector
7832
+    ey[0] /= j; ey[1] /= j;  ey[2] /= j;
7833
+
7834
+    //The cross product of the unit x and y is the unit z
7835
+    //float[] ez = vectorCrossProd(ex, ey);
7836
+    float ez[3] = { ex[1]*ey[2] - ex[2]*ey[1], ex[2]*ey[0] - ex[0]*ey[2], ex[0]*ey[1] - ex[1]*ey[0] };
7837
+
7838
+    //Now we have the d, i and j values defined in Wikipedia.
7839
+    //We can plug them into the equations defined in
7840
+    //Wikipedia for Xnew, Ynew and Znew
7841
+    float Xnew = (delta_diagonal_rod_2_tower_1 - delta_diagonal_rod_2_tower_2 + d*d)/(d*2);
7842
+    float Ynew = ((delta_diagonal_rod_2_tower_1 - delta_diagonal_rod_2_tower_3 + i*i + j*j)/2 - i*Xnew) /j;
7843
+    float Znew = sqrt(delta_diagonal_rod_2_tower_1 - Xnew*Xnew - Ynew*Ynew);
7844
+
7845
+    //Now we can start from the origin in the old coords and
7846
+    //add vectors in the old coords that represent the
7847
+    //Xnew, Ynew and Znew to find the point in the old system
7848
+    cartesian[X_AXIS] = delta_tower1_x + ex[0]*Xnew + ey[0]*Ynew - ez[0]*Znew;
7849
+    cartesian[Y_AXIS] = delta_tower1_y + ex[1]*Xnew + ey[1]*Ynew - ez[1]*Znew;
7850
+    cartesian[Z_AXIS] = z1             + ex[2]*Xnew + ey[2]*Ynew - ez[2]*Znew;
7851
+  };
7852
+
7783 7853
   #if ENABLED(AUTO_BED_LEVELING_FEATURE)
7784 7854
 
7785 7855
     // Adjust print surface height by linear interpolation over the bed_level array.

Loading…
Cancel
Save