|
@@ -506,7 +506,9 @@ void stop();
|
506
|
506
|
void get_available_commands();
|
507
|
507
|
void process_next_command();
|
508
|
508
|
|
509
|
|
-void plan_arc(float target[NUM_AXIS], float* offset, uint8_t clockwise);
|
|
509
|
+#if ENABLED(ARC_SUPPORT)
|
|
510
|
+ void plan_arc(float target[NUM_AXIS], float* offset, uint8_t clockwise);
|
|
511
|
+#endif
|
510
|
512
|
|
511
|
513
|
void serial_echopair_P(const char* s_P, int v) { serialprintPGM(s_P); SERIAL_ECHO(v); }
|
512
|
514
|
void serial_echopair_P(const char* s_P, long v) { serialprintPGM(s_P); SERIAL_ECHO(v); }
|
|
@@ -2461,32 +2463,34 @@ inline void gcode_G0_G1() {
|
2461
|
2463
|
* G2: Clockwise Arc
|
2462
|
2464
|
* G3: Counterclockwise Arc
|
2463
|
2465
|
*/
|
2464
|
|
-inline void gcode_G2_G3(bool clockwise) {
|
2465
|
|
- if (IsRunning()) {
|
|
2466
|
+#if ENABLED(ARC_SUPPORT)
|
|
2467
|
+ inline void gcode_G2_G3(bool clockwise) {
|
|
2468
|
+ if (IsRunning()) {
|
2466
|
2469
|
|
2467
|
|
- #if ENABLED(SF_ARC_FIX)
|
2468
|
|
- bool relative_mode_backup = relative_mode;
|
2469
|
|
- relative_mode = true;
|
2470
|
|
- #endif
|
|
2470
|
+ #if ENABLED(SF_ARC_FIX)
|
|
2471
|
+ bool relative_mode_backup = relative_mode;
|
|
2472
|
+ relative_mode = true;
|
|
2473
|
+ #endif
|
2471
|
2474
|
|
2472
|
|
- gcode_get_destination();
|
|
2475
|
+ gcode_get_destination();
|
2473
|
2476
|
|
2474
|
|
- #if ENABLED(SF_ARC_FIX)
|
2475
|
|
- relative_mode = relative_mode_backup;
|
2476
|
|
- #endif
|
|
2477
|
+ #if ENABLED(SF_ARC_FIX)
|
|
2478
|
+ relative_mode = relative_mode_backup;
|
|
2479
|
+ #endif
|
2477
|
2480
|
|
2478
|
|
- // Center of arc as offset from current_position
|
2479
|
|
- float arc_offset[2] = {
|
2480
|
|
- code_seen('I') ? code_value() : 0,
|
2481
|
|
- code_seen('J') ? code_value() : 0
|
2482
|
|
- };
|
|
2481
|
+ // Center of arc as offset from current_position
|
|
2482
|
+ float arc_offset[2] = {
|
|
2483
|
+ code_seen('I') ? code_value() : 0,
|
|
2484
|
+ code_seen('J') ? code_value() : 0
|
|
2485
|
+ };
|
2483
|
2486
|
|
2484
|
|
- // Send an arc to the planner
|
2485
|
|
- plan_arc(destination, arc_offset, clockwise);
|
|
2487
|
+ // Send an arc to the planner
|
|
2488
|
+ plan_arc(destination, arc_offset, clockwise);
|
2486
|
2489
|
|
2487
|
|
- refresh_cmd_timeout();
|
|
2490
|
+ refresh_cmd_timeout();
|
|
2491
|
+ }
|
2488
|
2492
|
}
|
2489
|
|
-}
|
|
2493
|
+#endif
|
2490
|
2494
|
|
2491
|
2495
|
/**
|
2492
|
2496
|
* G4: Dwell S<seconds> or P<milliseconds>
|
|
@@ -6484,7 +6488,7 @@ void process_next_command() {
|
6484
|
6488
|
break;
|
6485
|
6489
|
|
6486
|
6490
|
// G2, G3
|
6487
|
|
- #if DISABLED(SCARA)
|
|
6491
|
+ #if ENABLED(ARC_SUPPORT) & DISABLED(SCARA)
|
6488
|
6492
|
case 2: // G2 - CW ARC
|
6489
|
6493
|
case 3: // G3 - CCW ARC
|
6490
|
6494
|
gcode_G2_G3(codenum == 2);
|
|
@@ -7423,147 +7427,149 @@ void prepare_move() {
|
7423
|
7427
|
set_current_to_destination();
|
7424
|
7428
|
}
|
7425
|
7429
|
|
7426
|
|
-/**
|
7427
|
|
- * Plan an arc in 2 dimensions
|
7428
|
|
- *
|
7429
|
|
- * The arc is approximated by generating many small linear segments.
|
7430
|
|
- * The length of each segment is configured in MM_PER_ARC_SEGMENT (Default 1mm)
|
7431
|
|
- * Arcs should only be made relatively large (over 5mm), as larger arcs with
|
7432
|
|
- * larger segments will tend to be more efficient. Your slicer should have
|
7433
|
|
- * options for G2/G3 arc generation. In future these options may be GCode tunable.
|
7434
|
|
- */
|
7435
|
|
-void plan_arc(
|
7436
|
|
- float target[NUM_AXIS], // Destination position
|
7437
|
|
- float* offset, // Center of rotation relative to current_position
|
7438
|
|
- uint8_t clockwise // Clockwise?
|
7439
|
|
-) {
|
7440
|
|
-
|
7441
|
|
- float radius = hypot(offset[X_AXIS], offset[Y_AXIS]),
|
7442
|
|
- center_X = current_position[X_AXIS] + offset[X_AXIS],
|
7443
|
|
- center_Y = current_position[Y_AXIS] + offset[Y_AXIS],
|
7444
|
|
- linear_travel = target[Z_AXIS] - current_position[Z_AXIS],
|
7445
|
|
- extruder_travel = target[E_AXIS] - current_position[E_AXIS],
|
7446
|
|
- r_X = -offset[X_AXIS], // Radius vector from center to current location
|
7447
|
|
- r_Y = -offset[Y_AXIS],
|
7448
|
|
- rt_X = target[X_AXIS] - center_X,
|
7449
|
|
- rt_Y = target[Y_AXIS] - center_Y;
|
7450
|
|
-
|
7451
|
|
- // CCW angle of rotation between position and target from the circle center. Only one atan2() trig computation required.
|
7452
|
|
- float angular_travel = atan2(r_X * rt_Y - r_Y * rt_X, r_X * rt_X + r_Y * rt_Y);
|
7453
|
|
- if (angular_travel < 0) angular_travel += RADIANS(360);
|
7454
|
|
- if (clockwise) angular_travel -= RADIANS(360);
|
7455
|
|
-
|
7456
|
|
- // Make a circle if the angular rotation is 0
|
7457
|
|
- if (angular_travel == 0 && current_position[X_AXIS] == target[X_AXIS] && current_position[Y_AXIS] == target[Y_AXIS])
|
7458
|
|
- angular_travel += RADIANS(360);
|
7459
|
|
-
|
7460
|
|
- float mm_of_travel = hypot(angular_travel * radius, fabs(linear_travel));
|
7461
|
|
- if (mm_of_travel < 0.001) return;
|
7462
|
|
- uint16_t segments = floor(mm_of_travel / (MM_PER_ARC_SEGMENT));
|
7463
|
|
- if (segments == 0) segments = 1;
|
7464
|
|
-
|
7465
|
|
- float theta_per_segment = angular_travel / segments;
|
7466
|
|
- float linear_per_segment = linear_travel / segments;
|
7467
|
|
- float extruder_per_segment = extruder_travel / segments;
|
7468
|
|
-
|
|
7430
|
+#if ENABLED(ARC_SUPPORT)
|
7469
|
7431
|
/**
|
7470
|
|
- * Vector rotation by transformation matrix: r is the original vector, r_T is the rotated vector,
|
7471
|
|
- * and phi is the angle of rotation. Based on the solution approach by Jens Geisler.
|
7472
|
|
- * r_T = [cos(phi) -sin(phi);
|
7473
|
|
- * sin(phi) cos(phi] * r ;
|
7474
|
|
- *
|
7475
|
|
- * For arc generation, the center of the circle is the axis of rotation and the radius vector is
|
7476
|
|
- * defined from the circle center to the initial position. Each line segment is formed by successive
|
7477
|
|
- * vector rotations. This requires only two cos() and sin() computations to form the rotation
|
7478
|
|
- * matrix for the duration of the entire arc. Error may accumulate from numerical round-off, since
|
7479
|
|
- * all double numbers are single precision on the Arduino. (True double precision will not have
|
7480
|
|
- * round off issues for CNC applications.) Single precision error can accumulate to be greater than
|
7481
|
|
- * tool precision in some cases. Therefore, arc path correction is implemented.
|
|
7432
|
+ * Plan an arc in 2 dimensions
|
7482
|
7433
|
*
|
7483
|
|
- * Small angle approximation may be used to reduce computation overhead further. This approximation
|
7484
|
|
- * holds for everything, but very small circles and large MM_PER_ARC_SEGMENT values. In other words,
|
7485
|
|
- * theta_per_segment would need to be greater than 0.1 rad and N_ARC_CORRECTION would need to be large
|
7486
|
|
- * to cause an appreciable drift error. N_ARC_CORRECTION~=25 is more than small enough to correct for
|
7487
|
|
- * numerical drift error. N_ARC_CORRECTION may be on the order a hundred(s) before error becomes an
|
7488
|
|
- * issue for CNC machines with the single precision Arduino calculations.
|
7489
|
|
- *
|
7490
|
|
- * This approximation also allows plan_arc to immediately insert a line segment into the planner
|
7491
|
|
- * without the initial overhead of computing cos() or sin(). By the time the arc needs to be applied
|
7492
|
|
- * a correction, the planner should have caught up to the lag caused by the initial plan_arc overhead.
|
7493
|
|
- * This is important when there are successive arc motions.
|
|
7434
|
+ * The arc is approximated by generating many small linear segments.
|
|
7435
|
+ * The length of each segment is configured in MM_PER_ARC_SEGMENT (Default 1mm)
|
|
7436
|
+ * Arcs should only be made relatively large (over 5mm), as larger arcs with
|
|
7437
|
+ * larger segments will tend to be more efficient. Your slicer should have
|
|
7438
|
+ * options for G2/G3 arc generation. In future these options may be GCode tunable.
|
7494
|
7439
|
*/
|
7495
|
|
- // Vector rotation matrix values
|
7496
|
|
- float cos_T = 1 - 0.5 * theta_per_segment * theta_per_segment; // Small angle approximation
|
7497
|
|
- float sin_T = theta_per_segment;
|
|
7440
|
+ void plan_arc(
|
|
7441
|
+ float target[NUM_AXIS], // Destination position
|
|
7442
|
+ float* offset, // Center of rotation relative to current_position
|
|
7443
|
+ uint8_t clockwise // Clockwise?
|
|
7444
|
+ ) {
|
|
7445
|
+
|
|
7446
|
+ float radius = hypot(offset[X_AXIS], offset[Y_AXIS]),
|
|
7447
|
+ center_X = current_position[X_AXIS] + offset[X_AXIS],
|
|
7448
|
+ center_Y = current_position[Y_AXIS] + offset[Y_AXIS],
|
|
7449
|
+ linear_travel = target[Z_AXIS] - current_position[Z_AXIS],
|
|
7450
|
+ extruder_travel = target[E_AXIS] - current_position[E_AXIS],
|
|
7451
|
+ r_X = -offset[X_AXIS], // Radius vector from center to current location
|
|
7452
|
+ r_Y = -offset[Y_AXIS],
|
|
7453
|
+ rt_X = target[X_AXIS] - center_X,
|
|
7454
|
+ rt_Y = target[Y_AXIS] - center_Y;
|
|
7455
|
+
|
|
7456
|
+ // CCW angle of rotation between position and target from the circle center. Only one atan2() trig computation required.
|
|
7457
|
+ float angular_travel = atan2(r_X * rt_Y - r_Y * rt_X, r_X * rt_X + r_Y * rt_Y);
|
|
7458
|
+ if (angular_travel < 0) angular_travel += RADIANS(360);
|
|
7459
|
+ if (clockwise) angular_travel -= RADIANS(360);
|
|
7460
|
+
|
|
7461
|
+ // Make a circle if the angular rotation is 0
|
|
7462
|
+ if (angular_travel == 0 && current_position[X_AXIS] == target[X_AXIS] && current_position[Y_AXIS] == target[Y_AXIS])
|
|
7463
|
+ angular_travel += RADIANS(360);
|
|
7464
|
+
|
|
7465
|
+ float mm_of_travel = hypot(angular_travel * radius, fabs(linear_travel));
|
|
7466
|
+ if (mm_of_travel < 0.001) return;
|
|
7467
|
+ uint16_t segments = floor(mm_of_travel / (MM_PER_ARC_SEGMENT));
|
|
7468
|
+ if (segments == 0) segments = 1;
|
|
7469
|
+
|
|
7470
|
+ float theta_per_segment = angular_travel / segments;
|
|
7471
|
+ float linear_per_segment = linear_travel / segments;
|
|
7472
|
+ float extruder_per_segment = extruder_travel / segments;
|
|
7473
|
+
|
|
7474
|
+ /**
|
|
7475
|
+ * Vector rotation by transformation matrix: r is the original vector, r_T is the rotated vector,
|
|
7476
|
+ * and phi is the angle of rotation. Based on the solution approach by Jens Geisler.
|
|
7477
|
+ * r_T = [cos(phi) -sin(phi);
|
|
7478
|
+ * sin(phi) cos(phi] * r ;
|
|
7479
|
+ *
|
|
7480
|
+ * For arc generation, the center of the circle is the axis of rotation and the radius vector is
|
|
7481
|
+ * defined from the circle center to the initial position. Each line segment is formed by successive
|
|
7482
|
+ * vector rotations. This requires only two cos() and sin() computations to form the rotation
|
|
7483
|
+ * matrix for the duration of the entire arc. Error may accumulate from numerical round-off, since
|
|
7484
|
+ * all double numbers are single precision on the Arduino. (True double precision will not have
|
|
7485
|
+ * round off issues for CNC applications.) Single precision error can accumulate to be greater than
|
|
7486
|
+ * tool precision in some cases. Therefore, arc path correction is implemented.
|
|
7487
|
+ *
|
|
7488
|
+ * Small angle approximation may be used to reduce computation overhead further. This approximation
|
|
7489
|
+ * holds for everything, but very small circles and large MM_PER_ARC_SEGMENT values. In other words,
|
|
7490
|
+ * theta_per_segment would need to be greater than 0.1 rad and N_ARC_CORRECTION would need to be large
|
|
7491
|
+ * to cause an appreciable drift error. N_ARC_CORRECTION~=25 is more than small enough to correct for
|
|
7492
|
+ * numerical drift error. N_ARC_CORRECTION may be on the order a hundred(s) before error becomes an
|
|
7493
|
+ * issue for CNC machines with the single precision Arduino calculations.
|
|
7494
|
+ *
|
|
7495
|
+ * This approximation also allows plan_arc to immediately insert a line segment into the planner
|
|
7496
|
+ * without the initial overhead of computing cos() or sin(). By the time the arc needs to be applied
|
|
7497
|
+ * a correction, the planner should have caught up to the lag caused by the initial plan_arc overhead.
|
|
7498
|
+ * This is important when there are successive arc motions.
|
|
7499
|
+ */
|
|
7500
|
+ // Vector rotation matrix values
|
|
7501
|
+ float cos_T = 1 - 0.5 * theta_per_segment * theta_per_segment; // Small angle approximation
|
|
7502
|
+ float sin_T = theta_per_segment;
|
7498
|
7503
|
|
7499
|
|
- float arc_target[NUM_AXIS];
|
7500
|
|
- float sin_Ti, cos_Ti, r_new_Y;
|
7501
|
|
- uint16_t i;
|
7502
|
|
- int8_t count = 0;
|
|
7504
|
+ float arc_target[NUM_AXIS];
|
|
7505
|
+ float sin_Ti, cos_Ti, r_new_Y;
|
|
7506
|
+ uint16_t i;
|
|
7507
|
+ int8_t count = 0;
|
7503
|
7508
|
|
7504
|
|
- // Initialize the linear axis
|
7505
|
|
- arc_target[Z_AXIS] = current_position[Z_AXIS];
|
|
7509
|
+ // Initialize the linear axis
|
|
7510
|
+ arc_target[Z_AXIS] = current_position[Z_AXIS];
|
7506
|
7511
|
|
7507
|
|
- // Initialize the extruder axis
|
7508
|
|
- arc_target[E_AXIS] = current_position[E_AXIS];
|
|
7512
|
+ // Initialize the extruder axis
|
|
7513
|
+ arc_target[E_AXIS] = current_position[E_AXIS];
|
7509
|
7514
|
|
7510
|
|
- float feed_rate = feedrate * feedrate_multiplier / 60 / 100.0;
|
|
7515
|
+ float feed_rate = feedrate * feedrate_multiplier / 60 / 100.0;
|
7511
|
7516
|
|
7512
|
|
- for (i = 1; i < segments; i++) { // Iterate (segments-1) times
|
|
7517
|
+ for (i = 1; i < segments; i++) { // Iterate (segments-1) times
|
7513
|
7518
|
|
7514
|
|
- if (++count < N_ARC_CORRECTION) {
|
7515
|
|
- // Apply vector rotation matrix to previous r_X / 1
|
7516
|
|
- r_new_Y = r_X * sin_T + r_Y * cos_T;
|
7517
|
|
- r_X = r_X * cos_T - r_Y * sin_T;
|
7518
|
|
- r_Y = r_new_Y;
|
7519
|
|
- }
|
7520
|
|
- else {
|
7521
|
|
- // Arc correction to radius vector. Computed only every N_ARC_CORRECTION increments.
|
7522
|
|
- // Compute exact location by applying transformation matrix from initial radius vector(=-offset).
|
7523
|
|
- // To reduce stuttering, the sin and cos could be computed at different times.
|
7524
|
|
- // For now, compute both at the same time.
|
7525
|
|
- cos_Ti = cos(i * theta_per_segment);
|
7526
|
|
- sin_Ti = sin(i * theta_per_segment);
|
7527
|
|
- r_X = -offset[X_AXIS] * cos_Ti + offset[Y_AXIS] * sin_Ti;
|
7528
|
|
- r_Y = -offset[X_AXIS] * sin_Ti - offset[Y_AXIS] * cos_Ti;
|
7529
|
|
- count = 0;
|
7530
|
|
- }
|
|
7519
|
+ if (++count < N_ARC_CORRECTION) {
|
|
7520
|
+ // Apply vector rotation matrix to previous r_X / 1
|
|
7521
|
+ r_new_Y = r_X * sin_T + r_Y * cos_T;
|
|
7522
|
+ r_X = r_X * cos_T - r_Y * sin_T;
|
|
7523
|
+ r_Y = r_new_Y;
|
|
7524
|
+ }
|
|
7525
|
+ else {
|
|
7526
|
+ // Arc correction to radius vector. Computed only every N_ARC_CORRECTION increments.
|
|
7527
|
+ // Compute exact location by applying transformation matrix from initial radius vector(=-offset).
|
|
7528
|
+ // To reduce stuttering, the sin and cos could be computed at different times.
|
|
7529
|
+ // For now, compute both at the same time.
|
|
7530
|
+ cos_Ti = cos(i * theta_per_segment);
|
|
7531
|
+ sin_Ti = sin(i * theta_per_segment);
|
|
7532
|
+ r_X = -offset[X_AXIS] * cos_Ti + offset[Y_AXIS] * sin_Ti;
|
|
7533
|
+ r_Y = -offset[X_AXIS] * sin_Ti - offset[Y_AXIS] * cos_Ti;
|
|
7534
|
+ count = 0;
|
|
7535
|
+ }
|
7531
|
7536
|
|
7532
|
|
- // Update arc_target location
|
7533
|
|
- arc_target[X_AXIS] = center_X + r_X;
|
7534
|
|
- arc_target[Y_AXIS] = center_Y + r_Y;
|
7535
|
|
- arc_target[Z_AXIS] += linear_per_segment;
|
7536
|
|
- arc_target[E_AXIS] += extruder_per_segment;
|
|
7537
|
+ // Update arc_target location
|
|
7538
|
+ arc_target[X_AXIS] = center_X + r_X;
|
|
7539
|
+ arc_target[Y_AXIS] = center_Y + r_Y;
|
|
7540
|
+ arc_target[Z_AXIS] += linear_per_segment;
|
|
7541
|
+ arc_target[E_AXIS] += extruder_per_segment;
|
7537
|
7542
|
|
7538
|
|
- clamp_to_software_endstops(arc_target);
|
|
7543
|
+ clamp_to_software_endstops(arc_target);
|
|
7544
|
+
|
|
7545
|
+ #if ENABLED(DELTA) || ENABLED(SCARA)
|
|
7546
|
+ calculate_delta(arc_target);
|
|
7547
|
+ #if ENABLED(AUTO_BED_LEVELING_FEATURE)
|
|
7548
|
+ adjust_delta(arc_target);
|
|
7549
|
+ #endif
|
|
7550
|
+ planner.buffer_line(delta[X_AXIS], delta[Y_AXIS], delta[Z_AXIS], arc_target[E_AXIS], feed_rate, active_extruder);
|
|
7551
|
+ #else
|
|
7552
|
+ planner.buffer_line(arc_target[X_AXIS], arc_target[Y_AXIS], arc_target[Z_AXIS], arc_target[E_AXIS], feed_rate, active_extruder);
|
|
7553
|
+ #endif
|
|
7554
|
+ }
|
7539
|
7555
|
|
|
7556
|
+ // Ensure last segment arrives at target location.
|
7540
|
7557
|
#if ENABLED(DELTA) || ENABLED(SCARA)
|
7541
|
|
- calculate_delta(arc_target);
|
|
7558
|
+ calculate_delta(target);
|
7542
|
7559
|
#if ENABLED(AUTO_BED_LEVELING_FEATURE)
|
7543
|
|
- adjust_delta(arc_target);
|
|
7560
|
+ adjust_delta(target);
|
7544
|
7561
|
#endif
|
7545
|
|
- planner.buffer_line(delta[X_AXIS], delta[Y_AXIS], delta[Z_AXIS], arc_target[E_AXIS], feed_rate, active_extruder);
|
|
7562
|
+ planner.buffer_line(delta[X_AXIS], delta[Y_AXIS], delta[Z_AXIS], target[E_AXIS], feed_rate, active_extruder);
|
7546
|
7563
|
#else
|
7547
|
|
- planner.buffer_line(arc_target[X_AXIS], arc_target[Y_AXIS], arc_target[Z_AXIS], arc_target[E_AXIS], feed_rate, active_extruder);
|
|
7564
|
+ planner.buffer_line(target[X_AXIS], target[Y_AXIS], target[Z_AXIS], target[E_AXIS], feed_rate, active_extruder);
|
7548
|
7565
|
#endif
|
7549
|
|
- }
|
7550
|
7566
|
|
7551
|
|
- // Ensure last segment arrives at target location.
|
7552
|
|
- #if ENABLED(DELTA) || ENABLED(SCARA)
|
7553
|
|
- calculate_delta(target);
|
7554
|
|
- #if ENABLED(AUTO_BED_LEVELING_FEATURE)
|
7555
|
|
- adjust_delta(target);
|
7556
|
|
- #endif
|
7557
|
|
- planner.buffer_line(delta[X_AXIS], delta[Y_AXIS], delta[Z_AXIS], target[E_AXIS], feed_rate, active_extruder);
|
7558
|
|
- #else
|
7559
|
|
- planner.buffer_line(target[X_AXIS], target[Y_AXIS], target[Z_AXIS], target[E_AXIS], feed_rate, active_extruder);
|
7560
|
|
- #endif
|
7561
|
|
-
|
7562
|
|
- // As far as the parser is concerned, the position is now == target. In reality the
|
7563
|
|
- // motion control system might still be processing the action and the real tool position
|
7564
|
|
- // in any intermediate location.
|
7565
|
|
- set_current_to_destination();
|
7566
|
|
-}
|
|
7567
|
+ // As far as the parser is concerned, the position is now == target. In reality the
|
|
7568
|
+ // motion control system might still be processing the action and the real tool position
|
|
7569
|
+ // in any intermediate location.
|
|
7570
|
+ set_current_to_destination();
|
|
7571
|
+ }
|
|
7572
|
+#endif
|
7567
|
7573
|
|
7568
|
7574
|
#if HAS_CONTROLLERFAN
|
7569
|
7575
|
|