Explorar el Código

Move get_axis_position_mm to Planner (#10718)

Scott Lahteine hace 6 años
padre
commit
8f8c6a9bc4
No account linked to committer's email address

+ 3
- 3
Marlin/src/core/utility.cpp Ver fichero

@@ -338,9 +338,9 @@ void safe_delay(millis_t ms) {
338 338
         #endif
339 339
         #if ABL_PLANAR
340 340
           const float diff[XYZ] = {
341
-            stepper.get_axis_position_mm(X_AXIS) - current_position[X_AXIS],
342
-            stepper.get_axis_position_mm(Y_AXIS) - current_position[Y_AXIS],
343
-            stepper.get_axis_position_mm(Z_AXIS) - current_position[Z_AXIS]
341
+            planner.get_axis_position_mm(X_AXIS) - current_position[X_AXIS],
342
+            planner.get_axis_position_mm(Y_AXIS) - current_position[Y_AXIS],
343
+            planner.get_axis_position_mm(Z_AXIS) - current_position[Z_AXIS]
344 344
           };
345 345
           SERIAL_ECHOPGM("ABL Adjustment X");
346 346
           if (diff[X_AXIS] > 0) SERIAL_CHAR('+');

+ 12
- 12
Marlin/src/feature/I2CPositionEncoder.cpp Ver fichero

@@ -99,15 +99,15 @@ void I2CPositionEncoder::update() {
99 99
 
100 100
         //the encoder likely lost its place when the error occured, so we'll reset and use the printer's
101 101
         //idea of where it the axis is to re-initialise
102
-        float position = stepper.get_axis_position_mm(encoderAxis);
103
-        int32_t positionInTicks = position * get_ticks_unit();
102
+        const float pos = planner.get_axis_position_mm(encoderAxis);
103
+        int32_t positionInTicks = pos * get_ticks_unit();
104 104
 
105 105
         //shift position from previous to current position
106 106
         zeroOffset -= (positionInTicks - get_position());
107 107
 
108 108
         #ifdef I2CPE_DEBUG
109 109
           SERIAL_ECHOPGM("Current position is ");
110
-          SERIAL_ECHOLN(position);
110
+          SERIAL_ECHOLN(pos);
111 111
 
112 112
           SERIAL_ECHOPGM("Position in encoder ticks is ");
113 113
           SERIAL_ECHOLN(positionInTicks);
@@ -254,7 +254,7 @@ bool I2CPositionEncoder::passes_test(const bool report) {
254 254
 float I2CPositionEncoder::get_axis_error_mm(const bool report) {
255 255
   float target, actual, error;
256 256
 
257
-  target = stepper.get_axis_position_mm(encoderAxis);
257
+  target = planner.get_axis_position_mm(encoderAxis);
258 258
   actual = mm_from_count(position);
259 259
   error = actual - target;
260 260
 
@@ -349,8 +349,8 @@ bool I2CPositionEncoder::test_axis() {
349 349
   ec = false;
350 350
 
351 351
   LOOP_NA(i) {
352
-    startCoord[i] = stepper.get_axis_position_mm((AxisEnum)i);
353
-    endCoord[i] = stepper.get_axis_position_mm((AxisEnum)i);
352
+    startCoord[i] = planner.get_axis_position_mm((AxisEnum)i);
353
+    endCoord[i] = planner.get_axis_position_mm((AxisEnum)i);
354 354
   }
355 355
 
356 356
   startCoord[encoderAxis] = startPosition;
@@ -359,7 +359,7 @@ bool I2CPositionEncoder::test_axis() {
359 359
   planner.synchronize();
360 360
 
361 361
   planner.buffer_line(startCoord[X_AXIS], startCoord[Y_AXIS], startCoord[Z_AXIS],
362
-                      stepper.get_axis_position_mm(E_AXIS), feedrate, 0);
362
+                      planner.get_axis_position_mm(E_AXIS), feedrate, 0);
363 363
   planner.synchronize();
364 364
 
365 365
   // if the module isn't currently trusted, wait until it is (or until it should be if things are working)
@@ -371,7 +371,7 @@ bool I2CPositionEncoder::test_axis() {
371 371
 
372 372
   if (trusted) { // if trusted, commence test
373 373
     planner.buffer_line(endCoord[X_AXIS], endCoord[Y_AXIS], endCoord[Z_AXIS],
374
-                        stepper.get_axis_position_mm(E_AXIS), feedrate, 0);
374
+                        planner.get_axis_position_mm(E_AXIS), feedrate, 0);
375 375
     planner.synchronize();
376 376
   }
377 377
 
@@ -408,8 +408,8 @@ void I2CPositionEncoder::calibrate_steps_mm(const uint8_t iter) {
408 408
   travelDistance = endDistance - startDistance;
409 409
 
410 410
   LOOP_NA(i) {
411
-    startCoord[i] = stepper.get_axis_position_mm((AxisEnum)i);
412
-    endCoord[i] = stepper.get_axis_position_mm((AxisEnum)i);
411
+    startCoord[i] = planner.get_axis_position_mm((AxisEnum)i);
412
+    endCoord[i] = planner.get_axis_position_mm((AxisEnum)i);
413 413
   }
414 414
 
415 415
   startCoord[encoderAxis] = startDistance;
@@ -419,7 +419,7 @@ void I2CPositionEncoder::calibrate_steps_mm(const uint8_t iter) {
419 419
 
420 420
   LOOP_L_N(i, iter) {
421 421
     planner.buffer_line(startCoord[X_AXIS], startCoord[Y_AXIS], startCoord[Z_AXIS],
422
-                        stepper.get_axis_position_mm(E_AXIS), feedrate, 0);
422
+                        planner.get_axis_position_mm(E_AXIS), feedrate, 0);
423 423
     planner.synchronize();
424 424
 
425 425
     delay(250);
@@ -428,7 +428,7 @@ void I2CPositionEncoder::calibrate_steps_mm(const uint8_t iter) {
428 428
     //do_blocking_move_to(endCoord[X_AXIS],endCoord[Y_AXIS],endCoord[Z_AXIS]);
429 429
 
430 430
     planner.buffer_line(endCoord[X_AXIS], endCoord[Y_AXIS], endCoord[Z_AXIS],
431
-                        stepper.get_axis_position_mm(E_AXIS), feedrate, 0);
431
+                        planner.get_axis_position_mm(E_AXIS), feedrate, 0);
432 432
     planner.synchronize();
433 433
 
434 434
     //Read encoder distance

+ 2
- 2
Marlin/src/feature/bedlevel/ubl/ubl_motion.cpp Ver fichero

@@ -448,8 +448,8 @@
448 448
 
449 449
     #if IS_SCARA // scale the feed rate from mm/s to degrees/s
450 450
       scara_feed_factor = cartesian_xy_mm * inv_segments * feedrate;
451
-      scara_oldA = stepper.get_axis_position_degrees(A_AXIS);
452
-      scara_oldB = stepper.get_axis_position_degrees(B_AXIS);
451
+      scara_oldA = planner.get_axis_position_degrees(A_AXIS);
452
+      scara_oldB = planner.get_axis_position_degrees(B_AXIS);
453 453
     #endif
454 454
 
455 455
     const float diff[XYZE] = {

+ 3
- 3
Marlin/src/gcode/host/M114.cpp Ver fichero

@@ -90,8 +90,8 @@
90 90
 
91 91
     #if IS_SCARA
92 92
       const float deg[XYZ] = {
93
-        stepper.get_axis_position_degrees(A_AXIS),
94
-        stepper.get_axis_position_degrees(B_AXIS)
93
+        planner.get_axis_position_degrees(A_AXIS),
94
+        planner.get_axis_position_degrees(B_AXIS)
95 95
       };
96 96
       SERIAL_PROTOCOLPGM("Degrees:");
97 97
       report_xyze(deg, 2);
@@ -99,7 +99,7 @@
99 99
 
100 100
     SERIAL_PROTOCOLPGM("FromStp:");
101 101
     get_cartesian_from_steppers();  // writes cartes[XYZ] (with forward kinematics)
102
-    const float from_steppers[XYZE] = { cartes[X_AXIS], cartes[Y_AXIS], cartes[Z_AXIS], stepper.get_axis_position_mm(E_AXIS) };
102
+    const float from_steppers[XYZE] = { cartes[X_AXIS], cartes[Y_AXIS], cartes[Z_AXIS], planner.get_axis_position_mm(E_AXIS) };
103 103
     report_xyze(from_steppers);
104 104
 
105 105
     const float diff[XYZE] = {

+ 9
- 14
Marlin/src/module/motion.cpp Ver fichero

@@ -193,21 +193,21 @@ void sync_plan_position_e() { planner.set_e_position_mm(current_position[E_AXIS]
193 193
 void get_cartesian_from_steppers() {
194 194
   #if ENABLED(DELTA)
195 195
     forward_kinematics_DELTA(
196
-      stepper.get_axis_position_mm(A_AXIS),
197
-      stepper.get_axis_position_mm(B_AXIS),
198
-      stepper.get_axis_position_mm(C_AXIS)
196
+      planner.get_axis_position_mm(A_AXIS),
197
+      planner.get_axis_position_mm(B_AXIS),
198
+      planner.get_axis_position_mm(C_AXIS)
199 199
     );
200 200
   #else
201 201
     #if IS_SCARA
202 202
       forward_kinematics_SCARA(
203
-        stepper.get_axis_position_degrees(A_AXIS),
204
-        stepper.get_axis_position_degrees(B_AXIS)
203
+        planner.get_axis_position_degrees(A_AXIS),
204
+        planner.get_axis_position_degrees(B_AXIS)
205 205
       );
206 206
     #else
207
-      cartes[X_AXIS] = stepper.get_axis_position_mm(X_AXIS);
208
-      cartes[Y_AXIS] = stepper.get_axis_position_mm(Y_AXIS);
207
+      cartes[X_AXIS] = planner.get_axis_position_mm(X_AXIS);
208
+      cartes[Y_AXIS] = planner.get_axis_position_mm(Y_AXIS);
209 209
     #endif
210
-    cartes[Z_AXIS] = stepper.get_axis_position_mm(Z_AXIS);
210
+    cartes[Z_AXIS] = planner.get_axis_position_mm(Z_AXIS);
211 211
   #endif
212 212
 }
213 213
 
@@ -870,12 +870,7 @@ float soft_endstop_min[XYZ] = { X_MIN_BED, Y_MIN_BED, Z_MIN_POS },
870 870
               }
871 871
             #endif
872 872
             // move duplicate extruder into correct duplication position.
873
-            planner.set_position_mm(
874
-              inactive_extruder_x_pos,
875
-              current_position[Y_AXIS],
876
-              current_position[Z_AXIS],
877
-              current_position[E_AXIS]
878
-            );
873
+            planner.set_position_mm(inactive_extruder_x_pos, current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);
879 874
             planner.buffer_line(
880 875
               current_position[X_AXIS] + duplicate_extruder_x_offset,
881 876
               current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS],

+ 31
- 0
Marlin/src/module/planner.cpp Ver fichero

@@ -1300,6 +1300,37 @@ void Planner::check_axes_activity() {
1300 1300
 #endif // PLANNER_LEVELING
1301 1301
 
1302 1302
 /**
1303
+ * Get an axis position according to stepper position(s)
1304
+ * For CORE machines apply translation from ABC to XYZ.
1305
+ */
1306
+float Planner::get_axis_position_mm(const AxisEnum axis) {
1307
+  float axis_steps;
1308
+  #if IS_CORE
1309
+    // Requesting one of the "core" axes?
1310
+    if (axis == CORE_AXIS_1 || axis == CORE_AXIS_2) {
1311
+
1312
+      // Protect the access to the position.
1313
+      const bool was_enabled = STEPPER_ISR_ENABLED();
1314
+      DISABLE_STEPPER_DRIVER_INTERRUPT();
1315
+
1316
+      // ((a1+a2)+(a1-a2))/2 -> (a1+a2+a1-a2)/2 -> (a1+a1)/2 -> a1
1317
+      // ((a1+a2)-(a1-a2))/2 -> (a1+a2-a1+a2)/2 -> (a2+a2)/2 -> a2
1318
+      axis_steps = 0.5f * (
1319
+        axis == CORE_AXIS_2 ? CORESIGN(stepper.position(CORE_AXIS_1) - stepper.position(CORE_AXIS_2))
1320
+                            : stepper.position(CORE_AXIS_1) + stepper.position(CORE_AXIS_2)
1321
+      );
1322
+
1323
+      if (was_enabled) ENABLE_STEPPER_DRIVER_INTERRUPT();
1324
+    }
1325
+    else
1326
+      axis_steps = stepper.position(axis);
1327
+  #else
1328
+    axis_steps = stepper.position(axis);
1329
+  #endif
1330
+  return axis_steps * steps_to_mm[axis];
1331
+}
1332
+
1333
+/**
1303 1334
  * Block until all buffered steps are executed / cleaned
1304 1335
  */
1305 1336
 void Planner::synchronize() { while (has_blocks_queued() || stepper.cleaning_buffer_counter) idle(); }

+ 11
- 0
Marlin/src/module/planner.h Ver fichero

@@ -547,6 +547,17 @@ class Planner {
547 547
     static void sync_from_steppers();
548 548
 
549 549
     /**
550
+     * Get an axis position according to stepper position(s)
551
+     * For CORE machines apply translation from ABC to XYZ.
552
+     */
553
+    static float get_axis_position_mm(const AxisEnum axis);
554
+
555
+    // SCARA AB axes are in degrees, not mm
556
+    #if IS_SCARA
557
+      FORCE_INLINE static float get_axis_position_degrees(const AxisEnum axis) { return get_axis_position_mm(axis); }
558
+    #endif
559
+
560
+    /**
550 561
      * Does the buffer have any blocks queued?
551 562
      */
552 563
     FORCE_INLINE static bool has_blocks_queued() { return (block_buffer_head != block_buffer_tail); }

+ 3
- 3
Marlin/src/module/scara.cpp Ver fichero

@@ -30,7 +30,7 @@
30 30
 
31 31
 #include "scara.h"
32 32
 #include "motion.h"
33
-#include "stepper.h"
33
+#include "planner.h"
34 34
 
35 35
 float delta_segments_per_second = SCARA_SEGMENTS_PER_SECOND;
36 36
 
@@ -147,8 +147,8 @@ void inverse_kinematics(const float raw[XYZ]) {
147 147
 }
148 148
 
149 149
 void scara_report_positions() {
150
-  SERIAL_PROTOCOLPAIR("SCARA Theta:", stepper.get_axis_position_degrees(A_AXIS));
151
-  SERIAL_PROTOCOLLNPAIR("   Psi+Theta:", stepper.get_axis_position_degrees(B_AXIS));
150
+  SERIAL_PROTOCOLPAIR("SCARA Theta:", planner.get_axis_position_degrees(A_AXIS));
151
+  SERIAL_PROTOCOLLNPAIR("   Psi+Theta:", planner.get_axis_position_degrees(B_AXIS));
152 152
   SERIAL_EOL();
153 153
 }
154 154
 

+ 0
- 26
Marlin/src/module/stepper.cpp Ver fichero

@@ -2037,32 +2037,6 @@ int32_t Stepper::position(const AxisEnum axis) {
2037 2037
   return count_pos;
2038 2038
 }
2039 2039
 
2040
-/**
2041
- * Get an axis position according to stepper position(s)
2042
- * For CORE machines apply translation from ABC to XYZ.
2043
- */
2044
-float Stepper::get_axis_position_mm(const AxisEnum axis) {
2045
-  float axis_steps;
2046
-  #if IS_CORE
2047
-    // Requesting one of the "core" axes?
2048
-    if (axis == CORE_AXIS_1 || axis == CORE_AXIS_2) {
2049
-      CRITICAL_SECTION_START;
2050
-      // ((a1+a2)+(a1-a2))/2 -> (a1+a2+a1-a2)/2 -> (a1+a1)/2 -> a1
2051
-      // ((a1+a2)-(a1-a2))/2 -> (a1+a2-a1+a2)/2 -> (a2+a2)/2 -> a2
2052
-      axis_steps = 0.5f * (
2053
-        axis == CORE_AXIS_2 ? CORESIGN(count_position[CORE_AXIS_1] - count_position[CORE_AXIS_2])
2054
-                            : count_position[CORE_AXIS_1] + count_position[CORE_AXIS_2]
2055
-      );
2056
-      CRITICAL_SECTION_END;
2057
-    }
2058
-    else
2059
-      axis_steps = position(axis);
2060
-  #else
2061
-    axis_steps = position(axis);
2062
-  #endif
2063
-  return axis_steps * planner.steps_to_mm[axis];
2064
-}
2065
-
2066 2040
 void Stepper::finish_and_disable() {
2067 2041
   planner.synchronize();
2068 2042
   disable_all_steppers();

+ 0
- 12
Marlin/src/module/stepper.h Ver fichero

@@ -229,18 +229,6 @@ class Stepper {
229 229
     static void report_positions();
230 230
 
231 231
     //
232
-    // Get the position (mm) of an axis based on stepper position(s)
233
-    //
234
-    static float get_axis_position_mm(const AxisEnum axis);
235
-
236
-    //
237
-    // SCARA AB axes are in degrees, not mm
238
-    //
239
-    #if IS_SCARA
240
-      FORCE_INLINE static float get_axis_position_degrees(const AxisEnum axis) { return get_axis_position_mm(axis); }
241
-    #endif
242
-
243
-    //
244 232
     // The stepper subsystem goes to sleep when it runs out of things to execute. Call this
245 233
     // to notify the subsystem that it is time to go to work.
246 234
     //

+ 1
- 1
Marlin/src/module/temperature.cpp Ver fichero

@@ -36,7 +36,7 @@
36 36
   #include "../libs/private_spi.h"
37 37
 #endif
38 38
 
39
-#if ENABLED(BABYSTEPPING)
39
+#if ENABLED(BABYSTEPPING) || ENABLED(PID_EXTRUSION_SCALING)
40 40
   #include "stepper.h"
41 41
 #endif
42 42
 

+ 0
- 4
Marlin/src/module/temperature.h Ver fichero

@@ -38,10 +38,6 @@
38 38
   #include "../feature/power.h"
39 39
 #endif
40 40
 
41
-#if ENABLED(PID_EXTRUSION_SCALING)
42
-  #include "stepper.h"
43
-#endif
44
-
45 41
 #ifndef SOFT_PWM_SCALE
46 42
   #define SOFT_PWM_SCALE 0
47 43
 #endif

Loading…
Cancelar
Guardar