Browse Source

TPARA - 3DOF robot arm IK (#21005)

Co-authored-by: Scott Lahteine <github@thinkyhead.com>
Axel 4 years ago
parent
commit
a46e025725
No account linked to committer's email address

+ 4
- 9
Marlin/Configuration.h View File

58
  */
58
  */
59
 
59
 
60
 //===========================================================================
60
 //===========================================================================
61
-//============================= DELTA Printer ===============================
61
+//========================== DELTA / SCARA / TPARA ==========================
62
 //===========================================================================
62
 //===========================================================================
63
-// For a Delta printer, start with one of the configuration files in the config/examples/delta directory
64
-// from https://github.com/MarlinFirmware/Configurations/branches/all and customize for your machine.
65
 //
63
 //
66
-
67
-//===========================================================================
68
-//============================= SCARA Printer ===============================
69
-//===========================================================================
70
-// For a SCARA printer, start with one of the configuration files in the config/examples/SCARA directory
71
-// from https://github.com/MarlinFirmware/Configurations/branches/all and customize for your machine.
64
+// Download configurations from the link above and customize for your machine.
65
+// Examples are located in config/examples/delta, .../SCARA, and .../TPARA.
72
 //
66
 //
67
+//===========================================================================
73
 
68
 
74
 // @section info
69
 // @section info
75
 
70
 

+ 1
- 0
Marlin/src/core/macros.h View File

104
 #define RADIANS(d) ((d)*float(M_PI)/180.0f)
104
 #define RADIANS(d) ((d)*float(M_PI)/180.0f)
105
 #define DEGREES(r) ((r)*180.0f/float(M_PI))
105
 #define DEGREES(r) ((r)*180.0f/float(M_PI))
106
 #define HYPOT2(x,y) (sq(x)+sq(y))
106
 #define HYPOT2(x,y) (sq(x)+sq(y))
107
+#define NORMSQ(x,y,z) (sq(x)+sq(y)+sq(z))
107
 
108
 
108
 #define CIRCLE_AREA(R) (float(M_PI) * sq(float(R)))
109
 #define CIRCLE_AREA(R) (float(M_PI) * sq(float(R)))
109
 #define CIRCLE_CIRC(R) (2 * float(M_PI) * float(R))
110
 #define CIRCLE_CIRC(R) (2 * float(M_PI) * float(R))

+ 8
- 2
Marlin/src/gcode/calibrate/G28.cpp View File

311
 
311
 
312
     TERN_(IMPROVE_HOMING_RELIABILITY, end_slow_homing(slow_homing));
312
     TERN_(IMPROVE_HOMING_RELIABILITY, end_slow_homing(slow_homing));
313
 
313
 
314
-  #else // NOT DELTA
314
+  #elif ENABLED(AXEL_TPARA)
315
+
316
+    constexpr bool doZ = true; // for NANODLP_Z_SYNC if your DLP is on a TPARA
317
+
318
+    home_TPARA();
319
+
320
+  #else
315
 
321
 
316
     const bool homeZ = parser.seen('Z'),
322
     const bool homeZ = parser.seen('Z'),
317
                needX = homeZ && TERN0(Z_SAFE_HOMING, axes_should_home(_BV(X_AXIS))),
323
                needX = homeZ && TERN0(Z_SAFE_HOMING, axes_should_home(_BV(X_AXIS))),
392
 
398
 
393
     sync_plan_position();
399
     sync_plan_position();
394
 
400
 
395
-  #endif // !DELTA (G28)
401
+  #endif
396
 
402
 
397
   /**
403
   /**
398
    * Preserve DXC mode across a G28 for IDEX printers in DXC_DUPLICATION_MODE.
404
    * Preserve DXC mode across a G28 for IDEX printers in DXC_DUPLICATION_MODE.

+ 13
- 13
Marlin/src/gcode/calibrate/M665.cpp View File

40
    *    X = Alpha (Tower 1) angle trim
40
    *    X = Alpha (Tower 1) angle trim
41
    *    Y = Beta  (Tower 2) angle trim
41
    *    Y = Beta  (Tower 2) angle trim
42
    *    Z = Gamma (Tower 3) angle trim
42
    *    Z = Gamma (Tower 3) angle trim
43
-   *    A = Alpha (Tower 1) digonal rod trim
44
-   *    B = Beta  (Tower 2) digonal rod trim
45
-   *    C = Gamma (Tower 3) digonal rod trim
43
+   *    A = Alpha (Tower 1) diagonal rod trim
44
+   *    B = Beta  (Tower 2) diagonal rod trim
45
+   *    C = Gamma (Tower 3) diagonal rod trim
46
    */
46
    */
47
   void GcodeSuite::M665() {
47
   void GcodeSuite::M665() {
48
-    if (parser.seen('H')) delta_height              = parser.value_linear_units();
49
-    if (parser.seen('L')) delta_diagonal_rod        = parser.value_linear_units();
50
-    if (parser.seen('R')) delta_radius              = parser.value_linear_units();
51
-    if (parser.seen('S')) delta_segments_per_second = parser.value_float();
52
-    if (parser.seen('X')) delta_tower_angle_trim.a  = parser.value_float();
53
-    if (parser.seen('Y')) delta_tower_angle_trim.b  = parser.value_float();
54
-    if (parser.seen('Z')) delta_tower_angle_trim.c  = parser.value_float();
55
-    if (parser.seen('A')) delta_diagonal_rod_trim.a = parser.value_float();
56
-    if (parser.seen('B')) delta_diagonal_rod_trim.b = parser.value_float();
57
-    if (parser.seen('C')) delta_diagonal_rod_trim.c = parser.value_float();
48
+    if (parser.seenval('H')) delta_height              = parser.value_linear_units();
49
+    if (parser.seenval('L')) delta_diagonal_rod        = parser.value_linear_units();
50
+    if (parser.seenval('R')) delta_radius              = parser.value_linear_units();
51
+    if (parser.seenval('S')) delta_segments_per_second = parser.value_float();
52
+    if (parser.seenval('X')) delta_tower_angle_trim.a  = parser.value_float();
53
+    if (parser.seenval('Y')) delta_tower_angle_trim.b  = parser.value_float();
54
+    if (parser.seenval('Z')) delta_tower_angle_trim.c  = parser.value_float();
55
+    if (parser.seenval('A')) delta_diagonal_rod_trim.a = parser.value_float();
56
+    if (parser.seenval('B')) delta_diagonal_rod_trim.b = parser.value_float();
57
+    if (parser.seenval('C')) delta_diagonal_rod_trim.c = parser.value_float();
58
     recalc_delta_settings();
58
     recalc_delta_settings();
59
   }
59
   }
60
 
60
 

+ 1
- 1
Marlin/src/inc/Conditionals_LCD.h View File

924
   #define NORMAL_AXIS Z_AXIS
924
   #define NORMAL_AXIS Z_AXIS
925
 #endif
925
 #endif
926
 
926
 
927
-#if ENABLED(MORGAN_SCARA)
927
+#if EITHER(MORGAN_SCARA, AXEL_TPARA)
928
   #define IS_SCARA 1
928
   #define IS_SCARA 1
929
   #define IS_KINEMATIC 1
929
   #define IS_KINEMATIC 1
930
 #elif ENABLED(DELTA)
930
 #elif ENABLED(DELTA)

+ 3
- 1
Marlin/src/inc/Conditionals_post.h View File

143
  */
143
  */
144
 #if IS_SCARA
144
 #if IS_SCARA
145
   #undef SLOWDOWN
145
   #undef SLOWDOWN
146
-  #define QUICK_HOME
146
+  #if DISABLED(AXEL_TPARA)
147
+    #define QUICK_HOME
148
+  #endif
147
   #define SCARA_PRINTABLE_RADIUS (SCARA_LINKAGE_1 + SCARA_LINKAGE_2)
149
   #define SCARA_PRINTABLE_RADIUS (SCARA_LINKAGE_1 + SCARA_LINKAGE_2)
148
 #endif
150
 #endif
149
 
151
 

+ 2
- 2
Marlin/src/inc/SanityCheck.h View File

1227
 /**
1227
 /**
1228
  * Allow only one kinematic type to be defined
1228
  * Allow only one kinematic type to be defined
1229
  */
1229
  */
1230
-#if MANY(DELTA, MORGAN_SCARA, COREXY, COREXZ, COREYZ, COREYX, COREZX, COREZY, MARKFORGED_XY)
1231
-  #error "Please enable only one of DELTA, MORGAN_SCARA, COREXY, COREYX, COREXZ, COREZX, COREYZ, COREZY, or MARKFORGED_XY."
1230
+#if MANY(DELTA, MORGAN_SCARA, AXEL_TPARA, COREXY, COREXZ, COREYZ, COREYX, COREZX, COREZY, MARKFORGED_XY)
1231
+  #error "Please enable only one of DELTA, MORGAN_SCARA, AXEL_TPARA, COREXY, COREYX, COREXZ, COREZX, COREYZ, COREZY, or MARKFORGED_XY."
1232
 #endif
1232
 #endif
1233
 
1233
 
1234
 /**
1234
 /**

+ 6
- 6
Marlin/src/module/delta.cpp View File

242
 
242
 
243
   // Disable stealthChop if used. Enable diag1 pin on driver.
243
   // Disable stealthChop if used. Enable diag1 pin on driver.
244
   #if ENABLED(SENSORLESS_HOMING)
244
   #if ENABLED(SENSORLESS_HOMING)
245
-  TERN_(X_SENSORLESS, sensorless_t stealth_states_x = start_sensorless_homing_per_axis(X_AXIS));
246
-  TERN_(Y_SENSORLESS, sensorless_t stealth_states_y = start_sensorless_homing_per_axis(Y_AXIS));
247
-  TERN_(Z_SENSORLESS, sensorless_t stealth_states_z = start_sensorless_homing_per_axis(Z_AXIS));
245
+    TERN_(X_SENSORLESS, sensorless_t stealth_states_x = start_sensorless_homing_per_axis(X_AXIS));
246
+    TERN_(Y_SENSORLESS, sensorless_t stealth_states_y = start_sensorless_homing_per_axis(Y_AXIS));
247
+    TERN_(Z_SENSORLESS, sensorless_t stealth_states_z = start_sensorless_homing_per_axis(Z_AXIS));
248
   #endif
248
   #endif
249
 
249
 
250
   // Move all carriages together linearly until an endstop is hit.
250
   // Move all carriages together linearly until an endstop is hit.
254
 
254
 
255
   // Re-enable stealthChop if used. Disable diag1 pin on driver.
255
   // Re-enable stealthChop if used. Disable diag1 pin on driver.
256
   #if ENABLED(SENSORLESS_HOMING)
256
   #if ENABLED(SENSORLESS_HOMING)
257
-  TERN_(X_SENSORLESS, end_sensorless_homing_per_axis(X_AXIS, stealth_states_x));
258
-  TERN_(Y_SENSORLESS, end_sensorless_homing_per_axis(Y_AXIS, stealth_states_y));
259
-  TERN_(Z_SENSORLESS, end_sensorless_homing_per_axis(Z_AXIS, stealth_states_z));
257
+    TERN_(X_SENSORLESS, end_sensorless_homing_per_axis(X_AXIS, stealth_states_x));
258
+    TERN_(Y_SENSORLESS, end_sensorless_homing_per_axis(Y_AXIS, stealth_states_y));
259
+    TERN_(Z_SENSORLESS, end_sensorless_homing_per_axis(Z_AXIS, stealth_states_z));
260
   #endif
260
   #endif
261
 
261
 
262
   endstops.validate_homing_move();
262
   endstops.validate_homing_move();

+ 12
- 7
Marlin/src/module/motion.cpp View File

267
   #else
267
   #else
268
     #if IS_SCARA
268
     #if IS_SCARA
269
       forward_kinematics_SCARA(
269
       forward_kinematics_SCARA(
270
-        planner.get_axis_position_degrees(A_AXIS),
271
-        planner.get_axis_position_degrees(B_AXIS)
270
+          planner.get_axis_position_degrees(A_AXIS)
271
+        , planner.get_axis_position_degrees(B_AXIS)
272
+        #if ENABLED(AXEL_TPARA)
273
+          , planner.get_axis_position_degrees(C_AXIS)
274
+        #endif
272
       );
275
       );
273
     #else
276
     #else
274
-      cartes.set(planner.get_axis_position_mm(X_AXIS), planner.get_axis_position_mm(Y_AXIS));
277
+      cartes.x = planner.get_axis_position_mm(X_AXIS);
278
+      cartes.y = planner.get_axis_position_mm(Y_AXIS);
275
     #endif
279
     #endif
276
     cartes.z = planner.get_axis_position_mm(Z_AXIS);
280
     cartes.z = planner.get_axis_position_mm(Z_AXIS);
277
   #endif
281
   #endif
1340
       TERN_(SENSORLESS_HOMING, stealth_states = start_sensorless_homing_per_axis(axis));
1344
       TERN_(SENSORLESS_HOMING, stealth_states = start_sensorless_homing_per_axis(axis));
1341
     }
1345
     }
1342
 
1346
 
1343
-    #if IS_SCARA
1347
+    #if EITHER(MORGAN_SCARA, MP_SCARA)
1344
       // Tell the planner the axis is at 0
1348
       // Tell the planner the axis is at 0
1345
       current_position[axis] = 0;
1349
       current_position[axis] = 0;
1346
       sync_plan_position();
1350
       sync_plan_position();
1490
 
1494
 
1491
   void homeaxis(const AxisEnum axis) {
1495
   void homeaxis(const AxisEnum axis) {
1492
 
1496
 
1493
-    #if IS_SCARA
1497
+    #if EITHER(MORGAN_SCARA, MP_SCARA)
1494
       // Only Z homing (with probe) is permitted
1498
       // Only Z homing (with probe) is permitted
1495
       if (axis != Z_AXIS) { BUZZ(100, 880); return; }
1499
       if (axis != Z_AXIS) { BUZZ(100, 880); return; }
1496
     #else
1500
     #else
1732
         TERN_(Z_MULTI_ENDSTOPS, case Z_AXIS:)
1736
         TERN_(Z_MULTI_ENDSTOPS, case Z_AXIS:)
1733
           stepper.set_separate_multi_axis(false);
1737
           stepper.set_separate_multi_axis(false);
1734
       }
1738
       }
1735
-    #endif
1739
+
1740
+    #endif // HAS_EXTRA_ENDSTOPS
1736
 
1741
 
1737
     #ifdef TMC_HOME_PHASE
1742
     #ifdef TMC_HOME_PHASE
1738
       // move back to homing phase if configured and capable
1743
       // move back to homing phase if configured and capable
1839
     }
1844
     }
1840
   #endif
1845
   #endif
1841
 
1846
 
1842
-  #if ENABLED(MORGAN_SCARA)
1847
+  #if EITHER(MORGAN_SCARA, AXEL_TPARA)
1843
     scara_set_axis_is_at_home(axis);
1848
     scara_set_axis_is_at_home(axis);
1844
   #elif ENABLED(DELTA)
1849
   #elif ENABLED(DELTA)
1845
     current_position[axis] = (axis == Z_AXIS) ? delta_height - TERN0(HAS_BED_PROBE, probe.offset.z) : base_home_pos(axis);
1850
     current_position[axis] = (axis == Z_AXIS) ? delta_height - TERN0(HAS_BED_PROBE, probe.offset.z) : base_home_pos(axis);

+ 14
- 0
Marlin/src/module/motion.h View File

395
   // Return true if the given point is within the printable area
395
   // Return true if the given point is within the printable area
396
   inline bool position_is_reachable(const float &rx, const float &ry, const float inset=0) {
396
   inline bool position_is_reachable(const float &rx, const float &ry, const float inset=0) {
397
     #if ENABLED(DELTA)
397
     #if ENABLED(DELTA)
398
+
398
       return HYPOT2(rx, ry) <= sq(DELTA_PRINTABLE_RADIUS - inset + fslop);
399
       return HYPOT2(rx, ry) <= sq(DELTA_PRINTABLE_RADIUS - inset + fslop);
400
+
401
+    #elif ENABLED(AXEL_TPARA)
402
+
403
+      const float R2 = HYPOT2(rx - TPARA_OFFSET_X, ry - TPARA_OFFSET_Y);
404
+      return (
405
+        R2 <= sq(L1 + L2) - inset
406
+        #if MIDDLE_DEAD_ZONE_R > 0
407
+          && R2 >= sq(float(MIDDLE_DEAD_ZONE_R))
408
+        #endif
409
+      );
410
+
399
     #elif IS_SCARA
411
     #elif IS_SCARA
412
+
400
       const float R2 = HYPOT2(rx - SCARA_OFFSET_X, ry - SCARA_OFFSET_Y);
413
       const float R2 = HYPOT2(rx - SCARA_OFFSET_X, ry - SCARA_OFFSET_Y);
401
       return (
414
       return (
402
         R2 <= sq(L1 + L2) - inset
415
         R2 <= sq(L1 + L2) - inset
404
           && R2 >= sq(float(MIDDLE_DEAD_ZONE_R))
417
           && R2 >= sq(float(MIDDLE_DEAD_ZONE_R))
405
         #endif
418
         #endif
406
       );
419
       );
420
+
407
     #endif
421
     #endif
408
   }
422
   }
409
 
423
 

+ 206
- 72
Marlin/src/module/scara.cpp View File

32
 #include "motion.h"
32
 #include "motion.h"
33
 #include "planner.h"
33
 #include "planner.h"
34
 
34
 
35
-float delta_segments_per_second = SCARA_SEGMENTS_PER_SECOND;
35
+#if ENABLED(AXEL_TPARA)
36
+  // For homing, as in delta
37
+  #include "planner.h"
38
+  #include "endstops.h"
39
+  #include "../lcd/marlinui.h"
40
+  #include "../MarlinCore.h"
41
+#endif
42
+
43
+float delta_segments_per_second = TERN(AXEL_TPARA, TPARA_SEGMENTS_PER_SECOND, SCARA_SEGMENTS_PER_SECOND);
36
 
44
 
37
 void scara_set_axis_is_at_home(const AxisEnum axis) {
45
 void scara_set_axis_is_at_home(const AxisEnum axis) {
38
   if (axis == Z_AXIS)
46
   if (axis == Z_AXIS)
39
     current_position.z = Z_HOME_POS;
47
     current_position.z = Z_HOME_POS;
40
   else {
48
   else {
41
-
42
-    /**
43
-     * SCARA homes XY at the same time
44
-     */
45
     xyz_pos_t homeposition;
49
     xyz_pos_t homeposition;
46
     LOOP_XYZ(i) homeposition[i] = base_home_pos((AxisEnum)i);
50
     LOOP_XYZ(i) homeposition[i] = base_home_pos((AxisEnum)i);
47
-
48
     #if ENABLED(MORGAN_SCARA)
51
     #if ENABLED(MORGAN_SCARA)
49
       // MORGAN_SCARA uses arm angles for AB home position
52
       // MORGAN_SCARA uses arm angles for AB home position
50
       //DEBUG_ECHOLNPAIR("homeposition A:", homeposition.a, " B:", homeposition.b);
53
       //DEBUG_ECHOLNPAIR("homeposition A:", homeposition.a, " B:", homeposition.b);
51
       inverse_kinematics(homeposition);
54
       inverse_kinematics(homeposition);
52
       forward_kinematics_SCARA(delta.a, delta.b);
55
       forward_kinematics_SCARA(delta.a, delta.b);
53
       current_position[axis] = cartes[axis];
56
       current_position[axis] = cartes[axis];
54
-    #else
57
+    #elif ENABLED(MP_SCARA)
55
       // MP_SCARA uses a Cartesian XY home position
58
       // MP_SCARA uses a Cartesian XY home position
56
       //DEBUG_ECHOPGM("homeposition");
59
       //DEBUG_ECHOPGM("homeposition");
57
       //DEBUG_ECHOLNPAIR_P(SP_X_LBL, homeposition.x, SP_Y_LBL, homeposition.y);
60
       //DEBUG_ECHOLNPAIR_P(SP_X_LBL, homeposition.x, SP_Y_LBL, homeposition.y);
59
       delta.b = SCARA_OFFSET_THETA2;
62
       delta.b = SCARA_OFFSET_THETA2;
60
       forward_kinematics_SCARA(delta.a, delta.b);
63
       forward_kinematics_SCARA(delta.a, delta.b);
61
       current_position[axis] = cartes[axis];
64
       current_position[axis] = cartes[axis];
65
+    #elif ENABLED(AXEL_TPARA)
66
+      //DEBUG_ECHOPGM("homeposition");
67
+      //DEBUG_ECHOLNPAIR_P(SP_X_LBL, homeposition.x, SP_Y_LBL, homeposition.y, SP_Z_LBL, homeposition.z);
68
+      inverse_kinematics(homeposition);
69
+      forward_kinematics_TPARA(delta.a, delta.b, delta.c);
70
+      current_position[axis] = cartes[axis];
62
     #endif
71
     #endif
63
 
72
 
64
     //DEBUG_ECHOPGM("Cartesian");
73
     //DEBUG_ECHOPGM("Cartesian");
67
   }
76
   }
68
 }
77
 }
69
 
78
 
70
-static constexpr xy_pos_t scara_offset = { SCARA_OFFSET_X, SCARA_OFFSET_Y };
79
+#if EITHER(MORGAN_SCARA, MP_SCARA)
71
 
80
 
72
-/**
73
- * Morgan SCARA Forward Kinematics. Results in 'cartes'.
74
- * Maths and first version by QHARLEY.
75
- * Integrated into Marlin and slightly restructured by Joachim Cerny.
76
- */
77
-void forward_kinematics_SCARA(const float &a, const float &b) {
78
-
79
-  const float a_sin = sin(RADIANS(a)) * L1,
80
-              a_cos = cos(RADIANS(a)) * L1,
81
-              b_sin = sin(RADIANS(b + TERN0(MP_SCARA, a))) * L2,
82
-              b_cos = cos(RADIANS(b + TERN0(MP_SCARA, a))) * L2;
83
-
84
-  cartes.set(a_cos + b_cos + scara_offset.x,  // theta
85
-             a_sin + b_sin + scara_offset.y); // phi
86
-
87
-  /*
88
-    DEBUG_ECHOLNPAIR(
89
-      "SCARA FK Angle a=", a,
90
-      " b=", b,
91
-      " a_sin=", a_sin,
92
-      " a_cos=", a_cos,
93
-      " b_sin=", b_sin,
94
-      " b_cos=", b_cos
95
-    );
96
-    DEBUG_ECHOLNPAIR(" cartes (X,Y) = "(cartes.x, ", ", cartes.y, ")");
97
-  //*/
98
-}
81
+  static constexpr xy_pos_t scara_offset = { SCARA_OFFSET_X, SCARA_OFFSET_Y };
99
 
82
 
100
-/**
101
- * SCARA Inverse Kinematics. Results in 'delta'.
102
- *
103
- * See https://reprap.org/forum/read.php?185,283327
104
- *
105
- * Maths and first version by QHARLEY.
106
- * Integrated into Marlin and slightly restructured by Joachim Cerny.
107
- */
108
-void inverse_kinematics(const xyz_pos_t &raw) {
109
-  float C2, S2, SK1, SK2, THETA, PSI;
83
+  /**
84
+   * Morgan SCARA Forward Kinematics. Results in 'cartes'.
85
+   * Maths and first version by QHARLEY.
86
+   * Integrated into Marlin and slightly restructured by Joachim Cerny.
87
+   */
88
+  void forward_kinematics_SCARA(const float &a, const float &b) {
89
+    const float a_sin = sin(RADIANS(a)) * L1,
90
+                a_cos = cos(RADIANS(a)) * L1,
91
+                b_sin = sin(RADIANS(b + TERN0(MP_SCARA, a))) * L2,
92
+                b_cos = cos(RADIANS(b + TERN0(MP_SCARA, a))) * L2;
110
 
93
 
111
-  // Translate SCARA to standard XY with scaling factor
112
-  const xy_pos_t spos = raw - scara_offset;
94
+    cartes.x = a_cos + b_cos + scara_offset.x;  // theta
95
+    cartes.y = a_sin + b_sin + scara_offset.y;  // phi
113
 
96
 
114
-  const float H2 = HYPOT2(spos.x, spos.y);
115
-  if (L1 == L2)
116
-    C2 = H2 / L1_2_2 - 1;
117
-  else
118
-    C2 = (H2 - (L1_2 + L2_2)) / (2.0f * L1 * L2);
97
+    /*
98
+      DEBUG_ECHOLNPAIR(
99
+        "SCARA FK Angle a=", a,
100
+        " b=", b,
101
+        " a_sin=", a_sin,
102
+        " a_cos=", a_cos,
103
+        " b_sin=", b_sin,
104
+        " b_cos=", b_cos
105
+      );
106
+      DEBUG_ECHOLNPAIR(" cartes (X,Y) = "(cartes.x, ", ", cartes.y, ")");
107
+    //*/
108
+  }
119
 
109
 
120
-  LIMIT(C2, -1, 1);
110
+  /**
111
+   * Morgan SCARA Inverse Kinematics. Results are stored in 'delta'.
112
+   *
113
+   * See https://reprap.org/forum/read.php?185,283327
114
+   *
115
+   * Maths and first version by QHARLEY.
116
+   * Integrated into Marlin and slightly restructured by Joachim Cerny.
117
+   */
118
+  void inverse_kinematics(const xyz_pos_t &raw) {
119
+    float C2, S2, SK1, SK2, THETA, PSI;
121
 
120
 
122
-  S2 = SQRT(1.0f - sq(C2));
121
+    // Translate SCARA to standard XY with scaling factor
122
+    const xy_pos_t spos = raw - scara_offset;
123
 
123
 
124
-  // Unrotated Arm1 plus rotated Arm2 gives the distance from Center to End
125
-  SK1 = L1 + L2 * C2;
124
+    const float H2 = HYPOT2(spos.x, spos.y);
125
+    if (L1 == L2)
126
+      C2 = H2 / L1_2_2 - 1;
127
+    else
128
+      C2 = (H2 - (L1_2 + L2_2)) / (2.0f * L1 * L2);
126
 
129
 
127
-  // Rotated Arm2 gives the distance from Arm1 to Arm2
128
-  SK2 = L2 * S2;
130
+    LIMIT(C2, -1, 1);
129
 
131
 
130
-  // Angle of Arm1 is the difference between Center-to-End angle and the Center-to-Elbow
131
-  THETA = ATAN2(SK1, SK2) - ATAN2(spos.x, spos.y);
132
+    S2 = SQRT(1.0f - sq(C2));
132
 
133
 
133
-  // Angle of Arm2
134
-  PSI = ATAN2(S2, C2);
134
+    // Unrotated Arm1 plus rotated Arm2 gives the distance from Center to End
135
+    SK1 = L1 + L2 * C2;
135
 
136
 
136
-  delta.set(DEGREES(THETA), DEGREES(PSI + TERN0(MORGAN_SCARA, THETA)), raw.z);
137
+    // Rotated Arm2 gives the distance from Arm1 to Arm2
138
+    SK2 = L2 * S2;
137
 
139
 
138
-  /*
139
-    DEBUG_POS("SCARA IK", raw);
140
-    DEBUG_POS("SCARA IK", delta);
141
-    DEBUG_ECHOLNPAIR("  SCARA (x,y) ", sx, ",", sy, " C2=", C2, " S2=", S2, " Theta=", THETA, " Psi=", PSI);
142
-  //*/
143
-}
140
+    // Angle of Arm1 is the difference between Center-to-End angle and the Center-to-Elbow
141
+    THETA = ATAN2(SK1, SK2) - ATAN2(spos.x, spos.y);
142
+
143
+    // Angle of Arm2
144
+    PSI = ATAN2(S2, C2);
145
+
146
+    delta.set(DEGREES(THETA), DEGREES(PSI + TERN0(MORGAN_SCARA, THETA)), raw.z);
147
+
148
+    /*
149
+      DEBUG_POS("SCARA IK", raw);
150
+      DEBUG_POS("SCARA IK", delta);
151
+      DEBUG_ECHOLNPAIR("  SCARA (x,y) ", sx, ",", sy, " C2=", C2, " S2=", S2, " Theta=", THETA, " Psi=", PSI);
152
+    //*/
153
+  }
154
+
155
+#elif ENABLED(MP_SCARA)
156
+
157
+  void inverse_kinematics(const xyz_pos_t &raw) {
158
+    const float x = raw.x, y = raw.y, c = HYPOT(x, y),
159
+                THETA3 = ATAN2(y, x),
160
+                THETA1 = THETA3 + ACOS((sq(c) + sq(L1) - sq(L2)) / (2.0f * c * L1)),
161
+                THETA2 = THETA3 - ACOS((sq(c) + sq(L2) - sq(L1)) / (2.0f * c * L2));
162
+
163
+    delta.set(DEGREES(THETA1), DEGREES(THETA2), raw.z);
164
+
165
+    /*
166
+      DEBUG_POS("SCARA IK", raw);
167
+      DEBUG_POS("SCARA IK", delta);
168
+      SERIAL_ECHOLNPAIR("  SCARA (x,y) ", x, ",", y," Theta1=", THETA1, " Theta2=", THETA2);
169
+    //*/
170
+  }
171
+
172
+#elif ENABLED(AXEL_TPARA)
173
+
174
+  static constexpr xyz_pos_t robot_offset = { TPARA_OFFSET_X, TPARA_OFFSET_Y, TPARA_OFFSET_Z };
175
+
176
+  // Convert ABC inputs in degrees to XYZ outputs in mm
177
+  void forward_kinematics_TPARA(const float &a, const float &b, const float &c) {
178
+    const float w = c - b,
179
+                r = L1 * cos(RADIANS(b)) + L2 * sin(RADIANS(w - (90 - b))),
180
+                x = r  * cos(RADIANS(a)),
181
+                y = r  * sin(RADIANS(a)),
182
+                rho2 = L1_2 + L2_2 - 2.0f * L1 * L2 * cos(RADIANS(w));
183
+
184
+    cartes = robot_offset + xyz_pos_t({ x, y, SQRT(rho2 - x * x - y * y) });
185
+  }
186
+
187
+  // Home YZ together, then X (or all at once). Based on quick_home_xy & home_delta
188
+  void home_TPARA() {
189
+    // Init the current position of all carriages to 0,0,0
190
+    current_position.reset();
191
+    destination.reset();
192
+    sync_plan_position();
193
+
194
+    // Disable stealthChop if used. Enable diag1 pin on driver.
195
+    #if ENABLED(SENSORLESS_HOMING)
196
+      TERN_(X_SENSORLESS, sensorless_t stealth_states_x = start_sensorless_homing_per_axis(X_AXIS));
197
+      TERN_(Y_SENSORLESS, sensorless_t stealth_states_y = start_sensorless_homing_per_axis(Y_AXIS));
198
+      TERN_(Z_SENSORLESS, sensorless_t stealth_states_z = start_sensorless_homing_per_axis(Z_AXIS));
199
+    #endif
200
+
201
+    // const int x_axis_home_dir = x_home_dir(active_extruder);
202
+
203
+    // const xy_pos_t pos { max_length(X_AXIS) , max_length(Y_AXIS) };
204
+    // const float mlz = max_length(X_AXIS),
205
+
206
+    // Move all carriages together linearly until an endstop is hit.
207
+    //do_blocking_move_to_xy_z(pos, mlz, homing_feedrate(Z_AXIS));
208
+
209
+    current_position.x = 0 ;
210
+    current_position.y = 0 ;
211
+    current_position.z = max_length(Z_AXIS) ;
212
+    line_to_current_position(homing_feedrate(Z_AXIS));
213
+    planner.synchronize();
214
+
215
+    // Re-enable stealthChop if used. Disable diag1 pin on driver.
216
+    #if ENABLED(SENSORLESS_HOMING)
217
+      TERN_(X_SENSORLESS, end_sensorless_homing_per_axis(X_AXIS, stealth_states_x));
218
+      TERN_(Y_SENSORLESS, end_sensorless_homing_per_axis(Y_AXIS, stealth_states_y));
219
+      TERN_(Z_SENSORLESS, end_sensorless_homing_per_axis(Z_AXIS, stealth_states_z));
220
+    #endif
221
+
222
+    endstops.validate_homing_move();
223
+
224
+    // At least one motor has reached its endstop.
225
+    // Now re-home each motor separately.
226
+    homeaxis(A_AXIS);
227
+    homeaxis(C_AXIS);
228
+    homeaxis(B_AXIS);
229
+
230
+
231
+    // Set all carriages to their home positions
232
+    // Do this here all at once for Delta, because
233
+    // XYZ isn't ABC. Applying this per-tower would
234
+    // give the impression that they are the same.
235
+    LOOP_XYZ(i) set_axis_is_at_home((AxisEnum)i);
236
+
237
+    sync_plan_position();
238
+  }
239
+
240
+  void inverse_kinematics(const xyz_pos_t &raw) {
241
+    const xyz_pos_t spos = raw - robot_offset;
242
+
243
+    const float RXY = SQRT(HYPOT2(spos.x, spos.y)),
244
+                RHO2 = NORMSQ(spos.x, spos.y, spos.z),
245
+                //RHO = SQRT(RHO2),
246
+                LSS = L1_2 + L2_2,
247
+                LM = 2.0f * L1 * L2,
248
+
249
+                CG = (LSS - RHO2) / LM,
250
+                SG = SQRT(1 - POW(CG, 2)), // Method 2
251
+                K1 = L1 - L2 * CG,
252
+                K2 = L2 * SG,
253
+
254
+                // Angle of Body Joint
255
+                THETA = ATAN2(spos.y, spos.x),
256
+
257
+                // Angle of Elbow Joint
258
+                //GAMMA = ACOS(CG),
259
+                GAMMA = ATAN2(SG, CG), // Method 2
260
+
261
+                // Angle of Shoulder Joint, elevation angle measured from horizontal (r+)
262
+                //PHI = asin(spos.z/RHO) + asin(L2 * sin(GAMMA) / RHO),
263
+                PHI = ATAN2(spos.z, RXY) + ATAN2(K2, K1),   // Method 2
264
+
265
+                // Elbow motor angle measured from horizontal, same frame as shoulder  (r+)
266
+                PSI = PHI + GAMMA;
267
+
268
+    delta.set(DEGREES(THETA), DEGREES(PHI), DEGREES(PSI));
269
+
270
+    //SERIAL_ECHOLNPAIR(" SCARA (x,y,z) ", spos.x , ",", spos.y, ",", spos.z, " Rho=", RHO, " Rho2=", RHO2, " Theta=", THETA, " Phi=", PHI, " Psi=", PSI, " Gamma=", GAMMA);
271
+  }
272
+
273
+#endif
144
 
274
 
145
 void scara_report_positions() {
275
 void scara_report_positions() {
146
-  SERIAL_ECHOLNPAIR(
147
-    "SCARA Theta:", planner.get_axis_position_degrees(A_AXIS),
148
-    "  Psi" TERN_(MORGAN_SCARA, "+Theta") ":", planner.get_axis_position_degrees(B_AXIS)
276
+  SERIAL_ECHOLNPAIR("SCARA Theta:", planner.get_axis_position_degrees(A_AXIS)
277
+    #if ENABLED(AXEL_TPARA)
278
+      , "  Phi:", planner.get_axis_position_degrees(B_AXIS)
279
+      , "  Psi:", planner.get_axis_position_degrees(C_AXIS)
280
+    #else
281
+      , "  Psi" TERN_(MORGAN_SCARA, "+Theta") ":", planner.get_axis_position_degrees(B_AXIS)
282
+    #endif
149
   );
283
   );
150
   SERIAL_EOL();
284
   SERIAL_EOL();
151
 }
285
 }

+ 18
- 7
Marlin/src/module/scara.h View File

29
 
29
 
30
 extern float delta_segments_per_second;
30
 extern float delta_segments_per_second;
31
 
31
 
32
-// Float constants for SCARA calculations
33
-float constexpr L1 = SCARA_LINKAGE_1, L2 = SCARA_LINKAGE_2,
34
-                L1_2 = sq(float(L1)), L1_2_2 = 2.0 * L1_2,
35
-                L2_2 = sq(float(L2));
32
+#if ENABLED(AXEL_TPARA)
36
 
33
 
37
-void scara_set_axis_is_at_home(const AxisEnum axis);
34
+  float constexpr L1 = TPARA_LINKAGE_1, L2 = TPARA_LINKAGE_2,   // Float constants for Robot arm calculations
35
+                  L1_2 = sq(float(L1)), L1_2_2 = 2.0 * L1_2,
36
+                  L2_2 = sq(float(L2));
38
 
37
 
39
-void inverse_kinematics(const xyz_pos_t &raw);
40
-void forward_kinematics_SCARA(const float &a, const float &b);
38
+  void forward_kinematics_TPARA(const float &a, const float &b, const float &c);
39
+  void home_TPARA();
40
+
41
+#else
42
+
43
+  float constexpr L1 = SCARA_LINKAGE_1, L2 = SCARA_LINKAGE_2,   // Float constants for SCARA calculations
44
+                  L1_2 = sq(float(L1)), L1_2_2 = 2.0 * L1_2,
45
+                  L2_2 = sq(float(L2));
41
 
46
 
47
+  void forward_kinematics_SCARA(const float &a, const float &b);
48
+
49
+#endif
50
+
51
+void inverse_kinematics(const xyz_pos_t &raw);
52
+void scara_set_axis_is_at_home(const AxisEnum axis);
42
 void scara_report_positions();
53
 void scara_report_positions();

Loading…
Cancel
Save