|
@@ -564,7 +564,7 @@ void stop();
|
564
|
564
|
void get_available_commands();
|
565
|
565
|
void process_next_command();
|
566
|
566
|
void prepare_move_to_destination();
|
567
|
|
-void set_current_from_steppers();
|
|
567
|
+void set_current_from_steppers_for_axis(AxisEnum axis);
|
568
|
568
|
|
569
|
569
|
#if ENABLED(ARC_SUPPORT)
|
570
|
570
|
void plan_arc(float target[NUM_AXIS], float* offset, uint8_t clockwise);
|
|
@@ -1524,8 +1524,7 @@ static void set_axis_is_at_home(AxisEnum axis) {
|
1524
|
1524
|
if (axis == X_AXIS || axis == Y_AXIS) {
|
1525
|
1525
|
|
1526
|
1526
|
float homeposition[3];
|
1527
|
|
- for (uint8_t i = X_AXIS; i <= Z_AXIS; i++)
|
1528
|
|
- homeposition[i] = LOGICAL_POSITION(base_home_pos(i), i);
|
|
1527
|
+ LOOP_XYZ(i) homeposition[i] = LOGICAL_POSITION(base_home_pos(i), i);
|
1529
|
1528
|
|
1530
|
1529
|
// SERIAL_ECHOPGM("homeposition[x]= "); SERIAL_ECHO(homeposition[0]);
|
1531
|
1530
|
// SERIAL_ECHOPGM("homeposition[y]= "); SERIAL_ECHOLN(homeposition[1]);
|
|
@@ -2104,12 +2103,6 @@ static void clean_up_after_endstop_or_probe_move() {
|
2104
|
2103
|
return false;
|
2105
|
2104
|
}
|
2106
|
2105
|
|
2107
|
|
- #if ENABLED(DELTA)
|
2108
|
|
- #define SET_Z_FROM_STEPPERS() set_current_from_steppers()
|
2109
|
|
- #else
|
2110
|
|
- #define SET_Z_FROM_STEPPERS() current_position[Z_AXIS] = LOGICAL_POSITION(stepper.get_axis_position_mm(Z_AXIS), Z_AXIS)
|
2111
|
|
- #endif
|
2112
|
|
-
|
2113
|
2106
|
// Do a single Z probe and return with current_position[Z_AXIS]
|
2114
|
2107
|
// at the height where the probe triggered.
|
2115
|
2108
|
static float run_z_probe() {
|
|
@@ -2121,28 +2114,18 @@ static void clean_up_after_endstop_or_probe_move() {
|
2121
|
2114
|
planner.bed_level_matrix.set_to_identity();
|
2122
|
2115
|
#endif
|
2123
|
2116
|
|
2124
|
|
- #if ENABLED(DELTA)
|
2125
|
|
- float z_before = current_position[Z_AXIS], // Current Z
|
2126
|
|
- z_mm = stepper.get_axis_position_mm(Z_AXIS); // Some tower's current position
|
2127
|
|
- #endif
|
2128
|
|
-
|
2129
|
2117
|
do_blocking_move_to_z(-(Z_MAX_LENGTH + 10), Z_PROBE_SPEED_FAST);
|
2130
|
2118
|
endstops.hit_on_purpose();
|
2131
|
|
- SET_Z_FROM_STEPPERS();
|
|
2119
|
+ set_current_from_steppers_for_axis(Z_AXIS);
|
2132
|
2120
|
SYNC_PLAN_POSITION_KINEMATIC();
|
2133
|
2121
|
|
2134
|
2122
|
// move up the retract distance
|
2135
|
2123
|
do_blocking_move_to_z(current_position[Z_AXIS] + home_bump_mm(Z_AXIS), Z_PROBE_SPEED_FAST);
|
2136
|
2124
|
|
2137
|
|
- #if ENABLED(DELTA)
|
2138
|
|
- z_before = current_position[Z_AXIS];
|
2139
|
|
- z_mm = stepper.get_axis_position_mm(Z_AXIS);
|
2140
|
|
- #endif
|
2141
|
|
-
|
2142
|
2125
|
// move back down slowly to find bed
|
2143
|
2126
|
do_blocking_move_to_z(current_position[Z_AXIS] - home_bump_mm(Z_AXIS) * 2, Z_PROBE_SPEED_SLOW);
|
2144
|
2127
|
endstops.hit_on_purpose();
|
2145
|
|
- SET_Z_FROM_STEPPERS();
|
|
2128
|
+ set_current_from_steppers_for_axis(Z_AXIS);
|
2146
|
2129
|
SYNC_PLAN_POSITION_KINEMATIC();
|
2147
|
2130
|
|
2148
|
2131
|
#if ENABLED(DEBUG_LEVELING_FEATURE)
|
|
@@ -2597,7 +2580,7 @@ static void homeaxis(AxisEnum axis) {
|
2597
|
2580
|
* - Set the feedrate, if included
|
2598
|
2581
|
*/
|
2599
|
2582
|
void gcode_get_destination() {
|
2600
|
|
- for (int i = 0; i < NUM_AXIS; i++) {
|
|
2583
|
+ LOOP_XYZE(i) {
|
2601
|
2584
|
if (code_seen(axis_codes[i]))
|
2602
|
2585
|
destination[i] = code_value_axis_units(i) + (axis_relative_modes[i] || relative_mode ? current_position[i] : 0);
|
2603
|
2586
|
else
|
|
@@ -3900,7 +3883,7 @@ inline void gcode_G92() {
|
3900
|
3883
|
if (!didE) stepper.synchronize();
|
3901
|
3884
|
|
3902
|
3885
|
bool didXYZ = false;
|
3903
|
|
- for (int i = 0; i < NUM_AXIS; i++) {
|
|
3886
|
+ LOOP_XYZE(i) {
|
3904
|
3887
|
if (code_seen(axis_codes[i])) {
|
3905
|
3888
|
float p = current_position[i],
|
3906
|
3889
|
v = code_value_axis_units(i);
|
|
@@ -5147,7 +5130,7 @@ inline void gcode_M85() {
|
5147
|
5130
|
* (Follows the same syntax as G92)
|
5148
|
5131
|
*/
|
5149
|
5132
|
inline void gcode_M92() {
|
5150
|
|
- for (int8_t i = 0; i < NUM_AXIS; i++) {
|
|
5133
|
+ LOOP_XYZE(i) {
|
5151
|
5134
|
if (code_seen(axis_codes[i])) {
|
5152
|
5135
|
if (i == E_AXIS) {
|
5153
|
5136
|
float value = code_value_per_axis_unit(i);
|
|
@@ -5339,7 +5322,7 @@ inline void gcode_M200() {
|
5339
|
5322
|
* M201: Set max acceleration in units/s^2 for print moves (M201 X1000 Y1000)
|
5340
|
5323
|
*/
|
5341
|
5324
|
inline void gcode_M201() {
|
5342
|
|
- for (int8_t i = 0; i < NUM_AXIS; i++) {
|
|
5325
|
+ LOOP_XYZE(i) {
|
5343
|
5326
|
if (code_seen(axis_codes[i])) {
|
5344
|
5327
|
planner.max_acceleration_mm_per_s2[i] = code_value_axis_units(i);
|
5345
|
5328
|
}
|
|
@@ -5350,7 +5333,7 @@ inline void gcode_M201() {
|
5350
|
5333
|
|
5351
|
5334
|
#if 0 // Not used for Sprinter/grbl gen6
|
5352
|
5335
|
inline void gcode_M202() {
|
5353
|
|
- for (int8_t i = 0; i < NUM_AXIS; i++) {
|
|
5336
|
+ LOOP_XYZE(i) {
|
5354
|
5337
|
if (code_seen(axis_codes[i])) axis_travel_steps_per_sqr_second[i] = code_value_axis_units(i) * planner.axis_steps_per_mm[i];
|
5355
|
5338
|
}
|
5356
|
5339
|
}
|
|
@@ -5361,7 +5344,7 @@ inline void gcode_M201() {
|
5361
|
5344
|
* M203: Set maximum feedrate that your machine can sustain (M203 X200 Y200 Z300 E10000) in units/sec
|
5362
|
5345
|
*/
|
5363
|
5346
|
inline void gcode_M203() {
|
5364
|
|
- for (int8_t i = 0; i < NUM_AXIS; i++)
|
|
5347
|
+ LOOP_XYZE(i)
|
5365
|
5348
|
if (code_seen(axis_codes[i]))
|
5366
|
5349
|
planner.max_feedrate_mm_s[i] = code_value_axis_units(i);
|
5367
|
5350
|
}
|
|
@@ -5421,7 +5404,7 @@ inline void gcode_M205() {
|
5421
|
5404
|
* M206: Set Additional Homing Offset (X Y Z). SCARA aliases T=X, P=Y
|
5422
|
5405
|
*/
|
5423
|
5406
|
inline void gcode_M206() {
|
5424
|
|
- for (int8_t i = X_AXIS; i <= Z_AXIS; i++)
|
|
5407
|
+ LOOP_XYZ(i)
|
5425
|
5408
|
if (code_seen(axis_codes[i]))
|
5426
|
5409
|
set_home_offset((AxisEnum)i, code_value_axis_units(i));
|
5427
|
5410
|
|
|
@@ -5463,7 +5446,7 @@ inline void gcode_M206() {
|
5463
|
5446
|
SERIAL_ECHOLNPGM(">>> gcode_M666");
|
5464
|
5447
|
}
|
5465
|
5448
|
#endif
|
5466
|
|
- for (int8_t i = X_AXIS; i <= Z_AXIS; i++) {
|
|
5449
|
+ LOOP_XYZ(i) {
|
5467
|
5450
|
if (code_seen(axis_codes[i])) {
|
5468
|
5451
|
endstop_adj[i] = code_value_axis_units(i);
|
5469
|
5452
|
#if ENABLED(DEBUG_LEVELING_FEATURE)
|
|
@@ -5955,7 +5938,7 @@ inline void gcode_M303() {
|
5955
|
5938
|
* M365: SCARA calibration: Scaling factor, X, Y, Z axis
|
5956
|
5939
|
*/
|
5957
|
5940
|
inline void gcode_M365() {
|
5958
|
|
- for (int8_t i = X_AXIS; i <= Z_AXIS; i++)
|
|
5941
|
+ LOOP_XYZ(i)
|
5959
|
5942
|
if (code_seen(axis_codes[i]))
|
5960
|
5943
|
axis_scaling[i] = code_value_float();
|
5961
|
5944
|
}
|
|
@@ -6091,8 +6074,8 @@ void quickstop_stepper() {
|
6091
|
6074
|
stepper.quick_stop();
|
6092
|
6075
|
#if DISABLED(SCARA)
|
6093
|
6076
|
stepper.synchronize();
|
6094
|
|
- set_current_from_steppers();
|
6095
|
|
- sync_plan_position(); // ...re-apply to planner position
|
|
6077
|
+ LOOP_XYZ(i) set_current_from_steppers_for_axis((AxisEnum)i);
|
|
6078
|
+ SYNC_PLAN_POSITION_KINEMATIC();
|
6096
|
6079
|
#endif
|
6097
|
6080
|
}
|
6098
|
6081
|
|
|
@@ -6155,7 +6138,7 @@ void quickstop_stepper() {
|
6155
|
6138
|
*/
|
6156
|
6139
|
inline void gcode_M428() {
|
6157
|
6140
|
bool err = false;
|
6158
|
|
- for (int8_t i = X_AXIS; i <= Z_AXIS; i++) {
|
|
6141
|
+ LOOP_XYZ(i) {
|
6159
|
6142
|
if (axis_homed[i]) {
|
6160
|
6143
|
float base = (current_position[i] > (sw_endstop_min[i] + sw_endstop_max[i]) / 2) ? base_home_pos(i) : 0,
|
6161
|
6144
|
diff = current_position[i] - LOGICAL_POSITION(base, i);
|
|
@@ -6285,7 +6268,7 @@ inline void gcode_M503() {
|
6285
|
6268
|
float lastpos[NUM_AXIS];
|
6286
|
6269
|
|
6287
|
6270
|
// Save current position of all axes
|
6288
|
|
- for (uint8_t i = 0; i < NUM_AXIS; i++)
|
|
6271
|
+ LOOP_XYZE(i)
|
6289
|
6272
|
lastpos[i] = destination[i] = current_position[i];
|
6290
|
6273
|
|
6291
|
6274
|
// Define runplan for move axes
|
|
@@ -6506,7 +6489,7 @@ inline void gcode_M503() {
|
6506
|
6489
|
*/
|
6507
|
6490
|
inline void gcode_M907() {
|
6508
|
6491
|
#if HAS_DIGIPOTSS
|
6509
|
|
- for (int i = 0; i < NUM_AXIS; i++)
|
|
6492
|
+ LOOP_XYZE(i)
|
6510
|
6493
|
if (code_seen(axis_codes[i])) stepper.digipot_current(i, code_value_int());
|
6511
|
6494
|
if (code_seen('B')) stepper.digipot_current(4, code_value_int());
|
6512
|
6495
|
if (code_seen('S')) for (int i = 0; i <= 4; i++) stepper.digipot_current(i, code_value_int());
|
|
@@ -6522,7 +6505,7 @@ inline void gcode_M907() {
|
6522
|
6505
|
#endif
|
6523
|
6506
|
#if ENABLED(DIGIPOT_I2C)
|
6524
|
6507
|
// this one uses actual amps in floating point
|
6525
|
|
- for (int i = 0; i < NUM_AXIS; i++) if (code_seen(axis_codes[i])) digipot_i2c_set_current(i, code_value_float());
|
|
6508
|
+ LOOP_XYZE(i) if (code_seen(axis_codes[i])) digipot_i2c_set_current(i, code_value_float());
|
6526
|
6509
|
// for each additional extruder (named B,C,D,E..., channels 4,5,6,7...)
|
6527
|
6510
|
for (int i = NUM_AXIS; i < DIGIPOT_I2C_NUM_CHANNELS; i++) if (code_seen('B' + i - (NUM_AXIS))) digipot_i2c_set_current(i, code_value_float());
|
6528
|
6511
|
#endif
|
|
@@ -6531,7 +6514,7 @@ inline void gcode_M907() {
|
6531
|
6514
|
float dac_percent = code_value_float();
|
6532
|
6515
|
for (uint8_t i = 0; i <= 4; i++) dac_current_percent(i, dac_percent);
|
6533
|
6516
|
}
|
6534
|
|
- for (uint8_t i = 0; i < NUM_AXIS; i++) if (code_seen(axis_codes[i])) dac_current_percent(i, code_value_float());
|
|
6517
|
+ LOOP_XYZE(i) if (code_seen(axis_codes[i])) dac_current_percent(i, code_value_float());
|
6535
|
6518
|
#endif
|
6536
|
6519
|
}
|
6537
|
6520
|
|
|
@@ -6570,7 +6553,7 @@ inline void gcode_M907() {
|
6570
|
6553
|
// M350 Set microstepping mode. Warning: Steps per unit remains unchanged. S code sets stepping mode for all drivers.
|
6571
|
6554
|
inline void gcode_M350() {
|
6572
|
6555
|
if (code_seen('S')) for (int i = 0; i <= 4; i++) stepper.microstep_mode(i, code_value_byte());
|
6573
|
|
- for (int i = 0; i < NUM_AXIS; i++) if (code_seen(axis_codes[i])) stepper.microstep_mode(i, code_value_byte());
|
|
6556
|
+ LOOP_XYZE(i) if (code_seen(axis_codes[i])) stepper.microstep_mode(i, code_value_byte());
|
6574
|
6557
|
if (code_seen('B')) stepper.microstep_mode(4, code_value_byte());
|
6575
|
6558
|
stepper.microstep_readings();
|
6576
|
6559
|
}
|
|
@@ -6582,11 +6565,11 @@ inline void gcode_M907() {
|
6582
|
6565
|
inline void gcode_M351() {
|
6583
|
6566
|
if (code_seen('S')) switch (code_value_byte()) {
|
6584
|
6567
|
case 1:
|
6585
|
|
- for (int i = 0; i < NUM_AXIS; i++) if (code_seen(axis_codes[i])) stepper.microstep_ms(i, code_value_byte(), -1);
|
|
6568
|
+ LOOP_XYZE(i) if (code_seen(axis_codes[i])) stepper.microstep_ms(i, code_value_byte(), -1);
|
6586
|
6569
|
if (code_seen('B')) stepper.microstep_ms(4, code_value_byte(), -1);
|
6587
|
6570
|
break;
|
6588
|
6571
|
case 2:
|
6589
|
|
- for (int i = 0; i < NUM_AXIS; i++) if (code_seen(axis_codes[i])) stepper.microstep_ms(i, -1, code_value_byte());
|
|
6572
|
+ LOOP_XYZE(i) if (code_seen(axis_codes[i])) stepper.microstep_ms(i, -1, code_value_byte());
|
6590
|
6573
|
if (code_seen('B')) stepper.microstep_ms(4, -1, code_value_byte());
|
6591
|
6574
|
break;
|
6592
|
6575
|
}
|
|
@@ -7929,25 +7912,16 @@ void clamp_to_software_endstops(float target[3]) {
|
7929
|
7912
|
|
7930
|
7913
|
#endif // DELTA
|
7931
|
7914
|
|
7932
|
|
-void set_current_from_steppers() {
|
|
7915
|
+void set_current_from_steppers_for_axis(AxisEnum axis) {
|
7933
|
7916
|
#if ENABLED(DELTA)
|
7934
|
7917
|
set_cartesian_from_steppers();
|
7935
|
|
- current_position[X_AXIS] = cartesian_position[X_AXIS];
|
7936
|
|
- current_position[Y_AXIS] = cartesian_position[Y_AXIS];
|
7937
|
|
- current_position[Z_AXIS] = cartesian_position[Z_AXIS];
|
|
7918
|
+ current_position[axis] = LOGICAL_POSITION(cartesian_position[axis], axis);
|
7938
|
7919
|
#elif ENABLED(AUTO_BED_LEVELING_FEATURE)
|
7939
|
|
- vector_3 pos = planner.adjusted_position(); // values directly from steppers...
|
7940
|
|
- current_position[X_AXIS] = pos.x;
|
7941
|
|
- current_position[Y_AXIS] = pos.y;
|
7942
|
|
- current_position[Z_AXIS] = pos.z;
|
|
7920
|
+ vector_3 pos = planner.adjusted_position();
|
|
7921
|
+ current_position[axis] = LOGICAL_POSITION(axis == X_AXIS ? pos.x : axis == Y_AXIS ? pos.y : pos.z, axis);
|
7943
|
7922
|
#else
|
7944
|
|
- current_position[X_AXIS] = stepper.get_axis_position_mm(X_AXIS); // CORE handled transparently
|
7945
|
|
- current_position[Y_AXIS] = stepper.get_axis_position_mm(Y_AXIS);
|
7946
|
|
- current_position[Z_AXIS] = stepper.get_axis_position_mm(Z_AXIS);
|
|
7923
|
+ current_position[axis] = LOGICAL_POSITION(stepper.get_axis_position_mm(axis), axis); // CORE handled transparently
|
7947
|
7924
|
#endif
|
7948
|
|
-
|
7949
|
|
- for (uint8_t i = X_AXIS; i <= Z_AXIS; i++)
|
7950
|
|
- current_position[i] += LOGICAL_POSITION(0, i);
|
7951
|
7925
|
}
|
7952
|
7926
|
|
7953
|
7927
|
#if ENABLED(MESH_BED_LEVELING)
|
|
@@ -8013,7 +7987,7 @@ void mesh_line_to_destination(float fr_mm_m, uint8_t x_splits = 0xff, uint8_t y_
|
8013
|
7987
|
|
8014
|
7988
|
inline bool prepare_kinematic_move_to(float target[NUM_AXIS]) {
|
8015
|
7989
|
float difference[NUM_AXIS];
|
8016
|
|
- for (int8_t i = 0; i < NUM_AXIS; i++) difference[i] = target[i] - current_position[i];
|
|
7990
|
+ LOOP_XYZE(i) difference[i] = target[i] - current_position[i];
|
8017
|
7991
|
|
8018
|
7992
|
float cartesian_mm = sqrt(sq(difference[X_AXIS]) + sq(difference[Y_AXIS]) + sq(difference[Z_AXIS]));
|
8019
|
7993
|
if (cartesian_mm < 0.000001) cartesian_mm = abs(difference[E_AXIS]);
|
|
@@ -8031,7 +8005,7 @@ void mesh_line_to_destination(float fr_mm_m, uint8_t x_splits = 0xff, uint8_t y_
|
8031
|
8005
|
|
8032
|
8006
|
float fraction = float(s) * inv_steps;
|
8033
|
8007
|
|
8034
|
|
- for (int8_t i = 0; i < NUM_AXIS; i++)
|
|
8008
|
+ LOOP_XYZE(i)
|
8035
|
8009
|
target[i] = current_position[i] + difference[i] * fraction;
|
8036
|
8010
|
|
8037
|
8011
|
inverse_kinematics(target);
|