Browse Source

🐛 Fix G2/G3 angular motion calculation (#22407)

Yash 4 years ago
parent
commit
497541e199
No account linked to committer's email address
1 changed files with 9 additions and 6 deletions
  1. 9
    6
      Marlin/src/gcode/motion/G2_G3.cpp

+ 9
- 6
Marlin/src/gcode/motion/G2_G3.cpp View File

83
   #endif
83
   #endif
84
 
84
 
85
   // Angle of rotation between position and target from the circle center.
85
   // Angle of rotation between position and target from the circle center.
86
-  float angular_travel;
86
+  float angular_travel, abs_angular_travel;
87
 
87
 
88
   // Do a full circle if starting and ending positions are "identical"
88
   // Do a full circle if starting and ending positions are "identical"
89
   if (NEAR(current_position[p_axis], cart[p_axis]) && NEAR(current_position[q_axis], cart[q_axis])) {
89
   if (NEAR(current_position[p_axis], cart[p_axis]) && NEAR(current_position[q_axis], cart[q_axis])) {
90
     // Preserve direction for circles
90
     // Preserve direction for circles
91
     angular_travel = clockwise ? -RADIANS(360) : RADIANS(360);
91
     angular_travel = clockwise ? -RADIANS(360) : RADIANS(360);
92
+    abs_angular_travel = RADIANS(360);
92
   }
93
   }
93
   else {
94
   else {
94
     // Calculate the angle
95
     // Calculate the angle
103
       case 2: angular_travel += RADIANS(360); break; // Negative but CCW? Reverse direction.
104
       case 2: angular_travel += RADIANS(360); break; // Negative but CCW? Reverse direction.
104
     }
105
     }
105
 
106
 
107
+    abs_angular_travel = ABS(angular_travel);
108
+
106
     #ifdef MIN_ARC_SEGMENTS
109
     #ifdef MIN_ARC_SEGMENTS
107
-      min_segments = CEIL(min_segments * ABS(angular_travel) / RADIANS(360));
110
+      min_segments = CEIL(min_segments * abs_angular_travel / RADIANS(360));
108
       NOLESS(min_segments, 1U);
111
       NOLESS(min_segments, 1U);
109
     #endif
112
     #endif
110
   }
113
   }
117
   #endif
120
   #endif
118
 
121
 
119
   // If circling around...
122
   // If circling around...
120
-  if (ENABLED(ARC_P_CIRCLES) && circles) {
121
-    const float total_angular = angular_travel + circles * RADIANS(360),  // Total rotation with all circles and remainder
123
+  if (TERN0(ARC_P_CIRCLES, circles)) {
124
+    const float total_angular = abs_angular_travel + circles * RADIANS(360),  // Total rotation with all circles and remainder
122
               part_per_circle = RADIANS(360) / total_angular;             // Each circle's part of the total
125
               part_per_circle = RADIANS(360) / total_angular;             // Each circle's part of the total
123
 
126
 
124
     #if HAS_Z_AXIS
127
     #if HAS_Z_AXIS
138
     TERN_(HAS_EXTRUDERS, extruder_travel = cart.e - current_position.e);
141
     TERN_(HAS_EXTRUDERS, extruder_travel = cart.e - current_position.e);
139
   }
142
   }
140
 
143
 
141
-  const float flat_mm = radius * angular_travel,
142
-              mm_of_travel = TERN_(HAS_Z_AXIS, linear_travel ? HYPOT(flat_mm, linear_travel) :) ABS(flat_mm);
144
+  const float flat_mm = radius * abs_angular_travel,
145
+              mm_of_travel = TERN_(HAS_Z_AXIS, linear_travel ? HYPOT(flat_mm, linear_travel) :) flat_mm;
143
   if (mm_of_travel < 0.001f) return;
146
   if (mm_of_travel < 0.001f) return;
144
 
147
 
145
   const feedRate_t scaled_fr_mm_s = MMS_SCALED(feedrate_mm_s);
148
   const feedRate_t scaled_fr_mm_s = MMS_SCALED(feedrate_mm_s);

Loading…
Cancel
Save