|
@@ -54,6 +54,9 @@
|
54
|
54
|
* G10 - Retract filament according to settings of M207
|
55
|
55
|
* G11 - Retract recover filament according to settings of M208
|
56
|
56
|
* G12 - Clean tool
|
|
57
|
+ * G17 - Select Plane XY (Requires CNC_WORKSPACE_PLANES)
|
|
58
|
+ * G18 - Select Plane ZX (Requires CNC_WORKSPACE_PLANES)
|
|
59
|
+ * G19 - Select Plane YZ (Requires CNC_WORKSPACE_PLANES)
|
57
|
60
|
* G20 - Set input units to inches
|
58
|
61
|
* G21 - Set input units to millimeters
|
59
|
62
|
* G26 - Mesh Validation Pattern (Requires UBL_G26_MESH_VALIDATION)
|
|
@@ -73,7 +76,7 @@
|
73
|
76
|
* "M" Codes
|
74
|
77
|
*
|
75
|
78
|
* M0 - Unconditional stop - Wait for user to press a button on the LCD (Only if ULTRA_LCD is enabled)
|
76
|
|
- * M1 - Same as M0
|
|
79
|
+ * M1 -> M0
|
77
|
80
|
* M3 - Turn laser/spindle on, set spindle/laser speed/power, set rotation to clockwise
|
78
|
81
|
* M4 - Turn laser/spindle on, set spindle/laser speed/power, set rotation to counter-clockwise
|
79
|
82
|
* M5 - Turn laser/spindle off
|
|
@@ -630,9 +633,9 @@ float cartes[XYZ] = { 0 };
|
630
|
633
|
bool filament_sensor = false; // M405 turns on filament sensor control. M406 turns it off.
|
631
|
634
|
float filament_width_nominal = DEFAULT_NOMINAL_FILAMENT_DIA, // Nominal filament width. Change with M404.
|
632
|
635
|
filament_width_meas = DEFAULT_MEASURED_FILAMENT_DIA; // Measured filament diameter
|
633
|
|
- int8_t measurement_delay[MAX_MEASUREMENT_DELAY + 1]; // Ring buffer to delayed measurement. Store extruder factor after subtracting 100
|
634
|
|
- int filwidth_delay_index[2] = { 0, -1 }; // Indexes into ring buffer
|
635
|
|
- int meas_delay_cm = MEASUREMENT_DELAY_CM; // Distance delay setting
|
|
636
|
+ uint8_t meas_delay_cm = MEASUREMENT_DELAY_CM, // Distance delay setting
|
|
637
|
+ measurement_delay[MAX_MEASUREMENT_DELAY + 1]; // Ring buffer to delayed measurement. Store extruder factor after subtracting 100
|
|
638
|
+ int8_t filwidth_delay_index[2] = { 0, -1 }; // Indexes into ring buffer
|
636
|
639
|
#endif
|
637
|
640
|
|
638
|
641
|
#if ENABLED(FILAMENT_RUNOUT_SENSOR)
|
|
@@ -688,6 +691,10 @@ static bool send_ok[BUFSIZE];
|
688
|
691
|
millis_t lastUpdateMillis;
|
689
|
692
|
#endif
|
690
|
693
|
|
|
694
|
+#if ENABLED(CNC_WORKSPACE_PLANES)
|
|
695
|
+ static WorkspacePlane workspace_plane = PLANE_XY;
|
|
696
|
+#endif
|
|
697
|
+
|
691
|
698
|
FORCE_INLINE float pgm_read_any(const float *p) { return pgm_read_float_near(p); }
|
692
|
699
|
FORCE_INLINE signed char pgm_read_any(const signed char *p) { return pgm_read_byte_near(p); }
|
693
|
700
|
|
|
@@ -3264,12 +3271,16 @@ inline void gcode_G0_G1(
|
3264
|
3271
|
* X or Y must differ from the current XY.
|
3265
|
3272
|
* Mixing R with I or J will throw an error.
|
3266
|
3273
|
*
|
|
3274
|
+ * - P specifies the number of full circles to do
|
|
3275
|
+ * before the specified arc move.
|
|
3276
|
+ *
|
3267
|
3277
|
* Examples:
|
3268
|
3278
|
*
|
3269
|
3279
|
* G2 I10 ; CW circle centered at X+10
|
3270
|
3280
|
* G3 X20 Y12 R14 ; CCW circle with r=14 ending at X20 Y12
|
3271
|
3281
|
*/
|
3272
|
3282
|
#if ENABLED(ARC_SUPPORT)
|
|
3283
|
+
|
3273
|
3284
|
inline void gcode_G2_G3(bool clockwise) {
|
3274
|
3285
|
if (IsRunning()) {
|
3275
|
3286
|
|
|
@@ -3287,27 +3298,39 @@ inline void gcode_G0_G1(
|
3287
|
3298
|
float arc_offset[2] = { 0.0, 0.0 };
|
3288
|
3299
|
if (parser.seen('R')) {
|
3289
|
3300
|
const float r = parser.value_linear_units(),
|
3290
|
|
- x1 = current_position[X_AXIS], y1 = current_position[Y_AXIS],
|
3291
|
|
- x2 = destination[X_AXIS], y2 = destination[Y_AXIS];
|
3292
|
|
- if (r && (x2 != x1 || y2 != y1)) {
|
|
3301
|
+ p1 = current_position[X_AXIS], q1 = current_position[Y_AXIS],
|
|
3302
|
+ p2 = destination[X_AXIS], q2 = destination[Y_AXIS];
|
|
3303
|
+ if (r && (p2 != p1 || q2 != q1)) {
|
3293
|
3304
|
const float e = clockwise ^ (r < 0) ? -1 : 1, // clockwise -1/1, counterclockwise 1/-1
|
3294
|
|
- dx = x2 - x1, dy = y2 - y1, // X and Y differences
|
|
3305
|
+ dx = p2 - p1, dy = q2 - q1, // X and Y differences
|
3295
|
3306
|
d = HYPOT(dx, dy), // Linear distance between the points
|
3296
|
3307
|
h = SQRT(sq(r) - sq(d * 0.5)), // Distance to the arc pivot-point
|
3297
|
|
- mx = (x1 + x2) * 0.5, my = (y1 + y2) * 0.5, // Point between the two points
|
|
3308
|
+ mx = (p1 + p2) * 0.5, my = (q1 + q2) * 0.5, // Point between the two points
|
3298
|
3309
|
sx = -dy / d, sy = dx / d, // Slope of the perpendicular bisector
|
3299
|
3310
|
cx = mx + e * h * sx, cy = my + e * h * sy; // Pivot-point of the arc
|
3300
|
|
- arc_offset[X_AXIS] = cx - x1;
|
3301
|
|
- arc_offset[Y_AXIS] = cy - y1;
|
|
3311
|
+ arc_offset[0] = cx - p1;
|
|
3312
|
+ arc_offset[1] = cy - q1;
|
3302
|
3313
|
}
|
3303
|
3314
|
}
|
3304
|
3315
|
else {
|
3305
|
|
- if (parser.seen('I')) arc_offset[X_AXIS] = parser.value_linear_units();
|
3306
|
|
- if (parser.seen('J')) arc_offset[Y_AXIS] = parser.value_linear_units();
|
|
3316
|
+ if (parser.seen('I')) arc_offset[0] = parser.value_linear_units();
|
|
3317
|
+ if (parser.seen('J')) arc_offset[1] = parser.value_linear_units();
|
3307
|
3318
|
}
|
3308
|
3319
|
|
3309
|
3320
|
if (arc_offset[0] || arc_offset[1]) {
|
3310
|
|
- // Send an arc to the planner
|
|
3321
|
+
|
|
3322
|
+ #if ENABLED(ARC_P_CIRCLES)
|
|
3323
|
+ // P indicates number of circles to do
|
|
3324
|
+ int8_t circles_to_do = parser.seen('P') ? parser.value_byte() : 0;
|
|
3325
|
+ if (!WITHIN(circles_to_do, 0, 100)) {
|
|
3326
|
+ SERIAL_ERROR_START();
|
|
3327
|
+ SERIAL_ERRORLNPGM(MSG_ERR_ARC_ARGS);
|
|
3328
|
+ }
|
|
3329
|
+ while (circles_to_do--)
|
|
3330
|
+ plan_arc(current_position, arc_offset, clockwise);
|
|
3331
|
+ #endif
|
|
3332
|
+
|
|
3333
|
+ // Send the arc to the planner
|
3311
|
3334
|
plan_arc(destination, arc_offset, clockwise);
|
3312
|
3335
|
refresh_cmd_timeout();
|
3313
|
3336
|
}
|
|
@@ -3318,7 +3341,8 @@ inline void gcode_G0_G1(
|
3318
|
3341
|
}
|
3319
|
3342
|
}
|
3320
|
3343
|
}
|
3321
|
|
-#endif
|
|
3344
|
+
|
|
3345
|
+#endif // ARC_SUPPORT
|
3322
|
3346
|
|
3323
|
3347
|
/**
|
3324
|
3348
|
* G4: Dwell S<seconds> or P<milliseconds>
|
|
@@ -3406,6 +3430,25 @@ inline void gcode_G4() {
|
3406
|
3430
|
}
|
3407
|
3431
|
#endif
|
3408
|
3432
|
|
|
3433
|
+#if ENABLED(CNC_WORKSPACE_PLANES)
|
|
3434
|
+
|
|
3435
|
+ void report_workspace_plane() {
|
|
3436
|
+ SERIAL_ECHO_START();
|
|
3437
|
+ SERIAL_ECHOPGM("Workspace Plane ");
|
|
3438
|
+ serialprintPGM(workspace_plane == PLANE_YZ ? PSTR("YZ\n") : workspace_plane == PLANE_ZX ? PSTR("ZX\n") : PSTR("XY\n"));
|
|
3439
|
+ }
|
|
3440
|
+
|
|
3441
|
+ /**
|
|
3442
|
+ * G17: Select Plane XY
|
|
3443
|
+ * G18: Select Plane ZX
|
|
3444
|
+ * G19: Select Plane YZ
|
|
3445
|
+ */
|
|
3446
|
+ inline void gcode_G17() { workspace_plane = PLANE_XY; }
|
|
3447
|
+ inline void gcode_G18() { workspace_plane = PLANE_ZX; }
|
|
3448
|
+ inline void gcode_G19() { workspace_plane = PLANE_YZ; }
|
|
3449
|
+
|
|
3450
|
+#endif // CNC_WORKSPACE_PLANES
|
|
3451
|
+
|
3409
|
3452
|
#if ENABLED(INCH_MODE_SUPPORT)
|
3410
|
3453
|
/**
|
3411
|
3454
|
* G20: Set input mode to inches
|
|
@@ -3720,6 +3763,10 @@ inline void gcode_G28(const bool always_home_all) {
|
3720
|
3763
|
set_bed_leveling_enabled(false);
|
3721
|
3764
|
#endif
|
3722
|
3765
|
|
|
3766
|
+ #if ENABLED(CNC_WORKSPACE_PLANES)
|
|
3767
|
+ workspace_plane = PLANE_XY;
|
|
3768
|
+ #endif
|
|
3769
|
+
|
3723
|
3770
|
// Always home with tool 0 active
|
3724
|
3771
|
#if HOTENDS > 1
|
3725
|
3772
|
const uint8_t old_tool_index = active_extruder;
|
|
@@ -8898,11 +8945,11 @@ inline void gcode_M400() { stepper.synchronize(); }
|
8898
|
8945
|
inline void gcode_M405() {
|
8899
|
8946
|
// This is technically a linear measurement, but since it's quantized to centimeters and is a different unit than
|
8900
|
8947
|
// everything else, it uses parser.value_int() instead of parser.value_linear_units().
|
8901
|
|
- if (parser.seen('D')) meas_delay_cm = parser.value_int();
|
|
8948
|
+ if (parser.seen('D')) meas_delay_cm = parser.value_byte();
|
8902
|
8949
|
NOMORE(meas_delay_cm, MAX_MEASUREMENT_DELAY);
|
8903
|
8950
|
|
8904
|
8951
|
if (filwidth_delay_index[1] == -1) { // Initialize the ring buffer if not done since startup
|
8905
|
|
- const int temp_ratio = thermalManager.widthFil_to_size_ratio() - 100; // -100 to scale within a signed byte
|
|
8952
|
+ const uint8_t temp_ratio = thermalManager.widthFil_to_size_ratio() - 100; // -100 to scale within a signed byte
|
8906
|
8953
|
|
8907
|
8954
|
for (uint8_t i = 0; i < COUNT(measurement_delay); ++i)
|
8908
|
8955
|
measurement_delay[i] = temp_ratio;
|
|
@@ -10309,6 +10356,18 @@ void process_next_command() {
|
10309
|
10356
|
break;
|
10310
|
10357
|
#endif // NOZZLE_CLEAN_FEATURE
|
10311
|
10358
|
|
|
10359
|
+ #if ENABLED(CNC_WORKSPACE_PLANES)
|
|
10360
|
+ case 17: // G17: Select Plane XY
|
|
10361
|
+ gcode_G17();
|
|
10362
|
+ break;
|
|
10363
|
+ case 18: // G18: Select Plane ZX
|
|
10364
|
+ gcode_G18();
|
|
10365
|
+ break;
|
|
10366
|
+ case 19: // G19: Select Plane YZ
|
|
10367
|
+ gcode_G19();
|
|
10368
|
+ break;
|
|
10369
|
+ #endif // CNC_WORKSPACE_PLANES
|
|
10370
|
+
|
10312
|
10371
|
#if ENABLED(INCH_MODE_SUPPORT)
|
10313
|
10372
|
case 20: //G20: Inch Mode
|
10314
|
10373
|
gcode_G20();
|
|
@@ -11920,6 +11979,12 @@ void prepare_move_to_destination() {
|
11920
|
11979
|
}
|
11921
|
11980
|
|
11922
|
11981
|
#if ENABLED(ARC_SUPPORT)
|
|
11982
|
+
|
|
11983
|
+ #if N_ARC_CORRECTION < 1
|
|
11984
|
+ #undef N_ARC_CORRECTION
|
|
11985
|
+ #define N_ARC_CORRECTION 1
|
|
11986
|
+ #endif
|
|
11987
|
+
|
11923
|
11988
|
/**
|
11924
|
11989
|
* Plan an arc in 2 dimensions
|
11925
|
11990
|
*
|
|
@@ -11934,26 +11999,36 @@ void prepare_move_to_destination() {
|
11934
|
11999
|
float *offset, // Center of rotation relative to current_position
|
11935
|
12000
|
uint8_t clockwise // Clockwise?
|
11936
|
12001
|
) {
|
|
12002
|
+ #if ENABLED(CNC_WORKSPACE_PLANES)
|
|
12003
|
+ AxisEnum p_axis, q_axis, l_axis;
|
|
12004
|
+ switch (workspace_plane) {
|
|
12005
|
+ case PLANE_XY: p_axis = X_AXIS; q_axis = Y_AXIS; l_axis = Z_AXIS; break;
|
|
12006
|
+ case PLANE_ZX: p_axis = Z_AXIS; q_axis = X_AXIS; l_axis = Y_AXIS; break;
|
|
12007
|
+ case PLANE_YZ: p_axis = Y_AXIS; q_axis = Z_AXIS; l_axis = X_AXIS; break;
|
|
12008
|
+ }
|
|
12009
|
+ #else
|
|
12010
|
+ constexpr AxisEnum p_axis = X_AXIS, q_axis = Y_AXIS, l_axis = Z_AXIS;
|
|
12011
|
+ #endif
|
11937
|
12012
|
|
11938
|
|
- float r_X = -offset[X_AXIS], // Radius vector from center to current location
|
11939
|
|
- r_Y = -offset[Y_AXIS];
|
|
12013
|
+ // Radius vector from center to current location
|
|
12014
|
+ float r_P = -offset[0], r_Q = -offset[1];
|
11940
|
12015
|
|
11941
|
|
- const float radius = HYPOT(r_X, r_Y),
|
11942
|
|
- center_X = current_position[X_AXIS] - r_X,
|
11943
|
|
- center_Y = current_position[Y_AXIS] - r_Y,
|
11944
|
|
- rt_X = logical[X_AXIS] - center_X,
|
11945
|
|
- rt_Y = logical[Y_AXIS] - center_Y,
|
11946
|
|
- linear_travel = logical[Z_AXIS] - current_position[Z_AXIS],
|
|
12016
|
+ const float radius = HYPOT(r_P, r_Q),
|
|
12017
|
+ center_P = current_position[p_axis] - r_P,
|
|
12018
|
+ center_Q = current_position[q_axis] - r_Q,
|
|
12019
|
+ rt_X = logical[p_axis] - center_P,
|
|
12020
|
+ rt_Y = logical[q_axis] - center_Q,
|
|
12021
|
+ linear_travel = logical[l_axis] - current_position[l_axis],
|
11947
|
12022
|
extruder_travel = logical[E_AXIS] - current_position[E_AXIS];
|
11948
|
12023
|
|
11949
|
12024
|
// CCW angle of rotation between position and target from the circle center. Only one atan2() trig computation required.
|
11950
|
|
- float angular_travel = ATAN2(r_X * rt_Y - r_Y * rt_X, r_X * rt_X + r_Y * rt_Y);
|
|
12025
|
+ float angular_travel = ATAN2(r_P * rt_Y - r_Q * rt_X, r_P * rt_X + r_Q * rt_Y);
|
11951
|
12026
|
if (angular_travel < 0) angular_travel += RADIANS(360);
|
11952
|
12027
|
if (clockwise) angular_travel -= RADIANS(360);
|
11953
|
12028
|
|
11954
|
|
- // Make a circle if the angular rotation is 0
|
11955
|
|
- if (angular_travel == 0 && current_position[X_AXIS] == logical[X_AXIS] && current_position[Y_AXIS] == logical[Y_AXIS])
|
11956
|
|
- angular_travel += RADIANS(360);
|
|
12029
|
+ // Make a circle if the angular rotation is 0 and the target is current position
|
|
12030
|
+ if (angular_travel == 0 && current_position[p_axis] == logical[p_axis] && current_position[q_axis] == logical[q_axis])
|
|
12031
|
+ angular_travel = RADIANS(360);
|
11957
|
12032
|
|
11958
|
12033
|
const float mm_of_travel = HYPOT(angular_travel * radius, FABS(linear_travel));
|
11959
|
12034
|
if (mm_of_travel < 0.001) return;
|
|
@@ -11996,7 +12071,7 @@ void prepare_move_to_destination() {
|
11996
|
12071
|
cos_T = 1 - 0.5 * sq(theta_per_segment); // Small angle approximation
|
11997
|
12072
|
|
11998
|
12073
|
// Initialize the linear axis
|
11999
|
|
- arc_target[Z_AXIS] = current_position[Z_AXIS];
|
|
12074
|
+ arc_target[l_axis] = current_position[l_axis];
|
12000
|
12075
|
|
12001
|
12076
|
// Initialize the extruder axis
|
12002
|
12077
|
arc_target[E_AXIS] = current_position[E_AXIS];
|
|
@@ -12005,7 +12080,10 @@ void prepare_move_to_destination() {
|
12005
|
12080
|
|
12006
|
12081
|
millis_t next_idle_ms = millis() + 200UL;
|
12007
|
12082
|
|
12008
|
|
- int8_t count = 0;
|
|
12083
|
+ #if N_ARC_CORRECTION > 1
|
|
12084
|
+ int8_t count = N_ARC_CORRECTION;
|
|
12085
|
+ #endif
|
|
12086
|
+
|
12009
|
12087
|
for (uint16_t i = 1; i < segments; i++) { // Iterate (segments-1) times
|
12010
|
12088
|
|
12011
|
12089
|
thermalManager.manage_heater();
|
|
@@ -12014,28 +12092,33 @@ void prepare_move_to_destination() {
|
12014
|
12092
|
idle();
|
12015
|
12093
|
}
|
12016
|
12094
|
|
12017
|
|
- if (++count < N_ARC_CORRECTION) {
|
12018
|
|
- // Apply vector rotation matrix to previous r_X / 1
|
12019
|
|
- const float r_new_Y = r_X * sin_T + r_Y * cos_T;
|
12020
|
|
- r_X = r_X * cos_T - r_Y * sin_T;
|
12021
|
|
- r_Y = r_new_Y;
|
12022
|
|
- }
|
12023
|
|
- else {
|
|
12095
|
+ #if N_ARC_CORRECTION > 1
|
|
12096
|
+ if (--count) {
|
|
12097
|
+ // Apply vector rotation matrix to previous r_P / 1
|
|
12098
|
+ const float r_new_Y = r_P * sin_T + r_Q * cos_T;
|
|
12099
|
+ r_P = r_P * cos_T - r_Q * sin_T;
|
|
12100
|
+ r_Q = r_new_Y;
|
|
12101
|
+ }
|
|
12102
|
+ else
|
|
12103
|
+ #endif
|
|
12104
|
+ {
|
|
12105
|
+ #if N_ARC_CORRECTION > 1
|
|
12106
|
+ count = N_ARC_CORRECTION;
|
|
12107
|
+ #endif
|
|
12108
|
+
|
12024
|
12109
|
// Arc correction to radius vector. Computed only every N_ARC_CORRECTION increments.
|
12025
|
12110
|
// Compute exact location by applying transformation matrix from initial radius vector(=-offset).
|
12026
|
12111
|
// To reduce stuttering, the sin and cos could be computed at different times.
|
12027
|
12112
|
// For now, compute both at the same time.
|
12028
|
|
- const float cos_Ti = cos(i * theta_per_segment),
|
12029
|
|
- sin_Ti = sin(i * theta_per_segment);
|
12030
|
|
- r_X = -offset[X_AXIS] * cos_Ti + offset[Y_AXIS] * sin_Ti;
|
12031
|
|
- r_Y = -offset[X_AXIS] * sin_Ti - offset[Y_AXIS] * cos_Ti;
|
12032
|
|
- count = 0;
|
|
12113
|
+ const float cos_Ti = cos(i * theta_per_segment), sin_Ti = sin(i * theta_per_segment);
|
|
12114
|
+ r_P = -offset[0] * cos_Ti + offset[1] * sin_Ti;
|
|
12115
|
+ r_Q = -offset[0] * sin_Ti - offset[1] * cos_Ti;
|
12033
|
12116
|
}
|
12034
|
12117
|
|
12035
|
12118
|
// Update arc_target location
|
12036
|
|
- arc_target[X_AXIS] = center_X + r_X;
|
12037
|
|
- arc_target[Y_AXIS] = center_Y + r_Y;
|
12038
|
|
- arc_target[Z_AXIS] += linear_per_segment;
|
|
12119
|
+ arc_target[p_axis] = center_P + r_P;
|
|
12120
|
+ arc_target[q_axis] = center_Q + r_Q;
|
|
12121
|
+ arc_target[l_axis] += linear_per_segment;
|
12039
|
12122
|
arc_target[E_AXIS] += extruder_per_segment;
|
12040
|
12123
|
|
12041
|
12124
|
clamp_to_software_endstops(arc_target);
|
|
@@ -12201,7 +12284,7 @@ void prepare_move_to_destination() {
|
12201
|
12284
|
#endif
|
12202
|
12285
|
HOTEND_LOOP()
|
12203
|
12286
|
max_temp = MAX3(max_temp, thermalManager.degHotend(e), thermalManager.degTargetHotend(e));
|
12204
|
|
- bool new_led = (max_temp > 55.0) ? true : (max_temp < 54.0) ? false : red_led;
|
|
12287
|
+ const bool new_led = (max_temp > 55.0) ? true : (max_temp < 54.0) ? false : red_led;
|
12205
|
12288
|
if (new_led != red_led) {
|
12206
|
12289
|
red_led = new_led;
|
12207
|
12290
|
#if PIN_EXISTS(STAT_LED_RED)
|