Browse Source

✨ Polargraph M665 settings (#24401)

Arthur Masson 2 years ago
parent
commit
9706cd0d7d
No account linked to committer's email address

+ 1
- 1
Marlin/src/gcode/bedlevel/G26.cpp View File

@@ -306,7 +306,7 @@ typedef struct {
306 306
         LIMIT(e.x, X_MIN_POS + 1, X_MAX_POS - 1);
307 307
       #endif
308 308
 
309
-      if (position_is_reachable(s.x, s.y) && position_is_reachable(e.x, e.y))
309
+      if (position_is_reachable(s) && position_is_reachable(e))
310 310
         print_line_from_here_to_there(s, e);
311 311
     }
312 312
   }

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

@@ -86,13 +86,13 @@
86 86
    *
87 87
    * Parameters:
88 88
    *
89
-   *   S[segments-per-second] - Segments-per-second
89
+   *   S[segments]          - Segments-per-second
90 90
    *
91 91
    * Without NO_WORKSPACE_OFFSETS:
92 92
    *
93
-   *   P[theta-psi-offset]    - Theta-Psi offset, added to the shoulder (A/X) angle
94
-   *   T[theta-offset]        - Theta     offset, added to the elbow    (B/Y) angle
95
-   *   Z[z-offset]            - Z offset, added to Z
93
+   *   P[theta-psi-offset]  - Theta-Psi offset, added to the shoulder (A/X) angle
94
+   *   T[theta-offset]      - Theta     offset, added to the elbow    (B/Y) angle
95
+   *   Z[z-offset]          - Z offset, added to Z
96 96
    *
97 97
    *   A, P, and X are all aliases for the shoulder angle
98 98
    *   B, T, and Y are all aliases for the elbow angle
@@ -152,18 +152,35 @@
152 152
    *
153 153
    * Parameters:
154 154
    *
155
-   *   S[segments-per-second] - Segments-per-second
155
+   *   S[segments]  - Segments-per-second
156
+   *   L[left]      - Work area minimum X
157
+   *   R[right]     - Work area maximum X
158
+   *   T[top]       - Work area maximum Y
159
+   *   B[bottom]    - Work area minimum Y
160
+   *   H[length]    - Maximum belt length
156 161
    */
157 162
   void GcodeSuite::M665() {
158
-    if (parser.seenval('S'))
159
-      segments_per_second = parser.value_float();
160
-    else
161
-      M665_report();
163
+    if (!parser.seen_any()) return M665_report();
164
+    if (parser.seenval('S')) segments_per_second = parser.value_float();
165
+    if (parser.seenval('L')) draw_area_min.x = parser.value_linear_units();
166
+    if (parser.seenval('R')) draw_area_max.x = parser.value_linear_units();
167
+    if (parser.seenval('T')) draw_area_max.y = parser.value_linear_units();
168
+    if (parser.seenval('B')) draw_area_min.y = parser.value_linear_units();
169
+    if (parser.seenval('H')) polargraph_max_belt_len = parser.value_linear_units();
170
+    draw_area_size.x = draw_area_max.x - draw_area_min.x;
171
+    draw_area_size.y = draw_area_max.y - draw_area_min.y;
162 172
   }
163 173
 
164 174
   void GcodeSuite::M665_report(const bool forReplay/*=true*/) {
165
-    report_heading_etc(forReplay, F(STR_POLARGRAPH_SETTINGS " (" STR_S_SEG_PER_SEC ")"));
166
-    SERIAL_ECHOLNPGM("  M665 S", segments_per_second);
175
+    report_heading_etc(forReplay, F(STR_POLARGRAPH_SETTINGS));
176
+    SERIAL_ECHOLNPGM_P(
177
+      PSTR("  M665 S"), LINEAR_UNIT(segments_per_second),
178
+      PSTR(" L"), LINEAR_UNIT(draw_area_min.x),
179
+      PSTR(" R"), LINEAR_UNIT(draw_area_max.x),
180
+      SP_T_STR, LINEAR_UNIT(draw_area_max.y),
181
+      SP_B_STR, LINEAR_UNIT(draw_area_min.y),
182
+      PSTR(" H"), LINEAR_UNIT(polargraph_max_belt_len)
183
+    );
167 184
   }
168 185
 
169 186
 #endif

+ 1
- 1
Marlin/src/gcode/gcode.cpp View File

@@ -933,7 +933,7 @@ void GcodeSuite::process_parsed_command(const bool no_ok/*=false*/) {
933 933
       #endif
934 934
 
935 935
       #if IS_KINEMATIC
936
-        case 665: M665(); break;                                  // M665: Set Delta/SCARA parameters
936
+        case 665: M665(); break;                                  // M665: Set Kinematics parameters
937 937
       #endif
938 938
 
939 939
       #if ENABLED(DELTA) || HAS_EXTRA_ENDSTOPS

+ 1
- 0
Marlin/src/gcode/gcode.h View File

@@ -262,6 +262,7 @@
262 262
  * M605 - Set Dual X-Carriage movement mode: "M605 S<mode> [X<x_offset>] [R<temp_offset>]". (Requires DUAL_X_CARRIAGE)
263 263
  * M665 - Set delta configurations: "M665 H<delta height> L<diagonal rod> R<delta radius> S<segments/s> B<calibration radius> X<Alpha angle trim> Y<Beta angle trim> Z<Gamma angle trim> (Requires DELTA)
264 264
  *        Set SCARA configurations: "M665 S<segments-per-second> P<theta-psi-offset> T<theta-offset> Z<z-offset> (Requires MORGAN_SCARA or MP_SCARA)
265
+ *        Set Polargraph draw area and belt length: "M665 S<segments-per-second> L<draw-area-left> R<draw-area-right> T<draw-area-top> B<draw-area-bottom> H<max-belt-length>"
265 266
  * M666 - Set/get offsets for delta (Requires DELTA) or dual endstops. (Requires [XYZ]_DUAL_ENDSTOPS)
266 267
  * M672 - Set/Reset Duet Smart Effector's sensitivity. (Requires DUET_SMART_EFFECTOR and SMART_EFFECTOR_MOD_PIN)
267 268
  * M701 - Load filament (Requires FILAMENT_LOAD_UNLOAD_GCODES)

+ 67
- 0
Marlin/src/module/motion.cpp View File

@@ -300,6 +300,73 @@ void report_current_position_projected() {
300 300
 
301 301
 #endif
302 302
 
303
+#if IS_KINEMATIC
304
+
305
+  bool position_is_reachable(const_float_t rx, const_float_t ry, const float inset/*=0*/) {
306
+
307
+    bool can_reach;
308
+
309
+    #if ENABLED(DELTA)
310
+
311
+      can_reach = HYPOT2(rx, ry) <= sq(DELTA_PRINTABLE_RADIUS - inset + fslop);
312
+
313
+    #elif ENABLED(AXEL_TPARA)
314
+
315
+      const float R2 = HYPOT2(rx - TPARA_OFFSET_X, ry - TPARA_OFFSET_Y);
316
+      can_reach = (
317
+        R2 <= sq(L1 + L2) - inset
318
+        #if MIDDLE_DEAD_ZONE_R > 0
319
+          && R2 >= sq(float(MIDDLE_DEAD_ZONE_R))
320
+        #endif
321
+      );
322
+
323
+    #elif IS_SCARA
324
+
325
+      const float R2 = HYPOT2(rx - SCARA_OFFSET_X, ry - SCARA_OFFSET_Y);
326
+      can_reach = (
327
+        R2 <= sq(L1 + L2) - inset
328
+        #if MIDDLE_DEAD_ZONE_R > 0
329
+          && R2 >= sq(float(MIDDLE_DEAD_ZONE_R))
330
+        #endif
331
+      );
332
+
333
+    #elif ENABLED(POLARGRAPH)
334
+
335
+      const float d1 = rx - (draw_area_min.x),
336
+                  d2 = (draw_area_max.x) - rx,
337
+                   y = ry - (draw_area_max.y),
338
+                   a = HYPOT(d1, y),
339
+                   b = HYPOT(d2, y);
340
+
341
+      can_reach = (
342
+           a < polargraph_max_belt_len + 1
343
+        && b < polargraph_max_belt_len + 1
344
+        && (a + b) > _MIN(draw_area_size.x, draw_area_size.y)
345
+      );
346
+
347
+    #endif
348
+
349
+    return can_reach;
350
+  }
351
+
352
+#else // CARTESIAN
353
+
354
+  // Return true if the given position is within the machine bounds.
355
+  bool position_is_reachable(const_float_t rx, const_float_t ry) {
356
+    if (!COORDINATE_OKAY(ry, Y_MIN_POS - fslop, Y_MAX_POS + fslop)) return false;
357
+    #if ENABLED(DUAL_X_CARRIAGE)
358
+      if (active_extruder)
359
+        return COORDINATE_OKAY(rx, X2_MIN_POS - fslop, X2_MAX_POS + fslop);
360
+      else
361
+        return COORDINATE_OKAY(rx, X1_MIN_POS - fslop, X1_MAX_POS + fslop);
362
+    #else
363
+      return COORDINATE_OKAY(rx, X_MIN_POS - fslop, X_MAX_POS + fslop);
364
+    #endif
365
+  }
366
+
367
+#endif // CARTESIAN
368
+
369
+
303 370
 void home_if_needed(const bool keeplev/*=false*/) {
304 371
   if (!all_axes_trusted()) gcode.home_all_axes(keeplev);
305 372
 }

+ 6
- 48
Marlin/src/module/motion.h View File

@@ -549,63 +549,21 @@ void home_if_needed(const bool keeplev=false);
549 549
   #endif
550 550
 
551 551
   // Return true if the given point is within the printable area
552
-  inline bool position_is_reachable(const_float_t rx, const_float_t ry, const float inset=0) {
553
-    #if ENABLED(DELTA)
554
-
555
-      return HYPOT2(rx, ry) <= sq(DELTA_PRINTABLE_RADIUS - inset + fslop);
556
-
557
-    #elif ENABLED(POLARGRAPH)
558
-
559
-      const float x1 = rx - (X_MIN_POS), x2 = (X_MAX_POS) - rx, y = ry - (Y_MAX_POS),
560
-                  a = HYPOT(x1, y), b = HYPOT(x2, y);
561
-      return a < (POLARGRAPH_MAX_BELT_LEN) + 1
562
-          && b < (POLARGRAPH_MAX_BELT_LEN) + 1
563
-          && (a + b) > _MIN(X_BED_SIZE, Y_BED_SIZE);
564
-
565
-    #elif ENABLED(AXEL_TPARA)
566
-
567
-      const float R2 = HYPOT2(rx - TPARA_OFFSET_X, ry - TPARA_OFFSET_Y);
568
-      return (
569
-        R2 <= sq(L1 + L2) - inset
570
-        #if MIDDLE_DEAD_ZONE_R > 0
571
-          && R2 >= sq(float(MIDDLE_DEAD_ZONE_R))
572
-        #endif
573
-      );
574
-
575
-    #elif IS_SCARA
576
-
577
-      const float R2 = HYPOT2(rx - SCARA_OFFSET_X, ry - SCARA_OFFSET_Y);
578
-      return (
579
-        R2 <= sq(L1 + L2) - inset
580
-        #if MIDDLE_DEAD_ZONE_R > 0
581
-          && R2 >= sq(float(MIDDLE_DEAD_ZONE_R))
582
-        #endif
583
-      );
584
-
585
-    #endif
586
-  }
552
+  bool position_is_reachable(const_float_t rx, const_float_t ry, const float inset=0);
587 553
 
588 554
   inline bool position_is_reachable(const xy_pos_t &pos, const float inset=0) {
589 555
     return position_is_reachable(pos.x, pos.y, inset);
590 556
   }
591 557
 
592
-#else // CARTESIAN
558
+#else
593 559
 
594 560
   // Return true if the given position is within the machine bounds.
595
-  inline bool position_is_reachable(const_float_t rx, const_float_t ry) {
596
-    if (!COORDINATE_OKAY(ry, Y_MIN_POS - fslop, Y_MAX_POS + fslop)) return false;
597
-    #if ENABLED(DUAL_X_CARRIAGE)
598
-      if (active_extruder)
599
-        return COORDINATE_OKAY(rx, X2_MIN_POS - fslop, X2_MAX_POS + fslop);
600
-      else
601
-        return COORDINATE_OKAY(rx, X1_MIN_POS - fslop, X1_MAX_POS + fslop);
602
-    #else
603
-      return COORDINATE_OKAY(rx, X_MIN_POS - fslop, X_MAX_POS + fslop);
604
-    #endif
561
+  bool position_is_reachable(const_float_t rx, const_float_t ry);
562
+  inline bool position_is_reachable(const xy_pos_t &pos) {
563
+    return position_is_reachable(pos.x, pos.y);
605 564
   }
606
-  inline bool position_is_reachable(const xy_pos_t &pos) { return position_is_reachable(pos.x, pos.y); }
607 565
 
608
-#endif // CARTESIAN
566
+#endif
609 567
 
610 568
 /**
611 569
  * Duplication mode

+ 8
- 1
Marlin/src/module/polargraph.cpp View File

@@ -39,8 +39,15 @@
39 39
 
40 40
 float segments_per_second; // Initialized by settings.load()
41 41
 
42
+xy_pos_t draw_area_min = { X_MIN_POS, Y_MIN_POS },
43
+         draw_area_max = { X_MAX_POS, Y_MAX_POS };
44
+
45
+xy_float_t draw_area_size = { X_MAX_POS - X_MIN_POS, Y_MAX_POS - Y_MIN_POS };
46
+
47
+float polargraph_max_belt_len = HYPOT(draw_area_size.x, draw_area_size.y);
48
+
42 49
 void inverse_kinematics(const xyz_pos_t &raw) {
43
-  const float x1 = raw.x - (X_MIN_POS), x2 = (X_MAX_POS) - raw.x, y = raw.y - (Y_MAX_POS);
50
+  const float x1 = raw.x - (draw_area_min.x), x2 = (draw_area_max.x) - raw.x, y = raw.y - (draw_area_max.y);
44 51
   delta.set(HYPOT(x1, y), HYPOT(x2, y), raw.z);
45 52
 }
46 53
 

+ 3
- 0
Marlin/src/module/polargraph.h View File

@@ -29,5 +29,8 @@
29 29
 #include "../core/macros.h"
30 30
 
31 31
 extern float segments_per_second;
32
+extern xy_pos_t draw_area_min, draw_area_max;
33
+extern xy_float_t draw_area_size;
34
+extern float polargraph_max_belt_len;
32 35
 
33 36
 void inverse_kinematics(const xyz_pos_t &raw);

Loading…
Cancel
Save