diff --git a/Marlin/src/MarlinCore.cpp b/Marlin/src/MarlinCore.cpp index 5897ee7274..2eca094371 100644 --- a/Marlin/src/MarlinCore.cpp +++ b/Marlin/src/MarlinCore.cpp @@ -374,7 +374,7 @@ void Marlin::startOrResumeJob() { if (!printingIsPaused()) { TERN_(GCODE_REPEAT_MARKERS, repeat.reset()); TERN_(CANCEL_OBJECTS, cancelable.reset()); - TERN_(LCD_SHOW_E_TOTAL, e_move_accumulator = 0); + TERN_(LCD_SHOW_E_TOTAL, motion.e_move_accumulator = 0); TERN_(SET_REMAINING_TIME, ui.reset_remaining_time()); TERN_(HAS_PRUSA_MMU3, MMU3::operation_statistics.reset_per_print_stats()); } @@ -388,7 +388,7 @@ void Marlin::startOrResumeJob() { card.abortFilePrintNow(TERN_(SD_RESORT, true)); queue.clear(); - quickstop_stepper(); + motion.quickstop_stepper(); print_job_timer.abort(); @@ -709,18 +709,18 @@ void Marlin::manage_inactivity(const bool no_stepper_sleep/*=false*/) { #endif #if ENABLED(EXTRUDER_RUNOUT_PREVENT) - if (thermalManager.degHotend(active_extruder) > (EXTRUDER_RUNOUT_MINTEMP) + if (thermalManager.degHotend(motion.extruder) > (EXTRUDER_RUNOUT_MINTEMP) && ELAPSED(ms, gcode.previous_move_ms, SEC_TO_MS(EXTRUDER_RUNOUT_SECONDS)) && !planner.has_blocks_queued() ) { - const int8_t e_stepper = TERN(HAS_SWITCHING_EXTRUDER, active_extruder >> 1, active_extruder); + const int8_t e_stepper = TERN(HAS_SWITCHING_EXTRUDER, motion.extruder / 2, motion.extruder); const bool e_off = !stepper.AXIS_IS_ENABLED(E_AXIS, e_stepper); if (e_off) stepper.ENABLE_EXTRUDER(e_stepper); - const float olde = current_position.e; - current_position.e += EXTRUDER_RUNOUT_EXTRUDE; - line_to_current_position(MMM_TO_MMS(EXTRUDER_RUNOUT_SPEED)); - current_position.e = olde; + const float olde = motion.position.e; + motion.position.e += EXTRUDER_RUNOUT_EXTRUDE; + motion.goto_current_position(MMM_TO_MMS(EXTRUDER_RUNOUT_SPEED)); + motion.position.e = olde; planner.set_e_position_mm(olde); planner.synchronize(); @@ -735,8 +735,8 @@ void Marlin::manage_inactivity(const bool no_stepper_sleep/*=false*/) { if (delayed_move_time && ELAPSED(ms, delayed_move_time) && isRunning()) { // travel moves have been received so enact them delayed_move_time = UINT32_MAX; // force moves to be done - destination = current_position; - prepare_line_to_destination(); + motion.destination = motion.position; + motion.prepare_line_to_destination(); planner.synchronize(); } #endif @@ -816,7 +816,7 @@ void Marlin::idle(const bool no_stepper_sleep/*=false*/) { if (is(MF_INITIALIZING)) goto IDLE_DONE; // TODO: Still causing errors - TERN_(TOOL_SENSOR, (void)check_tool_sensor_stats(active_extruder, true)); + TERN_(TOOL_SENSOR, (void)check_tool_sensor_stats(motion.extruder, true)); // Handle filament runout sensors #if HAS_FILAMENT_SENSOR @@ -891,7 +891,7 @@ void Marlin::idle(const bool no_stepper_sleep/*=false*/) { TERN_(AUTO_REPORT_TEMPERATURES, thermalManager.auto_reporter.tick()); TERN_(AUTO_REPORT_FANS, fan_check.auto_reporter.tick()); TERN_(AUTO_REPORT_SD_STATUS, card.auto_reporter.tick()); - TERN_(AUTO_REPORT_POSITION, position_auto_reporter.tick()); + TERN_(AUTO_REPORT_POSITION, motion.position_auto_reporter.tick()); TERN_(BUFFER_MONITORING, queue.auto_report_buffer_statistics()); } #endif @@ -1411,9 +1411,9 @@ void setup() { SETUP_RUN(touchBt.init()); #endif - TERN_(HAS_HOME_OFFSET, current_position += home_offset); // Init current position based on home_offset + TERN_(HAS_HOME_OFFSET, motion.position += motion.home_offset); // Init current position based on home_offset - sync_plan_position(); // Vital to init stepper/planner equivalent for current_position + motion.sync_plan_position(); // Vital to init stepper/planner equivalent for motion.position SETUP_RUN(thermalManager.init()); // Initialize temperature loop diff --git a/Marlin/src/core/debug_section.h b/Marlin/src/core/debug_section.h index 6319515b71..15ff8f270b 100644 --- a/Marlin/src/core/debug_section.h +++ b/Marlin/src/core/debug_section.h @@ -41,6 +41,6 @@ private: SERIAL_ECHO(fpre); if (the_msg) SERIAL_ECHO(C(' '), the_msg); SERIAL_CHAR(' '); - print_xyz(xyz_pos_t(current_position)); + print_xyz(xyz_pos_t(motion.position)); } }; diff --git a/Marlin/src/core/utility.cpp b/Marlin/src/core/utility.cpp index f6b8b304c0..86a7b75640 100644 --- a/Marlin/src/core/utility.cpp +++ b/Marlin/src/core/utility.cpp @@ -133,7 +133,7 @@ SERIAL_ECHOPGM("ABL Adjustment"); LOOP_NUM_AXES(a) { SERIAL_ECHOPGM_P((PGM_P)pgm_read_ptr(&SP_AXIS_STR[a])); - serial_offset(planner.get_axis_position_mm((AxisEnum)a) - current_position[a]); + serial_offset(planner.get_axis_position_mm((AxisEnum)a) - motion.position[a]); } #else #if ENABLED(AUTO_BED_LEVELING_UBL) @@ -141,11 +141,11 @@ #elif ENABLED(AUTO_BED_LEVELING_BILINEAR) SERIAL_ECHOPGM("ABL Adjustment Z"); #endif - const float rz = bedlevel.get_z_correction(current_position); + const float rz = bedlevel.get_z_correction(motion.position); SERIAL_ECHO(ftostr43sign(rz, '+')); #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT) if (planner.z_fade_height) - SERIAL_ECHO(F(" ("), ftostr43sign(rz * planner.fade_scaling_factor_for_z(current_position.z), '+'), C(')')); + SERIAL_ECHO(F(" ("), ftostr43sign(rz * planner.fade_scaling_factor_for_z(motion.position.z), '+'), C(')')); #endif #endif } @@ -160,11 +160,11 @@ if (planner.leveling_active) { SERIAL_ECHOLNPGM(" (enabled)"); const float z_offset = bedlevel.get_z_offset(), - z_correction = bedlevel.get_z_correction(current_position); + z_correction = bedlevel.get_z_correction(motion.position); SERIAL_ECHOPGM("MBL Adjustment Z", ftostr43sign(z_offset + z_correction, '+')); #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT) if (planner.z_fade_height) { - SERIAL_ECHO(F(" ("), ftostr43sign(z_offset + z_correction * planner.fade_scaling_factor_for_z(current_position.z), '+'), C(')')); + SERIAL_ECHO(F(" ("), ftostr43sign(z_offset + z_correction * planner.fade_scaling_factor_for_z(motion.position.z), '+'), C(')')); } #endif } diff --git a/Marlin/src/feature/babystep.cpp b/Marlin/src/feature/babystep.cpp index d61784517b..6a5c2bb13f 100644 --- a/Marlin/src/feature/babystep.cpp +++ b/Marlin/src/feature/babystep.cpp @@ -59,7 +59,7 @@ void Babystep::add_mm(const AxisEnum axis, const float mm) { #if ENABLED(BD_SENSOR) void Babystep::set_mm(const AxisEnum axis, const float mm) { - //if (DISABLED(BABYSTEP_WITHOUT_HOMING) && axis_should_home(axis)) return; + //if (DISABLED(BABYSTEP_WITHOUT_HOMING) && motion.axis_should_home(axis)) return; const int16_t distance = mm * planner.settings.axis_steps_per_mm[axis]; accum = distance; // Count up babysteps for the UI steps[BS_AXIS_IND(axis)] = distance; @@ -70,7 +70,7 @@ void Babystep::add_mm(const AxisEnum axis, const float mm) { #endif bool Babystep::can_babystep(const AxisEnum axis) { - return (ENABLED(BABYSTEP_WITHOUT_HOMING) || !axis_should_home(axis)); + return (ENABLED(BABYSTEP_WITHOUT_HOMING) || !motion.axis_should_home(axis)); } void Babystep::add_steps(const AxisEnum axis, const int16_t distance) { diff --git a/Marlin/src/feature/backlash.cpp b/Marlin/src/feature/backlash.cpp index 2de0aa00ef..c18d32edd1 100644 --- a/Marlin/src/feature/backlash.cpp +++ b/Marlin/src/feature/backlash.cpp @@ -224,12 +224,12 @@ class Backlash::StepAdjuster { void Backlash::measure_with_probe() { if (measured_count.z == 255) return; - const float start_height = current_position.z; - while (current_position.z < (start_height + BACKLASH_MEASUREMENT_LIMIT) && PROBE_TRIGGERED()) - do_blocking_move_to_z(current_position.z + BACKLASH_MEASUREMENT_RESOLUTION, MMM_TO_MMS(BACKLASH_MEASUREMENT_FEEDRATE)); + const float start_height = motion.position.z; + while (motion.position.z < (start_height + BACKLASH_MEASUREMENT_LIMIT) && PROBE_TRIGGERED()) + motion.blocking_move_z(motion.position.z + BACKLASH_MEASUREMENT_RESOLUTION, MMM_TO_MMS(BACKLASH_MEASUREMENT_FEEDRATE)); // The backlash from all probe points is averaged, so count the number of measurements - measured_mm.z += current_position.z - start_height; + measured_mm.z += motion.position.z - start_height; measured_count.z++; } diff --git a/Marlin/src/feature/bedlevel/abl/bbl.cpp b/Marlin/src/feature/bedlevel/abl/bbl.cpp index 918b06d2b4..280700c1f1 100644 --- a/Marlin/src/feature/bedlevel/abl/bbl.cpp +++ b/Marlin/src/feature/bedlevel/abl/bbl.cpp @@ -371,8 +371,8 @@ float LevelingBilinear::get_z_correction(const xy_pos_t &raw) { */ void LevelingBilinear::line_to_destination(const feedRate_t scaled_fr_mm_s, uint16_t x_splits, uint16_t y_splits) { // Get current and destination cells for this line - xy_int_t c1 { CELL_INDEX(x, current_position.x), CELL_INDEX(y, current_position.y) }, - c2 { CELL_INDEX(x, destination.x), CELL_INDEX(y, destination.y) }; + xy_int_t c1 { CELL_INDEX(x, motion.position.x), CELL_INDEX(y, motion.position.y) }, + c2 { CELL_INDEX(x, motion.destination.x), CELL_INDEX(y, motion.destination.y) }; LIMIT(c1.x, 0, ABL_BG_POINTS_X - 2); LIMIT(c1.y, 0, ABL_BG_POINTS_Y - 2); LIMIT(c2.x, 0, ABL_BG_POINTS_X - 2); @@ -380,12 +380,12 @@ float LevelingBilinear::get_z_correction(const xy_pos_t &raw) { // Start and end in the same cell? No split needed. if (c1 == c2) { - current_position = destination; - line_to_current_position(scaled_fr_mm_s); + motion.position = motion.destination; + motion.goto_current_position(scaled_fr_mm_s); return; } - #define LINE_SEGMENT_END(A) (current_position.A + (destination.A - current_position.A) * normalized_dist) + #define LINE_SEGMENT_END(A) (motion.position.A + (motion.destination.A - motion.position.A) * normalized_dist) float normalized_dist; xyze_pos_t end; @@ -396,36 +396,36 @@ float LevelingBilinear::get_z_correction(const xy_pos_t &raw) { if (c2.x != c1.x && TEST(x_splits, gc.x)) { // Split on the X grid line CBI(x_splits, gc.x); - end = destination; - destination.x = grid_start.x + ABL_BG_SPACING(x) * gc.x; - normalized_dist = (destination.x - current_position.x) / (end.x - current_position.x); - destination.y = LINE_SEGMENT_END(y); + end = motion.destination; + motion.destination.x = grid_start.x + ABL_BG_SPACING(x) * gc.x; + normalized_dist = (motion.destination.x - motion.position.x) / (end.x - motion.position.x); + motion.destination.y = LINE_SEGMENT_END(y); } // Crosses on the Y and not already split on this Y? else if (c2.y != c1.y && TEST(y_splits, gc.y)) { // Split on the Y grid line CBI(y_splits, gc.y); - end = destination; - destination.y = grid_start.y + ABL_BG_SPACING(y) * gc.y; - normalized_dist = (destination.y - current_position.y) / (end.y - current_position.y); - destination.x = LINE_SEGMENT_END(x); + end = motion.destination; + motion.destination.y = grid_start.y + ABL_BG_SPACING(y) * gc.y; + normalized_dist = (motion.destination.y - motion.position.y) / (end.y - motion.position.y); + motion.destination.x = LINE_SEGMENT_END(x); } else { // Must already have been split on these border(s) // This should be a rare case. - current_position = destination; - line_to_current_position(scaled_fr_mm_s); + motion.position = motion.destination; + motion.goto_current_position(scaled_fr_mm_s); return; } - destination.z = LINE_SEGMENT_END(z); - destination.e = LINE_SEGMENT_END(e); + motion.destination.z = LINE_SEGMENT_END(z); + motion.destination.e = LINE_SEGMENT_END(e); // Do the split and look for more borders line_to_destination(scaled_fr_mm_s, x_splits, y_splits); // Restore destination from stack - destination = end; + motion.destination = end; line_to_destination(scaled_fr_mm_s, x_splits, y_splits); } diff --git a/Marlin/src/feature/bedlevel/bdl/bdl.cpp b/Marlin/src/feature/bedlevel/bdl/bdl.cpp index 45c7792d5c..c115ea93c9 100644 --- a/Marlin/src/feature/bedlevel/bdl/bdl.cpp +++ b/Marlin/src/feature/bedlevel/bdl/bdl.cpp @@ -72,8 +72,8 @@ void BDS_Leveling::init(uint8_t _sda, uint8_t _scl, uint16_t delay_s) { config_state = BDS_IDLE; const int ret = BD_I2C_SENSOR.i2c_init(_sda, _scl, BD_SENSOR_I2C_ADDR, delay_s); if (ret != 1) SERIAL_ECHOLNPGM("BD Sensor Init Fail (", ret, ")"); - sync_plan_position(); - pos_zero_offset = planner.get_axis_position_mm(Z_AXIS) - current_position.z; + motion.sync_plan_position(); + pos_zero_offset = planner.get_axis_position_mm(Z_AXIS) - motion.position.z; SERIAL_ECHOLNPGM("BD Sensor Zero Offset:", pos_zero_offset); } @@ -119,7 +119,7 @@ void BDS_Leveling::process() { uint16_t tmp = 0; const float cur_z = planner.get_axis_position_mm(Z_AXIS) - pos_zero_offset; - static float old_cur_z = cur_z, old_buf_z = current_position.z; + static float old_cur_z = cur_z, old_buf_z = motion.position.z; tmp = BD_I2C_SENSOR.BD_i2c_read(); if (BD_I2C_SENSOR.BD_Check_OddEven(tmp) && good_data(tmp)) { const float z_sensor = interpret(tmp); @@ -127,11 +127,11 @@ void BDS_Leveling::process() { if (config_state > 0) { if (cur_z < config_state * 0.1f && old_cur_z == cur_z - && old_buf_z == current_position.z + && old_buf_z == motion.position.z && z_sensor < (MAX_BD_HEIGHT) - 0.1f ) { babystep.set_mm(Z_AXIS, cur_z - z_sensor); - DEBUG_ECHOLNPGM("BD:", z_sensor, ", Z:", cur_z, "|", current_position.z); + DEBUG_ECHOLNPGM("BD:", z_sensor, ", Z:", cur_z, "|", motion.position.z); } else babystep.set_mm(Z_AXIS, 0); @@ -139,7 +139,7 @@ void BDS_Leveling::process() { #endif old_cur_z = cur_z; - old_buf_z = current_position.z; + old_buf_z = motion.position.z; endstops.bdp_state_update(z_sensor <= BD_SENSOR_HOME_Z_POSITION); #if HAS_STATUS_MESSAGE @@ -158,7 +158,7 @@ void BDS_Leveling::process() { marlin.kill(F("BDsensor connect Err!")); } - DEBUG_ECHOLNPGM("BD:", tmp & 0x3FF, " Z:", cur_z, "|", current_position.z); + DEBUG_ECHOLNPGM("BD:", tmp & 0x3FF, " Z:", cur_z, "|", motion.position.z); if (TERN0(DEBUG_OUT_BD, BD_I2C_SENSOR.BD_Check_OddEven(tmp) == 0)) DEBUG_ECHOLNPGM("CRC error"); if (!good_data(tmp)) { @@ -204,15 +204,15 @@ void BDS_Leveling::process() { SERIAL_ECHOLNPGM("c_z0:", planner.get_axis_position_mm(Z_AXIS), "-", pos_zero_offset); // Move the z axis instead of enabling the Z axis with M17 - // TODO: Use do_blocking_move_to_z for synchronized move. - current_position.z = 0; - sync_plan_position(); + // TODO: Use motion.blocking_move_z for synchronized move. + motion.position.z = 0; + motion.sync_plan_position(); gcode.process_subcommands_now(F("G1Z0.05")); safe_delay(300); gcode.process_subcommands_now(F("G1Z0.00")); safe_delay(300); - current_position.z = 0; - sync_plan_position(); + motion.position.z = 0; + motion.sync_plan_position(); //safe_delay(1000); while ((planner.get_axis_position_mm(Z_AXIS) - pos_zero_offset) > 0.00001f) { @@ -235,10 +235,10 @@ void BDS_Leveling::process() { } else { char tmp_1[32]; - // TODO: Use prepare_internal_move_to_destination to guarantee machine space + // TODO: Use motion.prepare_internal_move_to_destination to guarantee machine space sprintf_P(tmp_1, PSTR("G1Z%d.%d"), int(zpos), int(zpos * 10) % 10); gcode.process_subcommands_now(tmp_1); - SERIAL_ECHO(tmp_1); SERIAL_ECHOLNPGM(", Z:", current_position.z); + SERIAL_ECHO(tmp_1); SERIAL_ECHOLNPGM(", Z:", motion.position.z); uint16_t failcount = 300; for (float tmp_k = 0; abs(zpos - tmp_k) > 0.006f && failcount--;) { tmp_k = planner.get_axis_position_mm(Z_AXIS) - pos_zero_offset; diff --git a/Marlin/src/feature/bedlevel/bedlevel.cpp b/Marlin/src/feature/bedlevel/bedlevel.cpp index e479e4c70a..c49afa30e2 100644 --- a/Marlin/src/feature/bedlevel/bedlevel.cpp +++ b/Marlin/src/feature/bedlevel/bedlevel.cpp @@ -66,9 +66,9 @@ void set_bed_leveling_enabled(const bool enable/*=true*/) { auto _report_leveling = []{ if (DEBUGGING(LEVELING)) { if (planner.leveling_active) - DEBUG_POS("Leveling ON", current_position); + DEBUG_POS("Leveling ON", motion.position); else - DEBUG_POS("Leveling OFF", current_position); + DEBUG_POS("Leveling OFF", motion.position); } }; @@ -76,11 +76,11 @@ void set_bed_leveling_enabled(const bool enable/*=true*/) { planner.synchronize(); // Get the corrected leveled / unleveled position - planner.apply_modifiers(current_position, true); // Physical position with all modifiers - FLIP(planner.leveling_active); // Toggle leveling between apply and unapply - planner.unapply_modifiers(current_position, true); // Logical position with modifiers removed + planner.apply_modifiers(motion.position, true); // Physical position with all modifiers + FLIP(planner.leveling_active); // Toggle leveling between apply and unapply + planner.unapply_modifiers(motion.position, true); // Logical position with modifiers removed - sync_plan_position(); + motion.sync_plan_position(); _report_leveling(); } } @@ -101,10 +101,10 @@ TemporaryBedLevelingState::TemporaryBedLevelingState(const bool enable) : saved( planner.set_z_fade_height(zfh); if (leveling_was_active) { - const xyz_pos_t oldpos = current_position; + const xyz_pos_t oldpos = motion.position; set_bed_leveling_enabled(true); - if (do_report && oldpos != current_position) - report_current_position(); + if (do_report && oldpos != motion.position) + motion.report_position(); } } @@ -198,16 +198,16 @@ void reset_bed_level() { #else #warning "It's recommended to set some MANUAL_PROBE_START_Z value for manual leveling." #endif - #if Z_CLEARANCE_BETWEEN_MANUAL_PROBES > 0 // A probe/obstacle clearance exists so there is a raise: + #if Z_CLEARANCE_BETWEEN_MANUAL_PROBES > 0 // A probe/obstacle clearance exists so there is a raise: #ifndef MANUAL_PROBE_START_Z - const float finalz = current_position.z; // - Use the current Z for starting-Z if no MANUAL_PROBE_START_Z was provided + const float finalz = motion.position.z; // - Use the current Z for starting-Z if no MANUAL_PROBE_START_Z was provided #endif - do_blocking_move_to_xy_z(pos, Z_CLEARANCE_BETWEEN_MANUAL_PROBES); // - Raise Z, then move to the new XY - do_blocking_move_to_z(finalz); // - Lower down to the starting Z height, ready for adjustment! - #elif defined(MANUAL_PROBE_START_Z) // A starting-Z was provided, but there's no raise: - do_blocking_move_to_xy_z(pos, finalz); // - Move in XY then down to the starting Z height, ready for adjustment! - #else // Zero raise and no starting Z height either: - do_blocking_move_to_xy(pos); // - Move over with no raise, ready for adjustment! + motion.blocking_move_xy_z(pos, Z_CLEARANCE_BETWEEN_MANUAL_PROBES); // - Raise Z, then move to the new XY + motion.blocking_move_z(finalz); // - Lower down to the starting Z height, ready for adjustment! + #elif defined(MANUAL_PROBE_START_Z) // A starting-Z was provided, but there's no raise: + motion.blocking_move_xy_z(pos, finalz); // - Move in XY then down to the starting Z height, ready for adjustment! + #else // Zero raise and no starting Z height either: + motion.blocking_move_xy(pos); // - Move over with no raise, ready for adjustment! #endif TERN_(LCD_BED_LEVELING, ui.wait_for_move = false); diff --git a/Marlin/src/feature/bedlevel/mbl/mesh_bed_leveling.cpp b/Marlin/src/feature/bedlevel/mbl/mesh_bed_leveling.cpp index 155d34c4df..47e8e34fbd 100644 --- a/Marlin/src/feature/bedlevel/mbl/mesh_bed_leveling.cpp +++ b/Marlin/src/feature/bedlevel/mbl/mesh_bed_leveling.cpp @@ -63,7 +63,7 @@ */ void mesh_bed_leveling::line_to_destination(const feedRate_t scaled_fr_mm_s, uint8_t x_splits, uint8_t y_splits) { // Get current and destination cells for this line - xy_uint8_t scel = cell_indexes(current_position), ecel = cell_indexes(destination); + xy_uint8_t scel = cell_indexes(motion.position), ecel = cell_indexes(motion.destination); NOMORE(scel.x, GRID_MAX_CELLS_X - 1); NOMORE(scel.y, GRID_MAX_CELLS_Y - 1); NOMORE(ecel.x, GRID_MAX_CELLS_X - 1); @@ -71,12 +71,12 @@ // Start and end in the same cell? No split needed. if (scel == ecel) { - current_position = destination; - line_to_current_position(scaled_fr_mm_s); + motion.position = motion.destination; + motion.goto_current_position(scaled_fr_mm_s); return; } - #define MBL_SEGMENT_END(A) (current_position.A + (destination.A - current_position.A) * normalized_dist) + #define MBL_SEGMENT_END(A) (motion.position.A + (motion.destination.A - motion.position.A) * normalized_dist) float normalized_dist; xyze_pos_t dest; @@ -87,36 +87,36 @@ if (ecel.x != scel.x && TEST(x_splits, gcx)) { // Split on the X grid line CBI(x_splits, gcx); - dest = destination; - destination.x = index_to_xpos[gcx]; - normalized_dist = (destination.x - current_position.x) / (dest.x - current_position.x); - destination.y = MBL_SEGMENT_END(y); + dest = motion.destination; + motion.destination.x = index_to_xpos[gcx]; + normalized_dist = (motion.destination.x - motion.position.x) / (dest.x - motion.position.x); + motion.destination.y = MBL_SEGMENT_END(y); } // Crosses on the Y and not already split on this Y? else if (ecel.y != scel.y && TEST(y_splits, gcy)) { // Split on the Y grid line CBI(y_splits, gcy); - dest = destination; - destination.y = index_to_ypos[gcy]; - normalized_dist = (destination.y - current_position.y) / (dest.y - current_position.y); - destination.x = MBL_SEGMENT_END(x); + dest = motion.destination; + motion.destination.y = index_to_ypos[gcy]; + normalized_dist = (motion.destination.y - motion.position.y) / (dest.y - motion.position.y); + motion.destination.x = MBL_SEGMENT_END(x); } else { // Must already have been split on these border(s) // This should be a rare case. - current_position = destination; - line_to_current_position(scaled_fr_mm_s); + motion.position = motion.destination; + motion.goto_current_position(scaled_fr_mm_s); return; } - destination.z = MBL_SEGMENT_END(z); - destination.e = MBL_SEGMENT_END(e); + motion.destination.z = MBL_SEGMENT_END(z); + motion.destination.e = MBL_SEGMENT_END(e); // Do the split and look for more borders line_to_destination(scaled_fr_mm_s, x_splits, y_splits); // Restore destination from stack - destination = dest; + motion.destination = dest; line_to_destination(scaled_fr_mm_s, x_splits, y_splits); } diff --git a/Marlin/src/feature/bedlevel/ubl/ubl.cpp b/Marlin/src/feature/bedlevel/ubl/ubl.cpp index 2357437633..cc887fd23b 100644 --- a/Marlin/src/feature/bedlevel/ubl/ubl.cpp +++ b/Marlin/src/feature/bedlevel/ubl/ubl.cpp @@ -93,7 +93,7 @@ void unified_bed_leveling::reset() { #if ENABLED(EXTENSIBLE_UI) GRID_LOOP(x, y) ExtUI::onMeshUpdate(x, y, 0); #endif - if (was_enabled) report_current_position(); + if (was_enabled) motion.report_position(); } void unified_bed_leveling::invalidate() { @@ -184,7 +184,7 @@ void unified_bed_leveling::display_map(const uint8_t map_type) { // Add XY probe offset from extruder because probe.probe_at_point() subtracts them when // moving to the XY position to be measured. This ensures better agreement between // the current Z position after G28 and the mesh values. - const xy_int8_t curr = closest_indexes(xy_pos_t(current_position) + probe.offset_xy); + const xy_int8_t curr = closest_indexes(xy_pos_t(motion.position) + probe.offset_xy); if (!lcd) SERIAL_EOL(); for (int8_t j = (GRID_MAX_POINTS_Y) - 1; j >= 0; j--) { diff --git a/Marlin/src/feature/bedlevel/ubl/ubl_G29.cpp b/Marlin/src/feature/bedlevel/ubl/ubl_G29.cpp index 42b0d0d5f6..02b904adca 100644 --- a/Marlin/src/feature/bedlevel/ubl/ubl_G29.cpp +++ b/Marlin/src/feature/bedlevel/ubl/ubl_G29.cpp @@ -324,7 +324,7 @@ void unified_bed_leveling::G29() { restore_ubl_active_state(false); // ...without telling ExtUI "done" #else // Send 'N' to force homing before G29 (internal only) - if (axes_should_home() || parser.seen_test('N')) gcode.home_all_axes(); + if (motion.axes_should_home() || parser.seen_test('N')) gcode.home_all_axes(); #endif probe.use_probing_tool(); @@ -335,7 +335,7 @@ void unified_bed_leveling::G29() { // Position bed horizontally and Z probe vertically. #if HAS_SAFE_BED_LEVELING - xyze_pos_t safe_position = current_position; + xyze_pos_t safe_position = motion.position; #ifdef SAFE_BED_LEVELING_START_X safe_position.x = SAFE_BED_LEVELING_START_X; #endif @@ -364,7 +364,7 @@ void unified_bed_leveling::G29() { safe_position.w = SAFE_BED_LEVELING_START_W; #endif - do_blocking_move_to(safe_position); + motion.blocking_move(safe_position); #endif // HAS_SAFE_BED_LEVELING } @@ -444,9 +444,9 @@ void unified_bed_leveling::G29() { tilt_mesh_based_on_probed_grid(param.J_grid_size == 0); // Zero size does 3-Point restore_ubl_active_state(); #if ENABLED(UBL_G29_J_RECENTER) - do_blocking_move_to_xy(0.5f * ((MESH_MIN_X) + (MESH_MAX_X)), 0.5f * ((MESH_MIN_Y) + (MESH_MAX_Y))); + motion.blocking_move_xy(0.5f * ((MESH_MIN_X) + (MESH_MAX_X)), 0.5f * ((MESH_MIN_Y) + (MESH_MAX_Y))); #endif - report_current_position(); + motion.report_position(); SET_PROBE_DEPLOYED(true); } @@ -481,7 +481,7 @@ void unified_bed_leveling::G29() { SERIAL_ECHOLN(F("Probing around ("), param.XY_pos.x, C(','), param.XY_pos.y, F(").\n")); probe_entire_mesh(param.XY_pos, parser.seen_test('T'), parser.seen_test('E'), parser.seen_test('U')); - report_current_position(); + motion.report_position(); SET_PROBE_DEPLOYED(true); } break; @@ -493,7 +493,7 @@ void unified_bed_leveling::G29() { // Manually Probe Mesh in areas that can't be reached by the probe // SERIAL_ECHOLNPGM("Manually probing unreachable points."); - do_z_clearance(Z_CLEARANCE_BETWEEN_PROBES); + motion.do_z_clearance(Z_CLEARANCE_BETWEEN_PROBES); if (parser.seen_test('C') && !param.XY_seen) { @@ -523,7 +523,7 @@ void unified_bed_leveling::G29() { SET_PROBE_DEPLOYED(true); } - if (!position_is_reachable(param.XY_pos)) { + if (!motion.can_reach(param.XY_pos)) { SERIAL_ECHOLNPGM("XY outside printable radius."); return; } @@ -533,7 +533,7 @@ void unified_bed_leveling::G29() { SERIAL_ECHOLNPGM("G29 P2 finished."); - report_current_position(); + motion.report_position(); #else @@ -827,7 +827,7 @@ void unified_bed_leveling::shift_mesh_height(const float zoffs) { probe.move_z_after_probing(); - do_blocking_move_to_xy( + motion.blocking_move_xy( constrain(nearby.x - probe.offset_xy.x, MESH_MIN_X, MESH_MAX_X), constrain(nearby.y - probe.offset_xy.y, MESH_MIN_Y, MESH_MAX_Y) ); @@ -874,7 +874,7 @@ void set_message_with_feedback(FSTR_P const fstr) { marlin.idle(); gcode.reset_stepper_timeout(); // Keep steppers powered if (encoder_diff) { - do_blocking_move_to_z(current_position.z + float(encoder_diff) * multiplier); + motion.blocking_move_z(motion.position.z + float(encoder_diff) * multiplier); encoder_diff = 0; } } @@ -884,7 +884,7 @@ void set_message_with_feedback(FSTR_P const fstr) { KEEPALIVE_STATE(PAUSED_FOR_USER); const float z_step = 0.01f; move_z_with_encoder(z_step); - return current_position.z; + return motion.position.z; } static void echo_and_take_a_measurement() { SERIAL_ECHOLNPGM(" and take a measurement."); } @@ -893,7 +893,7 @@ void set_message_with_feedback(FSTR_P const fstr) { ui.capture(); save_ubl_active_state_and_disable(); // Disable bed level correction for probing - do_blocking_move_to( + motion.blocking_move( xyz_pos_t({ 0.5f * ((MESH_MIN_X) + (MESH_MAX_X)), 0.5f * ((MESH_MIN_Y) + (MESH_MAX_Y)), @@ -927,14 +927,14 @@ void set_message_with_feedback(FSTR_P const fstr) { echo_and_take_a_measurement(); const float z1 = measure_point_with_encoder(); - do_z_clearance_by(SIZE_OF_LITTLE_RAISE); + motion.do_z_clearance_by(SIZE_OF_LITTLE_RAISE); SERIAL_ECHOPGM("Remove shim"); LCD_MESSAGE(MSG_UBL_BC_REMOVE); echo_and_take_a_measurement(); const float z2 = measure_point_with_encoder(); - do_z_clearance_by(Z_CLEARANCE_BETWEEN_PROBES); + motion.do_z_clearance_by(Z_CLEARANCE_BETWEEN_PROBES); const float thickness = ABS(z1 - z2); @@ -956,7 +956,7 @@ void set_message_with_feedback(FSTR_P const fstr) { TERN_(EXTENSIBLE_UI, ExtUI::onLevelingStart()); save_ubl_active_state_and_disable(); // No bed level correction so only raw data is obtained - do_blocking_move_to_xy_z(current_position, z_clearance); + motion.blocking_move_xy_z(motion.position, z_clearance); ui.return_to_status(); @@ -969,12 +969,12 @@ void set_message_with_feedback(FSTR_P const fstr) { const xyz_pos_t ppos = { get_mesh_x(lpos.x), get_mesh_y(lpos.y), z_clearance }; - if (!position_is_reachable(ppos)) break; // SHOULD NOT OCCUR (find_closest_mesh_point only returns reachable points) + if (!motion.can_reach(ppos)) break; // SHOULD NOT OCCUR (find_closest_mesh_point only returns reachable points) LCD_MESSAGE(MSG_UBL_MOVING_TO_NEXT); - do_blocking_move_to(ppos); - do_z_clearance(z_clearance); + motion.blocking_move(ppos); + motion.do_z_clearance(z_clearance); KEEPALIVE_STATE(PAUSED_FOR_USER); ui.capture(); @@ -995,11 +995,11 @@ void set_message_with_feedback(FSTR_P const fstr) { if (_click_and_hold([]{ SERIAL_ECHOLNPGM("\nMesh only partially populated."); - do_z_clearance(Z_CLEARANCE_DEPLOY_PROBE); + motion.do_z_clearance(Z_CLEARANCE_DEPLOY_PROBE); })) return restore_ubl_active_state(); // Store the Z position minus the shim height - z_values[lpos.x][lpos.y] = current_position.z - thick; + z_values[lpos.x][lpos.y] = motion.position.z - thick; // Tell the external UI to update TERN_(EXTENSIBLE_UI, ExtUI::onMeshUpdate(location, z_values[lpos.x][lpos.y])); @@ -1012,7 +1012,7 @@ void set_message_with_feedback(FSTR_P const fstr) { if (do_ubl_mesh_map) display_map(param.T_map_type); // show user where we're probing restore_ubl_active_state(); - do_blocking_move_to_xy_z(pos, Z_CLEARANCE_DEPLOY_PROBE); + motion.blocking_move_xy_z(pos, Z_CLEARANCE_DEPLOY_PROBE); } /** @@ -1033,7 +1033,7 @@ void set_message_with_feedback(FSTR_P const fstr) { mesh_index_pair location; - if (!position_is_reachable(pos)) { + if (!motion.can_reach(pos)) { SERIAL_ECHOLNPGM("(X,Y) outside printable radius."); return; } @@ -1043,7 +1043,7 @@ void set_message_with_feedback(FSTR_P const fstr) { LCD_MESSAGE(MSG_UBL_FINE_TUNE_MESH); ui.capture(); // Take over control of the LCD encoder - do_blocking_move_to_xy_z(pos, Z_TWEEN_SAFE_CLEARANCE); // Move to the given XY with probe clearance + motion.blocking_move_xy_z(pos, Z_TWEEN_SAFE_CLEARANCE); // Move to the given XY with probe clearance MeshFlags done_flags{0}; const xy_int8_t &lpos = location.pos; @@ -1062,18 +1062,18 @@ void set_message_with_feedback(FSTR_P const fstr) { // location is used on the next loop const xyz_pos_t raw = { get_mesh_x(lpos.x), get_mesh_y(lpos.y), Z_TWEEN_SAFE_CLEARANCE }; - if (!position_is_reachable(raw)) break; // SHOULD NOT OCCUR (find_closest_mesh_point_of_type only returns reachable) + if (!motion.can_reach(raw)) break; // SHOULD NOT OCCUR (find_closest_mesh_point_of_type only returns reachable) - do_blocking_move_to(raw); // Move the nozzle to the edit point with probe clearance + motion.blocking_move(raw); // Move the nozzle to the edit point with probe clearance - TERN_(UBL_MESH_EDIT_MOVES_Z, do_blocking_move_to_z(h_offset)); // Move Z to the given 'H' offset before editing + TERN_(UBL_MESH_EDIT_MOVES_Z, motion.blocking_move_z(h_offset)); // Move Z to the given 'H' offset before editing KEEPALIVE_STATE(PAUSED_FOR_USER); if (do_ubl_mesh_map) display_map(param.T_map_type); // Display the current point #if IS_TFTGLCD_PANEL - ui.ubl_plot(lpos.x, lpos.y); // update plot screen + ui.ubl_plot(lpos.x, lpos.y); // Update plot screen #endif ui.refresh(); @@ -1084,23 +1084,23 @@ void set_message_with_feedback(FSTR_P const fstr) { ui.ubl_mesh_edit_start(new_z); - SET_SOFT_ENDSTOP_LOOSE(true); + motion.set_soft_endstop_loose(true); do { marlin.idle_no_sleep(); new_z = ui.ubl_mesh_value(); - TERN_(UBL_MESH_EDIT_MOVES_Z, do_blocking_move_to_z(h_offset + new_z)); // Move the nozzle as the point is edited + TERN_(UBL_MESH_EDIT_MOVES_Z, motion.blocking_move_z(h_offset + new_z)); // Move the nozzle as the point is edited SERIAL_FLUSH(); // Prevent host M105 buffer overrun. } while (!ui.button_pressed()); - SET_SOFT_ENDSTOP_LOOSE(false); + motion.set_soft_endstop_loose(false); if (!lcd_map_control) ui.return_to_status(); // Just editing a single point? Return to status // Button held down? Abort editing if (_click_and_hold([]{ ui.return_to_status(); - do_z_clearance(Z_TWEEN_SAFE_CLEARANCE); + motion.do_z_clearance(Z_TWEEN_SAFE_CLEARANCE); set_message_with_feedback(GET_TEXT_F(MSG_EDITING_STOPPED)); })) break; @@ -1120,7 +1120,7 @@ void set_message_with_feedback(FSTR_P const fstr) { if (do_ubl_mesh_map) display_map(param.T_map_type); restore_ubl_active_state(); - do_blocking_move_to_xy_z(pos, Z_TWEEN_SAFE_CLEARANCE); + motion.blocking_move_xy_z(pos, Z_TWEEN_SAFE_CLEARANCE); LCD_MESSAGE(MSG_UBL_DONE_EDITING_MESH); SERIAL_ECHOLNPGM("Done Editing Mesh"); @@ -1191,9 +1191,9 @@ bool unified_bed_leveling::G29_parse_parameters() { } param.XY_seen.x = parser.seenval('X'); - float sx = param.XY_seen.x ? parser.value_float() : current_position.x; + float sx = param.XY_seen.x ? parser.value_float() : motion.position.x; param.XY_seen.y = parser.seenval('Y'); - float sy = param.XY_seen.y ? parser.value_float() : current_position.y; + float sy = param.XY_seen.y ? parser.value_float() : motion.position.y; if (param.XY_seen.x != param.XY_seen.y) { SERIAL_ECHOLNPGM("Both X & Y locations must be specified.\n"); @@ -1358,7 +1358,7 @@ mesh_index_pair unified_bed_leveling::find_furthest_invalid_mesh_point() { // Also for round beds, there are grid points outside the bed the nozzle can't reach. // Prune them from the list and ignore them till the next Phase (manual nozzle probing). - if (!(d->probe_relative ? probe.can_reach(mpos) : position_is_reachable(mpos))) + if (!(d->probe_relative ? probe.can_reach(mpos) : motion.can_reach(mpos))) return false; d->closest.pos.set(i, j); return true; @@ -1402,12 +1402,12 @@ mesh_index_pair unified_bed_leveling::find_closest_mesh_point_of_type(const Mesh // Also for round beds, there are grid points outside the bed the nozzle can't reach. // Prune them from the list and ignore them till the next Phase (manual nozzle probing). - if (!(probe_relative ? probe.can_reach(mpos) : position_is_reachable(mpos))) + if (!(probe_relative ? probe.can_reach(mpos) : motion.can_reach(mpos))) continue; // Reachable. Check if it's the best_so_far location to the nozzle. - const xy_pos_t diff = current_position - mpos; + const xy_pos_t diff = motion.position - mpos; const float distance = (ref - mpos).magnitude() + diff.magnitude() * 0.1f; // factor in the distance from the current location for the normal case @@ -1771,14 +1771,14 @@ void unified_bed_leveling::smart_fill_mesh() { SERIAL_ECHOPGM("X-Axis Mesh Points at: "); for (uint8_t i = 0; i < GRID_MAX_POINTS_X; ++i) { - SERIAL_ECHO(p_float_t(LOGICAL_X_POSITION(get_mesh_x(i)), 3), F(" ")); + SERIAL_ECHO(p_float_t(motion.logical_x(get_mesh_x(i)), 3), F(" ")); serial_delay(25); } SERIAL_EOL(); SERIAL_ECHOPGM("Y-Axis Mesh Points at: "); for (uint8_t i = 0; i < GRID_MAX_POINTS_Y; ++i) { - SERIAL_ECHO(p_float_t(LOGICAL_Y_POSITION(get_mesh_y(i)), 3), F(" ")); + SERIAL_ECHO(p_float_t(motion.logical_y(get_mesh_y(i)), 3), F(" ")); serial_delay(25); } SERIAL_EOL(); diff --git a/Marlin/src/feature/bedlevel/ubl/ubl_motion.cpp b/Marlin/src/feature/bedlevel/ubl/ubl_motion.cpp index b6b9ec4368..fa77bc1e18 100644 --- a/Marlin/src/feature/bedlevel/ubl/ubl_motion.cpp +++ b/Marlin/src/feature/bedlevel/ubl/ubl_motion.cpp @@ -53,11 +53,11 @@ * just do the required Z-Height correction, call the Planner's buffer_line() routine, and leave */ #if HAS_POSITION_MODIFIERS - xyze_pos_t start = current_position, end = destination; + xyze_pos_t start = motion.position, end = motion.destination; planner.apply_modifiers(start); planner.apply_modifiers(end); #else - const xyze_pos_t &start = current_position, &end = destination; + const xyze_pos_t &start = motion.position, &end = motion.destination; #endif const xy_uint8_t istart = cell_indexes(start), iend = cell_indexes(end); @@ -78,7 +78,7 @@ end.z += UBL_Z_RAISE_WHEN_OFF_MESH; planner.buffer_segment(end, scaled_fr_mm_s, extruder); - current_position = destination; + motion.position = motion.destination; return; } #endif @@ -96,7 +96,7 @@ // Replace NAN corrections with 0.0 to prevent NAN propagation. if (!isnan(z0)) end.z += z0; planner.buffer_segment(end, scaled_fr_mm_s, extruder); - current_position = destination; + motion.position = motion.destination; return; } @@ -190,10 +190,10 @@ } // At the final destination? Usually not, but when on a Y Mesh Line it's completed. - if (xy_pos_t(current_position) != xy_pos_t(end)) + if (xy_pos_t(motion.position) != xy_pos_t(end)) goto FINAL_MOVE; - current_position = destination; + motion.position = motion.destination; return; } @@ -240,10 +240,10 @@ DEBUG_ECHOLNPGM("[ubl] skip Y segment"); } - if (xy_pos_t(current_position) != xy_pos_t(end)) + if (xy_pos_t(motion.position) != xy_pos_t(end)) goto FINAL_MOVE; - current_position = destination; + motion.position = motion.destination; return; } @@ -324,10 +324,10 @@ if (cnt.x < 0 || cnt.y < 0) break; // Too far! Exit the loop and go to FINAL_MOVE } - if (xy_pos_t(current_position) != xy_pos_t(end)) + if (xy_pos_t(motion.position) != xy_pos_t(end)) goto FINAL_MOVE; - current_position = destination; + motion.position = motion.destination; } #else // UBL_SEGMENTED @@ -347,15 +347,15 @@ /** * Prepare a segmented linear move for DELTA/SCARA/CARTESIAN with UBL and FADE semantics. * This calls planner.buffer_segment multiple times for small incremental moves. - * Returns true if did NOT move, false if moved (requires current_position update). + * Returns true if did NOT move, false if moved (requires motion.position update). */ bool __O2 unified_bed_leveling::line_to_destination_segmented(const feedRate_t scaled_fr_mm_s) { - if (!position_is_reachable(destination)) // fail if moving outside reachable boundary - return true; // did not move, so current_position still accurate + if (!motion.can_reach(motion.destination)) // Fail if moving outside reachable boundary + return true; // Did not move, so motion.position still accurate - const xyze_pos_t total = destination - current_position; + const xyze_pos_t total = motion.destination - motion.position; const float cart_xy_mm_2 = HYPOT2(total.x, total.y), cart_xy_mm = SQRT(cart_xy_mm_2); // Total XY distance @@ -383,22 +383,22 @@ // Note that E segment distance could vary slightly as z mesh height // changes for each segment, but small enough to ignore. - xyze_pos_t raw = current_position; + xyze_pos_t raw = motion.position; // Just do plain segmentation if UBL is inactive or the target is above the fade height - if (!planner.leveling_active || !planner.leveling_active_at_z(destination.z)) { + if (!planner.leveling_active || !planner.leveling_active_at_z(motion.destination.z)) { while (--segments) { raw += diff; - planner.buffer_line(raw, scaled_fr_mm_s, active_extruder, hints); + planner.buffer_line(raw, scaled_fr_mm_s, motion.extruder, hints); } - planner.buffer_line(destination, scaled_fr_mm_s, active_extruder, hints); + planner.buffer_line(motion.destination, scaled_fr_mm_s, motion.extruder, hints); return false; // Did not set current from destination } // Otherwise perform per-segment leveling #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT) - const float fade_scaling_factor = planner.fade_scaling_factor_for_z(destination.z); + const float fade_scaling_factor = planner.fade_scaling_factor_for_z(motion.destination.z); #endif // Move to first segment destination @@ -456,13 +456,13 @@ for (;;) { // for all segments within this mesh cell - if (--segments == 0) raw = destination; // if this is last segment, use destination for exact + if (--segments == 0) raw = motion.destination; // If this is last segment, use destination for exact const float z_cxcy = (z_cxy0 + z_cxym * cell.y) // interpolated mesh z height along cell.x at cell.y TERN_(ENABLE_LEVELING_FADE_HEIGHT, * fade_scaling_factor); // apply fade factor to interpolated height const float oldz = raw.z; raw.z += z_cxcy; - planner.buffer_line(raw, scaled_fr_mm_s, active_extruder, hints); + planner.buffer_line(raw, scaled_fr_mm_s, motion.extruder, hints); raw.z = oldz; if (segments == 0) // done with last segment @@ -483,7 +483,7 @@ } // segment loop } // cell loop - return false; // caller will update current_position + return false; // caller will update motion.position } #endif // UBL_SEGMENTED diff --git a/Marlin/src/feature/e_parser.cpp b/Marlin/src/feature/e_parser.cpp index 3744870164..0e0bbc1752 100644 --- a/Marlin/src/feature/e_parser.cpp +++ b/Marlin/src/feature/e_parser.cpp @@ -54,10 +54,7 @@ EmergencyParser emergency_parser; #endif #if ENABLED(REALTIME_REPORTING_COMMANDS) - // From motion.h, which cannot be included here - void report_current_position_moving(); - void quickpause_stepper(); - void quickresume_stepper(); + #include "../module/motion.h" #endif #if ENABLED(SOFT_FEED_HOLD) @@ -226,9 +223,9 @@ void EmergencyParser::update(EmergencyParser::State &state, const uint8_t c) { case EP_M876SN: hostui.handle_response(M876_reason); break; #endif #if ENABLED(REALTIME_REPORTING_COMMANDS) - case EP_GRBL_STATUS: report_current_position_moving(); break; - case EP_GRBL_PAUSE: TERN(SOFT_FEED_HOLD, realtime_ramping_pause_flag = true, quickpause_stepper()); break; - case EP_GRBL_RESUME: TERN(SOFT_FEED_HOLD, realtime_ramping_pause_flag = false, quickresume_stepper()); break; + case EP_GRBL_STATUS: motion.report_position_moving(); break; + case EP_GRBL_PAUSE: TERN(SOFT_FEED_HOLD, realtime_ramping_pause_flag = true, motion.quickpause_stepper()); break; + case EP_GRBL_RESUME: TERN(SOFT_FEED_HOLD, realtime_ramping_pause_flag = false, motion.quickresume_stepper()); break; #endif #if ENABLED(SOFT_RESET_VIA_SERIAL) case EP_KILL: hal.reboot(); break; diff --git a/Marlin/src/feature/easythreed_ui.cpp b/Marlin/src/feature/easythreed_ui.cpp index 7180c4dbcd..49d490cd76 100644 --- a/Marlin/src/feature/easythreed_ui.cpp +++ b/Marlin/src/feature/easythreed_ui.cpp @@ -136,7 +136,7 @@ void EasythreedUI::loadButton() { if (READ(BTN_RETRACT) && READ(BTN_FEED)) { // Switch in center position (stop) flag = false; // Restore flag to false filament_status = FS_IDLE; // Go back to idle state - quickstop_stepper(); // Hard-stop all the steppers ... now! + motion.quickstop_stepper(); // Hard-stop all the steppers ... now! thermalManager.disable_all_heaters(); // And disable all the heaters blink_interval_ms = LED_ON; } diff --git a/Marlin/src/feature/encoder_i2c.cpp b/Marlin/src/feature/encoder_i2c.cpp index 7c83053b89..ca7481a84d 100644 --- a/Marlin/src/feature/encoder_i2c.cpp +++ b/Marlin/src/feature/encoder_i2c.cpp @@ -318,9 +318,9 @@ bool I2CPositionEncoder::test_axis() { // Only works on XYZ Cartesian machines for the time being if (!(encoderAxis == X_AXIS || encoderAxis == Y_AXIS || encoderAxis == Z_AXIS)) return false; - const float startPosition = soft_endstop.min[encoderAxis] + 10, - endPosition = soft_endstop.max[encoderAxis] - 10; - const feedRate_t fr_mm_s = FLOOR(homing_feedrate(encoderAxis)); + const float startPosition = motion.soft_endstop.min[encoderAxis] + 10, + endPosition = motion.soft_endstop.max[encoderAxis] - 10; + const feedRate_t fr_mm_s = FLOOR(motion.homing_feedrate(encoderAxis)); ec = false; @@ -373,13 +373,13 @@ void I2CPositionEncoder::calibrate_steps_mm(const uint8_t iter) { int32_t startCount, stopCount; - const feedRate_t fr_mm_s = homing_feedrate(encoderAxis); + const feedRate_t fr_mm_s = motion.homing_feedrate(encoderAxis); bool oldec = ec; ec = false; startDistance = 20; - endDistance = soft_endstop.max[encoderAxis] - 20; + endDistance = motion.soft_endstop.max[encoderAxis] - 20; travelDistance = endDistance - startDistance; xyze_pos_t startCoord, endCoord; @@ -400,7 +400,7 @@ void I2CPositionEncoder::calibrate_steps_mm(const uint8_t iter) { delay(250); startCount = get_position(); - //do_blocking_move_to(endCoord); + //motion.blocking_move(endCoord); TERN_(HAS_EXTRUDERS, endCoord.e = planner.get_axis_position_mm(E_AXIS)); planner.buffer_line(endCoord, fr_mm_s, 0); diff --git a/Marlin/src/feature/fwretract.cpp b/Marlin/src/feature/fwretract.cpp index 5ea20401ea..6a726445a7 100644 --- a/Marlin/src/feature/fwretract.cpp +++ b/Marlin/src/feature/fwretract.cpp @@ -92,14 +92,14 @@ void FWRetract::reset() { */ void FWRetract::retract(const bool retracting E_OPTARG(bool swapping/*=false*/)) { // Prevent two retracts or recovers in a row - if (retracted[active_extruder] == retracting) return; + if (retracted[motion.extruder] == retracting) return; // Prevent two swap-retract or recovers in a row #if HAS_MULTI_EXTRUDER // Allow G10 S1 only after G11 - if (swapping && retracted_swap[active_extruder] == retracting) return; + if (swapping && retracted_swap[motion.extruder] == retracting) return; // G11 priority to recover the long retract if activated - if (!retracting) swapping = retracted_swap[active_extruder]; + if (!retracting) swapping = retracted_swap[motion.extruder]; #else constexpr bool swapping = false; #endif @@ -108,7 +108,7 @@ void FWRetract::retract(const bool retracting E_OPTARG(bool swapping/*=false*/)) SERIAL_ECHOLNPGM( "retracting ", AS_DIGIT(retracting), " swapping ", swapping, - " active extruder ", active_extruder + " active extruder ", motion.extruder ); EXTRUDER_LOOP() { SERIAL_ECHOLNPGM("retracted[", e, "] ", AS_DIGIT(retracted[e])); @@ -116,8 +116,8 @@ void FWRetract::retract(const bool retracting E_OPTARG(bool swapping/*=false*/)) SERIAL_ECHOLNPGM("retracted_swap[", e, "] ", AS_DIGIT(retracted_swap[e])); #endif } - SERIAL_ECHOLNPGM("current_position.z ", current_position.z); - SERIAL_ECHOLNPGM("current_position.e ", current_position.e); + SERIAL_ECHOLNPGM("motion.position.z ", motion.position.z); + SERIAL_ECHOLNPGM("motion.position.e ", motion.position.e); SERIAL_ECHOLNPGM("current_hop ", current_hop); //*/ @@ -125,7 +125,7 @@ void FWRetract::retract(const bool retracting E_OPTARG(bool swapping/*=false*/)) * (swapping ? settings.swap_retract_length : settings.retract_length); // The current position will be the destination for E and Z moves - destination = current_position; + motion.destination = motion.position; #if ENABLED(RETRACT_SYNC_MIXING) const uint8_t old_mixing_tool = mixer.get_current_vtool(); @@ -135,8 +135,8 @@ void FWRetract::retract(const bool retracting E_OPTARG(bool swapping/*=false*/)) const feedRate_t fr_max_z = planner.settings.max_feedrate_mm_s[Z_AXIS]; if (retracting) { // Retract by moving from a faux E position back to the current E position - current_retract[active_extruder] = base_retract; - prepare_internal_move_to_destination( // set current from destination + current_retract[motion.extruder] = base_retract; + motion.prepare_internal_move_to_destination( // Set current from destination MUL_TERN(RETRACT_SYNC_MIXING, settings.retract_feedrate_mm_s, MIXING_STEPPERS) ); @@ -144,7 +144,7 @@ void FWRetract::retract(const bool retracting E_OPTARG(bool swapping/*=false*/)) if (!current_hop && settings.retract_zraise > 0.01f) { // Apply hop only once current_hop += settings.retract_zraise; // Add to the hop total (again, only once) // Raise up, set_current_to_destination. Maximum Z feedrate - prepare_internal_move_to_destination(fr_max_z); + motion.prepare_internal_move_to_destination(fr_max_z); } } else { @@ -152,43 +152,42 @@ void FWRetract::retract(const bool retracting E_OPTARG(bool swapping/*=false*/)) if (current_hop) { current_hop = 0; // Lower Z, set_current_to_destination. Maximum Z feedrate - prepare_internal_move_to_destination(fr_max_z); + motion.prepare_internal_move_to_destination(fr_max_z); } + // Adjust the current E position by the extra amount to recover + // Sync the planner position so the extra amount is recovered const float extra_recover = swapping ? settings.swap_retract_recover_extra : settings.retract_recover_extra; - if (extra_recover) { - current_position.e -= extra_recover; // Adjust the current E position by the extra amount to recover - sync_plan_position_e(); // Sync the planner position so the extra amount is recovered - } + if (extra_recover) motion.set_and_sync_e(motion.position.e - extra_recover); - current_retract[active_extruder] = 0; + current_retract[motion.extruder] = 0; // Recover E, set_current_to_destination const feedRate_t fr_mm_s = swapping ? settings.swap_retract_recover_feedrate_mm_s : settings.retract_recover_feedrate_mm_s; - prepare_internal_move_to_destination(MUL_TERN(RETRACT_SYNC_MIXING, fr_mm_s, MIXING_STEPPERS)); + motion.prepare_internal_move_to_destination(MUL_TERN(RETRACT_SYNC_MIXING, fr_mm_s, MIXING_STEPPERS)); } TERN_(RETRACT_SYNC_MIXING, mixer.T(old_mixing_tool)); // Restore original mixing tool - retracted.set(active_extruder, retracting); // Active extruder now retracted / recovered + retracted.set(motion.extruder, retracting); // Active extruder now retracted / recovered // If swap retract/recover update the retracted_swap flag too #if HAS_MULTI_EXTRUDER - if (swapping) retracted_swap.set(active_extruder, retracting); + if (swapping) retracted_swap.set(motion.extruder, retracting); #endif /* // debugging SERIAL_ECHOLNPGM("retracting ", AS_DIGIT(retracting)); SERIAL_ECHOLNPGM("swapping ", AS_DIGIT(swapping)); - SERIAL_ECHOLNPGM("active_extruder ", active_extruder); + SERIAL_ECHOLNPGM("motion.extruder ", motion.extruder); EXTRUDER_LOOP() { SERIAL_ECHOLNPGM("retracted[", e, "] ", AS_DIGIT(retracted[e])); #if HAS_MULTI_EXTRUDER SERIAL_ECHOLNPGM("retracted_swap[", e, "] ", AS_DIGIT(retracted_swap[e])); #endif } - SERIAL_ECHOLNPGM("current_position.z ", current_position.z); - SERIAL_ECHOLNPGM("current_position.e ", current_position.e); + SERIAL_ECHOLNPGM("motion.position.z ", motion.position.z); + SERIAL_ECHOLNPGM("motion.position.e ", motion.position.e); SERIAL_ECHOLNPGM("current_hop ", current_hop); //*/ } diff --git a/Marlin/src/feature/hotend_idle.cpp b/Marlin/src/feature/hotend_idle.cpp index a779efeaff..f05e127a99 100644 --- a/Marlin/src/feature/hotend_idle.cpp +++ b/Marlin/src/feature/hotend_idle.cpp @@ -60,8 +60,8 @@ void HotendIdleProtection::check_hotends(const millis_t &ms) { void HotendIdleProtection::check_e_motion(const millis_t &ms) { static float old_e_position = 0; - if (old_e_position != current_position.e) { - old_e_position = current_position.e; // Track filament motion + if (old_e_position != motion.position.e) { + old_e_position = motion.position.e; // Track filament motion if (next_protect_ms) // If some heater is on then... next_protect_ms = ms + 1000UL * cfg.timeout; // ...delay the timeout till later } diff --git a/Marlin/src/feature/joystick.cpp b/Marlin/src/feature/joystick.cpp index cbfab1fed8..1bc38aba8c 100644 --- a/Marlin/src/feature/joystick.cpp +++ b/Marlin/src/feature/joystick.cpp @@ -119,7 +119,7 @@ Joystick joystick; if (injecting_now) return; #if ENABLED(NO_MOTION_BEFORE_HOMING) - if (TERN0(HAS_JOY_ADC_X, axis_should_home(X_AXIS)) || TERN0(HAS_JOY_ADC_Y, axis_should_home(Y_AXIS)) || TERN0(HAS_JOY_ADC_Z, axis_should_home(Z_AXIS))) + if (TERN0(HAS_JOY_ADC_X, motion.axis_should_home(X_AXIS)) || TERN0(HAS_JOY_ADC_Y, motion.axis_should_home(Y_AXIS)) || TERN0(HAS_JOY_ADC_Z, motion.axis_should_home(Z_AXIS))) return; #endif @@ -161,12 +161,12 @@ Joystick joystick; } if (!UNEAR_ZERO(hypot2)) { - current_position += move_dist; - apply_motion_limits(current_position); + motion.position += move_dist; + motion.apply_limits(motion.position); const float length = sqrt(hypot2); PlannerHints hints(length); injecting_now = true; - planner.buffer_line(current_position, length / seg_time, active_extruder, hints); + planner.buffer_line(motion.position, length / seg_time, motion.extruder, hints); injecting_now = false; } } diff --git a/Marlin/src/feature/mixing.cpp b/Marlin/src/feature/mixing.cpp index bc98bf3b26..fb4ebc894b 100644 --- a/Marlin/src/feature/mixing.cpp +++ b/Marlin/src/feature/mixing.cpp @@ -185,8 +185,8 @@ void Mixer::refresh_collector(const float proportion/*=1.0*/, const uint8_t t/*= void Mixer::update_gradient_for_planner_z() { #if ENABLED(DELTA) - get_cartesian_from_steppers(); - update_gradient_for_z(cartes.z); + motion.get_cartesian_from_steppers(); + update_gradient_for_z(motion.cartes.z); #else update_gradient_for_z(planner.get_axis_position_mm(Z_AXIS)); #endif diff --git a/Marlin/src/feature/mmu/mmu2.cpp b/Marlin/src/feature/mmu/mmu2.cpp index 76e2b8505f..0a4a2cb4ed 100644 --- a/Marlin/src/feature/mmu/mmu2.cpp +++ b/Marlin/src/feature/mmu/mmu2.cpp @@ -96,8 +96,8 @@ struct E_Step { }; inline void unscaled_mmu2_e_move(const float dist, const feedRate_t fr_mm_s, const bool sync=true) { - current_position.e += dist / planner.e_factor[active_extruder]; - line_to_current_position(fr_mm_s); + motion.position.e += dist / planner.e_factor[motion.extruder]; + motion.goto_current_position(fr_mm_s); if (sync) planner.synchronize(); } @@ -505,7 +505,7 @@ inline void beep_bad_cmd() { BUZZ(400, 40); } if (load_to_gears()) { extruder = index; // filament change is finished - active_extruder = 0; + motion.extruder = 0; stepper.enable_extruder(); SERIAL_ECHO_MSG(STR_ACTIVE_EXTRUDER, extruder); } @@ -531,7 +531,7 @@ inline void beep_bad_cmd() { BUZZ(400, 40); } case '?': { #if ENABLED(MMU_MENUS) const uint8_t index = mmu2_choose_filament(); - while (!thermalManager.wait_for_hotend(active_extruder, false)) safe_delay(100); + while (!thermalManager.wait_for_hotend(motion.extruder, false)) safe_delay(100); load_to_nozzle(index); #else beep_bad_cmd(); @@ -550,7 +550,7 @@ inline void beep_bad_cmd() { BUZZ(400, 40); } mmu_loop(); stepper.enable_extruder(); extruder = index; - active_extruder = 0; + motion.extruder = 0; } #else beep_bad_cmd(); @@ -558,7 +558,7 @@ inline void beep_bad_cmd() { BUZZ(400, 40); } } break; case 'c': { - while (!thermalManager.wait_for_hotend(active_extruder, false)) safe_delay(100); + while (!thermalManager.wait_for_hotend(motion.extruder, false)) safe_delay(100); load_to_nozzle_sequence(); } break; } @@ -591,7 +591,7 @@ inline void beep_bad_cmd() { BUZZ(400, 40); } mmu_continue_loading(); //command(MMU_CMD_C0); extruder = index; - active_extruder = 0; + motion.extruder = 0; stepper.enable_extruder(); SERIAL_ECHO_MSG(STR_ACTIVE_EXTRUDER, extruder); @@ -619,7 +619,7 @@ inline void beep_bad_cmd() { BUZZ(400, 40); } DEBUG_ECHOLNPGM("case ?\n"); #if ENABLED(MMU_MENUS) uint8_t index = mmu2_choose_filament(); - while (!thermalManager.wait_for_hotend(active_extruder, false)) safe_delay(100); + while (!thermalManager.wait_for_hotend(motion.extruder, false)) safe_delay(100); load_to_nozzle(index); #else beep_bad_cmd(); @@ -640,7 +640,7 @@ inline void beep_bad_cmd() { BUZZ(400, 40); } stepper.enable_extruder(); extruder = index; - active_extruder = 0; + motion.extruder = 0; #else beep_bad_cmd(); #endif @@ -648,7 +648,7 @@ inline void beep_bad_cmd() { BUZZ(400, 40); } case 'c': { DEBUG_ECHOLNPGM("case c\n"); - while (!thermalManager.wait_for_hotend(active_extruder, false)) safe_delay(100); + while (!thermalManager.wait_for_hotend(motion.extruder, false)) safe_delay(100); load_to_nozzle_sequence(); } break; } @@ -671,8 +671,8 @@ inline void beep_bad_cmd() { BUZZ(400, 40); } stepper.enable_extruder(); const millis_t expire_ms = millis() + 3000; do { - current_position.e += 1; - line_to_current_position(MMU_LOAD_FEEDRATE); + motion.position.e += 1; + motion.goto_current_position(MMU_LOAD_FEEDRATE); planner.synchronize(); // When (T0 rx->ok) load is ready, but in fact it did not load // successfully or an overload created pressure in the extruder. @@ -708,7 +708,7 @@ inline void beep_bad_cmd() { BUZZ(400, 40); } manage_response(true, true); command(MMU_CMD_C0); extruder = index; // Filament change is finished - active_extruder = 0; + motion.extruder = 0; stepper.enable_extruder(); SERIAL_ECHO_MSG(STR_ACTIVE_EXTRUDER, extruder); ui.reset_status(); @@ -734,7 +734,7 @@ inline void beep_bad_cmd() { BUZZ(400, 40); } DEBUG_ECHOLNPGM("case ?\n"); #if ENABLED(MMU_MENUS) uint8_t index = mmu2_choose_filament(); - while (!thermalManager.wait_for_hotend(active_extruder, false)) safe_delay(100); + while (!thermalManager.wait_for_hotend(motion.extruder, false)) safe_delay(100); load_to_nozzle(index); #else beep_bad_cmd(); @@ -754,7 +754,7 @@ inline void beep_bad_cmd() { BUZZ(400, 40); } stepper.enable_extruder(); extruder = index; - active_extruder = 0; + motion.extruder = 0; #else beep_bad_cmd(); #endif @@ -762,7 +762,7 @@ inline void beep_bad_cmd() { BUZZ(400, 40); } case 'c': { DEBUG_ECHOLNPGM("case c\n"); - while (!thermalManager.wait_for_hotend(active_extruder, false)) safe_delay(100); + while (!thermalManager.wait_for_hotend(motion.extruder, false)) safe_delay(100); load_to_nozzle_sequence(); } break; } @@ -806,7 +806,7 @@ void MMU2::manage_response(const bool move_axes, const bool turn_off_nozzle) { constexpr xyz_pos_t park_point = NOZZLE_PARK_POINT; bool response = false, mmu_print_saved = false; xyz_pos_t resume_position; - celsius_t resume_hotend_temp = thermalManager.degTargetHotend(active_extruder); + celsius_t resume_hotend_temp = thermalManager.degTargetHotend(motion.extruder); KEEPALIVE_STATE(PAUSED_FOR_USER); @@ -823,12 +823,12 @@ void MMU2::manage_response(const bool move_axes, const bool turn_off_nozzle) { SERIAL_ECHOLNPGM("MMU not responding"); - resume_hotend_temp = thermalManager.degTargetHotend(active_extruder); - resume_position = current_position; + resume_hotend_temp = thermalManager.degTargetHotend(motion.extruder); + resume_position = motion.position; - if (move_axes && all_axes_homed()) nozzle.park(0, park_point); + if (move_axes && motion.all_axes_homed()) nozzle.park(0, park_point); - if (turn_off_nozzle) thermalManager.setTargetHotend(0, active_extruder); + if (turn_off_nozzle) thermalManager.setTargetHotend(0, motion.extruder); mmu2_not_responding(); } @@ -837,10 +837,10 @@ void MMU2::manage_response(const bool move_axes, const bool turn_off_nozzle) { SERIAL_ECHOLNPGM("\nMMU starts responding"); if (turn_off_nozzle && resume_hotend_temp) { - thermalManager.setTargetHotend(resume_hotend_temp, active_extruder); + thermalManager.setTargetHotend(resume_hotend_temp, motion.extruder); LCD_MESSAGE(MSG_HEATING); ERR_BUZZ(); - while (!thermalManager.wait_for_hotend(active_extruder, false)) safe_delay(1000); + while (!thermalManager.wait_for_hotend(motion.extruder, false)) safe_delay(1000); } LCD_MESSAGE(MSG_MMU2_RESUMING); @@ -849,11 +849,11 @@ void MMU2::manage_response(const bool move_axes, const bool turn_off_nozzle) { #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wmaybe-uninitialized" - if (move_axes && all_axes_homed()) { + if (move_axes && motion.all_axes_homed()) { // Move XY to starting position, then Z - do_blocking_move_to_xy(resume_position, feedRate_t(NOZZLE_PARK_XY_FEEDRATE)); + motion.blocking_move_xy(resume_position, feedRate_t(NOZZLE_PARK_XY_FEEDRATE)); // Move Z_AXIS to saved position - do_blocking_move_to_z(resume_position.z, feedRate_t(NOZZLE_PARK_Z_FEEDRATE)); + motion.blocking_move_z(resume_position.z, feedRate_t(NOZZLE_PARK_Z_FEEDRATE)); } #pragma GCC diagnostic pop @@ -935,7 +935,7 @@ void MMU2::load_to_feeder(const uint8_t index) { bool MMU2::load_to_nozzle(const uint8_t index) { if (!_enabled) return false; - if (thermalManager.tooColdToExtrude(active_extruder)) { + if (thermalManager.tooColdToExtrude(motion.extruder)) { mmu2_attn_buzz(); LCD_ALERTMESSAGE(MSG_HOTEND_TOO_COLD); return false; @@ -956,7 +956,7 @@ bool MMU2::load_to_nozzle(const uint8_t index) { if (success) { mmu_loop(); extruder = index; - active_extruder = 0; + motion.extruder = 0; load_to_nozzle_sequence(); mmu2_attn_buzz(); } @@ -967,7 +967,7 @@ bool MMU2::eject_filament(const uint8_t index, const bool recover) { if (!_enabled) return false; - if (thermalManager.tooColdToExtrude(active_extruder)) { + if (thermalManager.tooColdToExtrude(motion.extruder)) { mmu2_attn_buzz(); LCD_ALERTMESSAGE(MSG_HOTEND_TOO_COLD); return false; @@ -1012,7 +1012,7 @@ bool MMU2::unload() { if (!_enabled) return false; - if (thermalManager.tooColdToExtrude(active_extruder)) { + if (thermalManager.tooColdToExtrude(motion.extruder)) { mmu2_attn_buzz(); LCD_ALERTMESSAGE(MSG_HOTEND_TOO_COLD); return false; diff --git a/Marlin/src/feature/mmu3/mmu3.cpp b/Marlin/src/feature/mmu3/mmu3.cpp index dd06126724..4c3c5e6fd7 100644 --- a/Marlin/src/feature/mmu3/mmu3.cpp +++ b/Marlin/src/feature/mmu3/mmu3.cpp @@ -362,12 +362,12 @@ namespace MMU3 { * in the slope's sign or check the last machine position. * y(x) * â–² - * │ ^◄────────── tryload_length + current_position + * │ ^◄────────── tryload_length + motion.position * machine │ / \ - * position │ / \◄────────── stepper_position_mm + current_position + * position │ / \◄────────── stepper_position_mm + motion.position * (mm) │ / \ * │ / \ - * │/ \◄───────current_position + * │/ \◄───────motion.position * └──────────────► x * 0 19 * pixel # diff --git a/Marlin/src/feature/mmu3/mmu3_marlin1.cpp b/Marlin/src/feature/mmu3/mmu3_marlin1.cpp index f12d83772a..aeddcbef40 100644 --- a/Marlin/src/feature/mmu3/mmu3_marlin1.cpp +++ b/Marlin/src/feature/mmu3/mmu3_marlin1.cpp @@ -41,7 +41,7 @@ namespace MMU3 { static void planner_line_to_current_position(float feedRate_mm_s) { - line_to_current_position(feedRate_mm_s); + motion.goto_current_position(feedRate_mm_s); } static void planner_line_to_current_position_sync(float feedRate_mm_s) { @@ -50,21 +50,21 @@ namespace MMU3 { } void extruder_move(const float delta, const float feedRate_mm_s, const bool sync/*=true*/) { - current_position.e += delta / planner.e_factor[active_extruder]; + motion.position.e += delta / planner.e_factor[motion.extruder]; planner_line_to_current_position(feedRate_mm_s); if (sync) planner.synchronize(); } float move_raise_z(const float delta) { //return raise_z(delta); - xyze_pos_t current_position_before = current_position; - do_z_clearance_by(delta); - return (current_position - current_position_before).z; + xyze_pos_t current_position_before = motion.position; + motion.do_z_clearance_by(delta); + return (motion.position - current_position_before).z; } void planner_abort_queued_moves() { //planner_abort_hard(); - quickstop_stepper(); + motion.quickstop_stepper(); // Unblock the planner. This should be safe in the // toolchange context. Currently we are mainly aborting @@ -75,41 +75,21 @@ namespace MMU3 { // eoyilmaz: we don't need this part, the print is not aborted } - void planner_synchronize() { - planner.synchronize(); - } - - bool planner_any_moves() { - return planner.has_blocks_queued(); - } - - float planner_get_machine_position_E_mm() { - return current_position.e; - } - - float stepper_get_machine_position_E_mm() { - return planner.get_axis_position_mm(E_AXIS); - } - - float planner_get_current_position_E() { - return current_position.e; - } - - void planner_set_current_position_E(float e) { - current_position.e = e; - } - - xyz_pos_t planner_current_position() { - return xyz_pos_t(current_position); - } + void planner_synchronize() { planner.synchronize(); } + bool planner_any_moves() { return planner.has_blocks_queued(); } + float planner_get_machine_position_E_mm() { return motion.position.e; } + float stepper_get_machine_position_E_mm() { return planner.get_axis_position_mm(E_AXIS); } + float planner_get_current_position_E() { return motion.position.e; } + void planner_set_current_position_E(float e) { motion.position.e = e; } + xyz_pos_t planner_current_position() { return xyz_pos_t(motion.position); } void motion_blocking_move_xy(float rx, float ry, float feedRate_mm_s) { - current_position.set(rx, ry); + motion.position.set(rx, ry); planner_line_to_current_position_sync(feedRate_mm_s); } void motion_blocking_move_z(float z, float feedRate_mm_s) { - current_position.z = z; + motion.position.z = z; planner_line_to_current_position_sync(feedRate_mm_s); } @@ -165,7 +145,7 @@ namespace MMU3 { void Disable_E0() { stepper.disable_extruder(TERN_(HAS_EXTRUDERS, 0)); } bool xy_are_trusted() { - return axis_is_trusted(X_AXIS) && axis_is_trusted(Y_AXIS); + return motion.axis_is_trusted(X_AXIS) && motion.axis_is_trusted(Y_AXIS); } } // MMU3 diff --git a/Marlin/src/feature/pause.cpp b/Marlin/src/feature/pause.cpp index 025bcb8383..1a188ca169 100644 --- a/Marlin/src/feature/pause.cpp +++ b/Marlin/src/feature/pause.cpp @@ -146,8 +146,8 @@ static bool ensure_safe_temperature(const bool wait=true, const PauseMode mode=P DEBUG_ECHOLNPGM("... wait:", wait, " mode:", mode); #if ENABLED(PREVENT_COLD_EXTRUSION) - if (!DEBUGGING(DRYRUN) && thermalManager.targetTooColdToExtrude(active_extruder)) - thermalManager.setTargetHotend(thermalManager.extrude_min_temp, active_extruder); + if (!DEBUGGING(DRYRUN) && thermalManager.targetTooColdToExtrude(motion.extruder)) + thermalManager.setTargetHotend(thermalManager.extrude_min_temp, motion.extruder); #endif ui.pause_show_message(PAUSE_MESSAGE_HEATING, mode); @@ -157,17 +157,17 @@ static bool ensure_safe_temperature(const bool wait=true, const PauseMode mode=P rts.updateTempE0(); #endif - if (wait) return thermalManager.wait_for_hotend(active_extruder); + if (wait) return thermalManager.wait_for_hotend(motion.extruder); // Allow interruption by Emergency Parser M108 marlin.wait_for_heatup = TERN1(PREVENT_COLD_EXTRUSION, !thermalManager.allow_cold_extrude); - while (marlin.is_heating() && ABS(thermalManager.wholeDegHotend(active_extruder) - thermalManager.degTargetHotend(active_extruder)) > (TEMP_WINDOW)) + while (marlin.is_heating() && ABS(thermalManager.wholeDegHotend(motion.extruder) - thermalManager.degTargetHotend(motion.extruder)) > (TEMP_WINDOW)) marlin.idle(); marlin.heatup_done(); #if ENABLED(PREVENT_COLD_EXTRUSION) // A user can cancel wait-for-heating with M108 - if (!DEBUGGING(DRYRUN) && thermalManager.targetTooColdToExtrude(active_extruder)) { + if (!DEBUGGING(DRYRUN) && thermalManager.targetTooColdToExtrude(motion.extruder)) { SERIAL_ECHO_MSG(STR_ERR_HOTEND_TOO_COLD); return false; } @@ -211,7 +211,7 @@ bool load_filament(const float slow_load_length/*=0*/, const float fast_load_len TERN_(EXTENSIBLE_UI, ExtUI::onUserConfirmRequired(GET_TEXT_F(MSG_FILAMENTLOAD))); #if ENABLED(HOST_PROMPT_SUPPORT) - const char tool = '0' + TERN0(MULTI_FILAMENT_SENSOR, active_extruder); + const char tool = '0' + TERN0(MULTI_FILAMENT_SENSOR, motion.extruder); hostui.prompt_do(PROMPT_USER_CONTINUE, F("Load Filament T"), tool, FPSTR(CONTINUE_STR)); #endif @@ -220,7 +220,7 @@ bool load_filament(const float slow_load_length/*=0*/, const float fast_load_len #if ALL(HAS_FILAMENT_SENSOR, FILAMENT_CHANGE_RESUME_ON_INSERT) #if MULTI_FILAMENT_SENSOR #define _CASE_INSERTED(N) case N-1: if (!FILAMENT_IS_OUT(N)) marlin.user_resume(); break; - switch (active_extruder) { + switch (motion.extruder) { REPEAT_1(NUM_RUNOUT_SENSORS, _CASE_INSERTED) } #else @@ -234,17 +234,17 @@ bool load_filament(const float slow_load_length/*=0*/, const float fast_load_len if (show_lcd) ui.pause_show_message(PAUSE_MESSAGE_LOAD, mode); #if ENABLED(DUAL_X_CARRIAGE) - const int8_t saved_ext = active_extruder; + const int8_t saved_ext = motion.extruder; const bool saved_ext_dup_mode = extruder_duplication_enabled; set_duplication_enabled(false, DXC_ext); #endif - TERN_(BELTPRINTER, do_blocking_move_to_xy(0.00, 50.00)); + TERN_(BELTPRINTER, motion.blocking_move_xy(0.00, 50.00)); TERN_(MPCTEMP, MPC::e_paused = true); // Slow Load filament - if (slow_load_length) unscaled_e_move(slow_load_length, FILAMENT_CHANGE_SLOW_LOAD_FEEDRATE); + if (slow_load_length) motion.unscaled_e_move(slow_load_length, FILAMENT_CHANGE_SLOW_LOAD_FEEDRATE); // Fast Load Filament if (fast_load_length) { @@ -253,7 +253,7 @@ bool load_filament(const float slow_load_length/*=0*/, const float fast_load_len planner.settings.retract_acceleration = FILAMENT_CHANGE_FAST_LOAD_ACCEL; #endif - unscaled_e_move(fast_load_length, FILAMENT_CHANGE_FAST_LOAD_FEEDRATE); + motion.unscaled_e_move(fast_load_length, FILAMENT_CHANGE_FAST_LOAD_FEEDRATE); #if FILAMENT_CHANGE_FAST_LOAD_ACCEL > 0 planner.settings.retract_acceleration = saved_acceleration; @@ -272,7 +272,7 @@ bool load_filament(const float slow_load_length/*=0*/, const float fast_load_len TERN_(HOST_PROMPT_SUPPORT, hostui.continue_prompt(GET_TEXT_F(MSG_FILAMENT_CHANGE_PURGE))); marlin.wait_start(); // A click or M108 breaks the purge_length loop for (float purge_count = purge_length; purge_count > 0 && marlin.wait_for_user; --purge_count) - unscaled_e_move(1, ADVANCED_PAUSE_PURGE_FEEDRATE); + motion.unscaled_e_move(1, ADVANCED_PAUSE_PURGE_FEEDRATE); marlin.user_resume(); #else @@ -288,7 +288,7 @@ bool load_filament(const float slow_load_length/*=0*/, const float fast_load_len #endif // Extrude filament to get into hotend - unscaled_e_move(purge_length, ADVANCED_PAUSE_PURGE_FEEDRATE); + motion.unscaled_e_move(purge_length, ADVANCED_PAUSE_PURGE_FEEDRATE); } TERN_(HOST_PROMPT_SUPPORT, hostui.filament_load_prompt()); // Initiate another host prompt. @@ -327,7 +327,7 @@ bool load_filament(const float slow_load_length/*=0*/, const float fast_load_len */ inline void disable_active_extruder() { #if HAS_EXTRUDERS - stepper.DISABLE_EXTRUDER(active_extruder); + stepper.DISABLE_EXTRUDER(motion.extruder); safe_delay(100); #endif } @@ -372,13 +372,13 @@ bool unload_filament(const float unload_length, const bool show_lcd/*=false*/, #endif // Retract filament - unscaled_e_move(-(FILAMENT_UNLOAD_PURGE_RETRACT) * mix_multiplier, (PAUSE_PARK_RETRACT_FEEDRATE) * mix_multiplier); + motion.unscaled_e_move(-(FILAMENT_UNLOAD_PURGE_RETRACT) * mix_multiplier, (PAUSE_PARK_RETRACT_FEEDRATE) * mix_multiplier); // Wait for filament to cool safe_delay(FILAMENT_UNLOAD_PURGE_DELAY); // Quickly purge - unscaled_e_move((FILAMENT_UNLOAD_PURGE_RETRACT + FILAMENT_UNLOAD_PURGE_LENGTH) * mix_multiplier, + motion.unscaled_e_move((FILAMENT_UNLOAD_PURGE_RETRACT + FILAMENT_UNLOAD_PURGE_LENGTH) * mix_multiplier, (FILAMENT_UNLOAD_PURGE_FEEDRATE) * mix_multiplier); // Unload filament @@ -387,7 +387,7 @@ bool unload_filament(const float unload_length, const bool show_lcd/*=false*/, planner.settings.retract_acceleration = FILAMENT_CHANGE_UNLOAD_ACCEL; #endif - unscaled_e_move(unload_length * mix_multiplier, (FILAMENT_CHANGE_UNLOAD_FEEDRATE) * mix_multiplier); + motion.unscaled_e_move(unload_length * mix_multiplier, (FILAMENT_CHANGE_UNLOAD_FEEDRATE) * mix_multiplier); #if FILAMENT_CHANGE_FAST_LOAD_ACCEL > 0 planner.settings.retract_acceleration = saved_acceleration; @@ -447,14 +447,14 @@ bool pause_print(const float retract, const xyz_pos_t &park_point, const bool sh print_job_timer.pause(); // Save current position - resume_position = current_position; + resume_position = motion.position; // Will the nozzle be parking? - const bool do_park = !axes_should_home(); + const bool do_park = !motion.axes_should_home(); #if ENABLED(POWER_LOSS_RECOVERY) // Save PLR info in case the power goes out while parked - const float park_raise = do_park ? nozzle.park_mode_0_height(park_point.z) - current_position.z : POWER_LOSS_ZRAISE; + const float park_raise = do_park ? nozzle.park_mode_0_height(park_point.z) - motion.position.z : POWER_LOSS_ZRAISE; if (was_sd_printing && recovery.enabled) recovery.save(true, park_raise, do_park); #endif @@ -466,7 +466,7 @@ bool pause_print(const float retract, const xyz_pos_t &park_point, const bool sh #endif // Initial retract before move to filament change position - if (retract && thermalManager.hotEnoughToExtrude(active_extruder)) { + if (retract && thermalManager.hotEnoughToExtrude(motion.extruder)) { DEBUG_ECHOLNPGM("... retract:", retract); #if ENABLED(AUTO_BED_LEVELING_UBL) @@ -474,7 +474,7 @@ bool pause_print(const float retract, const xyz_pos_t &park_point, const bool sh set_bed_leveling_enabled(false); // turn off leveling #endif - unscaled_e_move(retract, PAUSE_PARK_RETRACT_FEEDRATE); + motion.unscaled_e_move(retract, PAUSE_PARK_RETRACT_FEEDRATE); TERN_(AUTO_BED_LEVELING_UBL, set_bed_leveling_enabled(leveling_was_enabled)); // restore leveling } @@ -484,7 +484,7 @@ bool pause_print(const float retract, const xyz_pos_t &park_point, const bool sh if (!do_park) LCD_MESSAGE(MSG_PARK_FAILED); #if ENABLED(DUAL_X_CARRIAGE) - const int8_t saved_ext = active_extruder; + const int8_t saved_ext = motion.extruder; const bool saved_ext_dup_mode = extruder_duplication_enabled; set_duplication_enabled(false, DXC_ext); #endif @@ -544,7 +544,7 @@ void wait_for_confirmation(const bool is_reload/*=false*/, const int8_t max_beep HOTEND_LOOP() thermalManager.heater_idle[e].start(nozzle_timeout); #if ENABLED(DUAL_X_CARRIAGE) - const int8_t saved_ext = active_extruder; + const int8_t saved_ext = motion.extruder; const bool saved_ext_dup_mode = extruder_duplication_enabled; set_duplication_enabled(false, DXC_ext); #endif @@ -662,7 +662,7 @@ void resume_print( SERIAL_ECHOLNPGM( "start of resume_print()\ndual_x_carriage_mode:", dual_x_carriage_mode, "\nextruder_duplication_enabled:", extruder_duplication_enabled, - "\nactive_extruder:", active_extruder, + "\nactive_extruder:", motion.extruder, "\n" ); //*/ @@ -676,15 +676,15 @@ void resume_print( thermalManager.reset_hotend_idle_timer(e); } - if (targetTemp > thermalManager.degTargetHotend(active_extruder)) - thermalManager.setTargetHotend(targetTemp, active_extruder); + if (targetTemp > thermalManager.degTargetHotend(motion.extruder)) + thermalManager.setTargetHotend(targetTemp, motion.extruder); // Load the new filament load_filament(slow_load_length, fast_load_length, purge_length, max_beep_count, show_lcd, nozzle_timed_out, PAUSE_MODE_SAME DXC_PASS); if (targetTemp > 0) { - thermalManager.setTargetHotend(targetTemp, active_extruder); - thermalManager.wait_for_hotend(active_extruder, false); + thermalManager.setTargetHotend(targetTemp, motion.extruder); + thermalManager.wait_for_hotend(motion.extruder, false); } ui.pause_show_message(PAUSE_MESSAGE_RESUME); @@ -693,16 +693,16 @@ void resume_print( ensure_safe_temperature(DISABLED(BELTPRINTER)); // Retract to prevent oozing - unscaled_e_move(-(PAUSE_PARK_RETRACT_LENGTH), feedRate_t(PAUSE_PARK_RETRACT_FEEDRATE)); + motion.unscaled_e_move(-(PAUSE_PARK_RETRACT_LENGTH), feedRate_t(PAUSE_PARK_RETRACT_FEEDRATE)); - if (!axes_should_home()) { + if (!motion.axes_should_home()) { // Move XY back to saved position - destination.set(resume_position.x, resume_position.y, current_position.z, current_position.e); - prepare_internal_move_to_destination(NOZZLE_PARK_XY_FEEDRATE); + motion.destination.set(resume_position.x, resume_position.y, motion.position.z, motion.position.e); + motion.prepare_internal_move_to_destination(NOZZLE_PARK_XY_FEEDRATE); // Move Z back to saved position - destination.z = resume_position.z; - prepare_internal_move_to_destination(NOZZLE_PARK_Z_FEEDRATE); + motion.destination.z = resume_position.z; + motion.prepare_internal_move_to_destination(NOZZLE_PARK_Z_FEEDRATE); } #if ENABLED(AUTO_BED_LEVELING_UBL) @@ -711,27 +711,27 @@ void resume_print( #endif // Unretract - unscaled_e_move(PAUSE_PARK_RETRACT_LENGTH, feedRate_t(PAUSE_PARK_RETRACT_FEEDRATE)); + motion.unscaled_e_move(PAUSE_PARK_RETRACT_LENGTH, feedRate_t(PAUSE_PARK_RETRACT_FEEDRATE)); TERN_(AUTO_BED_LEVELING_UBL, set_bed_leveling_enabled(leveling_was_enabled)); // restore leveling // Intelligent resuming #if ENABLED(FWRETRACT) // If retracted before goto pause - if (fwretract.retracted[active_extruder]) - unscaled_e_move(-fwretract.settings.retract_length, fwretract.settings.retract_feedrate_mm_s); + if (fwretract.retracted[motion.extruder]) + motion.unscaled_e_move(-fwretract.settings.retract_length, fwretract.settings.retract_feedrate_mm_s); #endif // If resume_position is negative - if (resume_position.e < 0) unscaled_e_move(resume_position.e, feedRate_t(PAUSE_PARK_RETRACT_FEEDRATE)); + if (resume_position.e < 0) motion.unscaled_e_move(resume_position.e, feedRate_t(PAUSE_PARK_RETRACT_FEEDRATE)); #ifdef ADVANCED_PAUSE_RESUME_PRIME if (ADVANCED_PAUSE_RESUME_PRIME != 0) - unscaled_e_move(ADVANCED_PAUSE_RESUME_PRIME, feedRate_t(ADVANCED_PAUSE_PURGE_FEEDRATE)); + motion.unscaled_e_move(ADVANCED_PAUSE_RESUME_PRIME, feedRate_t(ADVANCED_PAUSE_PURGE_FEEDRATE)); #endif // Now all extrusion positions are resumed and ready to be confirmed // Set extruder to saved position - planner.set_e_position_mm((destination.e = current_position.e = resume_position.e)); + planner.set_e_position_mm((motion.destination.e = motion.position.e = resume_position.e)); ui.pause_show_message(PAUSE_MESSAGE_STATUS); #if ENABLED(SOVOL_SV06_RTS) diff --git a/Marlin/src/feature/powerloss.cpp b/Marlin/src/feature/powerloss.cpp index 0dd19808bc..1620b0bb2e 100644 --- a/Marlin/src/feature/powerloss.cpp +++ b/Marlin/src/feature/powerloss.cpp @@ -200,7 +200,7 @@ void PrintJobRecovery::save(const bool force/*=false*/, const float zraise/*=POW || ELAPSED(ms, next_save_ms) #endif // Save if Z is above the last-saved position by some minimum height - || current_position.z > info.current_position.z + POWER_LOSS_MIN_Z_CHANGE + || motion.position.z > info.current_position.z + POWER_LOSS_MIN_Z_CHANGE #endif ) { @@ -216,8 +216,8 @@ void PrintJobRecovery::save(const bool force/*=false*/, const float zraise/*=POW // Machine state // info.sdpos and info.current_position are pre-filled from the Stepper ISR - info.feedrate = uint16_t(MMS_TO_MMM(feedrate_mm_s)); - info.feedrate_percentage = feedrate_percentage; + info.feedrate = uint16_t(MMS_TO_MMM(motion.feedrate_mm_s)); + info.feedrate_percentage = motion.feedrate_percentage; COPY(info.flow_percentage, planner.flow_percentage); info.zraise = zraise; @@ -225,16 +225,16 @@ void PrintJobRecovery::save(const bool force/*=false*/, const float zraise/*=POW TERN_(CANCEL_OBJECTS, info.cancel_state = cancelable.state); TERN_(GCODE_REPEAT_MARKERS, info.stored_repeat = repeat); - TERN_(HAS_HOME_OFFSET, info.home_offset = home_offset); - TERN_(HAS_WORKSPACE_OFFSET, info.workspace_offset = workspace_offset); - E_TERN_(info.active_extruder = active_extruder); + TERN_(HAS_HOME_OFFSET, info.home_offset = motion.home_offset); + TERN_(HAS_WORKSPACE_OFFSET, info.workspace_offset = motion.workspace_offset); + E_TERN_(info.extruder = motion.extruder); #if HAS_VOLUMETRIC_EXTRUSION info.flag.volumetric_enabled = parser.volumetric_enabled; #if HAS_MULTI_EXTRUDER COPY(info.filament_size, planner.filament_size); #else - if (parser.volumetric_enabled) info.filament_size[0] = planner.filament_size[active_extruder]; + if (parser.volumetric_enabled) info.filament_size[0] = planner.filament_size[motion.extruder]; #endif #endif @@ -285,10 +285,10 @@ void PrintJobRecovery::save(const bool force/*=false*/, const float zraise/*=POW #if POWER_LOSS_RETRACT_LEN // Retract filament now - const uint16_t old_flow = planner.flow_percentage[active_extruder]; - planner.set_flow(active_extruder, 100); + const uint16_t old_flow = planner.flow_percentage[motion.extruder]; + planner.set_flow(motion.extruder, 100); gcode.process_subcommands_now(F("G1F3000E-" STRINGIFY(POWER_LOSS_RETRACT_LEN))); - planner.set_flow(active_extruder, old_flow); + planner.set_flow(motion.extruder, old_flow); #endif #if POWER_LOSS_ZRAISE @@ -327,7 +327,7 @@ void PrintJobRecovery::save(const bool force/*=false*/, const float zraise/*=POW #if POWER_LOSS_ZRAISE // Get the limited Z-raise to do now or on resume - const float zraise = _MAX(0, _MIN(current_position.z + POWER_LOSS_ZRAISE, Z_MAX_POS - 1) - current_position.z); + const float zraise = _MAX(0, _MIN(motion.position.z + POWER_LOSS_ZRAISE, Z_MAX_POS - 1) - motion.position.z); #else constexpr float zraise = 0; #endif @@ -344,15 +344,15 @@ void PrintJobRecovery::save(const bool force/*=false*/, const float zraise/*=POW #if ENABLED(BACKUP_POWER_SUPPLY) // Do a hard-stop of the steppers (with possibly a loud thud) - quickstop_stepper(); + motion.quickstop_stepper(); // With backup power a retract and raise can be done now retract_and_lift(zraise); #endif if (TERN0(DEBUG_POWER_LOSS_RECOVERY, simulated)) { card.fileHasFinished(); - current_position.reset(); - sync_plan_position(); + motion.position.reset(); + motion.sync_plan_position(); } else marlin.kill(GET_TEXT_F(MSG_OUTAGE_RECOVERY)); @@ -489,8 +489,8 @@ void PrintJobRecovery::resume() { PROCESS_SUBCOMMANDS_NOW(TS(F("G1F1000X"), p_float_t(p.x, 3), 'Y', p_float_t(p.y, 3), F("\nG28HZ"))); #endif - // Mark all axes as having been homed (no effect on current_position) - set_all_homed(); + // Mark all axes as having been homed (no effect on motion.position) + motion.set_all_homed(); #if HAS_LEVELING // Restore Z fade and possibly re-enable bed leveling compensation. @@ -516,7 +516,7 @@ void PrintJobRecovery::resume() { EXTRUDER_LOOP() PROCESS_SUBCOMMANDS_NOW(TS(F("M200T"), e, F("D"), p_float_t(info.filament_size[e], 3))); if (!info.flag.volumetric_enabled) - PROCESS_SUBCOMMANDS_NOW(TS(F("M200D0T"), info.active_extruder)); + PROCESS_SUBCOMMANDS_NOW(TS(F("M200D0T"), info.extruder)); #else if (info.flag.volumetric_enabled) PROCESS_SUBCOMMANDS_NOW(TS(F("M200D"), p_float_t(info.filament_size[0], 3))); @@ -536,7 +536,7 @@ void PrintJobRecovery::resume() { // Restore the previously active tool (with no_move) #if HAS_MULTI_EXTRUDER || HAS_MULTI_HOTEND - PROCESS_SUBCOMMANDS_NOW(TS('T', info.active_extruder, 'S')); + PROCESS_SUBCOMMANDS_NOW(TS('T', info.extruder, 'S')); #endif // Restore print cooling fan speeds @@ -586,7 +586,7 @@ void PrintJobRecovery::resume() { // Restore the feedrate and percentage PROCESS_SUBCOMMANDS_NOW(TS(F("G1F"), info.feedrate)); - feedrate_percentage = info.feedrate_percentage; + motion.feedrate_percentage = info.feedrate_percentage; // Flowrate percentage EXTRUDER_LOOP() planner.set_flow(e, info.flow_percentage[e]); @@ -600,8 +600,8 @@ void PrintJobRecovery::resume() { #endif TERN_(GCODE_REPEAT_MARKERS, repeat = info.stored_repeat); - TERN_(HAS_HOME_OFFSET, home_offset = info.home_offset); - TERN_(HAS_WORKSPACE_OFFSET, workspace_offset = info.workspace_offset); + TERN_(HAS_HOME_OFFSET, motion.home_offset = info.home_offset); + TERN_(HAS_WORKSPACE_OFFSET, motion.workspace_offset = info.workspace_offset); // Relative axis modes gcode.axis_relative = info.axis_relative; @@ -625,7 +625,7 @@ void PrintJobRecovery::resume() { DEBUG_ECHOLN(prefix, F(" Job Recovery Info...\nvalid_head:"), info.valid_head, F(" valid_foot:"), info.valid_foot); if (info.valid_head) { if (info.valid_head == info.valid_foot) { - DEBUG_ECHOPGM("current_position: "); + DEBUG_ECHOPGM("curr.position: "); LOOP_LOGICAL_AXES(i) { if (i) DEBUG_CHAR(','); DEBUG_ECHO(info.current_position[i]); @@ -671,7 +671,7 @@ void PrintJobRecovery::resume() { #endif #if HAS_MULTI_EXTRUDER - DEBUG_ECHOLNPGM("active_extruder: ", info.active_extruder); + DEBUG_ECHOLNPGM("extruder: ", info.extruder); #endif #if HAS_VOLUMETRIC_EXTRUSION diff --git a/Marlin/src/feature/powerloss.h b/Marlin/src/feature/powerloss.h index bfa5b4717f..df17f956ed 100644 --- a/Marlin/src/feature/powerloss.h +++ b/Marlin/src/feature/powerloss.h @@ -85,7 +85,7 @@ typedef struct { xyz_pos_t workspace_offset; #endif #if HAS_MULTI_EXTRUDER - uint8_t active_extruder; + uint8_t extruder; #endif #if HAS_VOLUMETRIC_EXTRUSION diff --git a/Marlin/src/feature/runout.h b/Marlin/src/feature/runout.h index 7881af4e38..dec89c3791 100644 --- a/Marlin/src/feature/runout.h +++ b/Marlin/src/feature/runout.h @@ -154,12 +154,12 @@ class TFilamentMonitor : public FilamentMonitorBase { uint8_t extruder = 0; if (ran_out) while (!runout_flags.test(extruder)) extruder++; #else - const bool ran_out = runout_flags[active_extruder]; // suppress non active extruders - uint8_t extruder = active_extruder; + const bool ran_out = runout_flags[motion.extruder]; // suppress non active extruders + uint8_t extruder = motion.extruder; #endif #else const bool ran_out = bool(runout_flags); - uint8_t extruder = active_extruder; + uint8_t extruder = motion.extruder; #endif if (!ran_out) return; diff --git a/Marlin/src/feature/solenoid.cpp b/Marlin/src/feature/solenoid.cpp index cc4522e30a..33799c5ffb 100644 --- a/Marlin/src/feature/solenoid.cpp +++ b/Marlin/src/feature/solenoid.cpp @@ -26,7 +26,7 @@ #include "solenoid.h" -#include "../module/motion.h" // for active_extruder +#include "../module/motion.h" // for motion.extruder #include "../module/tool_change.h" // for parking_extruder_set_parked // Used primarily with MANUAL_SOLENOID_CONTROL @@ -38,7 +38,7 @@ static void set_solenoid(const uint8_t num, const uint8_t state) { } #if ENABLED(PARKING_EXTRUDER) - if (state == LOW && active_extruder == num) // If active extruder's solenoid is disabled, carriage is considered parked + if (state == LOW && motion.extruder == num) // If active extruder's solenoid is disabled, carriage is considered parked parking_extruder_set_parked(true); #endif } diff --git a/Marlin/src/feature/tramming.cpp b/Marlin/src/feature/tramming.cpp index 3721c5eb81..cd49ed90b3 100644 --- a/Marlin/src/feature/tramming.cpp +++ b/Marlin/src/feature/tramming.cpp @@ -41,7 +41,7 @@ PGM_P const tramming_point_name[] PROGMEM = { REPLIST_1(_NR_TRAM_NAMES, _TRAM_NA void move_to_tramming_wait_pos() { constexpr xyz_pos_t wait_pos = ASSISTED_TRAMMING_WAIT_POSITION; if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("Moving away"); - do_blocking_move_to(wait_pos, XY_PROBE_FEEDRATE_MM_S); + motion.blocking_move(wait_pos, XY_PROBE_FEEDRATE_MM_S); } #endif diff --git a/Marlin/src/gcode/bedlevel/G26.cpp b/Marlin/src/gcode/bedlevel/G26.cpp index 899498faae..dab99c300c 100644 --- a/Marlin/src/gcode/bedlevel/G26.cpp +++ b/Marlin/src/gcode/bedlevel/G26.cpp @@ -174,25 +174,25 @@ void move_to(const float rx, const float ry, const float z, const float e_delta) const xy_pos_t dest = { rx, ry }; - const bool has_xy_component = dest != current_position, // Check if X or Y is involved in the movement. + const bool has_xy_component = dest != motion.position, // Check if X or Y is involved in the movement. has_e_component = e_delta != 0.0; if (z != last_z) { last_z = z; - destination.set(current_position.x, current_position.y, z, current_position.e); + motion.destination.set(motion.position.x, motion.position.y, z, motion.position.e); const feedRate_t fr_mm_s = planner.settings.max_feedrate_mm_s[Z_AXIS] * 0.5f; // Use half of the Z_AXIS max feed rate - prepare_internal_move_to_destination(fr_mm_s); + motion.prepare_internal_move_to_destination(fr_mm_s); } // If X or Y in combination with E is involved do a 'normal' move. // If X or Y with no E is involved do a 'fast' move // Otherwise retract/recover/hop. - destination = dest; - destination.e += e_delta; + motion.destination = dest; + motion.destination.e += e_delta; const feedRate_t fr_mm_s = has_xy_component ? (has_e_component ? feedRate_t(G26_XY_FEEDRATE) : feedRate_t(G26_XY_FEEDRATE_TRAVEL)) : planner.settings.max_feedrate_mm_s[E_AXIS] * 0.666f; - prepare_internal_move_to_destination(fr_mm_s); + motion.prepare_internal_move_to_destination(fr_mm_s); } void move_to(const xyz_pos_t &where, const float de) { move_to(where.x, where.y, where.z, de); } @@ -229,8 +229,8 @@ typedef struct { // TODO: Parameterize the Z lift with a define void retract_lift_move(const xyz_pos_t &s) { - retract_filament(destination); - move_to(current_position.x, current_position.y, current_position.z + 0.5f, 0.0f); // Z lift to minimize scraping + retract_filament(motion.destination); + move_to(motion.position.x, motion.position.y, motion.position.z + 0.5f, 0.0f); // Z lift to minimize scraping move_to(s.x, s.y, s.z + 0.5f, 0.0f); // Get to the starting point with no extrusion while lifted } @@ -259,7 +259,7 @@ typedef struct { void print_line_from_here_to_there(const xyz_pos_t &s, const xyz_pos_t &e) { // Distances to the start / end of the line - xy_float_t svec = current_position - s, evec = current_position - e; + xy_float_t svec = motion.position - s, evec = motion.position - e; const float dist_start = HYPOT2(svec.x, svec.y), dist_end = HYPOT2(evec.x, evec.y), @@ -279,7 +279,7 @@ typedef struct { const float e_pos_delta = line_length * g26_e_axis_feedrate * extrusion_multiplier; - recover_filament(destination); + recover_filament(motion.destination); move_to(e, e_pos_delta); // Get to the ending point with an appropriate amount of extrusion } @@ -306,7 +306,7 @@ typedef struct { LIMIT(e.x, X_MIN_POS + 1, X_MAX_POS - 1); #endif - if (position_is_reachable(s) && position_is_reachable(e)) + if (motion.can_reach(s) && motion.can_reach(e)) print_line_from_here_to_there(s, e); } } @@ -341,10 +341,10 @@ typedef struct { // Start heating the active nozzle LCD_MESSAGE_MAX(MSG_G26_HEATING_NOZZLE); ui.quick_feedback(); - thermalManager.setTargetHotend(hotend_temp, active_extruder); + thermalManager.setTargetHotend(hotend_temp, motion.extruder); // Wait for the temperature to stabilize - if (!thermalManager.wait_for_hotend(active_extruder, true OPTARG(G26_CLICK_CAN_CANCEL, true))) + if (!thermalManager.wait_for_hotend(motion.extruder, true OPTARG(G26_CLICK_CAN_CANCEL, true))) return G26_ERR; ui.reset_status(); @@ -369,13 +369,13 @@ typedef struct { LCD_MESSAGE_MAX(MSG_G26_MANUAL_PRIME); ui.chirp(); - destination = current_position; + motion.destination = motion.position; - recover_filament(destination); // Make sure G26 doesn't think the filament is retracted(). + recover_filament(motion.destination); // Make sure G26 doesn't think the filament is retracted(). while (!ui.button_pressed()) { ui.chirp(); - destination.e += 0.25; + motion.destination.e += 0.25; #if ENABLED(PREVENT_LENGTHY_EXTRUDE) Total_Prime += 0.25; if (Total_Prime >= EXTRUDE_MAXLENGTH) { @@ -383,8 +383,8 @@ typedef struct { return G26_ERR; } #endif - prepare_internal_move_to_destination(fr_slow_e); - destination = current_position; + motion.prepare_internal_move_to_destination(fr_slow_e); + motion.destination = motion.position; planner.synchronize(); // Without this synchronize, the purge is more consistent, // but because the planner has a buffer, we won't be able // to stop as quickly. So we put up with the less smooth @@ -402,11 +402,11 @@ typedef struct { { LCD_MESSAGE_MAX(MSG_G26_FIXED_LENGTH); ui.quick_feedback(); - destination = current_position; - destination.e += prime_length; - prepare_internal_move_to_destination(fr_slow_e); - destination.e -= prime_length; - retract_filament(destination); + motion.destination = motion.position; + motion.destination.e += prime_length; + motion.prepare_internal_move_to_destination(fr_slow_e); + motion.destination.e -= prime_length; + retract_filament(motion.destination); } return G26_OK; @@ -500,7 +500,7 @@ void GcodeSuite::G26() { // Don't allow Mesh Validation without homing first, // or if the parameter parsing did not go OK, abort - if (homing_needed_error()) return; + if (motion.homing_needed_error()) return; #if HAS_TOOLCHANGE // Change the tool first, if specified @@ -616,7 +616,7 @@ void GcodeSuite::G26() { // If any preset or temperature was specified if (noztemp) { - if (!WITHIN(noztemp, 165, thermalManager.hotend_max_target(active_extruder))) { + if (!WITHIN(noztemp, 165, thermalManager.hotend_max_target(motion.extruder))) { SERIAL_ECHOLNPGM(GCODE_ERR_MSG("Specified nozzle temperature not plausible.")); return; } @@ -647,10 +647,10 @@ void GcodeSuite::G26() { return; } - // Set a position with 'X' and/or 'Y'. Default: current_position - g26.xy_pos.set(parser.seenval('X') ? RAW_X_POSITION(parser.value_linear_units()) : current_position.x, - parser.seenval('Y') ? RAW_Y_POSITION(parser.value_linear_units()) : current_position.y); - if (!position_is_reachable(g26.xy_pos)) { + // Set a position with 'X' and/or 'Y'. Default: motion.position + g26.xy_pos.set(parser.seenval('X') ? motion.raw_x(parser.value_linear_units()) : motion.position.x, + parser.seenval('Y') ? motion.raw_y(parser.value_linear_units()) : motion.position.y); + if (!motion.can_reach(g26.xy_pos)) { SERIAL_ECHOLNPGM(GCODE_ERR_MSG("Specified X,Y coordinate out of bounds.")); return; } @@ -660,7 +660,7 @@ void GcodeSuite::G26() { */ set_bed_leveling_enabled(!parser.seen_test('D')); - do_z_clearance(Z_CLEARANCE_BETWEEN_PROBES); + motion.do_z_clearance(Z_CLEARANCE_BETWEEN_PROBES); #if HAS_VOLUMETRIC_EXTRUSION bool volumetric_was_enabled = parser.volumetric_enabled; @@ -670,8 +670,7 @@ void GcodeSuite::G26() { if (g26.turn_on_heaters() != G26_OK) goto LEAVE; - current_position.e = 0.0; - sync_plan_position_e(); + motion.set_and_sync_e(0.0f); if (g26.prime_flag && g26.prime_nozzle() != G26_OK) goto LEAVE; @@ -688,10 +687,10 @@ void GcodeSuite::G26() { circle_flags.reset(); // Move nozzle to the specified height for the first layer - destination = current_position; - destination.z = g26.layer_height; - move_to(destination, 0.0); - move_to(destination, g26.ooze_amount); + motion.destination = motion.position; + motion.destination.z = g26.layer_height; + move_to(motion.destination, 0.0); + move_to(motion.destination, g26.ooze_amount); TERN_(HAS_MARLINUI_MENU, ui.capture()); @@ -719,14 +718,14 @@ void GcodeSuite::G26() { TERN_(EXTENSIBLE_UI, ExtUI::onMeshUpdate(location.pos, ExtUI::G26_START)); do { // Find the nearest confluence - location = g26.find_closest_circle_to_print(g26.continue_with_closest ? xy_pos_t(current_position) : g26.xy_pos); + location = g26.find_closest_circle_to_print(g26.continue_with_closest ? xy_pos_t(motion.position) : g26.xy_pos); if (location.valid()) { TERN_(EXTENSIBLE_UI, ExtUI::onMeshUpdate(location.pos, ExtUI::G26_POINT_START)); const xy_pos_t circle = { bedlevel.get_mesh_x(location.pos.a), bedlevel.get_mesh_y(location.pos.b) }; // If this mesh location is outside the printable radius, skip it. - if (!position_is_reachable(circle)) continue; + if (!motion.can_reach(circle)) continue; // Determine where to start and end the circle, // which is always drawn counter-clockwise. @@ -767,11 +766,11 @@ void GcodeSuite::G26() { } const ab_float_t arc_offset = circle - s; - const xy_float_t dist = current_position - s; // Distance from the start of the actual circle + const xy_float_t dist = motion.position - s; // Distance from the start of the actual circle const float dist_start = HYPOT2(dist.x, dist.y); const xyze_pos_t endpoint = { e.x, e.y, g26.layer_height, - current_position.e + (arc_length * g26_e_axis_feedrate * g26.extrusion_multiplier) + motion.position.e + (arc_length * g26_e_axis_feedrate * g26.extrusion_multiplier) }; if (dist_start > 2.0) { @@ -782,11 +781,11 @@ void GcodeSuite::G26() { s.z = g26.layer_height; move_to(s, 0.0); // Get to the starting point with no extrusion / un-Z lift - g26.recover_filament(destination); + g26.recover_filament(motion.destination); - { REMEMBER(fr, feedrate_mm_s, PLANNER_XY_FEEDRATE_MM_S * 0.1f); + { REMEMBER(fr, motion.feedrate_mm_s, PLANNER_XY_FEEDRATE_MM_S * 0.1f); plan_arc(endpoint, arc_offset, false, 0); // Draw a counter-clockwise arc - destination = current_position; + motion.destination = motion.position; } if (TERN0(HAS_MARLINUI_MENU, user_canceled())) goto LEAVE; // Check if the user wants to stop the Mesh Validation @@ -820,7 +819,7 @@ void GcodeSuite::G26() { #if IS_KINEMATIC // Check to make sure this segment is entirely on the bed, skip if not. - if (!position_is_reachable(p) || !position_is_reachable(q)) continue; + if (!motion.can_reach(p) || !motion.can_reach(q)) continue; #elif HAS_ENDSTOPS LIMIT(p.x, X_MIN_POS + 1, X_MAX_POS - 1); // Prevent hitting the endstops LIMIT(p.y, Y_MIN_POS + 1, Y_MAX_POS - 1); @@ -851,9 +850,9 @@ void GcodeSuite::G26() { LCD_MESSAGE_MIN(MSG_G26_LEAVING); TERN_(EXTENSIBLE_UI, ExtUI::onMeshUpdate(location, ExtUI::G26_FINISH)); - g26.retract_filament(destination); - destination.z = Z_CLEARANCE_BETWEEN_PROBES; - move_to(destination, 0); // Raise the nozzle + g26.retract_filament(motion.destination); + motion.destination.z = Z_CLEARANCE_BETWEEN_PROBES; + move_to(motion.destination, 0); // Raise the nozzle #if HAS_VOLUMETRIC_EXTRUSION parser.volumetric_enabled = volumetric_was_enabled; @@ -864,7 +863,7 @@ void GcodeSuite::G26() { if (!g26.keep_heaters_on) { TERN_(HAS_HEATED_BED, thermalManager.setTargetBed(0)); - thermalManager.setTargetHotend(active_extruder, 0); + thermalManager.setTargetHotend(motion.extruder, 0); } } diff --git a/Marlin/src/gcode/bedlevel/G35.cpp b/Marlin/src/gcode/bedlevel/G35.cpp index b3c56b49b3..0c9c4651e3 100644 --- a/Marlin/src/gcode/bedlevel/G35.cpp +++ b/Marlin/src/gcode/bedlevel/G35.cpp @@ -87,7 +87,7 @@ void GcodeSuite::G35() { TERN_(HAS_DUPLICATION_MODE, set_duplication_enabled(false)); // Home only Z axis when X and Y is trusted, otherwise all axes, if needed before this procedure - if (!all_axes_trusted()) process_subcommands_now(F("G28Z")); + if (!motion.all_axes_trusted()) process_subcommands_now(F("G28Z")); bool err_break = false; @@ -153,7 +153,7 @@ void GcodeSuite::G35() { move_to_tramming_wait_pos(); // After this operation the Z position needs correction - set_axis_never_homed(Z_AXIS); + motion.set_axis_never_homed(Z_AXIS); } #endif // ASSISTED_TRAMMING diff --git a/Marlin/src/gcode/bedlevel/G42.cpp b/Marlin/src/gcode/bedlevel/G42.cpp index 4b9b028419..dec0ee2b5f 100644 --- a/Marlin/src/gcode/bedlevel/G42.cpp +++ b/Marlin/src/gcode/bedlevel/G42.cpp @@ -54,16 +54,16 @@ void GcodeSuite::G42() { return; } - // Move to current_position, as modified by I, J, P parameters - destination = current_position; + // Move to motion.position, as modified by I, J, P parameters + motion.destination = motion.position; - if (hasI) destination.x = bedlevel.get_mesh_x(ix); - if (hasJ) destination.y = bedlevel.get_mesh_y(iy); + if (hasI) motion.destination.x = bedlevel.get_mesh_x(ix); + if (hasJ) motion.destination.y = bedlevel.get_mesh_y(iy); #if HAS_PROBE_XY_OFFSET if (parser.seen_test('P')) { - if (hasI) destination.x -= probe.offset_xy.x; - if (hasJ) destination.y -= probe.offset_xy.y; + if (hasI) motion.destination.x -= probe.offset_xy.x; + if (hasJ) motion.destination.y -= probe.offset_xy.y; } #endif @@ -72,9 +72,9 @@ void GcodeSuite::G42() { // SCARA kinematic has "safe" XY raw moves #if IS_SCARA - prepare_internal_fast_move_to_destination(fr_mm_s); + motion.prepare_internal_fast_move_to_destination(fr_mm_s); #else - prepare_internal_move_to_destination(fr_mm_s); + motion.prepare_internal_move_to_destination(fr_mm_s); #endif } diff --git a/Marlin/src/gcode/bedlevel/M420.cpp b/Marlin/src/gcode/bedlevel/M420.cpp index 05fa98e459..680d99fe46 100644 --- a/Marlin/src/gcode/bedlevel/M420.cpp +++ b/Marlin/src/gcode/bedlevel/M420.cpp @@ -90,7 +90,7 @@ void GcodeSuite::M420() { } #endif - xyz_pos_t oldpos = current_position; + xyz_pos_t oldpos = motion.position; // If disabling leveling do it right away // (Don't disable for just M420 or M420 V) @@ -240,8 +240,8 @@ void GcodeSuite::M420() { #endif // Report change in position - if (oldpos != current_position) - report_current_position(); + if (oldpos != motion.position) + motion.report_position(); } void GcodeSuite::M420_report(const bool forReplay/*=true*/) { diff --git a/Marlin/src/gcode/bedlevel/abl/G29.cpp b/Marlin/src/gcode/bedlevel/abl/G29.cpp index 800d51dac6..7cc821408c 100644 --- a/Marlin/src/gcode/bedlevel/abl/G29.cpp +++ b/Marlin/src/gcode/bedlevel/abl/G29.cpp @@ -84,7 +84,7 @@ */ static void pre_g29_return(const bool retry, const bool did) { if (!retry) { - TERN_(FULL_REPORT_TO_HOST_FEATURE, set_and_report_grblstate(M_IDLE, false)); + TERN_(FULL_REPORT_TO_HOST_FEATURE, motion.set_and_report_grblstate(M_IDLE, false)); } #if DISABLED(G29_RETRY_AND_RECOVER) if (!retry || did) { @@ -259,7 +259,7 @@ G29_TYPE GcodeSuite::G29() { process_subcommands_now(TERN(CAN_SET_LEVELING_AFTER_G28, F("G28L0"), FPSTR(G28_STR))); // Don't allow auto-leveling without homing first - if (homing_needed_error()) G29_RETURN(false, false); + if (motion.homing_needed_error()) G29_RETURN(false, false); // 3-point leveling gets points from the probe class #if ENABLED(AUTO_BED_LEVELING_3POINT) @@ -273,7 +273,7 @@ G29_TYPE GcodeSuite::G29() { #endif // Set and report "probing" state to host - TERN_(FULL_REPORT_TO_HOST_FEATURE, set_and_report_grblstate(M_PROBE, false)); + TERN_(FULL_REPORT_TO_HOST_FEATURE, motion.set_and_report_grblstate(M_PROBE, false)); #if DISABLED(PROBE_MANUALLY) // Potentially disable Fixed-Time Motion for probing @@ -307,14 +307,14 @@ G29_TYPE GcodeSuite::G29() { G29_RETURN(false, false); } - const float rz = parser.seenval('Z') ? RAW_Z_POSITION(parser.value_linear_units()) : current_position.z; + const float rz = parser.seenval('Z') ? motion.raw_z(parser.value_linear_units()) : motion.position.z; if (!WITHIN(rz, -10, 10)) { SERIAL_ERROR_MSG("Bad Z value"); G29_RETURN(false, false); } - const float rx = RAW_X_POSITION(parser.linearval('X', NAN)), - ry = RAW_Y_POSITION(parser.linearval('Y', NAN)); + const float rx = motion.raw_x(parser.linearval('X', NAN)), + ry = motion.raw_y(parser.linearval('Y', NAN)); int8_t i = parser.byteval('I', -1), j = parser.byteval('J', -1); #pragma GCC diagnostic push @@ -337,7 +337,7 @@ G29_TYPE GcodeSuite::G29() { TERN_(EXTENSIBLE_UI, ExtUI::onMeshUpdate(i, j, rz)); if (abl.reenable) { set_bed_leveling_enabled(true); - report_current_position(); + motion.report_position(); } } G29_RETURN(false, false); @@ -448,7 +448,7 @@ G29_TYPE GcodeSuite::G29() { TERN_(EXTENSIBLE_UI, ExtUI::onLevelingStart()); if (!faux) { - remember_feedrate_scaling_off(); + motion.remember_feedrate_scaling_off(); #if ENABLED(PREHEAT_BEFORE_LEVELING) #if ENABLED(SOVOL_SV06_RTS) @@ -465,7 +465,7 @@ G29_TYPE GcodeSuite::G29() { // Position bed horizontally and Z probe vertically. #if HAS_SAFE_BED_LEVELING - xyze_pos_t safe_position = current_position; + xyze_pos_t safe_position = motion.position; #ifdef SAFE_BED_LEVELING_START_X safe_position.x = SAFE_BED_LEVELING_START_X; #endif @@ -494,7 +494,7 @@ G29_TYPE GcodeSuite::G29() { safe_position.w = SAFE_BED_LEVELING_START_W; #endif - do_blocking_move_to(safe_position); + motion.blocking_move(safe_position); #endif // HAS_SAFE_BED_LEVELING // Disable auto bed leveling during G29. @@ -503,7 +503,7 @@ G29_TYPE GcodeSuite::G29() { // Deploy certain probes before starting probing #if ENABLED(BLTOUCH) || ALL(HAS_Z_SERVO_PROBE, Z_SERVO_INTERMEDIATE_STOW) - do_z_clearance(Z_CLEARANCE_DEPLOY_PROBE); + motion.do_z_clearance(Z_CLEARANCE_DEPLOY_PROBE); #elif HAS_BED_PROBE if (probe.deploy()) { // (returns true on deploy failure) set_bed_leveling_enabled(abl.reenable); @@ -534,7 +534,7 @@ G29_TYPE GcodeSuite::G29() { // Abort current G29 procedure, go back to idle state if (seenA && g29_in_progress) { SERIAL_ECHOLNPGM("Manual G29 aborted"); - SET_SOFT_ENDSTOP_LOOSE(false); + motion.set_soft_endstop_loose(false); set_bed_leveling_enabled(abl.reenable); g29_in_progress = false; TERN_(LCD_BED_LEVELING, ui.wait_for_move = false); @@ -554,9 +554,9 @@ G29_TYPE GcodeSuite::G29() { if (abl.abl_probe_index == 0) { // For the initial G29 S2 save software endstop state - SET_SOFT_ENDSTOP_LOOSE(true); + motion.set_soft_endstop_loose(true); // Move close to the bed before the first point - do_blocking_move_to_z(0); + motion.blocking_move_z(0); } else { @@ -566,7 +566,7 @@ G29_TYPE GcodeSuite::G29() { // For G29 after adjusting Z. // Save the previous Z before going to the next point - abl.measured_z = current_position.z; + abl.measured_z = motion.position.z; #if ENABLED(AUTO_BED_LEVELING_LINEAR) @@ -615,7 +615,7 @@ G29_TYPE GcodeSuite::G29() { TERN_(AUTO_BED_LEVELING_LINEAR, abl.indexIntoAB[abl.meshCount.x][abl.meshCount.y] = abl.abl_probe_index); // Keep looping till a reachable point is found - if (position_is_reachable(abl.probePos)) break; + if (motion.can_reach(abl.probePos)) break; ++abl.abl_probe_index; } @@ -624,14 +624,14 @@ G29_TYPE GcodeSuite::G29() { _manual_goto_xy(abl.probePos); // Can be used here too! // Disable software endstops to allow manual adjustment // If G29 is not completed, they will not be re-enabled - SET_SOFT_ENDSTOP_LOOSE(true); + motion.set_soft_endstop_loose(true); G29_RETURN(false, true); } else { // Leveling done! Fall through to G29 finishing code below SERIAL_ECHOLNPGM("Grid probing done."); // Re-enable software endstops, if needed - SET_SOFT_ENDSTOP_LOOSE(false); + motion.set_soft_endstop_loose(false); } #elif ENABLED(AUTO_BED_LEVELING_3POINT) @@ -642,7 +642,7 @@ G29_TYPE GcodeSuite::G29() { _manual_goto_xy(abl.probePos); // Disable software endstops to allow manual adjustment // If G29 is not completed, they will not be re-enabled - SET_SOFT_ENDSTOP_LOOSE(true); + motion.set_soft_endstop_loose(true); G29_RETURN(false, true); } else { @@ -650,7 +650,7 @@ G29_TYPE GcodeSuite::G29() { SERIAL_ECHOLNPGM("3-point probing done."); // Re-enable software endstops, if needed - SET_SOFT_ENDSTOP_LOOSE(false); + motion.set_soft_endstop_loose(false); if (!abl.dryrun) { vector_3 planeNormal = vector_3::cross(points[0] - points[1], points[2] - points[1]).get_normal(); @@ -731,9 +731,9 @@ G29_TYPE GcodeSuite::G29() { // Put a G1 move into the buffer // TODO: Instead of G1, we can just add the move directly to the planner... // { - // destination = current_position; destination = abl.probePos; - // REMEMBER(fr, feedrate_mm_s, XY_PROBE_FEEDRATE_MM_S); - // prepare_line_to_destination(); + // motion.destination = motion.position; motion.destination = abl.probePos; + // REMEMBER(fr, motion.feedrate_mm_s, XY_PROBE_FEEDRATE_MM_S); + // motion.prepare_line_to_destination(); // } sprintf_P(tmp_1, PSTR("G1X%d.%d Y%d.%d F%d"), int(abl.probePos.x), int(abl.probePos.x * 10) % 10, @@ -764,7 +764,7 @@ G29_TYPE GcodeSuite::G29() { //if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM_P(axis == Y_AXIS ? PSTR("Y=") : PSTR("X=", pos); safe_delay(4); - abl.measured_z = current_position.z - bdl.read(); + abl.measured_z = motion.position.z - bdl.read(); if (DEBUGGING(LEVELING)) SERIAL_ECHOLNPGM("x_cur ", planner.get_axis_position_mm(X_AXIS), " z ", abl.measured_z); #else // !BD_SENSOR_PROBE_NO_STOP @@ -857,7 +857,7 @@ G29_TYPE GcodeSuite::G29() { * return or loop before this point. */ - if (DEBUGGING(LEVELING)) DEBUG_POS("> probing complete", current_position); + if (DEBUGGING(LEVELING)) DEBUG_POS("> probing complete", motion.position); #if ENABLED(PROBE_MANUALLY) g29_in_progress = false; @@ -969,24 +969,24 @@ G29_TYPE GcodeSuite::G29() { // Correct the current XYZ position based on the tilted plane. // - if (DEBUGGING(LEVELING)) DEBUG_POS("G29 uncorrected XYZ", current_position); + if (DEBUGGING(LEVELING)) DEBUG_POS("G29 uncorrected XYZ", motion.position); - xyze_pos_t converted = current_position; + xyze_pos_t converted = motion.position; planner.force_unapply_leveling(converted); // use conversion machinery // Use the last measured distance to the bed, if possible - if ( NEAR(current_position.x, abl.probePos.x - probe.offset_xy.x) - && NEAR(current_position.y, abl.probePos.y - probe.offset_xy.y) + if ( NEAR(motion.position.x, abl.probePos.x - probe.offset_xy.x) + && NEAR(motion.position.y, abl.probePos.y - probe.offset_xy.y) ) { - const float simple_z = current_position.z - abl.measured_z; + const float simple_z = motion.position.z - abl.measured_z; if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("Probed Z", simple_z, " Matrix Z", converted.z, " Discrepancy ", simple_z - converted.z); converted.z = simple_z; } - // The rotated XY and corrected Z are now current_position - current_position = converted; + // The rotated XY and corrected Z are now motion.position + motion.position = converted; - if (DEBUGGING(LEVELING)) DEBUG_POS("G29 corrected XYZ", current_position); + if (DEBUGGING(LEVELING)) DEBUG_POS("G29 corrected XYZ", motion.position); abl.reenable = true; } @@ -994,7 +994,7 @@ G29_TYPE GcodeSuite::G29() { // Auto Bed Leveling is complete! Enable if possible. if (abl.reenable) { planner.leveling_active = true; - sync_plan_position(); + motion.sync_plan_position(); } #elif ENABLED(AUTO_BED_LEVELING_BILINEAR) @@ -1007,7 +1007,7 @@ G29_TYPE GcodeSuite::G29() { } // !isnan(abl.measured_z) // Restore state after probing - if (!faux) restore_feedrate_and_scaling(); + if (!faux) motion.restore_feedrate_and_scaling(); TERN_(HAS_BED_PROBE, probe.move_z_after_probing()); @@ -1021,7 +1021,7 @@ G29_TYPE GcodeSuite::G29() { probe.use_probing_tool(false); - report_current_position(); + motion.report_position(); G29_RETURN(isnan(abl.measured_z), true); } diff --git a/Marlin/src/gcode/bedlevel/mbl/G29.cpp b/Marlin/src/gcode/bedlevel/mbl/G29.cpp index a08ecc327d..b8087f9ec2 100644 --- a/Marlin/src/gcode/bedlevel/mbl/G29.cpp +++ b/Marlin/src/gcode/bedlevel/mbl/G29.cpp @@ -89,7 +89,7 @@ void GcodeSuite::G29() { return; } - TERN_(FULL_REPORT_TO_HOST_FEATURE, set_and_report_grblstate(M_PROBE)); + TERN_(FULL_REPORT_TO_HOST_FEATURE, motion.set_and_report_grblstate(M_PROBE)); int8_t ix, iy; ix = iy = 0; @@ -114,7 +114,7 @@ void GcodeSuite::G29() { // Position bed horizontally and Z probe vertically. #if HAS_SAFE_BED_LEVELING - xyze_pos_t safe_position = current_position; + xyze_pos_t safe_position = motion.position; #ifdef SAFE_BED_LEVELING_START_X safe_position.x = SAFE_BED_LEVELING_START_X; #endif @@ -143,7 +143,7 @@ void GcodeSuite::G29() { safe_position.w = SAFE_BED_LEVELING_START_W; #endif - do_blocking_move_to(safe_position); + motion.blocking_move(safe_position); #endif // HAS_SAFE_BED_LEVELING queue.inject(F("G29S2")); @@ -162,7 +162,7 @@ void GcodeSuite::G29() { // For each G29 S2... if (mbl_probe_index == 0) { // Move close to the bed before the first point - do_blocking_move_to_z( + motion.blocking_move_z( #ifdef MANUAL_PROBE_START_Z MANUAL_PROBE_START_Z #else @@ -172,28 +172,28 @@ void GcodeSuite::G29() { } else { // Save Z for the previous mesh position - bedlevel.set_zigzag_z(mbl_probe_index - 1, current_position.z); - TERN_(EXTENSIBLE_UI, ExtUI::onMeshUpdate(ix, iy, current_position.z)); - SET_SOFT_ENDSTOP_LOOSE(false); + bedlevel.set_zigzag_z(mbl_probe_index - 1, motion.position.z); + TERN_(EXTENSIBLE_UI, ExtUI::onMeshUpdate(ix, iy, motion.position.z)); + motion.set_soft_endstop_loose(false); } // If there's another point to sample, move there with optional lift. if (mbl_probe_index < GRID_MAX_POINTS) { // Disable software endstops to allow manual adjustment // If G29 is left hanging without completion they won't be re-enabled! - SET_SOFT_ENDSTOP_LOOSE(true); + motion.set_soft_endstop_loose(true); bedlevel.zigzag(mbl_probe_index++, ix, iy); _manual_goto_xy({ bedlevel.index_to_xpos[ix], bedlevel.index_to_ypos[iy] }); } else { // Move to the after probing position - current_position.z = ( + motion.position.z = ( #ifdef Z_AFTER_PROBING Z_AFTER_PROBING #else Z_CLEARANCE_BETWEEN_MANUAL_PROBES #endif ); - line_to_current_position(); + motion.goto_current_position(); planner.synchronize(); // After recording the last point, activate home and activate @@ -206,8 +206,8 @@ void GcodeSuite::G29() { set_bed_leveling_enabled(true); #if ENABLED(MESH_G28_REST_ORIGIN) - current_position.z = 0; - line_to_current_position(homing_feedrate(Z_AXIS)); + motion.position.z = 0; + motion.goto_current_position(motion.homing_feedrate(Z_AXIS)); planner.synchronize(); #endif @@ -263,9 +263,9 @@ void GcodeSuite::G29() { if (mbl_probe_index > 0) TERN_(HAS_STATUS_MESSAGE, ui.status_printf(0, F(S_FMT " %i/%i"), GET_TEXT(MSG_PROBING_POINT), _MIN(mbl_probe_index, GRID_MAX_POINTS), int(GRID_MAX_POINTS))); } - report_current_position(); + motion.report_position(); - TERN_(FULL_REPORT_TO_HOST_FEATURE, set_and_report_grblstate(M_IDLE)); + TERN_(FULL_REPORT_TO_HOST_FEATURE, motion.set_and_report_grblstate(M_IDLE)); } #endif // MESH_BED_LEVELING diff --git a/Marlin/src/gcode/bedlevel/mbl/M421.cpp b/Marlin/src/gcode/bedlevel/mbl/M421.cpp index e23683d55f..aa5bf3a391 100644 --- a/Marlin/src/gcode/bedlevel/mbl/M421.cpp +++ b/Marlin/src/gcode/bedlevel/mbl/M421.cpp @@ -43,9 +43,9 @@ */ void GcodeSuite::M421() { const bool hasX = parser.seen('X'), hasI = parser.seen('I'); - const int8_t ix = hasI ? parser.value_int() : hasX ? bedlevel.probe_index_x(RAW_X_POSITION(parser.value_linear_units())) : -1; + const int8_t ix = hasI ? parser.value_int() : hasX ? bedlevel.probe_index_x(motion.raw_x(parser.value_linear_units())) : -1; const bool hasY = parser.seen('Y'), hasJ = parser.seen('J'); - const int8_t iy = hasJ ? parser.value_int() : hasY ? bedlevel.probe_index_y(RAW_Y_POSITION(parser.value_linear_units())) : -1; + const int8_t iy = hasJ ? parser.value_int() : hasY ? bedlevel.probe_index_y(motion.raw_y(parser.value_linear_units())) : -1; const bool hasZ = parser.seen('Z'), hasQ = !hasZ && parser.seen('Q'); if (int(hasI && hasJ) + int(hasX && hasY) != 1 || !(hasZ || hasQ)) diff --git a/Marlin/src/gcode/bedlevel/ubl/G29.cpp b/Marlin/src/gcode/bedlevel/ubl/G29.cpp index 90deab3d2e..aaac7f145b 100644 --- a/Marlin/src/gcode/bedlevel/ubl/G29.cpp +++ b/Marlin/src/gcode/bedlevel/ubl/G29.cpp @@ -37,11 +37,11 @@ void GcodeSuite::G29() { - TERN_(FULL_REPORT_TO_HOST_FEATURE, set_and_report_grblstate(M_PROBE)); + TERN_(FULL_REPORT_TO_HOST_FEATURE, motion.set_and_report_grblstate(M_PROBE)); bedlevel.G29(); - TERN_(FULL_REPORT_TO_HOST_FEATURE, set_and_report_grblstate(M_IDLE)); + TERN_(FULL_REPORT_TO_HOST_FEATURE, motion.set_and_report_grblstate(M_IDLE)); } #endif // AUTO_BED_LEVELING_UBL diff --git a/Marlin/src/gcode/bedlevel/ubl/M421.cpp b/Marlin/src/gcode/bedlevel/ubl/M421.cpp index 99ba3ce19b..fab13e4d84 100644 --- a/Marlin/src/gcode/bedlevel/ubl/M421.cpp +++ b/Marlin/src/gcode/bedlevel/ubl/M421.cpp @@ -54,7 +54,7 @@ void GcodeSuite::M421() { hasZ = parser.seen('Z'), hasQ = !hasZ && parser.seen('Q'); - if (hasC) ij = bedlevel.find_closest_mesh_point_of_type(CLOSEST, current_position); + if (hasC) ij = bedlevel.find_closest_mesh_point_of_type(CLOSEST, motion.position); // Test for bad parameter combinations if (int(hasC) + int(hasI && hasJ) != 1 || !(hasZ || hasQ || hasN)) diff --git a/Marlin/src/gcode/calibrate/G28.cpp b/Marlin/src/gcode/calibrate/G28.cpp index fe0a3a792e..97aa17c3f0 100644 --- a/Marlin/src/gcode/calibrate/G28.cpp +++ b/Marlin/src/gcode/calibrate/G28.cpp @@ -78,13 +78,13 @@ static void quick_home_xy() { // Pretend the current position is 0,0 - current_position.set(0.0, 0.0); - sync_plan_position(); + motion.position.set(0.0, 0.0); + motion.sync_plan_position(); - const int x_axis_home_dir = TOOL_X_HOME_DIR(active_extruder); + const int x_axis_home_dir = TOOL_X_HOME_DIR(motion.extruder); // Use a higher diagonal feedrate so axes move at homing speed - const float minfr = _MIN(homing_feedrate(X_AXIS), homing_feedrate(Y_AXIS)), + const float minfr = _MIN(motion.homing_feedrate(X_AXIS), motion.homing_feedrate(Y_AXIS)), fr_mm_s = HYPOT(minfr, minfr); // Set homing current to X and Y axis if defined @@ -105,11 +105,11 @@ }; #endif - do_blocking_move_to_xy(1.5 * max_length(X_AXIS) * x_axis_home_dir, 1.5 * max_length(Y_AXIS) * Y_HOME_DIR, fr_mm_s); + motion.blocking_move_xy(1.5 * max_length(X_AXIS) * x_axis_home_dir, 1.5 * max_length(Y_AXIS) * Y_HOME_DIR, fr_mm_s); endstops.validate_homing_move(); - current_position.set(0.0, 0.0); + motion.position.set(0.0, 0.0); TERN_(X_HAS_HOME_CURRENT, restore_homing_current(X_AXIS)); #if Y_HAS_HOME_CURRENT && NONE(CORE_IS_XY, MARKFORGED_XY, MARKFORGED_YX) @@ -132,33 +132,33 @@ DEBUG_SECTION(log_G28, "home_z_safely", DEBUGGING(LEVELING)); // Disallow Z homing if X or Y homing is needed - if (homing_needed_error(_BV(X_AXIS) | _BV(Y_AXIS))) return; + if (motion.homing_needed_error(_BV(X_AXIS) | _BV(Y_AXIS))) return; // Potentially disable Fixed-Time Motion for homing TERN_(FT_MOTION, FTM_DISABLE_IN_SCOPE()); - sync_plan_position(); + motion.sync_plan_position(); /** * Move the Z probe (or just the nozzle) to the safe homing point * (Z is already at the right height) */ constexpr xy_float_t safe_homing_xy = { Z_SAFE_HOMING_X_POINT, Z_SAFE_HOMING_Y_POINT }; - destination.set(safe_homing_xy, current_position.z); + motion.destination.set(safe_homing_xy, motion.position.z); - TERN_(HOMING_Z_WITH_PROBE, destination -= probe.offset_xy); + TERN_(HOMING_Z_WITH_PROBE, motion.destination -= probe.offset_xy); - if (position_is_reachable(destination)) { + if (motion.can_reach(motion.destination)) { - if (DEBUGGING(LEVELING)) DEBUG_POS("home_z_safely", destination); + if (DEBUGGING(LEVELING)) DEBUG_POS("home_z_safely", motion.destination); // Free the active extruder for movement TERN_(DUAL_X_CARRIAGE, idex_set_parked(false)); TERN_(SENSORLESS_HOMING, safe_delay(500)); // Short delay needed to settle - do_blocking_move_to_xy(destination); - homeaxis(Z_AXIS); + motion.blocking_move_xy(motion.destination); + motion.homeaxis(Z_AXIS); } else { LCD_MESSAGE(MSG_ZPROBE_OUT); @@ -227,10 +227,10 @@ void GcodeSuite::G28() { #if ENABLED(MARLIN_DEV_MODE) if (parser.seen_test('S')) { - LOOP_NUM_AXES(a) set_axis_is_at_home((AxisEnum)a); - sync_plan_position(); + LOOP_NUM_AXES(a) motion.set_axis_is_at_home((AxisEnum)a); + motion.sync_plan_position(); SERIAL_ECHOLNPGM("Simulated Homing"); - report_current_position(); + motion.report_position(); return; } #endif @@ -243,14 +243,14 @@ void GcodeSuite::G28() { #endif // Home (O)nly if position is unknown - if (!axes_should_home() && parser.seen_test('O')) { + if (!motion.axes_should_home() && parser.seen_test('O')) { if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("> homing not needed, skip"); return; } #if ENABLED(FULL_REPORT_TO_HOST_FEATURE) - const M_StateEnum old_grblstate = M_State_grbl; - set_and_report_grblstate(M_HOMING); + const M_StateEnum old_grblstate = motion.M_State_grbl; + motion.set_and_report_grblstate(M_HOMING); #endif TERN_(DWIN_CREALITY_LCD, dwinHomingStart()); @@ -268,7 +268,7 @@ void GcodeSuite::G28() { DualXMode IDEX_saved_mode = dual_x_carriage_mode; #endif - SET_SOFT_ENDSTOP_LOOSE(false); // Reset a leftover 'loose' motion state + motion.set_soft_endstop_loose(false); // Reset a leftover 'loose' motion state // Disable the leveling matrix before homing #if CAN_SET_LEVELING_AFTER_G28 @@ -294,7 +294,7 @@ void GcodeSuite::G28() { // Always home with tool 0 active #if HAS_MULTI_HOTEND #if DISABLED(DELTA) || ENABLED(DELTA_HOME_TO_SAFE_ZONE) - const uint8_t old_tool_index = active_extruder; + const uint8_t old_tool_index = motion.extruder; #endif // PARKING_EXTRUDER homing requires different handling of movement / solenoid activation, depending on the side of homing #if ENABLED(PARKING_EXTRUDER) @@ -306,7 +306,7 @@ void GcodeSuite::G28() { TERN_(HAS_DUPLICATION_MODE, set_duplication_enabled(false)); - remember_feedrate_scaling_off(); + motion.remember_feedrate_scaling_off(); endstops.enable(true); // Enable endstops for next homing move @@ -330,7 +330,7 @@ void GcodeSuite::G28() { #else // !DELTA && !AXEL_TPARA - #define _UNSAFE(A) TERN0(Z_SAFE_HOMING, homeZZ && axis_should_home(_AXIS(A))) + #define _UNSAFE(A) TERN0(Z_SAFE_HOMING, homeZZ && motion.axis_should_home(_AXIS(A))) const bool homeZZ = TERN0(HAS_Z_AXIS, parser.seen_test('Z')), NUM_AXIS_LIST_( // Other axes should be homed before Z safe-homing @@ -367,7 +367,7 @@ void GcodeSuite::G28() { // Z may home first, e.g., when homing away from the bed. // This is also permitted when homing with a Z endstop. - if (TERN0(HOME_Z_FIRST, doZ)) homeaxis(Z_AXIS); + if (TERN0(HOME_Z_FIRST, doZ)) motion.homeaxis(Z_AXIS); // 'R' to specify a specific raise. 'R0' indicates no raise, e.g., for recovery.resume // When 'R0' is used, there should already be adequate clearance, e.g., from homing Z to max. @@ -386,15 +386,15 @@ void GcodeSuite::G28() { bool with_probe = ENABLED(HOMING_Z_WITH_PROBE); // Raise above the current Z (which should be synced in the planner) // The "height" for Z is a coordinate. But if Z is not trusted/homed make it relative. - if (seenR || !(z_min_trusted || axis_should_home(Z_AXIS))) { - z_homing_height += current_position.z; + if (seenR || !(motion.z_min_trusted || motion.axis_should_home(Z_AXIS))) { + z_homing_height += motion.position.z; with_probe = false; } if (may_skate) { // Apply Z clearance before doing any lateral motion if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("Raise Z before homing:"); - do_z_clearance(z_homing_height, with_probe); + motion.do_z_clearance(z_homing_height, with_probe); } } @@ -409,7 +409,7 @@ void GcodeSuite::G28() { #if HAS_Y_AXIS // Home Y (before X) if (ENABLED(HOME_Y_BEFORE_X) && (doY || TERN0(CODEPENDENT_XY_HOMING, doX))) - homeaxis(Y_AXIS); + motion.homeaxis(Y_AXIS); #endif // Home X @@ -419,22 +419,22 @@ void GcodeSuite::G28() { #if ENABLED(DUAL_X_CARRIAGE) // Always home the 2nd (right) extruder first - active_extruder = 1; - homeaxis(X_AXIS); + motion.extruder = 1; + motion.homeaxis(X_AXIS); // Remember this extruder's position for later tool change - inactive_extruder_x = current_position.x; + inactive_extruder_x = motion.position.x; // Home the 1st (left) extruder - active_extruder = 0; - homeaxis(X_AXIS); + motion.extruder = 0; + motion.homeaxis(X_AXIS); // Consider the active extruder to be in its "parked" position idex_set_parked(); #else - homeaxis(X_AXIS); + motion.homeaxis(X_AXIS); #endif } @@ -442,17 +442,17 @@ void GcodeSuite::G28() { #if ALL(FOAMCUTTER_XYUV, HAS_I_AXIS) // Home I (after X) - if (doI) homeaxis(I_AXIS); + if (doI) motion.homeaxis(I_AXIS); #endif #if HAS_Y_AXIS // Home Y (after X) - if (DISABLED(HOME_Y_BEFORE_X) && doY) homeaxis(Y_AXIS); + if (DISABLED(HOME_Y_BEFORE_X) && doY) motion.homeaxis(Y_AXIS); #endif #if ALL(FOAMCUTTER_XYUV, HAS_J_AXIS) // Home J (after Y) - if (doJ) homeaxis(J_AXIS); + if (doJ) motion.homeaxis(J_AXIS); #endif TERN_(IMPROVE_HOMING_RELIABILITY, end_slow_homing(saved_motion_state)); @@ -460,7 +460,7 @@ void GcodeSuite::G28() { #if ENABLED(FOAMCUTTER_XYUV) // Skip homing of unused Z axis for foamcutters - if (doZ) set_axis_is_at_home(Z_AXIS); + if (doZ) motion.set_axis_is_at_home(Z_AXIS); #elif HAS_Z_AXIS @@ -478,9 +478,9 @@ void GcodeSuite::G28() { if (!parser.seen_test('H')) home_z_safely(); else - homeaxis(Z_AXIS); + motion.homeaxis(Z_AXIS); #else - homeaxis(Z_AXIS); + motion.homeaxis(Z_AXIS); #endif #if ANY(Z_HOME_TO_MIN, ALLOW_Z_AFTER_HOMING) @@ -490,17 +490,17 @@ void GcodeSuite::G28() { #endif SECONDARY_AXIS_CODE( - if (doI) homeaxis(I_AXIS), - if (doJ) homeaxis(J_AXIS), - if (doK) homeaxis(K_AXIS), - if (doU) homeaxis(U_AXIS), - if (doV) homeaxis(V_AXIS), - if (doW) homeaxis(W_AXIS) + if (doI) motion.homeaxis(I_AXIS), + if (doJ) motion.homeaxis(J_AXIS), + if (doK) motion.homeaxis(K_AXIS), + if (doU) motion.homeaxis(U_AXIS), + if (doV) motion.homeaxis(V_AXIS), + if (doW) motion.homeaxis(W_AXIS) ); #endif // HAS_Z_AXIS - sync_plan_position(); + motion.sync_plan_position(); #endif @@ -517,15 +517,15 @@ void GcodeSuite::G28() { TERN_(IMPROVE_HOMING_RELIABILITY, saved_motion_state = begin_slow_homing()); // Always home the 2nd (right) extruder first - active_extruder = 1; - homeaxis(X_AXIS); + motion.extruder = 1; + motion.homeaxis(X_AXIS); // Remember this extruder's position for later tool change - inactive_extruder_x = current_position.x; + inactive_extruder_x = motion.position.x; // Home the 1st (left) extruder - active_extruder = 0; - homeaxis(X_AXIS); + motion.extruder = 0; + motion.homeaxis(X_AXIS); // Consider the active extruder to be parked idex_set_parked(); @@ -544,13 +544,13 @@ void GcodeSuite::G28() { TERN_(SPI_ENDSTOPS, endstops.clear_endstop_state()); // Move to a height where we can use the full xy-area - TERN_(DELTA_HOME_TO_SAFE_ZONE, do_blocking_move_to_z(delta_clip_start_height)); + TERN_(DELTA_HOME_TO_SAFE_ZONE, motion.blocking_move_z(delta_clip_start_height)); #if HAS_Z_AXIS // Move to the configured Z only if Z was homed to MIN, because machines that // home to MAX historically expect 'G28 Z' to be safe to use at the end of a // print, and do_move_after_z_homing is not very nuanced. - if (finalRaiseZ) do_move_after_z_homing(); + if (finalRaiseZ) motion.do_move_after_z_homing(); #endif TERN_(CAN_SET_LEVELING_AFTER_G28, if (leveling_restore_state) set_bed_leveling_enabled()); @@ -561,11 +561,11 @@ void GcodeSuite::G28() { #endif #ifdef XY_AFTER_HOMING - if (!axes_should_home(_BV(X_AXIS) | _BV(Y_AXIS))) - do_blocking_move_to(xy_pos_t(XY_AFTER_HOMING)); + if (!motion.axes_should_home(_BV(X_AXIS) | _BV(Y_AXIS))) + motion.blocking_move(xy_pos_t(XY_AFTER_HOMING)); #endif - restore_feedrate_and_scaling(); + motion.restore_feedrate_and_scaling(); if (ENABLED(NANODLP_Z_SYNC) && (ENABLED(NANODLP_ALL_AXIS) || TERN0(HAS_Z_AXIS, doZ))) SERIAL_ECHOLNPGM(STR_Z_MOVE_COMP); @@ -578,9 +578,9 @@ void GcodeSuite::G28() { TERN_(DWIN_CREALITY_LCD, dwinHomingDone()); TERN_(EXTENSIBLE_UI, ExtUI::onHomingDone()); - report_current_position(); + motion.report_position(); - TERN_(FULL_REPORT_TO_HOST_FEATURE, set_and_report_grblstate(old_grblstate)); + TERN_(FULL_REPORT_TO_HOST_FEATURE, motion.set_and_report_grblstate(old_grblstate)); #ifdef EVENT_GCODE_AFTER_HOMING gcode.process_subcommands_now(F(EVENT_GCODE_AFTER_HOMING)); diff --git a/Marlin/src/gcode/calibrate/G33.cpp b/Marlin/src/gcode/calibrate/G33.cpp index 0a8dd459ca..f3ad5cebea 100644 --- a/Marlin/src/gcode/calibrate/G33.cpp +++ b/Marlin/src/gcode/calibrate/G33.cpp @@ -73,7 +73,7 @@ void ac_setup(const bool reset_bed) { TERN_(HAS_BED_PROBE, probe.use_probing_tool()); planner.synchronize(); - remember_feedrate_scaling_off(); + motion.remember_feedrate_scaling_off(); #if HAS_LEVELING if (reset_bed) reset_bed_level(); // After full calibration bed-level data is no longer valid @@ -81,9 +81,9 @@ void ac_setup(const bool reset_bed) { } void ac_cleanup() { - TERN_(DELTA_HOME_TO_SAFE_ZONE, do_blocking_move_to_z(delta_clip_start_height)); + TERN_(DELTA_HOME_TO_SAFE_ZONE, motion.blocking_move_z(delta_clip_start_height)); TERN_(HAS_BED_PROBE, probe.stow()); - restore_feedrate_and_scaling(); + motion.restore_feedrate_and_scaling(); TERN_(HAS_BED_PROBE, probe.use_probing_tool(false)); } @@ -247,7 +247,7 @@ static bool probe_calibration_points(float z_pt[NPP + 1], const int8_t probe_poi LOOP_CAL_RAD(rad) z_pt[rad] /= _7P_STEP / steps; - do_blocking_move_to_xy(0.0f, 0.0f); + motion.blocking_move_xy(0.0f, 0.0f); } } return true; @@ -268,7 +268,7 @@ static void reverse_kinematics_probe_points(float z_pt[NPP + 1], abc_float_t mm_ r = (rad == CEN ? 0.0f : dcr); pos.set(cos(a) * r, sin(a) * r, z_pt[rad]); inverse_kinematics(pos); - mm_at_pt_axis[rad] = delta; + mm_at_pt_axis[rad] = motion.delta; } } @@ -387,7 +387,7 @@ static float auto_tune_a(const float dcr) { */ void GcodeSuite::G33() { - TERN_(FULL_REPORT_TO_HOST_FEATURE, set_and_report_grblstate(M_PROBE)); + TERN_(FULL_REPORT_TO_HOST_FEATURE, motion.set_and_report_grblstate(M_PROBE)); const int8_t probe_points = parser.intval('P', DELTA_CALIBRATION_DEFAULT_POINTS); if (!WITHIN(probe_points, 0, 10)) { @@ -677,7 +677,7 @@ void GcodeSuite::G33() { ac_cleanup(); - TERN_(FULL_REPORT_TO_HOST_FEATURE, set_and_report_grblstate(M_IDLE)); + TERN_(FULL_REPORT_TO_HOST_FEATURE, motion.set_and_report_grblstate(M_IDLE)); #if HAS_DELTA_SENSORLESS_PROBING probe.test_sensitivity = { true, true, true }; #endif diff --git a/Marlin/src/gcode/calibrate/G34.cpp b/Marlin/src/gcode/calibrate/G34.cpp index 504dcd1c6f..a8d5eef9d6 100644 --- a/Marlin/src/gcode/calibrate/G34.cpp +++ b/Marlin/src/gcode/calibrate/G34.cpp @@ -61,11 +61,11 @@ void GcodeSuite::G34() { // Home before the alignment procedure - home_if_needed(); + motion.home_if_needed(); TERN_(HAS_LEVELING, TEMPORARY_BED_LEVELING_STATE(false)); - SET_SOFT_ENDSTOP_LOOSE(true); + motion.set_soft_endstop_loose(true); TemporaryGlobalEndstopsState unlock_z(false); #ifdef GANTRY_CALIBRATION_COMMANDS_PRE @@ -77,7 +77,7 @@ void GcodeSuite::G34() { // Move XY to safe position if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("Parking XY"); const xy_pos_t safe_pos = GANTRY_CALIBRATION_SAFE_POSITION; - do_blocking_move_to_xy(safe_pos, MMM_TO_MMS(GANTRY_CALIBRATION_XY_PARK_FEEDRATE)); + motion.blocking_move_xy(safe_pos, MMM_TO_MMS(GANTRY_CALIBRATION_XY_PARK_FEEDRATE)); #endif const float move_distance = parser.intval('Z', GANTRY_CALIBRATION_EXTRA_HEIGHT), @@ -86,7 +86,7 @@ void GcodeSuite::G34() { // Move Z to pounce position if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("Setting Z Pounce"); - do_blocking_move_to_z(zpounce, homing_feedrate(Z_AXIS)); + motion.blocking_move_z(zpounce, motion.homing_feedrate(Z_AXIS)); // Store current motor settings, then apply reduced value @@ -133,7 +133,7 @@ void GcodeSuite::G34() { // Do Final Z move to adjust if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("Final Z Move"); - do_blocking_move_to_z(zgrind, MMM_TO_MMS(GANTRY_CALIBRATION_FEEDRATE)); + motion.blocking_move_z(zgrind, MMM_TO_MMS(GANTRY_CALIBRATION_FEEDRATE)); #if _REDUCE_CURRENT // Reset current to original values @@ -157,14 +157,14 @@ void GcodeSuite::G34() { // Back off end plate, back to normal motion range if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("Z Backoff"); - do_blocking_move_to_z(zpounce, MMM_TO_MMS(GANTRY_CALIBRATION_FEEDRATE)); + motion.blocking_move_z(zpounce, MMM_TO_MMS(GANTRY_CALIBRATION_FEEDRATE)); #ifdef GANTRY_CALIBRATION_COMMANDS_POST if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("Running Post Commands"); process_subcommands_now(F(GANTRY_CALIBRATION_COMMANDS_POST)); #endif - SET_SOFT_ENDSTOP_LOOSE(false); + motion.set_soft_endstop_loose(false); } #endif // MECHANICAL_GANTRY_CALIBRATION diff --git a/Marlin/src/gcode/calibrate/G34_M422.cpp b/Marlin/src/gcode/calibrate/G34_M422.cpp index 6c367ad882..a4544db1fb 100644 --- a/Marlin/src/gcode/calibrate/G34_M422.cpp +++ b/Marlin/src/gcode/calibrate/G34_M422.cpp @@ -167,7 +167,7 @@ void GcodeSuite::G34() { )); // Home before the alignment procedure - home_if_needed(); + motion.home_if_needed(); #if !HAS_Z_STEPPER_ALIGN_STEPPER_XY float last_z_align_move[NUM_Z_STEPPERS] = ARRAY_N_1(NUM_Z_STEPPERS, 10000.0f); @@ -217,7 +217,7 @@ void GcodeSuite::G34() { // Probe a Z height for each stepper. // Probing sanity check is disabled, as it would trigger even in normal cases because - // current_position.z has been manually altered in the "dirty trick" above. + // motion.position.z has been manually altered in the "dirty trick" above. const float minz = (Z_PROBE_LOW_POINT) - (z_probe * 0.5f); @@ -228,7 +228,7 @@ void GcodeSuite::G34() { } const float z_probed_height = probe.probe_at_point( - DIFF_TERN(HAS_HOME_OFFSET, ppos, xy_pos_t(home_offset)), // xy + DIFF_TERN(HAS_HOME_OFFSET, ppos, xy_pos_t(motion.home_offset)), // xy raise_after, // raise_after (DEBUGGING(LEVELING) || DEBUGGING(INFO)) ? 3 : 0, // verbose_level true, false, // probe_relative, sanity_check @@ -396,7 +396,7 @@ void GcodeSuite::G34() { #endif // Do a move to correct part of the misalignment for the current stepper - do_blocking_move_to_z(amplification * z_align_move + current_position.z); + motion.blocking_move_z(amplification * z_align_move + motion.position.z); } // for (zstepper) // Back to normal stepper operations @@ -440,8 +440,8 @@ void GcodeSuite::G34() { ); if (!err_break) - current_position.z -= z_measured_min - (Z_TWEEN_SAFE_CLEARANCE + zoffs); // We shouldn't want to subtract the clearance from here right? (Depends if we added it further up) - sync_plan_position(); + motion.position.z -= z_measured_min - (Z_TWEEN_SAFE_CLEARANCE + zoffs); // We shouldn't want to subtract the clearance from here right? (Depends if we added it further up) + motion.sync_plan_position(); #endif #ifdef EVENT_GCODE_AFTER_G34 diff --git a/Marlin/src/gcode/calibrate/G425.cpp b/Marlin/src/gcode/calibrate/G425.cpp index 883d7b4b6f..177d99a05a 100644 --- a/Marlin/src/gcode/calibrate/G425.cpp +++ b/Marlin/src/gcode/calibrate/G425.cpp @@ -145,7 +145,7 @@ struct measurements_t { #endif inline void calibration_move() { - do_blocking_move_to((xyz_pos_t)current_position, MMM_TO_MMS(CALIBRATION_FEEDRATE_TRAVEL)); + motion.blocking_move((xyz_pos_t)motion.position, MMM_TO_MMS(CALIBRATION_FEEDRATE_TRAVEL)); } /** @@ -156,17 +156,17 @@ inline void calibration_move() { */ inline void park_above_object(measurements_t &m, const float uncertainty) { // Move to safe distance above calibration object - current_position.z = m.obj_center.z + dimensions.z / 2 + uncertainty; + motion.position.z = m.obj_center.z + dimensions.z / 2 + uncertainty; calibration_move(); // Move to center of calibration object in XY - current_position = xy_pos_t(m.obj_center); + motion.position = xy_pos_t(m.obj_center); calibration_move(); } #if HAS_MULTI_HOTEND inline void set_nozzle(measurements_t &m, const uint8_t extruder) { - if (extruder != active_extruder) { + if (extruder != motion.extruder) { park_above_object(m, CALIBRATION_MEASUREMENT_UNKNOWN); tool_change(extruder); } @@ -196,15 +196,15 @@ float measuring_movement(const AxisEnum axis, const int dir, const bool stop_sta const feedRate_t mms = fast ? MMM_TO_MMS(CALIBRATION_FEEDRATE_FAST) : MMM_TO_MMS(CALIBRATION_FEEDRATE_SLOW); const float limit = fast ? 50 : 5; - destination = current_position; - destination[axis] += dir * limit; + motion.destination = motion.position; + motion.destination[axis] += dir * limit; endstops.enable_calibration_probe(true, stop_state); - do_blocking_move_to((xyz_pos_t)destination, mms); + motion.blocking_move((xyz_pos_t)motion.destination, mms); endstops.enable_calibration_probe(false); endstops.hit_on_purpose(); - set_current_from_steppers_for_axis(axis); - sync_plan_position(); - return current_position[axis]; + motion.set_current_from_steppers_for_axis(axis); + motion.sync_plan_position(); + return motion.position[axis]; } /** @@ -221,7 +221,7 @@ inline float measure(const AxisEnum axis, const int dir, const bool stop_state, const bool fast = uncertainty == CALIBRATION_MEASUREMENT_UNKNOWN; // Save the current position of the specified axis - const float start_pos = current_position[axis]; + const float start_pos = motion.position[axis]; // Take a measurement. Only the specified axis will be affected. const float measured_pos = measuring_movement(axis, dir, stop_state, fast); @@ -233,9 +233,9 @@ inline float measure(const AxisEnum axis, const int dir, const bool stop_state, } // Move back to the starting position - destination = current_position; - destination[axis] = start_pos; - do_blocking_move_to((xyz_pos_t)destination, MMM_TO_MMS(CALIBRATION_FEEDRATE_TRAVEL)); + motion.destination = motion.position; + motion.destination[axis] = start_pos; + motion.blocking_move((xyz_pos_t)motion.destination, MMM_TO_MMS(CALIBRATION_FEEDRATE_TRAVEL)); return measured_pos; } @@ -297,7 +297,7 @@ inline void probe_side(measurements_t &m, const float uncertainty, const side_t if (probe_top_at_edge) { #if AXIS_CAN_CALIBRATE(Z) // Probe top nearest the side we are probing - current_position[axis] = m.obj_center[axis] + (-dir) * (dimensions[axis] / 2 - m.nozzle_outer_dimension[axis]); + motion.position[axis] = m.obj_center[axis] + (-dir) * (dimensions[axis] / 2 - m.nozzle_outer_dimension[axis]); calibration_move(); m.obj_side[TOP] = measure(Z_AXIS, -1, true, &m.backlash[TOP], uncertainty); m.obj_center.z = m.obj_side[TOP] - dimensions.z / 2; @@ -306,11 +306,11 @@ inline void probe_side(measurements_t &m, const float uncertainty, const side_t if ((AXIS_CAN_CALIBRATE(X) && axis == X_AXIS) || (AXIS_CAN_CALIBRATE(Y) && axis == Y_AXIS)) { // Move to safe distance to the side of the calibration object - current_position[axis] = m.obj_center[axis] + (-dir) * (dimensions[axis] / 2 + m.nozzle_outer_dimension[axis] / 2 + uncertainty); + motion.position[axis] = m.obj_center[axis] + (-dir) * (dimensions[axis] / 2 + m.nozzle_outer_dimension[axis] / 2 + uncertainty); calibration_move(); // Plunge below the side of the calibration object and measure - current_position.z = m.obj_side[TOP] - (CALIBRATION_NOZZLE_TIP_HEIGHT) * 0.7f; + motion.position.z = m.obj_side[TOP] - (CALIBRATION_NOZZLE_TIP_HEIGHT) * 0.7f; calibration_move(); const float measurement = measure(axis, dir, true, &m.backlash[side], uncertainty); m.obj_center[axis] = measurement + dir * (dimensions[axis] / 2 + m.nozzle_outer_dimension[axis] / 2); @@ -522,7 +522,7 @@ inline void probe_sides(measurements_t &m, const float uncertainty) { inline void report_measured_positional_error(const measurements_t &m) { SERIAL_CHAR('T'); - SERIAL_ECHO(active_extruder); + SERIAL_ECHO(motion.extruder); SERIAL_ECHOLNPGM(" Positional Error:"); #if HAS_X_CENTER && AXIS_CAN_CALIBRATE(X) SERIAL_ECHOLNPGM_P(SP_X_STR, m.pos_error.x); @@ -673,14 +673,14 @@ inline void calibrate_backlash(measurements_t &m, const float uncertainty) { AXIS_CAN_CALIBRATE(I) * 3, AXIS_CAN_CALIBRATE(J) * 3, AXIS_CAN_CALIBRATE(K) * 3, AXIS_CAN_CALIBRATE(U) * 3, AXIS_CAN_CALIBRATE(V) * 3, AXIS_CAN_CALIBRATE(W) * 3 ); - current_position += move; calibration_move(); - current_position -= move; calibration_move(); + motion.position += move; calibration_move(); + motion.position -= move; calibration_move(); } #endif } inline void update_measurements(measurements_t &m, const AxisEnum axis) { - current_position[axis] += m.pos_error[axis]; + motion.position[axis] += m.pos_error[axis]; m.obj_center[axis] = true_center[axis]; m.pos_error[axis] = 0; } @@ -726,7 +726,7 @@ inline void calibrate_toolhead(measurements_t &m, const float uncertainty, const TERN_(HAS_V_CENTER, update_measurements(m, V_AXIS)); TERN_(HAS_W_CENTER, update_measurements(m, W_AXIS)); - sync_plan_position(); + motion.sync_plan_position(); } /** @@ -779,7 +779,7 @@ inline void calibrate_all() { // Do a slow and precise calibration of the toolheads calibrate_all_toolheads(m, CALIBRATION_MEASUREMENT_UNCERTAIN); - current_position.x = X_CENTER; + motion.position.x = X_CENTER; calibration_move(); // Park nozzle away from calibration object } @@ -799,10 +799,10 @@ void GcodeSuite::G425() { process_subcommands_now(F(CALIBRATION_SCRIPT_PRE)); #endif - if (homing_needed_error()) return; + if (motion.homing_needed_error()) return; TEMPORARY_BED_LEVELING_STATE(false); - SET_SOFT_ENDSTOP_LOOSE(true); + motion.set_soft_endstop_loose(true); measurements_t m; const float uncertainty = parser.floatval('U', CALIBRATION_MEASUREMENT_UNCERTAIN); @@ -810,7 +810,7 @@ void GcodeSuite::G425() { if (parser.seen_test('B')) calibrate_backlash(m, uncertainty); else if (parser.seen_test('T')) - calibrate_toolhead(m, uncertainty, parser.intval('T', active_extruder)); + calibrate_toolhead(m, uncertainty, parser.intval('T', motion.extruder)); #if ENABLED(CALIBRATION_REPORTING) else if (parser.seen('V')) { probe_sides(m, uncertainty); @@ -829,7 +829,7 @@ void GcodeSuite::G425() { else calibrate_all(); - SET_SOFT_ENDSTOP_LOOSE(false); + motion.set_soft_endstop_loose(false); #ifdef CALIBRATION_SCRIPT_POST process_subcommands_now(F(CALIBRATION_SCRIPT_POST)); diff --git a/Marlin/src/gcode/calibrate/G76_M871.cpp b/Marlin/src/gcode/calibrate/G76_M871.cpp index 35f7ac3174..d3fd166257 100644 --- a/Marlin/src/gcode/calibrate/G76_M871.cpp +++ b/Marlin/src/gcode/calibrate/G76_M871.cpp @@ -100,7 +100,7 @@ const millis_t ms = millis(); if (ELAPSED(ms, ntr)) { ntr = ms + 1000; - thermalManager.print_heater_states(active_extruder); + thermalManager.print_heater_states(motion.extruder); } return (timeout && ELAPSED(ms, timeout)); }; @@ -150,7 +150,7 @@ if (do_bed_cal || do_probe_cal) { // Ensure park position is reachable - bool reachable = position_is_reachable(parkpos) || WITHIN(parkpos.z, Z_MIN_POS - fslop, Z_MAX_POS + fslop); + bool reachable = motion.can_reach(parkpos) || WITHIN(parkpos.z, Z_MIN_POS - fslop, Z_MAX_POS + fslop); if (!reachable) SERIAL_ECHOLNPGM("!Park"); else { @@ -167,7 +167,7 @@ process_subcommands_now(FPSTR(G28_STR)); } - remember_feedrate_scaling_off(); + motion.remember_feedrate_scaling_off(); /****************************************** * Calibrate bed temperature offsets @@ -198,7 +198,7 @@ report_targets(target_bed, target_probe); // Park nozzle - do_blocking_move_to(parkpos); + motion.blocking_move(parkpos); // Wait for heatbed to reach target temp and probe to cool below target temp if (wait_for_temps(target_bed, target_probe, next_temp_report, millis() + MIN_TO_MS(15))) { @@ -207,7 +207,7 @@ } // Move the nozzle to the probing point and wait for the probe to reach target temp - do_blocking_move_to(noz_pos_xyz); + motion.blocking_move(noz_pos_xyz); say_waiting_for_probe_heating(); SERIAL_EOL(); while (thermalManager.wholeDegProbe() < target_probe) @@ -239,7 +239,7 @@ if (do_probe_cal) { // Park nozzle - do_blocking_move_to(parkpos); + motion.blocking_move(parkpos); // Initialize temperatures const celsius_t target_bed = BED_MAX_TARGET; @@ -258,7 +258,7 @@ bool timeout = false; for (uint8_t idx = 0; idx <= PTC_PROBE_COUNT; idx++) { // Move probe to probing point and wait for it to reach target temperature - do_blocking_move_to(noz_pos_xyz); + motion.blocking_move(noz_pos_xyz); say_waiting_for_probe_heating(); SERIAL_ECHOLNPGM(" Bed:", target_bed, " Probe:", target_probe); @@ -291,7 +291,7 @@ ptc.print_offsets(); } // do_probe_cal - restore_feedrate_and_scaling(); + motion.restore_feedrate_and_scaling(); } #endif // PTC_PROBE && PTC_BED diff --git a/Marlin/src/gcode/calibrate/M48.cpp b/Marlin/src/gcode/calibrate/M48.cpp index 0c4355f5b1..fbcb5354f8 100644 --- a/Marlin/src/gcode/calibrate/M48.cpp +++ b/Marlin/src/gcode/calibrate/M48.cpp @@ -58,7 +58,7 @@ void GcodeSuite::M48() { - if (homing_needed_error()) return; + if (motion.homing_needed_error()) return; const int8_t verbose_level = parser.byteval('V', 1); if (!WITHIN(verbose_level, 0, 4)) { @@ -76,8 +76,8 @@ void GcodeSuite::M48() { // Test at the current position by default, overridden by X and Y const xy_pos_t test_position = { - parser.linearval('X', current_position.x + probe.offset_xy.x), // If no X use the probe's current X position - parser.linearval('Y', current_position.y + probe.offset_xy.y) // If no Y, ditto + parser.linearval('X', motion.position.x + probe.offset_xy.x), // If no X use the probe's current X position + parser.linearval('Y', motion.position.y + probe.offset_xy.y) // If no Y, ditto }; if (!probe.can_reach(test_position)) { @@ -115,7 +115,7 @@ void GcodeSuite::M48() { TERN_(HAS_PTC, ptc.set_enabled(parser.boolval('C', true))); // Work with reasonable feedrates - remember_feedrate_scaling_off(); + motion.remember_feedrate_scaling_off(); // Working variables float mean = 0.0, // The average of all points so far, used to calculate deviation @@ -216,7 +216,7 @@ void GcodeSuite::M48() { if (verbose_level > 3) SERIAL_ECHOLN(F("Going to: X"), next_pos.x, FPSTR(SP_Y_STR), next_pos.y); - do_blocking_move_to_xy(next_pos); + motion.blocking_move_xy(next_pos); } // n_legs loop } // n_legs @@ -277,7 +277,7 @@ void GcodeSuite::M48() { #endif } - restore_feedrate_and_scaling(); + motion.restore_feedrate_and_scaling(); // Re-enable bed level correction if it had been on TERN_(HAS_LEVELING, set_bed_leveling_enabled(was_enabled)); @@ -285,7 +285,7 @@ void GcodeSuite::M48() { // Re-enable probe temperature correction TERN_(HAS_PTC, ptc.set_enabled(true)); - report_current_position(); + motion.report_position(); } #endif // Z_MIN_PROBE_REPEATABILITY_TEST diff --git a/Marlin/src/gcode/calibrate/M665.cpp b/Marlin/src/gcode/calibrate/M665.cpp index 5409ff4232..ac2be7652f 100644 --- a/Marlin/src/gcode/calibrate/M665.cpp +++ b/Marlin/src/gcode/calibrate/M665.cpp @@ -106,13 +106,13 @@ #if HAS_SCARA_OFFSET - if (parser.seenval('Z')) scara_home_offset.z = parser.value_linear_units(); + if (parser.seenval('Z')) motion.scara_home_offset.z = parser.value_linear_units(); const bool hasA = parser.seenval('A'), hasP = parser.seenval('P'), hasX = parser.seenval('X'); const uint8_t sumAPX = hasA + hasP + hasX; if (sumAPX) { if (sumAPX == 1) - scara_home_offset.a = parser.value_float(); + motion.scara_home_offset.a = parser.value_float(); else { SERIAL_ERROR_MSG("Only one of A, P, or X is allowed."); return; @@ -123,7 +123,7 @@ const uint8_t sumBTY = hasB + hasT + hasY; if (sumBTY) { if (sumBTY == 1) - scara_home_offset.b = parser.value_float(); + motion.scara_home_offset.b = parser.value_float(); else { SERIAL_ERROR_MSG("Only one of B, T, or Y is allowed."); return; @@ -140,9 +140,9 @@ SERIAL_ECHOLNPGM_P( PSTR(" M665 S"), segments_per_second #if HAS_SCARA_OFFSET - , SP_P_STR, scara_home_offset.a - , SP_T_STR, scara_home_offset.b - , SP_Z_STR, LINEAR_UNIT(scara_home_offset.z) + , SP_P_STR, motion.scara_home_offset.a + , SP_T_STR, motion.scara_home_offset.b + , SP_Z_STR, LINEAR_UNIT(motion.scara_home_offset.z) #endif ); } diff --git a/Marlin/src/gcode/calibrate/M852.cpp b/Marlin/src/gcode/calibrate/M852.cpp index 7cd9aaf718..726aedefd8 100644 --- a/Marlin/src/gcode/calibrate/M852.cpp +++ b/Marlin/src/gcode/calibrate/M852.cpp @@ -89,9 +89,9 @@ void GcodeSuite::M852() { // When skew is changed the current position changes if (setval) { - set_current_from_steppers_for_axis(ALL_AXES_ENUM); - sync_plan_position(); - report_current_position(); + motion.set_current_from_steppers_for_axis(ALL_AXES_ENUM); + motion.sync_plan_position(); + motion.report_position(); } } diff --git a/Marlin/src/gcode/config/M210.cpp b/Marlin/src/gcode/config/M210.cpp index 41dbd73db4..0f1ecddec0 100644 --- a/Marlin/src/gcode/config/M210.cpp +++ b/Marlin/src/gcode/config/M210.cpp @@ -48,15 +48,15 @@ void GcodeSuite::M210() { return M210_report(); NUM_AXIS_CODE( - if (parser.floatval(AXIS1_PARAM) > 0) homing_feedrate_mm_m.x = parser.value_axis_units(X_AXIS), - if (parser.floatval(AXIS2_PARAM) > 0) homing_feedrate_mm_m.y = parser.value_axis_units(Y_AXIS), - if (parser.floatval(AXIS3_PARAM) > 0) homing_feedrate_mm_m.z = parser.value_axis_units(Z_AXIS), - if (parser.floatval(AXIS4_PARAM) > 0) homing_feedrate_mm_m.i = parser.value_axis_units(I_AXIS), - if (parser.floatval(AXIS5_PARAM) > 0) homing_feedrate_mm_m.j = parser.value_axis_units(J_AXIS), - if (parser.floatval(AXIS6_PARAM) > 0) homing_feedrate_mm_m.k = parser.value_axis_units(K_AXIS), - if (parser.floatval(AXIS7_PARAM) > 0) homing_feedrate_mm_m.u = parser.value_axis_units(U_AXIS), - if (parser.floatval(AXIS8_PARAM) > 0) homing_feedrate_mm_m.v = parser.value_axis_units(V_AXIS), - if (parser.floatval(AXIS9_PARAM) > 0) homing_feedrate_mm_m.w = parser.value_axis_units(W_AXIS) + if (parser.floatval(AXIS1_PARAM) > 0) motion.homing_feedrate_mm_m.x = parser.value_axis_units(X_AXIS), + if (parser.floatval(AXIS2_PARAM) > 0) motion.homing_feedrate_mm_m.y = parser.value_axis_units(Y_AXIS), + if (parser.floatval(AXIS3_PARAM) > 0) motion.homing_feedrate_mm_m.z = parser.value_axis_units(Z_AXIS), + if (parser.floatval(AXIS4_PARAM) > 0) motion.homing_feedrate_mm_m.i = parser.value_axis_units(I_AXIS), + if (parser.floatval(AXIS5_PARAM) > 0) motion.homing_feedrate_mm_m.j = parser.value_axis_units(J_AXIS), + if (parser.floatval(AXIS6_PARAM) > 0) motion.homing_feedrate_mm_m.k = parser.value_axis_units(K_AXIS), + if (parser.floatval(AXIS7_PARAM) > 0) motion.homing_feedrate_mm_m.u = parser.value_axis_units(U_AXIS), + if (parser.floatval(AXIS8_PARAM) > 0) motion.homing_feedrate_mm_m.v = parser.value_axis_units(V_AXIS), + if (parser.floatval(AXIS9_PARAM) > 0) motion.homing_feedrate_mm_m.w = parser.value_axis_units(W_AXIS) ); } @@ -67,15 +67,15 @@ void GcodeSuite::M210_report(const bool forReplay/*=true*/) { SERIAL_ECHOPGM(" M210"); SERIAL_ECHOLNPGM_P(NUM_AXIS_PAIRED_LIST( - SP_X_STR, X_AXIS_UNIT(homing_feedrate_mm_m.x), - SP_Y_STR, Y_AXIS_UNIT(homing_feedrate_mm_m.y), - SP_Z_STR, Z_AXIS_UNIT(homing_feedrate_mm_m.z), - SP_I_STR, I_AXIS_UNIT(homing_feedrate_mm_m.i), - SP_J_STR, J_AXIS_UNIT(homing_feedrate_mm_m.j), - SP_K_STR, K_AXIS_UNIT(homing_feedrate_mm_m.k), - SP_U_STR, U_AXIS_UNIT(homing_feedrate_mm_m.u), - SP_V_STR, V_AXIS_UNIT(homing_feedrate_mm_m.v), - SP_W_STR, W_AXIS_UNIT(homing_feedrate_mm_m.w) + SP_X_STR, X_AXIS_UNIT(motion.homing_feedrate_mm_m.x), + SP_Y_STR, Y_AXIS_UNIT(motion.homing_feedrate_mm_m.y), + SP_Z_STR, Z_AXIS_UNIT(motion.homing_feedrate_mm_m.z), + SP_I_STR, I_AXIS_UNIT(motion.homing_feedrate_mm_m.i), + SP_J_STR, J_AXIS_UNIT(motion.homing_feedrate_mm_m.j), + SP_K_STR, K_AXIS_UNIT(motion.homing_feedrate_mm_m.k), + SP_U_STR, U_AXIS_UNIT(motion.homing_feedrate_mm_m.u), + SP_V_STR, V_AXIS_UNIT(motion.homing_feedrate_mm_m.v), + SP_W_STR, W_AXIS_UNIT(motion.homing_feedrate_mm_m.w) )); } diff --git a/Marlin/src/gcode/config/M217.cpp b/Marlin/src/gcode/config/M217.cpp index df275c2d31..d05bb37b51 100644 --- a/Marlin/src/gcode/config/M217.cpp +++ b/Marlin/src/gcode/config/M217.cpp @@ -31,7 +31,7 @@ #endif #if ENABLED(TOOLCHANGE_MIGRATION_FEATURE) - #include "../../module/motion.h" // for active_extruder + #include "../../module/motion.h" // for motion.extruder #endif /** @@ -133,7 +133,7 @@ void GcodeSuite::M217() { const int16_t lval = parser.value_int(); if (WITHIN(lval, 0, EXTRUDERS - 1)) { migration.last = lval; - migration.automode = (active_extruder < migration.last); + migration.automode = (motion.extruder < migration.last); } } @@ -143,7 +143,7 @@ void GcodeSuite::M217() { if (parser.seen('T')) { // Migrate now if (parser.has_value()) { const int16_t tval = parser.value_int(); - if (WITHIN(tval, 0, EXTRUDERS - 1) && tval != active_extruder) { + if (WITHIN(tval, 0, EXTRUDERS - 1) && tval != motion.extruder) { migration.target = tval + 1; extruder_migration(); migration.target = 0; // disable diff --git a/Marlin/src/gcode/config/M218.cpp b/Marlin/src/gcode/config/M218.cpp index 7d167e502d..69bb89d74c 100644 --- a/Marlin/src/gcode/config/M218.cpp +++ b/Marlin/src/gcode/config/M218.cpp @@ -57,8 +57,8 @@ void GcodeSuite::M218() { #endif #if ENABLED(DELTA) - if (target_extruder == active_extruder) - do_blocking_move_to_xy(current_position, planner.settings.max_feedrate_mm_s[X_AXIS]); + if (target_extruder == motion.extruder) + motion.blocking_move_xy(motion.position, planner.settings.max_feedrate_mm_s[X_AXIS]); #endif } diff --git a/Marlin/src/gcode/config/M220.cpp b/Marlin/src/gcode/config/M220.cpp index 0d1e204800..6229cc2261 100644 --- a/Marlin/src/gcode/config/M220.cpp +++ b/Marlin/src/gcode/config/M220.cpp @@ -36,14 +36,14 @@ */ void GcodeSuite::M220() { if (!parser.seen_any()) { - SERIAL_ECHOLNPGM("FR:", feedrate_percentage, "%"); + SERIAL_ECHOLNPGM("FR:", motion.feedrate_percentage, "%"); return; } static int16_t backup_feedrate_percentage = 100; - const int16_t now_feedrate_perc = feedrate_percentage; - if (parser.seen_test('R')) feedrate_percentage = backup_feedrate_percentage; + const int16_t now_feedrate_perc = motion.feedrate_percentage; + if (parser.seen_test('R')) motion.feedrate_percentage = backup_feedrate_percentage; if (parser.seen_test('B')) backup_feedrate_percentage = now_feedrate_perc; - if (parser.seenval('S')) feedrate_percentage = parser.value_int(); + if (parser.seenval('S')) motion.feedrate_percentage = parser.value_int(); } diff --git a/Marlin/src/gcode/config/M92.cpp b/Marlin/src/gcode/config/M92.cpp index 48c3c5f2f0..a043074585 100644 --- a/Marlin/src/gcode/config/M92.cpp +++ b/Marlin/src/gcode/config/M92.cpp @@ -57,7 +57,7 @@ void GcodeSuite::M92() { planner.settings.axis_steps_per_mm[i] = parser.value_per_axis_units((AxisEnum)i); else { #if HAS_EXTRUDERS - const float value = parser.value_per_axis_units((AxisEnum)(E_AXIS_N(target_extruder))); + const float value = parser.value_per_axis_units(AxisEnum(E_AXIS_N(target_extruder))); if (value < 20) { float factor = planner.settings.axis_steps_per_mm[E_AXIS_N(target_extruder)] / value; // increase e constants if M92 E14 is given for netfab. #if ALL(CLASSIC_JERK, HAS_CLASSIC_E_JERK) diff --git a/Marlin/src/gcode/control/M108_M112_M410.cpp b/Marlin/src/gcode/control/M108_M112_M410.cpp index e2ca9b2247..dc7213b98e 100644 --- a/Marlin/src/gcode/control/M108_M112_M410.cpp +++ b/Marlin/src/gcode/control/M108_M112_M410.cpp @@ -45,5 +45,5 @@ void GcodeSuite::M112() { * will be out of sync with the stepper position after this. */ void GcodeSuite::M410() { - quickstop_stepper(); + motion.quickstop_stepper(); } diff --git a/Marlin/src/gcode/control/M211.cpp b/Marlin/src/gcode/control/M211.cpp index e51a9d5297..07d849c0f2 100644 --- a/Marlin/src/gcode/control/M211.cpp +++ b/Marlin/src/gcode/control/M211.cpp @@ -34,7 +34,7 @@ */ void GcodeSuite::M211() { if (parser.seen('S')) - soft_endstop._enabled = parser.value_bool(); + motion.soft_endstop._enabled = parser.value_bool(); else M211_report(); } @@ -43,11 +43,11 @@ void GcodeSuite::M211_report(const bool forReplay/*=true*/) { TERN_(MARLIN_SMALL_BUILD, return); report_heading_etc(forReplay, F(STR_SOFT_ENDSTOPS)); - SERIAL_ECHOLNPGM(" M211 S", AS_DIGIT(soft_endstop._enabled), " ; ", ON_OFF(soft_endstop._enabled)); + SERIAL_ECHOLNPGM(" M211 S", AS_DIGIT(motion.soft_endstop._enabled), " ; ", ON_OFF(motion.soft_endstop._enabled)); report_echo_start(forReplay); - const xyz_pos_t l_soft_min = soft_endstop.min.asLogical(), - l_soft_max = soft_endstop.max.asLogical(); + const xyz_pos_t l_soft_min = motion.soft_endstop.min.asLogical(), + l_soft_max = motion.soft_endstop.max.asLogical(); print_xyz(l_soft_min, F(STR_SOFT_MIN), F(" ")); print_xyz(l_soft_max, F(STR_SOFT_MAX)); } diff --git a/Marlin/src/gcode/control/M380_M381.cpp b/Marlin/src/gcode/control/M380_M381.cpp index 20d24484ed..9b8de3eccf 100644 --- a/Marlin/src/gcode/control/M380_M381.cpp +++ b/Marlin/src/gcode/control/M380_M381.cpp @@ -35,9 +35,9 @@ */ void GcodeSuite::M380() { #if ENABLED(MANUAL_SOLENOID_CONTROL) - enable_solenoid(parser.intval('S', active_extruder)); + enable_solenoid(parser.intval('S', motion.extruder)); #else - enable_solenoid(active_extruder); + enable_solenoid(motion.extruder); #endif } @@ -47,7 +47,7 @@ void GcodeSuite::M380() { */ void GcodeSuite::M381() { #if ENABLED(MANUAL_SOLENOID_CONTROL) - disable_solenoid(parser.intval('S', active_extruder)); + disable_solenoid(parser.intval('S', motion.extruder)); #else disable_all_solenoids(); #endif diff --git a/Marlin/src/gcode/control/M605.cpp b/Marlin/src/gcode/control/M605.cpp index bf5549262d..f5d514bd3f 100644 --- a/Marlin/src/gcode/control/M605.cpp +++ b/Marlin/src/gcode/control/M605.cpp @@ -80,7 +80,7 @@ if (parser.seenval('X')) duplicate_extruder_x_offset = _MAX(parser.value_linear_units(), (X2_MIN_POS) - (X1_MIN_POS)); if (parser.seenval('R')) duplicate_extruder_temp_offset = parser.value_celsius_diff(); // Always switch back to tool 0 - if (active_extruder != 0) tool_change(0); + if (motion.extruder != 0) tool_change(0); break; case DXC_MIRRORED_MODE: { @@ -93,9 +93,9 @@ idex_set_mirrored_mode(true); // Do a small 'jog' motion in the X axis - xyze_pos_t dest = current_position; dest.x -= 0.1f; + xyze_pos_t dest = motion.position; dest.x -= 0.1f; for (uint8_t i = 2; --i;) { - planner.buffer_line(dest, feedrate_mm_s, 0); + planner.buffer_line(dest, motion.feedrate_mm_s, 0); dest.x += 0.1f; } } return; @@ -126,10 +126,10 @@ case DXC_DUPLICATION_MODE: DEBUG_ECHOPGM("DUPLICATION"); break; case DXC_MIRRORED_MODE: DEBUG_ECHOPGM("MIRRORED"); break; } - DEBUG_ECHOPGM("\nActive Ext: ", active_extruder); + DEBUG_ECHOPGM("\nActive Ext: ", motion.extruder); if (!active_extruder_parked) DEBUG_ECHOPGM(" NOT ", F(" parked.")); DEBUG_ECHOLNPGM( - "\nactive_extruder_x_pos: ", current_position.x, + "\nactive_extruder_x_pos: ", motion.position.x, "\ninactive_extruder_x: ", inactive_extruder_x, "\nextruder_duplication_enabled: ", extruder_duplication_enabled, "\nduplicate_extruder_x_offset: ", duplicate_extruder_x_offset, diff --git a/Marlin/src/gcode/control/T.cpp b/Marlin/src/gcode/control/T.cpp index d5affa37e2..75f7adea2d 100644 --- a/Marlin/src/gcode/control/T.cpp +++ b/Marlin/src/gcode/control/T.cpp @@ -58,7 +58,7 @@ void GcodeSuite::T(const int8_t tool_index) { #if HAS_MULTI_EXTRUDER // For 'T' with no parameter report the current tool. if (parser.string_arg && *parser.string_arg == '*') { - SERIAL_ECHOLNPGM(STR_ACTIVE_EXTRUDER, active_extruder); + SERIAL_ECHOLNPGM(STR_ACTIVE_EXTRUDER, motion.extruder); return; } #endif @@ -84,7 +84,7 @@ void GcodeSuite::T(const int8_t tool_index) { tool_change(tool_index #if HAS_MULTI_EXTRUDER , parser.boolval('S') - || TERN(PARKING_EXTRUDER, false, tool_index == active_extruder) // For PARKING_EXTRUDER motion is decided in tool_change() + || TERN(PARKING_EXTRUDER, false, tool_index == motion.extruder) // For PARKING_EXTRUDER motion is decided in tool_change() #endif ); } diff --git a/Marlin/src/gcode/feature/advance/M900.cpp b/Marlin/src/gcode/feature/advance/M900.cpp index 7631cd0e8c..617bb57916 100644 --- a/Marlin/src/gcode/feature/advance/M900.cpp +++ b/Marlin/src/gcode/feature/advance/M900.cpp @@ -58,7 +58,7 @@ void GcodeSuite::M900() { constexpr uint8_t tool_index = 0; UNUSED(tool_index); #else - const uint8_t tool_index = parser.intval('T', active_extruder); + const uint8_t tool_index = parser.intval('T', motion.extruder); if (tool_index >= EXTRUDERS) { echo_value_oor('T', false); return; diff --git a/Marlin/src/gcode/feature/camera/M240.cpp b/Marlin/src/gcode/feature/camera/M240.cpp index 191a827ff4..7ce0a1934c 100644 --- a/Marlin/src/gcode/feature/camera/M240.cpp +++ b/Marlin/src/gcode/feature/camera/M240.cpp @@ -25,7 +25,7 @@ #if ENABLED(PHOTO_GCODE) #include "../../gcode.h" -#include "../../../module/motion.h" // for active_extruder and current_position +#include "../../../module/motion.h" // for motion.extruder and motion.position #if PIN_EXISTS(CHDK) millis_t chdk_timeout; // = 0 @@ -44,8 +44,8 @@ #ifdef PHOTO_RETRACT_MM inline void e_move_m240(const float length, const feedRate_t fr_mm_s) { - if (length && thermalManager.hotEnoughToExtrude(active_extruder)) - unscaled_e_move(length, fr_mm_s); + if (length && thermalManager.hotEnoughToExtrude(motion.extruder)) + motion.unscaled_e_move(length, fr_mm_s); } #endif @@ -122,14 +122,14 @@ void GcodeSuite::M240() { #ifdef PHOTO_POSITION - if (homing_needed_error()) return; + if (motion.homing_needed_error()) return; const xyz_pos_t old_pos = NUM_AXIS_ARRAY( - current_position.x + parser.linearval('A'), - current_position.y + parser.linearval('B'), - current_position.z, - current_position.i, current_position.j, current_position.k, - current_position.u, current_position.v, current_position.w + motion.position.x + parser.linearval('A'), + motion.position.y + parser.linearval('B'), + motion.position.z, + motion.position.i, motion.position.j, motion.position.k, + motion.position.u, motion.position.v, motion.position.w ); #ifdef PHOTO_RETRACT_MM @@ -143,24 +143,24 @@ void GcodeSuite::M240() { constexpr xyz_pos_t photo_position = PHOTO_POSITION; xyz_pos_t raw = { - parser.seenval('X') ? RAW_X_POSITION(parser.value_linear_units()) : photo_position.x, - parser.seenval('Y') ? RAW_Y_POSITION(parser.value_linear_units()) : photo_position.y, - (parser.seenval('Z') ? parser.value_linear_units() : photo_position.z) + current_position.z + parser.seenval('X') ? motion.raw_x(parser.value_linear_units()) : photo_position.x, + parser.seenval('Y') ? motion.raw_y(parser.value_linear_units()) : photo_position.y, + (parser.seenval('Z') ? parser.value_linear_units() : photo_position.z) + motion.position.z }; - apply_motion_limits(raw); - do_blocking_move_to(raw, fr_mm_s); + motion.apply_limits(raw); + motion.blocking_move(raw, fr_mm_s); #ifdef PHOTO_SWITCH_POSITION constexpr xy_pos_t photo_switch_position = PHOTO_SWITCH_POSITION; const xy_pos_t sraw = { - parser.seenval('I') ? RAW_X_POSITION(parser.value_linear_units()) : photo_switch_position.x, - parser.seenval('J') ? RAW_Y_POSITION(parser.value_linear_units()) : photo_switch_position.y + parser.seenval('I') ? motion.raw_x(parser.value_linear_units()) : photo_switch_position.x, + parser.seenval('J') ? motion.raw_y(parser.value_linear_units()) : photo_switch_position.y }; - do_blocking_move_to_xy(sraw, get_homing_bump_feedrate(X_AXIS)); + motion.blocking_move_xy(sraw, motion.get_homing_bump_feedrate(X_AXIS)); #if PHOTO_SWITCH_MS > 0 safe_delay(parser.intval('D', PHOTO_SWITCH_MS)); #endif - do_blocking_move_to(raw); + motion.blocking_move(raw); #endif #endif @@ -183,7 +183,7 @@ void GcodeSuite::M240() { const millis_t timeout = millis() + parser.intval('P', PHOTO_DELAY_MS); while (PENDING(millis(), timeout)) marlin.idle(); #endif - do_blocking_move_to(old_pos, fr_mm_s); + motion.blocking_move(old_pos, fr_mm_s); #ifdef PHOTO_RETRACT_MM e_move_m240(rval, sval); #endif diff --git a/Marlin/src/gcode/feature/clean/G12.cpp b/Marlin/src/gcode/feature/clean/G12.cpp index a5e312f8fd..2e8d784207 100644 --- a/Marlin/src/gcode/feature/clean/G12.cpp +++ b/Marlin/src/gcode/feature/clean/G12.cpp @@ -48,7 +48,7 @@ void GcodeSuite::G12() { // Don't allow nozzle cleaning without homing first constexpr main_axes_bits_t clean_axis_mask = main_axes_mask & ~TERN0(NOZZLE_CLEAN_NO_Z, Z_AXIS) & ~TERN0(NOZZLE_CLEAN_NO_Y, Y_AXIS); - if (homing_needed_error(clean_axis_mask)) return; + if (motion.homing_needed_error(clean_axis_mask)) return; #ifdef WIPE_SEQUENCE_COMMANDS if (!parser.seen_any()) { @@ -79,11 +79,11 @@ void GcodeSuite::G12() { TEMPORARY_BED_LEVELING_STATE(!TEST(cleans, Z_AXIS) && planner.leveling_active); #endif - SET_SOFT_ENDSTOP_LOOSE(!parser.boolval('E')); + motion.set_soft_endstop_loose(!parser.boolval('E')); nozzle.clean(pattern, strokes, radius, objects, cleans); - SET_SOFT_ENDSTOP_LOOSE(false); + motion.set_soft_endstop_loose(false); } #endif // NOZZLE_CLEAN_FEATURE diff --git a/Marlin/src/gcode/feature/mixing/M166.cpp b/Marlin/src/gcode/feature/mixing/M166.cpp index d3741f5931..9d717de7f5 100644 --- a/Marlin/src/gcode/feature/mixing/M166.cpp +++ b/Marlin/src/gcode/feature/mixing/M166.cpp @@ -92,8 +92,8 @@ void GcodeSuite::M166() { SERIAL_ECHOPGM(" ; Current Z"); #if ENABLED(DELTA) - get_cartesian_from_steppers(); - SERIAL_ECHO(cartes.z); + motion.get_cartesian_from_steppers(); + SERIAL_ECHO(motion.cartes.z); #else SERIAL_ECHO(planner.get_axis_position_mm(Z_AXIS)); #endif diff --git a/Marlin/src/gcode/feature/pause/G27.cpp b/Marlin/src/gcode/feature/pause/G27.cpp index 1fe6a490ea..9fdff6ccc3 100644 --- a/Marlin/src/gcode/feature/pause/G27.cpp +++ b/Marlin/src/gcode/feature/pause/G27.cpp @@ -43,7 +43,7 @@ */ void GcodeSuite::G27() { // Don't allow nozzle parking without homing first - if (homing_needed_error()) return; + if (motion.homing_needed_error()) return; const int16_t pval = parser.intval('P'); if (WITHIN(pval, 0, 4)) { nozzle.park(pval); diff --git a/Marlin/src/gcode/feature/pause/G60_G61.cpp b/Marlin/src/gcode/feature/pause/G60_G61.cpp index 8a24433cdb..ca2dc7d5f2 100644 --- a/Marlin/src/gcode/feature/pause/G60_G61.cpp +++ b/Marlin/src/gcode/feature/pause/G60_G61.cpp @@ -99,7 +99,7 @@ void GcodeSuite::G60() { } // G60 S - stored_position[slot] = current_position; + stored_position[slot] = motion.position; did_save_position.set(slot); report_stored_position(slot); } @@ -130,7 +130,7 @@ void GcodeSuite::G61(int8_t slot/*=-1*/) { if (slot < 0) slot = parser.byteval('S'); - #define SYNC_E(E) planner.set_e_position_mm(current_position.e = (E)) + #define SYNC_E(E) planner.set_e_position_mm(motion.position.e = (E)) if (SAVED_POSITIONS < 256 && slot >= SAVED_POSITIONS) { SERIAL_ERROR_MSG(STR_INVALID_POS_SLOT STRINGIFY(SAVED_POSITIONS)); @@ -141,9 +141,9 @@ void GcodeSuite::G61(int8_t slot/*=-1*/) { if (!did_save_position[slot]) return; // Apply any given feedrate over 0.0 - REMEMBER(saved, feedrate_mm_s); + REMEMBER(saved, motion.feedrate_mm_s); const float fr = parser.linearval('F'); - if (fr > 0.0) feedrate_mm_s = MMM_TO_MMS(fr); + if (fr > 0.0) motion.feedrate_mm_s = MMM_TO_MMS(fr); // No XYZ...E parameters, move to stored position @@ -153,10 +153,10 @@ void GcodeSuite::G61(int8_t slot/*=-1*/) { if (!parser.seen_axis()) { DEBUG_ECHOLNPGM(STR_RESTORING_POSITION, slot, " (all axes)"); // Move to the saved position, all axes except E - do_blocking_move_to(stored_position[slot], feedrate_mm_s); + motion.blocking_move(stored_position[slot], motion.feedrate_mm_s); // Just set E to the saved position without moving it TERN_(HAS_EXTRUDERS, SYNC_E(stored_position[slot].e)); - report_current_position(); + motion.report_position(); return; } @@ -165,14 +165,14 @@ void GcodeSuite::G61(int8_t slot/*=-1*/) { DEBUG_ECHOPGM(STR_RESTORING_POSITION " S", slot); if (parser.seen(STR_AXES_MAIN)) { - destination = current_position; + motion.destination = motion.position; LOOP_NUM_AXES(i) { if (parser.seen(AXIS_CHAR(i))) { - destination[i] = stored_position[slot][i] + parser.value_axis_units((AxisEnum)i); - DEBUG_ECHO(C(' '), C(AXIS_CHAR(i)), p_float_t(destination[i], 2)); + motion.destination[i] = stored_position[slot][i] + parser.value_axis_units((AxisEnum)i); + DEBUG_ECHO(C(' '), C(AXIS_CHAR(i)), p_float_t(motion.destination[i], 2)); } } - prepare_line_to_destination(); + motion.prepare_line_to_destination(); } #if HAS_EXTRUDERS @@ -185,7 +185,7 @@ void GcodeSuite::G61(int8_t slot/*=-1*/) { DEBUG_EOL(); - report_current_position(); + motion.report_position(); } #endif // SAVED_POSITIONS diff --git a/Marlin/src/gcode/feature/pause/M125.cpp b/Marlin/src/gcode/feature/pause/M125.cpp index 75611760f1..5ec7b3e01b 100644 --- a/Marlin/src/gcode/feature/pause/M125.cpp +++ b/Marlin/src/gcode/feature/pause/M125.cpp @@ -68,15 +68,15 @@ void GcodeSuite::M125() { // Move to filament change position or given position NUM_AXIS_CODE( - if (parser.seenval('X')) park_point.x = RAW_X_POSITION(parser.linearval('X')), - if (parser.seenval('Y')) park_point.y = RAW_Y_POSITION(parser.linearval('Y')), + if (parser.seenval('X')) park_point.x = motion.raw_x(parser.linearval('X')), + if (parser.seenval('Y')) park_point.y = motion.raw_y(parser.linearval('Y')), NOOP, - if (parser.seenval(AXIS4_NAME)) park_point.i = RAW_I_POSITION(parser.linearval(AXIS4_NAME)), - if (parser.seenval(AXIS5_NAME)) park_point.j = RAW_J_POSITION(parser.linearval(AXIS5_NAME)), - if (parser.seenval(AXIS6_NAME)) park_point.k = RAW_K_POSITION(parser.linearval(AXIS6_NAME)), - if (parser.seenval(AXIS7_NAME)) park_point.u = RAW_U_POSITION(parser.linearval(AXIS7_NAME)), - if (parser.seenval(AXIS8_NAME)) park_point.v = RAW_V_POSITION(parser.linearval(AXIS8_NAME)), - if (parser.seenval(AXIS9_NAME)) park_point.w = RAW_W_POSITION(parser.linearval(AXIS9_NAME)) + if (parser.seenval(AXIS4_NAME)) park_point.i = motion.raw_i(parser.linearval(AXIS4_NAME)), + if (parser.seenval(AXIS5_NAME)) park_point.j = motion.raw_j(parser.linearval(AXIS5_NAME)), + if (parser.seenval(AXIS6_NAME)) park_point.k = motion.raw_k(parser.linearval(AXIS6_NAME)), + if (parser.seenval(AXIS7_NAME)) park_point.u = motion.raw_u(parser.linearval(AXIS7_NAME)), + if (parser.seenval(AXIS8_NAME)) park_point.v = motion.raw_v(parser.linearval(AXIS8_NAME)), + if (parser.seenval(AXIS9_NAME)) park_point.w = motion.raw_w(parser.linearval(AXIS9_NAME)) ); // Lift Z axis @@ -85,7 +85,7 @@ void GcodeSuite::M125() { #endif #if HAS_HOTEND_OFFSET && NONE(DUAL_X_CARRIAGE, DELTA) - park_point += hotend_offset[active_extruder]; + park_point += hotend_offset[motion.extruder]; #endif const bool sd_printing = card.isStillPrinting(); diff --git a/Marlin/src/gcode/feature/pause/M600.cpp b/Marlin/src/gcode/feature/pause/M600.cpp index 294836fbba..774c96e9f6 100644 --- a/Marlin/src/gcode/feature/pause/M600.cpp +++ b/Marlin/src/gcode/feature/pause/M600.cpp @@ -94,7 +94,7 @@ void GcodeSuite::M600() { MIXER_STEPPER_LOOP(i) mixer.set_collector(i, i == uint8_t(eindex) ? 1.0 : 0.0); mixer.normalize(); - const int8_t target_extruder = active_extruder; + const int8_t target_extruder = motion.extruder; #else const int8_t target_extruder = get_target_extruder_from_command(); if (target_extruder < 0) return; @@ -108,7 +108,7 @@ void GcodeSuite::M600() { if (idex_is_duplicating()) DXC_ext = (READ(FIL_RUNOUT2_PIN) == FIL_RUNOUT2_STATE) ? 1 : 0; #else - DXC_ext = active_extruder; + DXC_ext = motion.extruder; #endif } #endif @@ -122,12 +122,12 @@ void GcodeSuite::M600() { TERN_(SOVOL_SV06_RTS, rts.gotoPage(ID_ChangeWait_L, ID_ChangeWait_D)); //given the context it seems this likely should have been pages 6 & 61 // If needed, home before parking for filament change - TERN_(HOME_BEFORE_FILAMENT_CHANGE, home_if_needed(true)); + TERN_(HOME_BEFORE_FILAMENT_CHANGE, motion.home_if_needed(true)); #if HAS_MULTI_EXTRUDER // Change toolhead if specified - const uint8_t active_extruder_before_filament_change = active_extruder; - if (active_extruder != target_extruder && TERN1(DUAL_X_CARRIAGE, !idex_is_duplicating())) + const uint8_t active_extruder_before_filament_change = motion.extruder; + if (motion.extruder != target_extruder && TERN1(DUAL_X_CARRIAGE, !idex_is_duplicating())) tool_change(target_extruder); #endif @@ -150,12 +150,12 @@ void GcodeSuite::M600() { ); #if HAS_HOTEND_OFFSET && NONE(DUAL_X_CARRIAGE, DELTA) - park_point += hotend_offset[active_extruder]; + park_point += hotend_offset[motion.extruder]; #endif // Unload filament // For MMU2, when enabled, reset retract value so it doesn't mess with MMU filament handling - const float unload_length = standardM600 ? -ABS(parser.axisunitsval('U', E_AXIS, fc_settings[active_extruder].unload_length)) : 0.5f; + const float unload_length = standardM600 ? -ABS(parser.axisunitsval('U', E_AXIS, fc_settings[motion.extruder].unload_length)) : 0.5f; const int beep_count = parser.intval('B', -1 #ifdef FILAMENT_CHANGE_ALERT_BEEPS @@ -168,7 +168,7 @@ void GcodeSuite::M600() { wait_for_confirmation(true, beep_count DXC_PASS); resume_print( FILAMENT_CHANGE_SLOW_LOAD_LENGTH, - ABS(parser.axisunitsval('L', E_AXIS, fc_settings[active_extruder].load_length)), + ABS(parser.axisunitsval('L', E_AXIS, fc_settings[motion.extruder].load_length)), ADVANCED_PAUSE_PURGE_LENGTH, beep_count, parser.celsiusval('R'), @@ -188,7 +188,7 @@ void GcodeSuite::M600() { #if HAS_MULTI_EXTRUDER // Restore toolhead if it was changed - if (active_extruder_before_filament_change != active_extruder) + if (active_extruder_before_filament_change != motion.extruder) tool_change(active_extruder_before_filament_change); #endif diff --git a/Marlin/src/gcode/feature/pause/M701_M702.cpp b/Marlin/src/gcode/feature/pause/M701_M702.cpp index dcdc1c9cbc..b7f5a47bae 100644 --- a/Marlin/src/gcode/feature/pause/M701_M702.cpp +++ b/Marlin/src/gcode/feature/pause/M701_M702.cpp @@ -59,7 +59,7 @@ void GcodeSuite::M701() { xyz_pos_t park_point = NOZZLE_PARK_POINT; // Don't raise Z if the machine isn't homed - if (TERN0(NO_MOTION_BEFORE_HOMING, axes_should_home())) park_point.z = 0; + if (TERN0(NO_MOTION_BEFORE_HOMING, motion.axes_should_home())) park_point.z = 0; #if ENABLED(MIXING_EXTRUDER) const int8_t eindex = get_target_e_stepper_from_command(); @@ -71,7 +71,7 @@ void GcodeSuite::M701() { MIXER_STEPPER_LOOP(i) mixer.set_collector(i, i == uint8_t(eindex) ? 1.0 : 0.0); mixer.normalize(); - const int8_t target_extruder = active_extruder; + const int8_t target_extruder = motion.extruder; #else const int8_t target_extruder = get_target_extruder_from_command(); if (target_extruder < 0) return; @@ -85,21 +85,21 @@ void GcodeSuite::M701() { #if HAS_MULTI_EXTRUDER && (HAS_PRUSA_MMU1 || !HAS_MMU) // Change toolhead if specified - uint8_t active_extruder_before_filament_change = active_extruder; - if (active_extruder != target_extruder) + uint8_t active_extruder_before_filament_change = motion.extruder; + if (motion.extruder != target_extruder) tool_change(target_extruder); #endif auto move_z_by = [](const float zdist) { if (zdist) { - destination = current_position; - destination.z += zdist; - prepare_internal_move_to_destination(NOZZLE_PARK_Z_FEEDRATE); + motion.destination = motion.position; + motion.destination.z += zdist; + motion.prepare_internal_move_to_destination(NOZZLE_PARK_Z_FEEDRATE); } }; // Raise the Z axis (with max limit) - const float park_raise = _MIN(park_point.z, (Z_MAX_POS) - current_position.z); + const float park_raise = _MIN(park_point.z, (Z_MAX_POS) - motion.position.z); move_z_by(park_raise); // Load filament @@ -111,7 +111,7 @@ void GcodeSuite::M701() { constexpr float purge_length = ADVANCED_PAUSE_PURGE_LENGTH, slow_load_length = FILAMENT_CHANGE_SLOW_LOAD_LENGTH; const float fast_load_length = ABS(parser.seenval('L') ? parser.value_axis_units(E_AXIS) - : fc_settings[active_extruder].load_length); + : fc_settings[motion.extruder].load_length); load_filament( slow_load_length, fast_load_length, purge_length, FILAMENT_CHANGE_ALERT_BEEPS, @@ -127,7 +127,7 @@ void GcodeSuite::M701() { #if HAS_MULTI_EXTRUDER && (HAS_PRUSA_MMU1 || !HAS_MMU) // Restore toolhead if it was changed - if (active_extruder_before_filament_change != active_extruder) + if (active_extruder_before_filament_change != motion.extruder) tool_change(active_extruder_before_filament_change); #endif @@ -152,7 +152,7 @@ void GcodeSuite::M702() { xyz_pos_t park_point = NOZZLE_PARK_POINT; // Don't raise Z if the machine isn't homed - if (TERN0(NO_MOTION_BEFORE_HOMING, axes_should_home())) park_point.z = 0; + if (TERN0(NO_MOTION_BEFORE_HOMING, motion.axes_should_home())) park_point.z = 0; #if ENABLED(MIXING_EXTRUDER) const uint8_t old_mixing_tool = mixer.get_current_vtool(); @@ -176,7 +176,7 @@ void GcodeSuite::M702() { mixer.normalize(); } - const int8_t target_extruder = active_extruder; + const int8_t target_extruder = motion.extruder; #else const int8_t target_extruder = get_target_extruder_from_command(); if (target_extruder < 0) return; @@ -190,14 +190,14 @@ void GcodeSuite::M702() { #if HAS_MULTI_EXTRUDER && (HAS_PRUSA_MMU1 || !HAS_MMU) // Change toolhead if specified - uint8_t active_extruder_before_filament_change = active_extruder; - if (active_extruder != target_extruder) + uint8_t active_extruder_before_filament_change = motion.extruder; + if (motion.extruder != target_extruder) tool_change(target_extruder); #endif // Lift Z axis if (park_point.z > 0) - do_blocking_move_to_z(_MIN(current_position.z + park_point.z, Z_MAX_POS), feedRate_t(NOZZLE_PARK_Z_FEEDRATE)); + motion.blocking_move_z(_MIN(motion.position.z + park_point.z, Z_MAX_POS), feedRate_t(NOZZLE_PARK_Z_FEEDRATE)); // Unload filament #if HAS_PRUSA_MMU3 @@ -208,7 +208,7 @@ void GcodeSuite::M702() { #if ALL(HAS_MULTI_EXTRUDER, FILAMENT_UNLOAD_ALL_EXTRUDERS) if (!parser.seenval('T')) { HOTEND_LOOP() { - if (e != active_extruder) tool_change(e); + if (e != motion.extruder) tool_change(e); unload_filament(-fc_settings[e].unload_length, true, PAUSE_MODE_UNLOAD_FILAMENT); } } @@ -229,11 +229,11 @@ void GcodeSuite::M702() { // Restore Z axis if (park_point.z > 0) - do_blocking_move_to_z(_MAX(current_position.z - park_point.z, 0), feedRate_t(NOZZLE_PARK_Z_FEEDRATE)); + motion.blocking_move_z(_MAX(motion.position.z - park_point.z, 0), feedRate_t(NOZZLE_PARK_Z_FEEDRATE)); #if HAS_MULTI_EXTRUDER && (HAS_PRUSA_MMU1 || !HAS_MMU) // Restore toolhead if it was changed - if (active_extruder_before_filament_change != active_extruder) + if (active_extruder_before_filament_change != motion.extruder) tool_change(active_extruder_before_filament_change); #endif diff --git a/Marlin/src/gcode/gcode.cpp b/Marlin/src/gcode/gcode.cpp index 10a6f3d65b..e84b367e7a 100644 --- a/Marlin/src/gcode/gcode.cpp +++ b/Marlin/src/gcode/gcode.cpp @@ -126,7 +126,7 @@ void GcodeSuite::say_units() { } /** - * Get the target extruder from the T parameter or the active_extruder + * Get the target extruder from the T parameter or the motion.extruder * Return -1 if the T parameter is out of range */ int8_t GcodeSuite::get_target_extruder_from_command() { @@ -137,7 +137,7 @@ int8_t GcodeSuite::get_target_extruder_from_command() { SERIAL_ECHOLN(C('M'), parser.codenum, F(" " STR_INVALID_EXTRUDER " "), e); return -1; } - return active_extruder; + return motion.extruder; } /** @@ -181,22 +181,22 @@ void GcodeSuite::get_destination_from_command() { if ( (seen[i] = parser.seenval(AXIS_CHAR(i))) ) { const float v = parser.value_axis_units((AxisEnum)i); if (skip_move) - destination[i] = current_position[i]; + motion.destination[i] = motion.position[i]; else - destination[i] = axis_is_relative((AxisEnum)i) ? current_position[i] + v : LOGICAL_TO_NATIVE(v, i); + motion.destination[i] = axis_is_relative((AxisEnum)i) ? motion.position[i] + v : motion.logical_to_native(v, (AxisEnum)i); } else - destination[i] = current_position[i]; + motion.destination[i] = motion.position[i]; } #if HAS_EXTRUDERS // Get new E position, whether absolute or relative if ( (seen.e = parser.seenval('E')) ) { const float v = parser.value_axis_units(E_AXIS); - destination.e = axis_is_relative(E_AXIS) ? current_position.e + v : v; + motion.destination.e = axis_is_relative(E_AXIS) ? motion.position.e + v : v; } else - destination.e = current_position.e; + motion.destination.e = motion.position.e; #endif #if ENABLED(POWER_LOSS_RECOVERY) && !PIN_EXISTS(POWER_LOSS) @@ -207,14 +207,14 @@ void GcodeSuite::get_destination_from_command() { if (parser.floatval('F') > 0) { const float fr_mm_min = parser.value_linear_units(); - feedrate_mm_s = MMM_TO_MMS(fr_mm_min); + motion.feedrate_mm_s = MMM_TO_MMS(fr_mm_min); // Update the cutter feed rate for use by M4 I set inline moves. TERN_(LASER_FEATURE, cutter.feedrate_mm_m = fr_mm_min); } #if ALL(PRINTCOUNTER, HAS_EXTRUDERS) if (!DEBUGGING(DRYRUN) && !skip_move) - print_job_timer.incFilamentUsed(destination.e - current_position.e); + print_job_timer.incFilamentUsed(motion.destination.e - motion.position.e); #endif // Get ABCDHI mixing factors @@ -904,7 +904,7 @@ void GcodeSuite::process_parsed_command(bool no_ok/*=false*/) { #endif #if HAS_HOME_OFFSET - case 428: M428(); break; // M428: Apply current_position to home_offset + case 428: M428(); break; // M428: Apply position to home_offset #endif #if HAS_POWER_MONITOR @@ -1273,15 +1273,15 @@ void GcodeSuite::process_subcommands_now(char * gcode) { case IN_HANDLER: case IN_PROCESS: SERIAL_ECHO_MSG(STR_BUSY_PROCESSING); - TERN_(FULL_REPORT_TO_HOST_FEATURE, report_current_position_moving()); + TERN_(FULL_REPORT_TO_HOST_FEATURE, motion.report_position_moving()); break; case PAUSED_FOR_USER: SERIAL_ECHO_MSG(STR_BUSY_PAUSED_FOR_USER); - TERN_(FULL_REPORT_TO_HOST_FEATURE, set_and_report_grblstate(M_HOLD)); + TERN_(FULL_REPORT_TO_HOST_FEATURE, motion.set_and_report_grblstate(M_HOLD)); break; case PAUSED_FOR_INPUT: SERIAL_ECHO_MSG(STR_BUSY_PAUSED_FOR_INPUT); - TERN_(FULL_REPORT_TO_HOST_FEATURE, set_and_report_grblstate(M_HOLD)); + TERN_(FULL_REPORT_TO_HOST_FEATURE, motion.set_and_report_grblstate(M_HOLD)); break; default: break; diff --git a/Marlin/src/gcode/gcode.h b/Marlin/src/gcode/gcode.h index 378a1a73f4..d80305fb75 100644 --- a/Marlin/src/gcode/gcode.h +++ b/Marlin/src/gcode/gcode.h @@ -247,7 +247,7 @@ * M421 - Set a single Z coordinate in the Mesh Leveling grid. X Y Z (Requires MESH_BED_LEVELING, AUTO_BED_LEVELING_BILINEAR, or AUTO_BED_LEVELING_UBL) * M422 - Set Z Stepper automatic alignment position using probe. X Y A (Requires Z_STEPPER_AUTO_ALIGN) * M425 - Enable/Disable and tune backlash correction. (Requires BACKLASH_COMPENSATION and BACKLASH_GCODE) - * M428 - Set the home_offset based on the current_position. Nearest edge applies. (Disabled by NO_WORKSPACE_OFFSETS or DELTA) + * M428 - Set the home_offset based on the position. Nearest edge applies. (Disabled by NO_WORKSPACE_OFFSETS or DELTA) * M430 - Read the system current, voltage, and power (Requires POWER_MONITOR_CURRENT, POWER_MONITOR_VOLTAGE, or POWER_MONITOR_FIXED_VOLTAGE) * M485 - Send RS485 packets (Requires RS485_SERIAL_PORT) * M486 - Identify and cancel objects. (Requires CANCEL_OBJECTS) diff --git a/Marlin/src/gcode/geometry/G53-G59.cpp b/Marlin/src/gcode/geometry/G53-G59.cpp index 017b54a084..1539ab61b5 100644 --- a/Marlin/src/gcode/geometry/G53-G59.cpp +++ b/Marlin/src/gcode/geometry/G53-G59.cpp @@ -37,7 +37,7 @@ bool GcodeSuite::select_coordinate_system(const int8_t _new) { xyz_float_t new_offset{0}; if (WITHIN(_new, 0, MAX_COORDINATE_SYSTEMS - 1)) new_offset = coordinate_system[_new]; - workspace_offset = new_offset; + motion.workspace_offset = new_offset; return true; } @@ -55,7 +55,7 @@ void GcodeSuite::G53() { select_coordinate_system(-1); // Always remove workspace offsets #ifdef DEBUG_M53 SERIAL_ECHOLNPGM("Go to native space"); - report_current_position(); + motion.report_position(); #endif if (parser.chain()) { // Command to chain? @@ -63,7 +63,7 @@ void GcodeSuite::G53() { select_coordinate_system(old_system); #ifdef DEBUG_M53 SERIAL_ECHOLNPGM("Go back to workspace ", old_system); - report_current_position(); + motion.report_position(); #endif } } @@ -81,7 +81,7 @@ void G54_59(uint8_t subcode=0) { const int8_t _space = parser.codenum - 54 + subcode; if (gcode.select_coordinate_system(_space)) { SERIAL_ECHOLNPGM("Select workspace ", _space); - report_current_position(); + motion.report_position(); } } void GcodeSuite::G54() { G54_59(); } diff --git a/Marlin/src/gcode/geometry/G92.cpp b/Marlin/src/gcode/geometry/G92.cpp index cfdff51eba..6b4b2bb32b 100644 --- a/Marlin/src/gcode/geometry/G92.cpp +++ b/Marlin/src/gcode/geometry/G92.cpp @@ -59,16 +59,16 @@ void GcodeSuite::G92() { #endif switch (subcode_G92) { - default: return; // Ignore unknown G92.x + default: return; // Ignore unknown G92.x #if ENABLED(CNC_COORDINATE_SYSTEMS) && !IS_SCARA - case 1: // G92.1 - Zero the Workspace Offset - workspace_offset.reset(); + case 1: // G92.1 - Zero the Workspace Offset + motion.workspace_offset.reset(); break; #endif #if ANY(POWER_LOSS_RECOVERY, HAS_ROTATIONAL_AXES) - case 9: // G92.9 - Set Current Position directly (like Marlin 1.0) + case 9: // G92.9 - Set Current Position directly (like Marlin 1.0) LOOP_LOGICAL_AXES(i) { if (parser.seenval(AXIS_CHAR(i))) { if (TERN1(HAS_EXTRUDERS, i != E_AXIS)) @@ -76,7 +76,7 @@ void GcodeSuite::G92() { else { TERN_(HAS_EXTRUDERS, sync_E = true); } - current_position[i] = parser.value_axis_units((AxisEnum)i); + motion.position[i] = parser.value_axis_units((AxisEnum)i); } } break; @@ -86,17 +86,17 @@ void GcodeSuite::G92() { LOOP_LOGICAL_AXES(i) { if (parser.seenval(AXIS_CHAR(i))) { const float l = parser.value_axis_units((AxisEnum)i), // Given axis coordinate value, converted to millimeters - v = TERN0(HAS_EXTRUDERS, i == E_AXIS) ? l : LOGICAL_TO_NATIVE(l, i), // Axis position in NATIVE space (applying the existing offset) - d = v - current_position[i]; // How much is the current axis position altered by? + v = TERN0(HAS_EXTRUDERS, i == E_AXIS) ? l : motion.logical_to_native(l, (AxisEnum)i), // Axis position in NATIVE space (applying the existing offset) + d = v - motion.position[i]; // How much is the current axis position altered by? if (!NEAR_ZERO(d)) { #if HAS_WORKSPACE_OFFSET && NONE(IS_SCARA, POLARGRAPH) // When using workspaces... if (TERN1(HAS_EXTRUDERS, i != E_AXIS)) { - workspace_offset[i] += d; // ...most axes offset the workspace... + motion.workspace_offset[i] += d; // ...most axes offset the workspace... } else { #if HAS_EXTRUDERS sync_E = true; - current_position.e = v; // ...but E is set directly + motion.position.e = v; // ...but E is set directly #endif } #else // Without workspaces... @@ -105,7 +105,7 @@ void GcodeSuite::G92() { else { TERN_(HAS_EXTRUDERS, sync_E = true); } - current_position[i] = v; // ...set Current Position directly (like Marlin 1.0) + motion.position[i] = v; // ...set Current Position directly (like Marlin 1.0) #endif } } @@ -116,13 +116,13 @@ void GcodeSuite::G92() { #if ENABLED(CNC_COORDINATE_SYSTEMS) // Apply Workspace Offset to the active coordinate system if (WITHIN(active_coordinate_system, 0, MAX_COORDINATE_SYSTEMS - 1)) - coordinate_system[active_coordinate_system] = workspace_offset; + coordinate_system[active_coordinate_system] = motion.workspace_offset; #endif - if (sync_XYZE) sync_plan_position(); + if (sync_XYZE) motion.sync_plan_position(); #if HAS_EXTRUDERS - else if (sync_E) sync_plan_position_e(); + else if (sync_E) motion.sync_plan_position_e(); #endif - IF_DISABLED(DIRECT_STEPPING, report_current_position()); + IF_DISABLED(DIRECT_STEPPING, motion.report_position()); } diff --git a/Marlin/src/gcode/geometry/M206_M428.cpp b/Marlin/src/gcode/geometry/M206_M428.cpp index 17bd2b1ff6..80771fb60c 100644 --- a/Marlin/src/gcode/geometry/M206_M428.cpp +++ b/Marlin/src/gcode/geometry/M206_M428.cpp @@ -37,13 +37,13 @@ void GcodeSuite::M206() { if (!parser.seen_any()) return M206_report(); LOOP_NUM_AXES(a) - if (parser.seenval(AXIS_CHAR(a))) set_home_offset((AxisEnum)a, parser.value_axis_units((AxisEnum)a)); + if (parser.seenval(AXIS_CHAR(a))) motion.set_home_offset((AxisEnum)a, parser.value_axis_units((AxisEnum)a)); #if ENABLED(MORGAN_SCARA) - if (parser.seenval('T')) set_home_offset(A_AXIS, parser.value_float()); // Theta - if (parser.seenval('P')) set_home_offset(B_AXIS, parser.value_float()); // Psi + if (parser.seenval('T')) motion.set_home_offset(A_AXIS, parser.value_float()); // Theta + if (parser.seenval('P')) motion.set_home_offset(B_AXIS, parser.value_float()); // Psi #endif - report_current_position(); + motion.report_position(); } void GcodeSuite::M206_report(const bool forReplay/*=true*/) { @@ -52,24 +52,24 @@ void GcodeSuite::M206_report(const bool forReplay/*=true*/) { report_heading_etc(forReplay, F(STR_HOME_OFFSET)); #if IS_CARTESIAN SERIAL_ECHOLNPGM_P(NUM_AXIS_PAIRED_LIST( - PSTR(" M206 X"), LINEAR_UNIT(home_offset.x), - SP_Y_STR, LINEAR_UNIT(home_offset.y), - SP_Z_STR, LINEAR_UNIT(home_offset.z), - SP_I_STR, I_AXIS_UNIT(home_offset.i), - SP_J_STR, J_AXIS_UNIT(home_offset.j), - SP_K_STR, K_AXIS_UNIT(home_offset.k), - SP_U_STR, U_AXIS_UNIT(home_offset.u), - SP_V_STR, V_AXIS_UNIT(home_offset.v), - SP_W_STR, W_AXIS_UNIT(home_offset.w) + PSTR(" M206 X"), LINEAR_UNIT(motion.home_offset.x), + SP_Y_STR, LINEAR_UNIT(motion.home_offset.y), + SP_Z_STR, LINEAR_UNIT(motion.home_offset.z), + SP_I_STR, I_AXIS_UNIT(motion.home_offset.i), + SP_J_STR, J_AXIS_UNIT(motion.home_offset.j), + SP_K_STR, K_AXIS_UNIT(motion.home_offset.k), + SP_U_STR, U_AXIS_UNIT(motion.home_offset.u), + SP_V_STR, V_AXIS_UNIT(motion.home_offset.v), + SP_W_STR, W_AXIS_UNIT(motion.home_offset.w) )); #else - SERIAL_ECHOLNPGM_P(PSTR(" M206 Z"), LINEAR_UNIT(home_offset.z)); + SERIAL_ECHOLNPGM_P(PSTR(" M206 Z"), LINEAR_UNIT(motion.home_offset.z)); #endif } /** * M428: Set home_offset based on the distance between the - * current_position and the nearest "reference point." + * current position and the nearest "reference point." * If an axis is past center its endstop position * is the reference-point. Otherwise it uses 0. This allows * the Z offset to be set near the bed when using a max endstop. @@ -79,13 +79,13 @@ void GcodeSuite::M206_report(const bool forReplay/*=true*/) { * Use M206 to set these values directly. */ void GcodeSuite::M428() { - if (homing_needed_error()) return; + if (motion.homing_needed_error()) return; xyz_float_t diff; LOOP_NUM_AXES(i) { - diff[i] = base_home_pos((AxisEnum)i) - current_position[i]; + diff[i] = base_home_pos((AxisEnum)i) - motion.position[i]; if (!WITHIN(diff[i], -20, 20) && home_dir((AxisEnum)i) > 0) - diff[i] = -current_position[i]; + diff[i] = -motion.position[i]; if (!WITHIN(diff[i], -20, 20)) { SERIAL_ERROR_MSG(STR_ERR_M428_TOO_FAR); LCD_ALERTMESSAGE(MSG_ERR_M428_TOO_FAR); @@ -94,8 +94,8 @@ void GcodeSuite::M428() { } } - LOOP_NUM_AXES(i) set_home_offset((AxisEnum)i, diff[i]); - report_current_position(); + LOOP_NUM_AXES(i) motion.set_home_offset((AxisEnum)i, diff[i]); + motion.report_position(); LCD_MESSAGE(MSG_HOME_OFFSETS_APPLIED); OKAY_BUZZ(); } diff --git a/Marlin/src/gcode/host/M114.cpp b/Marlin/src/gcode/host/M114.cpp index 35e618e6f2..6ae2c14502 100644 --- a/Marlin/src/gcode/host/M114.cpp +++ b/Marlin/src/gcode/host/M114.cpp @@ -39,20 +39,21 @@ inline void report_linear_axis_pos(const xyze_pos_t &pos) { report_all_axis_pos(pos, 3); } void report_linear_axis_pos(const xyz_pos_t &pos, const uint8_t precision=3) { - LOOP_NUM_AXES(a) SERIAL_ECHO(FPSTR(pgm_read_ptr(&SP_AXIS_LBL[a])), p_float_t(pos[a], precision)); + LOOP_NUM_AXES(a) + SERIAL_ECHO(FPSTR(pgm_read_ptr(&SP_AXIS_LBL[a])), p_float_t(pos[a], precision)); SERIAL_EOL(); } void report_current_position_detail() { // Position as sent by G-code SERIAL_ECHOPGM("\nLogical:"); - report_linear_axis_pos(current_position.asLogical()); + report_linear_axis_pos(motion.position.asLogical()); // Cartesian position in native machine space SERIAL_ECHOPGM("Raw: "); - report_linear_axis_pos(current_position); + report_linear_axis_pos(motion.position); - xyze_pos_t leveled = current_position; + xyze_pos_t leveled = motion.position; #if HAS_LEVELING // Current position with leveling applied @@ -71,7 +72,7 @@ // Kinematics applied to the leveled position SERIAL_ECHOPGM(TERN(POLAR, "Polar", TERN(IS_SCARA, "SCARA", "Delta")) "K: " ); inverse_kinematics(leveled); // writes delta[] - report_linear_axis_pos(delta); + report_linear_axis_pos(motion.delta); #endif planner.synchronize(); @@ -92,10 +93,10 @@ #endif SERIAL_ECHOPGM("FromStp:"); - get_cartesian_from_steppers(); // Writes 'cartes' (with forward kinematics) + motion.get_cartesian_from_steppers(); // Writes 'motion.cartes' (with forward kinematics) xyze_pos_t from_steppers = LOGICAL_AXIS_ARRAY( planner.get_axis_position_mm(E_AXIS), - cartes.x, cartes.y, cartes.z, + motion.cartes.x, motion.cartes.y, motion.cartes.z, planner.get_axis_position_mm(I_AXIS), planner.get_axis_position_mm(J_AXIS), planner.get_axis_position_mm(K_AXIS), @@ -109,7 +110,7 @@ SERIAL_ECHOPGM("Diff: "); report_all_axis_pos(diff); - TERN_(FULL_REPORT_TO_HOST_FEATURE, report_current_grblstate_moving()); + TERN_(FULL_REPORT_TO_HOST_FEATURE, motion.report_current_grblstate_moving()); } #endif // M114_DETAIL @@ -133,7 +134,7 @@ void GcodeSuite::M114() { #if ENABLED(M114_DETAIL) if (parser.seen_test('D')) { IF_DISABLED(M114_LEGACY, planner.synchronize()); - report_current_position(); + motion.report_position(); report_current_position_detail(); return; } @@ -145,10 +146,10 @@ void GcodeSuite::M114() { #endif #endif - TERN_(M114_REALTIME, if (parser.seen_test('R')) return report_real_position()); + TERN_(M114_REALTIME, if (parser.seen_test('R')) return motion.report_position_real()); TERN_(M114_LEGACY, planner.synchronize()); - report_current_position_projected(); + motion.report_position_projected(); - TERN_(FULL_REPORT_TO_HOST_FEATURE, report_current_grblstate_moving()); + TERN_(FULL_REPORT_TO_HOST_FEATURE, motion.report_current_grblstate_moving()); } diff --git a/Marlin/src/gcode/host/M115.cpp b/Marlin/src/gcode/host/M115.cpp index 19d0ae9b63..0e059e6584 100644 --- a/Marlin/src/gcode/host/M115.cpp +++ b/Marlin/src/gcode/host/M115.cpp @@ -254,8 +254,8 @@ void GcodeSuite::M115() { dmin = NUM_AXIS_ARRAY(X_MIN_POS, Y_MIN_POS, Z_MIN_POS, I_MIN_POS, J_MIN_POS, K_MIN_POS, U_MIN_POS, V_MIN_POS, W_MIN_POS), dmax = NUM_AXIS_ARRAY(X_MAX_POS, Y_MAX_POS, Z_MAX_POS, I_MAX_POS, J_MAX_POS, K_MAX_POS, U_MAX_POS, V_MAX_POS, W_MAX_POS); xyz_pos_t cmin = bmin, cmax = bmax; - apply_motion_limits(cmin); - apply_motion_limits(cmax); + motion.apply_limits(cmin); + motion.apply_limits(cmax); const xyz_pos_t lmin = dmin.asLogical(), lmax = dmax.asLogical(), wmin = cmin.asLogical(), wmax = cmax.asLogical(); diff --git a/Marlin/src/gcode/host/M154.cpp b/Marlin/src/gcode/host/M154.cpp index 156e6b69b6..daba03b10a 100644 --- a/Marlin/src/gcode/host/M154.cpp +++ b/Marlin/src/gcode/host/M154.cpp @@ -33,7 +33,7 @@ void GcodeSuite::M154() { if (parser.seenval('S')) - position_auto_reporter.set_interval(parser.value_byte()); + motion.position_auto_reporter.set_interval(parser.value_byte()); } diff --git a/Marlin/src/gcode/host/M360.cpp b/Marlin/src/gcode/host/M360.cpp index d5f54a81a1..0792595ec5 100644 --- a/Marlin/src/gcode/host/M360.cpp +++ b/Marlin/src/gcode/host/M360.cpp @@ -171,8 +171,8 @@ void GcodeSuite::M360() { const xyz_pos_t dmin = NUM_AXIS_ARRAY(X_MIN_POS, Y_MIN_POS, Z_MIN_POS, I_MIN_POS, J_MIN_POS, K_MIN_POS, U_MIN_POS, V_MIN_POS, W_MIN_POS), dmax = NUM_AXIS_ARRAY(X_MAX_POS, Y_MAX_POS, Z_MAX_POS, I_MAX_POS, J_MAX_POS, K_MAX_POS, U_MAX_POS, V_MAX_POS, W_MAX_POS); xyz_pos_t cmin = dmin, cmax = dmax; - apply_motion_limits(cmin); - apply_motion_limits(cmax); + motion.apply_limits(cmin); + motion.apply_limits(cmax); const xyz_pos_t wmin = cmin.asLogical(), wmax = cmax.asLogical(); PGMSTR(MIN_STR, "Min"); diff --git a/Marlin/src/gcode/motion/G0_G1.cpp b/Marlin/src/gcode/motion/G0_G1.cpp index b489b659ae..f2386841ca 100644 --- a/Marlin/src/gcode/motion/G0_G1.cpp +++ b/Marlin/src/gcode/motion/G0_G1.cpp @@ -39,8 +39,6 @@ #include "../../lcd/sovol_rts/sovol_rts.h" #endif -extern xyze_pos_t destination; - #if ENABLED(VARIABLE_G0_FEEDRATE) feedRate_t fast_move_feedrate = MMM_TO_MMS(G0_FEEDRATE); #endif @@ -51,27 +49,27 @@ extern xyze_pos_t destination; void GcodeSuite::G0_G1(TERN_(HAS_FAST_MOVES, const bool fast_move/*=false*/)) { if (!MOTION_CONDITIONS) return; - TERN_(FULL_REPORT_TO_HOST_FEATURE, set_and_report_grblstate(M_RUNNING)); + TERN_(FULL_REPORT_TO_HOST_FEATURE, motion.set_and_report_grblstate(M_RUNNING)); #ifdef G0_FEEDRATE feedRate_t old_feedrate; #if ENABLED(VARIABLE_G0_FEEDRATE) if (fast_move) { - old_feedrate = feedrate_mm_s; // Back up the (old) motion mode feedrate - feedrate_mm_s = fast_move_feedrate; // Get G0 feedrate from last usage + old_feedrate = motion.feedrate_mm_s; // Back up the (old) motion mode feedrate + motion.feedrate_mm_s = fast_move_feedrate; // Get G0 feedrate from last usage } #endif #endif - get_destination_from_command(); // Get X Y [Z[I[J[K]]]] [E] F (and set cutter power) + get_destination_from_command(); // Get X Y [Z[I[J[K]]]] [E] F (and set cutter power) #ifdef G0_FEEDRATE if (fast_move) { #if ENABLED(VARIABLE_G0_FEEDRATE) - fast_move_feedrate = feedrate_mm_s; // Save feedrate for the next G0 + fast_move_feedrate = motion.feedrate_mm_s; // Save feedrate for the next G0 #else - old_feedrate = feedrate_mm_s; // Back up the (new) motion mode feedrate - feedrate_mm_s = MMM_TO_MMS(G0_FEEDRATE); // Get the fixed G0 feedrate + old_feedrate = motion.feedrate_mm_s; // Back up the (new) motion mode feedrate + motion.feedrate_mm_s = MMM_TO_MMS(G0_FEEDRATE); // Get the fixed G0 feedrate #endif } #endif @@ -83,12 +81,11 @@ void GcodeSuite::G0_G1(TERN_(HAS_FAST_MOVES, const bool fast_move/*=false*/)) { if (fwretract.autoretract_enabled && parser.seen_test('E') && !parser.seen(STR_AXES_MAIN) ) { - const float echange = destination.e - current_position.e; + const float echange = motion.destination.e - motion.position.e; // Is this a retract or recover move? - if (WITHIN(ABS(echange), MIN_AUTORETRACT, MAX_AUTORETRACT) && fwretract.retracted[active_extruder] == (echange > 0.0)) { - current_position.e = destination.e; // Hide a G1-based retract/recover from calculations - sync_plan_position_e(); // AND from the planner - fwretract.retract(echange < 0.0); // Firmware-based retract/recover (double-retract ignored) + if (WITHIN(ABS(echange), MIN_AUTORETRACT, MAX_AUTORETRACT) && fwretract.retracted[motion.extruder] == (echange > 0.0f)) { + motion.set_and_sync_e(motion.destination.e); // Hide a G1-based retract/recover from calculations AND from the planner + fwretract.retract(echange < 0.0f); // Firmware-based retract/recover (double-retract ignored) return; } } @@ -97,14 +94,14 @@ void GcodeSuite::G0_G1(TERN_(HAS_FAST_MOVES, const bool fast_move/*=false*/)) { #endif // FWRETRACT #if ANY(IS_SCARA, POLAR) - fast_move ? prepare_fast_move_to_destination() : prepare_line_to_destination(); + fast_move ? motion.prepare_fast_move_to_destination() : motion.prepare_line_to_destination(); #else - prepare_line_to_destination(); + motion.prepare_line_to_destination(); #endif #ifdef G0_FEEDRATE // Restore the motion mode feedrate - if (fast_move) feedrate_mm_s = old_feedrate; + if (fast_move) motion.feedrate_mm_s = old_feedrate; #endif #if ENABLED(NANODLP_Z_SYNC) @@ -117,9 +114,9 @@ void GcodeSuite::G0_G1(TERN_(HAS_FAST_MOVES, const bool fast_move/*=false*/)) { planner.synchronize(); SERIAL_ECHOLNPGM(STR_Z_MOVE_COMP); } - TERN_(FULL_REPORT_TO_HOST_FEATURE, set_and_report_grblstate(M_IDLE)); + TERN_(FULL_REPORT_TO_HOST_FEATURE, motion.set_and_report_grblstate(M_IDLE)); #else - TERN_(FULL_REPORT_TO_HOST_FEATURE, report_current_grblstate_moving()); + TERN_(FULL_REPORT_TO_HOST_FEATURE, motion.report_current_grblstate_moving()); #endif TERN_(SOVOL_SV06_RTS, RTS_PauseMoveAxisPage()); diff --git a/Marlin/src/gcode/motion/G2_G3.cpp b/Marlin/src/gcode/motion/G2_G3.cpp index 9c5dd27f0f..a885c3a17b 100644 --- a/Marlin/src/gcode/motion/G2_G3.cpp +++ b/Marlin/src/gcode/motion/G2_G3.cpp @@ -51,7 +51,7 @@ */ void plan_arc( const xyze_pos_t &cart, // Destination position - const ab_float_t &offset, // Center of rotation relative to current_position + const ab_float_t &offset, // Center of rotation relative to motion.position const bool clockwise, // Clockwise? const uint8_t circles // Take the scenic route ) { @@ -71,22 +71,22 @@ void plan_arc( ab_float_t rvec = -offset; const float radius = HYPOT(rvec.a, rvec.b), - center_P = current_position[axis_p] - rvec.a, - center_Q = current_position[axis_q] - rvec.b, + center_P = motion.position[axis_p] - rvec.a, + center_Q = motion.position[axis_q] - rvec.b, rt_X = cart[axis_p] - center_P, rt_Y = cart[axis_q] - center_Q; // Starting position of the move for all non-arc axes // i.e., only one of X, Y, or Z, plus the rest. ARC_LIJKUVWE_CODE( - float start_L = current_position[axis_l], - float start_I = current_position.i, - float start_J = current_position.j, - float start_K = current_position.k, - float start_U = current_position.u, - float start_V = current_position.v, - float start_W = current_position.w, - float start_E = current_position.e + float start_L = motion.position[axis_l], + float start_I = motion.position.i, + float start_J = motion.position.j, + float start_K = motion.position.k, + float start_U = motion.position.u, + float start_V = motion.position.v, + float start_W = motion.position.w, + float start_E = motion.position.e ); // Angle of rotation between position and target from the circle center. @@ -96,7 +96,7 @@ void plan_arc( uint16_t min_segments = 1; // Do a full circle if starting and ending positions are "identical" - if (NEAR(current_position[axis_p], cart[axis_p]) && NEAR(current_position[axis_q], cart[axis_q])) { + if (NEAR(motion.position[axis_p], cart[axis_p]) && NEAR(motion.position[axis_q], cart[axis_q])) { // Preserve direction for circles angular_travel = clockwise ? -RADIANS(360) : RADIANS(360); abs_angular_travel = RADIANS(360); @@ -150,7 +150,7 @@ void plan_arc( const float per_circle_E = travel_E * part_per_circle // E movement per circle ); - xyze_pos_t temp_position = current_position; + xyze_pos_t temp_position = motion.position; for (uint16_t n = circles; n--;) { ARC_LIJKUVWE_CODE( // Destination Linear Axes temp_position[axis_l] += per_circle_L, // Linear X, Y, or Z @@ -167,14 +167,14 @@ void plan_arc( // Get starting coordinates for the remainder from the current position ARC_LIJKUVWE_CODE( - start_L = current_position[axis_l], - start_I = current_position.i, - start_J = current_position.j, - start_K = current_position.k, - start_U = current_position.u, - start_V = current_position.v, - start_W = current_position.w, - start_E = current_position.e + start_L = motion.position[axis_l], + start_I = motion.position.i, + start_J = motion.position.j, + start_K = motion.position.k, + start_U = motion.position.u, + start_V = motion.position.v, + start_W = motion.position.w, + start_E = motion.position.e ); // Update travel distance for the remainder @@ -212,7 +212,7 @@ void plan_arc( } // Feedrate for the move, scaled by the feedrate multiplier - const feedRate_t scaled_fr_mm_s = MMS_SCALED(feedrate_mm_s); + const feedRate_t scaled_fr_mm_s = motion.mms_scaled(); // Get the ideal segment length for the move based on settings const float ideal_segment_mm = ( @@ -361,7 +361,7 @@ void plan_arc( raw.e = start_E + per_segment_E * i ); - apply_motion_limits(raw); + motion.apply_limits(raw); #if HAS_LEVELING && !PLANNER_LEVELING planner.apply_leveling(raw); @@ -371,7 +371,7 @@ void plan_arc( const float arc_mm_remaining = flat_mm - segment_mm * i; hints.safe_exit_speed_sqr = _MIN(limiting_speed_sqr, 2 * limiting_accel * arc_mm_remaining); - if (!planner.buffer_line(raw, scaled_fr_mm_s, active_extruder, hints)) + if (!planner.buffer_line(raw, scaled_fr_mm_s, motion.extruder, hints)) break; hints.curve_radius = radius; @@ -381,7 +381,7 @@ void plan_arc( // Ensure last segment arrives at target location. raw = cart; - apply_motion_limits(raw); + motion.apply_limits(raw); #if HAS_LEVELING && !PLANNER_LEVELING planner.apply_leveling(raw); @@ -389,9 +389,9 @@ void plan_arc( hints.curve_radius = 0; hints.safe_exit_speed_sqr = 0.0f; - planner.buffer_line(raw, scaled_fr_mm_s, active_extruder, hints); + planner.buffer_line(raw, scaled_fr_mm_s, motion.extruder, hints); - current_position = cart; + motion.position = cart; } // plan_arc @@ -425,22 +425,22 @@ void plan_arc( void GcodeSuite::G2_G3(const bool clockwise) { if (!MOTION_CONDITIONS) return; - TERN_(FULL_REPORT_TO_HOST_FEATURE, set_and_report_grblstate(M_RUNNING)); + TERN_(FULL_REPORT_TO_HOST_FEATURE, motion.set_and_report_grblstate(M_RUNNING)); #if ENABLED(SF_ARC_FIX) - const bool relative_mode_backup = relative_mode; - relative_mode = true; + const bool relative_mode_backup = motion.relative_mode; + motion.relative_mode = true; #endif get_destination_from_command(); // Get X Y [Z[I[J[K...]]]] [E] F (and set cutter power) - TERN_(SF_ARC_FIX, relative_mode = relative_mode_backup); + TERN_(SF_ARC_FIX, motion.relative_mode = relative_mode_backup); ab_float_t arc_offset = { 0, 0 }; if (parser.seenval('R')) { const float r = parser.value_linear_units(); if (r) { - const xy_pos_t p1 = current_position, p2 = destination; + const xy_pos_t p1 = motion.position, p2 = motion.destination; if (p1 != p2) { const xy_pos_t d2 = (p2 - p1) * 0.5f; // XY vector to midpoint of move from current const float e = clockwise ^ (r < 0) ? -1 : 1, // clockwise -1/1, counterclockwise 1/-1 @@ -480,13 +480,13 @@ void GcodeSuite::G2_G3(const bool clockwise) { #endif // Send the arc to the planner - plan_arc(destination, arc_offset, clockwise, circles_to_do); + plan_arc(motion.destination, arc_offset, clockwise, circles_to_do); reset_stepper_timeout(); } else SERIAL_ERROR_MSG(STR_ERR_ARC_ARGS); - TERN_(FULL_REPORT_TO_HOST_FEATURE, set_and_report_grblstate(M_IDLE)); + TERN_(FULL_REPORT_TO_HOST_FEATURE, motion.set_and_report_grblstate(M_IDLE)); } #endif // ARC_SUPPORT diff --git a/Marlin/src/gcode/motion/G5.cpp b/Marlin/src/gcode/motion/G5.cpp index 64aafffba2..227ea0792e 100644 --- a/Marlin/src/gcode/motion/G5.cpp +++ b/Marlin/src/gcode/motion/G5.cpp @@ -60,8 +60,8 @@ void GcodeSuite::G5() { { parser.linearval('P'), parser.linearval('Q') } }; - cubic_b_spline(current_position, destination, offsets, MMS_SCALED(feedrate_mm_s), active_extruder); - current_position = destination; + cubic_b_spline(motion.position, motion.destination, offsets, motion.mms_scaled(), motion.extruder); + motion.position = motion.destination; } #endif // BEZIER_CURVE_SUPPORT diff --git a/Marlin/src/gcode/motion/M290.cpp b/Marlin/src/gcode/motion/M290.cpp index 039f48381a..e65478b059 100644 --- a/Marlin/src/gcode/motion/M290.cpp +++ b/Marlin/src/gcode/motion/M290.cpp @@ -36,14 +36,14 @@ #if ENABLED(BABYSTEP_ZPROBE_OFFSET) FORCE_INLINE void mod_probe_offset(const float offs) { - if (TERN1(BABYSTEP_HOTEND_Z_OFFSET, active_extruder == 0)) { + if (TERN1(BABYSTEP_HOTEND_Z_OFFSET, motion.extruder == 0)) { probe.offset.z += offs; SERIAL_ECHO_MSG(STR_PROBE_OFFSET " " STR_Z, probe.offset.z); } else { #if ENABLED(BABYSTEP_HOTEND_Z_OFFSET) - hotend_offset[active_extruder].z -= offs; - SERIAL_ECHO_MSG(STR_PROBE_OFFSET STR_Z ": ", hotend_offset[active_extruder].z); + hotend_offset[motion.extruder].z -= offs; + SERIAL_ECHO_MSG(STR_PROBE_OFFSET STR_Z ": ", hotend_offset[motion.extruder].z); #endif } } @@ -93,15 +93,15 @@ void GcodeSuite::M290() { #if ENABLED(BABYSTEP_HOTEND_Z_OFFSET) { SERIAL_ECHOLNPGM_P( - PSTR("Hotend "), active_extruder + PSTR("Hotend "), motion.extruder #if ENABLED(BABYSTEP_XY) - , PSTR("Offset X"), hotend_offset[active_extruder].x - , SP_Y_STR, hotend_offset[active_extruder].y + , PSTR("Offset X"), hotend_offset[motion.extruder].x + , SP_Y_STR, hotend_offset[motion.extruder].y , SP_Z_STR #else , PSTR("Offset Z") #endif - , hotend_offset[active_extruder].z + , hotend_offset[motion.extruder].z ); } #endif diff --git a/Marlin/src/gcode/probe/G30.cpp b/Marlin/src/gcode/probe/G30.cpp index 463a4cd836..0119ed16b8 100644 --- a/Marlin/src/gcode/probe/G30.cpp +++ b/Marlin/src/gcode/probe/G30.cpp @@ -54,12 +54,12 @@ */ void GcodeSuite::G30() { - xy_pos_t probepos = current_position; + xy_pos_t probepos = motion.position; const bool seenX = parser.seenval('X'); - if (seenX) probepos.x = RAW_X_POSITION(parser.value_linear_units()); + if (seenX) probepos.x = motion.raw_x(parser.value_linear_units()); const bool seenY = parser.seenval('Y'); - if (seenY) probepos.y = RAW_Y_POSITION(parser.value_linear_units()); + if (seenY) probepos.y = motion.raw_y(parser.value_linear_units()); probe.use_probing_tool(); @@ -69,7 +69,7 @@ void GcodeSuite::G30() { TERN_(HAS_LEVELING, set_bed_leveling_enabled(false)); // Disable feedrate scaling so movement speeds are correct - remember_feedrate_scaling_off(); + motion.remember_feedrate_scaling_off(); // With VERBOSE_SINGLE_PROBE home only if needed TERN_(VERBOSE_SINGLE_PROBE, process_subcommands_now(F("G28O"))); @@ -102,15 +102,15 @@ void GcodeSuite::G30() { } // Restore feedrate scaling - restore_feedrate_and_scaling(); + motion.restore_feedrate_and_scaling(); // Move the nozzle to the position of the probe - do_blocking_move_to(probepos); + motion.blocking_move(probepos); if (raise_after == PROBE_PT_STOW) probe.move_z_after_probing(); - report_current_position(); + motion.report_position(); } else { SERIAL_ECHOLN(GET_EN_TEXT_F(MSG_ZPROBE_OUT)); diff --git a/Marlin/src/gcode/probe/G38.cpp b/Marlin/src/gcode/probe/G38.cpp index cd10b7295d..2bd8e10052 100644 --- a/Marlin/src/gcode/probe/G38.cpp +++ b/Marlin/src/gcode/probe/G38.cpp @@ -36,12 +36,12 @@ probe_target_t G38_move{0}; inline void G38_single_probe(const uint8_t move_value) { endstops.enable(true); G38_move.type = move_value; - prepare_line_to_destination(); + motion.prepare_line_to_destination(); planner.synchronize(); G38_move.type = 0; endstops.hit_on_purpose(); - set_current_from_steppers_for_axis(ALL_AXES_ENUM); - sync_plan_position(); + motion.set_current_from_steppers_for_axis(ALL_AXES_ENUM); + motion.sync_plan_position(); } /** @@ -59,7 +59,7 @@ FORCE_INLINE bool G38_run_probe() { // Get direction of move and retract xyz_float_t retract_mm; LOOP_NUM_AXES(i) { - const float dist = destination[i] - current_position[i]; + const float dist = motion.destination[i] - motion.position[i]; retract_mm[i] = ABS(dist) < G38_MINIMUM_MOVE ? 0 : home_bump_mm((AxisEnum)i) * (dist > 0 ? -1 : 1); } #endif @@ -84,15 +84,15 @@ FORCE_INLINE bool G38_run_probe() { #if MULTIPLE_PROBING > 1 // Move away by the retract distance - destination = current_position + retract_mm; + motion.destination = motion.position + retract_mm; endstops.enable(false); - prepare_line_to_destination(); + motion.prepare_line_to_destination(); planner.synchronize(); - REMEMBER(fr, feedrate_mm_s, feedrate_mm_s * 0.25); + REMEMBER(fr, motion.feedrate_mm_s, motion.feedrate_mm_s * 0.25); // Bump the target more slowly - destination -= retract_mm * 2; + motion.destination -= retract_mm * 2; G38_single_probe(move_value); #endif @@ -118,20 +118,20 @@ void GcodeSuite::G38(const int8_t subcode) { // Get X Y Z E F get_destination_from_command(); - remember_feedrate_scaling_off(); + motion.remember_feedrate_scaling_off(); const bool error_on_fail = TERN(G38_PROBE_AWAY, !TEST(subcode, 0), subcode == 2); // If any axis has enough movement, do the move LOOP_NUM_AXES(i) - if (ABS(destination[i] - current_position[i]) >= G38_MINIMUM_MOVE) { - if (!parser.seenval('F')) feedrate_mm_s = homing_feedrate((AxisEnum)i); + if (ABS(motion.destination[i] - motion.position[i]) >= G38_MINIMUM_MOVE) { + if (!parser.seenval('F')) motion.feedrate_mm_s = motion.homing_feedrate((AxisEnum)i); // If G38.2 fails throw an error if (!G38_run_probe() && error_on_fail) SERIAL_ERROR_MSG("Failed to reach target"); break; } - restore_feedrate_and_scaling(); + motion.restore_feedrate_and_scaling(); } #endif // G38_PROBE_TARGET diff --git a/Marlin/src/gcode/probe/M401_M402.cpp b/Marlin/src/gcode/probe/M401_M402.cpp index a2a1caa01d..305ddc2fa2 100644 --- a/Marlin/src/gcode/probe/M401_M402.cpp +++ b/Marlin/src/gcode/probe/M401_M402.cpp @@ -54,7 +54,7 @@ void GcodeSuite::M401() { probe.deploy(parser.boolval('R')); TERN_(PROBE_TARE, probe.tare()); - report_current_position(); + motion.report_position(); } void GcodeSuite::M401_report(const bool forReplay/*=true*/) { @@ -75,9 +75,9 @@ void GcodeSuite::M401_report(const bool forReplay/*=true*/) { void GcodeSuite::M402() { probe.stow(parser.boolval('R')); #ifdef Z_AFTER_PROBING - do_z_clearance(Z_AFTER_PROBING); + motion.do_z_clearance(Z_AFTER_PROBING); #endif - report_current_position(); + motion.report_position(); } #endif // HAS_BED_PROBE diff --git a/Marlin/src/gcode/probe/M951.cpp b/Marlin/src/gcode/probe/M951.cpp index 15d3d47af0..1a9127f88b 100644 --- a/Marlin/src/gcode/probe/M951.cpp +++ b/Marlin/src/gcode/probe/M951.cpp @@ -46,7 +46,7 @@ void mpe_settings_init() { mpe_settings.parking_xpos[0] = pex[0]; // M951 L mpe_settings.parking_xpos[1] = pex[1]; // M951 R mpe_settings.grab_distance = PARKING_EXTRUDER_GRAB_DISTANCE; // M951 I - TERN_(HAS_HOME_OFFSET, set_home_offset(X_AXIS, -mpe_settings.grab_distance)); + TERN_(HAS_HOME_OFFSET, motion.set_home_offset(X_AXIS, -mpe_settings.grab_distance)); mpe_settings.slow_feedrate = MMM_TO_MMS(MPE_SLOW_SPEED); // M951 J mpe_settings.fast_feedrate = MMM_TO_MMS(MPE_FAST_SPEED); // M951 H mpe_settings.travel_distance = MPE_TRAVEL_DISTANCE; // M951 D @@ -74,7 +74,7 @@ void GcodeSuite::M951() { if (parser.seenval('R')) mpe_settings.parking_xpos[1] = parser.value_linear_units(); if (parser.seenval('I')) { mpe_settings.grab_distance = parser.value_linear_units(); - TERN_(HAS_HOME_OFFSET, set_home_offset(X_AXIS, -mpe_settings.grab_distance)); + TERN_(HAS_HOME_OFFSET, motion.set_home_offset(X_AXIS, -mpe_settings.grab_distance)); } if (parser.seenval('J')) mpe_settings.slow_feedrate = MMM_TO_MMS(parser.value_linear_units()); if (parser.seenval('H')) mpe_settings.fast_feedrate = MMM_TO_MMS(parser.value_linear_units()); diff --git a/Marlin/src/gcode/queue.cpp b/Marlin/src/gcode/queue.cpp index 0014ca44a5..68e5e868b4 100644 --- a/Marlin/src/gcode/queue.cpp +++ b/Marlin/src/gcode/queue.cpp @@ -539,7 +539,7 @@ void GCodeQueue::get_serial_commands() { if (command[0] == 'M') switch (command[3]) { case '8': if (command[2] == '0' && command[1] == '1') { marlin.end_waiting(); } break; case '2': if (command[2] == '1' && command[1] == '1') marlin.kill(FPSTR(M112_KILL_STR), nullptr, true); break; - case '0': if (command[1] == '4' && command[2] == '1') quickstop_stepper(); break; + case '0': if (command[1] == '4' && command[2] == '1') motion.quickstop_stepper(); break; } #if NO_TIMEOUTS > 0 diff --git a/Marlin/src/gcode/scara/M360-M364.cpp b/Marlin/src/gcode/scara/M360-M364.cpp index ad142a09ba..0fcfde3f50 100644 --- a/Marlin/src/gcode/scara/M360-M364.cpp +++ b/Marlin/src/gcode/scara/M360-M364.cpp @@ -31,7 +31,7 @@ inline bool SCARA_move_to_cal(const uint8_t delta_a, const uint8_t delta_b) { if (marlin.isRunning()) { forward_kinematics(delta_a, delta_b); - do_blocking_move_to_xy(cartes); + motion.blocking_move_xy(motion.cartes); return true; } return false; diff --git a/Marlin/src/gcode/temp/M104_M109.cpp b/Marlin/src/gcode/temp/M104_M109.cpp index d27ff75d39..79da98abff 100644 --- a/Marlin/src/gcode/temp/M104_M109.cpp +++ b/Marlin/src/gcode/temp/M104_M109.cpp @@ -106,7 +106,7 @@ void GcodeSuite::M104_M109(const bool isM109) { if (got_temp) { #if ENABLED(SINGLENOZZLE_STANDBY_TEMP) thermalManager.singlenozzle_temp[target_extruder] = temp; - if (target_extruder != active_extruder) return; + if (target_extruder != motion.extruder) return; #endif thermalManager.setTargetHotend(temp, target_extruder); diff --git a/Marlin/src/gcode/temp/M106_M107.cpp b/Marlin/src/gcode/temp/M106_M107.cpp index dc0c3d6b27..6d163ce648 100644 --- a/Marlin/src/gcode/temp/M106_M107.cpp +++ b/Marlin/src/gcode/temp/M106_M107.cpp @@ -37,10 +37,10 @@ #endif #if ENABLED(SINGLENOZZLE) - #define _ALT_P active_extruder + #define _ALT_P motion.extruder #define _CNT_P EXTRUDERS #else - #define _ALT_P _MIN(active_extruder, FAN_COUNT - 1) + #define _ALT_P _MIN(motion.extruder, FAN_COUNT - 1) #define _CNT_P FAN_COUNT #endif @@ -71,7 +71,7 @@ void GcodeSuite::M106() { } #endif - const uint16_t dspeed = parser.seen_test('A') ? thermalManager.fan_speed[active_extruder] : 255; + const uint16_t dspeed = parser.seen_test('A') ? thermalManager.fan_speed[motion.extruder] : 255; uint16_t speed = dspeed; diff --git a/Marlin/src/gcode/temp/M306.cpp b/Marlin/src/gcode/temp/M306.cpp index 7e79581f2b..c129bdd512 100644 --- a/Marlin/src/gcode/temp/M306.cpp +++ b/Marlin/src/gcode/temp/M306.cpp @@ -49,7 +49,7 @@ */ void GcodeSuite::M306() { - const uint8_t e = E_TERN0(parser.intval('E', active_extruder)); + const uint8_t e = E_TERN0(parser.intval('E', motion.extruder)); if (e >= (EXTRUDERS)) { SERIAL_ECHOLNPGM("?(E)xtruder index out of range (0-", (EXTRUDERS) - 1, ")."); return; diff --git a/Marlin/src/inc/Conditionals-5-post.h b/Marlin/src/inc/Conditionals-5-post.h index 55cd16c8d7..05e036c774 100644 --- a/Marlin/src/inc/Conditionals-5-post.h +++ b/Marlin/src/inc/Conditionals-5-post.h @@ -3250,7 +3250,7 @@ #define ENDSTOPPULLUP_ZMIN_PROBE #endif #ifndef XY_PROBE_FEEDRATE - #define XY_PROBE_FEEDRATE ((homing_feedrate_mm_m.x + homing_feedrate_mm_m.y) / 2) + #define XY_PROBE_FEEDRATE ((motion.homing_feedrate_mm_m.x + motion.homing_feedrate_mm_m.y) / 2) #endif #ifndef NOZZLE_TO_PROBE_OFFSET #define NOZZLE_TO_PROBE_OFFSET { 0, 0, 0 } diff --git a/Marlin/src/lcd/HD44780/marlinui_HD44780.cpp b/Marlin/src/lcd/HD44780/marlinui_HD44780.cpp index 81063d5e2e..e586fcc27f 100644 --- a/Marlin/src/lcd/HD44780/marlinui_HD44780.cpp +++ b/Marlin/src/lcd/HD44780/marlinui_HD44780.cpp @@ -584,9 +584,9 @@ FORCE_INLINE void _draw_axis_value(const AxisEnum axis, const char *value, const lcd_put_lchar('X' + uint8_t(axis)); if (blink) lcd_put_u8str(value); - else if (axis_should_home(axis)) + else if (motion.axis_should_home(axis)) while (const char c = *value++) lcd_put_lchar(c <= '.' ? c : '?'); - else if (NONE(HOME_AFTER_DEACTIVATE, DISABLE_REDUCED_ACCURACY_WARNING) && !axis_is_trusted(axis)) + else if (NONE(HOME_AFTER_DEACTIVATE, DISABLE_REDUCED_ACCURACY_WARNING) && !motion.axis_is_trusted(axis)) lcd_put_u8str(TERN0(HAS_Z_AXIS, axis == Z_AXIS) ? F(" ") : F(" ")); else lcd_put_u8str(value); @@ -1077,14 +1077,14 @@ void MarlinUI::draw_status_screen() { if (show_e_total) { #if ENABLED(LCD_SHOW_E_TOTAL) char tmp[20]; - const uint8_t escale = e_move_accumulator >= 100000.0f ? 10 : 1; // After 100m switch to cm - sprintf_P(tmp, PSTR("E %ld%cm "), uint32_t(_MAX(e_move_accumulator, 0.0f)) / escale, escale == 10 ? 'c' : 'm'); // 1234567mm + const uint8_t escale = motion.e_move_accumulator >= 100000.0f ? 10 : 1; // After 100m switch to cm + sprintf_P(tmp, PSTR("E %ld%cm "), uint32_t(_MAX(motion.e_move_accumulator, 0.0f)) / escale, escale == 10 ? 'c' : 'm'); // 1234567mm lcd_put_u8str(tmp); #endif } else { #if HAS_X_AXIS - const xy_pos_t lpos = current_position.asLogical(); + const xy_pos_t lpos = motion.position.asLogical(); _draw_axis_value(X_AXIS, ftostr4sign(lpos.x), blink); #endif #if HAS_Y_AXIS @@ -1101,7 +1101,7 @@ void MarlinUI::draw_status_screen() { #if HAS_Z_AXIS lcd_moveto(LCD_WIDTH - 8, 1); - _draw_axis_value(Z_AXIS, ftostr52sp(LOGICAL_Z_POSITION(current_position.z)), blink); + _draw_axis_value(Z_AXIS, ftostr52sp(motion.logical_z(motion.position.z)), blink); #if HAS_LEVELING && !HAS_HEATED_BED lcd_put_lchar(planner.leveling_active || blink ? '_' : ' '); #endif @@ -1114,7 +1114,7 @@ void MarlinUI::draw_status_screen() { #if LCD_HEIGHT > 3 lcd_put_lchar(0, 2, LCD_STR_FEEDRATE[0]); - lcd_put_u8str(i16tostr3rj(feedrate_percentage)); + lcd_put_u8str(i16tostr3rj(motion.feedrate_percentage)); lcd_put_u8str(F("%")); #if LCD_WIDTH >= 20 @@ -1168,7 +1168,7 @@ void MarlinUI::draw_status_screen() { // #if HAS_Z_AXIS lcd_moveto(LCD_WIDTH - 9, 0); - _draw_axis_value(Z_AXIS, ftostr52sp(LOGICAL_Z_POSITION(current_position.z)), blink); + _draw_axis_value(Z_AXIS, ftostr52sp(motion.logical_z(motion.position.z)), blink); #endif #if HAS_LEVELING && (HAS_MULTI_HOTEND || !HAS_HEATED_BED) @@ -1188,7 +1188,7 @@ void MarlinUI::draw_status_screen() { #endif lcd_put_lchar(LCD_WIDTH - 9, 1, LCD_STR_FEEDRATE[0]); - lcd_put_u8str(i16tostr3rj(feedrate_percentage)); + lcd_put_u8str(i16tostr3rj(motion.feedrate_percentage)); lcd_put_u8str(F("%")); // ========== Line 3 ========== @@ -1223,20 +1223,20 @@ void MarlinUI::draw_status_screen() { // X Coordinate // lcd_moveto(0, 0); - _draw_axis_value(X_AXIS, ftostr52sp(LOGICAL_X_POSITION(current_position.x)), blink); + _draw_axis_value(X_AXIS, ftostr52sp(motion.logical_x(motion.position.x)), blink); // // Y Coordinate // lcd_moveto(LCD_WIDTH - 9, 0); - _draw_axis_value(Y_AXIS, ftostr52sp(LOGICAL_Y_POSITION(current_position.y)), blink); + _draw_axis_value(Y_AXIS, ftostr52sp(motion.logical_y(motion.position.y)), blink); // ========== Line 2 ========== lcd_moveto(0, 1); - _draw_axis_value(Z_AXIS, ftostr52sp(LOGICAL_Z_POSITION(current_position.z)), blink); + _draw_axis_value(Z_AXIS, ftostr52sp(motion.logical_z(motion.position.z)), blink); lcd_moveto(LCD_WIDTH - 9, 1); - _draw_axis_value(I_AXIS, ftostr52sp(LOGICAL_I_POSITION(current_position.i)), blink); + _draw_axis_value(I_AXIS, ftostr52sp(motion.logical_i(motion.position.i)), blink); // ========== Line 3 ========== lcd_moveto(0, 2); @@ -1521,9 +1521,9 @@ void MarlinUI::draw_status_screen() { * Show X and Y positions */ _XLABEL(_PLOT_X, 0); - lcd_put_u8str(ftostr52(LOGICAL_X_POSITION(bedlevel.get_mesh_x(x_plot)))); + lcd_put_u8str(ftostr52(motion.logical_x(bedlevel.get_mesh_x(x_plot)))); _YLABEL(_LCD_W_POS, 0); - lcd_put_u8str(ftostr52(LOGICAL_Y_POSITION(bedlevel.get_mesh_y(y_plot)))); + lcd_put_u8str(ftostr52(motion.logical_y(bedlevel.get_mesh_y(y_plot)))); lcd_moveto(_PLOT_X, 0); @@ -1726,9 +1726,9 @@ void MarlinUI::draw_status_screen() { * Show all values at right of screen */ _XLABEL(_LCD_W_POS, 1); - lcd_put_u8str(ftostr52(LOGICAL_X_POSITION(bedlevel.get_mesh_x(x_plot)))); + lcd_put_u8str(ftostr52(motion.logical_x(bedlevel.get_mesh_x(x_plot)))); _YLABEL(_LCD_W_POS, 2); - lcd_put_u8str(ftostr52(LOGICAL_Y_POSITION(bedlevel.get_mesh_y(y_plot)))); + lcd_put_u8str(ftostr52(motion.logical_y(bedlevel.get_mesh_y(y_plot)))); /** * Show the location value diff --git a/Marlin/src/lcd/TFTGLCD/marlinui_TFTGLCD.cpp b/Marlin/src/lcd/TFTGLCD/marlinui_TFTGLCD.cpp index cdb18a74b7..e12339e5b1 100644 --- a/Marlin/src/lcd/TFTGLCD/marlinui_TFTGLCD.cpp +++ b/Marlin/src/lcd/TFTGLCD/marlinui_TFTGLCD.cpp @@ -429,9 +429,9 @@ FORCE_INLINE void _draw_axis_value(const AxisEnum axis, const char *value, const lcd.write('X' + uint8_t(axis)); if (blink) lcd.print(value); - else if (axis_should_home(axis)) + else if (motion.axis_should_home(axis)) while (const char c = *value++) lcd.write(c <= '.' ? c : '?'); - else if (NONE(HOME_AFTER_DEACTIVATE, DISABLE_REDUCED_ACCURACY_WARNING) && !axis_is_trusted(axis)) + else if (NONE(HOME_AFTER_DEACTIVATE, DISABLE_REDUCED_ACCURACY_WARNING) && !motion.axis_is_trusted(axis)) lcd_put_u8str(axis == Z_AXIS ? F(" ") : F(" ")); else lcd_put_u8str(value); @@ -816,7 +816,7 @@ void MarlinUI::draw_status_screen() { #if NUM_AXES lcd_moveto(0, 0); - const xyz_pos_t lpos = current_position.asLogical(); + const xyz_pos_t lpos = motion.position.asLogical(); _draw_axis_value(X_AXIS, ftostr4sign(lpos.x), blink); #if HAS_Y_AXIS lcd.write(' '); _draw_axis_value(Y_AXIS, ftostr4sign(lpos.y), blink); @@ -835,7 +835,7 @@ void MarlinUI::draw_status_screen() { // lcd_moveto(0, 1); - lcd_put_u8str(F("FR")); lcd.print(i16tostr3rj(feedrate_percentage)); lcd.write('%'); + lcd_put_u8str(F("FR")); lcd.print(i16tostr3rj(motion.feedrate_percentage)); lcd.write('%'); ui.rotate_progress(); // UNTESTED!!! // @@ -1126,9 +1126,9 @@ void MarlinUI::draw_status_screen() { // Show all values lcd_moveto(_LCD_W_POS, 1); lcd_put_u8str(F("X:")); - lcd.print(ftostr52(LOGICAL_X_POSITION(pgm_read_float(&bedlevel._mesh_index_to_xpos[x_plot])))); + lcd.print(ftostr52(motion.logical_x(pgm_read_float(&bedlevel._mesh_index_to_xpos[x_plot])))); lcd_moveto(_LCD_W_POS, 2); lcd_put_u8str(F("Y:")); - lcd.print(ftostr52(LOGICAL_Y_POSITION(pgm_read_float(&bedlevel._mesh_index_to_ypos[y_plot])))); + lcd.print(ftostr52(motion.logical_y(pgm_read_float(&bedlevel._mesh_index_to_ypos[y_plot])))); // Show the location value lcd_moveto(_LCD_W_POS, 3); lcd_put_u8str(F("Z:")); diff --git a/Marlin/src/lcd/dogm/status_screen_DOGM.cpp b/Marlin/src/lcd/dogm/status_screen_DOGM.cpp index 7fd3052772..e27636a9d8 100644 --- a/Marlin/src/lcd/dogm/status_screen_DOGM.cpp +++ b/Marlin/src/lcd/dogm/status_screen_DOGM.cpp @@ -311,20 +311,20 @@ FORCE_INLINE void _draw_centered_temp(const celsius_t temp, const uint8_t tx, co const bool draw_partial = isHeat && tall < BAR_TALL; if (draw_partial) { const uint8_t ph = STATUS_HEATERS_HEIGHT - 1 - tall; - u8g.drawBitmapP(hx, STATUS_HEATERS_Y, bw, ph, HOTEND_BITMAP(TERN(HAS_MMU, active_extruder, heater_id), false)); - u8g.drawBitmapP(hx, STATUS_HEATERS_Y + ph, bw, tall + 1, HOTEND_BITMAP(TERN(HAS_MMU, active_extruder, heater_id), true) + ph * bw); + u8g.drawBitmapP(hx, STATUS_HEATERS_Y, bw, ph, HOTEND_BITMAP(TERN(HAS_MMU, motion.extruder, heater_id), false)); + u8g.drawBitmapP(hx, STATUS_HEATERS_Y + ph, bw, tall + 1, HOTEND_BITMAP(TERN(HAS_MMU, motion.extruder, heater_id), true) + ph * bw); } #else constexpr bool draw_partial = false; #endif if (!draw_partial) - u8g.drawBitmapP(hx, STATUS_HEATERS_Y, bw, STATUS_HEATERS_HEIGHT, HOTEND_BITMAP(TERN(HAS_MMU, active_extruder, heater_id), isHeat)); + u8g.drawBitmapP(hx, STATUS_HEATERS_Y, bw, STATUS_HEATERS_HEIGHT, HOTEND_BITMAP(TERN(HAS_MMU, motion.extruder, heater_id), isHeat)); } // PAGE_CONTAINS #if HAS_MULTI_EXTRUDER && NONE(SLIM_LCD_MENUS, STATUS_HOTEND_NUMBERLESS, SINGLENOZZLE) - if (active_extruder == heater_id) + if (motion.extruder == heater_id) u8g.drawBitmapP(_MAX(0, STATUS_HOTEND_X(heater_id) - 6), STATUS_HEATERS_Y + 3, 1, 5, status_active_extruder_indicator_bmp); #endif @@ -472,9 +472,9 @@ FORCE_INLINE void _draw_axis_value(const AxisEnum axis, const char *value, const if (blink) lcd_put_u8str(value); - else if (axis_should_home(axis)) + else if (motion.axis_should_home(axis)) while (const char c = *value++) lcd_put_lchar(c <= '.' ? c : '?'); - else if (NONE(HOME_AFTER_DEACTIVATE, DISABLE_REDUCED_ACCURACY_WARNING) && !axis_is_trusted(axis)) + else if (NONE(HOME_AFTER_DEACTIVATE, DISABLE_REDUCED_ACCURACY_WARNING) && !motion.axis_is_trusted(axis)) lcd_put_u8str(TERN0(HAS_Z_AXIS, axis == Z_AXIS) ? F(" ") : F(" ")); else lcd_put_u8str(value); @@ -573,14 +573,14 @@ void MarlinUI::draw_status_screen() { #endif #if NUM_AXES - const xyz_pos_t lpos = current_position.asLogical(); + const xyz_pos_t lpos = motion.position.asLogical(); const bool is_inch = parser.using_inch_units(); #endif if (show_e_total) { #if ENABLED(LCD_SHOW_E_TOTAL) - const uint8_t escale = e_move_accumulator >= 100000.0f ? 10 : 1; // After 100m switch to cm - sprintf_P(xstring, PSTR("%ld%cm"), uint32_t(_MAX(e_move_accumulator, 0.0f)) / escale, escale == 10 ? 'c' : 'm'); // 1234567mm + const uint8_t escale = motion.e_move_accumulator >= 100000.0f ? 10 : 1; // After 100m switch to cm + sprintf_P(xstring, PSTR("%ld%cm"), uint32_t(_MAX(motion.e_move_accumulator, 0.0f)) / escale, escale == 10 ? 'c' : 'm'); // 1234567mm #endif } else { @@ -898,9 +898,9 @@ void MarlinUI::draw_status_screen() { set_font(FONT_STATUSMENU); #if ENABLED(ULTIPANEL_FLOWPERCENT) - lcd_put_u8str(12, EXTRAS_2_BASELINE, i16tostr3rj(planner.flow_percentage[active_extruder])); + lcd_put_u8str(12, EXTRAS_2_BASELINE, i16tostr3rj(planner.flow_percentage[motion.extruder])); #else - lcd_put_u8str(12, EXTRAS_2_BASELINE, i16tostr3rj(feedrate_percentage)); + lcd_put_u8str(12, EXTRAS_2_BASELINE, i16tostr3rj(motion.feedrate_percentage)); #endif lcd_put_u8str(F("%")); diff --git a/Marlin/src/lcd/dogm/status_screen_lite_ST7920.cpp b/Marlin/src/lcd/dogm/status_screen_lite_ST7920.cpp index ac7941f844..9daba7dd8f 100644 --- a/Marlin/src/lcd/dogm/status_screen_lite_ST7920.cpp +++ b/Marlin/src/lcd/dogm/status_screen_lite_ST7920.cpp @@ -614,8 +614,8 @@ void ST7920_Lite_Status_Screen::draw_position(const xyze_pos_t &pos, const bool if (TERN0(LCD_SHOW_E_TOTAL, marlin.printingIsActive())) { #if ENABLED(LCD_SHOW_E_TOTAL) char tmp[15]; - const uint8_t escale = e_move_accumulator >= 100000.0f ? 10 : 1; // After 100m switch to cm - sprintf_P(tmp, PSTR("E%-7ld%cm "), uint32_t(_MAX(e_move_accumulator, 0.0f)) / escale, escale == 10 ? 'c' : 'm'); // 1234567mm + const uint8_t escale = motion.e_move_accumulator >= 100000.0f ? 10 : 1; // After 100m switch to cm + sprintf_P(tmp, PSTR("E%-7ld%cm "), uint32_t(_MAX(motion.e_move_accumulator, 0.0f)) / escale, escale == 10 ? 'c' : 'm'); // 1234567mm write_str(tmp); #endif } @@ -636,7 +636,7 @@ bool ST7920_Lite_Status_Screen::indicators_changed() { // because the actual temps fluctuate so by updating // them only during blinks we gain a bit of stability. const bool blink = ui.get_blink(); - const uint16_t feedrate_perc = feedrate_percentage; + const uint16_t feedrate_perc = motion.feedrate_percentage; const uint16_t fs = thermalManager.scaledFanSpeed(0); const celsius_t extruder_1_target = thermalManager.degTargetHotend(0); #if HAS_MULTI_HOTEND @@ -802,7 +802,7 @@ bool ST7920_Lite_Status_Screen::indicators_changed() { void ST7920_Lite_Status_Screen::update_indicators(const bool forceUpdate) { if (forceUpdate || indicators_changed()) { const bool blink = ui.get_blink(); - const uint16_t feedrate_perc = feedrate_percentage; + const uint16_t feedrate_perc = motion.feedrate_percentage; const celsius_t extruder_1_temp = thermalManager.wholeDegHotend(0), extruder_1_target = thermalManager.degTargetHotend(0); #if HAS_MULTI_HOTEND @@ -836,7 +836,7 @@ void ST7920_Lite_Status_Screen::update_indicators(const bool forceUpdate) { } bool ST7920_Lite_Status_Screen::position_changed() { - const xyz_pos_t pos = current_position; + const xyz_pos_t pos = motion.position; const uint8_t checksum = uint8_t(pos.x) ^ uint8_t(pos.y) ^ uint8_t(pos.z); static uint8_t last_checksum = 0, changed = last_checksum != checksum; if (changed) last_checksum = checksum; @@ -906,7 +906,7 @@ void ST7920_Lite_Status_Screen::update_status_or_position(bool forceUpdate) { } if (countdown == 0 && (forceUpdate || position_changed() || TERN(DISABLE_REDUCED_ACCURACY_WARNING, 0, blink_changed()))) - draw_position(current_position, TERN(DISABLE_REDUCED_ACCURACY_WARNING, 1, all_axes_trusted())); + draw_position(motion.position, TERN(DISABLE_REDUCED_ACCURACY_WARNING, 1, motion.all_axes_trusted())); #endif } diff --git a/Marlin/src/lcd/dwin/creality/dwin.cpp b/Marlin/src/lcd/dwin/creality/dwin.cpp index 875dfd5fd1..1874c69a0a 100644 --- a/Marlin/src/lcd/dwin/creality/dwin.cpp +++ b/Marlin/src/lcd/dwin/creality/dwin.cpp @@ -972,7 +972,7 @@ void drawTuneMenu() { if (select_tune.now != CASE_BACK) drawMenuCursor(select_tune.now); drawMenuLine(TUNE_CASE_SPEED, ICON_Speed); - drawEditInteger3(TUNE_CASE_SPEED, feedrate_percentage); + drawEditInteger3(TUNE_CASE_SPEED, motion.feedrate_percentage); #if HAS_HOTEND drawMenuLine(TUNE_CASE_TEMP, ICON_HotendTemp); @@ -1267,7 +1267,7 @@ void gotoMainMenu() { void hmiPlanMove(const feedRate_t fr_mm_s) { if (!planner.is_full()) { planner.synchronize(); - planner.buffer_line(current_position, fr_mm_s); + planner.buffer_line(motion.position, fr_mm_s); dwinUpdateLCD(); } } @@ -1289,10 +1289,10 @@ void hmiMoveDone(const AxisEnum axis) { return hmiMoveDone(X_AXIS); } LIMIT(hmiValues.moveScaled.x, (X_MIN_POS) * MINUNITMULT, (X_MAX_POS) * MINUNITMULT); - current_position.x = hmiValues.moveScaled.x / MINUNITMULT; + motion.position.x = hmiValues.moveScaled.x / MINUNITMULT; drawEditFloat3(1, hmiValues.moveScaled.x, true); dwinUpdateLCD(); - hmiPlanMove(homing_feedrate(X_AXIS)); + hmiPlanMove(motion.homing_feedrate(X_AXIS)); } #endif @@ -1307,10 +1307,10 @@ void hmiMoveDone(const AxisEnum axis) { return hmiMoveDone(Y_AXIS); } LIMIT(hmiValues.moveScaled.y, (Y_MIN_POS) * MINUNITMULT, (Y_MAX_POS) * MINUNITMULT); - current_position.y = hmiValues.moveScaled.y / MINUNITMULT; + motion.position.y = hmiValues.moveScaled.y / MINUNITMULT; drawEditFloat3(2, hmiValues.moveScaled.y, true); dwinUpdateLCD(); - hmiPlanMove(homing_feedrate(Y_AXIS)); + hmiPlanMove(motion.homing_feedrate(Y_AXIS)); } #endif @@ -1325,10 +1325,10 @@ void hmiMoveDone(const AxisEnum axis) { return hmiMoveDone(Z_AXIS); } LIMIT(hmiValues.moveScaled.z, (Z_MIN_POS) * MINUNITMULT, (Z_MAX_POS) * MINUNITMULT); - current_position.z = hmiValues.moveScaled.z / MINUNITMULT; + motion.position.z = hmiValues.moveScaled.z / MINUNITMULT; drawEditFloat3(3, hmiValues.moveScaled.z, true); dwinUpdateLCD(); - hmiPlanMove(homing_feedrate(Z_AXIS)); + hmiPlanMove(motion.homing_feedrate(Z_AXIS)); } #endif @@ -1345,7 +1345,7 @@ void hmiMoveDone(const AxisEnum axis) { return hmiMoveDone(E_AXIS); } LIMIT(hmiValues.moveScaled.e, last_E_scaled - (EXTRUDE_MAXLENGTH) * MINUNITMULT, last_E_scaled + (EXTRUDE_MAXLENGTH) * MINUNITMULT); - current_position.e = hmiValues.moveScaled.e / MINUNITMULT; + motion.position.e = hmiValues.moveScaled.e / MINUNITMULT; drawEditSignedFloat3(4, hmiValues.moveScaled.e, true); dwinUpdateLCD(); hmiPlanMove(MMM_TO_MMS(FEEDRATE_E)); @@ -1544,7 +1544,7 @@ void hmiPrintSpeed() { if (applyEncoder(encoder_diffState, hmiValues.printSpeed)) { checkkey = ID_Tune; encoderRate.enabled = false; - feedrate_percentage = hmiValues.printSpeed; + motion.feedrate_percentage = hmiValues.printSpeed; drawEditInteger3(select_tune.now + MROWS - index_tune, hmiValues.printSpeed); return; } @@ -1659,12 +1659,12 @@ void hmiMaxAccelerationXYZE() { // Draw X, Y, Z and blink if in an un-homed or un-trusted state void _update_axis_value(const AxisEnum axis, const uint16_t x, const uint16_t y, const bool blink, const bool force) { - const bool draw_qmark = axis_should_home(axis), - draw_empty = NONE(HOME_AFTER_DEACTIVATE, DISABLE_REDUCED_ACCURACY_WARNING) && !draw_qmark && !axis_is_trusted(axis); + const bool draw_qmark = motion.axis_should_home(axis), + draw_empty = NONE(HOME_AFTER_DEACTIVATE, DISABLE_REDUCED_ACCURACY_WARNING) && !draw_qmark && !motion.axis_is_trusted(axis); // Check for a position change static xyz_pos_t oldpos = { -1, -1, -1 }; - const float p = current_position[axis]; + const float p = motion.position[axis]; const bool changed = oldpos[axis] != p; if (changed) oldpos[axis] = p; @@ -1768,8 +1768,8 @@ void updateVariable() { #endif static int16_t _feedrate = 0; - if (_feedrate != feedrate_percentage) { - _feedrate = feedrate_percentage; + if (_feedrate != motion.feedrate_percentage) { + _feedrate = motion.feedrate_percentage; drawStatInt(116 + 2 * STAT_CHR_W, 384, _feedrate); } @@ -2021,7 +2021,7 @@ void drawStatusArea(const bool with_update) { #endif dwinIconShow(ICON, ICON_Speed, 113, 383); - drawStatInt(116 + 2 * STAT_CHR_W, 384, feedrate_percentage); + drawStatInt(116 + 2 * STAT_CHR_W, 384, motion.feedrate_percentage); dwinDrawString(false, DWIN_FONT_STAT, COLOR_WHITE, COLOR_BG_BLACK, 116 + 5 * STAT_CHR_W + 2, 384, F("%")); #if HAS_FAN @@ -2730,11 +2730,11 @@ void hmiPrepare() { select_axis.reset(); drawMoveMenu(); - drawEditFloat3(1, current_position.x * MINUNITMULT); - drawEditFloat3(2, current_position.y * MINUNITMULT); - drawEditFloat3(3, current_position.z * MINUNITMULT); + drawEditFloat3(1, motion.position.x * MINUNITMULT); + drawEditFloat3(2, motion.position.y * MINUNITMULT); + drawEditFloat3(3, motion.position.z * MINUNITMULT); #if HAS_HOTEND - hmiValues.moveScaled.e = current_position.e * MINUNITMULT; + hmiValues.moveScaled.e = motion.position.e * MINUNITMULT; drawEditSignedFloat3(4, hmiValues.moveScaled.e); #endif break; @@ -2990,7 +2990,7 @@ void hmiAxisMove() { if (hmiFlag.cold_flag) { if (encoder_diffState == ENCODER_DIFF_ENTER) { hmiFlag.cold_flag = false; - hmiValues.moveScaled.e = current_position.e * MINUNITMULT; + hmiValues.moveScaled.e = motion.position.e * MINUNITMULT; drawMoveMenu(); XYZ_CODE( drawEditFloat3(1, hmiValues.moveScaled.x), @@ -3023,7 +3023,7 @@ void hmiAxisMove() { #if HAS_X_AXIS case 1: // X axis move checkkey = ID_MoveX; - hmiValues.moveScaled.x = current_position.x * MINUNITMULT; + hmiValues.moveScaled.x = motion.position.x * MINUNITMULT; drawEditFloat3(1, hmiValues.moveScaled.x, true); encoderRate.enabled = true; break; @@ -3031,7 +3031,7 @@ void hmiAxisMove() { #if HAS_Y_AXIS case 2: // Y axis move checkkey = ID_MoveY; - hmiValues.moveScaled.y = current_position.y * MINUNITMULT; + hmiValues.moveScaled.y = motion.position.y * MINUNITMULT; drawEditFloat3(2, hmiValues.moveScaled.y, true); encoderRate.enabled = true; break; @@ -3039,7 +3039,7 @@ void hmiAxisMove() { #if HAS_Z_AXIS case 3: // Z axis move checkkey = ID_MoveZ; - hmiValues.moveScaled.z = current_position.z * MINUNITMULT; + hmiValues.moveScaled.z = motion.position.z * MINUNITMULT; drawEditFloat3(3, hmiValues.moveScaled.z, true); encoderRate.enabled = true; break; @@ -3055,7 +3055,7 @@ void hmiAxisMove() { } #endif checkkey = ID_Extruder; - hmiValues.moveScaled.e = current_position.e * MINUNITMULT; + hmiValues.moveScaled.e = motion.position.e * MINUNITMULT; drawEditSignedFloat3(4, hmiValues.moveScaled.e, true); encoderRate.enabled = true; break; @@ -3595,9 +3595,9 @@ void hmiAdvSet() { case ADVSET_CASE_HOMEOFF: checkkey = ID_HomeOff; select_item.reset(); - hmiValues.homeOffsScaled.x = home_offset.x * 10; - hmiValues.homeOffsScaled.y = home_offset.y * 10; - hmiValues.homeOffsScaled.z = home_offset.z * 10; + hmiValues.homeOffsScaled.x = motion.home_offset.x * 10; + hmiValues.homeOffsScaled.y = motion.home_offset.y * 10; + hmiValues.homeOffsScaled.z = motion.home_offset.z * 10; drawHomeOffMenu(); break; #endif @@ -3685,7 +3685,7 @@ void hmiAdvSet() { if (applyEncoder(encoder_diffState, posScaled)) { checkkey = ID_HomeOff; encoderRate.enabled = false; - set_home_offset(axis, posScaled / 10); + motion.set_home_offset(axis, posScaled / 10); drawEditSignedFloat3(select_item.now, posScaled); return; } @@ -3808,7 +3808,7 @@ void hmiTune() { break; case TUNE_CASE_SPEED: // Print speed checkkey = ID_PrintSpeed; - hmiValues.printSpeed = feedrate_percentage; + hmiValues.printSpeed = motion.feedrate_percentage; drawEditInteger3(TUNE_CASE_SPEED + MROWS - index_tune, hmiValues.printSpeed, true); encoderRate.enabled = true; break; @@ -4190,7 +4190,7 @@ void eachMomentUpdate() { } else if (dwin_abort_flag && !hmiFlag.home_flag) { // Print Stop dwin_abort_flag = false; - hmiValues.printSpeed = feedrate_percentage = 100; + hmiValues.printSpeed = motion.feedrate_percentage = 100; dwin_zoffset = BABY_Z_VAR; select_page.set(0); gotoMainMenu(); @@ -4326,7 +4326,7 @@ void dwinHomingDone() { drawPrepareMenu(); } else if (checkkey == ID_BackMain) { - hmiValues.printSpeed = feedrate_percentage = 100; + hmiValues.printSpeed = motion.feedrate_percentage = 100; planner.finish_and_disable(); gotoMainMenu(); } diff --git a/Marlin/src/lcd/dwin/jyersui/dwin.cpp b/Marlin/src/lcd/dwin/jyersui/dwin.cpp index 3ffdc4ab89..0c55f3d16d 100644 --- a/Marlin/src/lcd/dwin/jyersui/dwin.cpp +++ b/Marlin/src/lcd/dwin/jyersui/dwin.cpp @@ -306,7 +306,7 @@ private: #endif void manualValueUpdate(const bool reset=false) { - const float zval = reset ? 0.0f : current_position.z; + const float zval = reset ? 0.0f : motion.position.z; queue.inject(TS(F("M421I"), mesh_x, F("J"), mesh_y, F("Z"), p_float_t(zval, 3))); planner.synchronize(); } @@ -314,17 +314,17 @@ private: void manual_mesh_move(const bool zmove=false) { if (zmove) { planner.synchronize(); - current_position.z = goto_mesh_value ? bedlevel.z_values[mesh_x][mesh_y] : Z_CLEARANCE_BETWEEN_PROBES; - planner.buffer_line(current_position, homing_feedrate(Z_AXIS), active_extruder); + motion.position.z = goto_mesh_value ? bedlevel.z_values[mesh_x][mesh_y] : Z_CLEARANCE_BETWEEN_PROBES; + planner.buffer_line(motion.position, motion.homing_feedrate(Z_AXIS), motion.extruder); planner.synchronize(); } else { jyersDWIN.popupHandler(Popup_MoveWait); - gcode.process_subcommands_now(TS(F("G0F300Z"), p_float_t(current_position.z, 3))); + gcode.process_subcommands_now(TS(F("G0F300Z"), p_float_t(motion.position.z, 3))); gcode.process_subcommands_now(TS(F("G42 F4000 I"), mesh_x, 'J', mesh_y)); planner.synchronize(); - current_position.z = goto_mesh_value ? bedlevel.z_values[mesh_x][mesh_y] : Z_CLEARANCE_BETWEEN_PROBES; - planner.buffer_line(current_position, homing_feedrate(Z_AXIS), active_extruder); + motion.position.z = goto_mesh_value ? bedlevel.z_values[mesh_x][mesh_y] : Z_CLEARANCE_BETWEEN_PROBES; + planner.buffer_line(motion.position, motion.homing_feedrate(Z_AXIS), motion.extruder); planner.synchronize(); jyersDWIN.redrawMenu(); } @@ -875,16 +875,16 @@ void JyersDWIN::drawStatusArea(const bool icons/*=false*/) { dwinIconShow(ICON, ICON_Speed, 113, 383); dwinDrawString(false, DWIN_FONT_STAT, getColor(eeprom_settings.status_area_text, COLOR_WHITE), COLOR_BG_BLACK, 116 + 5 * STAT_CHR_W + 2, 384, F("%")); } - if (feedrate_percentage != feedrate) { - feedrate = feedrate_percentage; - dwinDrawIntValue(true, true, 0, DWIN_FONT_STAT, getColor(eeprom_settings.status_area_text, COLOR_WHITE), COLOR_BG_BLACK, 3, 116 + 2 * STAT_CHR_W, 384, feedrate_percentage); + if (motion.feedrate_percentage != feedrate) { + feedrate = motion.feedrate_percentage; + dwinDrawIntValue(true, true, 0, DWIN_FONT_STAT, getColor(eeprom_settings.status_area_text, COLOR_WHITE), COLOR_BG_BLACK, 3, 116 + 2 * STAT_CHR_W, 384, motion.feedrate_percentage); } static float x = -1, y = -1, z = -1; static bool update_x = false, update_y = false, update_z = false; - update_x = (current_position.x != x || axis_should_home(X_AXIS) || update_x); - update_y = (current_position.y != y || axis_should_home(Y_AXIS) || update_y); - update_z = (current_position.z != z || axis_should_home(Z_AXIS) || update_z); + update_x = (motion.position.x != x || motion.axis_should_home(X_AXIS) || update_x); + update_y = (motion.position.y != y || motion.axis_should_home(Y_AXIS) || update_y); + update_z = (motion.position.z != z || motion.axis_should_home(Z_AXIS) || update_z); if (icons) { x = y = z = -1; dwinDrawLine(getColor(eeprom_settings.coordinates_split_line, COLOR_LINE, true), 16, 450, 256, 450); @@ -893,25 +893,25 @@ void JyersDWIN::drawStatusArea(const bool icons/*=false*/) { dwinIconShow(ICON, ICON_MaxSpeedZ, 180, 456); } if (update_x) { - x = current_position.x; - if ((update_x = axis_should_home(X_AXIS) && ui.get_blink())) + x = motion.position.x; + if ((update_x = motion.axis_should_home(X_AXIS) && ui.get_blink())) dwinDrawString(true, DWIN_FONT_MENU, getColor(eeprom_settings.coordinates_text, COLOR_WHITE), COLOR_BG_BLACK, 35, 459, F(" -?- ")); else - dwinDrawFloatValue(true, true, 0, DWIN_FONT_MENU, getColor(eeprom_settings.coordinates_text, COLOR_WHITE), COLOR_BG_BLACK, 3, 1, 35, 459, current_position.x); + dwinDrawFloatValue(true, true, 0, DWIN_FONT_MENU, getColor(eeprom_settings.coordinates_text, COLOR_WHITE), COLOR_BG_BLACK, 3, 1, 35, 459, motion.position.x); } if (update_y) { - y = current_position.y; - if ((update_y = axis_should_home(Y_AXIS) && ui.get_blink())) + y = motion.position.y; + if ((update_y = motion.axis_should_home(Y_AXIS) && ui.get_blink())) dwinDrawString(true, DWIN_FONT_MENU, getColor(eeprom_settings.coordinates_text, COLOR_WHITE), COLOR_BG_BLACK, 120, 459, F(" -?- ")); else - dwinDrawFloatValue(true, true, 0, DWIN_FONT_MENU, getColor(eeprom_settings.coordinates_text, COLOR_WHITE), COLOR_BG_BLACK, 3, 1, 120, 459, current_position.y); + dwinDrawFloatValue(true, true, 0, DWIN_FONT_MENU, getColor(eeprom_settings.coordinates_text, COLOR_WHITE), COLOR_BG_BLACK, 3, 1, 120, 459, motion.position.y); } if (update_z) { - z = current_position.z; - if ((update_z = axis_should_home(Z_AXIS) && ui.get_blink())) + z = motion.position.z; + if ((update_z = motion.axis_should_home(Z_AXIS) && ui.get_blink())) dwinDrawString(true, DWIN_FONT_MENU, getColor(eeprom_settings.coordinates_text, COLOR_WHITE), COLOR_BG_BLACK, 205, 459, F(" -?- ")); else - dwinDrawFloatValue(true, true, 0, DWIN_FONT_MENU, getColor(eeprom_settings.coordinates_text, COLOR_WHITE), COLOR_BG_BLACK, 3, 2, 205, 459, current_position.z >= 0 ? current_position.z : 0); + dwinDrawFloatValue(true, true, 0, DWIN_FONT_MENU, getColor(eeprom_settings.coordinates_text, COLOR_WHITE), COLOR_BG_BLACK, 3, 2, 205, 459, motion.position.z >= 0 ? motion.position.z : 0); } dwinUpdateLCD(); } @@ -1089,7 +1089,7 @@ void JyersDWIN::menuItemHandler(const uint8_t menu, const uint8_t item, bool dra if (draw) drawMenuItem(row, ICON_PrintSize, F("Manual Leveling"), nullptr, true); else { - if (axes_should_home()) { + if (motion.axes_should_home()) { popupHandler(Popup_Home); gcode.home_all_axes(true); } @@ -1277,35 +1277,35 @@ void JyersDWIN::menuItemHandler(const uint8_t menu, const uint8_t item, bool dra case MOVE_X: if (draw) { drawMenuItem(row, ICON_MoveX, GET_TEXT_F(MSG_MOVE_X)); - drawFloat(current_position.x, row, false); + drawFloat(motion.position.x, row, false); } else - modifyValue(current_position.x, X_MIN_POS, X_MAX_POS, 10); + modifyValue(motion.position.x, X_MIN_POS, X_MAX_POS, 10); break; case MOVE_Y: if (draw) { drawMenuItem(row, ICON_MoveY, GET_TEXT_F(MSG_MOVE_Y)); - drawFloat(current_position.y, row); + drawFloat(motion.position.y, row); } else - modifyValue(current_position.y, Y_MIN_POS, Y_MAX_POS, 10); + modifyValue(motion.position.y, Y_MIN_POS, Y_MAX_POS, 10); break; case MOVE_Z: if (draw) { drawMenuItem(row, ICON_MoveZ, GET_TEXT_F(MSG_MOVE_Z)); - drawFloat(current_position.z, row); + drawFloat(motion.position.z, row); } else - modifyValue(current_position.z, Z_MIN_POS, Z_MAX_POS, 10); + modifyValue(motion.position.z, Z_MIN_POS, Z_MAX_POS, 10); break; #if HAS_HOTEND case MOVE_E: if (draw) { drawMenuItem(row, ICON_Extruder, GET_TEXT_F(MSG_MOVE_E)); - current_position.e = 0; - sync_plan_position(); - drawFloat(current_position.e, row); + motion.position.e = 0; + motion.sync_plan_position(); + drawFloat(motion.position.e, row); } else { if (thermalManager.targetTooColdToExtrude(0)) { @@ -1317,9 +1317,9 @@ void JyersDWIN::menuItemHandler(const uint8_t menu, const uint8_t item, bool dra thermalManager.wait_for_hotend(0); redrawMenu(); } - current_position.e = 0; - sync_plan_position(); - modifyValue(current_position.e, -500, 500, 10); + motion.position.e = 0; + motion.sync_plan_position(); + modifyValue(motion.position.e, -500, 500, 10); } } break; @@ -1589,7 +1589,7 @@ void JyersDWIN::menuItemHandler(const uint8_t menu, const uint8_t item, bool dra } else { if (!liveadjust) { - if (axes_should_home()) { + if (motion.axes_should_home()) { popupHandler(Popup_Home); gcode.home_all_axes(true); } @@ -2249,7 +2249,7 @@ void JyersDWIN::menuItemHandler(const uint8_t menu, const uint8_t item, bool dra drawMenuItem(row, ICON_HotendTemp, GET_TEXT_F(MSG_PID_AUTOTUNE)); else { popupHandler(Popup_MPCWait); - thermalManager.MPC_autotune(active_extruder, Temperature::MPCTuningType::AUTO); + thermalManager.MPC_autotune(motion.extruder, Temperature::MPCTuningType::AUTO); redrawMenu(); } break; @@ -2416,18 +2416,18 @@ void JyersDWIN::menuItemHandler(const uint8_t menu, const uint8_t item, bool dra case HOMEOFFSETS_XOFFSET: if (draw) { drawMenuItem(row, ICON_StepX, GET_TEXT_F(MSG_HOME_OFFSET_X)); - drawFloat(home_offset.x, row, false, 100); + drawFloat(motion.home_offset.x, row, false, 100); } else - modifyValue(home_offset.x, -MAX_XY_OFFSET, MAX_XY_OFFSET, 100); + modifyValue(motion.home_offset.x, -MAX_XY_OFFSET, MAX_XY_OFFSET, 100); break; case HOMEOFFSETS_YOFFSET: if (draw) { drawMenuItem(row, ICON_StepY, GET_TEXT_F(MSG_HOME_OFFSET_Y)); - drawFloat(home_offset.y, row, false, 100); + drawFloat(motion.home_offset.y, row, false, 100); } else - modifyValue(home_offset.y, -MAX_XY_OFFSET, MAX_XY_OFFSET, 100); + modifyValue(motion.home_offset.y, -MAX_XY_OFFSET, MAX_XY_OFFSET, 100); break; } break; @@ -3287,7 +3287,7 @@ void JyersDWIN::menuItemHandler(const uint8_t menu, const uint8_t item, bool dra break; } #endif - if (axes_should_home()) { + if (motion.axes_should_home()) { popupHandler(Popup_Home); gcode.home_all_axes(true); } @@ -3567,8 +3567,8 @@ void JyersDWIN::menuItemHandler(const uint8_t menu, const uint8_t item, bool dra bedlevel.z_values[mesh_conf.mesh_x][mesh_conf.mesh_y] += 0.01; queue.inject(F("M290 Z0.01")); planner.synchronize(); - current_position.z += 0.01f; - sync_plan_position(); + motion.position.z += 0.01f; + motion.sync_plan_position(); drawFloat(bedlevel.z_values[mesh_conf.mesh_x][mesh_conf.mesh_y], row - 1, false, 100); } break; @@ -3579,8 +3579,8 @@ void JyersDWIN::menuItemHandler(const uint8_t menu, const uint8_t item, bool dra bedlevel.z_values[mesh_conf.mesh_x][mesh_conf.mesh_y] -= 0.01; queue.inject(F("M290 Z-0.01")); planner.synchronize(); - current_position.z -= 0.01f; - sync_plan_position(); + motion.position.z -= 0.01f; + motion.sync_plan_position(); drawFloat(bedlevel.z_values[mesh_conf.mesh_x][mesh_conf.mesh_y], row - 2, false, 100); } break; @@ -3591,7 +3591,7 @@ void JyersDWIN::menuItemHandler(const uint8_t menu, const uint8_t item, bool dra } else { FLIP(mesh_conf.goto_mesh_value); - current_position.z = 0; + motion.position.z = 0; mesh_conf.manual_mesh_move(true); drawCheckbox(row, mesh_conf.goto_mesh_value); } @@ -3686,8 +3686,8 @@ void JyersDWIN::menuItemHandler(const uint8_t menu, const uint8_t item, bool dra bedlevel.z_values[mesh_conf.mesh_x][mesh_conf.mesh_y] += 0.01; queue.inject(F("M290 Z0.01")); planner.synchronize(); - current_position.z += 0.01f; - sync_plan_position(); + motion.position.z += 0.01f; + motion.sync_plan_position(); drawFloat(bedlevel.z_values[mesh_conf.mesh_x][mesh_conf.mesh_y], row - 1, false, 100); } break; @@ -3698,8 +3698,8 @@ void JyersDWIN::menuItemHandler(const uint8_t menu, const uint8_t item, bool dra bedlevel.z_values[mesh_conf.mesh_x][mesh_conf.mesh_y] -= 0.01; queue.inject(F("M290 Z-0.01")); planner.synchronize(); - current_position.z -= 0.01f; - sync_plan_position(); + motion.position.z -= 0.01f; + motion.sync_plan_position(); drawFloat(bedlevel.z_values[mesh_conf.mesh_x][mesh_conf.mesh_y], row - 2, false, 100); } break; @@ -3753,32 +3753,32 @@ void JyersDWIN::menuItemHandler(const uint8_t menu, const uint8_t item, bool dra case MMESH_OFFSET: if (draw) { drawMenuItem(row, ICON_SetZOffset, F("Z Position")); - current_position.z = MANUAL_PROBE_START_Z; - drawFloat(current_position.z, row, false, 100); + motion.position.z = MANUAL_PROBE_START_Z; + drawFloat(motion.position.z, row, false, 100); } else - modifyValue(current_position.z, MIN_Z_OFFSET, MAX_Z_OFFSET, 100); + modifyValue(motion.position.z, MIN_Z_OFFSET, MAX_Z_OFFSET, 100); break; case MMESH_UP: if (draw) drawMenuItem(row, ICON_Axis, F("+0.01mm Up")); - else if (current_position.z < MAX_Z_OFFSET) { + else if (motion.position.z < MAX_Z_OFFSET) { gcode.process_subcommands_now(F("M290 Z0.01")); planner.synchronize(); - current_position.z += 0.01f; - sync_plan_position(); - drawFloat(current_position.z, row - 1, false, 100); + motion.position.z += 0.01f; + motion.sync_plan_position(); + drawFloat(motion.position.z, row - 1, false, 100); } break; case MMESH_DOWN: if (draw) drawMenuItem(row, ICON_AxisD, F("-0.01mm Down")); - else if (current_position.z > MIN_Z_OFFSET) { + else if (motion.position.z > MIN_Z_OFFSET) { gcode.process_subcommands_now(F("M290 Z-0.01")); planner.synchronize(); - current_position.z -= 0.01f; - sync_plan_position(); - drawFloat(current_position.z, row - 2, false, 100); + motion.position.z -= 0.01f; + motion.sync_plan_position(); + drawFloat(motion.position.z, row - 2, false, 100); } break; case MMESH_OLD: @@ -3797,11 +3797,11 @@ void JyersDWIN::menuItemHandler(const uint8_t menu, const uint8_t item, bool dra drawFloat(currval, row, false, 100); } else if (!isnan(currval)) { - current_position.z = currval; + motion.position.z = currval; planner.synchronize(); - planner.buffer_line(current_position, homing_feedrate(Z_AXIS), active_extruder); + planner.buffer_line(motion.position, motion.homing_feedrate(Z_AXIS), motion.extruder); planner.synchronize(); - drawFloat(current_position.z, row - 3, false, 100); + drawFloat(motion.position.z, row - 3, false, 100); } break; } @@ -3837,10 +3837,10 @@ void JyersDWIN::menuItemHandler(const uint8_t menu, const uint8_t item, bool dra case TUNE_SPEED: if (draw) { drawMenuItem(row, ICON_Speed, GET_TEXT_F(MSG_SPEED)); - drawFloat(feedrate_percentage, row, false, 1); + drawFloat(motion.feedrate_percentage, row, false, 1); } else - modifyValue(feedrate_percentage, MIN_PRINT_SPEED, MAX_PRINT_SPEED, 1); + modifyValue(motion.feedrate_percentage, MIN_PRINT_SPEED, MAX_PRINT_SPEED, 1); break; #if HAS_HOTEND @@ -4414,10 +4414,10 @@ void JyersDWIN::valueControl() { dwinUpdateLCD(); if (active_menu == ID_ZOffset && liveadjust) { planner.synchronize(); - current_position.z += (tempvalue / valueunit - zoffsetvalue); - planner.buffer_line(current_position, homing_feedrate(Z_AXIS), active_extruder); - current_position.z = 0; - sync_plan_position(); + motion.position.z += (tempvalue / valueunit - zoffsetvalue); + planner.buffer_line(motion.position, motion.homing_feedrate(Z_AXIS), motion.extruder); + motion.position.z = 0; + motion.sync_plan_position(); } else if (active_menu == ID_Tune && selection == TUNE_ZOFFSET) { gcode.process_subcommands_now(TS(F("M290Z"), p_float_t((tempvalue / valueunit - zoffsetvalue), 3))); @@ -4437,12 +4437,12 @@ void JyersDWIN::valueControl() { switch (active_menu) { case ID_Move: planner.synchronize(); - planner.buffer_line(current_position, manual_feedrate_mm_s[selection - 1], active_extruder); + planner.buffer_line(motion.position, manual_feedrate_mm_s[selection - 1], motion.extruder); break; #if HAS_MESH case ID_ManualMesh: planner.synchronize(); - planner.buffer_line(current_position, homing_feedrate(Z_AXIS), active_extruder); + planner.buffer_line(motion.position, motion.homing_feedrate(Z_AXIS), motion.extruder); planner.synchronize(); break; case ID_UBLMesh: mesh_conf.manual_mesh_move(true); break; @@ -4457,7 +4457,7 @@ void JyersDWIN::valueControl() { dwinUpdateLCD(); if (active_menu == ID_Move && livemove) { *(float*)valuepointer = tempvalue / valueunit; - planner.buffer_line(current_position, manual_feedrate_mm_s[selection - 1], active_extruder); + planner.buffer_line(motion.position, manual_feedrate_mm_s[selection - 1], motion.extruder); } } @@ -4703,7 +4703,7 @@ void JyersDWIN::popupControl() { #if HAS_BED_PROBE case Popup_ManualProbing: if (selection == 0) { - const float dif = probe.probe_at_point(current_position.x, current_position.y, PROBE_PT_STOW, 0, false) - corner_avg; + const float dif = probe.probe_at_point(motion.position.x, motion.position.y, PROBE_PT_STOW, 0, false) - corner_avg; updateStatus(TS(F("Corner is "), p_float_t(abs(dif), 3), "mm ", dif > 0 ? F("high") : F("low"))); } else { @@ -5005,7 +5005,7 @@ void JyersDWIN::screenUpdate() { #if HAS_BED_PROBE probe.offset.z = zoffsetvalue; #else - set_home_offset(Z_AXIS, -zoffsetvalue); + motion.set_home_offset(Z_AXIS, -zoffsetvalue); #endif } @@ -5013,8 +5013,8 @@ void JyersDWIN::screenUpdate() { if (probe.offset.z != lastzoffset) zoffsetvalue = lastzoffset = probe.offset.z; #else - if (-home_offset.z != lastzoffset) - zoffsetvalue = lastzoffset = -home_offset.z; + if (-motion.home_offset.z != lastzoffset) + zoffsetvalue = lastzoffset = -motion.home_offset.z; #endif #endif // HAS_ZOFFSET_ITEM @@ -5152,7 +5152,7 @@ void MarlinUI::init_lcd() { void MarlinUI::clear_lcd() {} #if ENABLED(ADVANCED_PAUSE_FEATURE) - void MarlinUI::pause_show_message(const PauseMessage message, const PauseMode mode/*=PAUSE_MODE_SAME*/, const uint8_t extruder/*=active_extruder*/) { + void MarlinUI::pause_show_message(const PauseMessage message, const PauseMode mode/*=PAUSE_MODE_SAME*/, const uint8_t extruder/*=motion.extruder*/) { if (mode != PAUSE_MODE_SAME) pause_mode = mode; switch (message) { case PAUSE_MESSAGE_INSERT: jyersDWIN.confirmHandler(Popup_FilInsert); break; diff --git a/Marlin/src/lcd/dwin/marlinui/ui_status_480x272.cpp b/Marlin/src/lcd/dwin/marlinui/ui_status_480x272.cpp index dbeb02dc67..43e9f2805c 100644 --- a/Marlin/src/lcd/dwin/marlinui/ui_status_480x272.cpp +++ b/Marlin/src/lcd/dwin/marlinui/ui_status_480x272.cpp @@ -85,9 +85,9 @@ void _draw_axis_value(const AxisEnum axis, const char *value, const bool blink, dwin_string.set(); if (blink) dwin_string.add(value); - else if (!TEST(axes_homed, axis)) + else if (!motion.axis_was_homed(axis)) while (const char c = *value++) dwin_string.add(c <= '.' ? c : '?'); - else if (NONE(HOME_AFTER_DEACTIVATE, DISABLE_REDUCED_ACCURACY_WARNING) && !TEST(axes_trusted, axis)) + else if (NONE(HOME_AFTER_DEACTIVATE, DISABLE_REDUCED_ACCURACY_WARNING) && !TEST(motion.axes_trusted, axis)) dwin_string.add(TERN1(DWIN_MARLINUI_PORTRAIT, axis == Z_AXIS) ? PSTR(" ") : PSTR(" ")); else dwin_string.add(value); @@ -307,12 +307,12 @@ void MarlinUI::draw_status_screen() { #endif // Axis values - const xyz_pos_t lpos = current_position.asLogical(); + const xyz_pos_t lpos = motion.position.asLogical(); const bool show_e_total = TERN1(HAS_X_AXIS, TERN0(LCD_SHOW_E_TOTAL, marlin.printingIsActive())); constexpr int16_t cpy = TERN(DWIN_MARLINUI_PORTRAIT, 195, 117); if (show_e_total) { - TERN_(LCD_SHOW_E_TOTAL, _draw_e_value(e_move_accumulator, TERN(DWIN_MARLINUI_PORTRAIT, 6, 75), cpy)); + TERN_(LCD_SHOW_E_TOTAL, _draw_e_value(motion.e_move_accumulator, TERN(DWIN_MARLINUI_PORTRAIT, 6, 75), cpy)); } else { XY_CODE( @@ -324,9 +324,9 @@ void MarlinUI::draw_status_screen() { // Feedrate static uint16_t old_fp = 0; - if (!ui.did_first_redraw || old_fp != feedrate_percentage) { - old_fp = feedrate_percentage; - _draw_feedrate_status(i16tostr3rj(feedrate_percentage), + if (!ui.did_first_redraw || old_fp != motion.feedrate_percentage) { + old_fp = motion.feedrate_percentage; + _draw_feedrate_status(i16tostr3rj(motion.feedrate_percentage), #if ENABLED(DWIN_MARLINUI_PORTRAIT) 5, 290 #else diff --git a/Marlin/src/lcd/dwin/proui/bedlevel_tools.cpp b/Marlin/src/lcd/dwin/proui/bedlevel_tools.cpp index 4621ce6653..91a991d29f 100644 --- a/Marlin/src/lcd/dwin/proui/bedlevel_tools.cpp +++ b/Marlin/src/lcd/dwin/proui/bedlevel_tools.cpp @@ -117,7 +117,7 @@ bool drawing_mesh = false; #endif void BedLevelTools::manualValueUpdate(const uint8_t mesh_x, const uint8_t mesh_y, const bool reset/*=false*/) { - const float zval = reset ? 0.0f : current_position.z; + const float zval = reset ? 0.0f : motion.position.z; queue.inject(TS(F("M421I"), mesh_x, F("J"), mesh_y, F("Z"), p_float_t(zval, 3))); planner.synchronize(); } @@ -131,8 +131,8 @@ void BedLevelTools::manualMove(const uint8_t mesh_x, const uint8_t mesh_y, bool gcode.process_subcommands_now(TS(F("G42 F4000 I"), mesh_x, F(" J"), mesh_y)); } planner.synchronize(); - current_position.z = goto_mesh_value ? bedlevel.z_values[mesh_x][mesh_y] : Z_CLEARANCE_BETWEEN_PROBES; - planner.buffer_line(current_position, homing_feedrate(Z_AXIS), active_extruder); + motion.position.z = goto_mesh_value ? bedlevel.z_values[mesh_x][mesh_y] : Z_CLEARANCE_BETWEEN_PROBES; + planner.buffer_line(motion.position, motion.homing_feedrate(Z_AXIS), motion.extruder); planner.synchronize(); if (!zmove) hmiReturnScreen(); } diff --git a/Marlin/src/lcd/dwin/proui/dwin.cpp b/Marlin/src/lcd/dwin/proui/dwin.cpp index 9d404b3690..8684020e17 100644 --- a/Marlin/src/lcd/dwin/proui/dwin.cpp +++ b/Marlin/src/lcd/dwin/proui/dwin.cpp @@ -697,8 +697,8 @@ void gotoMainMenu() { // Draw X, Y, Z and blink if in an un-homed or un-trusted state void _update_axis_value(const AxisEnum axis, const uint16_t x, const uint16_t y, const bool force) { - const bool draw_qmark = axis_should_home(axis), - draw_empty = NONE(HOME_AFTER_DEACTIVATE, DISABLE_REDUCED_ACCURACY_WARNING) && !draw_qmark && !axis_is_trusted(axis); + const bool draw_qmark = motion.axis_should_home(axis), + draw_empty = NONE(HOME_AFTER_DEACTIVATE, DISABLE_REDUCED_ACCURACY_WARNING) && !draw_qmark && !motion.axis_is_trusted(axis); // Check for a position change static xyz_pos_t oldpos = { -1, -1, -1 }; @@ -707,7 +707,7 @@ void _update_axis_value(const AxisEnum axis, const uint16_t x, const uint16_t y, #if ALL(IS_FULL_CARTESIAN, SHOW_REAL_POS) planner.get_axis_position_mm(axis) #else - current_position[axis] + motion.position[axis] #endif ); @@ -759,18 +759,18 @@ void _drawFeedrate() { #if ENABLED(SHOW_SPEED_IND) int16_t _value; if (blink) { - _value = feedrate_percentage; + _value = motion.feedrate_percentage; DWINUI::drawString(DWIN_FONT_STAT, hmiData.colorIndicator, hmiData.colorBackground, 116 + 4 * STAT_CHR_W + 2, 384, F(" %")); } else { - _value = CEIL(MMS_SCALED(feedrate_mm_s)); + _value = CEIL(motion.mms_scaled()); dwinDrawBox(1, hmiData.colorBackground, 116 + 5 * STAT_CHR_W + 2, 384, 20, 20); } DWINUI::drawInt(DWIN_FONT_STAT, hmiData.colorIndicator, hmiData.colorBackground, 3, 116 + 2 * STAT_CHR_W, 384, _value); #else static int16_t _feedrate = 100; - if (_feedrate != feedrate_percentage) { - _feedrate = feedrate_percentage; + if (_feedrate != motion.feedrate_percentage) { + _feedrate = motion.feedrate_percentage; DWINUI::drawInt(DWIN_FONT_STAT, hmiData.colorIndicator, hmiData.colorBackground, 3, 116 + 2 * STAT_CHR_W, 384, _feedrate); } #endif @@ -1091,7 +1091,7 @@ void dwinDrawDashboard() { #endif DWINUI::drawIcon(ICON_Speed, 113, 383); - DWINUI::drawInt(DWIN_FONT_STAT, hmiData.colorIndicator, hmiData.colorBackground, 3, 116 + 2 * STAT_CHR_W, 384, feedrate_percentage); + DWINUI::drawInt(DWIN_FONT_STAT, hmiData.colorIndicator, hmiData.colorBackground, 3, 116 + 2 * STAT_CHR_W, 384, motion.feedrate_percentage); IF_DISABLED(SHOW_SPEED_IND, DWINUI::drawString(DWIN_FONT_STAT, hmiData.colorIndicator, hmiData.colorBackground, 116 + 5 * STAT_CHR_W + 2, 384, F("%"))); #if HAS_FAN @@ -1839,7 +1839,7 @@ void dwinPrintAborted() { #if ENABLED(NOZZLE_PARK_FEATURE) F("G27") #else - TS(F("G0Z"), float(_MIN(current_position.z + (Z_POST_CLEARANCE), Z_MAX_POS)), F("\nG0F2000Y"), Y_MAX_POS) + TS(F("G0Z"), float(_MIN(motion.position.z + (Z_POST_CLEARANCE), Z_MAX_POS)), F("\nG0F2000Y"), Y_MAX_POS) #endif ); } @@ -1915,7 +1915,7 @@ void dwinCopySettingsFrom(const char * const buff) { if (hmiData.colorText == hmiData.colorBackground) dwinSetColorDefaults(); DWINUI::setColors(hmiData.colorText, hmiData.colorBackground, hmiData.colorStatusBg); TERN_(PREVENT_COLD_EXTRUSION, applyExtMinT()); - feedrate_percentage = 100; + motion.feedrate_percentage = 100; TERN_(BAUD_RATE_GCODE, hmiSetBaudRate()); #if ALL(LED_CONTROL_MENU, HAS_COLOR_LEDS) leds.set_color( @@ -2234,7 +2234,7 @@ void axisMove(AxisEnum axis) { } #endif planner.synchronize(); - if (!planner.is_full()) planner.buffer_line(current_position, manual_feedrate_mm_s[axis]); + if (!planner.is_full()) planner.buffer_line(motion.position, manual_feedrate_mm_s[axis]); } void liveMove() { if (!enableLiveMove) return; @@ -2259,8 +2259,8 @@ void setMoveZ() { hmiValue.axis = Z_AXIS; setPFloatOnClick(Z_MIN_POS, Z_MAX_POS, #if HAS_HOTEND void setMoveE() { - const float e_min = current_position.e - (EXTRUDE_MAXLENGTH), - e_max = current_position.e + (EXTRUDE_MAXLENGTH); + const float e_min = motion.position.e - (EXTRUDE_MAXLENGTH), + e_max = motion.position.e + (EXTRUDE_MAXLENGTH); hmiValue.axis = E_AXIS; setPFloatOnClick(e_min, e_max, UNITFDIGITS, applyMove, liveMove); } #endif @@ -2337,7 +2337,7 @@ void setMoveZ() { hmiValue.axis = Z_AXIS; setPFloatOnClick(Z_MIN_POS, Z_MAX_POS, #endif #if HAS_HOME_OFFSET - void applyHomeOffset() { set_home_offset(hmiValue.axis, menuData.value / MINUNITMULT); } + void applyHomeOffset() { motion.set_home_offset(hmiValue.axis, menuData.value / MINUNITMULT); } void setHomeOffsetX() { hmiValue.axis = X_AXIS; setPFloatOnClick(-50, 50, UNITFDIGITS, applyHomeOffset); } void setHomeOffsetY() { hmiValue.axis = Y_AXIS; setPFloatOnClick(-50, 50, UNITFDIGITS, applyHomeOffset); } void setHomeOffsetZ() { hmiValue.axis = Z_AXIS; setPFloatOnClick( -2, 2, UNITFDIGITS, applyHomeOffset); } @@ -2619,7 +2619,7 @@ void setFlow() { setPIntOnClick(FLOW_EDIT_MIN, FLOW_EDIT_MAX, []{ planner.refres *menuData.floatPtr = menuData.value / POW(10, MESH_Z_FDIGITS); if (!planner.is_full()) { planner.synchronize(); - planner.buffer_line(current_position, manual_feedrate_mm_s[Z_AXIS]); + planner.buffer_line(motion.position, manual_feedrate_mm_s[Z_AXIS]); } } void setMMeshMoveZ() { setPFloatOnClick(-1, 1, MESH_Z_FDIGITS, planner.synchronize, liveMeshMoveZ); } @@ -2721,21 +2721,21 @@ void applyMaxAccel() { planner.set_max_acceleration(hmiValue.axis, menuData.valu #if ENABLED(EDITABLE_HOMING_FEEDRATE) void updateHomingFR(AxisEnum axis, feedRate_t value) { switch (axis) { - case X_AXIS: homing_feedrate_mm_m.x = value; break; - case Y_AXIS: homing_feedrate_mm_m.y = value; break; - case Z_AXIS: homing_feedrate_mm_m.z = value; break; + case X_AXIS: motion.homing_feedrate_mm_m.x = value; break; + case Y_AXIS: motion.homing_feedrate_mm_m.y = value; break; + case Z_AXIS: motion.homing_feedrate_mm_m.z = value; break; default: break; } } void applyHomingFR() { updateHomingFR(hmiValue.axis, menuData.value); } #if HAS_X_AXIS - void setHomingX() { hmiValue.axis = X_AXIS; setIntOnClick(min_homing_edit_values.x, max_homing_edit_values.x, homing_feedrate_mm_m.x, applyHomingFR); } + void setHomingX() { hmiValue.axis = X_AXIS; setIntOnClick(min_homing_edit_values.x, max_homing_edit_values.x, motion.homing_feedrate_mm_m.x, applyHomingFR); } #endif #if HAS_Y_AXIS - void setHomingY() { hmiValue.axis = Y_AXIS; setIntOnClick(min_homing_edit_values.y, max_homing_edit_values.y, homing_feedrate_mm_m.x, applyHomingFR); } + void setHomingY() { hmiValue.axis = Y_AXIS; setIntOnClick(min_homing_edit_values.y, max_homing_edit_values.y, motion.homing_feedrate_mm_m.x, applyHomingFR); } #endif #if HAS_Z_AXIS - void setHomingZ() { hmiValue.axis = Z_AXIS; setIntOnClick(min_homing_edit_values.z, max_homing_edit_values.z, homing_feedrate_mm_m.x, applyHomingFR); } + void setHomingZ() { hmiValue.axis = Z_AXIS; setIntOnClick(min_homing_edit_values.z, max_homing_edit_values.z, motion.homing_feedrate_mm_m.x, applyHomingFR); } #endif #endif @@ -3357,21 +3357,21 @@ void drawMoveMenu() { BACK_ITEM(drawPrepareMenu); EDIT_ITEM(ICON_Axis, MSG_LIVE_MOVE, onDrawChkbMenu, setLiveMove, &enableLiveMove); #if HAS_X_AXIS - EDIT_ITEM(ICON_MoveX, MSG_MOVE_X, onDrawMoveX, setMoveX, ¤t_position.x); + EDIT_ITEM(ICON_MoveX, MSG_MOVE_X, onDrawMoveX, setMoveX, &motion.position.x); #endif #if HAS_Y_AXIS - EDIT_ITEM(ICON_MoveY, MSG_MOVE_Y, onDrawMoveY, setMoveY, ¤t_position.y); + EDIT_ITEM(ICON_MoveY, MSG_MOVE_Y, onDrawMoveY, setMoveY, &motion.position.y); #endif #if HAS_Z_AXIS - EDIT_ITEM(ICON_MoveZ, MSG_MOVE_Z, onDrawMoveZ, setMoveZ, ¤t_position.z); + EDIT_ITEM(ICON_MoveZ, MSG_MOVE_Z, onDrawMoveZ, setMoveZ, &motion.position.z); #endif #if HAS_HOTEND gcode.process_subcommands_now(F("G92E0")); // Reset extruder position - EDIT_ITEM(ICON_Extruder, MSG_MOVE_E, onDrawMoveE, setMoveE, ¤t_position.e); + EDIT_ITEM(ICON_Extruder, MSG_MOVE_E, onDrawMoveE, setMoveE, &motion.position.e); #endif } updateMenu(moveMenu); - if (!all_axes_trusted()) LCD_MESSAGE_F("WARNING: Current position unknown. Home axes."); + if (!motion.all_axes_trusted()) LCD_MESSAGE_F("WARNING: Current position unknown. Home axes."); } #if HAS_HOME_OFFSET @@ -3382,13 +3382,13 @@ void drawMoveMenu() { if (SET_MENU(homeOffsetMenu, MSG_SET_HOME_OFFSETS, items)) { BACK_ITEM(drawAdvancedSettingsMenu); #if HAS_X_AXIS - EDIT_ITEM(ICON_HomeOffsetX, MSG_HOME_OFFSET_X, onDrawPFloatMenu, setHomeOffsetX, &home_offset.x); + EDIT_ITEM(ICON_HomeOffsetX, MSG_HOME_OFFSET_X, onDrawPFloatMenu, setHomeOffsetX, &motion.home_offset.x); #endif #if HAS_Y_AXIS - EDIT_ITEM(ICON_HomeOffsetY, MSG_HOME_OFFSET_Y, onDrawPFloatMenu, setHomeOffsetY, &home_offset.y); + EDIT_ITEM(ICON_HomeOffsetY, MSG_HOME_OFFSET_Y, onDrawPFloatMenu, setHomeOffsetY, &motion.home_offset.y); #endif #if HAS_Z_AXIS - EDIT_ITEM(ICON_HomeOffsetZ, MSG_HOME_OFFSET_Z, onDrawPFloatMenu, setHomeOffsetZ, &home_offset.z); + EDIT_ITEM(ICON_HomeOffsetZ, MSG_HOME_OFFSET_Z, onDrawPFloatMenu, setHomeOffsetZ, &motion.home_offset.z); #endif } updateMenu(homeOffsetMenu); @@ -3529,7 +3529,7 @@ void drawTuneMenu() { checkkey = ID_Menu; if (SET_MENU_R(tuneMenu, selrect({73, 2, 28, 12}), MSG_TUNE, items)) { BACK_ITEM(gotoPrintProcess); - EDIT_ITEM(ICON_Speed, MSG_SPEED, onDrawSpeedItem, setSpeed, &feedrate_percentage); + EDIT_ITEM(ICON_Speed, MSG_SPEED, onDrawSpeedItem, setSpeed, &motion.feedrate_percentage); EDIT_ITEM(ICON_Flow, MSG_FLOW, onDrawPIntMenu, setFlow, &planner.flow_percentage[0]); #if HAS_HOTEND hotendTargetItem = EDIT_ITEM(ICON_HotendTemp, MSG_UBL_SET_TEMP_HOTEND, onDrawHotendTemp, setHotendTemp, &thermalManager.temp_hotend[0].target); @@ -3721,7 +3721,7 @@ void drawMotionMenu() { #if ENABLED(ADAPTIVE_STEP_SMOOTHING_TOGGLE) EDIT_ITEM(ICON_UBLActive, MSG_STEP_SMOOTHING, onDrawChkbMenu, toggleAdaptiveStepSmoothing, &stepper.adaptive_step_smoothing_enabled); #endif - EDIT_ITEM(ICON_Speed, MSG_SPEED, onDrawSpeedItem, setSpeed, &feedrate_percentage); + EDIT_ITEM(ICON_Speed, MSG_SPEED, onDrawSpeedItem, setSpeed, &motion.feedrate_percentage); EDIT_ITEM(ICON_Flow, MSG_FLOW, onDrawPIntMenu, setFlow, &planner.flow_percentage[0]); } updateMenu(motionMenu); @@ -3775,7 +3775,7 @@ void drawFilamentManMenu() { if (SET_MENU(manualMeshMenu, MSG_UBL_MANUAL_MESH, items)) { BACK_ITEM(drawPrepareMenu); MENU_ITEM(ICON_ManualMesh, MSG_LEVEL_BED, onDrawMenuItem, manualMeshStart); - mMeshMoveZItem = EDIT_ITEM(ICON_Zoffset, MSG_MOVE_Z, onDrawMMeshMoveZ, setMMeshMoveZ, ¤t_position.z); + mMeshMoveZItem = EDIT_ITEM(ICON_Zoffset, MSG_MOVE_Z, onDrawMMeshMoveZ, setMMeshMoveZ, &motion.position.z); MENU_ITEM(ICON_Axis, MSG_UBL_CONTINUE_MESH, onDrawMenuItem, manualMeshContinue); MENU_ITEM(ICON_MeshViewer, MSG_MESH_VIEW, onDrawSubMenu, dwinMeshViewer); #if USE_GRID_MESHVIEWER @@ -3945,15 +3945,15 @@ void drawMaxAccelMenu() { if (SET_MENU(homingFRMenu, MSG_HOMING_FEEDRATE, items)) { BACK_ITEM(drawMotionMenu); #if HAS_X_AXIS - uint16_t xhome = static_cast(homing_feedrate_mm_m.x); + uint16_t xhome = static_cast(motion.homing_feedrate_mm_m.x); EDIT_ITEM(ICON_MaxSpeedJerkX, MSG_HOMING_FEEDRATE_X, onDrawPIntMenu, setHomingX, &xhome); #endif #if HAS_Y_AXIS - uint16_t yhome = static_cast(homing_feedrate_mm_m.y); + uint16_t yhome = static_cast(motion.homing_feedrate_mm_m.y); EDIT_ITEM(ICON_MaxSpeedJerkY, MSG_HOMING_FEEDRATE_Y, onDrawPIntMenu, setHomingY, &yhome); #endif #if HAS_Z_AXIS - uint16_t zhome = static_cast(homing_feedrate_mm_m.z); + uint16_t zhome = static_cast(motion.homing_feedrate_mm_m.z); EDIT_ITEM(ICON_MaxSpeedJerkZ, MSG_HOMING_FEEDRATE_Z, onDrawPIntMenu, setHomingZ, &zhome); #endif } @@ -4072,7 +4072,7 @@ void drawMaxAccelMenu() { MPC_t &mpc = thermalManager.temp_hotend[0].mpc; BACK_ITEM(drawAdvancedSettingsMenu); #if ENABLED(MPC_AUTOTUNE_MENU) - MENU_ITEM(ICON_MPCNozzle, MSG_MPC_AUTOTUNE, onDrawMenuItem, []{ thermalManager.MPC_autotune(active_extruder, Temperature::MPCTuningType::AUTO); }); + MENU_ITEM(ICON_MPCNozzle, MSG_MPC_AUTOTUNE, onDrawMenuItem, []{ thermalManager.MPC_autotune(motion.extruder, Temperature::MPCTuningType::AUTO); }); #endif #if ENABLED(MPC_EDIT_MENU) EDIT_ITEM(ICON_MPCHeater, MSG_MPC_POWER, onDrawPFloatMenu, setHeaterPower, &mpc.heater_power); @@ -4250,7 +4250,7 @@ void drawMaxAccelMenu() { EDIT_ITEM(ICON_Zoffset, MSG_BABYSTEP_PROBE_Z, onDrawPFloat2Menu, setZOffset, &BABY_Z_VAR); } updateMenu(zOffsetWizMenu); - if (!axis_is_trusted(Z_AXIS)) LCD_MESSAGE_F("WARNING: Z position unknown, move Z to home"); + if (!motion.axis_is_trusted(Z_AXIS)) LCD_MESSAGE_F("WARNING: Z position unknown, move Z to home"); } #endif diff --git a/Marlin/src/lcd/dwin/proui/proui_extui.cpp b/Marlin/src/lcd/dwin/proui/proui_extui.cpp index 9f19d354ad..4aec61f0fb 100644 --- a/Marlin/src/lcd/dwin/proui/proui_extui.cpp +++ b/Marlin/src/lcd/dwin/proui/proui_extui.cpp @@ -107,7 +107,7 @@ namespace ExtUI { void onStatusChanged(const char * const) { dwinCheckStatusMessage(); } #if ENABLED(ADVANCED_PAUSE_FEATURE) - void onPauseMode(const PauseMessage message, const PauseMode mode/*=PAUSE_MODE_SAME*/, const uint8_t extruder/*=active_extruder*/) { + void onPauseMode(const PauseMessage message, const PauseMode mode/*=PAUSE_MODE_SAME*/, const uint8_t extruder/*=motion.extruder*/) { if (mode != PAUSE_MODE_SAME) pause_mode = mode; switch (message) { case PAUSE_MESSAGE_PARKING: dwinPopupPause(GET_TEXT_F(MSG_PAUSE_PRINT_PARKING)); break; // M125 @@ -238,7 +238,7 @@ namespace ExtUI { void onSteppersDisabled() {} void onSteppersEnabled() {} void onAxisDisabled(const axis_t axis) { - set_axis_untrusted((AxisEnum)axis); // MRISCOC workaround: https://github.com/MarlinFirmware/Marlin/issues/23095 + motion.set_axis_untrusted((AxisEnum)axis); // MRISCOC workaround: https://github.com/MarlinFirmware/Marlin/issues/23095 } void onAxisEnabled(const axis_t) {} diff --git a/Marlin/src/lcd/extui/anycubic_chiron/chiron_extui.cpp b/Marlin/src/lcd/extui/anycubic_chiron/chiron_extui.cpp index 966ff905d4..127d454a9a 100644 --- a/Marlin/src/lcd/extui/anycubic_chiron/chiron_extui.cpp +++ b/Marlin/src/lcd/extui/anycubic_chiron/chiron_extui.cpp @@ -81,7 +81,7 @@ namespace ExtUI { void onPauseMode( const PauseMessage message, const PauseMode mode/*=PAUSE_MODE_SAME*/, - const uint8_t extruder/*=active_extruder*/ + const uint8_t extruder/*=motion.extruder*/ ) { stdOnPauseMode(message, mode, extruder); } diff --git a/Marlin/src/lcd/extui/anycubic_i3mega/anycubic_extui.cpp b/Marlin/src/lcd/extui/anycubic_i3mega/anycubic_extui.cpp index 26be48f2ff..022d38fc9e 100644 --- a/Marlin/src/lcd/extui/anycubic_i3mega/anycubic_extui.cpp +++ b/Marlin/src/lcd/extui/anycubic_i3mega/anycubic_extui.cpp @@ -69,7 +69,7 @@ namespace ExtUI { void onPauseMode( const PauseMessage message, const PauseMode mode/*=PAUSE_MODE_SAME*/, - const uint8_t extruder/*=active_extruder*/ + const uint8_t extruder/*=motion.extruder*/ ) { stdOnPauseMode(message, mode, extruder); } diff --git a/Marlin/src/lcd/extui/anycubic_i3mega/anycubic_i3mega_lcd.cpp b/Marlin/src/lcd/extui/anycubic_i3mega/anycubic_i3mega_lcd.cpp index bc212bf42c..fb8f8dcd01 100644 --- a/Marlin/src/lcd/extui/anycubic_i3mega/anycubic_i3mega_lcd.cpp +++ b/Marlin/src/lcd/extui/anycubic_i3mega/anycubic_i3mega_lcd.cpp @@ -710,7 +710,7 @@ void AnycubicTFT::getCommandFromTFT() { case 19: // A19 stop stepper drivers - sent on stop extrude command and on turn motors off command if (!isPrinting()) { - quickstop_stepper(); + motion.quickstop_stepper(); stepper.disable_all_steppers(); } @@ -719,9 +719,9 @@ void AnycubicTFT::getCommandFromTFT() { case 20: // A20 read printing speed if (codeSeen('S')) - feedrate_percentage = constrain(codeValue(), 40, 999); + motion.feedrate_percentage = constrain(codeValue(), 40, 999); else - SEND_PGM_VAL("A20V ", feedrate_percentage); + SEND_PGM_VAL("A20V ", motion.feedrate_percentage); break; case 21: // A21 all home diff --git a/Marlin/src/lcd/extui/anycubic_vyper/dgus_tft.cpp b/Marlin/src/lcd/extui/anycubic_vyper/dgus_tft.cpp index 5678cb3d3f..5d6be5a20a 100644 --- a/Marlin/src/lcd/extui/anycubic_vyper/dgus_tft.cpp +++ b/Marlin/src/lcd/extui/anycubic_vyper/dgus_tft.cpp @@ -1047,7 +1047,7 @@ namespace Anycubic { else if (control_index == TXT_PRINT_SPEED_TARGET || control_index == TXT_ADJUST_SPEED) { // print speed control_value = (uint16_t(data_buf[4]) << 8) | uint16_t(data_buf[5]); const uint16_t feedrate = constrain(uint16_t(control_value), 40, 999); - //feedrate_percentage=constrain(control_value,40,999); + //motion.feedrate_percentage = constrain(control_value, 40, 999); sendTxtToTFT(MString<6>(feedrate), TXT_PRINT_SPEED); sendValueToTFT(feedrate, TXT_PRINT_SPEED_NOW); sendValueToTFT(feedrate, TXT_PRINT_SPEED_TARGET); diff --git a/Marlin/src/lcd/extui/anycubic_vyper/vyper_extui.cpp b/Marlin/src/lcd/extui/anycubic_vyper/vyper_extui.cpp index 5342991320..5983916d45 100644 --- a/Marlin/src/lcd/extui/anycubic_vyper/vyper_extui.cpp +++ b/Marlin/src/lcd/extui/anycubic_vyper/vyper_extui.cpp @@ -81,7 +81,7 @@ namespace ExtUI { void onPauseMode( const PauseMessage message, const PauseMode mode/*=PAUSE_MODE_SAME*/, - const uint8_t extruder/*=active_extruder*/ + const uint8_t extruder/*=motion.extruder*/ ) { stdOnPauseMode(message, mode, extruder); } diff --git a/Marlin/src/lcd/extui/dgus/dgus_extui.cpp b/Marlin/src/lcd/extui/dgus/dgus_extui.cpp index 59a4599df6..76253afb47 100644 --- a/Marlin/src/lcd/extui/dgus/dgus_extui.cpp +++ b/Marlin/src/lcd/extui/dgus/dgus_extui.cpp @@ -95,7 +95,7 @@ namespace ExtUI { void onPauseMode( const PauseMessage message, const PauseMode mode/*=PAUSE_MODE_SAME*/, - const uint8_t extruder/*=active_extruder*/ + const uint8_t extruder/*=motion.extruder*/ ) { stdOnPauseMode(message, mode, extruder); } diff --git a/Marlin/src/lcd/extui/dgus/fysetc/DGUSDisplayDef.cpp b/Marlin/src/lcd/extui/dgus/fysetc/DGUSDisplayDef.cpp index 9ec98779c8..948828014c 100644 --- a/Marlin/src/lcd/extui/dgus/fysetc/DGUSDisplayDef.cpp +++ b/Marlin/src/lcd/extui/dgus/fysetc/DGUSDisplayDef.cpp @@ -362,7 +362,7 @@ const struct DGUS_VP_Variable ListOfVP[] PROGMEM = { VPHELPER(VP_T_E0_Is, &thermalManager.temp_hotend[0].celsius, nullptr, screen.sendFloatAsLongValueToDisplay<0>), VPHELPER(VP_T_E0_Set, &thermalManager.temp_hotend[0].target, screen.handleTemperatureChanged, screen.sendWordValueToDisplay), VPHELPER(VP_Flowrate_E0, &planner.flow_percentage[0], screen.handleFlowRateChanged, screen.sendWordValueToDisplay), - VPHELPER(VP_EPos, &destination.e, nullptr, screen.sendFloatAsLongValueToDisplay<2>), + VPHELPER(VP_EPos, &motion.destination.e, nullptr, screen.sendFloatAsLongValueToDisplay<2>), VPHELPER(VP_MOVE_E0, nullptr, screen.handleManualExtrude, nullptr), VPHELPER(VP_E0_CONTROL, &thermalManager.temp_hotend[0].target, screen.handleHeaterControl, nullptr), VPHELPER(VP_E0_STATUS, &thermalManager.temp_hotend[0].target, nullptr, screen.sendHeaterStatusToDisplay), @@ -421,12 +421,12 @@ const struct DGUS_VP_Variable ListOfVP[] PROGMEM = { #endif // Feedrate - VPHELPER(VP_Feedrate_Percentage, &feedrate_percentage, screen.setValueDirectly, screen.sendWordValueToDisplay), + VPHELPER(VP_Feedrate_Percentage, &motion.feedrate_percentage, screen.setValueDirectly, screen.sendWordValueToDisplay), // Position Data - VPHELPER(VP_XPos, ¤t_position.x, nullptr, screen.sendFloatAsLongValueToDisplay<2>), - VPHELPER(VP_YPos, ¤t_position.y, nullptr, screen.sendFloatAsLongValueToDisplay<2>), - VPHELPER(VP_ZPos, ¤t_position.z, nullptr, screen.sendFloatAsLongValueToDisplay<2>), + VPHELPER(VP_XPos, &motion.position.x, nullptr, screen.sendFloatAsLongValueToDisplay<2>), + VPHELPER(VP_YPos, &motion.position.y, nullptr, screen.sendFloatAsLongValueToDisplay<2>), + VPHELPER(VP_ZPos, &motion.position.z, nullptr, screen.sendFloatAsLongValueToDisplay<2>), // Print Progress VPHELPER(VP_PrintProgress_Percentage, nullptr, nullptr, screen.sendPrintProgressToDisplay), diff --git a/Marlin/src/lcd/extui/dgus/fysetc/DGUSScreenHandler.cpp b/Marlin/src/lcd/extui/dgus/fysetc/DGUSScreenHandler.cpp index 2cf8193c74..2bbc2414e2 100644 --- a/Marlin/src/lcd/extui/dgus/fysetc/DGUSScreenHandler.cpp +++ b/Marlin/src/lcd/extui/dgus/fysetc/DGUSScreenHandler.cpp @@ -199,10 +199,10 @@ void DGUSScreenHandler::handleManualMove(DGUS_VP_Variable &var, void *val_ptr) { } else { // movement - bool old_relative_mode = relative_mode; - if (!relative_mode) queue.enqueue_now(F("G91")); + const bool old_relative_mode = motion.relative_mode; + if (!old_relative_mode) queue.enqueue_now(F("G91")); char buf[32]; // G1 X9999.99 F12345 - const uint16_t backup_speed = MMS_TO_MMM(feedrate_mm_s); + const uint16_t backup_speed = MMS_TO_MMM(motion.feedrate_mm_s); char sign[] = "\0"; int16_t value = movevalue / 100; if (movevalue < 0) { value *= -1; sign[0] = '-'; } diff --git a/Marlin/src/lcd/extui/dgus/hiprecy/DGUSDisplayDef.cpp b/Marlin/src/lcd/extui/dgus/hiprecy/DGUSDisplayDef.cpp index db0ebbc903..6d8ad3a95d 100644 --- a/Marlin/src/lcd/extui/dgus/hiprecy/DGUSDisplayDef.cpp +++ b/Marlin/src/lcd/extui/dgus/hiprecy/DGUSDisplayDef.cpp @@ -359,7 +359,7 @@ const struct DGUS_VP_Variable ListOfVP[] PROGMEM = { VPHELPER(VP_T_E0_Is, &thermalManager.temp_hotend[0].celsius, nullptr, screen.sendFloatAsLongValueToDisplay<0>), VPHELPER(VP_T_E0_Set, &thermalManager.temp_hotend[0].target, screen.handleTemperatureChanged, screen.sendWordValueToDisplay), VPHELPER(VP_Flowrate_E0, &planner.flow_percentage[0], screen.handleFlowRateChanged, screen.sendWordValueToDisplay), - VPHELPER(VP_EPos, &destination.e, nullptr, screen.sendFloatAsLongValueToDisplay<2>), + VPHELPER(VP_EPos, &motion.destination.e, nullptr, screen.sendFloatAsLongValueToDisplay<2>), VPHELPER(VP_MOVE_E0, nullptr, screen.handleManualExtrude, nullptr), VPHELPER(VP_E0_CONTROL, &thermalManager.temp_hotend[0].target, screen.handleHeaterControl, nullptr), VPHELPER(VP_E0_STATUS, &thermalManager.temp_hotend[0].target, nullptr, screen.sendHeaterStatusToDisplay), @@ -414,12 +414,12 @@ const struct DGUS_VP_Variable ListOfVP[] PROGMEM = { #endif // Feedrate - VPHELPER(VP_Feedrate_Percentage, &feedrate_percentage, screen.setValueDirectly, screen.sendWordValueToDisplay), + VPHELPER(VP_Feedrate_Percentage, &motion.feedrate_percentage, screen.setValueDirectly, screen.sendWordValueToDisplay), // Position Data - VPHELPER(VP_XPos, ¤t_position.x, nullptr, screen.sendFloatAsLongValueToDisplay<2>), - VPHELPER(VP_YPos, ¤t_position.y, nullptr, screen.sendFloatAsLongValueToDisplay<2>), - VPHELPER(VP_ZPos, ¤t_position.z, nullptr, screen.sendFloatAsLongValueToDisplay<2>), + VPHELPER(VP_XPos, &motion.position.x, nullptr, screen.sendFloatAsLongValueToDisplay<2>), + VPHELPER(VP_YPos, &motion.position.y, nullptr, screen.sendFloatAsLongValueToDisplay<2>), + VPHELPER(VP_ZPos, &motion.position.z, nullptr, screen.sendFloatAsLongValueToDisplay<2>), // Print Progress VPHELPER(VP_PrintProgress_Percentage, nullptr, nullptr, screen.sendPrintProgressToDisplay), diff --git a/Marlin/src/lcd/extui/dgus/hiprecy/DGUSScreenHandler.cpp b/Marlin/src/lcd/extui/dgus/hiprecy/DGUSScreenHandler.cpp index f718ee16af..03de8b268d 100644 --- a/Marlin/src/lcd/extui/dgus/hiprecy/DGUSScreenHandler.cpp +++ b/Marlin/src/lcd/extui/dgus/hiprecy/DGUSScreenHandler.cpp @@ -201,10 +201,10 @@ void DGUSScreenHandler::handleManualMove(DGUS_VP_Variable &var, void *val_ptr) { } else { // movement - const bool old_relative_mode = relative_mode; - if (!relative_mode) queue.enqueue_now(F("G91")); + const bool old_relative_mode = motion.relative_mode; + if (!old_relative_mode) queue.enqueue_now(F("G91")); char buf[32]; // G1 X9999.99 F12345 - const uint16_t backup_speed = MMS_TO_MMM(feedrate_mm_s); + const uint16_t backup_speed = MMS_TO_MMM(motion.feedrate_mm_s); char sign[] = "\0"; int16_t value = movevalue / 100; if (movevalue < 0) { value *= -1; sign[0] = '-'; } diff --git a/Marlin/src/lcd/extui/dgus/mks/DGUSDisplayDef.cpp b/Marlin/src/lcd/extui/dgus/mks/DGUSDisplayDef.cpp index b108dab0a0..e2f43efa21 100644 --- a/Marlin/src/lcd/extui/dgus/mks/DGUSDisplayDef.cpp +++ b/Marlin/src/lcd/extui/dgus/mks/DGUSDisplayDef.cpp @@ -81,23 +81,23 @@ constexpr feedRate_t park_speed_xy = TERN(NOZZLE_PARK_FEATURE, NOZZLE_PARK_XY_FE void MKS_pause_print_move() { queue.exhaust(); - position_before_pause = current_position; + position_before_pause = motion.position; // Save the current position, the raise amount, and 'already raised' TERN_(POWER_LOSS_RECOVERY, if (recovery.enabled) recovery.save(true, mks_park_pos.z, true)); - destination.z = _MIN(current_position.z + mks_park_pos.z, Z_MAX_POS); - prepare_internal_move_to_destination(park_speed_z); + motion.destination.z = _MIN(motion.position.z + mks_park_pos.z, Z_MAX_POS); + motion.prepare_internal_move_to_destination(park_speed_z); - destination.set(X_MIN_POS + mks_park_pos.x, Y_MIN_POS + mks_park_pos.y); - prepare_internal_move_to_destination(park_speed_xy); + motion.destination.set(X_MIN_POS + mks_park_pos.x, Y_MIN_POS + mks_park_pos.y); + motion.prepare_internal_move_to_destination(park_speed_xy); } void MKS_resume_print_move() { - destination.set(position_before_pause.x, position_before_pause.y); - prepare_internal_move_to_destination(park_speed_xy); - destination.z = position_before_pause.z; - prepare_internal_move_to_destination(park_speed_z); + motion.destination.set(position_before_pause.x, position_before_pause.y); + motion.prepare_internal_move_to_destination(park_speed_xy); + motion.destination.z = position_before_pause.z; + motion.prepare_internal_move_to_destination(park_speed_z); TERN_(POWER_LOSS_RECOVERY, if (recovery.enabled) recovery.save(true)); } @@ -471,7 +471,7 @@ const struct DGUS_VP_Variable ListOfVP[] PROGMEM = { VPHELPER(VP_T_E0_Is, &thermalManager.temp_hotend[0].celsius, nullptr, screen.sendFloatAsLongValueToDisplay<0>), VPHELPER(VP_T_E0_Set, &thermalManager.temp_hotend[0].target, screen.handleTemperatureChanged, screen.sendWordValueToDisplay), VPHELPER(VP_Flowrate_E0, &planner.flow_percentage[0], screen.handleFlowRateChanged, screen.sendWordValueToDisplay), - VPHELPER(VP_EPos, &destination.e, nullptr, screen.sendFloatAsLongValueToDisplay<2>), + VPHELPER(VP_EPos, &motion.destination.e, nullptr, screen.sendFloatAsLongValueToDisplay<2>), VPHELPER(VP_MOVE_E0, nullptr, screen.handleManualExtrude, nullptr), VPHELPER(VP_E0_CONTROL, &thermalManager.temp_hotend[0].target, screen.handleHeaterControl, nullptr), VPHELPER(VP_E0_STATUS, &thermalManager.temp_hotend[0].target, nullptr, screen.sendHeaterStatusToDisplay), @@ -542,12 +542,12 @@ const struct DGUS_VP_Variable ListOfVP[] PROGMEM = { #endif // Feedrate - VPHELPER(VP_Feedrate_Percentage, &feedrate_percentage, screen.setValueDirectly, screen.sendWordValueToDisplay), + VPHELPER(VP_Feedrate_Percentage, &motion.feedrate_percentage, screen.setValueDirectly, screen.sendWordValueToDisplay), // Position Data - VPHELPER(VP_XPos, ¤t_position.x, nullptr, screen.sendFloatAsLongValueToDisplay<2>), - VPHELPER(VP_YPos, ¤t_position.y, nullptr, screen.sendFloatAsLongValueToDisplay<2>), - VPHELPER(VP_ZPos, ¤t_position.z, nullptr, screen.sendFloatAsLongValueToDisplay<2>), + VPHELPER(VP_XPos, &motion.position.x, nullptr, screen.sendFloatAsLongValueToDisplay<2>), + VPHELPER(VP_YPos, &motion.position.y, nullptr, screen.sendFloatAsLongValueToDisplay<2>), + VPHELPER(VP_ZPos, &motion.position.z, nullptr, screen.sendFloatAsLongValueToDisplay<2>), // Level Point Set VPHELPER(VP_Level_Point_One_X, &mks_corner_offsets[0].x, screen.handleChangeLevelPoint, screen.sendWordValueToDisplay), diff --git a/Marlin/src/lcd/extui/dgus/mks/DGUSScreenHandler.cpp b/Marlin/src/lcd/extui/dgus/mks/DGUSScreenHandler.cpp index bd774f7523..7f43acf4f6 100644 --- a/Marlin/src/lcd/extui/dgus/mks/DGUSScreenHandler.cpp +++ b/Marlin/src/lcd/extui/dgus/mks/DGUSScreenHandler.cpp @@ -94,7 +94,7 @@ void DGUSScreenHandlerMKS::sendFanToDisplay(DGUS_VP_Variable &var) { } void DGUSScreenHandlerMKS::sendBabyStepToDisplay(DGUS_VP_Variable &var) { - float value = current_position.z; + float value = motion.position.z; value *= 100; //cpow(10, 2); dgus.writeVariable(VP_SD_Print_Baby, (uint16_t)value); } @@ -449,7 +449,7 @@ void DGUSScreenHandlerMKS::levelControl(DGUS_VP_Variable &var, void *val_ptr) { break; case 1: - soft_endstop._enabled = true; + motion.soft_endstop._enabled = true; gotoScreen(MKSLCD_SCREEM_TOOL); break; @@ -480,7 +480,7 @@ void DGUSScreenHandlerMKS::meshLevel(DGUS_VP_Variable &var, void *val_ptr) { integer = offset; // get int Deci = (offset * 10) % 10; Deci2 = (offset * 100) % 10; - soft_endstop._enabled = false; + motion.soft_endstop._enabled = false; queue.enqueue_now(F("G91")); snprintf_P(cmd_buf, 30, PSTR("G1 Z%d.%d%d"), integer, Deci, Deci2); queue.enqueue_one_now(cmd_buf); @@ -492,7 +492,7 @@ void DGUSScreenHandlerMKS::meshLevel(DGUS_VP_Variable &var, void *val_ptr) { integer = offset; // get int Deci = (offset * 10) % 10; Deci2 = (offset * 100) % 10; - soft_endstop._enabled = false; + motion.soft_endstop._enabled = false; queue.enqueue_now(F("G91")); snprintf_P(cmd_buf, 30, PSTR("G1 Z-%d.%d%d"), integer, Deci, Deci2); queue.enqueue_one_now(cmd_buf); @@ -549,7 +549,7 @@ void DGUSScreenHandlerMKS::meshLevel(DGUS_VP_Variable &var, void *val_ptr) { } else if (mesh_point_count == 0) { mesh_point_count = GRID_MAX_POINTS; - soft_endstop._enabled = true; + motion.soft_endstop._enabled = true; settings.save(); gotoScreen(MKSLCD_SCREEM_TOOL); } @@ -769,8 +769,8 @@ void DGUSScreenHandler::handleManualMove(DGUS_VP_Variable &var, void *val_ptr) { } // Movement - const bool old_relative_mode = relative_mode; - if (!relative_mode) queue.enqueue_now(F("G91")); + const bool old_relative_mode = motion.relative_mode; + if (!old_relative_mode) queue.enqueue_now(F("G91")); // TODO: Use MString / TS() ... diff --git a/Marlin/src/lcd/extui/dgus/origin/DGUSDisplayDef.cpp b/Marlin/src/lcd/extui/dgus/origin/DGUSDisplayDef.cpp index 2cb7bd6f83..90ed84b01e 100644 --- a/Marlin/src/lcd/extui/dgus/origin/DGUSDisplayDef.cpp +++ b/Marlin/src/lcd/extui/dgus/origin/DGUSDisplayDef.cpp @@ -165,7 +165,7 @@ const struct DGUS_VP_Variable ListOfVP[] PROGMEM = { VPHELPER(VP_T_E0_Is, &thermalManager.temp_hotend[0].celsius, nullptr, screen.sendFloatAsLongValueToDisplay<0>), VPHELPER(VP_T_E0_Set, &thermalManager.temp_hotend[0].target, screen.handleTemperatureChanged, &screen.sendWordValueToDisplay), VPHELPER(VP_Flowrate_E0, nullptr, screen.handleFlowRateChanged, screen.sendWordValueToDisplay), - VPHELPER(VP_EPos, &destination.e, nullptr, screen.sendFloatAsLongValueToDisplay<2>), + VPHELPER(VP_EPos, &motion.destination.e, nullptr, screen.sendFloatAsLongValueToDisplay<2>), VPHELPER(VP_MOVE_E0, nullptr, screen.handleManualExtrude, nullptr), VPHELPER(VP_E0_CONTROL, &thermalManager.temp_hotend[0].target, screen.handleHeaterControl, nullptr), VPHELPER(VP_E0_STATUS, &thermalManager.temp_hotend[0].target, nullptr, screen.sendHeaterStatusToDisplay), @@ -222,12 +222,12 @@ const struct DGUS_VP_Variable ListOfVP[] PROGMEM = { #endif // Feedrate - VPHELPER(VP_Feedrate_Percentage, &feedrate_percentage, screen.setValueDirectly, screen.sendWordValueToDisplay), + VPHELPER(VP_Feedrate_Percentage, &motion.feedrate_percentage, screen.setValueDirectly, screen.sendWordValueToDisplay), // Position Data - VPHELPER(VP_XPos, ¤t_position.x, nullptr, screen.sendFloatAsLongValueToDisplay<2>), - VPHELPER(VP_YPos, ¤t_position.y, nullptr, screen.sendFloatAsLongValueToDisplay<2>), - VPHELPER(VP_ZPos, ¤t_position.z, nullptr, screen.sendFloatAsLongValueToDisplay<2>), + VPHELPER(VP_XPos, &motion.position.x, nullptr, screen.sendFloatAsLongValueToDisplay<2>), + VPHELPER(VP_YPos, &motion.position.y, nullptr, screen.sendFloatAsLongValueToDisplay<2>), + VPHELPER(VP_ZPos, &motion.position.z, nullptr, screen.sendFloatAsLongValueToDisplay<2>), // Print Progress VPHELPER(VP_PrintProgress_Percentage, nullptr, nullptr, screen.sendPrintProgressToDisplay), diff --git a/Marlin/src/lcd/extui/dgus/origin/DGUSScreenHandler.cpp b/Marlin/src/lcd/extui/dgus/origin/DGUSScreenHandler.cpp index f577047e3a..7f52f959f1 100644 --- a/Marlin/src/lcd/extui/dgus/origin/DGUSScreenHandler.cpp +++ b/Marlin/src/lcd/extui/dgus/origin/DGUSScreenHandler.cpp @@ -201,10 +201,10 @@ void DGUSScreenHandler::handleManualMove(DGUS_VP_Variable &var, void *val_ptr) { } else { // movement - const bool old_relative_mode = relative_mode; - if (!relative_mode) queue.enqueue_now(F("G91")); + const bool old_relative_mode = motion.relative_mode; + if (!old_relative_mode) queue.enqueue_now(F("G91")); char buf[32]; // G1 X9999.99 F12345 - const uint16_t backup_speed = MMS_TO_MMM(feedrate_mm_s); + const uint16_t backup_speed = MMS_TO_MMM(motion.feedrate_mm_s); char sign[] = "\0"; int16_t value = movevalue / 100; if (movevalue < 0) { value *= -1; sign[0] = '-'; } diff --git a/Marlin/src/lcd/extui/dgus_e3s1pro/dgus_e3s1pro_extui.cpp b/Marlin/src/lcd/extui/dgus_e3s1pro/dgus_e3s1pro_extui.cpp index 07b7e9e94c..135f4d844a 100644 --- a/Marlin/src/lcd/extui/dgus_e3s1pro/dgus_e3s1pro_extui.cpp +++ b/Marlin/src/lcd/extui/dgus_e3s1pro/dgus_e3s1pro_extui.cpp @@ -99,7 +99,7 @@ namespace ExtUI { void onPauseMode( const PauseMessage message, const PauseMode mode/*=PAUSE_MODE_SAME*/, - const uint8_t extruder/*=active_extruder*/ + const uint8_t extruder/*=motion.extruder*/ ) { stdOnPauseMode(message, mode, extruder); } diff --git a/Marlin/src/lcd/extui/dgus_reloaded/definition/DGUS_VPList.cpp b/Marlin/src/lcd/extui/dgus_reloaded/definition/DGUS_VPList.cpp index 172cf98fe6..68a48e47f4 100644 --- a/Marlin/src/lcd/extui/dgus_reloaded/definition/DGUS_VPList.cpp +++ b/Marlin/src/lcd/extui/dgus_reloaded/definition/DGUS_VPList.cpp @@ -188,7 +188,7 @@ const struct DGUS_VP vp_list[] PROGMEM = { VP_HELPER_TX(DGUS_Addr::STATUS_Icons, &DGUSTxHandler::statusIcons), VP_HELPER_TX_AUTO(DGUS_Addr::ADJUST_Feedrate, - &feedrate_percentage, + &motion.feedrate_percentage, &DGUSTxHandler::extraToInteger), VP_HELPER_TX_AUTO(DGUS_Addr::ADJUST_Flowrate_CUR, nullptr, @@ -255,13 +255,13 @@ const struct DGUS_VP vp_list[] PROGMEM = { &DGUSTxHandler::extraToInteger), VP_HELPER_TX_AUTO(DGUS_Addr::MOVE_CurrentX, - ¤t_position.x, + &motion.position.x, (&DGUSTxHandler::extraToFixedPoint)), VP_HELPER_TX_AUTO(DGUS_Addr::MOVE_CurrentY, - ¤t_position.y, + &motion.position.y, (&DGUSTxHandler::extraToFixedPoint)), VP_HELPER_TX_AUTO(DGUS_Addr::MOVE_CurrentZ, - ¤t_position.z, + &motion.position.z, (&DGUSTxHandler::extraToFixedPoint)), VP_HELPER_TX_EXTRA(DGUS_Addr::MOVE_StepIcons, &DGUSScreenHandler::move_steps, diff --git a/Marlin/src/lcd/extui/dgus_reloaded/dgus_reloaded_extui.cpp b/Marlin/src/lcd/extui/dgus_reloaded/dgus_reloaded_extui.cpp index 2b7afa76d4..d969e58c84 100644 --- a/Marlin/src/lcd/extui/dgus_reloaded/dgus_reloaded_extui.cpp +++ b/Marlin/src/lcd/extui/dgus_reloaded/dgus_reloaded_extui.cpp @@ -94,7 +94,7 @@ namespace ExtUI { void onPauseMode( const PauseMessage message, const PauseMode mode/*=PAUSE_MODE_SAME*/, - const uint8_t extruder/*=active_extruder*/ + const uint8_t extruder/*=motion.extruder*/ ) { stdOnPauseMode(message, mode, extruder); } diff --git a/Marlin/src/lcd/extui/example/example.cpp b/Marlin/src/lcd/extui/example/example.cpp index 177ce156d5..4057609fc4 100644 --- a/Marlin/src/lcd/extui/example/example.cpp +++ b/Marlin/src/lcd/extui/example/example.cpp @@ -74,7 +74,7 @@ namespace ExtUI { void onPauseMode( const PauseMessage message, const PauseMode mode/*=PAUSE_MODE_SAME*/, - const uint8_t extruder/*=active_extruder*/ + const uint8_t extruder/*=motion.extruder*/ ) { stdOnPauseMode(message, mode, extruder); } diff --git a/Marlin/src/lcd/extui/ftdi_eve_touch_ui/cocoa_press/load_chocolate.cpp b/Marlin/src/lcd/extui/ftdi_eve_touch_ui/cocoa_press/load_chocolate.cpp index 03d47cf73a..9ad6c02f79 100644 --- a/Marlin/src/lcd/extui/ftdi_eve_touch_ui/cocoa_press/load_chocolate.cpp +++ b/Marlin/src/lcd/extui/ftdi_eve_touch_ui/cocoa_press/load_chocolate.cpp @@ -129,12 +129,12 @@ bool LoadChocolateScreen::onTouchEnd(uint8_t tag) { return true; } -void LoadChocolateScreen::setManualFeedrateAndIncrement(float feedrate_mm_s, float &increment_mm) { +void LoadChocolateScreen::setManualFeedrateAndIncrement(float fr_mm_s, float &increment_mm) { // Compute increment so feedrate so that the tool lags the adjuster when it is // being held down, this allows enough margin for the planner to // connect segments and even out the motion. - ExtUI::setFeedrate_mm_s(feedrate_mm_s); - increment_mm = feedrate_mm_s / ((TOUCH_REPEATS_PER_SECOND) * 0.80f); + ExtUI::setFeedrate_mm_s(fr_mm_s); + increment_mm = fr_mm_s / ((TOUCH_REPEATS_PER_SECOND) * 0.80f); } bool LoadChocolateScreen::onTouchHeld(uint8_t tag) { diff --git a/Marlin/src/lcd/extui/ftdi_eve_touch_ui/cocoa_press/load_chocolate.h b/Marlin/src/lcd/extui/ftdi_eve_touch_ui/cocoa_press/load_chocolate.h index 426669775d..dbdfd3f409 100644 --- a/Marlin/src/lcd/extui/ftdi_eve_touch_ui/cocoa_press/load_chocolate.h +++ b/Marlin/src/lcd/extui/ftdi_eve_touch_ui/cocoa_press/load_chocolate.h @@ -37,7 +37,7 @@ class LoadChocolateScreen : public BaseScreen, public CachedScreenmks_obj_id) { case ID_C_ADD: if (!editingFlowrate) - feedrate_percentage = _MIN(MAX_EXT_SPEED_PERCENT, feedrate_percentage + uiCfg.stepPrintSpeed); + motion.feedrate_percentage = _MIN(MAX_EXT_SPEED_PERCENT, motion.feedrate_percentage + uiCfg.stepPrintSpeed); else { const int16_t new_flow = _MIN(MAX_EXT_SPEED_PERCENT, planner.flow_percentage[0] + uiCfg.stepPrintSpeed); planner.set_flow(0, new_flow); @@ -62,7 +62,7 @@ static void event_handler(lv_obj_t *obj, lv_event_t event) { break; case ID_C_DEC: if (!editingFlowrate) - feedrate_percentage = _MAX(MIN_EXT_SPEED_PERCENT, feedrate_percentage - uiCfg.stepPrintSpeed); + motion.feedrate_percentage = _MAX(MIN_EXT_SPEED_PERCENT, motion.feedrate_percentage - uiCfg.stepPrintSpeed); else { const int16_t new_flow = _MAX(MIN_EXT_SPEED_PERCENT, planner.flow_percentage[0] - uiCfg.stepPrintSpeed); planner.set_flow(0, new_flow); @@ -165,7 +165,7 @@ void disp_print_speed() { } else { lbl = speed_menu.move_speed; - val = feedrate_percentage; + val = motion.feedrate_percentage; } strcpy(public_buf_l, lbl); strcat_P(public_buf_l, PSTR(": ")); diff --git a/Marlin/src/lcd/extui/mks_ui/draw_dialog.cpp b/Marlin/src/lcd/extui/mks_ui/draw_dialog.cpp index 596c78c6aa..372cffd399 100644 --- a/Marlin/src/lcd/extui/mks_ui/draw_dialog.cpp +++ b/Marlin/src/lcd/extui/mks_ui/draw_dialog.cpp @@ -101,7 +101,7 @@ static void btn_ok_event_cb(lv_obj_t *btn, lv_event_t event) { } card.openFileRead(cur_name); if (card.isFileOpen()) { - feedrate_percentage = 100; + motion.feedrate_percentage = 100; TERN_(HAS_EXTRUDERS, planner.set_flow(0, 100)); E_TERN_(planner.set_flow(1, 100)); card.startOrResumeFilePrinting(); diff --git a/Marlin/src/lcd/extui/mks_ui/draw_filament_change.cpp b/Marlin/src/lcd/extui/mks_ui/draw_filament_change.cpp index 26ed471a3a..4ed2363a78 100644 --- a/Marlin/src/lcd/extui/mks_ui/draw_filament_change.cpp +++ b/Marlin/src/lcd/extui/mks_ui/draw_filament_change.cpp @@ -96,9 +96,9 @@ static void event_handler(lv_obj_t *obj, lv_event_t event) { if (uiCfg.print_state != IDLE && uiCfg.print_state != REPRINTED) gcode.process_subcommands_now(uiCfg.extruderIndexBak == 1 ? F("T1") : F("T0")); #endif - feedrate_mm_s = (float)uiCfg.moveSpeed_bak; + motion.feedrate_mm_s = (float)uiCfg.moveSpeed_bak; if (uiCfg.print_state == PAUSED) - planner.set_e_position_mm((destination.e = current_position.e = uiCfg.current_e_position_bak)); + planner.set_e_position_mm((motion.destination.e = motion.position.e = uiCfg.current_e_position_bak)); thermalManager.setTargetHotend(uiCfg.hotendTargetTempBak, uiCfg.extruderIndex); goto_previous_ui(); diff --git a/Marlin/src/lcd/extui/mks_ui/draw_move_motor.cpp b/Marlin/src/lcd/extui/mks_ui/draw_move_motor.cpp index 84959c15a1..557910f782 100644 --- a/Marlin/src/lcd/extui/mks_ui/draw_move_motor.cpp +++ b/Marlin/src/lcd/extui/mks_ui/draw_move_motor.cpp @@ -89,9 +89,9 @@ static void event_handler(lv_obj_t *obj, lv_event_t event) { void refresh_pos(lv_task_t *) { switch (cur_label) { - case 'X': cur_pos = current_position.x; break; - case 'Y': cur_pos = current_position.y; break; - case 'Z': cur_pos = current_position.z; break; + case 'X': cur_pos = motion.position.x; break; + case 'Y': cur_pos = motion.position.y; break; + case 'Z': cur_pos = motion.position.z; break; default: return; } disp_cur_pos(); diff --git a/Marlin/src/lcd/extui/mks_ui/draw_operation.cpp b/Marlin/src/lcd/extui/mks_ui/draw_operation.cpp index 14b655e09c..6952e80f8d 100644 --- a/Marlin/src/lcd/extui/mks_ui/draw_operation.cpp +++ b/Marlin/src/lcd/extui/mks_ui/draw_operation.cpp @@ -67,7 +67,7 @@ static void event_handler(lv_obj_t *obj, lv_event_t event) { break; case ID_O_FILAMENT: #if HAS_MULTI_EXTRUDER - uiCfg.extruderIndexBak = active_extruder; + uiCfg.extruderIndexBak = motion.extruder; #endif if (uiCfg.print_state == WORKING) { #if HAS_MEDIA @@ -76,8 +76,8 @@ static void event_handler(lv_obj_t *obj, lv_event_t event) { uiCfg.print_state = PAUSING; #endif } - uiCfg.moveSpeed_bak = (uint16_t)feedrate_mm_s; - uiCfg.hotendTargetTempBak = thermalManager.degTargetHotend(active_extruder); + uiCfg.moveSpeed_bak = (uint16_t)motion.feedrate_mm_s; + uiCfg.hotendTargetTempBak = thermalManager.degTargetHotend(motion.extruder); lv_clear_operation(); lv_draw_filament_change(); break; diff --git a/Marlin/src/lcd/extui/mks_ui/draw_printing.cpp b/Marlin/src/lcd/extui/mks_ui/draw_printing.cpp index 5c13eeaa01..d13c040dbc 100644 --- a/Marlin/src/lcd/extui/mks_ui/draw_printing.cpp +++ b/Marlin/src/lcd/extui/mks_ui/draw_printing.cpp @@ -254,7 +254,7 @@ void disp_print_time() { } void disp_fan_Zpos() { - dtostrf(current_position.z, 1, 3, public_buf_l); + dtostrf(motion.position.z, 1, 3, public_buf_l); lv_label_set_text(labelZpos, public_buf_l); } diff --git a/Marlin/src/lcd/extui/mks_ui/draw_ui.cpp b/Marlin/src/lcd/extui/mks_ui/draw_ui.cpp index b3ae273a48..e9ed1078c4 100644 --- a/Marlin/src/lcd/extui/mks_ui/draw_ui.cpp +++ b/Marlin/src/lcd/extui/mks_ui/draw_ui.cpp @@ -649,7 +649,7 @@ char *creat_title_text() { card.openFileRead(cur_name); if (card.isFileOpen()) { - feedrate_percentage = 100; + motion.feedrate_percentage = 100; TERN_(HAS_EXTRUDERS, planner.set_flow(0, 100)); E_TERN_(planner.set_flow(1, 100)); card.startOrResumeFilePrinting(); diff --git a/Marlin/src/lcd/extui/mks_ui/draw_z_offset_wizard.cpp b/Marlin/src/lcd/extui/mks_ui/draw_z_offset_wizard.cpp index 7f4f12b930..6ca78aab20 100644 --- a/Marlin/src/lcd/extui/mks_ui/draw_z_offset_wizard.cpp +++ b/Marlin/src/lcd/extui/mks_ui/draw_z_offset_wizard.cpp @@ -82,7 +82,7 @@ static void event_handler(lv_obj_t *obj, lv_event_t event) { if (do_inject) { sprintf_P(public_buf_l, PSTR("G91\nG1 %c%s F%d\nG90"), cur_label, dtostrf(dist, 1, 3, str_1), uiCfg.moveSpeed); queue.inject(public_buf_l); - //calculated_z_offset = probe.offset.z + current_position.z - z_offset_ref; + //calculated_z_offset = probe.offset.z + motion.position.z - z_offset_ref; disp_cur_wizard_pos(); } @@ -97,23 +97,23 @@ static void event_handler(lv_obj_t *obj, lv_event_t event) { disp_move_wizard_dist(); break; case ID_M_SAVE: - current_position.z = z_offset_ref; // Set Z to z_offset_ref, as we can expect it is at probe height + motion.position.z = z_offset_ref; // Set Z to z_offset_ref, as we can expect it is at probe height probe.offset.z = calculated_z_offset; - sync_plan_position(); - do_z_post_clearance(); + motion.sync_plan_position(); + motion.do_z_post_clearance(); hal.watchdog_refresh(); draw_return_ui(); return; case ID_M_RETURN: probe.offset.z = z_offset_backup; - SET_SOFT_ENDSTOP_LOOSE(false); + motion.set_soft_endstop_loose(false); TERN_(HAS_LEVELING, set_bed_leveling_enabled(mks_leveling_was_active)); // On cancel the Z position needs correction #if HOMING_Z_WITH_PROBE && defined(PROBE_OFFSET_WIZARD_START_Z) - set_axis_never_homed(Z_AXIS); + motion.set_axis_never_homed(Z_AXIS); queue.inject(F("G28Z")); #else - do_z_post_clearance(); + motion.do_z_post_clearance(); #endif hal.watchdog_refresh(); draw_return_ui(); @@ -125,8 +125,8 @@ static void event_handler(lv_obj_t *obj, lv_event_t event) { void refresh_wizard_pos(lv_task_t *) { switch (cur_label) { case 'Z': - cur_pos = current_position.z; - calculated_z_offset = probe.offset.z + current_position.z - z_offset_ref; + cur_pos = motion.position.z; + calculated_z_offset = probe.offset.z + motion.position.z - z_offset_ref; cur_OffsetPos = calculated_z_offset; break; default: return; @@ -136,7 +136,7 @@ void refresh_wizard_pos(lv_task_t *) { void lv_draw_z_offset_wizard() { - set_all_unhomed(); + motion.set_all_unhomed(); // Store probe.offset.z for Case: Cancel z_offset_backup = probe.offset.z; @@ -154,7 +154,7 @@ void lv_draw_z_offset_wizard() { queue.inject(F("G28")); z_offset_ref = 0; // Set Z Value for Wizard Position to 0 - calculated_z_offset = probe.offset.z + current_position.z - z_offset_ref; + calculated_z_offset = probe.offset.z + motion.position.z - z_offset_ref; cur_OffsetPos = calculated_z_offset; scr = lv_screen_create(Z_OFFSET_WIZARD_UI, machine_menu.LevelingZoffsetTitle); diff --git a/Marlin/src/lcd/extui/mks_ui/printer_operation.cpp b/Marlin/src/lcd/extui/mks_ui/printer_operation.cpp index 9999aa4843..f4d7a5f913 100644 --- a/Marlin/src/lcd/extui/mks_ui/printer_operation.cpp +++ b/Marlin/src/lcd/extui/mks_ui/printer_operation.cpp @@ -61,9 +61,9 @@ void printer_state_polling() { gcode.process_subcommands_now(F("M25")); // save the position - uiCfg.current_x_position_bak = current_position.x; - uiCfg.current_y_position_bak = current_position.y; - uiCfg.current_z_position_bak = current_position.z; + uiCfg.current_x_position_bak = motion.position.x; + uiCfg.current_y_position_bak = motion.position.y; + uiCfg.current_z_position_bak = motion.position.z; if (gCfgItems.pausePosZ != (float)-1) { sprintf_P(public_buf_l, PSTR("G91\nG1 Z%s\nG90"), dtostrf(gCfgItems.pausePosZ, 1, 1, str_1)); @@ -74,7 +74,7 @@ void printer_state_polling() { gcode.process_subcommands_now(public_buf_l); } uiCfg.print_state = PAUSED; - uiCfg.current_e_position_bak = current_position.e; + uiCfg.current_e_position_bak = motion.position.e; gCfgItems.pause_reprint = true; update_spi_flash(); diff --git a/Marlin/src/lcd/extui/mks_ui/wifi_module.cpp b/Marlin/src/lcd/extui/mks_ui/wifi_module.cpp index 8ba81a6f2e..0b7765ea16 100644 --- a/Marlin/src/lcd/extui/mks_ui/wifi_module.cpp +++ b/Marlin/src/lcd/extui/mks_ui/wifi_module.cpp @@ -1069,8 +1069,8 @@ static void wifi_gcode_exec(uint8_t * const cmd_line) { } card.openFileRead(cur_name); if (card.isFileOpen()) { - //saved_feedrate_percentage = feedrate_percentage; - feedrate_percentage = 100; + //saved_feedrate_percentage = motion.feedrate_percentage; + motion.feedrate_percentage = 100; TERN_(HAS_EXTRUDERS, planner.set_flow(0, 100)); E_TERN_(planner.set_flow(1, 100)); card.startOrResumeFilePrinting(); @@ -2099,7 +2099,7 @@ void get_wifi_commands() { // Process critical commands early if (strcmp_P(command, PSTR("M108")) == 0) marlin.end_waiting(); if (strcmp_P(command, PSTR("M112")) == 0) marlin.kill(FPSTR(M112_KILL_STR), nullptr, true); - if (strcmp_P(command, PSTR("M410")) == 0) quickstop_stepper(); + if (strcmp_P(command, PSTR("M410")) == 0) motion.quickstop_stepper(); #endif // Add the command to the queue diff --git a/Marlin/src/lcd/extui/nextion/nextion_extui.cpp b/Marlin/src/lcd/extui/nextion/nextion_extui.cpp index 7beecfecbf..eab0e02cd8 100644 --- a/Marlin/src/lcd/extui/nextion/nextion_extui.cpp +++ b/Marlin/src/lcd/extui/nextion/nextion_extui.cpp @@ -67,7 +67,7 @@ namespace ExtUI { void onPauseMode( const PauseMessage message, const PauseMode mode/*=PAUSE_MODE_SAME*/, - const uint8_t extruder/*=active_extruder*/ + const uint8_t extruder/*=motion.extruder*/ ) { stdOnPauseMode(message, mode, extruder); } diff --git a/Marlin/src/lcd/extui/ui_api.cpp b/Marlin/src/lcd/extui/ui_api.cpp index ded9b80227..d13d6b4d38 100644 --- a/Marlin/src/lcd/extui/ui_api.cpp +++ b/Marlin/src/lcd/extui/ui_api.cpp @@ -189,7 +189,7 @@ namespace ExtUI { // Marlin by GCODE routines, but should remain untouched // during manual jogging, allowing us to reuse the space // for our direction vector. - destination = dir; + motion.destination = dir; flags.jogging = !NEAR_ZERO(dir.x) || !NEAR_ZERO(dir.y) || !NEAR_ZERO(dir.z); } @@ -198,7 +198,7 @@ namespace ExtUI { if (flags.jogging) { #define OUT_OF_RANGE(VALUE) (VALUE < -1.0f || VALUE > 1.0f) - if (OUT_OF_RANGE(destination.x) || OUT_OF_RANGE(destination.y) || OUT_OF_RANGE(destination.z)) { + if (OUT_OF_RANGE(motion.destination.x) || OUT_OF_RANGE(motion.destination.y) || OUT_OF_RANGE(motion.destination.z)) { // If destination on any axis is out of range, it // probably means the UI forgot to stop jogging and // ran GCODE that wrote a position to destination. @@ -206,7 +206,7 @@ namespace ExtUI { flags.jogging = false; return; } - norm_jog = destination; + norm_jog = motion.destination; } } #endif @@ -326,13 +326,13 @@ namespace ExtUI { // High level axis and extruder positions // float getAxisPosition_mm(const axis_t axis) { - return current_position[axis]; + return motion.position[axis]; } float getAxisPosition_mm(const extruder_t extruder) { const extruder_t old_tool = getActiveTool(); setActiveTool(extruder, true); - const float epos = TERN0(JOYSTICK, flags.jogging) ? destination.e : current_position.e; + const float epos = TERN0(JOYSTICK, flags.jogging) ? motion.destination.e : motion.position.e; setActiveTool(old_tool, true); return epos; } @@ -340,26 +340,26 @@ namespace ExtUI { void setAxisPosition_mm(const float position, const axis_t axis, const feedRate_t feedrate/*=0*/) { // Get motion limit from software endstops, if any float min, max; - soft_endstop.get_manual_axis_limits((AxisEnum)axis, min, max); + motion.soft_endstop.get_manual_axis_limits((AxisEnum)axis, min, max); // Delta limits XY based on the current offset from center // This assumes the center is 0,0 #if ENABLED(DELTA) if (axis != Z) { - max = SQRT(FLOAT_SQ(PRINTABLE_RADIUS) - sq(current_position[Y - axis])); // (Y - axis) == the other axis + max = SQRT(FLOAT_SQ(PRINTABLE_RADIUS) - sq(motion.position[Y - axis])); // (Y - axis) == the other axis min = -max; } #endif - current_position[axis] = constrain(position, min, max); - line_to_current_position(feedrate ?: manual_feedrate_mm_s[axis]); + motion.position[axis] = constrain(position, min, max); + motion.goto_current_position(feedrate ?: manual_feedrate_mm_s[axis]); } void setAxisPosition_mm(const float position, const extruder_t extruder, const feedRate_t feedrate/*=0*/) { setActiveTool(extruder, true); - current_position.e = position; - line_to_current_position(feedrate ?: manual_feedrate_mm_s.e); + motion.position.e = position; + motion.goto_current_position(feedrate ?: manual_feedrate_mm_s.e); } // @@ -368,8 +368,8 @@ namespace ExtUI { void setActiveTool(const extruder_t extruder, bool no_move) { #if HAS_MULTI_EXTRUDER const uint8_t e = extruder - E0; - if (e != active_extruder) tool_change(e, no_move); - active_extruder = e; + if (e != motion.extruder) tool_change(e, no_move); + motion.extruder = e; #else UNUSED(extruder); UNUSED(no_move); @@ -384,7 +384,7 @@ namespace ExtUI { } } - extruder_t getActiveTool() { return getTool(active_extruder); } + extruder_t getActiveTool() { return getTool(motion.extruder); } // // Moving axes and extruders @@ -397,9 +397,9 @@ namespace ExtUI { bool canMove(const axis_t axis) { switch (axis) { #if ANY(IS_KINEMATIC, NO_MOTION_BEFORE_HOMING) - OPTCODE(HAS_X_AXIS, case X: return !axis_should_home(X_AXIS)) - OPTCODE(HAS_Y_AXIS, case Y: return !axis_should_home(Y_AXIS)) - OPTCODE(HAS_Z_AXIS, case Z: return !axis_should_home(Z_AXIS)) + OPTCODE(HAS_X_AXIS, case X: return !motion.axis_should_home(X_AXIS)) + OPTCODE(HAS_Y_AXIS, case Y: return !motion.axis_should_home(Y_AXIS)) + OPTCODE(HAS_Z_AXIS, case Z: return !motion.axis_should_home(Z_AXIS)) #else case X: case Y: case Z: return true; #endif @@ -427,8 +427,8 @@ namespace ExtUI { // #if HAS_SOFTWARE_ENDSTOPS - bool getSoftEndstopState() { return soft_endstop._enabled; } - void setSoftEndstopState(const bool value) { soft_endstop._enabled = value; } + bool getSoftEndstopState() { return motion.soft_endstop._enabled; } + void setSoftEndstopState(const bool value) { motion.soft_endstop._enabled = value; } #endif // @@ -700,14 +700,14 @@ namespace ExtUI { #endif #endif - feedRate_t getFeedrate_mm_s() { return feedrate_mm_s; } + feedRate_t getFeedrate_mm_s() { return motion.feedrate_mm_s; } int16_t getFlow_percent(const extruder_t extr) { return planner.flow_percentage[extr]; } feedRate_t getMinFeedrate_mm_s() { return planner.settings.min_feedrate_mm_s; } feedRate_t getMinTravelFeedrate_mm_s() { return planner.settings.min_travel_feedrate_mm_s; } float getPrintingAcceleration_mm_s2() { return planner.settings.acceleration; } float getRetractAcceleration_mm_s2() { return planner.settings.retract_acceleration; } float getTravelAcceleration_mm_s2() { return planner.settings.travel_acceleration; } - void setFeedrate_mm_s(const feedRate_t fr) { feedrate_mm_s = fr; } + void setFeedrate_mm_s(const feedRate_t fr) { motion.feedrate_mm_s = fr; } void setFlow_percent(const int16_t flow, const extruder_t extr) { planner.set_flow(extr, flow); } void setMinFeedrate_mm_s(const feedRate_t fr) { planner.settings.min_feedrate_mm_s = fr; } void setMinTravelFeedrate_mm_s(const feedRate_t fr) { planner.settings.min_travel_feedrate_mm_s = fr; } @@ -752,7 +752,7 @@ namespace ExtUI { #if ENABLED(BABYSTEP_ZPROBE_OFFSET) // Make it so babystepping in Z adjusts the Z probe offset. - if (axis == Z && TERN1(HAS_MULTI_EXTRUDER, (linked_nozzles || active_extruder == 0))) + if (axis == Z && TERN1(HAS_MULTI_EXTRUDER, (linked_nozzles || motion.extruder == 0))) probe.offset.z += mm; #endif @@ -764,7 +764,7 @@ namespace ExtUI { */ if (!linked_nozzles) { HOTEND_LOOP() - if (e != active_extruder) + if (e != motion.extruder) hotend_offset[e][axis] += mm; TERN_(HAS_X_AXIS, normalizeNozzleOffset(X)); @@ -882,21 +882,21 @@ namespace ExtUI { void moveToMeshPoint(const xy_uint8_t &pos, const float z) { #if ANY(MESH_BED_LEVELING, AUTO_BED_LEVELING_UBL) - REMEMBER(fr, feedrate_mm_s); + REMEMBER(fr, motion.feedrate_mm_s); const float x_target = MESH_MIN_X + pos.x * (MESH_X_DIST), y_target = MESH_MIN_Y + pos.y * (MESH_Y_DIST); - if (x_target != current_position.x || y_target != current_position.y) { + if (x_target != motion.position.x || y_target != motion.position.y) { // If moving across bed, raise nozzle to safe height over bed - feedrate_mm_s = z_probe_fast_mm_s; - destination.set(current_position.x, current_position.y, Z_CLEARANCE_BETWEEN_PROBES); - prepare_line_to_destination(); - if (XY_PROBE_FEEDRATE_MM_S) feedrate_mm_s = XY_PROBE_FEEDRATE_MM_S; - destination.set(x_target, y_target); - prepare_line_to_destination(); + motion.feedrate_mm_s = z_probe_fast_mm_s; + motion.destination.set(motion.position.x, motion.position.y, Z_CLEARANCE_BETWEEN_PROBES); + motion.prepare_line_to_destination(); + if (XY_PROBE_FEEDRATE_MM_S) motion.feedrate_mm_s = XY_PROBE_FEEDRATE_MM_S; + motion.destination.set(x_target, y_target); + motion.prepare_line_to_destination(); } - feedrate_mm_s = z_probe_fast_mm_s; - destination.z = z; - prepare_line_to_destination(); + motion.feedrate_mm_s = z_probe_fast_mm_s; + motion.destination.z = z; + motion.prepare_line_to_destination(); #else UNUSED(pos); UNUSED(z); @@ -924,7 +924,7 @@ namespace ExtUI { } #endif - float getFeedrate_percent() { return feedrate_percentage; } + float getFeedrate_percent() { return motion.feedrate_percentage; } #if ENABLED(PIDTEMP) float getPID_Kp(const extruder_t tool) { return thermalManager.temp_hotend[tool].pid.p(); } @@ -959,10 +959,10 @@ namespace ExtUI { bool commandsInQueue() { return (planner.has_blocks_queued() || queue.has_commands_queued()); } - bool isAxisPositionKnown(const axis_t axis) { return axis_is_trusted((AxisEnum)axis); } - bool isAxisPositionKnown(const extruder_t) { return axis_is_trusted(E_AXIS); } - bool isPositionKnown() { return all_axes_trusted(); } - bool isMachineHomed() { return all_axes_homed(); } + bool isAxisPositionKnown(const axis_t axis) { return motion.axis_is_trusted((AxisEnum)axis); } + bool isAxisPositionKnown(const extruder_t) { return motion.axis_is_trusted(E_AXIS); } + bool isPositionKnown() { return motion.all_axes_trusted(); } + bool isMachineHomed() { return motion.all_axes_homed(); } PGM_P getFirmwareName_str() { static PGMSTR(firmware_name, "Marlin " SHORT_BUILD_VERSION); @@ -1016,7 +1016,7 @@ namespace ExtUI { #endif } - void setFeedrate_percent(const float value) { feedrate_percentage = constrain(value, 10, 500); } + void setFeedrate_percent(const float value) { motion.feedrate_percentage = constrain(value, 10, 500); } void coolDown() { thermalManager.cooldown(); } @@ -1034,7 +1034,7 @@ namespace ExtUI { void stdOnPauseMode( const PauseMessage message, const PauseMode mode/*=PAUSE_MODE_SAME*/, - const uint8_t extruder/*=active_extruder*/ + const uint8_t extruder/*=motion.extruder*/ ) { if (mode != PAUSE_MODE_SAME) pause_mode = mode; pauseModeStatus = message; @@ -1191,7 +1191,7 @@ namespace ExtUI { void MarlinUI::pause_show_message( const PauseMessage message, const PauseMode mode/*=PAUSE_MODE_SAME*/, - const uint8_t extruder/*=active_extruder*/ + const uint8_t extruder/*=motion.extruder*/ ) { ExtUI::onPauseMode(message, mode, extruder); } diff --git a/Marlin/src/lcd/extui/ui_api.h b/Marlin/src/lcd/extui/ui_api.h index 134bf62960..f09d90be0c 100644 --- a/Marlin/src/lcd/extui/ui_api.h +++ b/Marlin/src/lcd/extui/ui_api.h @@ -534,8 +534,8 @@ namespace ExtUI { #if ENABLED(ADVANCED_PAUSE_FEATURE) // Standard stdOnPauseMode sets pauseModeStatus and calls onUserConfirmRequired extern PauseMessage pauseModeStatus; - void stdOnPauseMode(const PauseMessage message, const PauseMode mode=PAUSE_MODE_SAME, const uint8_t extruder=active_extruder); - void onPauseMode(const PauseMessage message, const PauseMode mode=PAUSE_MODE_SAME, const uint8_t extruder=active_extruder); + void stdOnPauseMode(const PauseMessage message, const PauseMode mode=PAUSE_MODE_SAME, const uint8_t extruder=motion.extruder); + void onPauseMode(const PauseMessage message, const PauseMode mode=PAUSE_MODE_SAME, const uint8_t extruder=motion.extruder); #endif void onStatusChanged_P(PGM_P const msg); diff --git a/Marlin/src/lcd/marlinui.cpp b/Marlin/src/lcd/marlinui.cpp index 0c5a0b83a7..f475b52efc 100644 --- a/Marlin/src/lcd/marlinui.cpp +++ b/Marlin/src/lcd/marlinui.cpp @@ -171,7 +171,7 @@ constexpr uint8_t epps = ENCODER_PULSES_PER_STEP; return FPSTR((PGM_P)pgm_read_ptr(&preheat_labels[m])); } - void MarlinUI::apply_preheat(const uint8_t m, const uint8_t pmask, const uint8_t e/*=active_extruder*/) { + void MarlinUI::apply_preheat(const uint8_t m, const uint8_t pmask, const uint8_t e/*=motion.extruder*/) { const preheat_t &pre = material_preset[m]; TERN_(HAS_HOTEND, if (TEST(pmask, PT_HOTEND)) thermalManager.setTargetHotend(pre.hotend_temp, e)); TERN_(HAS_HEATED_BED, if (TEST(pmask, PT_BED)) thermalManager.setTargetBed(pre.bed_temp)); @@ -593,7 +593,7 @@ void MarlinUI::init() { else if (!keypad_debounce) { keypad_debounce = 2; - const bool homed = all_axes_homed(); + const bool homed = motion.all_axes_homed(); #if HAS_MARLINUI_MENU @@ -710,7 +710,7 @@ void MarlinUI::init() { #if ENABLED(ULTIPANEL_FEEDMULTIPLY) - const int16_t old_frm = feedrate_percentage; + const int16_t old_frm = motion.feedrate_percentage; int16_t new_frm = old_frm + int16_t(encoderPosition); // Dead zone at 100% feedrate @@ -728,7 +728,7 @@ void MarlinUI::init() { LIMIT(new_frm, SPEED_EDIT_MIN, SPEED_EDIT_MAX); if (old_frm != new_frm) { - feedrate_percentage = new_frm; + motion.feedrate_percentage = new_frm; encoderPosition = 0; #if ALL(HAS_SOUND, BEEP_ON_FEEDRATE_CHANGE) static millis_t next_beep; @@ -744,7 +744,7 @@ void MarlinUI::init() { #elif ENABLED(ULTIPANEL_FLOWPERCENT) - const int16_t old_fp = planner.flow_percentage[active_extruder]; + const int16_t old_fp = planner.flow_percentage[motion.extruder]; int16_t new_fp = old_fp + int16_t(encoderPosition); // Dead zone at 100% flow percentage @@ -762,7 +762,7 @@ void MarlinUI::init() { LIMIT(new_fp, FLOW_EDIT_MIN, FLOW_EDIT_MAX); if (old_fp != new_fp) { - planner.set_flow(active_extruder, new_fp); + planner.set_flow(motion.extruder, new_fp); encoderPosition = 0; } @@ -834,13 +834,13 @@ void MarlinUI::init() { /** * If a manual move has been posted and its time has arrived, and if the planner - * has a space for it, then add a linear move to current_position the planner. + * has a space for it, then add a linear move to motion.position the planner. * * If any manual move needs to be interrupted, make sure to force a manual move - * by setting manual_move.start_time to millis() after updating current_position. + * by setting manual_move.start_time to millis() after updating motion.position. * * To post a manual move: - * - Update current_position to the new place you want to go. + * - Update motion.position to the new place you want to go. * - Set manual_move.axis to an axis like X_AXIS. Use ALL_AXES_ENUM for diagonal moves. * - Set manual_move.start_time to a point in the future (in ms) when the move should be done. * @@ -867,18 +867,18 @@ void MarlinUI::init() { #if IS_KINEMATIC #if HAS_MULTI_EXTRUDER - REMEMBER(ae, active_extruder); + REMEMBER(ae, motion.extruder); #if MULTI_E_MANUAL - if (axis == E_AXIS) active_extruder = e_index; + if (axis == E_AXIS) motion.extruder = e_index; #endif #endif // Apply a linear offset to a single axis if (axis == ALL_AXES_ENUM) - destination = all_axes_destination; + motion.destination = all_axes_destination; else if (axis <= LOGICAL_AXES) { - destination = current_position; - destination[axis] += offset; + motion.destination = motion.position; + motion.destination[axis] += offset; } // Reset for the next move @@ -890,14 +890,14 @@ void MarlinUI::init() { // previous invocation is being blocked. Modifications to offset shouldn't be made while // processing is true or the planner will get out of sync. processing = true; - prepare_internal_move_to_destination(fr); // will set current_position from destination + motion.prepare_internal_move_to_destination(fr); // will set motion.position from destination processing = false; #else - // For Cartesian / Core motion simply move to the current_position - planner.buffer_line(current_position, fr, - TERN_(MULTI_E_MANUAL, axis == E_AXIS ? e_index :) active_extruder + // For Cartesian / Core motion simply move to the motion.position + planner.buffer_line(motion.position, fr, + TERN_(MULTI_E_MANUAL, axis == E_AXIS ? e_index :) motion.extruder ); //SERIAL_ECHOLNPGM("Add planner.move with Axis ", C(AXIS_CHAR(axis)), " at FR ", fr_mm_s); @@ -908,10 +908,10 @@ void MarlinUI::init() { } // - // Tell ui.update() to start a move to current_position after a short delay. + // Tell ui.update() to start a move to motion.position after a short delay. // void ManualMove::soon(const AxisEnum move_axis - OPTARG(MULTI_E_MANUAL, const int8_t eindex/*=active_extruder*/) + OPTARG(MULTI_E_MANUAL, const int8_t eindex/*=motion.extruder*/) ) { TERN_(MULTI_E_MANUAL, if (move_axis == E_AXIS) e_index = eindex); start_time = millis() + (menu_scale < 0.99f ? 0UL : 250UL); // delay for bigger moves diff --git a/Marlin/src/lcd/marlinui.h b/Marlin/src/lcd/marlinui.h index 8ec25ab5c6..23665ce243 100644 --- a/Marlin/src/lcd/marlinui.h +++ b/Marlin/src/lcd/marlinui.h @@ -155,27 +155,32 @@ typedef bool (*statusResetFunc_t)(); #if ENABLED(MANUAL_E_MOVES_RELATIVE) static float e_origin; #endif + template static void set_destination(const T& dest) { #if IS_KINEMATIC // Moves are segmented, so the entire move is not submitted at once. // Using a separate variable prevents corrupting the in-progress move. - all_axes_destination = current_position; + all_axes_destination = motion.position; all_axes_destination.set(dest); #else // Moves are submitted as single line to the planner using buffer_line. - current_position.set(dest); + motion.position.set(dest); #endif } + static float axis_value(const AxisEnum axis) { - return NATIVE_TO_LOGICAL(processing ? destination[axis] : SUM_TERN(IS_KINEMATIC, current_position[axis], offset), axis); + return motion.native_to_logical( + processing ? motion.destination[axis] : SUM_TERN(IS_KINEMATIC, motion.position[axis], offset), + axis + ); } static bool apply_diff(const AxisEnum axis, const float diff, const float min, const float max) { #if IS_KINEMATIC float &valref = offset; - const float rmin = min - current_position[axis], rmax = max - current_position[axis]; + const float rmin = min - motion.position[axis], rmax = max - motion.position[axis]; #else - float &valref = current_position[axis]; + float &valref = motion.position[axis]; const float rmin = min, rmax = max; #endif valref += diff; @@ -189,7 +194,7 @@ typedef bool (*statusResetFunc_t)(); static bool constexpr processing = false; #endif static void task(); - static void soon(const AxisEnum move_axis OPTARG(MULTI_E_MANUAL, const int8_t eindex=active_extruder)); + static void soon(const AxisEnum move_axis OPTARG(MULTI_E_MANUAL, const int8_t eindex=motion.extruder)); }; void lcd_move_axis(const AxisEnum); @@ -658,13 +663,13 @@ public: static preheat_t material_preset[PREHEAT_COUNT]; static void reset_material_presets(); static FSTR_P get_preheat_label(const uint8_t m); - static void apply_preheat(const uint8_t m, const uint8_t pmask, const uint8_t e=active_extruder); + static void apply_preheat(const uint8_t m, const uint8_t pmask, const uint8_t e=motion.extruder); static void preheat_set_fan(const uint8_t m) { TERN_(HAS_FAN, apply_preheat(m, _BV(PT_FAN))); } - static void preheat_hotend(const uint8_t m, const uint8_t e=active_extruder) { TERN_(HAS_HOTEND, apply_preheat(m, _BV(PT_HOTEND), e)); } - static void preheat_hotend_and_fan(const uint8_t m, const uint8_t e=active_extruder) { preheat_hotend(m, e); preheat_set_fan(m); } + static void preheat_hotend(const uint8_t m, const uint8_t e=motion.extruder) { TERN_(HAS_HOTEND, apply_preheat(m, _BV(PT_HOTEND), e)); } + static void preheat_hotend_and_fan(const uint8_t m, const uint8_t e=motion.extruder) { preheat_hotend(m, e); preheat_set_fan(m); } static void preheat_bed(const uint8_t m) { TERN_(HAS_HEATED_BED, apply_preheat(m, _BV(PT_BED))); } static void preheat_chamber(const uint8_t m) { TERN_(HAS_HEATED_CHAMBER, apply_preheat(m, _BV(PT_CHAMBER))); } - static void preheat_all(const uint8_t m, const uint8_t e=active_extruder) { apply_preheat(m, PT_ALL, e); } + static void preheat_all(const uint8_t m, const uint8_t e=motion.extruder) { apply_preheat(m, PT_ALL, e); } #endif /** @@ -774,7 +779,7 @@ public: #endif #if ENABLED(ADVANCED_PAUSE_FEATURE) && ANY(HAS_MARLINUI_MENU, EXTENSIBLE_UI, DWIN_CREALITY_LCD_JYERSUI) - static void pause_show_message(const PauseMessage message, const PauseMode mode=PAUSE_MODE_SAME, const uint8_t extruder=active_extruder); + static void pause_show_message(const PauseMessage message, const PauseMode mode=PAUSE_MODE_SAME, const uint8_t extruder=motion.extruder); #else static void _pause_show_message() {} #define pause_show_message(...) _pause_show_message() diff --git a/Marlin/src/lcd/menu/menu.cpp b/Marlin/src/lcd/menu/menu.cpp index a9ddd978e7..c329382e45 100644 --- a/Marlin/src/lcd/menu/menu.cpp +++ b/Marlin/src/lcd/menu/menu.cpp @@ -296,8 +296,8 @@ void scroll_screen(const uint8_t limit, const bool is_menu) { #if HAS_LINE_TO_Z void line_to_z(const float z) { - current_position.z = z; - line_to_current_position(manual_feedrate_mm_s.z); + motion.position.z = z; + motion.goto_current_position(manual_feedrate_mm_s.z); } #endif @@ -309,7 +309,7 @@ void scroll_screen(const uint8_t limit, const bool is_menu) { void lcd_babystep_zoffset() { if (ui.use_click()) return ui.goto_previous_screen_no_defer(); ui.defer_status_screen(); - const bool do_probe = DISABLED(BABYSTEP_HOTEND_Z_OFFSET) || active_extruder == 0; + const bool do_probe = DISABLED(BABYSTEP_HOTEND_Z_OFFSET) || motion.extruder == 0; if (ui.encoderPosition) { const int16_t babystep_increment = int16_t(ui.encoderPosition) * (BABYSTEP_SIZE_Z); ui.encoderPosition = 0; @@ -317,7 +317,7 @@ void scroll_screen(const uint8_t limit, const bool is_menu) { const float diff = planner.mm_per_step[Z_AXIS] * babystep_increment, new_probe_offset = probe.offset.z + diff, new_offs = TERN(BABYSTEP_HOTEND_Z_OFFSET - , do_probe ? new_probe_offset : hotend_offset[active_extruder].z - diff + , do_probe ? new_probe_offset : hotend_offset[motion.extruder].z - diff , new_probe_offset ); if (WITHIN(new_offs, PROBE_OFFSET_ZMIN, PROBE_OFFSET_ZMAX)) { @@ -327,7 +327,7 @@ void scroll_screen(const uint8_t limit, const bool is_menu) { if (do_probe) probe.offset.z = new_offs; else - TERN(BABYSTEP_HOTEND_Z_OFFSET, hotend_offset[active_extruder].z = new_offs, NOOP); + TERN(BABYSTEP_HOTEND_Z_OFFSET, hotend_offset[motion.extruder].z = new_offs, NOOP); ui.refresh(LCDVIEW_CALL_REDRAW_NEXT); } @@ -339,7 +339,7 @@ void scroll_screen(const uint8_t limit, const bool is_menu) { } else { #if ENABLED(BABYSTEP_HOTEND_Z_OFFSET) - MenuEditItemBase::draw_edit_screen(GET_TEXT_F(MSG_HOTEND_OFFSET_Z), ftostr54sign(hotend_offset[active_extruder].z)); + MenuEditItemBase::draw_edit_screen(GET_TEXT_F(MSG_HOTEND_OFFSET_Z), ftostr54sign(hotend_offset[motion.extruder].z)); #endif } } diff --git a/Marlin/src/lcd/menu/menu_advanced.cpp b/Marlin/src/lcd/menu/menu_advanced.cpp index 94e3ee41b2..6c97d50e56 100644 --- a/Marlin/src/lcd/menu/menu_advanced.cpp +++ b/Marlin/src/lcd/menu/menu_advanced.cpp @@ -146,7 +146,7 @@ void menu_backlash(); EDIT_ITEM(bool, MSG_VOLUMETRIC_ENABLED, &parser.volumetric_enabled, planner.calculate_volumetric_multipliers); #if ENABLED(VOLUMETRIC_EXTRUDER_LIMIT) - EDIT_ITEM_FAST(float42_52, MSG_VOLUMETRIC_LIMIT, &planner.volumetric_extruder_limit[active_extruder], 0.0f, float(VOLUMETRIC_EXTRUDER_LIMIT_MAX), planner.calculate_volumetric_extruder_limits); + EDIT_ITEM_FAST(float42_52, MSG_VOLUMETRIC_LIMIT, &planner.volumetric_extruder_limit[motion.extruder], 0.0f, float(VOLUMETRIC_EXTRUDER_LIMIT_MAX), planner.calculate_volumetric_extruder_limits); #if HAS_MULTI_EXTRUDER EXTRUDER_LOOP() EDIT_ITEM_FAST_N(float42_52, e, MSG_VOLUMETRIC_LIMIT_E, &planner.volumetric_extruder_limit[e], 0.0f, float(VOLUMETRIC_EXTRUDER_LIMIT_MAX), planner.calculate_volumetric_extruder_limits); @@ -154,7 +154,7 @@ void menu_backlash(); #endif if (parser.volumetric_enabled) { - EDIT_ITEM_FAST(float43, MSG_FILAMENT_DIAM, &planner.filament_size[active_extruder], 1.5f, 3.25f, planner.calculate_volumetric_multipliers); + EDIT_ITEM_FAST(float43, MSG_FILAMENT_DIAM, &planner.filament_size[motion.extruder], 1.5f, 3.25f, planner.calculate_volumetric_multipliers); #if HAS_MULTI_EXTRUDER EXTRUDER_LOOP() EDIT_ITEM_FAST_N(float43, e, MSG_FILAMENT_DIAM_E, &planner.filament_size[e], 1.5f, 3.25f, planner.calculate_volumetric_multipliers); @@ -165,13 +165,13 @@ void menu_backlash(); #if ENABLED(CONFIGURE_FILAMENT_CHANGE) constexpr float extrude_maxlength = TERN(PREVENT_LENGTHY_EXTRUDE, EXTRUDE_MAXLENGTH, 999); - EDIT_ITEM_FAST(float4, MSG_FILAMENT_UNLOAD, &fc_settings[active_extruder].unload_length, 0, extrude_maxlength); + EDIT_ITEM_FAST(float4, MSG_FILAMENT_UNLOAD, &fc_settings[motion.extruder].unload_length, 0, extrude_maxlength); #if HAS_MULTI_EXTRUDER EXTRUDER_LOOP() EDIT_ITEM_FAST_N(float4, e, MSG_FILAMENTUNLOAD_E, &fc_settings[e].unload_length, 0, extrude_maxlength); #endif - EDIT_ITEM_FAST(float4, MSG_FILAMENT_LOAD, &fc_settings[active_extruder].load_length, 0, extrude_maxlength); + EDIT_ITEM_FAST(float4, MSG_FILAMENT_LOAD, &fc_settings[motion.extruder].load_length, 0, extrude_maxlength); #if HAS_MULTI_EXTRUDER EXTRUDER_LOOP() EDIT_ITEM_FAST_N(float4, e, MSG_FILAMENTLOAD_E, &fc_settings[e].load_length, 0, extrude_maxlength); @@ -494,7 +494,7 @@ void menu_backlash(); EDIT_ITEM_FAST_N(float5, a, MSG_VMAX_N, &planner.settings.max_feedrate_mm_s[a], 1, max_fr_edit_scaled[a]); #if E_STEPPERS - EDIT_ITEM_FAST_N(float5, E_AXIS, MSG_VMAX_N, &planner.settings.max_feedrate_mm_s[E_AXIS_N(active_extruder)], 1, max_fr_edit_scaled.e); + EDIT_ITEM_FAST_N(float5, E_AXIS, MSG_VMAX_N, &planner.settings.max_feedrate_mm_s[E_AXIS_N(motion.extruder)], 1, max_fr_edit_scaled.e); #endif #if ENABLED(DISTINCT_E_FACTORS) for (uint8_t n = 0; n < E_STEPPERS; ++n) @@ -557,7 +557,7 @@ void menu_backlash(); #if HAS_EXTRUDERS // M204 R Retract Acceleration - EDIT_ITEM_FAST(float5, MSG_A_RETRACT, &planner.settings.retract_acceleration, 100, planner.settings.max_acceleration_mm_per_s2[E_AXIS_N(active_extruder)]); + EDIT_ITEM_FAST(float5, MSG_A_RETRACT, &planner.settings.retract_acceleration, 100, planner.settings.max_acceleration_mm_per_s2[E_AXIS_N(motion.extruder)]); #endif // M204 T Travel Acceleration @@ -571,10 +571,10 @@ void menu_backlash(); ); #if ENABLED(DISTINCT_E_FACTORS) - EDIT_ITEM_FAST(long5_25, MSG_AMAX_E, &planner.settings.max_acceleration_mm_per_s2[E_AXIS_N(active_extruder)], 100, max_accel_edit_scaled.e, []{ planner.refresh_acceleration_rates(); }); + EDIT_ITEM_FAST(long5_25, MSG_AMAX_E, &planner.settings.max_acceleration_mm_per_s2[E_AXIS_N(motion.extruder)], 100, max_accel_edit_scaled.e, []{ planner.refresh_acceleration_rates(); }); for (uint8_t n = 0; n < E_STEPPERS; ++n) EDIT_ITEM_FAST_N(long5_25, n, MSG_AMAX_EN, &planner.settings.max_acceleration_mm_per_s2[E_AXIS_N(n)], 100, max_accel_edit_scaled.e, []{ - if (MenuItemBase::itemIndex == active_extruder) + if (MenuItemBase::itemIndex == motion.extruder) planner.refresh_acceleration_rates(); }); #elif E_STEPPERS @@ -668,7 +668,7 @@ void menu_backlash(); for (uint8_t n = 0; n < E_STEPPERS; ++n) EDIT_ITEM_FAST_N(float72, n, MSG_EN_STEPS, &planner.settings.axis_steps_per_mm[E_AXIS_N(n)], 5, 9999, []{ const uint8_t e = MenuItemBase::itemIndex; - if (e == active_extruder) + if (e == motion.extruder) planner.refresh_positioning(); else planner.mm_per_step[E_AXIS_N(e)] = 1.0f / planner.settings.axis_steps_per_mm[E_AXIS_N(e)]; diff --git a/Marlin/src/lcd/menu/menu_bed_tramming.cpp b/Marlin/src/lcd/menu/menu_bed_tramming.cpp index b96dd5b07d..4056b16dd9 100644 --- a/Marlin/src/lcd/menu/menu_bed_tramming.cpp +++ b/Marlin/src/lcd/menu/menu_bed_tramming.cpp @@ -144,12 +144,12 @@ static void _lcd_goto_next_corner() { } } - float z = _MIN(current_position.z + (BED_TRAMMING_Z_HOP), Z_MAX_POS); + float z = _MIN(motion.position.z + (BED_TRAMMING_Z_HOP), Z_MAX_POS); #if ALL(BED_TRAMMING_USE_PROBE, BLTOUCH) z += bltouch.z_extra_clearance(); #endif line_to_z(z); - do_blocking_move_to_xy(DIFF_TERN(BED_TRAMMING_USE_PROBE, corner_point, probe.offset_xy), manual_feedrate_mm_s.x); + motion.blocking_move_xy(DIFF_TERN(BED_TRAMMING_USE_PROBE, corner_point, probe.offset_xy), manual_feedrate_mm_s.x); #if DISABLED(BED_TRAMMING_USE_PROBE) line_to_z(BED_TRAMMING_HEIGHT); if (++bed_corner >= available_points) bed_corner = 0; @@ -232,25 +232,25 @@ static void _lcd_goto_next_corner() { // Probe down and return 'true' if the probe triggered bool _lcd_bed_tramming_probe(const bool verify=false) { - if (verify) do_z_clearance_by(BED_TRAMMING_Z_HOP); // Do clearance if needed + if (verify) motion.do_z_clearance_by(BED_TRAMMING_Z_HOP); // Do clearance if needed TERN_(BLTOUCH, if (!bltouch.high_speed_mode) bltouch.deploy()); // Deploy in LOW SPEED MODE on every probe action - do_blocking_move_to_z(last_z - BED_TRAMMING_PROBE_TOLERANCE, z_probe_slow_mm_s); // Move down to lower tolerance + motion.blocking_move_z(last_z - BED_TRAMMING_PROBE_TOLERANCE, z_probe_slow_mm_s); // Move down to lower tolerance if (TEST(endstops.trigger_state(), Z_MIN_PROBE)) { // Probe triggered? endstops.hit_on_purpose(); - set_current_from_steppers_for_axis(Z_AXIS); - sync_plan_position(); + motion.set_current_from_steppers_for_axis(Z_AXIS); + motion.sync_plan_position(); TERN_(BLTOUCH, if (!bltouch.high_speed_mode) bltouch.stow()); // Stow in LOW SPEED MODE on every trigger // Triggered outside tolerance range? - if (ABS(current_position.z - last_z) > BED_TRAMMING_PROBE_TOLERANCE) { - last_z = current_position.z; // Above tolerance. Set a new Z for subsequent corners. - good_points = 0; // ...and start over + if (ABS(motion.position.z - last_z) > BED_TRAMMING_PROBE_TOLERANCE) { + last_z = motion.position.z; // Above tolerance. Set a new Z for subsequent corners. + good_points = 0; // ...and start over } // Raise the probe after the last point to give clearance for stow if (TERN0(NEEDS_PROBE_DEPLOY, good_points == nr_edge_points - 1)) - do_z_clearance(BED_TRAMMING_Z_HOP); + motion.do_z_clearance(BED_TRAMMING_Z_HOP); return true; // Triggered } @@ -314,7 +314,7 @@ static void _lcd_goto_next_corner() { if (bltouch.high_speed_mode) { // In HIGH SPEED MODE do stow and clearance at the very end bltouch.stow(); - do_z_clearance(BED_TRAMMING_Z_HOP); + motion.do_z_clearance(BED_TRAMMING_Z_HOP); } #endif @@ -325,7 +325,7 @@ static void _lcd_goto_next_corner() { #endif // BED_TRAMMING_USE_PROBE void _lcd_bed_tramming_homing() { - if (!all_axes_homed() && TERN1(NEEDS_PROBE_DEPLOY, probe.deploy())) return; + if (!motion.all_axes_homed() && TERN1(NEEDS_PROBE_DEPLOY, probe.deploy())) return; #if HAS_LEVELING // Disable leveling so the planner won't mess with us menu_leveling_was_active = planner.leveling_active; @@ -380,11 +380,11 @@ void _lcd_bed_tramming_homing() { void _lcd_bed_tramming() { TERN_(BED_TRAMMING_USE_PROBE, tramming_done = false); ui.defer_status_screen(); - set_all_unhomed(); + motion.set_all_unhomed(); queue.inject(TERN(CAN_SET_LEVELING_AFTER_G28, F("G28L0"), FPSTR(G28_STR))); ui.goto_screen([]{ _lcd_draw_homing(); - if (!all_axes_homed()) return; + if (!motion.all_axes_homed()) return; TERN(NEEDS_PROBE_DEPLOY, deploy_probe(), ui.goto_screen(_lcd_bed_tramming_homing)); }); } diff --git a/Marlin/src/lcd/menu/menu_configuration.cpp b/Marlin/src/lcd/menu/menu_configuration.cpp index cf1a5996f0..13bcb0706f 100644 --- a/Marlin/src/lcd/menu/menu_configuration.cpp +++ b/Marlin/src/lcd/menu/menu_configuration.cpp @@ -196,7 +196,7 @@ void menu_advanced_settings(); #if ENABLED(TOOLCHANGE_MIGRATION_FEATURE) - #include "../../module/motion.h" // for active_extruder + #include "../../module/motion.h" // for motion.extruder #include "../../gcode/queue.h" void menu_toolchange_migration() { @@ -211,7 +211,7 @@ void menu_advanced_settings(); // Migrate to a chosen extruder EXTRUDER_LOOP() { - if (e != active_extruder) { + if (e != motion.extruder) { ACTION_ITEM_N_F(e, msg_migrate, []{ char cmd[12]; sprintf_P(cmd, PSTR("M217 T%i"), int(MenuItemBase::itemIndex)); @@ -232,9 +232,9 @@ void menu_advanced_settings(); void menu_tool_offsets() { auto _recalc_offsets = []{ - if (active_extruder && all_axes_trusted()) { // For the 2nd extruder re-home so the next tool-change gets the new offsets. + if (motion.extruder && motion.all_axes_trusted()) { // For the 2nd extruder re-home so the next tool-change gets the new offsets. queue.inject_P(G28_STR); // In future, we can babystep the 2nd extruder (if active), making homing unnecessary. - active_extruder = 0; + motion.extruder = 0; } }; @@ -277,7 +277,7 @@ void menu_advanced_settings(); #if ENABLED(DUAL_X_CARRIAGE) void menu_idex() { - const bool need_g28 = axes_should_home(_BV(Y_AXIS)|_BV(Z_AXIS)); + const bool need_g28 = motion.axes_should_home(_BV(Y_AXIS)|_BV(Z_AXIS)); START_MENU(); BACK_ITEM(MSG_CONFIGURATION); @@ -410,17 +410,17 @@ void menu_advanced_settings(); #if ENABLED(MENUS_ALLOW_INCH_UNITS) #define _EDIT_HOMING_FR(A) do{ \ - const float minfr = MMS_TO_MMM(planner.settings.min_feedrate_mm_s); \ - const float maxfr = MMS_TO_MMM(planner.settings.max_feedrate_mm_s[_AXIS(A)]); \ - editable.decimal = A##_AXIS_UNIT(homing_feedrate_mm_m.A); \ + const float minfr = MMS_TO_MMM(planner.settings.min_feedrate_mm_s), \ + maxfr = MMS_TO_MMM(planner.settings.max_feedrate_mm_s[_AXIS(A)]); \ + editable.decimal = A##_AXIS_UNIT(motion.homing_feedrate_mm_m.A); \ EDIT_ITEM_FAST_N(float5, _AXIS(A), MSG_HOMING_FEEDRATE_N, &editable.decimal, \ A##_AXIS_UNIT(minfr), A##_AXIS_UNIT(maxfr), []{ \ - homing_feedrate_mm_m.A = parser.axis_value_to_mm(_AXIS(A), editable.decimal); \ + motion.homing_feedrate_mm_m.A = parser.axis_value_to_mm(_AXIS(A), editable.decimal); \ }); \ }while(0); #else #define _EDIT_HOMING_FR(A) \ - EDIT_ITEM_FAST_N(float5, _AXIS(A), MSG_HOMING_FEEDRATE_N, &homing_feedrate_mm_m.A, MMS_TO_MMM(planner.settings.min_feedrate_mm_s), MMS_TO_MMM(planner.settings.max_feedrate_mm_s[_AXIS(A)])); + EDIT_ITEM_FAST_N(float5, _AXIS(A), MSG_HOMING_FEEDRATE_N, &motion.homing_feedrate_mm_m.A, MMS_TO_MMM(planner.settings.min_feedrate_mm_s), MMS_TO_MMM(planner.settings.max_feedrate_mm_s[_AXIS(A)])); #endif MAIN_AXIS_MAP(_EDIT_HOMING_FR); diff --git a/Marlin/src/lcd/menu/menu_delta_calibrate.cpp b/Marlin/src/lcd/menu/menu_delta_calibrate.cpp index a0e60bae26..3d56a1ed17 100644 --- a/Marlin/src/lcd/menu/menu_delta_calibrate.cpp +++ b/Marlin/src/lcd/menu/menu_delta_calibrate.cpp @@ -45,7 +45,7 @@ void _man_probe_pt(const xy_pos_t &xy) { if (!ui.wait_for_move) { ui.wait_for_move = true; - do_blocking_move_to_xy_z(xy, Z_CLEARANCE_BETWEEN_PROBES); + motion.blocking_move_xy_z(xy, Z_CLEARANCE_BETWEEN_PROBES); ui.wait_for_move = false; ui.synchronize(); ui.manual_move.menu_scale = _MAX(PROBE_MANUALLY_STEP, MIN_STEPS_PER_SEGMENT / planner.settings.axis_steps_per_mm[0]); // Use first axis as for delta XYZ should always match @@ -69,7 +69,7 @@ void _man_probe_pt(const xy_pos_t &xy) { TERN_(EXTENSIBLE_UI, ExtUI::onUserConfirmRequired(GET_TEXT_F(MSG_DELTA_CALIBRATION_IN_PROGRESS))); TERN_(HAS_RESUME_CONTINUE, marlin.wait_for_user_response()); ui.goto_previous_screen_no_defer(); - return current_position.z; + return motion.position.z; } #endif @@ -80,7 +80,7 @@ void _man_probe_pt(const xy_pos_t &xy) { void _lcd_calibrate_homing() { _lcd_draw_homing(); - if (all_axes_homed()) ui.goto_previous_screen(); + if (motion.all_axes_homed()) ui.goto_previous_screen(); } void _lcd_delta_calibrate_home() { @@ -125,7 +125,7 @@ void lcd_delta_settings() { void menu_delta_calibrate() { #if ENABLED(DELTA_CALIBRATION_MENU) - const bool all_homed = all_axes_homed(); // Acquire ahead of loop + const bool all_homed = motion.all_axes_homed(); // Acquire ahead of loop #endif START_MENU(); diff --git a/Marlin/src/lcd/menu/menu_filament.cpp b/Marlin/src/lcd/menu/menu_filament.cpp index d2d6342185..495b545e21 100644 --- a/Marlin/src/lcd/menu/menu_filament.cpp +++ b/Marlin/src/lcd/menu/menu_filament.cpp @@ -131,7 +131,7 @@ void menu_change_filament() { // Change filament #if E_STEPPERS == 1 FSTR_P const fmsg = GET_TEXT_F(MSG_FILAMENTCHANGE); - if (thermalManager.targetTooColdToExtrude(active_extruder)) + if (thermalManager.targetTooColdToExtrude(motion.extruder)) SUBMENU_F(fmsg, []{ _menu_temp_filament_op(PAUSE_MODE_CHANGE_FILAMENT, 0); }); else GCODES_ITEM_F(fmsg, F("M600 B0")); @@ -156,7 +156,7 @@ void menu_change_filament() { // Load filament #if E_STEPPERS == 1 FSTR_P const msg_load = GET_TEXT_F(MSG_FILAMENTLOAD); - if (thermalManager.targetTooColdToExtrude(active_extruder)) + if (thermalManager.targetTooColdToExtrude(motion.extruder)) SUBMENU_F(msg_load, []{ _menu_temp_filament_op(PAUSE_MODE_LOAD_FILAMENT, 0); }); else GCODES_ITEM_F(msg_load, F("M701")); @@ -178,7 +178,7 @@ void menu_change_filament() { // Unload filament #if E_STEPPERS == 1 FSTR_P const msg_unload = GET_TEXT_F(MSG_FILAMENTUNLOAD); - if (thermalManager.targetTooColdToExtrude(active_extruder)) + if (thermalManager.targetTooColdToExtrude(motion.extruder)) SUBMENU_F(msg_unload, []{ _menu_temp_filament_op(PAUSE_MODE_UNLOAD_FILAMENT, 0); }); else GCODES_ITEM_F(msg_unload, F("M702")); @@ -209,7 +209,7 @@ void menu_change_filament() { #else - if (thermalManager.targetHotEnoughToExtrude(active_extruder)) + if (thermalManager.targetHotEnoughToExtrude(motion.extruder)) queue.inject(F("M600B0")); else ui.goto_screen([]{ _menu_temp_filament_op(PAUSE_MODE_CHANGE_FILAMENT, 0); }); @@ -328,7 +328,7 @@ FORCE_INLINE screenFunc_t ap_message_screen(const PauseMessage message) { void MarlinUI::pause_show_message( const PauseMessage message, const PauseMode mode/*=PAUSE_MODE_SAME*/, - const uint8_t extruder/*=active_extruder*/ + const uint8_t extruder/*=motion.extruder*/ ) { if (mode != PAUSE_MODE_SAME) pause_mode = mode; hotend_status_extruder = extruder; diff --git a/Marlin/src/lcd/menu/menu_item.h b/Marlin/src/lcd/menu/menu_item.h index 8b23ab1b9c..280eb126fc 100644 --- a/Marlin/src/lcd/menu/menu_item.h +++ b/Marlin/src/lcd/menu/menu_item.h @@ -283,9 +283,9 @@ class MenuItem_bool : public MenuEditItemBase { * MenuItem_function::action(flabel, lcd_sdcard_pause) * MenuItem_function::draw(sel, row, flabel, lcd_sdcard_pause) * - * EDIT_ITEM(int3, MSG_SPEED, &feedrate_percentage, SPEED_EDIT_MIN, SPEED_EDIT_MAX) - * MenuItem_int3::action(flabel, &feedrate_percentage, SPEED_EDIT_MIN, SPEED_EDIT_MAX) - * MenuItem_int3::draw(sel, row, flabel, &feedrate_percentage, SPEED_EDIT_MIN, SPEED_EDIT_MAX) + * EDIT_ITEM(int3, MSG_SPEED, &motion.feedrate_percentage, SPEED_EDIT_MIN, SPEED_EDIT_MAX) + * MenuItem_int3::action(flabel, &motion.feedrate_percentage, SPEED_EDIT_MIN, SPEED_EDIT_MAX) + * MenuItem_int3::draw(sel, row, flabel, &motion.feedrate_percentage, SPEED_EDIT_MIN, SPEED_EDIT_MAX) * * Variants use standard suffixes. N:Number Index, S:C-string for substitution, F:F-string label, f:F-string for substitution * _MENU_ITEM_F(TYPE, V...) Item with optional data diff --git a/Marlin/src/lcd/menu/menu_motion.cpp b/Marlin/src/lcd/menu/menu_motion.cpp index 59172a4787..3a825afc0d 100644 --- a/Marlin/src/lcd/menu/menu_motion.cpp +++ b/Marlin/src/lcd/menu/menu_motion.cpp @@ -55,13 +55,13 @@ void lcd_move_axis(const AxisEnum axis) { if (ui.encoderPosition && !ui.manual_move.processing) { // Get motion limit from software endstops, if any float min, max; - soft_endstop.get_manual_axis_limits(axis, min, max); + motion.soft_endstop.get_manual_axis_limits(axis, min, max); // Delta limits XY based on the current offset from center // This assumes the center is 0,0 #if ENABLED(DELTA) if (axis != Z_AXIS) { - max = SQRT(FLOAT_SQ(PRINTABLE_RADIUS) - sq(current_position[Y_AXIS - axis])); // (Y_AXIS - axis) == the other axis + max = SQRT(FLOAT_SQ(PRINTABLE_RADIUS) - sq(motion.position[Y_AXIS - axis])); // (Y_AXIS - axis) == the other axis min = -max; } #endif @@ -87,12 +87,12 @@ void lcd_move_axis(const AxisEnum axis) { #if E_MANUAL - static void lcd_move_e(TERN_(MULTI_E_MANUAL, const int8_t eindex=active_extruder)) { + static void lcd_move_e(TERN_(MULTI_E_MANUAL, const int8_t eindex=motion.extruder)) { if (ui.use_click()) return ui.goto_previous_screen_no_defer(); if (ui.encoderPosition) { if (!ui.manual_move.processing) { const float diff = float(int32_t(ui.encoderPosition)) * ui.manual_move.menu_scale; - TERN(IS_KINEMATIC, ui.manual_move.offset, current_position.e) += diff; + TERN(IS_KINEMATIC, ui.manual_move.offset, motion.position.e) += diff; ui.manual_move.soon(E_AXIS OPTARG(MULTI_E_MANUAL, eindex)); ui.refresh(LCDVIEW_REDRAW_NOW); } @@ -102,7 +102,7 @@ void lcd_move_axis(const AxisEnum axis) { TERN_(MULTI_E_MANUAL, MenuItemBase::init(eindex)); MenuEditItemBase::draw_edit_screen( GET_TEXT_F(TERN(MULTI_E_MANUAL, MSG_MOVE_EN, MSG_MOVE_E)), - ftostr41sign(current_position.e + ftostr41sign(motion.position.e PLUS_TERN0(IS_KINEMATIC, ui.manual_move.offset) MINUS_TERN0(MANUAL_E_MOVES_RELATIVE, ui.manual_move.e_origin) ) @@ -136,14 +136,14 @@ void _goto_manual_move(const float scale) { thermalManager.set_menu_cold_override(true); } -void _menu_move_distance(const AxisEnum axis, const screenFunc_t func, const int8_t eindex=active_extruder) { +void _menu_move_distance(const AxisEnum axis, const screenFunc_t func, const int8_t eindex=motion.extruder) { ui.manual_move.screen_ptr = func; START_MENU(); if (LCD_HEIGHT >= 4) { if (axis < NUM_AXES) STATIC_ITEM_N(axis, MSG_MOVE_N, SS_DEFAULT|SS_INVERT); else { - TERN_(MANUAL_E_MOVES_RELATIVE, ui.manual_move.e_origin = current_position.e); + TERN_(MANUAL_E_MOVES_RELATIVE, ui.manual_move.e_origin = motion.position.e); STATIC_ITEM_N(eindex, MSG_MOVE_EN, SS_DEFAULT|SS_INVERT); } } @@ -193,7 +193,7 @@ void _menu_move_distance(const AxisEnum axis, const screenFunc_t func, const int } inline void _menu_move_distance_e_maybe() { - if (thermalManager.tooColdToExtrude(active_extruder)) { + if (thermalManager.tooColdToExtrude(motion.extruder)) { ui.goto_screen([]{ MenuItem_confirm::select_screen( GET_TEXT_F(MSG_BUTTON_PROCEED), GET_TEXT_F(MSG_BACK), @@ -213,12 +213,12 @@ void menu_move() { BACK_ITEM(MSG_MOTION); #if ALL(HAS_SOFTWARE_ENDSTOPS, SOFT_ENDSTOPS_MENU_ITEM) - EDIT_ITEM(bool, MSG_LCD_SOFT_ENDSTOPS, &soft_endstop._enabled); + EDIT_ITEM(bool, MSG_LCD_SOFT_ENDSTOPS, &motion.soft_endstop._enabled); #endif // Move submenu for each axis - if (NONE(IS_KINEMATIC, NO_MOTION_BEFORE_HOMING) || all_axes_homed()) { - if (TERN1(DELTA, current_position.z <= delta_clip_start_height)) { + if (NONE(IS_KINEMATIC, NO_MOTION_BEFORE_HOMING) || motion.all_axes_homed()) { + if (TERN1(DELTA, motion.position.z <= delta_clip_start_height)) { #if HAS_X_AXIS SUBMENU_N(X_AXIS, MSG_MOVE_N, []{ _menu_move_distance(X_AXIS, []{ lcd_move_axis(X_AXIS); }); }); #endif @@ -242,7 +242,7 @@ void menu_move() { #if ANY(HAS_SWITCHING_EXTRUDER, HAS_SWITCHING_NOZZLE, MAGNETIC_SWITCHING_TOOLHEAD) #if EXTRUDERS >= 4 - switch (active_extruder) { + switch (motion.extruder) { case 0: GCODES_ITEM_N(1, MSG_SELECT_E, F("T1")); break; case 1: GCODES_ITEM_N(0, MSG_SELECT_E, F("T0")); break; case 2: GCODES_ITEM_N(3, MSG_SELECT_E, F("T3")); break; @@ -253,15 +253,15 @@ void menu_move() { #endif } #elif EXTRUDERS == 3 - if (active_extruder < 2) - GCODES_ITEM_N(1 - active_extruder, MSG_SELECT_E, active_extruder ? F("T0") : F("T1")); + if (motion.extruder < 2) + GCODES_ITEM_N(1 - motion.extruder, MSG_SELECT_E, motion.extruder ? F("T0") : F("T1")); #else - GCODES_ITEM_N(1 - active_extruder, MSG_SELECT_E, active_extruder ? F("T0") : F("T1")); + GCODES_ITEM_N(1 - motion.extruder, MSG_SELECT_E, motion.extruder ? F("T0") : F("T1")); #endif #elif ENABLED(DUAL_X_CARRIAGE) - GCODES_ITEM_N(1 - active_extruder, MSG_SELECT_E, active_extruder ? F("T0") : F("T1")); + GCODES_ITEM_N(1 - motion.extruder, MSG_SELECT_E, motion.extruder ? F("T0") : F("T1")); #endif @@ -628,7 +628,7 @@ void menu_motion() { // // Move Axis // - if (TERN1(DELTA, all_axes_homed())) + if (TERN1(DELTA, motion.all_axes_homed())) SUBMENU(MSG_MOVE_AXIS, menu_move); // diff --git a/Marlin/src/lcd/menu/menu_probe_level.cpp b/Marlin/src/lcd/menu/menu_probe_level.cpp index ba806d665f..db248c8d59 100644 --- a/Marlin/src/lcd/menu/menu_probe_level.cpp +++ b/Marlin/src/lcd/menu/menu_probe_level.cpp @@ -124,7 +124,7 @@ // Encoder knob or keypad buttons adjust the Z position // if (ui.encoderPosition) { - const float z = current_position.z + float(int32_t(ui.encoderPosition)) * (MESH_EDIT_Z_STEP); + const float z = motion.position.z + float(int32_t(ui.encoderPosition)) * (MESH_EDIT_Z_STEP); line_to_z(constrain(z, -(LCD_PROBE_Z_RANGE) * 0.5f, (LCD_PROBE_Z_RANGE) * 0.5f)); ui.refresh(LCDVIEW_CALL_REDRAW_NEXT); ui.encoderPosition = 0; @@ -134,7 +134,7 @@ // Draw on first display, then only on Z change // if (ui.should_draw()) { - const float v = current_position.z; + const float v = motion.position.z; MenuEditItemBase::draw_edit_screen(GET_TEXT_F(MSG_MOVE_Z), ftostr43sign(v + (v < 0 ? -0.0001f : 0.0001f), '+')); } } @@ -190,7 +190,7 @@ // void _lcd_level_bed_homing() { _lcd_draw_homing(); - if (all_axes_homed()) ui.goto_screen(_lcd_level_bed_homing_done); + if (motion.all_axes_homed()) ui.goto_screen(_lcd_level_bed_homing_done); } #if ENABLED(PROBE_MANUALLY) @@ -202,7 +202,7 @@ // void _lcd_level_bed_continue() { ui.defer_status_screen(); - set_all_unhomed(); + motion.set_all_unhomed(); ui.goto_screen(_lcd_level_bed_homing); queue.inject_P(G28_STR); } @@ -212,8 +212,8 @@ #if ENABLED(MESH_EDIT_MENU) inline void refresh_planner() { - set_current_from_steppers_for_axis(ALL_AXES_ENUM); - sync_plan_position(); + motion.set_current_from_steppers_for_axis(ALL_AXES_ENUM); + motion.sync_plan_position(); } void menu_edit_mesh() { @@ -242,12 +242,12 @@ void menu_probe_level() { const bool can_babystep_z = TERN0(BABYSTEP_ZPROBE_OFFSET, babystep.can_babystep(Z_AXIS)); #if HAS_LEVELING - const bool is_homed = all_axes_homed(), + const bool is_homed = motion.all_axes_homed(), is_valid = leveling_is_valid(); #endif #if NONE(PROBE_MANUALLY, MESH_BED_LEVELING) - const bool is_trusted = all_axes_trusted(); + const bool is_trusted = motion.all_axes_trusted(); #endif START_MENU(); diff --git a/Marlin/src/lcd/menu/menu_probe_offset.cpp b/Marlin/src/lcd/menu/menu_probe_offset.cpp index e959c687ed..745d46230e 100644 --- a/Marlin/src/lcd/menu/menu_probe_offset.cpp +++ b/Marlin/src/lcd/menu/menu_probe_offset.cpp @@ -47,7 +47,7 @@ float z_offset_backup, calculated_z_offset, z_offset_ref; // "Done" - Set the offset, re-enable leveling, go back to the previous screen. void set_offset_and_go_back(const float z) { probe.offset.z = z; - SET_SOFT_ENDSTOP_LOOSE(false); + motion.set_soft_endstop_loose(false); TERN_(HAS_LEVELING, set_bed_leveling_enabled(menu_leveling_was_active)); ui.goto_previous_screen_no_defer(); } @@ -58,12 +58,12 @@ void set_offset_and_go_back(const float z) { */ void probe_offset_wizard_menu() { START_MENU(); - calculated_z_offset = probe.offset.z + current_position.z - z_offset_ref; + calculated_z_offset = probe.offset.z + motion.position.z - z_offset_ref; if (LCD_HEIGHT >= 4) STATIC_ITEM(MSG_MOVE_NOZZLE_TO_BED, SS_CENTER|SS_INVERT); - STATIC_ITEM_F(F("Z"), SS_CENTER, ftostr42_52(current_position.z)); + STATIC_ITEM_F(F("Z"), SS_CENTER, ftostr42_52(motion.position.z)); STATIC_ITEM_N(Z_AXIS, MSG_ZPROBE_OFFSET_N, SS_FULL, ftostr42_52(calculated_z_offset)); SUBMENU_S(F("1.0"), MSG_MOVE_N_MM, []{ _goto_manual_move_z( 1.0f); }); @@ -74,19 +74,19 @@ void probe_offset_wizard_menu() { ACTION_ITEM(MSG_BUTTON_DONE, []{ set_offset_and_go_back(calculated_z_offset); - current_position.z = z_offset_ref; // Set Z to z_offset_ref, as we can expect it is at probe height - sync_plan_position(); - do_z_post_clearance(); + motion.position.z = z_offset_ref; // Set Z to z_offset_ref, as we can expect it is at probe height + motion.sync_plan_position(); + motion.do_z_post_clearance(); }); ACTION_ITEM(MSG_BUTTON_CANCEL, []{ set_offset_and_go_back(z_offset_backup); // On cancel the Z position needs correction #if HOMING_Z_WITH_PROBE && defined(PROBE_OFFSET_WIZARD_START_Z) - set_axis_never_homed(Z_AXIS); + motion.set_axis_never_homed(Z_AXIS); queue.inject(F("G28Z")); #else - do_z_post_clearance(); + motion.do_z_post_clearance(); #endif }); @@ -129,12 +129,12 @@ void prepare_for_probe_offset_wizard() { // Move Nozzle to Probing/Homing Position ui.wait_for_move = true; - current_position += probe.offset_xy; - line_to_current_position(XY_PROBE_FEEDRATE_MM_S); + motion.position += probe.offset_xy; + motion.goto_current_position(XY_PROBE_FEEDRATE_MM_S); ui.synchronize(GET_TEXT_F(MSG_PROBE_WIZARD_MOVING)); ui.wait_for_move = false; - SET_SOFT_ENDSTOP_LOOSE(true); // Disable soft endstops for free Z movement + motion.set_soft_endstop_loose(true); // Disable soft endstops for free Z movement // Go to Calibration Menu ui.goto_screen(probe_offset_wizard_menu); @@ -145,7 +145,7 @@ void prepare_for_probe_offset_wizard() { // When homing is completed go to prepare_for_probe_offset_wizard(). void goto_probe_offset_wizard() { ui.defer_status_screen(); - set_all_unhomed(); + motion.set_all_unhomed(); // Store probe.offset.z for Case: Cancel z_offset_backup = probe.offset.z; @@ -166,7 +166,7 @@ void goto_probe_offset_wizard() { // Show "Homing XYZ" display until homing completes ui.goto_screen([]{ _lcd_draw_homing(); - if (all_axes_homed()) { + if (motion.all_axes_homed()) { z_offset_ref = 0; // Set Z Value for Wizard Position to 0 ui.goto_screen(prepare_for_probe_offset_wizard); ui.defer_status_screen(); diff --git a/Marlin/src/lcd/menu/menu_tramming_wizard.cpp b/Marlin/src/lcd/menu/menu_tramming_wizard.cpp index e0f88ea1bb..e3b32bc51b 100644 --- a/Marlin/src/lcd/menu/menu_tramming_wizard.cpp +++ b/Marlin/src/lcd/menu/menu_tramming_wizard.cpp @@ -100,12 +100,12 @@ void goto_tramming_wizard() { reference_index = -1; // Inject G28, wait for homing to complete, - set_all_unhomed(); + motion.set_all_unhomed(); queue.inject(TERN(CAN_SET_LEVELING_AFTER_G28, F("G28L0"), FPSTR(G28_STR))); ui.goto_screen([]{ _lcd_draw_homing(); - if (all_axes_homed()) + if (motion.all_axes_homed()) ui.goto_screen(tramming_wizard_menu); }); } diff --git a/Marlin/src/lcd/menu/menu_tune.cpp b/Marlin/src/lcd/menu/menu_tune.cpp index 856ae5a5f4..da1bf8eb69 100644 --- a/Marlin/src/lcd/menu/menu_tune.cpp +++ b/Marlin/src/lcd/menu/menu_tune.cpp @@ -111,7 +111,7 @@ void menu_tune() { // // Speed: // - EDIT_ITEM(int3, MSG_SPEED, &feedrate_percentage, SPEED_EDIT_MIN, SPEED_EDIT_MAX); + EDIT_ITEM(int3, MSG_SPEED, &motion.feedrate_percentage, SPEED_EDIT_MIN, SPEED_EDIT_MAX); // // Manual bed leveling, Bed Z: @@ -206,7 +206,7 @@ void menu_tune() { // Flow: // #if HAS_EXTRUDERS - EDIT_ITEM(int3, MSG_FLOW, &planner.flow_percentage[active_extruder], FLOW_EDIT_MIN, FLOW_EDIT_MAX, []{ planner.refresh_e_factor(active_extruder); }); + EDIT_ITEM(int3, MSG_FLOW, &planner.flow_percentage[motion.extruder], FLOW_EDIT_MIN, FLOW_EDIT_MAX, []{ planner.refresh_e_factor(motion.extruder); }); // Flow En: #if HAS_MULTI_EXTRUDER EXTRUDER_LOOP() diff --git a/Marlin/src/lcd/menu/menu_ubl.cpp b/Marlin/src/lcd/menu/menu_ubl.cpp index 3b14950ee0..0fac4420e2 100644 --- a/Marlin/src/lcd/menu/menu_ubl.cpp +++ b/Marlin/src/lcd/menu/menu_ubl.cpp @@ -398,13 +398,13 @@ void ubl_map_move_to_xy() { const xy_pos_t xy = { bedlevel.get_mesh_x(x_plot), bedlevel.get_mesh_y(y_plot) }; // Some printers have unreachable areas in the mesh. Skip the move if unreachable. - if (!position_is_reachable(xy)) return; + if (!motion.can_reach(xy)) return; #if ENABLED(DELTA) - if (current_position.z > delta_clip_start_height) { // Make sure the delta has fully free motion - destination = current_position; - destination.z = delta_clip_start_height; - prepare_internal_fast_move_to_destination(homing_feedrate(Z_AXIS)); // Set current_position from destination + if (motion.position.z > delta_clip_start_height) { // Make sure the delta has fully free motion + motion.destination = motion.position; + motion.destination.z = delta_clip_start_height; + motion.prepare_internal_fast_move_to_destination(motion.homing_feedrate(Z_AXIS)); // Set motion.position from destination } #endif @@ -455,7 +455,7 @@ void ubl_map_screen() { // Validate if needed #if IS_KINEMATIC const xy_pos_t xy = { bedlevel.get_mesh_x(x), bedlevel.get_mesh_y(y) }; - if (position_is_reachable(xy)) break; // Found a valid point + if (motion.can_reach(xy)) break; // Found a valid point ui.encoderPosition += step_dir; // Test the next point #endif } while (ENABLED(IS_KINEMATIC)); @@ -494,7 +494,7 @@ void ubl_map_screen() { void _ubl_map_screen_homing() { ui.defer_status_screen(); _lcd_draw_homing(); - if (all_axes_homed()) { + if (motion.all_axes_homed()) { bedlevel.lcd_map_control = true; // Return to the map screen after editing Z ui.goto_screen(ubl_map_screen, grid_index(x_plot, y_plot)); // Pre-set the encoder value ui.manual_move.menu_scale = 0; // Immediate move @@ -508,8 +508,8 @@ void _ubl_map_screen_homing() { */ void _ubl_goto_map_screen() { if (planner.has_blocks_queued()) return; // The ACTION_ITEM will do nothing - if (!all_axes_trusted()) { - set_all_unhomed(); + if (!motion.all_axes_trusted()) { + motion.set_all_unhomed(); queue.inject_P(G28_STR); } ui.goto_screen(_ubl_map_screen_homing); // Go to the "Homing" screen diff --git a/Marlin/src/lcd/menu/menu_x_twist.cpp b/Marlin/src/lcd/menu/menu_x_twist.cpp index d6d55965ec..37f795b7eb 100644 --- a/Marlin/src/lcd/menu/menu_x_twist.cpp +++ b/Marlin/src/lcd/menu/menu_x_twist.cpp @@ -52,7 +52,7 @@ void xatc_wizard_done() { if (!ui.wait_for_move) { xatc.print_points(); set_bed_leveling_enabled(menu_leveling_was_active); - SET_SOFT_ENDSTOP_LOOSE(false); + motion.set_soft_endstop_loose(false); ui.goto_screen(menu_advanced_settings); } if (ui.should_draw()) @@ -83,7 +83,7 @@ void xatc_wizard_update_z_offset() { // void xatc_wizard_set_offset_and_go_to_next_point() { // Set Z-offset at probed point - xatc.z_offset[manual_probe_index++] = probe.offset.z + current_position.z - measured_z; + xatc.z_offset[manual_probe_index++] = probe.offset.z + motion.position.z - measured_z; // Go to next point ui.goto_screen(xatc_wizard_goto_next_point); } @@ -93,12 +93,12 @@ void xatc_wizard_set_offset_and_go_to_next_point() { // void xatc_wizard_menu() { START_MENU(); - float calculated_z_offset = probe.offset.z + current_position.z - measured_z; + float calculated_z_offset = probe.offset.z + motion.position.z - measured_z; if (LCD_HEIGHT >= 4) STATIC_ITEM(MSG_MOVE_NOZZLE_TO_BED, SS_CENTER|SS_INVERT); - STATIC_ITEM_F(F("Z="), SS_CENTER, ftostr42_52(current_position.z)); + STATIC_ITEM_F(F("Z="), SS_CENTER, ftostr42_52(motion.position.z)); STATIC_ITEM_N(Z_AXIS, MSG_ZPROBE_OFFSET_N, SS_LEFT, ftostr42_52(calculated_z_offset)); SUBMENU_S(F("1.0"), MSG_MOVE_N_MM, []{ _goto_manual_move_z( 1.0f); }); @@ -139,14 +139,14 @@ void xatc_wizard_goto_next_point() { ui.goto_screen(xatc_wizard_moving); // Deploy certain probes before starting probing - TERN_(BLTOUCH, do_z_clearance(Z_CLEARANCE_DEPLOY_PROBE)); + TERN_(BLTOUCH, motion.do_z_clearance(Z_CLEARANCE_DEPLOY_PROBE)); xatc.set_enabled(false); measured_z = probe.probe_at_point(x, XATC_Y_POSITION, PROBE_PT_STOW); xatc.set_enabled(true); - current_position += probe.offset_xy; - current_position.z = (XATC_START_Z) - probe.offset.z + measured_z; - line_to_current_position(XY_PROBE_FEEDRATE_MM_S); + motion.position += probe.offset_xy; + motion.position.z = (XATC_START_Z) - probe.offset.z + measured_z; + motion.goto_current_position(XY_PROBE_FEEDRATE_MM_S); ui.wait_for_move = false; } else @@ -183,7 +183,7 @@ void xatc_wizard_homing_done() { if (ui.use_click()) { xatc.reset(); - SET_SOFT_ENDSTOP_LOOSE(true); // Disable soft endstops for free Z movement + motion.set_soft_endstop_loose(true); // Disable soft endstops for free Z movement ui.goto_screen(xatc_wizard_goto_next_point); } @@ -194,7 +194,7 @@ void xatc_wizard_homing_done() { // void xatc_wizard_homing() { _lcd_draw_homing(); - if (all_axes_homed()) + if (motion.all_axes_homed()) ui.goto_screen(xatc_wizard_homing_done); } @@ -210,7 +210,7 @@ void xatc_wizard_continue() { // Home all axes ui.defer_status_screen(); - set_all_unhomed(); + motion.set_all_unhomed(); ui.goto_screen(xatc_wizard_homing); queue.inject_P(G28_STR); } diff --git a/Marlin/src/lcd/sovol_rts/sovol_rts.cpp b/Marlin/src/lcd/sovol_rts/sovol_rts.cpp index 153db1bf6d..99815e3fcc 100644 --- a/Marlin/src/lcd/sovol_rts/sovol_rts.cpp +++ b/Marlin/src/lcd/sovol_rts/sovol_rts.cpp @@ -124,7 +124,7 @@ int16_t fan_speed; inline void RTS_line_to_current(const AxisEnum axis) { if (!planner.is_full()) - planner.buffer_line(current_position, MMM_TO_MMS(manual_feedrate_mm_m[axis]), active_extruder); + planner.buffer_line(motion.position, MMM_TO_MMS(manual_feedrate_mm_m[axis]), motion.extruder); } RTS::RTS() { @@ -271,8 +271,8 @@ void RTS::init() { TERN_(HAS_HOTEND, last_target_temperature[0] = thermalManager.degTargetHotend(0)); TERN_(HAS_HEATED_BED, last_target_temperature_bed = thermalManager.degTargetBed()); - feedrate_percentage = 100; - sendData(feedrate_percentage, PRINT_SPEED_RATE_VP); + motion.feedrate_percentage = 100; + sendData(motion.feedrate_percentage, PRINT_SPEED_RATE_VP); /***************turn off motor*****************/ sendData(1, MOTOR_FREE_ICON_VP); @@ -577,7 +577,7 @@ void RTS::handleData() { else if (recdat.data[0] == 2) { // Complete printing waitway = 7; card.flag.abort_sd_printing = true; - quickstop_stepper(); + motion.quickstop_stepper(); print_job_timer.reset(); queue.clear(); sendData(0, MOTOR_FREE_ICON_VP); @@ -652,8 +652,8 @@ void RTS::handleData() { break; case PrintSpeedKey: // Set the print speed - feedrate_percentage = recdat.data[0]; - sendData(feedrate_percentage, PRINT_SPEED_RATE_VP); + motion.feedrate_percentage = recdat.data[0]; + sendData(motion.feedrate_percentage, PRINT_SPEED_RATE_VP); break; case StopPrintKey: // Stop printing @@ -753,8 +753,8 @@ void RTS::handleData() { sendData(cardRec.display_filename[cardRec.recordcount], PRINT_FILE_TEXT_VP); delay(2); TERN_(BABYSTEPPING, sendData(0, AUTO_BED_LEVEL_ZOFFSET_VP)); - feedrate_percentage = 100; - sendData(feedrate_percentage, PRINT_SPEED_RATE_VP); + motion.feedrate_percentage = 100; + sendData(motion.feedrate_percentage, PRINT_SPEED_RATE_VP); zprobe_zoffset = last_zoffset; sendData(probe.offset.z * 100, AUTO_BED_LEVEL_ZOFFSET_VP); poweroff_continue = true; @@ -886,9 +886,9 @@ void RTS::handleData() { case 3: // Go to Move Axis AxisUnitMode = 1; - TERN_(HAS_X_AXIS, sendData(current_position.x * 10.0f, AXIS_X_COORD_VP)); - TERN_(HAS_Y_AXIS, sendData(current_position.y * 10.0f, AXIS_Y_COORD_VP)); - TERN_(HAS_Z_AXIS, sendData(current_position.z * 10.0f, AXIS_Z_COORD_VP)); + TERN_(HAS_X_AXIS, sendData(motion.position.x * 10.0f, AXIS_X_COORD_VP)); + TERN_(HAS_Y_AXIS, sendData(motion.position.y * 10.0f, AXIS_Y_COORD_VP)); + TERN_(HAS_Z_AXIS, sendData(motion.position.z * 10.0f, AXIS_Z_COORD_VP)); gotoPage(ID_Move10_L, ID_Move10_D); break; @@ -947,10 +947,10 @@ void RTS::handleData() { #if HAS_X_AXIS case XaxismoveKey: { waitway = 4; - current_position.x = float(recdat.data[0] >= 32768 ? recdat.data[0] - 65536 : recdat.data[0]) * 0.1f; - LIMIT(current_position.x, X_MIN_POS, X_MAX_POS); + motion.position.x = float(recdat.data[0] >= 32768 ? recdat.data[0] - 65536 : recdat.data[0]) * 0.1f; + LIMIT(motion.position.x, X_MIN_POS, X_MAX_POS); RTS_line_to_current(X_AXIS); - sendData(current_position.x * 10.0f, AXIS_X_COORD_VP); + sendData(motion.position.x * 10.0f, AXIS_X_COORD_VP); sendData(0, MOTOR_FREE_ICON_VP); waitway = 0; } break; @@ -959,10 +959,10 @@ void RTS::handleData() { #if HAS_Y_AXIS case YaxismoveKey: { waitway = 4; - current_position.y = float(recdat.data[0]) * 0.1f; - LIMIT(current_position.y, Y_MIN_POS, Y_MAX_POS); + motion.position.y = float(recdat.data[0]) * 0.1f; + LIMIT(motion.position.y, Y_MIN_POS, Y_MAX_POS); RTS_line_to_current(Y_AXIS); - sendData(current_position.y * 10.0f, AXIS_Y_COORD_VP); + sendData(motion.position.y * 10.0f, AXIS_Y_COORD_VP); sendData(0, MOTOR_FREE_ICON_VP); waitway = 0; } break; @@ -971,10 +971,10 @@ void RTS::handleData() { #if HAS_Z_AXIS case ZaxismoveKey: { waitway = 4; - current_position.z = float(recdat.data[0]) * 0.1f; - LIMIT(current_position.z, Z_MIN_POS, Z_MAX_POS); + motion.position.z = float(recdat.data[0]) * 0.1f; + LIMIT(motion.position.z, Z_MIN_POS, Z_MAX_POS); RTS_line_to_current(Z_AXIS); - sendData(current_position.z * 10.0f, AXIS_Z_COORD_VP); + sendData(motion.position.z * 10.0f, AXIS_Z_COORD_VP); sendData(0, MOTOR_FREE_ICON_VP); waitway = 0; } break; @@ -985,7 +985,7 @@ void RTS::handleData() { case 1: if (planner.has_blocks_queued()) break; if (TERN0(CHECKFILAMENT, runout.filament_ran_out)) gotoPage(ID_NoFilament_L, ID_NoFilament_D); - current_position.e -= filament_load_0; + motion.position.e -= filament_load_0; if (thermalManager.degHotend(0) < change_filament_temp_0 - 5) { sendData(int16_t(change_filament_temp_0), CHANGE_FILAMENT0_TEMP_VP); @@ -1000,7 +1000,7 @@ void RTS::handleData() { case 2: if (planner.has_blocks_queued()) break; if (TERN0(CHECKFILAMENT, runout.filament_ran_out)) gotoPage(ID_NoFilament_L, ID_NoFilament_D); - current_position.e += filament_load_0; + motion.position.e += filament_load_0; if (thermalManager.degHotend(0) < change_filament_temp_0 - 5) { sendData(int16_t(change_filament_temp_0), CHANGE_FILAMENT0_TEMP_VP); @@ -1077,7 +1077,7 @@ void RTS::handleData() { sdcard_pause_check = true; zprobe_zoffset = probe.offset.z; sendData(probe.offset.z * 100, AUTO_BED_LEVEL_ZOFFSET_VP); - sendData(feedrate_percentage, PRINT_SPEED_RATE_VP); + sendData(motion.feedrate_percentage, PRINT_SPEED_RATE_VP); print_state = 2; break; @@ -1087,7 +1087,7 @@ void RTS::handleData() { poweroff_continue = false; sdcard_pause_check = true; queue.clear(); - quickstop_stepper(); + motion.quickstop_stepper(); print_job_timer.abort(); thermalManager.disable_all_heaters(); print_job_timer.reset(); @@ -1160,8 +1160,8 @@ void RTS::handleData() { TERN_(BABYSTEPPING, sendData(0, AUTO_BED_LEVEL_ZOFFSET_VP)); - feedrate_percentage = 100; - sendData(feedrate_percentage, PRINT_SPEED_RATE_VP); + motion.feedrate_percentage = 100; + sendData(motion.feedrate_percentage, PRINT_SPEED_RATE_VP); #if HAS_BED_PROBE zprobe_zoffset = last_zoffset; sendData(probe.offset.z * 100, AUTO_BED_LEVEL_ZOFFSET_VP); @@ -1504,7 +1504,7 @@ void RTS::handleData() { TERN_(HAS_BED_PROBE, sendData(probe.offset.z * 100.0f, AUTO_BED_LEVEL_ZOFFSET_VP)); - sendData(feedrate_percentage, PRINT_SPEED_RATE_VP); + sendData(motion.feedrate_percentage, PRINT_SPEED_RATE_VP); updateTempE0(); updateTempBed(); @@ -1621,7 +1621,7 @@ void RTS::onIdle() { queue.enqueue_now(F("G0 F3000 X0 Y0\nM18 S0")); } - TERN_(HAS_Z_AXIS, sendData(current_position.z * 10.0f, AXIS_Z_COORD_VP)); + TERN_(HAS_Z_AXIS, sendData(motion.position.z * 10.0f, AXIS_Z_COORD_VP)); #if HAS_HOTEND if (last_target_temperature[0] != thermalManager.degTargetHotend(0)) { @@ -1736,9 +1736,9 @@ void RTS_MoveAxisHoming() { waitway = 0; } - TERN_(HAS_X_AXIS, rts.sendData(current_position.x * 10.0f, AXIS_X_COORD_VP)); - TERN_(HAS_Y_AXIS, rts.sendData(current_position.y * 10.0f, AXIS_Y_COORD_VP)); - TERN_(HAS_Z_AXIS, rts.sendData(current_position.z * 10.0f, AXIS_Z_COORD_VP)); + TERN_(HAS_X_AXIS, rts.sendData(motion.position.x * 10.0f, AXIS_X_COORD_VP)); + TERN_(HAS_Y_AXIS, rts.sendData(motion.position.y * 10.0f, AXIS_Y_COORD_VP)); + TERN_(HAS_Z_AXIS, rts.sendData(motion.position.z * 10.0f, AXIS_Z_COORD_VP)); } #endif // SOVOL_SV06_RTS diff --git a/Marlin/src/lcd/tft/touch.cpp b/Marlin/src/lcd/tft/touch.cpp index 661a013323..62619d90b3 100644 --- a/Marlin/src/lcd/tft/touch.cpp +++ b/Marlin/src/lcd/tft/touch.cpp @@ -273,7 +273,7 @@ void Touch::touch(touch_control_t * const control) { case FEEDRATE: ui.clear_for_drawing(); - MenuItem_int3::action(GET_TEXT_F(MSG_SPEED), &feedrate_percentage, SPEED_EDIT_MIN, SPEED_EDIT_MAX); + MenuItem_int3::action(GET_TEXT_F(MSG_SPEED), &motion.feedrate_percentage, SPEED_EDIT_MIN, SPEED_EDIT_MAX); break; #if HAS_EXTRUDERS diff --git a/Marlin/src/lcd/tft/ui_color_ui.cpp b/Marlin/src/lcd/tft/ui_color_ui.cpp index 53b3b0d068..b6871a6a16 100644 --- a/Marlin/src/lcd/tft/ui_color_ui.cpp +++ b/Marlin/src/lcd/tft/ui_color_ui.cpp @@ -263,26 +263,26 @@ void MarlinUI::draw_status_screen() { #if HAS_X_AXIS && defined(X_MARK_X) && defined(X_MARK_Y) && defined(X_VALUE_X) && defined(X_VALUE_Y) tft.add_text(X_MARK_X, X_MARK_Y, COLOR_AXIS_HOMED, "X"); - const bool nhx = axis_should_home(X_AXIS); - tft_string.set(blink && nhx ? "?" : ftostr4sign(LOGICAL_X_POSITION(current_position.x))); + const bool nhx = motion.axis_should_home(X_AXIS); + tft_string.set(blink && nhx ? "?" : ftostr4sign(motion.logical_x(motion.position.x))); tft.add_text(X_VALUE_X, X_VALUE_Y, nhx ? COLOR_AXIS_NOT_HOMED : COLOR_AXIS_HOMED, tft_string); #endif #if HAS_Y_AXIS && defined(Y_MARK_X) && defined(Y_MARK_Y) && defined(Y_VALUE_X) && defined(Y_VALUE_Y) tft.add_text(Y_MARK_X, Y_MARK_Y, COLOR_AXIS_HOMED, "Y"); - const bool nhy = axis_should_home(Y_AXIS); - tft_string.set(blink && nhy ? "?" : ftostr4sign(LOGICAL_Y_POSITION(current_position.y))); + const bool nhy = motion.axis_should_home(Y_AXIS); + tft_string.set(blink && nhy ? "?" : ftostr4sign(motion.logical_y(motion.position.y))); tft.add_text(Y_VALUE_X, Y_VALUE_Y, nhy ? COLOR_AXIS_NOT_HOMED : COLOR_AXIS_HOMED, tft_string); #endif #if HAS_Z_AXIS && defined(Z_MARK_X) && defined(Z_MARK_Y) && defined(Z_VALUE_X) && defined(Z_VALUE_Y) && defined(Z_VALUE_OFFSET) tft.add_text(Z_MARK_X, Z_MARK_Y, COLOR_AXIS_HOMED, "Z"); uint16_t offset = Z_VALUE_OFFSET; - const bool nhz = axis_should_home(Z_AXIS); + const bool nhz = motion.axis_should_home(Z_AXIS); if (blink && nhz) tft_string.set('?'); else { - const float z = LOGICAL_Z_POSITION(current_position.z); + const float z = motion.logical_z(motion.position.z); tft_string.set(ftostr52sp((int16_t)z)); tft_string.rtrim(); offset += tft_string.width(); @@ -296,8 +296,8 @@ void MarlinUI::draw_status_screen() { #if ENABLED(LCD_SHOW_E_TOTAL) && defined(E_MARK_X) && defined(E_MARK_Y) && defined(E_VALUE_X) && defined(E_VALUE_Y) tft.add_text(E_MARK_X, E_MARK_Y, COLOR_AXIS_HOMED, "E"); if (marlin.printingIsActive()) { - const uint8_t escale = e_move_accumulator >= 10000.0f ? 10 : 1; // After 10m switch to cm to fit into 4 digits output of ftostr4sign() - tft_string.set(ftostr4sign(e_move_accumulator / escale)); + const uint8_t escale = motion.e_move_accumulator >= 10000.0f ? 10 : 1; // After 10m switch to cm to fit into 4 digits output of ftostr4sign() + tft_string.set(ftostr4sign(motion.e_move_accumulator / escale)); const uint16_t e_value_x = E_VALUE_X; tft_string.add(escale == 10 ? " cm" : " mm"); tft.add_text(e_value_x, E_VALUE_Y, COLOR_AXIS_HOMED, tft_string); @@ -311,9 +311,9 @@ void MarlinUI::draw_status_screen() { // Feed rate tft.canvas(FEEDRATE_X, FEEDRATE_Y, FEEDRATE_W, FEEDRATE_H); tft.set_background(COLOR_BACKGROUND); - uint16_t color = feedrate_percentage == 100 ? COLOR_RATE_100 : COLOR_RATE_ALTERED; + uint16_t color = motion.feedrate_percentage == 100 ? COLOR_RATE_100 : COLOR_RATE_ALTERED; tft.add_image(0, 0, imgFeedRate, color); - tft_string.set(i16tostr3rj(feedrate_percentage)); + tft_string.set(i16tostr3rj(motion.feedrate_percentage)); tft_string.add('%'); tft.add_text(36, tft_string.vcenter(30), color, tft_string); TERN_(TOUCH_SCREEN, touch.add_control(FEEDRATE, FEEDRATE_X, FEEDRATE_Y, FEEDRATE_W, FEEDRATE_H)); @@ -324,10 +324,10 @@ void MarlinUI::draw_status_screen() { tft.set_background(COLOR_BACKGROUND); color = planner.flow_percentage[0] == 100 ? COLOR_RATE_100 : COLOR_RATE_ALTERED; tft.add_image(FLOWRATE_ICON_X, FLOWRATE_ICON_X, imgFlowRate, color); - tft_string.set(i16tostr3rj(planner.flow_percentage[active_extruder])); + tft_string.set(i16tostr3rj(planner.flow_percentage[motion.extruder])); tft_string.add('%'); tft.add_text(FLOWRATE_TEXT_X, FLOWRATE_TEXT_Y, color, tft_string); - TERN_(TOUCH_SCREEN, touch.add_control(FLOWRATE, FLOWRATE_X, FLOWRATE_Y, FLOWRATE_W, FLOWRATE_H, active_extruder)); + TERN_(TOUCH_SCREEN, touch.add_control(FLOWRATE, FLOWRATE_X, FLOWRATE_Y, FLOWRATE_W, FLOWRATE_H, motion.extruder)); #endif #if ENABLED(TOUCH_SCREEN) @@ -422,13 +422,13 @@ void MenuEditItemBase::draw_edit_screen(FSTR_P const ftpl, const char * const va tft_string.set(X_LBL); tft.add_text(UBL_X_LABEL_X, MENU_TEXT_Y, COLOR_MENU_TEXT, tft_string); - tft_string.set(ftostr52(LOGICAL_X_POSITION(current_position.x))); + tft_string.set(ftostr52(motion.logical_x(motion.position.x))); tft_string.trim(); tft.add_text(UBL_X_TEXT_X, MENU_TEXT_Y, COLOR_MENU_VALUE, tft_string); tft_string.set(Y_LBL); tft.add_text(UBL_Y_LABEL_X, MENU_TEXT_Y, COLOR_MENU_TEXT, tft_string); - tft_string.set(ftostr52(LOGICAL_X_POSITION(current_position.y))); + tft_string.set(ftostr52(motion.logical_x(motion.position.y))); tft_string.trim(); tft.add_text(UBL_Y_TEXT_X, MENU_TEXT_Y, COLOR_MENU_VALUE, tft_string); } @@ -530,7 +530,7 @@ void MenuItem_confirm::draw_select_screen(FSTR_P const yes, FSTR_P const no, con for (uint16_t x = 0; x < (GRID_MAX_POINTS_X); x++) for (uint16_t y = 0; y < (GRID_MAX_POINTS_Y); y++) - if (position_is_reachable({ bedlevel.get_mesh_x(x), bedlevel.get_mesh_y(y) })) + if (motion.can_reach({ bedlevel.get_mesh_x(x), bedlevel.get_mesh_y(y) })) tft.add_bar(1 + (x * 2 + 1) * (UBL_GRID_W - 4) / (GRID_MAX_POINTS_X) / 2, UBL_GRID_H - 3 - ((y * 2 + 1) * (UBL_GRID_H - 4) / (GRID_MAX_POINTS_Y) / 2), 2, 2, COLOR_UBL); tft.add_rectangle((x_plot * 2 + 1) * (UBL_GRID_W - 4) / (GRID_MAX_POINTS_X) / 2 - 1, UBL_GRID_H - 5 - ((y_plot * 2 + 1) * (UBL_GRID_H - 4) / (GRID_MAX_POINTS_Y) / 2), 6, 6, COLOR_UBL); diff --git a/Marlin/src/lcd/tft/ui_common.cpp b/Marlin/src/lcd/tft/ui_common.cpp index b16b3e80a0..9113aafdad 100644 --- a/Marlin/src/lcd/tft/ui_common.cpp +++ b/Marlin/src/lcd/tft/ui_common.cpp @@ -82,11 +82,11 @@ void moveAxis(const AxisEnum axis, const int8_t direction) { diff = 0; const int16_t babystep_increment = direction * BABYSTEP_SIZE_Z; - const bool do_probe = DISABLED(BABYSTEP_HOTEND_Z_OFFSET) || active_extruder == 0; + const bool do_probe = DISABLED(BABYSTEP_HOTEND_Z_OFFSET) || motion.extruder == 0; const float bsDiff = planner.mm_per_step[Z_AXIS] * babystep_increment, new_probe_offset = probe.offset.z + bsDiff, new_offs = TERN(BABYSTEP_HOTEND_Z_OFFSET - , do_probe ? new_probe_offset : hotend_offset[active_extruder].z - bsDiff + , do_probe ? new_probe_offset : hotend_offset[motion.extruder].z - bsDiff , new_probe_offset ); if (WITHIN(new_offs, PROBE_OFFSET_ZMIN, PROBE_OFFSET_ZMAX)) { @@ -94,7 +94,7 @@ void moveAxis(const AxisEnum axis, const int8_t direction) { if (do_probe) probe.offset.z = new_offs; else - TERN(BABYSTEP_HOTEND_Z_OFFSET, hotend_offset[active_extruder].z = new_offs, NOOP); + TERN(BABYSTEP_HOTEND_Z_OFFSET, hotend_offset[motion.extruder].z = new_offs, NOOP); drawMessage_P(NUL_STR); // Clear the error } else @@ -104,12 +104,12 @@ void moveAxis(const AxisEnum axis, const int8_t direction) { // Only change probe.offset.z probe.offset.z += diff; - if (direction < 0 && current_position.z < PROBE_OFFSET_ZMIN) { - current_position.z = PROBE_OFFSET_ZMIN; + if (direction < 0 && motion.position.z < PROBE_OFFSET_ZMIN) { + motion.position.z = PROBE_OFFSET_ZMIN; drawMessage(GET_TEXT_F(MSG_LCD_SOFT_ENDSTOPS)); } - else if (direction > 0 && current_position.z > PROBE_OFFSET_ZMAX) { - current_position.z = PROBE_OFFSET_ZMAX; + else if (direction > 0 && motion.position.z > PROBE_OFFSET_ZMAX) { + motion.position.z = PROBE_OFFSET_ZMAX; drawMessage(GET_TEXT_F(MSG_LCD_SOFT_ENDSTOPS)); } else @@ -123,13 +123,13 @@ void moveAxis(const AxisEnum axis, const int8_t direction) { if (diff && !ui.manual_move.processing) { // Get motion limit from software endstops, if any float min, max; - soft_endstop.get_manual_axis_limits(axis, min, max); + motion.soft_endstop.get_manual_axis_limits(axis, min, max); // Delta limits XY based on the current offset from center // This assumes the center is 0,0 #if ENABLED(DELTA) if (axis != Z_AXIS && TERN1(HAS_EXTRUDERS, axis != E_AXIS)) { - max = SQRT(FLOAT_SQ(PRINTABLE_RADIUS) - sq(current_position[Y_AXIS - axis])); // (Y_AXIS - axis) == the other axis + max = SQRT(FLOAT_SQ(PRINTABLE_RADIUS) - sq(motion.position[Y_AXIS - axis])); // (Y_AXIS - axis) == the other axis min = -max; } #endif diff --git a/Marlin/src/libs/nozzle.cpp b/Marlin/src/libs/nozzle.cpp index bfe51ed97a..7c1acee656 100644 --- a/Marlin/src/libs/nozzle.cpp +++ b/Marlin/src/libs/nozzle.cpp @@ -47,30 +47,30 @@ Nozzle nozzle; */ void Nozzle::stroke(const xyz_pos_t &start, const xyz_pos_t &end, const uint8_t strokes) { #if ENABLED(NOZZLE_CLEAN_GOBACK) - const xyz_pos_t oldpos = current_position; + const xyz_pos_t oldpos = motion.position; #endif // Move Z (and XY) to the starting point, if needed #if DISABLED(NOZZLE_CLEAN_NO_Z) - do_blocking_move_to(start); + motion.blocking_move(start); #endif // Run the stroke pattern for (uint8_t i = 0; i <= strokes; ++i) { #if ENABLED(NOZZLE_CLEAN_NO_Y) if (i & 1) - do_blocking_move_to_x(end.x); + motion.blocking_move_x(end.x); else - do_blocking_move_to_x(start.x); + motion.blocking_move_x(start.x); #else if (i & 1) - do_blocking_move_to_xy(end); + motion.blocking_move_xy(end); else - do_blocking_move_to_xy(start); + motion.blocking_move_xy(start); #endif } - TERN_(NOZZLE_CLEAN_GOBACK, do_blocking_move_to(oldpos)); + TERN_(NOZZLE_CLEAN_GOBACK, motion.blocking_move(oldpos)); } #endif @@ -89,13 +89,13 @@ Nozzle nozzle; if (!diff.x || !diff.y) return; #if ENABLED(NOZZLE_CLEAN_GOBACK) - const xyz_pos_t back = current_position; + const xyz_pos_t back = motion.position; #endif #if ENABLED(NOZZLE_CLEAN_NO_Z) - do_blocking_move_to_xy(start); + motion.blocking_move_xy(start); #else - do_blocking_move_to(start); + motion.blocking_move(start); #endif const uint8_t zigs = objects << 1; @@ -106,20 +106,20 @@ Nozzle nozzle; for (int8_t i = 0; i < zigs; i++) { side = (i & 1) ? &end : &start; if (horiz) - do_blocking_move_to_xy(start.x + i * P, side->y); + motion.blocking_move_xy(start.x + i * P, side->y); else - do_blocking_move_to_xy(side->x, start.y + i * P); + motion.blocking_move_xy(side->x, start.y + i * P); } for (int8_t i = zigs; i >= 0; i--) { side = (i & 1) ? &end : &start; if (horiz) - do_blocking_move_to_xy(start.x + i * P, side->y); + motion.blocking_move_xy(start.x + i * P, side->y); else - do_blocking_move_to_xy(side->x, start.y + i * P); + motion.blocking_move_xy(side->x, start.y + i * P); } } - TERN_(NOZZLE_CLEAN_GOBACK, do_blocking_move_to(back)); + TERN_(NOZZLE_CLEAN_GOBACK, motion.blocking_move(back)); } #endif @@ -136,21 +136,21 @@ Nozzle nozzle; if (strokes == 0) return; #if ENABLED(NOZZLE_CLEAN_GOBACK) - const xyz_pos_t back = current_position; + const xyz_pos_t back = motion.position; #endif - TERN(NOZZLE_CLEAN_NO_Z, do_blocking_move_to_xy, do_blocking_move_to)(start); + motion.TERN(NOZZLE_CLEAN_NO_Z, blocking_move_xy, blocking_move)(start); for (uint8_t s = 0; s < strokes; ++s) for (uint8_t i = 0; i < NOZZLE_CLEAN_CIRCLE_FN; ++i) - do_blocking_move_to_xy( + motion.blocking_move_xy( middle.x + sin((RADIANS(360) / NOZZLE_CLEAN_CIRCLE_FN) * i) * radius, middle.y + cos((RADIANS(360) / NOZZLE_CLEAN_CIRCLE_FN) * i) * radius ); // Let's be safe - do_blocking_move_to_xy(start); + motion.blocking_move_xy(start); - TERN_(NOZZLE_CLEAN_GOBACK, do_blocking_move_to(back)); + TERN_(NOZZLE_CLEAN_GOBACK, motion.blocking_move(back)); } #endif @@ -167,7 +167,7 @@ Nozzle nozzle; xyz_pos_t middle[HOTENDS] = NOZZLE_CLEAN_CIRCLE_MIDDLE; #endif - const uint8_t arrPos = ANY(SINGLENOZZLE, MIXING_EXTRUDER) ? 0 : active_extruder; + const uint8_t arrPos = ANY(SINGLENOZZLE, MIXING_EXTRUDER) ? 0 : motion.extruder; switch (pattern) { #if DISABLED(NOZZLE_CLEAN_PATTERN_LINE) @@ -197,16 +197,16 @@ Nozzle nozzle; #if HAS_SOFTWARE_ENDSTOPS #define LIMIT_AXIS(A) do{ \ - LIMIT( start[arrPos].A, soft_endstop.min.A, soft_endstop.max.A); \ - LIMIT( end[arrPos].A, soft_endstop.min.A, soft_endstop.max.A); \ - TERN_(NOZZLE_CLEAN_PATTERN_CIRCLE, LIMIT(middle[arrPos].A, soft_endstop.min.A, soft_endstop.max.A)); \ + LIMIT( start[arrPos].A, motion.soft_endstop.min.A, motion.soft_endstop.max.A); \ + LIMIT( end[arrPos].A, motion.soft_endstop.min.A, motion.soft_endstop.max.A); \ + TERN_(NOZZLE_CLEAN_PATTERN_CIRCLE, LIMIT(middle[arrPos].A, motion.soft_endstop.min.A, motion.soft_endstop.max.A)); \ }while(0) - if (soft_endstop.enabled()) { + if (motion.soft_endstop.enabled()) { LIMIT_AXIS(x); LIMIT_AXIS(y); LIMIT_AXIS(z); #if ENABLED(NOZZLE_CLEAN_PATTERN_CIRCLE) - if (pattern == 2 && !(WITHIN(middle[arrPos].x, soft_endstop.min.x + radius, soft_endstop.max.x - radius) - && WITHIN(middle[arrPos].y, soft_endstop.min.y + radius, soft_endstop.max.y - radius)) + if (pattern == 2 && !(WITHIN(middle[arrPos].x, motion.soft_endstop.min.x + radius, motion.soft_endstop.max.x - radius) + && WITHIN(middle[arrPos].y, motion.soft_endstop.min.y + radius, motion.soft_endstop.max.y - radius)) ) { SERIAL_ECHOLNPGM("Warning: Radius Out of Range"); return; } @@ -222,10 +222,10 @@ Nozzle nozzle; #endif if (TERN1(NOZZLE_CLEAN_PATTERN_CIRCLE, pattern != 2)) { - if (!TEST(cleans, X_AXIS)) start[arrPos].x = end[arrPos].x = current_position.x; - if (!TEST(cleans, Y_AXIS)) start[arrPos].y = end[arrPos].y = current_position.y; + if (!TEST(cleans, X_AXIS)) start[arrPos].x = end[arrPos].x = motion.position.x; + if (!TEST(cleans, Y_AXIS)) start[arrPos].y = end[arrPos].y = motion.position.y; } - if (!TEST(cleans, Z_AXIS)) start[arrPos].z = end[arrPos].z = current_position.z; + if (!TEST(cleans, Z_AXIS)) start[arrPos].z = end[arrPos].z = motion.position.z; switch (pattern) { // no default clause as pattern is already validated #if ENABLED(NOZZLE_CLEAN_PATTERN_LINE) @@ -252,7 +252,7 @@ Nozzle nozzle; #ifdef NOZZLE_PARK_Z_RAISE_MIN NOZZLE_PARK_Z_RAISE_MIN + // Minimum raise... #endif - current_position.z // ...over current position + motion.position.z // ...over current position ) ); } @@ -264,15 +264,15 @@ Nozzle nozzle; switch (z_action) { case 1: // Go to Z-park height - do_blocking_move_to_z(park.z, fr_z); + motion.blocking_move_z(park.z, fr_z); break; case 2: // Raise by Z-park height - do_blocking_move_to_z(_MIN(current_position.z + park.z, Z_MAX_POS), fr_z); + motion.blocking_move_z(_MIN(motion.position.z + park.z, Z_MAX_POS), fr_z); break; case 3: { // Raise by NOZZLE_PARK_Z_RAISE_MIN, bypass XY-park position - do_blocking_move_to_z(park_mode_0_height(0), fr_z); + motion.blocking_move_z(park_mode_0_height(0), fr_z); goto SKIP_XY_MOVE; } break; @@ -280,7 +280,7 @@ Nozzle nozzle; break; default: // Raise by NOZZLE_PARK_Z_RAISE_MIN, use park.z as a minimum height - do_blocking_move_to_z(park_mode_0_height(park.z), fr_z); + motion.blocking_move_z(park_mode_0_height(park.z), fr_z); break; } #endif // HAS_Z_AXIS @@ -291,18 +291,18 @@ Nozzle nozzle; #endif constexpr feedRate_t fr_xy = NOZZLE_PARK_XY_FEEDRATE; switch (NOZZLE_PARK_MOVE) { - case 0: do_blocking_move_to_xy(park, fr_xy); break; - case 1: do_blocking_move_to_x(park.x, fr_xy); break; - case 2: do_blocking_move_to_y(park.y, fr_xy); break; - case 3: do_blocking_move_to_x(park.x, fr_xy); - do_blocking_move_to_y(park.y, fr_xy); break; - case 4: do_blocking_move_to_y(park.y, fr_xy); - do_blocking_move_to_x(park.x, fr_xy); break; + case 0: motion.blocking_move_xy(park, fr_xy); break; + case 1: motion.blocking_move_x(park.x, fr_xy); break; + case 2: motion.blocking_move_y(park.y, fr_xy); break; + case 3: motion.blocking_move_x(park.x, fr_xy); + motion.blocking_move_y(park.y, fr_xy); break; + case 4: motion.blocking_move_y(park.y, fr_xy); + motion.blocking_move_x(park.x, fr_xy); break; } } SKIP_XY_MOVE: - report_current_position(); + motion.report_position(); } #endif // NOZZLE_PARK_FEATURE diff --git a/Marlin/src/module/delta.cpp b/Marlin/src/module/delta.cpp index d211c3a133..b9e70f5e5a 100644 --- a/Marlin/src/module/delta.cpp +++ b/Marlin/src/module/delta.cpp @@ -64,7 +64,7 @@ float delta_safe_distance_from_top(); void refresh_delta_clip_start_height() { delta_clip_start_height = TERN(HAS_SOFTWARE_ENDSTOPS, - soft_endstop.max.z, + motion.soft_endstop.max.z, DIFF_TERN(HAS_BED_PROBE, delta_height, probe.offset.z) ) - delta_safe_distance_from_top(); } @@ -84,8 +84,8 @@ void recalc_delta_settings() { delta_diagonal_rod_2_tower.set(sq(delta_diagonal_rod + delta_diagonal_rod_trim.a), sq(delta_diagonal_rod + delta_diagonal_rod_trim.b), sq(delta_diagonal_rod + delta_diagonal_rod_trim.c)); - update_software_endstops(Z_AXIS); - set_all_unhomed(); + motion.update_software_endstops(Z_AXIS); + motion.set_all_unhomed(); } /** @@ -106,14 +106,14 @@ void recalc_delta_settings() { #define DELTA_DEBUG(VAR) do { \ SERIAL_ECHOLNPGM_P(PSTR("Cartesian X"), VAR.x, SP_Y_STR, VAR.y, SP_Z_STR, VAR.z); \ - SERIAL_ECHOLNPGM_P(PSTR("Delta A"), delta.a, SP_B_STR, delta.b, SP_C_STR, delta.c); \ + SERIAL_ECHOLNPGM_P(PSTR("Delta A"), motion.delta.a, SP_B_STR, motion.delta.b, SP_C_STR, motion.delta.c); \ }while(0) void inverse_kinematics(const xyz_pos_t &raw) { #if HAS_HOTEND_OFFSET // Delta hotend offsets must be applied in Cartesian space with no "spoofing" - xyz_pos_t pos = { raw.x - hotend_offset[active_extruder].x, - raw.y - hotend_offset[active_extruder].y, + xyz_pos_t pos = { raw.x - hotend_offset[motion.extruder].x, + raw.y - hotend_offset[motion.extruder].y, raw.z }; DELTA_IK(pos); //DELTA_DEBUG(pos); @@ -130,10 +130,10 @@ void inverse_kinematics(const xyz_pos_t &raw) { float delta_safe_distance_from_top() { xyz_pos_t cartesian{0}; inverse_kinematics(cartesian); - const float centered_extent = delta.a; + const float centered_extent = motion.delta.a; cartesian.y = PRINTABLE_RADIUS; inverse_kinematics(cartesian); - return ABS(centered_extent - delta.a); + return ABS(centered_extent - motion.delta.a); } /** @@ -159,7 +159,7 @@ float delta_safe_distance_from_top() { * based on a Java function from "Delta Robot Kinematics V3" * by Steve Graves * - * The result is stored in the cartes[] array. + * The result is stored in the motion.cartes[] array. */ void forward_kinematics(const float z1, const float z2, const float z3) { // Create a vector in old coordinates along x axis of new coordinate @@ -207,9 +207,9 @@ void forward_kinematics(const float z1, const float z2, const float z3) { // Start from the origin of the old coordinates and add vectors in the // old coords that represent the Xnew, Ynew and Znew to find the point // in the old system. - cartes.set(delta_tower[A_AXIS].x + ex[0] * Xnew + ey[0] * Ynew - ez[0] * Znew, - delta_tower[A_AXIS].y + ex[1] * Xnew + ey[1] * Ynew - ez[1] * Znew, - z1 + ex[2] * Xnew + ey[2] * Ynew - ez[2] * Znew); + motion.cartes.set(delta_tower[A_AXIS].x + ex[0] * Xnew + ey[0] * Ynew - ez[0] * Znew, + delta_tower[A_AXIS].y + ex[1] * Xnew + ey[1] * Ynew - ez[1] * Znew, + z1 + ex[2] * Xnew + ey[2] * Ynew - ez[2] * Znew); } /** @@ -220,9 +220,9 @@ void home_delta() { DEBUG_SECTION(log_home_delta, "home_delta", DEBUGGING(LEVELING)); // Init the current position of all carriages to 0,0,0 - current_position.reset(); - destination.reset(); - sync_plan_position(); + motion.position.reset(); + motion.destination.reset(); + motion.sync_plan_position(); // Disable stealthChop if used. Enable diag1 pin on driver. #if ENABLED(SENSORLESS_HOMING) @@ -244,8 +244,8 @@ void home_delta() { TERN_(HAS_HOMING_CURRENT, set_homing_current(Z_AXIS)); // Move all carriages together linearly until an endstop is hit. - current_position.z = DIFF_TERN(HAS_BED_PROBE, delta_height + 10, probe.offset.z); - line_to_current_position(homing_feedrate(Z_AXIS)); + motion.position.z = DIFF_TERN(HAS_BED_PROBE, delta_height + 10, probe.offset.z); + motion.goto_current_position(motion.homing_feedrate(Z_AXIS)); planner.synchronize(); TERN_(HAS_DELTA_SENSORLESS_PROBING, endstops.report_states()); @@ -272,23 +272,23 @@ void home_delta() { // At least one carriage has reached the top. // Now re-home each carriage separately. - homeaxis(A_AXIS); - homeaxis(B_AXIS); - homeaxis(C_AXIS); + motion.homeaxis(A_AXIS); + motion.homeaxis(B_AXIS); + motion.homeaxis(C_AXIS); // Set all carriages to their home positions // Do this here all at once for Delta, because // XYZ isn't ABC. Applying this per-tower would // give the impression that they are the same. - LOOP_ABC(i) set_axis_is_at_home((AxisEnum)i); + LOOP_ABC(i) motion.set_axis_is_at_home((AxisEnum)i); - sync_plan_position(); + motion.sync_plan_position(); #if DISABLED(DELTA_HOME_TO_SAFE_ZONE) && defined(HOMING_BACKOFF_POST_MM) constexpr xyz_float_t endstop_backoff = HOMING_BACKOFF_POST_MM; if (endstop_backoff.z) { - current_position.z -= ABS(endstop_backoff.z) * Z_HOME_DIR; - line_to_current_position(homing_feedrate(Z_AXIS)); + motion.position.z -= ABS(endstop_backoff.z) * Z_HOME_DIR; + motion.goto_current_position(motion.homing_feedrate(Z_AXIS)); } #endif } diff --git a/Marlin/src/module/delta.h b/Marlin/src/module/delta.h index 92e647d6d9..3aa5d1b51c 100644 --- a/Marlin/src/module/delta.h +++ b/Marlin/src/module/delta.h @@ -79,7 +79,7 @@ void recalc_delta_settings(); ) \ ) -#define DELTA_IK(V) delta.set(DELTA_Z(V, A_AXIS), DELTA_Z(V, B_AXIS), DELTA_Z(V, C_AXIS)) +#define DELTA_IK(V) motion.delta.set(DELTA_Z(V, A_AXIS), DELTA_Z(V, B_AXIS), DELTA_Z(V, C_AXIS)) void inverse_kinematics(const xyz_pos_t &raw); @@ -114,7 +114,7 @@ void refresh_delta_clip_start_height(); * based on a Java function from "Delta Robot Kinematics V3" * by Steve Graves * - * The result is stored in the cartes[] array. + * The result is stored in the motion.cartes[] array. */ void forward_kinematics(const float z1, const float z2, const float z3); diff --git a/Marlin/src/module/endstops.cpp b/Marlin/src/module/endstops.cpp index 5269d942ad..2967a8af1d 100644 --- a/Marlin/src/module/endstops.cpp +++ b/Marlin/src/module/endstops.cpp @@ -364,7 +364,7 @@ void Endstops::event_handler() { #if ENABLED(SD_ABORT_ON_ENDSTOP_HIT) if (planner.abort_on_endstop_hit) { card.abortFilePrintNow(); - quickstop_stepper(); + motion.quickstop_stepper(); thermalManager.disable_all_heaters(); #ifdef SD_ABORT_ON_ENDSTOP_HIT_GCODE queue.clear(); diff --git a/Marlin/src/module/ft_motion.cpp b/Marlin/src/module/ft_motion.cpp index 45e7b9c93e..7042c0346c 100644 --- a/Marlin/src/module/ft_motion.cpp +++ b/Marlin/src/module/ft_motion.cpp @@ -688,7 +688,7 @@ void FTMotion::fill_stepper_plan_buffer() { // Start Resonance Testing void FTMotion::start_resonance_test() { - home_if_needed(); // Ensure known axes first + motion.home_if_needed(); // Ensure known axes first ftm_resonance_test_params_t &p = rtg.rt_params; @@ -697,10 +697,10 @@ void FTMotion::fill_stepper_plan_buffer() { p.accel_per_hz = 15.0f; // Always move to the center of the bed - do_blocking_move_to_xy(X_CENTER, Y_CENTER, Z_CLEARANCE_FOR_HOMING); + motion.blocking_move_xy(X_CENTER, Y_CENTER, Z_CLEARANCE_FOR_HOMING); // Start test at the current position with the configured time-step - rtg.start(current_position, FTM_TS); + rtg.start(motion.position, FTM_TS); } #endif // FTM_RESONANCE_TEST diff --git a/Marlin/src/module/motion.cpp b/Marlin/src/module/motion.cpp index 8a92482d82..326b65a2c6 100644 --- a/Marlin/src/module/motion.cpp +++ b/Marlin/src/module/motion.cpp @@ -38,10 +38,6 @@ #include "../lcd/marlinui.h" #endif -#if ENABLED(POLAR) - #include "polar.h" -#endif - #if HAS_BED_PROBE #include "probe.h" #endif @@ -77,12 +73,21 @@ #include "../feature/bedlevel/bdl/bdl.h" #endif +Motion motion; + // Relative Mode. Enable with G91, disable with G90. -bool relative_mode; // = false +bool Motion::relative_mode; // = false + +// The active extruder (tool). Set with T command. +#if HAS_MULTI_EXTRUDER + uint8_t Motion::extruder = 0; // = 0 +#else + constexpr uint8_t Motion::extruder; +#endif #if HAS_Z_AXIS - // If Z has been powered on trust that the real Z is >= current_position.z - bool z_min_trusted; // = false + // If Z has been powered on trust that the real Z is >= motion.position.z + bool Motion::z_min_trusted; // = false #endif // Warn for unexpected TPARA home position @@ -101,10 +106,10 @@ bool relative_mode; // = false /** * Cartesian Current Position * Used to track the native machine position as moves are queued. - * Used by 'line_to_current_position' to do a move after changing it. + * Used by 'goto_current_position' to do a move after changing it. * Used by 'sync_plan_position' to update 'planner.position'. */ -xyze_pos_t current_position = LOGICAL_AXIS_ARRAY(0, +xyze_pos_t Motion::position = LOGICAL_AXIS_ARRAY(0, X_HOME_POS, Y_HOME_POS, #ifdef Z_IDLE_HEIGHT Z_IDLE_HEIGHT @@ -120,15 +125,13 @@ xyze_pos_t current_position = LOGICAL_AXIS_ARRAY(0, * and expected by functions like 'prepare_line_to_destination'. * G-codes can set destination using 'get_destination_from_command' */ -xyze_pos_t destination; // {0} +xyze_pos_t Motion::destination; // {0} -// The active extruder (tool). Set with T command. -#if HAS_MULTI_EXTRUDER - uint8_t active_extruder = 0; // = 0 -#endif +// Scratch space for a cartesian result +xyz_pos_t Motion::cartes; #if ENABLED(LCD_SHOW_E_TOTAL) - float e_move_accumulator; // = 0 + float Motion::e_move_accumulator; // = 0 #endif // Extruder offsets @@ -153,21 +156,21 @@ xyze_pos_t destination; // {0} #ifndef DEFAULT_FEEDRATE_MM_M #define DEFAULT_FEEDRATE_MM_M 4000 #endif -feedRate_t feedrate_mm_s = MMM_TO_MMS(DEFAULT_FEEDRATE_MM_M); -int16_t feedrate_percentage = 100; -#if ENABLED(EDITABLE_HOMING_FEEDRATE) - xyz_feedrate_t homing_feedrate_mm_m = HOMING_FEEDRATE_MM_M; -#endif +feedRate_t Motion::feedrate_mm_s = MMM_TO_MMS(DEFAULT_FEEDRATE_MM_M); +int16_t Motion::feedrate_percentage = 100; -// Cartesian conversion result goes here: -xyz_pos_t cartes; +#if ENABLED(EDITABLE_HOMING_FEEDRATE) + xyz_feedrate_t Motion::homing_feedrate_mm_m = HOMING_FEEDRATE_MM_M; +#else + constexpr xyz_feedrate_t Motion::homing_feedrate_mm_m; +#endif #if IS_KINEMATIC - abce_pos_t delta; + abce_pos_t Motion::delta; #if HAS_SCARA_OFFSET - abc_pos_t scara_home_offset; + abc_pos_t Motion::scara_home_offset; #endif // If it does not have software endstops, use the printable radius #if HAS_SOFTWARE_ENDSTOPS @@ -183,7 +186,7 @@ xyz_pos_t cartes; delta_max_radius_2 = sq(float(PRINTABLE_RADIUS)); #endif -#endif +#endif // IS_KINEMATIC /** * The workspace can be offset by some commands, or @@ -192,12 +195,12 @@ xyz_pos_t cartes; #if HAS_HOME_OFFSET // This offset is added to the configured home position. // Set by M206, M428, or menu item. Saved to EEPROM. - xyz_pos_t home_offset{0}; + xyz_pos_t Motion::home_offset{0}; #endif #if HAS_WORKSPACE_OFFSET // The above two are combined to save on computes - xyz_pos_t workspace_offset{0}; + xyz_pos_t Motion::workspace_offset{0}; #endif #if ABL_USES_GRID @@ -229,7 +232,7 @@ inline void report_logical_position(const xyze_pos_t &rpos) { // Report the real current position according to the steppers. // Forward kinematics and un-leveling are applied. -void report_real_position() { +void Motion::report_position_real() { get_cartesian_from_steppers(); xyze_pos_t npos = LOGICAL_AXIS_ARRAY( planner.get_axis_position_mm(E_AXIS), @@ -245,8 +248,8 @@ void report_real_position() { } // Report the logical current position according to the most recent G-code command -void report_current_position() { - report_logical_position(current_position); +void Motion::report_position() { + report_logical_position(position); report_more_positions(); } @@ -256,8 +259,8 @@ void report_current_position() { * suitable for debugging kinematics and leveling while avoiding planner sync that * definitively interrupts the printing flow. */ -void report_current_position_projected() { - report_logical_position(current_position); +void Motion::report_position_projected() { + report_logical_position(position); stepper.report_a_position(planner.position); } @@ -590,27 +593,27 @@ void report_current_position_projected() { #endif // HAS_HOMING_CURRENT #if ENABLED(AUTO_REPORT_POSITION) - AutoReporter position_auto_reporter; + AutoReporter Motion::position_auto_reporter; #endif #if ENABLED(REALTIME_REPORTING_COMMANDS) - M_StateEnum M_State_grbl = M_INIT; + M_StateEnum Motion::M_State_grbl = M_INIT; /** * Output the current grbl compatible state to serial while moving */ - void report_current_grblstate_moving() { SERIAL_ECHOLNPGM("S_XYZ:", int(M_State_grbl)); } + void Motion::report_current_grblstate_moving() { SERIAL_ECHOLNPGM("S_XYZ:", int(M_State_grbl)); } /** * Output the current position (processed) to serial while moving */ - void report_current_position_moving() { + void Motion::report_position_moving() { get_cartesian_from_steppers(); const xyz_pos_t lpos = cartes.asLogical(); SERIAL_ECHOPGM_P(LOGICAL_AXIS_PAIRED_LIST( - SP_E_LBL, current_position.e, + SP_E_LBL, position.e, X_LBL, lpos.x, SP_Y_LBL, lpos.y, SP_Z_LBL, lpos.z, SP_I_LBL, lpos.i, SP_J_LBL, lpos.j, SP_K_LBL, lpos.k, SP_U_LBL, lpos.u, SP_V_LBL, lpos.v, SP_W_LBL, lpos.w @@ -623,7 +626,7 @@ void report_current_position_projected() { /** * Set a Grbl-compatible state from the current marlin.state */ - M_StateEnum grbl_state_for_marlin_state() { + M_StateEnum Motion::grbl_state_for_marlin_state() { switch (marlin.state) { case MF_INITIALIZING: return M_INIT; case MF_SD_COMPLETE: return M_ALARM; @@ -640,7 +643,7 @@ void report_current_position_projected() { #if IS_KINEMATIC - bool position_is_reachable(const float rx, const float ry, const float inset/*=0.0f*/) { + bool Motion::can_reach(const float rx, const float ry, const float inset/*=0*/) { bool can_reach; @@ -693,10 +696,10 @@ void report_current_position_projected() { #else // CARTESIAN // Return true if the given position is within the machine bounds. - bool position_is_reachable(XY_LIST(const float rx, const float ry)) { + bool Motion::can_reach(XY_LIST(const float rx, const float ry)) { if (TERN0(HAS_Y_AXIS, !COORDINATE_OKAY(ry, Y_MIN_POS - fslop, Y_MAX_POS + fslop))) return false; #if ENABLED(DUAL_X_CARRIAGE) - if (active_extruder) + if (extruder) return COORDINATE_OKAY(rx, X2_MIN_POS - fslop, X2_MAX_POS + fslop); else return COORDINATE_OKAY(rx, X1_MIN_POS - fslop, X1_MAX_POS + fslop); @@ -708,7 +711,7 @@ void report_current_position_projected() { #endif // CARTESIAN -void home_if_needed(const bool keeplev/*=false*/) { +void Motion::home_if_needed(const bool keeplev/*=false*/) { if (!all_axes_trusted()) gcode.home_all_axes(keeplev); } @@ -716,7 +719,7 @@ void home_if_needed(const bool keeplev/*=false*/) { * Run out the planner buffer and re-sync the current * position from the last-updated stepper positions. */ -void quickstop_stepper() { +void Motion::quickstop_stepper() { planner.quick_stop(); planner.synchronize(); set_current_from_steppers_for_axis(ALL_AXES_ENUM); @@ -725,12 +728,12 @@ void quickstop_stepper() { #if ENABLED(REALTIME_REPORTING_COMMANDS) - void quickpause_stepper() { + void Motion::quickpause_stepper() { planner.quick_pause(); //planner.synchronize(); } - void quickresume_stepper() { + void Motion::quickresume_stepper() { planner.quick_resume(); //planner.synchronize(); } @@ -738,18 +741,18 @@ void quickstop_stepper() { #endif /** - * Set the planner/stepper positions directly from current_position with + * Set the planner/stepper positions directly from the current position with * no kinematic translation. Used for homing axes and cartesian/core syncing. */ -void sync_plan_position() { - if (DEBUGGING(LEVELING)) DEBUG_POS("sync_plan_position", current_position); - planner.set_position_mm(current_position); - //SERIAL_ECHOLNPGM("Sync_plan_position: ", current_position.x, ", ", current_position.y, ", ", current_position.z); +void Motion::sync_plan_position() { + if (DEBUGGING(LEVELING)) DEBUG_POS("sync_plan_position", position); + planner.set_position_mm(motion.position); + //SERIAL_ECHOLNPGM("Sync_plan_position: ", position.x, ", ", position.y, ", ", position.z); //SERIAL_EOL(); } #if HAS_EXTRUDERS - void sync_plan_position_e() { planner.set_e_position_mm(current_position.e); } + void Motion::sync_plan_position_e() { planner.set_e_position_mm(position.e); } #endif /** @@ -759,9 +762,9 @@ void sync_plan_position() { * The result is in the current coordinate space with * leveling applied. The coordinates need to be run through * unapply_leveling to obtain the "ideal" coordinates - * suitable for current_position, etc. + * suitable for motion.position, etc. */ -void get_cartesian_from_steppers() { +void Motion::get_cartesian_from_steppers() { #if ENABLED(DELTA) forward_kinematics(planner.get_axis_positions_mm()); #elif IS_SCARA @@ -789,17 +792,17 @@ void get_cartesian_from_steppers() { } /** - * Set the current_position for an axis based on + * Set position for an axis based on * the stepper positions, removing any leveling that * may have been applied. * * To prevent small shifts in axis position always call * sync_plan_position after updating axes with this. * - * To keep hosts in sync, always call report_current_position - * after updating the current_position. + * To keep hosts in sync, always call report_position + * after updating the position. */ -void set_current_from_steppers_for_axis(const AxisEnum axis) { +void Motion::set_current_from_steppers_for_axis(const AxisEnum axis) { get_cartesian_from_steppers(); xyze_pos_t pos = cartes; @@ -808,24 +811,24 @@ void set_current_from_steppers_for_axis(const AxisEnum axis) { TERN_(HAS_POSITION_MODIFIERS, planner.unapply_modifiers(pos, true)); if (axis == ALL_AXES_ENUM) - current_position = pos; + position = pos; else - current_position[axis] = pos[axis]; + position[axis] = pos[axis]; } /** * Move the planner to the current position from wherever it last moved * (or from wherever it has been told it is located). */ -void line_to_current_position(const feedRate_t fr_mm_s/*=feedrate_mm_s*/) { - planner.buffer_line(current_position, fr_mm_s); +void Motion::goto_current_position(const feedRate_t fr_mm_s/*=feedrate_mm_s*/) { + planner.buffer_line(position, fr_mm_s); } #if HAS_EXTRUDERS - void unscaled_e_move(const float length, const feedRate_t fr_mm_s) { + void Motion::unscaled_e_move(const float length, const feedRate_t fr_mm_s) { TERN_(HAS_FILAMENT_SENSOR, runout.reset()); - current_position.e += length / planner.e_factor[active_extruder]; - line_to_current_position(fr_mm_s); + position.e += length / planner.e_factor[extruder]; + goto_current_position(fr_mm_s); planner.synchronize(); } #endif @@ -833,9 +836,9 @@ void line_to_current_position(const feedRate_t fr_mm_s/*=feedrate_mm_s*/) { #if IS_KINEMATIC /** - * Buffer a fast move without interpolation. Set current_position to destination + * Buffer a fast move without interpolation. Set position to destination */ - void prepare_fast_move_to_destination(const feedRate_t scaled_fr_mm_s/*=MMS_SCALED(feedrate_mm_s)*/) { + void Motion::prepare_fast_move_to_destination(const feedRate_t scaled_fr_mm_s/*=mms_scaled()*/) { if (DEBUGGING(LEVELING)) DEBUG_POS("prepare_fast_move_to_destination", destination); //SERIAL_ECHOLNPGM("Prepare fast move to destination: ", destination.x , ",", destination.y, ",", destination.z, "," , destination.e); @@ -845,12 +848,12 @@ void line_to_current_position(const feedRate_t fr_mm_s/*=feedrate_mm_s*/) { // UBL segmented line will do Z-only moves in single segment bedlevel.line_to_destination_segmented(scaled_fr_mm_s); #else - if (current_position == destination) return; + if (position == destination) return; planner.buffer_line(destination, scaled_fr_mm_s); #endif - current_position = destination; + position = destination; } #endif // IS_KINEMATIC @@ -860,12 +863,12 @@ void line_to_current_position(const feedRate_t fr_mm_s/*=feedrate_mm_s*/) { * - Move at normal speed regardless of feedrate percentage. * - Extrude the specified length regardless of flow percentage. */ -void _internal_move_to_destination(const feedRate_t fr_mm_s/*=0.0f*/ +void Motion::_goto_destination_internal(const feedRate_t fr_mm_s/*=0.0f*/ OPTARG(IS_KINEMATIC, const bool is_fast/*=false*/) ) { REMEMBER(fr, feedrate_mm_s); REMEMBER(pct, feedrate_percentage, 100); - TERN_(HAS_EXTRUDERS, REMEMBER(fac, planner.e_factor[active_extruder], 1.0f)); + TERN_(HAS_EXTRUDERS, REMEMBER(fac, planner.e_factor[extruder], 1.0f)); if (fr_mm_s) feedrate_mm_s = fr_mm_s; if (TERN0(IS_KINEMATIC, is_fast)) @@ -876,10 +879,10 @@ void _internal_move_to_destination(const feedRate_t fr_mm_s/*=0.0f*/ #if SECONDARY_AXES - void secondary_axis_moves(SECONDARY_AXIS_ARGS_LC(const float), const feedRate_t fr_mm_s) { + void Motion::secondary_axis_moves(SECONDARY_AXIS_ARGS_LC(const float), const feedRate_t fr_mm_s) { auto move_one = [&](const AxisEnum a, const float p) { const feedRate_t fr = fr_mm_s ?: homing_feedrate(a); - current_position[a] = p; line_to_current_position(fr); + position[a] = p; goto_current_position(fr); }; SECONDARY_AXIS_CODE( move_one(I_AXIS, i), move_one(J_AXIS, j), move_one(K_AXIS, k), @@ -890,7 +893,7 @@ void _internal_move_to_destination(const feedRate_t fr_mm_s/*=0.0f*/ #endif /** - * Plan a move to (X, Y, Z, [I, [J, [K...]]]) and set the current_position + * Plan a move to (X, Y, Z, [I, [J, [K...]]]) and set the position * Plan a move to (X, Y, Z, [I, [J, [K...]]]) with separation of Z from other components. * * - If Z is moving up, the Z move is done before XY, etc. @@ -898,8 +901,8 @@ void _internal_move_to_destination(const feedRate_t fr_mm_s/*=0.0f*/ * - Delta may lower Z first to get into the free motion zone. * - Before returning, wait for the planner buffer to empty. */ -void do_blocking_move_to(NUM_AXIS_ARGS_(const float) const feedRate_t fr_mm_s/*=0.0f*/) { - DEBUG_SECTION(log_move, "do_blocking_move_to", DEBUGGING(LEVELING)); +void Motion::blocking_move(NUM_AXIS_ARGS_(const float) const feedRate_t fr_mm_s/*=0.0f*/) { + DEBUG_SECTION(log_move, "blocking_move", DEBUGGING(LEVELING)); #if NUM_AXES if (DEBUGGING(LEVELING)) DEBUG_XYZ("> ", NUM_AXIS_ARGS_LC()); #endif @@ -912,48 +915,46 @@ void do_blocking_move_to(NUM_AXIS_ARGS_(const float) const feedRate_t fr_mm_s/*= #if IS_KINEMATIC && DISABLED(POLARGRAPH) // kinematic machines are expected to home to a point 1.5x their range? never reachable. - if (!position_is_reachable(x, y)) return; - destination = current_position; // sync destination at the start + if (!can_reach(x, y)) return; + destination = position; // sync destination at the start #endif #if ENABLED(DELTA) REMEMBER(fr, feedrate_mm_s, xy_feedrate); - if (DEBUGGING(LEVELING)) DEBUG_POS("destination = current_position", destination); + if (DEBUGGING(LEVELING)) DEBUG_POS("destination = position", destination); // when in the danger zone - if (current_position.z > delta_clip_start_height) { - if (z > delta_clip_start_height) { // staying in the danger zone - destination.set(x, y, z); // move directly (uninterpolated) - prepare_internal_fast_move_to_destination(); // set current_position from destination - if (DEBUGGING(LEVELING)) DEBUG_POS("danger zone move", current_position); + if (position.z > delta_clip_start_height) { + if (z > delta_clip_start_height) { // Staying in the danger zone + destination.set(x, y, z); // Move directly (uninterpolated) + prepare_internal_fast_move_to_destination(); // Set position from destination + if (DEBUGGING(LEVELING)) DEBUG_POS("danger zone move", position); return; } destination.z = delta_clip_start_height; - prepare_internal_fast_move_to_destination(); // set current_position from destination - if (DEBUGGING(LEVELING)) DEBUG_POS("zone border move", current_position); + prepare_internal_fast_move_to_destination(); // Set position from destination + if (DEBUGGING(LEVELING)) DEBUG_POS("zone border move", position); } - if (z > current_position.z) { // raising? + if (z > position.z) { // Raising? destination.z = z; - prepare_internal_fast_move_to_destination(z_feedrate); // set current_position from destination - if (DEBUGGING(LEVELING)) DEBUG_POS("z raise move", current_position); + prepare_internal_fast_move_to_destination(z_feedrate); // Set position from destination + if (DEBUGGING(LEVELING)) DEBUG_POS("z raise move", position); } destination.set(x, y); - prepare_internal_move_to_destination(); // set current_position from destination - if (DEBUGGING(LEVELING)) DEBUG_POS("xy move", current_position); + prepare_internal_move_to_destination(); // Set position from destination + if (DEBUGGING(LEVELING)) DEBUG_POS("xy move", position); - if (z < current_position.z) { // lowering? + if (z < position.z) { // Lowering? destination.z = z; - prepare_internal_fast_move_to_destination(z_feedrate); // set current_position from destination - if (DEBUGGING(LEVELING)) DEBUG_POS("z lower move", current_position); + prepare_internal_fast_move_to_destination(z_feedrate); // Set position from destination + if (DEBUGGING(LEVELING)) DEBUG_POS("z lower move", position); } - #if SECONDARY_AXES - secondary_axis_moves(SECONDARY_AXIS_LIST(i, j, k, u, v, w), fr_mm_s); - #endif + TERN_(SECONDARY_AXES, secondary_axis_moves(SECONDARY_AXIS_NAMES_LC, fr_mm_s)); #elif IS_SCARA @@ -962,9 +963,7 @@ void do_blocking_move_to(NUM_AXIS_ARGS_(const float) const feedRate_t fr_mm_s/*= destination.set(x, y); prepare_internal_fast_move_to_destination(xy_feedrate); - #if SECONDARY_AXES - secondary_axis_moves(SECONDARY_AXIS_LIST(i, j, k, u, v, w), fr_mm_s); - #endif + TERN_(SECONDARY_AXES, secondary_axis_moves(SECONDARY_AXIS_NAMES_LC, fr_mm_s)); // If Z needs to lower, do it after moving XY if (destination.z > z) { destination.z = z; prepare_internal_fast_move_to_destination(z_feedrate); } @@ -972,18 +971,16 @@ void do_blocking_move_to(NUM_AXIS_ARGS_(const float) const feedRate_t fr_mm_s/*= #else #if HAS_Z_AXIS // If Z needs to raise, do it before moving XY - if (current_position.z < z) { current_position.z = z; line_to_current_position(z_feedrate); } + if (position.z < z) { position.z = z; goto_current_position(z_feedrate); } #endif - current_position.set(XY_LIST(x, y)); line_to_current_position(xy_feedrate); + position.set(XY_LIST(x, y)); goto_current_position(xy_feedrate); - #if SECONDARY_AXES - secondary_axis_moves(SECONDARY_AXIS_LIST(i, j, k, u, v, w), fr_mm_s); - #endif + TERN_(SECONDARY_AXES, secondary_axis_moves(SECONDARY_AXIS_NAMES_LC, fr_mm_s)); #if HAS_Z_AXIS // If Z needs to lower, do it after moving XY - if (current_position.z > z) { current_position.z = z; line_to_current_position(z_feedrate); } + if (position.z > z) { position.z = z; goto_current_position(z_feedrate); } #endif #endif @@ -991,64 +988,62 @@ void do_blocking_move_to(NUM_AXIS_ARGS_(const float) const feedRate_t fr_mm_s/*= planner.synchronize(); } -void do_blocking_move_to(const xy_pos_t &raw, const feedRate_t fr_mm_s/*=0.0f*/) { - do_blocking_move_to(NUM_AXIS_LIST_(raw.x, raw.y, current_position.z, - current_position.i, current_position.j, current_position.k, - current_position.u, current_position.v, current_position.w) fr_mm_s); -} -void do_blocking_move_to(const xyz_pos_t &raw, const feedRate_t fr_mm_s/*=0.0f*/) { - do_blocking_move_to(NUM_AXIS_ELEM_(raw) fr_mm_s); -} -void do_blocking_move_to(const xyze_pos_t &raw, const feedRate_t fr_mm_s/*=0.0f*/) { - do_blocking_move_to(NUM_AXIS_ELEM_(raw) fr_mm_s); +void Motion::blocking_move(const xy_pos_t &raw, const feedRate_t fr_mm_s/*=0.0f*/) { + blocking_move( + NUM_AXIS_LIST_(raw.x, raw.y, position.z, + position.i, position.j, position.k, + position.u, position.v, position.w) + fr_mm_s + ); } #if HAS_X_AXIS - void do_blocking_move_to_x(const float rx, const feedRate_t fr_mm_s/*=0.0*/) { - if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("do_blocking_move_to_x(", rx, ", ", fr_mm_s, ")"); - do_blocking_move_to( - NUM_AXIS_LIST_(rx, current_position.y, current_position.z, - current_position.i, current_position.j, current_position.k, - current_position.u, current_position.v, current_position.w) + void Motion::blocking_move_x(const float rx, const feedRate_t fr_mm_s/*=0.0*/) { + if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("blocking_move_x(", rx, ", ", fr_mm_s, ")"); + blocking_move( + NUM_AXIS_LIST_(rx, position.y, position.z, + position.i, position.j, position.k, + position.u, position.v, position.w) fr_mm_s ); } #endif #if HAS_Y_AXIS - void do_blocking_move_to_y(const float ry, const feedRate_t fr_mm_s/*=0.0*/) { - if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("do_blocking_move_to_y(", ry, ", ", fr_mm_s, ")"); - do_blocking_move_to( - NUM_AXIS_LIST_(current_position.x, ry, current_position.z, - current_position.i, current_position.j, current_position.k, - current_position.u, current_position.v, current_position.w) + void Motion::blocking_move_y(const float ry, const feedRate_t fr_mm_s/*=0.0*/) { + if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("blocking_move_y(", ry, ", ", fr_mm_s, ")"); + blocking_move( + NUM_AXIS_LIST_(position.x, ry, position.z, + position.i, position.j, position.k, + position.u, position.v, position.w) fr_mm_s ); } - void do_blocking_move_to_xy(const float rx, const float ry, const feedRate_t fr_mm_s/*=0.0*/) { - if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("do_blocking_move_to_xy(", rx, ", ", ry, ", ", fr_mm_s, ")"); - do_blocking_move_to( - NUM_AXIS_LIST_(rx, ry, current_position.z, - current_position.i, current_position.j, current_position.k, - current_position.u, current_position.v, current_position.w) + void Motion::blocking_move_xy(const float rx, const float ry, const feedRate_t fr_mm_s/*=0.0*/) { + if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("blocking_move_xy(", rx, ", ", ry, ", ", fr_mm_s, ")"); + blocking_move( + NUM_AXIS_LIST_(rx, ry, position.z, + position.i, position.j, position.k, + position.u, position.v, position.w) fr_mm_s ); } - void do_blocking_move_to_xy(const xy_pos_t &raw, const feedRate_t fr_mm_s/*=0.0f*/) { - do_blocking_move_to_xy(raw.x, raw.y, fr_mm_s); + void Motion::blocking_move_xy(const xy_pos_t &raw, const feedRate_t fr_mm_s/*=0.0f*/) { + blocking_move_xy(raw.x, raw.y, fr_mm_s); } #endif #if HAS_Z_AXIS - void do_blocking_move_to_z(const float rz, const feedRate_t fr_mm_s/*=0.0*/) { - if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("do_blocking_move_to_z(", rz, ", ", fr_mm_s, ")"); - do_blocking_move_to_xy_z(current_position, rz, fr_mm_s); + + void Motion::blocking_move_z(const float rz, const feedRate_t fr_mm_s/*=0.0*/) { + if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("blocking_move_z(", rz, ", ", fr_mm_s, ")"); + blocking_move_xy_z(position, rz, fr_mm_s); } - void do_blocking_move_to_xy_z(const xy_pos_t &raw, const float z, const feedRate_t fr_mm_s/*=0.0f*/) { - do_blocking_move_to( + void Motion::blocking_move_xy_z(const xy_pos_t &raw, const float z, const feedRate_t fr_mm_s/*=0.0f*/) { + blocking_move( NUM_AXIS_LIST_(raw.x, raw.y, z, - current_position.i, current_position.j, current_position.k, - current_position.u, current_position.v, current_position.w) + position.i, position.j, position.k, + position.u, position.v, position.w) fr_mm_s ); } @@ -1060,24 +1055,24 @@ void do_blocking_move_to(const xyze_pos_t &raw, const feedRate_t fr_mm_s/*=0.0f* * - If lowering is not allowed then skip a downward move * - Execute the move at the probing (or homing) feedrate */ - void do_z_clearance(const float zclear, const bool with_probe/*=true*/, const bool lower_allowed/*=false*/) { + void Motion::do_z_clearance(const float zclear, const bool with_probe/*=true*/, const bool lower_allowed/*=false*/) { UNUSED(with_probe); float zdest = zclear; TERN_(HAS_BED_PROBE, if (with_probe && probe.offset.z < 0) zdest -= probe.offset.z); NOMORE(zdest, Z_MAX_POS); - if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("do_z_clearance(", zclear, " [", current_position.z, " to ", zdest, "], ", lower_allowed, ")"); - if ((!lower_allowed && zdest < current_position.z) || zdest == current_position.z) return; - do_blocking_move_to_z(zdest, TERN(HAS_BED_PROBE, z_probe_fast_mm_s, homing_feedrate(Z_AXIS))); + if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("do_z_clearance(", zclear, " [", position.z, " to ", zdest, "], ", lower_allowed, ")"); + if ((!lower_allowed && zdest < position.z) || zdest == position.z) return; + blocking_move_z(zdest, TERN(HAS_BED_PROBE, z_probe_fast_mm_s, homing_feedrate(Z_AXIS))); } - void do_z_clearance_by(const float zclear) { + void Motion::do_z_clearance_by(const float zclear) { if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("do_z_clearance_by(", zclear, ")"); - do_z_clearance(current_position.z + zclear, false); + do_z_clearance(position.z + zclear, false); } /** * Move Z to Z_POST_CLEARANCE, * The axis is allowed to move down. */ - void do_move_after_z_homing() { + void Motion::do_move_after_z_homing() { DEBUG_SECTION(mzah, "do_move_after_z_homing", DEBUGGING(LEVELING)); #ifdef Z_POST_CLEARANCE do_z_clearance( @@ -1089,77 +1084,91 @@ void do_blocking_move_to(const xyze_pos_t &raw, const feedRate_t fr_mm_s/*=0.0f* probe.move_z_after_probing(); #endif } + + #if ALL(DWIN_LCD_PROUI, INDIVIDUAL_AXIS_HOMING_SUBMENU, MESH_BED_LEVELING) + #include "../lcd/e3v2/proui/dwin.h" // for Z_POST_CLEARANCE + #endif + #ifndef Z_POST_CLEARANCE // May be set by proui/dwin.h :-P + #ifdef Z_AFTER_HOMING + #define Z_POST_CLEARANCE Z_AFTER_HOMING + #else + #define Z_POST_CLEARANCE Z_CLEARANCE_FOR_HOMING + #endif + #endif + + void Motion::do_z_post_clearance() { do_z_clearance(Z_POST_CLEARANCE); } + #endif // HAS_Z_AXIS #if HAS_I_AXIS - void do_blocking_move_to_xyz_i(const xyze_pos_t &raw, const float i, const feedRate_t fr_mm_s/*=0.0f*/) { - do_blocking_move_to( + void Motion::blocking_move_xyz_i(const xyze_pos_t &raw, const float i, const feedRate_t fr_mm_s/*=0.0f*/) { + blocking_move( NUM_AXIS_LIST_(raw.x, raw.y, raw.z, i, raw.j, raw.k, raw.u, raw.v, raw.w) fr_mm_s ); } - void do_blocking_move_to_i(const float ri, const feedRate_t fr_mm_s/*=0.0*/) { - do_blocking_move_to_xyz_i(current_position, ri, fr_mm_s); + void Motion::blocking_move_i(const float ri, const feedRate_t fr_mm_s/*=0.0*/) { + blocking_move_xyz_i(position, ri, fr_mm_s); } #endif #if HAS_J_AXIS - void do_blocking_move_to_xyzi_j(const xyze_pos_t &raw, const float j, const feedRate_t fr_mm_s/*=0.0f*/) { - do_blocking_move_to( + void Motion::blocking_move_xyzi_j(const xyze_pos_t &raw, const float j, const feedRate_t fr_mm_s/*=0.0f*/) { + blocking_move( NUM_AXIS_LIST_(raw.x, raw.y, raw.z, raw.i, j, raw.k, raw.u, raw.v, raw.w) fr_mm_s ); } - void do_blocking_move_to_j(const float rj, const feedRate_t fr_mm_s/*=0.0*/) { - do_blocking_move_to_xyzi_j(current_position, rj, fr_mm_s); + void Motion::blocking_move_j(const float rj, const feedRate_t fr_mm_s/*=0.0*/) { + blocking_move_xyzi_j(position, rj, fr_mm_s); } #endif #if HAS_K_AXIS - void do_blocking_move_to_xyzij_k(const xyze_pos_t &raw, const float k, const feedRate_t fr_mm_s/*=0.0f*/) { - do_blocking_move_to( + void Motion::blocking_move_xyzij_k(const xyze_pos_t &raw, const float k, const feedRate_t fr_mm_s/*=0.0f*/) { + blocking_move( NUM_AXIS_LIST_(raw.x, raw.y, raw.z, raw.i, raw.j, k, raw.u, raw.v, raw.w) fr_mm_s ); } - void do_blocking_move_to_k(const float rk, const feedRate_t fr_mm_s/*=0.0*/) { - do_blocking_move_to_xyzij_k(current_position, rk, fr_mm_s); + void Motion::blocking_move_k(const float rk, const feedRate_t fr_mm_s/*=0.0*/) { + blocking_move_xyzij_k(position, rk, fr_mm_s); } #endif #if HAS_U_AXIS - void do_blocking_move_to_xyzijk_u(const xyze_pos_t &raw, const float u, const feedRate_t fr_mm_s/*=0.0f*/) { - do_blocking_move_to( + void Motion::blocking_move_xyzijk_u(const xyze_pos_t &raw, const float u, const feedRate_t fr_mm_s/*=0.0f*/) { + blocking_move( NUM_AXIS_LIST_(raw.x, raw.y, raw.z, raw.i, raw.j, raw.k, u, raw.v, raw.w) fr_mm_s ); } - void do_blocking_move_to_u(const float ru, const feedRate_t fr_mm_s/*=0.0*/) { - do_blocking_move_to_xyzijk_u(current_position, ru, fr_mm_s); + void Motion::blocking_move_u(const float ru, const feedRate_t fr_mm_s/*=0.0*/) { + blocking_move_xyzijk_u(position, ru, fr_mm_s); } #endif #if HAS_V_AXIS - void do_blocking_move_to_xyzijku_v(const xyze_pos_t &raw, const float v, const feedRate_t fr_mm_s/*=0.0f*/) { - do_blocking_move_to( + void Motion::blocking_move_xyzijku_v(const xyze_pos_t &raw, const float v, const feedRate_t fr_mm_s/*=0.0f*/) { + blocking_move( NUM_AXIS_LIST_(raw.x, raw.y, raw.z, raw.i, raw.j, raw.k, raw.u, v, raw.w) fr_mm_s ); } - void do_blocking_move_to_v(const float rv, const feedRate_t fr_mm_s/*=0.0*/) { - do_blocking_move_to_xyzijku_v(current_position, rv, fr_mm_s); + void Motion::blocking_move_v(const float rv, const feedRate_t fr_mm_s/*=0.0*/) { + blocking_move_xyzijku_v(position, rv, fr_mm_s); } #endif #if HAS_W_AXIS - void do_blocking_move_to_xyzijkuv_w(const xyze_pos_t &raw, const float w, const feedRate_t fr_mm_s/*=0.0f*/) { - do_blocking_move_to( + void Motion::blocking_move_xyzijkuv_w(const xyze_pos_t &raw, const float w, const feedRate_t fr_mm_s/*=0.0f*/) { + blocking_move( NUM_AXIS_LIST_(raw.x, raw.y, raw.z, raw.i, raw.j, raw.k, raw.u, raw.v, w) fr_mm_s ); } - void do_blocking_move_to_w(const float rw, const feedRate_t fr_mm_s/*=0.0*/) { - do_blocking_move_to_xyzijkuv_w(current_position, rw, fr_mm_s); + void Motion::blocking_move_w(const float rw, const feedRate_t fr_mm_s/*=0.0*/) { + blocking_move_xyzijkuv_w(position, rw, fr_mm_s); } #endif @@ -1169,13 +1178,13 @@ void do_blocking_move_to(const xyze_pos_t &raw, const feedRate_t fr_mm_s/*=0.0f* // static float saved_feedrate_mm_s; static int16_t saved_feedrate_percentage; -void remember_feedrate_scaling_off() { +void Motion::remember_feedrate_scaling_off() { if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("remember_feedrate_scaling_off: fr=", feedrate_mm_s, " ", feedrate_percentage, "%"); saved_feedrate_mm_s = feedrate_mm_s; saved_feedrate_percentage = feedrate_percentage; feedrate_percentage = 100; } -void restore_feedrate_and_scaling() { +void Motion::restore_feedrate_and_scaling() { feedrate_mm_s = saved_feedrate_mm_s; feedrate_percentage = saved_feedrate_percentage; if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("restore_feedrate_and_scaling: fr=", feedrate_mm_s, " ", feedrate_percentage, "%"); @@ -1186,7 +1195,7 @@ void restore_feedrate_and_scaling() { // Software Endstops are based on the configured limits. #define _AMIN(A) A##_MIN_POS #define _AMAX(A) A##_MAX_POS - soft_endstops_t soft_endstop = { + Motion::soft_endstops_t Motion::soft_endstop = { true, false, { MAPLIST(_AMIN, MAIN_AXIS_NAMES) }, { MAPLIST(_AMAX, MAIN_AXIS_NAMES) }, @@ -1201,7 +1210,7 @@ void restore_feedrate_and_scaling() { * the software endstop positions must be refreshed to remain * at the same positions relative to the machine. */ - void update_software_endstops(const AxisEnum axis + void Motion::update_software_endstops(const AxisEnum axis OPTARG(HAS_HOTEND_OFFSET, const uint8_t old_tool_index/*=0*/, const uint8_t new_tool_index/*=0*/) ) { @@ -1255,7 +1264,7 @@ void restore_feedrate_and_scaling() { // retain the same physical limit when other tools are selected. if (new_tool_index == old_tool_index || axis == Z_AXIS) { // The Z axis is "special" and shouldn't be modified - const float offs = (axis == Z_AXIS) ? 0 : hotend_offset[active_extruder][axis]; + const float offs = (axis == Z_AXIS) ? 0 : hotend_offset[extruder][axis]; soft_endstop.min[axis] = base_min_pos(axis) + offs; soft_endstop.max[axis] = base_max_pos(axis) + offs; } @@ -1282,7 +1291,7 @@ void restore_feedrate_and_scaling() { * For DELTA/SCARA the XY constraint is based on the smallest * radius within the set software endstops. */ - void apply_motion_limits(xyz_pos_t &target) { + void Motion::apply_limits(xyz_pos_t &target) { //SERIAL_ECHOLNPGM("Motion limits in: ", target.x, ", ", target.y, ", ", target.z); //SERIAL_EOL(); @@ -1294,7 +1303,7 @@ void restore_feedrate_and_scaling() { #if ALL(HAS_HOTEND_OFFSET, DELTA) // The effector center position will be the target minus the hotend offset. - const xy_pos_t offs = hotend_offset[active_extruder]; + const xy_pos_t offs = hotend_offset[extruder]; #elif ENABLED(POLARGRAPH) // POLARGRAPH uses draw_area_* below... #elif ENABLED(POLAR) @@ -1419,7 +1428,7 @@ void restore_feedrate_and_scaling() { #else // !HAS_SOFTWARE_ENDSTOPS - soft_endstops_t soft_endstop; + Motion::soft_endstops_t Motion::soft_endstop; #endif // !HAS_SOFTWARE_ENDSTOPS @@ -1435,7 +1444,7 @@ FORCE_INLINE void segment_idle(millis_t &next_idle_ms) { /** * Get distance from displacements along axes and, if required, update move type. */ -float get_move_distance(const xyze_pos_t &diff OPTARG(HAS_ROTATIONAL_AXES, bool &is_cartesian_move)) { +float Motion::get_move_distance(const xyze_pos_t &diff OPTARG(HAS_ROTATIONAL_AXES, bool &is_cartesian_move)) { #if NUM_AXES if (NUM_AXIS_NONE(diff.x, diff.y, 0, diff.i, diff.j, diff.k, diff.u, diff.v, diff.w)) @@ -1556,28 +1565,28 @@ float get_move_distance(const xyze_pos_t &diff OPTARG(HAS_ROTATIONAL_AXES, bool * the bedlevel.line_to_destination_segmented method replaces this. * * For Auto Bed Leveling (Bilinear) with SEGMENT_LEVELED_MOVES - * this is replaced by segmented_line_to_destination below. + * this is replaced by goto_destination_segmented below. */ - inline bool line_to_destination_kinematic() { + bool Motion::goto_destination_kinematic() { // Get the top feedrate of the move in the XY plane - const float scaled_fr_mm_s = MMS_SCALED(feedrate_mm_s); + const float scaled_fr_mm_s = mms_scaled(); - const xyze_float_t diff = destination - current_position; + const xyze_float_t diff = destination - position; //SERIAL_ECHOLNPGM("Destination: ", destination.x, " , ", destination.y, " , ", destination.z, " , ", destination.e); - //SERIAL_ECHOLNPGM("Current pos: ", current_position.x, " , ", current_position.y, " , ", current_position.z, " , ", current_position.e); + //SERIAL_ECHOLNPGM("Current pos: ", position.x, " , ", position.y, " , ", position.z, " , ", position.e); //SERIAL_ECHOLNPGM("Difference : ", diff.x, " , ", diff.y, " , ", diff.z, " , ", diff.e); // For TPARA always split up the move, then skip next code // For DELTA/SCARA if the move is only in Z/E don't split up the move if (TERN0(AXEL_TPARA, !diff.x && !diff.y)) { planner.buffer_line(destination, scaled_fr_mm_s); - return false; // caller will update current_position + return false; // caller will update position } // Fail if attempting move outside printable radius - if (!position_is_reachable(destination)) return true; + if (!can_reach(destination)) return true; // Get the linear distance in XYZ #if HAS_ROTATIONAL_AXES @@ -1632,21 +1641,21 @@ float get_move_distance(const xyze_pos_t &diff OPTARG(HAS_ROTATIONAL_AXES, bool //*/ // Get the current position as starting point - xyze_pos_t raw = current_position; + xyze_pos_t raw = position; // Calculate and execute the segments millis_t next_idle_ms = millis() + 200UL; while (--segments) { segment_idle(next_idle_ms); raw += segment_distance; - if (!planner.buffer_line(raw, scaled_fr_mm_s, active_extruder, hints)) + if (!planner.buffer_line(raw, scaled_fr_mm_s, extruder, hints)) break; } // Ensure last segment arrives at target location. - planner.buffer_line(destination, scaled_fr_mm_s, active_extruder, hints); + planner.buffer_line(destination, scaled_fr_mm_s, extruder, hints); - return false; // caller will update current_position + return false; // caller will update position } #else // !IS_KINEMATIC @@ -1660,9 +1669,9 @@ float get_move_distance(const xyze_pos_t &diff OPTARG(HAS_ROTATIONAL_AXES, bool * small incremental moves. This allows the planner to * apply more detailed bed leveling to the full move. */ - inline void segmented_line_to_destination(const feedRate_t fr_mm_s, const float segment_size=LEVELED_SEGMENT_LENGTH) { + void Motion::goto_destination_segmented(const feedRate_t fr_mm_s, const float segment_size/*=LEVELED_SEGMENT_LENGTH*/) { - const xyze_float_t diff = destination - current_position; + const xyze_float_t diff = destination - position; // If the move is only in Z/E don't split up the move if (!diff.x && !diff.y) { @@ -1701,20 +1710,20 @@ float get_move_distance(const xyze_pos_t &diff OPTARG(HAS_ROTATIONAL_AXES, bool //SERIAL_ECHOLNPGM(" segment_mm=", hints.millimeters); // Get the raw current position as starting point - xyze_pos_t raw = current_position; + xyze_pos_t raw = position; // Calculate and execute the segments millis_t next_idle_ms = millis() + 200UL; while (--segments) { segment_idle(next_idle_ms); raw += segment_distance; - if (!planner.buffer_line(raw, fr_mm_s, active_extruder, hints)) + if (!planner.buffer_line(raw, fr_mm_s, extruder, hints)) break; } // Since segment_distance is only approximate, // the final move must be to the exact destination. - planner.buffer_line(destination, fr_mm_s, active_extruder, hints); + planner.buffer_line(destination, fr_mm_s, extruder, hints); } #endif // SEGMENT_LEVELED_MOVES && !AUTO_BED_LEVELING_UBL @@ -1725,28 +1734,28 @@ float get_move_distance(const xyze_pos_t &diff OPTARG(HAS_ROTATIONAL_AXES, bool * When a mesh-based leveling system is active, moves are segmented * according to the configuration of the leveling system. * - * Return true if 'current_position' was set to 'destination' + * Return true if 'position' was set to 'destination' */ - inline bool line_to_destination_cartesian() { - const float scaled_fr_mm_s = MMS_SCALED(feedrate_mm_s); + bool Motion::goto_destination_cartesian() { + const float scaled_fr_mm_s = mms_scaled(); #if HAS_MESH if (planner.leveling_active && planner.leveling_active_at_z(destination.z)) { #if ENABLED(AUTO_BED_LEVELING_UBL) #if UBL_SEGMENTED return bedlevel.line_to_destination_segmented(scaled_fr_mm_s); #else - bedlevel.line_to_destination_cartesian(scaled_fr_mm_s, active_extruder); // UBL's motion routine needs to know about + bedlevel.line_to_destination_cartesian(scaled_fr_mm_s, extruder); // UBL's motion routine needs to know about return true; // all moves, including Z-only moves. #endif #elif ENABLED(SEGMENT_LEVELED_MOVES) - segmented_line_to_destination(scaled_fr_mm_s); - return false; // caller will update current_position + goto_destination_segmented(scaled_fr_mm_s); + return false; // caller will update position #else /** * For MBL and ABL-BILINEAR only segment moves when X or Y are involved. * Otherwise fall through to do a direct single move. */ - if (xy_pos_t(current_position) != xy_pos_t(destination)) { + if (xy_pos_t(position) != xy_pos_t(destination)) { #if ENABLED(MESH_BED_LEVELING) bedlevel.line_to_destination(scaled_fr_mm_s); #elif ENABLED(AUTO_BED_LEVELING_BILINEAR) @@ -1759,7 +1768,7 @@ float get_move_distance(const xyze_pos_t &diff OPTARG(HAS_ROTATIONAL_AXES, bool #endif // HAS_MESH planner.buffer_line(destination, scaled_fr_mm_s); - return false; // caller will update current_position + return false; // caller will update position } #endif // !IS_KINEMATIC @@ -1801,20 +1810,20 @@ float get_move_distance(const xyze_pos_t &diff OPTARG(HAS_ROTATIONAL_AXES, bool void set_duplication_enabled(const bool dupe, const int8_t tool_index/*=-1*/) { extruder_duplication_enabled = dupe; - if (tool_index >= 0) active_extruder = tool_index; + if (tool_index >= 0) motion.extruder = tool_index; stepper.apply_directions(); } void idex_set_parked(const bool park/*=true*/) { delayed_move_time = 0; active_extruder_parked = park; - if (park) raised_parked_position = current_position; // Remember current raised toolhead position for use by unpark + if (park) raised_parked_position = motion.position; // Remember current raised toolhead position for use by unpark } /** * Prepare a linear move in a dual X axis setup * - * Return true if current_position[] was set to destination[] + * Return true if position[] was set to destination[] */ inline bool dual_x_carriage_unpark() { if (active_extruder_parked) { @@ -1823,13 +1832,13 @@ float get_move_distance(const xyze_pos_t &diff OPTARG(HAS_ROTATIONAL_AXES, bool case DXC_FULL_CONTROL_MODE: break; case DXC_AUTO_PARK_MODE: { - if (current_position.e == destination.e) { + if (motion.position.e == motion.destination.e) { // This is a travel move (with no extrusion) // Skip it, but keep track of the current position // (so it can be used as the start of the next non-travel move) if (delayed_move_time != UINT32_MAX) { - current_position = destination; - NOLESS(raised_parked_position.z, destination.z); + motion.position = motion.destination; + NOLESS(raised_parked_position.z, motion.destination.z); delayed_move_time = millis() + 1000UL; return true; } @@ -1839,13 +1848,13 @@ float get_move_distance(const xyze_pos_t &diff OPTARG(HAS_ROTATIONAL_AXES, bool // const feedRate_t fr_zfast = planner.settings.max_feedrate_mm_s[Z_AXIS]; // 1. Move to the raised parked XYZ. Presumably the tool is already at XY. - xyze_pos_t raised = raised_parked_position; raised.e = current_position.e; + xyze_pos_t raised = raised_parked_position; raised.e = motion.position.e; if (planner.buffer_line(raised, fr_zfast)) { // 2. Move to the current native XY and raised Z. Presumably this is a null move. - xyze_pos_t curpos = current_position; curpos.z = raised_parked_position.z; + xyze_pos_t curpos = motion.position; curpos.z = raised_parked_position.z; if (planner.buffer_line(curpos, PLANNER_XY_FEEDRATE_MM_S)) { // 3. Lower Z back down - line_to_current_position(fr_zfast); + motion.goto_current_position(fr_zfast); } } stepper.apply_directions(); @@ -1856,11 +1865,11 @@ float get_move_distance(const xyze_pos_t &diff OPTARG(HAS_ROTATIONAL_AXES, bool case DXC_MIRRORED_MODE: case DXC_DUPLICATION_MODE: - if (active_extruder == 0) { + if (motion.extruder == 0) { set_duplication_enabled(false); // Clear stale duplication state // Restore planner to parked head (T1) X position - float x0_pos = current_position.x; - xyze_pos_t pos_now = current_position; + float x0_pos = motion.position.x; + xyze_pos_t pos_now = motion.position; pos_now.x = inactive_extruder_x; planner.set_position_mm(pos_now); @@ -1876,7 +1885,7 @@ float get_move_distance(const xyze_pos_t &diff OPTARG(HAS_ROTATIONAL_AXES, bool if (!planner.buffer_line(new_pos, planner.settings.max_feedrate_mm_s[X_AXIS], 1)) break; planner.synchronize(); - sync_plan_position(); // Extra sync for good measure + motion.sync_plan_position(); // Extra sync for good measure set_duplication_enabled(true); // Enable Duplication idex_set_parked(false); // No longer parked if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("set_duplication_enabled(true)\nidex_set_parked(false)"); @@ -1896,25 +1905,25 @@ float get_move_distance(const xyze_pos_t &diff OPTARG(HAS_ROTATIONAL_AXES, bool * This may result in several calls to planner.buffer_line to * do smaller moves for DELTA, SCARA, mesh moves, etc. * - * Make sure current_position.e and destination.e are good + * Make sure position.e and destination.e are good * before calling or cold/lengthy extrusion may get missed. * - * Before exit, current_position is set to destination. + * Before exit, position is set to destination. */ -void prepare_line_to_destination() { - apply_motion_limits(destination); +void Motion::prepare_line_to_destination() { + apply_limits(destination); //SERIAL_ECHOLNPGM(">TPARA Prepare line to destination: ", destination.x , " , ", destination.y, " , ", destination.z, " , " , destination.e); //SERIAL_EOL(); #if ANY(PREVENT_COLD_EXTRUSION, PREVENT_LENGTHY_EXTRUDE) - if (!DEBUGGING(DRYRUN) && destination.e != current_position.e) { - bool ignore_e = thermalManager.tooColdToExtrude(active_extruder); + if (!DEBUGGING(DRYRUN) && destination.e != position.e) { + bool ignore_e = thermalManager.tooColdToExtrude(extruder); if (ignore_e) SERIAL_ECHO_MSG(STR_ERR_COLD_EXTRUDE_STOP); #if ENABLED(PREVENT_LENGTHY_EXTRUDE) - const float e_delta = ABS(destination.e - current_position.e) * planner.e_factor[active_extruder]; + const float e_delta = ABS(destination.e - position.e) * planner.e_factor[extruder]; if (e_delta > (EXTRUDE_MAXLENGTH)) { #if ENABLED(MIXING_EXTRUDER) float collector[MIXING_STEPPERS]; @@ -1934,7 +1943,7 @@ void prepare_line_to_destination() { #endif if (ignore_e) { - current_position.e = destination.e; // Behave as if the E move really took place + position.e = destination.e; // Behave as if the E move really took place planner.set_e_position_mm(destination.e); // Prevent the planner from complaining too } } @@ -1946,25 +1955,29 @@ void prepare_line_to_destination() { if ( #if UBL_SEGMENTED #if IS_KINEMATIC // UBL using Kinematic / Cartesian cases as a workaround for now. - bedlevel.line_to_destination_segmented(MMS_SCALED(feedrate_mm_s)) + bedlevel.line_to_destination_segmented(mms_scaled()) #else - line_to_destination_cartesian() + goto_destination_cartesian() #endif #elif IS_KINEMATIC - line_to_destination_kinematic() + goto_destination_kinematic() #else - line_to_destination_cartesian() + goto_destination_cartesian() #endif ) return; - current_position = destination; + position = destination; } #if HAS_ENDSTOPS + main_axes_bits_t Motion::axes_homed, Motion::axes_trusted; // = 0 +#else + constexpr main_axes_bits_t Motion::axes_homed, Motion::axes_trusted; +#endif - main_axes_bits_t axes_homed, axes_trusted; // = 0 +#if HAS_ENDSTOPS - main_axes_bits_t axes_should_home(main_axes_bits_t axis_bits/*=main_axes_mask*/) { + main_axes_bits_t Motion::axes_should_home(main_axes_bits_t axis_bits/*=main_axes_mask*/) { auto set_should = [](main_axes_bits_t &b, AxisEnum a) { if (TEST(b, a) && TERN(HOME_AFTER_DEACTIVATE, axis_is_trusted, axis_was_homed)(a)) CBI(b, a); @@ -1978,7 +1991,7 @@ void prepare_line_to_destination() { return axis_bits; } - bool homing_needed_error(main_axes_bits_t axis_bits/*=main_axes_mask*/) { + bool Motion::homing_needed_error(main_axes_bits_t axis_bits/*=main_axes_mask*/) { if (!(axis_bits &= axes_should_home(axis_bits))) return false; char all_axes[] = STR_AXES_MAIN, need[NUM_AXES + 1]; @@ -1998,7 +2011,7 @@ void prepare_line_to_destination() { /** * Homing bump feedrate (mm/s) */ - feedRate_t get_homing_bump_feedrate(const AxisEnum axis) { + feedRate_t Motion::get_homing_bump_feedrate(const AxisEnum axis) { #if HOMING_Z_WITH_PROBE if (axis == Z_AXIS) return z_probe_slow_mm_s; #endif @@ -2206,7 +2219,7 @@ void prepare_line_to_destination() { /** * Home an individual linear axis */ - void do_homing_move(const AxisEnum axis, const float distance, const feedRate_t fr_mm_s=0.0, const bool final_approach=true) { + void Motion::do_homing_move(const AxisEnum axis, const float distance, const feedRate_t fr_mm_s/*=0.0*/, const bool final_approach/*=true*/) { DEBUG_SECTION(log_move, "do_homing_move", DEBUGGING(LEVELING)); const feedRate_t home_fr_mm_s = fr_mm_s ?: homing_feedrate(axis); @@ -2222,7 +2235,7 @@ void prepare_line_to_destination() { // Only do some things when moving towards an endstop const int8_t axis_home_dir = TERN0(DUAL_X_CARRIAGE, axis == X_AXIS) - ? TOOL_X_HOME_DIR(active_extruder) : home_dir(axis); + ? TOOL_X_HOME_DIR(extruder) : home_dir(axis); const bool is_home_dir = (axis_home_dir > 0) == (distance > 0); #if ENABLED(SENSORLESS_HOMING) @@ -2239,7 +2252,7 @@ void prepare_line_to_destination() { #if ALL(HAS_HOTEND, WAIT_FOR_HOTEND) // Wait for the hotend to heat back up between probing points - thermalManager.wait_for_hotend_heating(active_extruder); + thermalManager.wait_for_hotend_heating(extruder); #endif TERN_(HAS_QUIET_PROBING, if (final_approach) probe.set_devices_paused_for_probing(true)); @@ -2256,10 +2269,10 @@ void prepare_line_to_destination() { #if ANY(MORGAN_SCARA, MP_SCARA) // Tell the planner the axis is at 0 - current_position[axis] = 0; + position[axis] = 0; sync_plan_position(); - current_position[axis] = distance; - line_to_current_position(home_fr_mm_s); + position[axis] = distance; + goto_current_position(home_fr_mm_s); #else // Get the ABC or XYZ positions in mm abce_pos_t target = planner.get_axis_positions_mm(); @@ -2273,7 +2286,7 @@ void prepare_line_to_destination() { // Set delta/cartesian axes directly target[axis] = distance; // The move will be towards the endstop - planner.buffer_segment(target OPTARG(HAS_DIST_MM_ARG, cart_dist_mm), home_fr_mm_s, active_extruder); + planner.buffer_segment(target OPTARG(HAS_DIST_MM_ARG, cart_dist_mm), home_fr_mm_s, extruder); #endif planner.synchronize(); @@ -2301,7 +2314,7 @@ void prepare_line_to_destination() { * that has no endstops. Such machines should always be considered to be in a "known" and * "trusted" position). */ - void set_axis_never_homed(const AxisEnum axis) { + void Motion::set_axis_never_homed(const AxisEnum axis) { if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM(">>> set_axis_never_homed(", C(AXIS_CHAR(axis)), ")"); set_axis_untrusted(axis); @@ -2450,7 +2463,7 @@ void prepare_line_to_destination() { * before updating the current position. */ - void homeaxis(const AxisEnum axis) { + void Motion::homeaxis(const AxisEnum axis) { #if ANY(MORGAN_SCARA, MP_SCARA) // Only Z homing (with probe) is permitted @@ -2464,7 +2477,7 @@ void prepare_line_to_destination() { if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM(">>> homeaxis(", C(AXIS_CHAR(axis)), ")"); const int axis_home_dir = TERN0(DUAL_X_CARRIAGE, axis == X_AXIS) - ? TOOL_X_HOME_DIR(active_extruder) : home_dir(axis); + ? TOOL_X_HOME_DIR(extruder) : home_dir(axis); // // Homing Z with a probe? Raise Z (maybe) and deploy the Z probe. @@ -2755,9 +2768,9 @@ void prepare_line_to_destination() { set_axis_is_at_home(axis); sync_plan_position(); - destination[axis] = current_position[axis]; + destination[axis] = position[axis]; - if (DEBUGGING(LEVELING)) DEBUG_POS("> AFTER set_axis_is_at_home", current_position); + if (DEBUGGING(LEVELING)) DEBUG_POS("> AFTER set_axis_is_at_home", position); #endif @@ -2771,8 +2784,8 @@ void prepare_line_to_destination() { #if DISABLED(DELTA) && defined(HOMING_BACKOFF_POST_MM) const xyz_float_t endstop_backoff = HOMING_BACKOFF_POST_MM; if (endstop_backoff[axis]) { - current_position[axis] -= ABS(endstop_backoff[axis]) * axis_home_dir; - line_to_current_position(TERN_(HOMING_Z_WITH_PROBE, (axis == Z_AXIS) ? z_probe_fast_mm_s :) homing_feedrate(axis)); + position[axis] -= ABS(endstop_backoff[axis]) * axis_home_dir; + goto_current_position(TERN_(HOMING_Z_WITH_PROBE, (axis == Z_AXIS) ? z_probe_fast_mm_s :) homing_feedrate(axis)); #if ENABLED(SENSORLESS_HOMING) planner.synchronize(); @@ -2808,30 +2821,30 @@ void prepare_line_to_destination() { * individual axis has been homed. * * DELTA should wait until all homing is done before setting the XYZ - * current_position to home, because homing is a single operation. + * position to home, because homing is a single operation. * In the case where the axis positions are trusted and previously * homed, DELTA could home to X or Y individually by moving either one * to the center. However, homing Z always homes XY and Z. * * SCARA should wait until all XY homing is done before setting the XY - * current_position to home, because neither X nor Y is at home until + * position to home, because neither X nor Y is at home until * both are at home. Z can however be homed individually. * * TPARA should wait until all YZ homing is done before setting the YZ - * current_position to home, because neither Y nor Z is at home until + * motion.position to home, because neither Y nor Z is at home until * both are at home. X can however be homed individually. * * Callers must sync the planner position after calling this! */ -void set_axis_is_at_home(const AxisEnum axis) { +void Motion::set_axis_is_at_home(const AxisEnum axis) { if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM(">>> set_axis_is_at_home(", C(AXIS_CHAR(axis)), ")"); set_axis_trusted(axis); set_axis_homed(axis); #if ENABLED(DUAL_X_CARRIAGE) - if (axis == X_AXIS && (active_extruder == 1 || dual_x_carriage_mode == DXC_DUPLICATION_MODE)) { - current_position.x = SUM_TERN(HAS_HOME_OFFSET, x_home_pos(active_extruder), home_offset.x); + if (axis == X_AXIS && (extruder == 1 || dual_x_carriage_mode == DXC_DUPLICATION_MODE)) { + position.x = SUM_TERN(HAS_HOME_OFFSET, x_home_pos(extruder), home_offset.x); return; } #endif @@ -2839,9 +2852,9 @@ void set_axis_is_at_home(const AxisEnum axis) { #if ANY(MORGAN_SCARA, AXEL_TPARA) scara_set_axis_is_at_home(axis); #elif ENABLED(DELTA) - current_position[axis] = (axis == Z_AXIS) ? DIFF_TERN(HAS_BED_PROBE, delta_height, probe.offset.z) : base_home_pos(axis); + position[axis] = (axis == Z_AXIS) ? DIFF_TERN(HAS_BED_PROBE, delta_height, probe.offset.z) : base_home_pos(axis); #else - current_position[axis] = SUM_TERN(HAS_HOME_OFFSET, base_home_pos(axis), home_offset[axis]); + position[axis] = SUM_TERN(HAS_HOME_OFFSET, base_home_pos(axis), home_offset[axis]); #endif /** @@ -2852,9 +2865,9 @@ void set_axis_is_at_home(const AxisEnum axis) { #if HOMING_Z_WITH_PROBE #if ENABLED(BD_SENSOR) safe_delay(100); - current_position.z = bdl.read(); + position.z = bdl.read(); #else - current_position.z -= probe.offset.z; + position.z -= probe.offset.z; #endif if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("*** Z homed with PROBE" TERN_(Z_MIN_PROBE_USES_Z_MIN_ENDSTOP_PIN, " (Z_MIN_PROBE_USES_Z_MIN_ENDSTOP_PIN)") " ***\n> (M851 Z", probe.offset.z, ")"); #else @@ -2873,16 +2886,8 @@ void set_axis_is_at_home(const AxisEnum axis) { #if HAS_HOME_OFFSET DEBUG_ECHOLNPGM("> home_offset[", C(AXIS_CHAR(axis)), "] = ", home_offset[axis]); #endif - DEBUG_POS("", current_position); + DEBUG_POS("", position); DEBUG_ECHOLNPGM("<<< set_axis_is_at_home(", C(AXIS_CHAR(axis)), ")"); } -} -#if HAS_HOME_OFFSET - /** - * Set the home offset for an axis. - */ - void set_home_offset(const AxisEnum axis, const float v) { - home_offset[axis] = v; - } -#endif +} // set_axis_is_at_home() diff --git a/Marlin/src/module/motion.h b/Marlin/src/module/motion.h index 8050e66448..4389821231 100644 --- a/Marlin/src/module/motion.h +++ b/Marlin/src/module/motion.h @@ -30,9 +30,9 @@ #include "../inc/MarlinConfig.h" -#if ALL(DWIN_LCD_PROUI, INDIVIDUAL_AXIS_HOMING_SUBMENU, MESH_BED_LEVELING) - #include "../lcd/dwin/proui/dwin.h" // for Z_POST_CLEARANCE -#endif +//#if ALL(DWIN_LCD_PROUI, INDIVIDUAL_AXIS_HOMING_SUBMENU, MESH_BED_LEVELING) +// #include "../lcd/dwin/proui/dwin.h" // for Z_POST_CLEARANCE +//#endif #if IS_SCARA #include "scara.h" @@ -40,22 +40,487 @@ #include "polar.h" #endif +#if ENABLED(AUTO_REPORT_POSITION) + #include "../libs/autoreport.h" +#endif + // Error margin to work around float imprecision constexpr float fslop = 0.0001; -extern bool relative_mode; - -extern xyze_pos_t current_position, // High-level current tool position - destination; // Destination for a move - -// Scratch space for a cartesian result -extern xyz_pos_t cartes; - -// Until kinematics.cpp is created, declare this here -#if IS_KINEMATIC - extern abce_pos_t delta; +#if ENABLED(REALTIME_REPORTING_COMMANDS) + #define HAS_GRBL_STATE 1 + /** + * Machine states for GRBL or TinyG + */ + enum M_StateEnum : uint8_t { + M_INIT = 0, // 0 machine is initializing + M_RESET, // 1 machine is ready for use + M_ALARM, // 2 machine is in alarm state (soft shut down) + M_IDLE, // 3 program stop or no more blocks (M0, M1, M60) + M_END, // 4 program end via M2, M30 + M_RUNNING, // 5 motion is running + M_HOLD, // 6 motion is holding + M_PROBE, // 7 probe cycle active + M_CYCLING, // 8 machine is running (cycling) + M_HOMING, // 9 machine is homing + M_JOGGING, // 10 machine is jogging + M_ERROR // 11 machine is in hard alarm state (shut down) + }; #endif +/** + * Homing and Trusted Axes + */ +typedef bits_t(NUM_AXES) main_axes_bits_t; +constexpr main_axes_bits_t main_axes_mask = _BV(NUM_AXES) - 1; + +class Motion { +public: + static bool relative_mode; // Relative Mode - G90/G91 + + #if HAS_MULTI_EXTRUDER + static uint8_t extruder; // Selected extruder (tool) - T + #else + static constexpr uint8_t extruder = 0; + #endif + + static xyze_pos_t position, // High-level current tool position + destination; // Destination for a move + + static feedRate_t feedrate_mm_s; // Feedrate for G-moves, set by the most recent G-move + + // Feedrate scaling is applied to all G0/G1, G2/G3, and G5 moves + static int16_t feedrate_percentage; + static feedRate_t mms_scaled(const feedRate_t f=feedrate_mm_s) { + return f * 0.01f * feedrate_percentage; + } + + #if IS_KINEMATIC + static abce_pos_t delta; // Scratch space for a kinematic result + #endif + #if HAS_SCARA_OFFSET + static abc_pos_t scara_home_offset; // A and B angular offsets, Z mm offset + #endif + + #if ENABLED(LCD_SHOW_E_TOTAL) + static float e_move_accumulator; + #endif + + static xyz_pos_t cartes; // Scratch space for a cartesian result + static void get_cartesian_from_steppers(); + static void set_current_from_steppers_for_axis(const AxisEnum axis); + + static void report_position(); + static void report_position_real(); + static void report_position_projected(); + + #if ENABLED(AUTO_REPORT_POSITION) + struct PositionReport { + static void report() { + TERN(AUTO_REPORT_REAL_POSITION, report_position_real(), report_position_projected()); + } + }; + static AutoReporter position_auto_reporter; + #endif + + /** + * Set the planner/stepper positions directly from motion.position with + * no kinematic translation. Used for homing axes and cartesian/core syncing. + */ + static void sync_plan_position(); + #if HAS_EXTRUDERS + static void sync_plan_position_e(); + static void set_and_sync_e(const float epos) { + position.e = epos; + sync_plan_position_e(); + } + #endif + + // + // Homing and Trusted Axes + // + + /** + * Feed rates are often configured with mm/m + * but the planner and stepper like mm/s units. + */ + #if ENABLED(EDITABLE_HOMING_FEEDRATE) + static xyz_feedrate_t homing_feedrate_mm_m; + #else + static constexpr xyz_feedrate_t homing_feedrate_mm_m = HOMING_FEEDRATE_MM_M; + #endif + + FORCE_INLINE static feedRate_t homing_feedrate(const AxisEnum a) { + float v = TERN0(HAS_Z_AXIS, homing_feedrate_mm_m.z); + #if DISABLED(DELTA) + NUM_AXIS_CODE( + if (a == X_AXIS) v = homing_feedrate_mm_m.x, + else if (a == Y_AXIS) v = homing_feedrate_mm_m.y, + else if (a == Z_AXIS) v = homing_feedrate_mm_m.z, + else if (a == I_AXIS) v = homing_feedrate_mm_m.i, + else if (a == J_AXIS) v = homing_feedrate_mm_m.j, + else if (a == K_AXIS) v = homing_feedrate_mm_m.k, + else if (a == U_AXIS) v = homing_feedrate_mm_m.u, + else if (a == V_AXIS) v = homing_feedrate_mm_m.v, + else if (a == W_AXIS) v = homing_feedrate_mm_m.w + ); + #endif + return MMM_TO_MMS(v); + } + + static feedRate_t get_homing_bump_feedrate(const AxisEnum axis); + + #if HAS_HOME_OFFSET + static xyz_pos_t home_offset; + static void set_home_offset(const AxisEnum axis, const float v) { home_offset[axis] = v; } + #endif + + // + // Workspace offsets + // + + #if HAS_WORKSPACE_OFFSET + static xyz_pos_t workspace_offset; + static float native_to_logical(const float f, const AxisEnum a) { return f + workspace_offset[a]; } + static float logical_to_native(const float f, const AxisEnum a) { return f - workspace_offset[a]; } + FORCE_INLINE static void toLogical(xy_pos_t &raw) { raw += workspace_offset; } + FORCE_INLINE static void toLogical(xyz_pos_t &raw) { raw += workspace_offset; } + FORCE_INLINE static void toLogical(xyze_pos_t &raw) { raw += workspace_offset; } + FORCE_INLINE static void toNative(xy_pos_t &raw) { raw -= workspace_offset; } + FORCE_INLINE static void toNative(xyz_pos_t &raw) { raw -= workspace_offset; } + FORCE_INLINE static void toNative(xyze_pos_t &raw) { raw -= workspace_offset; } + #else + static float native_to_logical(const float f, const AxisEnum) { return f; } + static float logical_to_native(const float f, const AxisEnum) { return f; } + FORCE_INLINE static void toLogical(xy_pos_t&) {} + FORCE_INLINE static void toLogical(xyz_pos_t&) {} + FORCE_INLINE static void toLogical(xyze_pos_t&) {} + FORCE_INLINE static void toNative(xy_pos_t&) {} + FORCE_INLINE static void toNative(xyz_pos_t&) {} + FORCE_INLINE static void toNative(xyze_pos_t&) {} + #endif + #if HAS_X_AXIS + static float logical_x(const float f) { return native_to_logical(f, X_AXIS); } + static float raw_x(const float f) { return logical_to_native(f, X_AXIS); } + #endif + #if HAS_Y_AXIS + static float logical_y(const float f) { return native_to_logical(f, Y_AXIS); } + static float raw_y(const float f) { return logical_to_native(f, Y_AXIS); } + #endif + #if HAS_Z_AXIS + static float logical_z(const float f) { return native_to_logical(f, Z_AXIS); } + static float raw_z(const float f) { return logical_to_native(f, Z_AXIS); } + #endif + #if HAS_I_AXIS + static float logical_i(const float f) { return native_to_logical(f, I_AXIS); } + static float raw_i(const float f) { return logical_to_native(f, I_AXIS); } + #endif + #if HAS_J_AXIS + static float logical_j(const float f) { return native_to_logical(f, J_AXIS); } + static float raw_j(const float f) { return logical_to_native(f, J_AXIS); } + #endif + #if HAS_K_AXIS + static float logical_k(const float f) { return native_to_logical(f, K_AXIS); } + static float raw_k(const float f) { return logical_to_native(f, K_AXIS); } + #endif + #if HAS_U_AXIS + static float logical_u(const float f) { return native_to_logical(f, U_AXIS); } + static float raw_u(const float f) { return logical_to_native(f, U_AXIS); } + #endif + #if HAS_V_AXIS + static float logical_v(const float f) { return native_to_logical(f, V_AXIS); } + static float raw_v(const float f) { return logical_to_native(f, V_AXIS); } + #endif + #if HAS_W_AXIS + static float logical_w(const float f) { return native_to_logical(f, W_AXIS); } + static float raw_w(const float f) { return logical_to_native(f, W_AXIS); } + #endif + + #if HAS_Z_AXIS + static bool z_min_trusted; // If Z has been powered on trust that the real Z is >= motion.position.z + #endif + static void set_axis_is_at_home(const AxisEnum axis); + + /** + * axes_homed + * Flags that each linear axis was homed. + * XYZ on cartesian, ABC on delta, ABZ on SCARA. + * + * axes_trusted + * Flags that the position is trusted in each linear axis. Set when homed. + * Cleared whenever a stepper powers off, potentially losing its position. + */ + #if HAS_ENDSTOPS + static main_axes_bits_t axes_homed, axes_trusted; + static void homeaxis(const AxisEnum axis); + static void set_axis_never_homed(const AxisEnum axis); + static main_axes_bits_t axes_should_home(main_axes_bits_t axes_mask=main_axes_mask); + static bool homing_needed_error(main_axes_bits_t axes_mask=main_axes_mask); + #else + static constexpr main_axes_bits_t axes_homed = main_axes_mask, axes_trusted = main_axes_mask; // Zero-endstop machines are always homed and trusted + static void homeaxis(const AxisEnum axis) {} + static void set_axis_never_homed(const AxisEnum) {} + static main_axes_bits_t axes_should_home(main_axes_bits_t=main_axes_mask) { return 0; } + static bool homing_needed_error(main_axes_bits_t=main_axes_mask) { return false; } + #endif + + static void set_axis_unhomed(const AxisEnum axis) { TERN_(HAS_ENDSTOPS, CBI(axes_homed, axis)); } + static void set_axis_untrusted(const AxisEnum axis) { TERN_(HAS_ENDSTOPS, CBI(axes_trusted, axis)); } + static void set_all_unhomed() { TERN_(HAS_ENDSTOPS, axes_homed = axes_trusted = 0); } + static void set_axis_homed(const AxisEnum axis) { TERN_(HAS_ENDSTOPS, SBI(axes_homed, axis)); } + static void set_axis_trusted(const AxisEnum axis) { TERN_(HAS_ENDSTOPS, SBI(axes_trusted, axis)); } + static void set_all_homed() { TERN_(HAS_ENDSTOPS, axes_homed = axes_trusted = main_axes_mask); } + + static bool axis_was_homed(const AxisEnum axis) { return TEST(axes_homed, axis); } + static bool axis_is_trusted(const AxisEnum axis) { return TEST(axes_trusted, axis); } + static bool axis_should_home(const AxisEnum axis) { return axes_should_home(_BV(axis)) != 0; } + static bool no_axes_homed() { return !axes_homed; } + static bool all_axes_homed() { return main_axes_mask == (axes_homed & main_axes_mask); } + static bool homing_needed() { return !all_axes_homed(); } + static bool all_axes_trusted() { return main_axes_mask == (axes_trusted & main_axes_mask); } + + static void home_if_needed(const bool keeplev=false); + + // + // Software Endstops + // + + #if HAS_SOFTWARE_ENDSTOPS + + typedef struct { + bool _enabled, _loose; + bool enabled() { return _enabled && !_loose; } + + xyz_pos_t min, max; + void get_manual_axis_limits(const AxisEnum axis, float &amin, float &amax) { + amin = -100000; amax = 100000; // "No limits" + #if HAS_SOFTWARE_ENDSTOPS + if (enabled()) switch (axis) { + #if HAS_X_AXIS + case X_AXIS: TERN_(MIN_SOFTWARE_ENDSTOP_X, amin = min.x); TERN_(MAX_SOFTWARE_ENDSTOP_X, amax = max.x); break; + #endif + #if HAS_Y_AXIS + case Y_AXIS: TERN_(MIN_SOFTWARE_ENDSTOP_Y, amin = min.y); TERN_(MAX_SOFTWARE_ENDSTOP_Y, amax = max.y); break; + #endif + #if HAS_Z_AXIS + case Z_AXIS: TERN_(MIN_SOFTWARE_ENDSTOP_Z, amin = min.z); TERN_(MAX_SOFTWARE_ENDSTOP_Z, amax = max.z); break; + #endif + #if HAS_I_AXIS + case I_AXIS: TERN_(MIN_SOFTWARE_ENDSTOP_I, amin = min.i); TERN_(MIN_SOFTWARE_ENDSTOP_I, amax = max.i); break; + #endif + #if HAS_J_AXIS + case J_AXIS: TERN_(MIN_SOFTWARE_ENDSTOP_J, amin = min.j); TERN_(MIN_SOFTWARE_ENDSTOP_J, amax = max.j); break; + #endif + #if HAS_K_AXIS + case K_AXIS: TERN_(MIN_SOFTWARE_ENDSTOP_K, amin = min.k); TERN_(MIN_SOFTWARE_ENDSTOP_K, amax = max.k); break; + #endif + #if HAS_U_AXIS + case U_AXIS: TERN_(MIN_SOFTWARE_ENDSTOP_U, amin = min.u); TERN_(MIN_SOFTWARE_ENDSTOP_U, amax = max.u); break; + #endif + #if HAS_V_AXIS + case V_AXIS: TERN_(MIN_SOFTWARE_ENDSTOP_V, amin = min.v); TERN_(MIN_SOFTWARE_ENDSTOP_V, amax = max.v); break; + #endif + #if HAS_W_AXIS + case W_AXIS: TERN_(MIN_SOFTWARE_ENDSTOP_W, amin = min.w); TERN_(MIN_SOFTWARE_ENDSTOP_W, amax = max.w); break; + #endif + default: break; + } + #endif + } + } soft_endstops_t; + + #else // !HAS_SOFTWARE_ENDSTOPS + + typedef struct { + bool enabled() { return false; } + void get_manual_axis_limits(const AxisEnum axis, float &amin, float &amax) { + // No limits + amin = position[axis] - 1000; + amax = position[axis] + 1000; + } + } soft_endstops_t; + + #endif // !HAS_SOFTWARE_ENDSTOPS + + static soft_endstops_t soft_endstop; + + #if HAS_SOFTWARE_ENDSTOPS + static void apply_limits(xyz_pos_t &target); + static void update_software_endstops(const AxisEnum axis + #if HAS_HOTEND_OFFSET + , const uint8_t old_tool_index=0, const uint8_t new_tool_index=0 + #endif + ); + static void set_soft_endstop_loose(const bool loose) { soft_endstop._loose = loose; } + #else + static void apply_limits(xyz_pos_t&) {} + static void update_software_endstops(...) {} + static void set_soft_endstop_loose(...) {} + #endif + + // + // Reachability Tests + // + #if IS_KINEMATIC + + // Return true if the given point is within the printable area + static bool can_reach(const float rx, const float ry, const float inset=0); + + static bool can_reach(const xy_pos_t &pos, const float inset=0) { + return can_reach(pos.x, pos.y, inset); + } + + #else + + // Return true if the given position is within the machine bounds. + static bool can_reach(XY_LIST(const float rx, const float ry)); + static bool can_reach(const xy_pos_t &pos) { + return can_reach(XY_LIST(pos.x, pos.y)); + } + + #endif + + // Hard Stop with potential step loss, used in rare situations + static void quickstop_stepper(); + + // Get the linear distance over multiple axes + static float get_move_distance(const xyze_pos_t &diff OPTARG(HAS_ROTATIONAL_AXES, bool &is_cartesian_move)); + + // Internal and procedural moves should run without feedrate scaling + static void remember_feedrate_scaling_off(); + static void restore_feedrate_and_scaling(); + + /** + * Move the planner to the current position from wherever it last moved + * (or from wherever it has been told it is located). + */ + static void goto_current_position(const feedRate_t fr_mm_s=feedrate_mm_s); + + #if HAS_EXTRUDERS + static void unscaled_e_move(const float length, const feedRate_t fr_mm_s); + #endif + + static void prepare_line_to_destination(); + + static void prepare_internal_move_to_destination(const feedRate_t fr_mm_s=0.0f) { + _goto_destination_internal(fr_mm_s); + } + + #if IS_KINEMATIC + static void prepare_fast_move_to_destination(const feedRate_t scaled_fr_mm_s=mms_scaled()); + + static void prepare_internal_fast_move_to_destination(const feedRate_t fr_mm_s=0.0f) { + _goto_destination_internal(fr_mm_s, true); + } + #endif + + // + // Blocking Move for internal procedures + // + + static void blocking_move(NUM_AXIS_ARGS_(const float) const feedRate_t fr_mm_s=0.0f); + static void blocking_move(const xy_pos_t &raw, const feedRate_t fr_mm_s=0.0f); + static void blocking_move(const xyz_pos_t &raw, const feedRate_t fr_mm_s=0.0f) { blocking_move(NUM_AXIS_ELEM_(raw) fr_mm_s); } + static void blocking_move(const xyze_pos_t &raw, const feedRate_t fr_mm_s=0.0f) { blocking_move(NUM_AXIS_ELEM_(raw) fr_mm_s); } + + #if HAS_X_AXIS + static void blocking_move_x(const float rx, const feedRate_t fr_mm_s=0.0f); + #endif + #if HAS_Y_AXIS + static void blocking_move_y(const float ry, const feedRate_t fr_mm_s=0.0f); + #endif + #if HAS_Z_AXIS + static void blocking_move_z(const float rz, const feedRate_t fr_mm_s=0.0f); + #endif + #if HAS_I_AXIS + static void blocking_move_i(const float ri, const feedRate_t fr_mm_s=0.0f); + static void blocking_move_xyz_i(const xyze_pos_t &raw, const float i, const feedRate_t fr_mm_s=0.0f); + #endif + #if HAS_J_AXIS + static void blocking_move_j(const float rj, const feedRate_t fr_mm_s=0.0f); + static void blocking_move_xyzi_j(const xyze_pos_t &raw, const float j, const feedRate_t fr_mm_s=0.0f); + #endif + #if HAS_K_AXIS + static void blocking_move_k(const float rk, const feedRate_t fr_mm_s=0.0f); + static void blocking_move_xyzij_k(const xyze_pos_t &raw, const float k, const feedRate_t fr_mm_s=0.0f); + #endif + #if HAS_U_AXIS + static void blocking_move_u(const float ru, const feedRate_t fr_mm_s=0.0f); + static void blocking_move_xyzijk_u(const xyze_pos_t &raw, const float u, const feedRate_t fr_mm_s=0.0f); + #endif + #if HAS_V_AXIS + static void blocking_move_v(const float rv, const feedRate_t fr_mm_s=0.0f); + static void blocking_move_xyzijku_v(const xyze_pos_t &raw, const float v, const feedRate_t fr_mm_s=0.0f); + #endif + #if HAS_W_AXIS + static void blocking_move_w(const float rw, const feedRate_t fr_mm_s=0.0f); + static void blocking_move_xyzijkuv_w(const xyze_pos_t &raw, const float w, const feedRate_t fr_mm_s=0.0f); + #endif + + #if HAS_Y_AXIS + static void blocking_move_xy(const float rx, const float ry, const feedRate_t fr_mm_s=0.0f); + static void blocking_move_xy(const xy_pos_t &raw, const feedRate_t fr_mm_s=0.0f); + static void blocking_move_xy(const xyz_pos_t &raw, const feedRate_t fr_mm_s=0.0f) { blocking_move_xy(xy_pos_t(raw), fr_mm_s); } + static void blocking_move_xy(const xyze_pos_t &raw, const feedRate_t fr_mm_s=0.0f) { blocking_move_xy(xy_pos_t(raw), fr_mm_s); } + #endif + + #if HAS_Z_AXIS + static void blocking_move_xy_z(const xy_pos_t &raw, const float z, const feedRate_t fr_mm_s=0.0f); + static void blocking_move_xy_z(const xyz_pos_t &raw, const float z, const feedRate_t fr_mm_s=0.0f) { blocking_move_xy_z(xy_pos_t(raw), z, fr_mm_s); } + static void blocking_move_xy_z(const xyze_pos_t &raw, const float z, const feedRate_t fr_mm_s=0.0f) { blocking_move_xy_z(xy_pos_t(raw), z, fr_mm_s); } + #endif + + static void do_homing_move(const AxisEnum axis, const float distance, const feedRate_t fr_mm_s=0.0, const bool final_approach=true); + + #if HAS_Z_AXIS + static void do_z_clearance(const float zclear, const bool with_probe=true, const bool lower_allowed=false); + static void do_z_clearance_by(const float zclear); + static void do_z_post_clearance(); + static void do_move_after_z_homing(); + #else + static void do_z_clearance(float, bool=true, bool=false) {} + static void do_z_clearance_by(float) {} + #endif + + // + // Realtime Reporting + // + + #if ENABLED(REALTIME_REPORTING_COMMANDS) + static M_StateEnum M_State_grbl; + M_StateEnum grbl_state_for_marlin_state(); + static void report_current_grblstate_moving(); + static void report_position_moving(); + + #if ENABLED(FULL_REPORT_TO_HOST_FEATURE) + static void set_and_report_grblstate(const M_StateEnum state, const bool force=true) { + if (force || M_State_grbl != state) { + M_State_grbl = state; + report_current_grblstate_moving(); + } + } + #endif + + static void quickpause_stepper(); + static void quickresume_stepper(); + #endif // REALTIME_REPORTING_COMMANDS + +private: + #if SECONDARY_AXES + static void secondary_axis_moves(SECONDARY_AXIS_ARGS_LC(const float), const feedRate_t fr_mm_s); + #endif + #if IS_KINEMATIC + static bool goto_destination_kinematic(); + #else + static bool goto_destination_cartesian(); + #if ENABLED(SEGMENT_LEVELED_MOVES) && DISABLED(AUTO_BED_LEVELING_UBL) + static void goto_destination_segmented(const feedRate_t fr_mm_s, const float segment_size=LEVELED_SEGMENT_LENGTH); + #endif + #endif + static void _goto_destination_internal(const feedRate_t fr_mm_s=0.0f OPTARG(IS_KINEMATIC, const bool is_fast=false)); + +}; // class Motion + // Determine XY_PROBE_FEEDRATE_MM_S - The feedrate used between Probe Points #if ABL_USES_GRID // ABL LINEAR and BILINEAR use 'G29 S' value, or MMM_TO_MMS(XY_PROBE_FEEDRATE) @@ -74,58 +539,6 @@ extern xyz_pos_t cartes; constexpr feedRate_t z_probe_fast_mm_s = MMM_TO_MMS(Z_PROBE_FEEDRATE_FAST); #endif -/** - * Feed rates are often configured with mm/m - * but the planner and stepper like mm/s units. - */ -#if ENABLED(EDITABLE_HOMING_FEEDRATE) - extern xyz_feedrate_t homing_feedrate_mm_m; -#else - constexpr xyz_feedrate_t homing_feedrate_mm_m = HOMING_FEEDRATE_MM_M; -#endif - -FORCE_INLINE feedRate_t homing_feedrate(const AxisEnum a) { - float v = TERN0(HAS_Z_AXIS, homing_feedrate_mm_m.z); - #if DISABLED(DELTA) - NUM_AXIS_CODE( - if (a == X_AXIS) v = homing_feedrate_mm_m.x, - else if (a == Y_AXIS) v = homing_feedrate_mm_m.y, - else if (a == Z_AXIS) v = homing_feedrate_mm_m.z, - else if (a == I_AXIS) v = homing_feedrate_mm_m.i, - else if (a == J_AXIS) v = homing_feedrate_mm_m.j, - else if (a == K_AXIS) v = homing_feedrate_mm_m.k, - else if (a == U_AXIS) v = homing_feedrate_mm_m.u, - else if (a == V_AXIS) v = homing_feedrate_mm_m.v, - else if (a == W_AXIS) v = homing_feedrate_mm_m.w - ); - #endif - return MMM_TO_MMS(v); -} - -feedRate_t get_homing_bump_feedrate(const AxisEnum axis); - -/** - * The default feedrate for many moves, set by the most recent move - */ -extern feedRate_t feedrate_mm_s; - -/** - * Feedrate scaling is applied to all G0/G1, G2/G3, and G5 moves - */ -extern int16_t feedrate_percentage; -#define MMS_SCALED(V) ((V) * 0.01f * feedrate_percentage) - -// The active extruder (tool). Set with T command. -#if HAS_MULTI_EXTRUDER - extern uint8_t active_extruder; -#else - constexpr uint8_t active_extruder = 0; -#endif - -#if ENABLED(LCD_SHOW_E_TOTAL) - extern float e_move_accumulator; -#endif - #ifdef __IMXRT1062__ #define DEFS_PROGMEM #else @@ -167,419 +580,13 @@ inline float home_bump_mm(const AxisEnum axis) { constexpr xyz_pos_t hotend_offset[1] = { { TERN_(HAS_X_AXIS, 0) } }; #endif -#if HAS_SOFTWARE_ENDSTOPS - - typedef struct { - bool _enabled, _loose; - bool enabled() { return _enabled && !_loose; } - - xyz_pos_t min, max; - void get_manual_axis_limits(const AxisEnum axis, float &amin, float &amax) { - amin = -100000; amax = 100000; // "No limits" - #if HAS_SOFTWARE_ENDSTOPS - if (enabled()) switch (axis) { - #if HAS_X_AXIS - case X_AXIS: - TERN_(MIN_SOFTWARE_ENDSTOP_X, amin = min.x); - TERN_(MAX_SOFTWARE_ENDSTOP_X, amax = max.x); - break; - #endif - #if HAS_Y_AXIS - case Y_AXIS: - TERN_(MIN_SOFTWARE_ENDSTOP_Y, amin = min.y); - TERN_(MAX_SOFTWARE_ENDSTOP_Y, amax = max.y); - break; - #endif - #if HAS_Z_AXIS - case Z_AXIS: - TERN_(MIN_SOFTWARE_ENDSTOP_Z, amin = min.z); - TERN_(MAX_SOFTWARE_ENDSTOP_Z, amax = max.z); - break; - #endif - #if HAS_I_AXIS - case I_AXIS: - TERN_(MIN_SOFTWARE_ENDSTOP_I, amin = min.i); - TERN_(MIN_SOFTWARE_ENDSTOP_I, amax = max.i); - break; - #endif - #if HAS_J_AXIS - case J_AXIS: - TERN_(MIN_SOFTWARE_ENDSTOP_J, amin = min.j); - TERN_(MIN_SOFTWARE_ENDSTOP_J, amax = max.j); - break; - #endif - #if HAS_K_AXIS - case K_AXIS: - TERN_(MIN_SOFTWARE_ENDSTOP_K, amin = min.k); - TERN_(MIN_SOFTWARE_ENDSTOP_K, amax = max.k); - break; - #endif - #if HAS_U_AXIS - case U_AXIS: - TERN_(MIN_SOFTWARE_ENDSTOP_U, amin = min.u); - TERN_(MIN_SOFTWARE_ENDSTOP_U, amax = max.u); - break; - #endif - #if HAS_V_AXIS - case V_AXIS: - TERN_(MIN_SOFTWARE_ENDSTOP_V, amin = min.v); - TERN_(MIN_SOFTWARE_ENDSTOP_V, amax = max.v); - break; - #endif - #if HAS_W_AXIS - case W_AXIS: - TERN_(MIN_SOFTWARE_ENDSTOP_W, amin = min.w); - TERN_(MIN_SOFTWARE_ENDSTOP_W, amax = max.w); - break; - #endif - default: break; - } - #endif - } - } soft_endstops_t; - - extern soft_endstops_t soft_endstop; - void apply_motion_limits(xyz_pos_t &target); - void update_software_endstops(const AxisEnum axis - #if HAS_HOTEND_OFFSET - , const uint8_t old_tool_index=0, const uint8_t new_tool_index=0 - #endif - ); - #define SET_SOFT_ENDSTOP_LOOSE(loose) (soft_endstop._loose = loose) - -#else // !HAS_SOFTWARE_ENDSTOPS - - typedef struct { - bool enabled() { return false; } - void get_manual_axis_limits(const AxisEnum axis, float &amin, float &amax) { - // No limits - amin = current_position[axis] - 1000; - amax = current_position[axis] + 1000; - } - } soft_endstops_t; - extern soft_endstops_t soft_endstop; - #define apply_motion_limits(V) NOOP - #define update_software_endstops(...) NOOP - #define SET_SOFT_ENDSTOP_LOOSE(V) NOOP - -#endif // !HAS_SOFTWARE_ENDSTOPS - -void report_real_position(); -void report_current_position(); -void report_current_position_projected(); - -#if ENABLED(AUTO_REPORT_POSITION) - #include "../libs/autoreport.h" - struct PositionReport { static void report() { - TERN(AUTO_REPORT_REAL_POSITION, report_real_position(), report_current_position_projected()); - } }; - extern AutoReporter position_auto_reporter; -#endif - -#if ENABLED(REALTIME_REPORTING_COMMANDS) - #define HAS_GRBL_STATE 1 - /** - * Machine states for GRBL or TinyG - */ - enum M_StateEnum : uint8_t { - M_INIT = 0, // 0 machine is initializing - M_RESET, // 1 machine is ready for use - M_ALARM, // 2 machine is in alarm state (soft shut down) - M_IDLE, // 3 program stop or no more blocks (M0, M1, M60) - M_END, // 4 program end via M2, M30 - M_RUNNING, // 5 motion is running - M_HOLD, // 6 motion is holding - M_PROBE, // 7 probe cycle active - M_CYCLING, // 8 machine is running (cycling) - M_HOMING, // 9 machine is homing - M_JOGGING, // 10 machine is jogging - M_ERROR // 11 machine is in hard alarm state (shut down) - }; - extern M_StateEnum M_State_grbl; - M_StateEnum grbl_state_for_marlin_state(); - void report_current_grblstate_moving(); - void report_current_position_moving(); - - #if ENABLED(FULL_REPORT_TO_HOST_FEATURE) - inline void set_and_report_grblstate(const M_StateEnum state, const bool force=true) { - if (force || M_State_grbl != state) { - M_State_grbl = state; - report_current_grblstate_moving(); - } - } - #endif - - void quickpause_stepper(); - void quickresume_stepper(); -#endif // REALTIME_REPORTING_COMMANDS - -float get_move_distance(const xyze_pos_t &diff OPTARG(HAS_ROTATIONAL_AXES, bool &is_cartesian_move)); - -void get_cartesian_from_steppers(); -void set_current_from_steppers_for_axis(const AxisEnum axis); - -void quickstop_stepper(); - -/** - * Set the planner/stepper positions directly from current_position with - * no kinematic translation. Used for homing axes and cartesian/core syncing. - */ -void sync_plan_position(); - -#if HAS_EXTRUDERS - void sync_plan_position_e(); -#endif - -/** - * Move the planner to the current position from wherever it last moved - * (or from wherever it has been told it is located). - */ -void line_to_current_position(const feedRate_t fr_mm_s=feedrate_mm_s); - -#if HAS_EXTRUDERS - void unscaled_e_move(const float length, const feedRate_t fr_mm_s); -#endif - -void prepare_line_to_destination(); - -void _internal_move_to_destination(const feedRate_t fr_mm_s=0.0f OPTARG(IS_KINEMATIC, const bool is_fast=false)); - -inline void prepare_internal_move_to_destination(const feedRate_t fr_mm_s=0.0f) { - _internal_move_to_destination(fr_mm_s); -} - -#if IS_KINEMATIC - void prepare_fast_move_to_destination(const feedRate_t scaled_fr_mm_s=MMS_SCALED(feedrate_mm_s)); - - inline void prepare_internal_fast_move_to_destination(const feedRate_t fr_mm_s=0.0f) { - _internal_move_to_destination(fr_mm_s, true); - } -#endif - -/** - * Blocking movement and shorthand functions - */ -void do_blocking_move_to(NUM_AXIS_ARGS_(const float) const feedRate_t fr_mm_s=0.0f); -void do_blocking_move_to(const xy_pos_t &raw, const feedRate_t fr_mm_s=0.0f); -void do_blocking_move_to(const xyz_pos_t &raw, const feedRate_t fr_mm_s=0.0f); -void do_blocking_move_to(const xyze_pos_t &raw, const feedRate_t fr_mm_s=0.0f); - -#if HAS_X_AXIS - void do_blocking_move_to_x(const float rx, const feedRate_t fr_mm_s=0.0f); -#endif -#if HAS_Y_AXIS - void do_blocking_move_to_y(const float ry, const feedRate_t fr_mm_s=0.0f); -#endif -#if HAS_Z_AXIS - void do_blocking_move_to_z(const float rz, const feedRate_t fr_mm_s=0.0f); -#endif -#if HAS_I_AXIS - void do_blocking_move_to_i(const float ri, const feedRate_t fr_mm_s=0.0f); - void do_blocking_move_to_xyz_i(const xyze_pos_t &raw, const float i, const feedRate_t fr_mm_s=0.0f); -#endif -#if HAS_J_AXIS - void do_blocking_move_to_j(const float rj, const feedRate_t fr_mm_s=0.0f); - void do_blocking_move_to_xyzi_j(const xyze_pos_t &raw, const float j, const feedRate_t fr_mm_s=0.0f); -#endif -#if HAS_K_AXIS - void do_blocking_move_to_k(const float rk, const feedRate_t fr_mm_s=0.0f); - void do_blocking_move_to_xyzij_k(const xyze_pos_t &raw, const float k, const feedRate_t fr_mm_s=0.0f); -#endif -#if HAS_U_AXIS - void do_blocking_move_to_u(const float ru, const feedRate_t fr_mm_s=0.0f); - void do_blocking_move_to_xyzijk_u(const xyze_pos_t &raw, const float u, const feedRate_t fr_mm_s=0.0f); -#endif -#if HAS_V_AXIS - void do_blocking_move_to_v(const float rv, const feedRate_t fr_mm_s=0.0f); - void do_blocking_move_to_xyzijku_v(const xyze_pos_t &raw, const float v, const feedRate_t fr_mm_s=0.0f); -#endif -#if HAS_W_AXIS - void do_blocking_move_to_w(const float rw, const feedRate_t fr_mm_s=0.0f); - void do_blocking_move_to_xyzijkuv_w(const xyze_pos_t &raw, const float w, const feedRate_t fr_mm_s=0.0f); -#endif - -#if HAS_Y_AXIS - void do_blocking_move_to_xy(const float rx, const float ry, const feedRate_t fr_mm_s=0.0f); - void do_blocking_move_to_xy(const xy_pos_t &raw, const feedRate_t fr_mm_s=0.0f); - FORCE_INLINE void do_blocking_move_to_xy(const xyz_pos_t &raw, const feedRate_t fr_mm_s=0.0f) { do_blocking_move_to_xy(xy_pos_t(raw), fr_mm_s); } - FORCE_INLINE void do_blocking_move_to_xy(const xyze_pos_t &raw, const feedRate_t fr_mm_s=0.0f) { do_blocking_move_to_xy(xy_pos_t(raw), fr_mm_s); } -#endif - -#if HAS_Z_AXIS - void do_blocking_move_to_xy_z(const xy_pos_t &raw, const float z, const feedRate_t fr_mm_s=0.0f); - FORCE_INLINE void do_blocking_move_to_xy_z(const xyz_pos_t &raw, const float z, const feedRate_t fr_mm_s=0.0f) { do_blocking_move_to_xy_z(xy_pos_t(raw), z, fr_mm_s); } - FORCE_INLINE void do_blocking_move_to_xy_z(const xyze_pos_t &raw, const float z, const feedRate_t fr_mm_s=0.0f) { do_blocking_move_to_xy_z(xy_pos_t(raw), z, fr_mm_s); } -#endif - -void remember_feedrate_scaling_off(); -void restore_feedrate_and_scaling(); - -#if HAS_Z_AXIS - #ifndef Z_POST_CLEARANCE // May be set by proui/dwin.h :-P - #ifdef Z_AFTER_HOMING - #define Z_POST_CLEARANCE Z_AFTER_HOMING - #else - #define Z_POST_CLEARANCE Z_CLEARANCE_FOR_HOMING - #endif - #endif - void do_z_clearance(const float zclear, const bool with_probe=true, const bool lower_allowed=false); - void do_z_clearance_by(const float zclear); - void do_move_after_z_homing(); - inline void do_z_post_clearance() { do_z_clearance(Z_POST_CLEARANCE); } -#else - inline void do_z_clearance(float, bool=true, bool=false) {} - inline void do_z_clearance_by(float) {} -#endif - -/** - * Homing and Trusted Axes - */ -typedef bits_t(NUM_AXES) main_axes_bits_t; -constexpr main_axes_bits_t main_axes_mask = _BV(NUM_AXES) - 1; - -#if HAS_Z_AXIS - extern bool z_min_trusted; // If Z has been powered on trust that the real Z is >= current_position.z -#endif - -void set_axis_is_at_home(const AxisEnum axis); - -#if HAS_ENDSTOPS - /** - * axes_homed - * Flags that each linear axis was homed. - * XYZ on cartesian, ABC on delta, ABZ on SCARA. - * - * axes_trusted - * Flags that the position is trusted in each linear axis. Set when homed. - * Cleared whenever a stepper powers off, potentially losing its position. - */ - extern main_axes_bits_t axes_homed, axes_trusted; - void homeaxis(const AxisEnum axis); - void set_axis_never_homed(const AxisEnum axis); - main_axes_bits_t axes_should_home(main_axes_bits_t axes_mask=main_axes_mask); - bool homing_needed_error(main_axes_bits_t axes_mask=main_axes_mask); -#else - constexpr main_axes_bits_t axes_homed = main_axes_mask, axes_trusted = main_axes_mask; // Zero-endstop machines are always homed and trusted - inline void homeaxis(const AxisEnum axis) {} - inline void set_axis_never_homed(const AxisEnum) {} - inline main_axes_bits_t axes_should_home(main_axes_bits_t=main_axes_mask) { return 0; } - inline bool homing_needed_error(main_axes_bits_t=main_axes_mask) { return false; } -#endif - -inline void set_axis_unhomed(const AxisEnum axis) { TERN_(HAS_ENDSTOPS, CBI(axes_homed, axis)); } -inline void set_axis_untrusted(const AxisEnum axis) { TERN_(HAS_ENDSTOPS, CBI(axes_trusted, axis)); } -inline void set_all_unhomed() { TERN_(HAS_ENDSTOPS, axes_homed = axes_trusted = 0); } -inline void set_axis_homed(const AxisEnum axis) { TERN_(HAS_ENDSTOPS, SBI(axes_homed, axis)); } -inline void set_axis_trusted(const AxisEnum axis) { TERN_(HAS_ENDSTOPS, SBI(axes_trusted, axis)); } -inline void set_all_homed() { TERN_(HAS_ENDSTOPS, axes_homed = axes_trusted = main_axes_mask); } - -inline bool axis_was_homed(const AxisEnum axis) { return TEST(axes_homed, axis); } -inline bool axis_is_trusted(const AxisEnum axis) { return TEST(axes_trusted, axis); } -inline bool axis_should_home(const AxisEnum axis) { return axes_should_home(_BV(axis)) != 0; } -inline bool no_axes_homed() { return !axes_homed; } -inline bool all_axes_homed() { return main_axes_mask == (axes_homed & main_axes_mask); } -inline bool homing_needed() { return !all_axes_homed(); } -inline bool all_axes_trusted() { return main_axes_mask == (axes_trusted & main_axes_mask); } - -void home_if_needed(const bool keeplev=false); - #if ENABLED(NO_MOTION_BEFORE_HOMING) #define MOTION_CONDITIONS (marlin.isRunning() && !homing_needed_error()) #else #define MOTION_CONDITIONS marlin.isRunning() #endif -#define BABYSTEP_ALLOWED() ((ENABLED(BABYSTEP_WITHOUT_HOMING) || all_axes_trusted()) && (ENABLED(BABYSTEP_ALWAYS_AVAILABLE) || marlin.printer_busy())) - -#if HAS_HOME_OFFSET - extern xyz_pos_t home_offset; -#endif - -/** - * Workspace offsets - */ -#if HAS_WORKSPACE_OFFSET - extern xyz_pos_t workspace_offset; - #define NATIVE_TO_LOGICAL(POS, AXIS) ((POS) + workspace_offset[AXIS]) - #define LOGICAL_TO_NATIVE(POS, AXIS) ((POS) - workspace_offset[AXIS]) - FORCE_INLINE void toLogical(xy_pos_t &raw) { raw += workspace_offset; } - FORCE_INLINE void toLogical(xyz_pos_t &raw) { raw += workspace_offset; } - FORCE_INLINE void toLogical(xyze_pos_t &raw) { raw += workspace_offset; } - FORCE_INLINE void toNative(xy_pos_t &raw) { raw -= workspace_offset; } - FORCE_INLINE void toNative(xyz_pos_t &raw) { raw -= workspace_offset; } - FORCE_INLINE void toNative(xyze_pos_t &raw) { raw -= workspace_offset; } -#else - #define NATIVE_TO_LOGICAL(POS, AXIS) (POS) - #define LOGICAL_TO_NATIVE(POS, AXIS) (POS) - FORCE_INLINE void toLogical(xy_pos_t&) {} - FORCE_INLINE void toLogical(xyz_pos_t&) {} - FORCE_INLINE void toLogical(xyze_pos_t&) {} - FORCE_INLINE void toNative(xy_pos_t&) {} - FORCE_INLINE void toNative(xyz_pos_t&) {} - FORCE_INLINE void toNative(xyze_pos_t&) {} -#endif -#if HAS_X_AXIS - #define LOGICAL_X_POSITION(POS) NATIVE_TO_LOGICAL(POS, X_AXIS) - #define RAW_X_POSITION(POS) LOGICAL_TO_NATIVE(POS, X_AXIS) -#endif -#if HAS_Y_AXIS - #define LOGICAL_Y_POSITION(POS) NATIVE_TO_LOGICAL(POS, Y_AXIS) - #define RAW_Y_POSITION(POS) LOGICAL_TO_NATIVE(POS, Y_AXIS) -#endif -#if HAS_Z_AXIS - #define LOGICAL_Z_POSITION(POS) NATIVE_TO_LOGICAL(POS, Z_AXIS) - #define RAW_Z_POSITION(POS) LOGICAL_TO_NATIVE(POS, Z_AXIS) -#endif -#if HAS_I_AXIS - #define LOGICAL_I_POSITION(POS) NATIVE_TO_LOGICAL(POS, I_AXIS) - #define RAW_I_POSITION(POS) LOGICAL_TO_NATIVE(POS, I_AXIS) -#endif -#if HAS_J_AXIS - #define LOGICAL_J_POSITION(POS) NATIVE_TO_LOGICAL(POS, J_AXIS) - #define RAW_J_POSITION(POS) LOGICAL_TO_NATIVE(POS, J_AXIS) -#endif -#if HAS_K_AXIS - #define LOGICAL_K_POSITION(POS) NATIVE_TO_LOGICAL(POS, K_AXIS) - #define RAW_K_POSITION(POS) LOGICAL_TO_NATIVE(POS, K_AXIS) -#endif -#if HAS_U_AXIS - #define LOGICAL_U_POSITION(POS) NATIVE_TO_LOGICAL(POS, U_AXIS) - #define RAW_U_POSITION(POS) LOGICAL_TO_NATIVE(POS, U_AXIS) -#endif -#if HAS_V_AXIS - #define LOGICAL_V_POSITION(POS) NATIVE_TO_LOGICAL(POS, V_AXIS) - #define RAW_V_POSITION(POS) LOGICAL_TO_NATIVE(POS, V_AXIS) -#endif -#if HAS_W_AXIS - #define LOGICAL_W_POSITION(POS) NATIVE_TO_LOGICAL(POS, W_AXIS) - #define RAW_W_POSITION(POS) LOGICAL_TO_NATIVE(POS, W_AXIS) -#endif - -/** - * position_is_reachable family of functions - */ -#if IS_KINEMATIC // (DELTA or SCARA) - - #if HAS_SCARA_OFFSET - extern abc_pos_t scara_home_offset; // A and B angular offsets, Z mm offset - #endif - - // Return true if the given point is within the printable area - bool position_is_reachable(const float rx, const float ry, const float inset=0.0f); - - inline bool position_is_reachable(const xy_pos_t &pos, const float inset=0.0f) { - return position_is_reachable(pos.x, pos.y, inset); - } - -#else - - // Return true if the given position is within the machine bounds. - bool position_is_reachable(XY_LIST(const float rx, const float ry)); - inline bool position_is_reachable(const xy_pos_t &pos) { - return position_is_reachable(XY_LIST(pos.x, pos.y)); - } - -#endif +#define BABYSTEP_ALLOWED() ((ENABLED(BABYSTEP_WITHOUT_HOMING) || motion.all_axes_trusted()) && (ENABLED(BABYSTEP_ALWAYS_AVAILABLE) || marlin.printer_busy())) /** * Duplication mode @@ -631,10 +638,6 @@ void home_if_needed(const bool keeplev=false); #endif -#if HAS_HOME_OFFSET - void set_home_offset(const AxisEnum axis, const float v); -#endif - // // Trinamic Stepper Drivers // @@ -648,3 +651,13 @@ void home_if_needed(const bool keeplev=false); void set_homing_current(const AxisEnum axis); void restore_homing_current(const AxisEnum axis); #endif + +extern Motion motion; + +// External conversion methods (motion.h) +inline void toLogical(xy_pos_t &raw) { motion.toLogical(raw); } +inline void toLogical(xyz_pos_t &raw) { motion.toLogical(raw); } +inline void toLogical(xyze_pos_t &raw) { motion.toLogical(raw); } +inline void toNative(xy_pos_t &lpos) { motion.toNative(lpos); } +inline void toNative(xyz_pos_t &lpos) { motion.toNative(lpos); } +inline void toNative(xyze_pos_t &lpos) { motion.toNative(lpos); } diff --git a/Marlin/src/module/planner.cpp b/Marlin/src/module/planner.cpp index 89f34e5e1b..ad727ce21f 100644 --- a/Marlin/src/module/planner.cpp +++ b/Marlin/src/module/planner.cpp @@ -1546,12 +1546,12 @@ void Planner::check_axes_activity() { */ void Planner::apply_retract(float &rz, float &e) { rz += fwretract.current_hop; - e -= fwretract.current_retract[active_extruder]; + e -= fwretract.current_retract[motion.extruder]; } void Planner::unapply_retract(float &rz, float &e) { rz -= fwretract.current_hop; - e += fwretract.current_retract[active_extruder]; + e += fwretract.current_retract[motion.extruder]; } #endif @@ -1598,12 +1598,12 @@ void Planner::quick_stop() { // Don't empty buffers or queues const bool did_suspend = stepper.suspend(); if (did_suspend) - TERN_(FULL_REPORT_TO_HOST_FEATURE, set_and_report_grblstate(M_HOLD)); + TERN_(FULL_REPORT_TO_HOST_FEATURE, motion.set_and_report_grblstate(M_HOLD)); } // Resume if suspended void Planner::quick_resume() { - TERN_(FULL_REPORT_TO_HOST_FEATURE, set_and_report_grblstate(grbl_state_for_marlin_state())); + TERN_(FULL_REPORT_TO_HOST_FEATURE, motion.set_and_report_grblstate(motion.grbl_state_for_marlin_state())); stepper.wake_up(); } @@ -2017,7 +2017,7 @@ bool Planner::_populate_block( TERN_(HAS_REAL_Z, dist_mm.real.z = dz); TERN_(HAS_EXTRUDERS, dist_mm.e = esteps_float * mm_per_step[E_AXIS_N(extruder)]); - TERN_(LCD_SHOW_E_TOTAL, e_move_accumulator += dist_mm.e); + TERN_(LCD_SHOW_E_TOTAL, motion.e_move_accumulator += dist_mm.e); TERN_(FT_MOTION, block->ext_distance_mm = dist_mm); // Store the distance for all axes in mm for this block @@ -2043,7 +2043,7 @@ bool Planner::_populate_block( dist_mm.u, dist_mm.v, dist_mm.w ); - block->millimeters = get_move_distance(displacement OPTARG(HAS_ROTATIONAL_AXES, cartesian_move)); + block->millimeters = motion.get_move_distance(displacement OPTARG(HAS_ROTATIONAL_AXES, cartesian_move)); } /** @@ -2822,7 +2822,7 @@ void Planner::buffer_sync_block(const BlockFlagBit sync_flag/*=BLOCK_BIT_SYNC_PO * @param abce Target position in mm and/or degrees * @param cart_dist_mm The pre-calculated move lengths for all axes, in mm * @param fr_mm_s (Target) speed of the move - * @param extruder Optional target extruder (otherwise active_extruder) + * @param extruder Optional target extruder (otherwise motion.extruder) * @param hints Optional parameters to aid planner calculations * * @return false if no segment was queued due to cleaning, cold extrusion, full queue, etc. @@ -2830,7 +2830,7 @@ void Planner::buffer_sync_block(const BlockFlagBit sync_flag/*=BLOCK_BIT_SYNC_PO bool Planner::buffer_segment(const abce_pos_t &abce OPTARG(HAS_DIST_MM_ARG, const xyze_float_t &cart_dist_mm) , const feedRate_t fr_mm_s - , const uint8_t extruder/*=active_extruder*/ + , const uint8_t extruder/*=motion.extruder*/ , const PlannerHints &hints/*=PlannerHints()*/ ) { @@ -2951,11 +2951,11 @@ bool Planner::buffer_segment(const abce_pos_t &abce * * @param cart Target position in mm or degrees * @param fr_mm_s (Target) speed of the move (mm/s) - * @param extruder Optional target extruder (otherwise active_extruder) + * @param extruder Optional target extruder (otherwise motion.extruder) * @param hints Optional parameters to aid planner calculations */ bool Planner::buffer_line(const xyze_pos_t &cart, const feedRate_t fr_mm_s - , const uint8_t extruder/*=active_extruder*/ + , const uint8_t extruder/*=motion.extruder*/ , const PlannerHints &hints/*=PlannerHints()*/ ) { xyze_pos_t machine = cart; @@ -2984,7 +2984,7 @@ bool Planner::buffer_line(const xyze_pos_t &cart, const feedRate_t fr_mm_s // Provide known Cartesian length in the hints structure PlannerHints ph = hints; if (!hints.millimeters) - ph.millimeters = get_move_distance(xyze_pos_t(cart_dist_mm) OPTARG(HAS_ROTATIONAL_AXES, ph.cartesian_move)); + ph.millimeters = motion.get_move_distance(xyze_pos_t(cart_dist_mm) OPTARG(HAS_ROTATIONAL_AXES, ph.cartesian_move)); #if DISABLED(FEEDRATE_SCALING) @@ -2995,7 +2995,7 @@ bool Planner::buffer_line(const xyze_pos_t &cart, const feedRate_t fr_mm_s // For SCARA scale the feedrate from mm/s to degrees/s // i.e., Complete the angular vector in the given time. const float duration_recip = hints.inv_duration ?: fr_mm_s / ph.millimeters; - const xyz_pos_t diff = delta - position_float; + const xyz_pos_t diff = motion.delta - position_float; const feedRate_t feedrate = diff.magnitude() * duration_recip; #elif ENABLED(POLAR) @@ -3023,9 +3023,9 @@ bool Planner::buffer_line(const xyze_pos_t &cart, const feedRate_t fr_mm_s * This shouldn't be a problem for cutting/milling operations. */ feedRate_t calculated_feedrate = fr_mm_s; - const xyz_pos_t diff = delta - position_float; + const xyz_pos_t diff = motion.delta - position_float; if (!NEAR_ZERO(diff.b)) { - if (delta.a <= POLAR_FAST_RADIUS) + if (motion.delta.a <= POLAR_FAST_RADIUS) calculated_feedrate = settings.max_feedrate_mm_s[Y_AXIS]; else { // Normalized vector of movement @@ -3034,7 +3034,7 @@ bool Planner::buffer_line(const xyze_pos_t &cart, const feedRate_t fr_mm_s normalizedTheta = 1.0f - (ABS(diffTheta > 90.0f ? 180.0f - diffTheta : diffTheta) / 90.0f); // Normalized position along the radius - const float radiusRatio = (PRINTABLE_RADIUS) / delta.a; + const float radiusRatio = (PRINTABLE_RADIUS) / motion.delta.a; calculated_feedrate += (fr_mm_s * radiusRatio * normalizedTheta); } } @@ -3042,8 +3042,8 @@ bool Planner::buffer_line(const xyze_pos_t &cart, const feedRate_t fr_mm_s #endif // POLAR && FEEDRATE_SCALING - TERN_(HAS_EXTRUDERS, delta.e = machine.e); - if (buffer_segment(delta OPTARG(HAS_DIST_MM_ARG, cart_dist_mm), feedrate, extruder, ph)) { + TERN_(HAS_EXTRUDERS, motion.delta.e = machine.e); + if (buffer_segment(motion.delta OPTARG(HAS_DIST_MM_ARG, cart_dist_mm), feedrate, extruder, ph)) { position_cart = cart; return true; } @@ -3122,11 +3122,11 @@ void Planner::set_machine_position_mm(const abce_pos_t &abce) { // When FT Motion is enabled, call synchronize() here instead of generating a sync block if (TERN0(FT_MOTION, ftMotion.cfg.active)) synchronize(); - TERN_(DISTINCT_E_FACTORS, last_extruder = active_extruder); + TERN_(DISTINCT_E_FACTORS, last_extruder = motion.extruder); TERN_(HAS_POSITION_FLOAT, position_float = abce); position.set( LOGICAL_AXIS_LIST( - LROUND(abce.e * settings.axis_steps_per_mm[E_AXIS_N(active_extruder)]), + LROUND(abce.e * settings.axis_steps_per_mm[E_AXIS_N(motion.extruder)]), LROUND(abce.a * settings.axis_steps_per_mm[A_AXIS]), LROUND(abce.b * settings.axis_steps_per_mm[B_AXIS]), LROUND(abce.c * settings.axis_steps_per_mm[C_AXIS]), @@ -3169,8 +3169,8 @@ void Planner::set_position_mm(const xyze_pos_t &xyze) { #if IS_KINEMATIC position_cart = xyze; inverse_kinematics(machine); - TERN_(HAS_EXTRUDERS, delta.e = machine.e); - set_machine_position_mm(delta); + TERN_(HAS_EXTRUDERS, motion.delta.e = machine.e); + set_machine_position_mm(motion.delta); #else set_machine_position_mm(machine); #endif @@ -3182,11 +3182,11 @@ void Planner::set_position_mm(const xyze_pos_t &xyze) { * Special setter for planner E position (also setting E stepper position). */ void Planner::set_e_position_mm(const float e) { - const uint8_t axis_index = E_AXIS_N(active_extruder); - TERN_(DISTINCT_E_FACTORS, last_extruder = active_extruder); + const uint8_t axis_index = E_AXIS_N(motion.extruder); + TERN_(DISTINCT_E_FACTORS, last_extruder = motion.extruder); // Unapply the current retraction before (immediately) setting the planner position - const float e_new = DIFF_TERN(FWRETRACT, e, fwretract.current_retract[active_extruder]); + const float e_new = DIFF_TERN(FWRETRACT, e, fwretract.current_retract[motion.extruder]); position.e = LROUND(settings.axis_steps_per_mm[axis_index] * e_new); TERN_(HAS_POSITION_FLOAT, position_float.e = e_new); TERN_(IS_KINEMATIC, TERN_(HAS_EXTRUDERS, position_cart.e = e)); @@ -3206,7 +3206,7 @@ void Planner::refresh_acceleration_rates() { uint32_t highest_rate = 1; LOOP_DISTINCT_AXES(i) { max_acceleration_steps_per_s2[i] = settings.max_acceleration_mm_per_s2[i] * settings.axis_steps_per_mm[i]; - if (TERN1(DISTINCT_E_FACTORS, i < E_AXIS || i == E_AXIS_N(active_extruder))) + if (TERN1(DISTINCT_E_FACTORS, i < E_AXIS || i == E_AXIS_N(motion.extruder))) NOLESS(highest_rate, max_acceleration_steps_per_s2[i]); } acceleration_long_cutoff = UINT32_MAX / highest_rate; @@ -3225,7 +3225,7 @@ void Planner::refresh_positioning() { stepper.nle.q30.B = _BV32(30) * (stepper.nle.settings.coeff.B * mm_per_step[E_AXIS_N(0)]); #endif #endif - set_position_mm(current_position); + set_position_mm(motion.position); refresh_acceleration_rates(); } diff --git a/Marlin/src/module/planner.h b/Marlin/src/module/planner.h index 46def85427..a9d4c37afa 100644 --- a/Marlin/src/module/planner.h +++ b/Marlin/src/module/planner.h @@ -580,19 +580,19 @@ class Planner { #if HAS_LIN_ADVANCE_K static float extruder_advance_K[DISTINCT_E]; - static void set_advance_k(const float k, const uint8_t e=active_extruder) { + static void set_advance_k(const float k, const uint8_t e=motion.extruder) { UNUSED(e); extruder_advance_K[E_INDEX_N(e)] = k; TERN_(SMOOTH_LIN_ADVANCE, extruder_advance_K_q27[E_INDEX_N(e)] = k * _BV32(27)); } - static float get_advance_k(const uint8_t e=active_extruder) { + static float get_advance_k(const uint8_t e=motion.extruder) { UNUSED(e); return extruder_advance_K[E_INDEX_N(e)]; } #endif #if ENABLED(SMOOTH_LIN_ADVANCE) - static uint32_t get_advance_k_q27(const uint8_t e=active_extruder) { + static uint32_t get_advance_k_q27(const uint8_t e=motion.extruder) { UNUSED(e); return extruder_advance_K_q27[E_INDEX_N(e)]; } @@ -1003,7 +1003,7 @@ class Planner { * @param abce Target position in mm and/or degrees * @param cart_dist_mm The pre-calculated move lengths for all axes, in mm * @param fr_mm_s (Target) speed of the move - * @param extruder Optional target extruder (otherwise active_extruder) + * @param extruder Optional target extruder (otherwise motion.extruder) * @param hints Optional parameters to aid planner calculations * * @return false if no segment was queued due to cleaning, cold extrusion, full queue, etc... @@ -1011,7 +1011,7 @@ class Planner { static bool buffer_segment(const abce_pos_t &abce OPTARG(HAS_DIST_MM_ARG, const xyze_float_t &cart_dist_mm) , const feedRate_t fr_mm_s - , const uint8_t extruder=active_extruder + , const uint8_t extruder=motion.extruder , const PlannerHints &hints=PlannerHints() ); @@ -1024,13 +1024,13 @@ class Planner { * * @param cart Target position in mm or degrees * @param fr_mm_s (Target) speed of the move (mm/s) - * @param extruder Optional target extruder (otherwise active_extruder) + * @param extruder Optional target extruder (otherwise motion.extruder) * @param hints Optional parameters to aid planner calculations * * @return false if no segment was queued due to cleaning, cold extrusion, full queue, etc... */ static bool buffer_line(const xyze_pos_t &cart, const feedRate_t fr_mm_s - , const uint8_t extruder=active_extruder + , const uint8_t extruder=motion.extruder , const PlannerHints &hints=PlannerHints() ); @@ -1200,7 +1200,7 @@ class Planner { #if IS_KINEMATIC // Allow do_homing_move to access internal functions, such as buffer_segment. - friend void do_homing_move(const AxisEnum, const float, const feedRate_t, const bool); + friend void Motion::do_homing_move(const AxisEnum, const float, const feedRate_t, const bool); #endif #if HAS_JUNCTION_DEVIATION diff --git a/Marlin/src/module/planner_bezier.cpp b/Marlin/src/module/planner_bezier.cpp index bcf92f7e51..4647d095ea 100644 --- a/Marlin/src/module/planner_bezier.cpp +++ b/Marlin/src/module/planner_bezier.cpp @@ -195,7 +195,7 @@ void cubic_b_spline( interp(position.v, target.v, t), // FIXME. Wrong, since t is not linear in the distance. interp(position.w, target.w, t) // FIXME. Wrong, since t is not linear in the distance. ); - apply_motion_limits(new_bez); + motion.apply_limits(new_bez); bez_target = new_bez; #if HAS_LEVELING && !PLANNER_LEVELING @@ -205,7 +205,7 @@ void cubic_b_spline( const xyze_pos_t &pos = bez_target; #endif - if (!planner.buffer_line(pos, scaled_fr_mm_s, active_extruder, hints)) + if (!planner.buffer_line(pos, scaled_fr_mm_s, motion.extruder, hints)) break; } } diff --git a/Marlin/src/module/polar.cpp b/Marlin/src/module/polar.cpp index fb35ae9f58..523c4f9cfd 100644 --- a/Marlin/src/module/polar.cpp +++ b/Marlin/src/module/polar.cpp @@ -58,8 +58,10 @@ void forward_kinematics(const float r, const float theta) { const float absTheta = absoluteAngle(theta); float radius = r; if (polar_center_offset > 0.0) radius = SQRT( ABS( sq(r) - sq(-polar_center_offset) ) ); - cartes.x = cos(RADIANS(absTheta))*radius; - cartes.y = sin(RADIANS(absTheta))*radius; + motion.cartes.set( + cos(RADIANS(absTheta)) * radius, + sin(RADIANS(absTheta)) * radius + ); } void inverse_kinematics(const xyz_pos_t &raw) { @@ -89,7 +91,7 @@ void inverse_kinematics(const xyz_pos_t &raw) { current_polar_theta = theta; - delta.set(r, theta, raw.z); + motion.delta.set(r, theta, raw.z); } void polar_report_positions() { diff --git a/Marlin/src/module/polargraph.cpp b/Marlin/src/module/polargraph.cpp index 10e596efed..7d702ce361 100644 --- a/Marlin/src/module/polargraph.cpp +++ b/Marlin/src/module/polargraph.cpp @@ -42,7 +42,7 @@ xy_pos_t draw_area_min, draw_area_max; void inverse_kinematics(const xyz_pos_t &raw) { const float x1 = raw.x - draw_area_min.x, x2 = draw_area_max.x - raw.x, y = raw.y - draw_area_max.y; - delta.set(HYPOT(x1, y), HYPOT(x2, y) OPTARG(HAS_Z_AXIS, raw.z)); + motion.delta.set(HYPOT(x1, y), HYPOT(x2, y) OPTARG(HAS_Z_AXIS, raw.z)); } #endif // POLARGRAPH diff --git a/Marlin/src/module/probe.cpp b/Marlin/src/module/probe.cpp index 3a8bb2b6c6..2f80a7044f 100644 --- a/Marlin/src/module/probe.cpp +++ b/Marlin/src/module/probe.cpp @@ -129,7 +129,7 @@ xyz_pos_t Probe::offset; // Initialized by settings.load if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("dock_sled(", stow, ")"); // Dock sled a bit closer to ensure proper capturing - do_blocking_move_to_x(X_MAX_POS + SLED_DOCKING_OFFSET - ((stow) ? 1 : 0)); + motion.blocking_move_x(X_MAX_POS + SLED_DOCKING_OFFSET - ((stow) ? 1 : 0)); #if HAS_SOLENOID_1 && DISABLED(EXT_SOLENOID) WRITE(SOL1_PIN, !stow); // switch solenoid @@ -145,7 +145,7 @@ xyz_pos_t Probe::offset; // Initialized by settings.load WRITE(MAGLEV_TRIGGER_PIN, LOW); } - inline void maglev_idle() { do_z_clearance(10); } + inline void maglev_idle() { motion.do_z_clearance(10); } #elif ENABLED(TOUCH_MI_PROBE) @@ -172,21 +172,21 @@ xyz_pos_t Probe::offset; // Initialized by settings.load ui.goto_screen(prev_screen); #elif defined(TOUCH_MI_DEPLOY_XPOS) && defined(TOUCH_MI_DEPLOY_YPOS) - do_blocking_move_to_xy(TOUCH_MI_DEPLOY_XPOS, TOUCH_MI_DEPLOY_YPOS); + motion.blocking_move_xy(TOUCH_MI_DEPLOY_XPOS, TOUCH_MI_DEPLOY_YPOS); #elif defined(TOUCH_MI_DEPLOY_XPOS) - do_blocking_move_to_x(TOUCH_MI_DEPLOY_XPOS); + motion.blocking_move_x(TOUCH_MI_DEPLOY_XPOS); #elif defined(TOUCH_MI_DEPLOY_YPOS) - do_blocking_move_to_y(TOUCH_MI_DEPLOY_YPOS); + motion.blocking_move_y(TOUCH_MI_DEPLOY_YPOS); #endif } // Move down to the bed to stow the probe // TODO: Handle cases where it would be a bad idea to move down. inline void run_stow_moves() { - const float oldz = current_position.z; + const float oldz = motion.position.z; endstops.enable_z_probe(false); - do_blocking_move_to_z(TOUCH_MI_RETRACT_Z, homing_feedrate(Z_AXIS)); - do_blocking_move_to_z(oldz, homing_feedrate(Z_AXIS)); + motion.blocking_move_z(TOUCH_MI_RETRACT_Z, motion.homing_feedrate(Z_AXIS)); + motion.blocking_move_z(oldz, motion.homing_feedrate(Z_AXIS)); } #elif ENABLED(Z_PROBE_ALLEN_KEY) @@ -197,35 +197,35 @@ xyz_pos_t Probe::offset; // Initialized by settings.load #define Z_PROBE_ALLEN_KEY_DEPLOY_1_FEEDRATE 0.0f #endif constexpr xyz_pos_t deploy_1 = Z_PROBE_ALLEN_KEY_DEPLOY_1; - do_blocking_move_to(deploy_1, MMM_TO_MMS(Z_PROBE_ALLEN_KEY_DEPLOY_1_FEEDRATE)); + motion.blocking_move(deploy_1, MMM_TO_MMS(Z_PROBE_ALLEN_KEY_DEPLOY_1_FEEDRATE)); #endif #ifdef Z_PROBE_ALLEN_KEY_DEPLOY_2 #ifndef Z_PROBE_ALLEN_KEY_DEPLOY_2_FEEDRATE #define Z_PROBE_ALLEN_KEY_DEPLOY_2_FEEDRATE 0.0f #endif constexpr xyz_pos_t deploy_2 = Z_PROBE_ALLEN_KEY_DEPLOY_2; - do_blocking_move_to(deploy_2, MMM_TO_MMS(Z_PROBE_ALLEN_KEY_DEPLOY_2_FEEDRATE)); + motion.blocking_move(deploy_2, MMM_TO_MMS(Z_PROBE_ALLEN_KEY_DEPLOY_2_FEEDRATE)); #endif #ifdef Z_PROBE_ALLEN_KEY_DEPLOY_3 #ifndef Z_PROBE_ALLEN_KEY_DEPLOY_3_FEEDRATE #define Z_PROBE_ALLEN_KEY_DEPLOY_3_FEEDRATE 0.0f #endif constexpr xyz_pos_t deploy_3 = Z_PROBE_ALLEN_KEY_DEPLOY_3; - do_blocking_move_to(deploy_3, MMM_TO_MMS(Z_PROBE_ALLEN_KEY_DEPLOY_3_FEEDRATE)); + motion.blocking_move(deploy_3, MMM_TO_MMS(Z_PROBE_ALLEN_KEY_DEPLOY_3_FEEDRATE)); #endif #ifdef Z_PROBE_ALLEN_KEY_DEPLOY_4 #ifndef Z_PROBE_ALLEN_KEY_DEPLOY_4_FEEDRATE #define Z_PROBE_ALLEN_KEY_DEPLOY_4_FEEDRATE 0.0f #endif constexpr xyz_pos_t deploy_4 = Z_PROBE_ALLEN_KEY_DEPLOY_4; - do_blocking_move_to(deploy_4, MMM_TO_MMS(Z_PROBE_ALLEN_KEY_DEPLOY_4_FEEDRATE)); + motion.blocking_move(deploy_4, MMM_TO_MMS(Z_PROBE_ALLEN_KEY_DEPLOY_4_FEEDRATE)); #endif #ifdef Z_PROBE_ALLEN_KEY_DEPLOY_5 #ifndef Z_PROBE_ALLEN_KEY_DEPLOY_5_FEEDRATE #define Z_PROBE_ALLEN_KEY_DEPLOY_5_FEEDRATE 0.0f #endif constexpr xyz_pos_t deploy_5 = Z_PROBE_ALLEN_KEY_DEPLOY_5; - do_blocking_move_to(deploy_5, MMM_TO_MMS(Z_PROBE_ALLEN_KEY_DEPLOY_5_FEEDRATE)); + motion.blocking_move(deploy_5, MMM_TO_MMS(Z_PROBE_ALLEN_KEY_DEPLOY_5_FEEDRATE)); #endif } @@ -235,35 +235,35 @@ xyz_pos_t Probe::offset; // Initialized by settings.load #define Z_PROBE_ALLEN_KEY_STOW_1_FEEDRATE 0.0f #endif constexpr xyz_pos_t stow_1 = Z_PROBE_ALLEN_KEY_STOW_1; - do_blocking_move_to(stow_1, MMM_TO_MMS(Z_PROBE_ALLEN_KEY_STOW_1_FEEDRATE)); + motion.blocking_move(stow_1, MMM_TO_MMS(Z_PROBE_ALLEN_KEY_STOW_1_FEEDRATE)); #endif #ifdef Z_PROBE_ALLEN_KEY_STOW_2 #ifndef Z_PROBE_ALLEN_KEY_STOW_2_FEEDRATE #define Z_PROBE_ALLEN_KEY_STOW_2_FEEDRATE 0.0f #endif constexpr xyz_pos_t stow_2 = Z_PROBE_ALLEN_KEY_STOW_2; - do_blocking_move_to(stow_2, MMM_TO_MMS(Z_PROBE_ALLEN_KEY_STOW_2_FEEDRATE)); + motion.blocking_move(stow_2, MMM_TO_MMS(Z_PROBE_ALLEN_KEY_STOW_2_FEEDRATE)); #endif #ifdef Z_PROBE_ALLEN_KEY_STOW_3 #ifndef Z_PROBE_ALLEN_KEY_STOW_3_FEEDRATE #define Z_PROBE_ALLEN_KEY_STOW_3_FEEDRATE 0.0f #endif constexpr xyz_pos_t stow_3 = Z_PROBE_ALLEN_KEY_STOW_3; - do_blocking_move_to(stow_3, MMM_TO_MMS(Z_PROBE_ALLEN_KEY_STOW_3_FEEDRATE)); + motion.blocking_move(stow_3, MMM_TO_MMS(Z_PROBE_ALLEN_KEY_STOW_3_FEEDRATE)); #endif #ifdef Z_PROBE_ALLEN_KEY_STOW_4 #ifndef Z_PROBE_ALLEN_KEY_STOW_4_FEEDRATE #define Z_PROBE_ALLEN_KEY_STOW_4_FEEDRATE 0.0f #endif constexpr xyz_pos_t stow_4 = Z_PROBE_ALLEN_KEY_STOW_4; - do_blocking_move_to(stow_4, MMM_TO_MMS(Z_PROBE_ALLEN_KEY_STOW_4_FEEDRATE)); + motion.blocking_move(stow_4, MMM_TO_MMS(Z_PROBE_ALLEN_KEY_STOW_4_FEEDRATE)); #endif #ifdef Z_PROBE_ALLEN_KEY_STOW_5 #ifndef Z_PROBE_ALLEN_KEY_STOW_5_FEEDRATE #define Z_PROBE_ALLEN_KEY_STOW_5_FEEDRATE 0.0f #endif constexpr xyz_pos_t stow_5 = Z_PROBE_ALLEN_KEY_STOW_5; - do_blocking_move_to(stow_5, MMM_TO_MMS(Z_PROBE_ALLEN_KEY_STOW_5_FEEDRATE)); + motion.blocking_move(stow_5, MMM_TO_MMS(Z_PROBE_ALLEN_KEY_STOW_5_FEEDRATE)); #endif } @@ -274,30 +274,30 @@ xyz_pos_t Probe::offset; // Initialized by settings.load inline void run_deploy_moves() { #ifdef MAG_MOUNTED_PRE_DEPLOY constexpr mag_probe_move_t pre_deploy = MAG_MOUNTED_PRE_DEPLOY; - do_blocking_move_to(pre_deploy.where, MMM_TO_MMS(pre_deploy.fr_mm_min)); + motion.blocking_move(pre_deploy.where, MMM_TO_MMS(pre_deploy.fr_mm_min)); #endif #if HAS_MAG_MOUNTED_SERVO_PROBE servo[MAG_MOUNTED_PROBE_SERVO_NR].move(servo_angles[MAG_MOUNTED_PROBE_SERVO_NR][0]); #endif #ifdef MAG_MOUNTED_DEPLOY_1 constexpr mag_probe_move_t deploy_1 = MAG_MOUNTED_DEPLOY_1; - do_blocking_move_to(deploy_1.where, MMM_TO_MMS(deploy_1.fr_mm_min)); + motion.blocking_move(deploy_1.where, MMM_TO_MMS(deploy_1.fr_mm_min)); #endif #ifdef MAG_MOUNTED_DEPLOY_2 constexpr mag_probe_move_t deploy_2 = MAG_MOUNTED_DEPLOY_2; - do_blocking_move_to(deploy_2.where, MMM_TO_MMS(deploy_2.fr_mm_min)); + motion.blocking_move(deploy_2.where, MMM_TO_MMS(deploy_2.fr_mm_min)); #endif #ifdef MAG_MOUNTED_DEPLOY_3 constexpr mag_probe_move_t deploy_3 = MAG_MOUNTED_DEPLOY_3; - do_blocking_move_to(deploy_3.where, MMM_TO_MMS(deploy_3.fr_mm_min)); + motion.blocking_move(deploy_3.where, MMM_TO_MMS(deploy_3.fr_mm_min)); #endif #ifdef MAG_MOUNTED_DEPLOY_4 constexpr mag_probe_move_t deploy_4 = MAG_MOUNTED_DEPLOY_4; - do_blocking_move_to(deploy_4.where, MMM_TO_MMS(deploy_4.fr_mm_min)); + motion.blocking_move(deploy_4.where, MMM_TO_MMS(deploy_4.fr_mm_min)); #endif #ifdef MAG_MOUNTED_DEPLOY_5 constexpr mag_probe_move_t deploy_5 = MAG_MOUNTED_DEPLOY_5; - do_blocking_move_to(deploy_5.where, MMM_TO_MMS(deploy_5.fr_mm_min)); + motion.blocking_move(deploy_5.where, MMM_TO_MMS(deploy_5.fr_mm_min)); #endif #if HAS_MAG_MOUNTED_SERVO_PROBE servo[MAG_MOUNTED_PROBE_SERVO_NR].move(servo_angles[MAG_MOUNTED_PROBE_SERVO_NR][1]); @@ -307,30 +307,30 @@ xyz_pos_t Probe::offset; // Initialized by settings.load inline void run_stow_moves() { #ifdef MAG_MOUNTED_PRE_STOW constexpr mag_probe_move_t pre_stow = MAG_MOUNTED_PRE_STOW; - do_blocking_move_to(pre_stow.where, MMM_TO_MMS(pre_stow.fr_mm_min)); + motion.blocking_move(pre_stow.where, MMM_TO_MMS(pre_stow.fr_mm_min)); #endif #if HAS_MAG_MOUNTED_SERVO_PROBE servo[MAG_MOUNTED_PROBE_SERVO_NR].move(servo_angles[MAG_MOUNTED_PROBE_SERVO_NR][0]); #endif #ifdef MAG_MOUNTED_STOW_1 constexpr mag_probe_move_t stow_1 = MAG_MOUNTED_STOW_1; - do_blocking_move_to(stow_1.where, MMM_TO_MMS(stow_1.fr_mm_min)); + motion.blocking_move(stow_1.where, MMM_TO_MMS(stow_1.fr_mm_min)); #endif #ifdef MAG_MOUNTED_STOW_2 constexpr mag_probe_move_t stow_2 = MAG_MOUNTED_STOW_2; - do_blocking_move_to(stow_2.where, MMM_TO_MMS(stow_2.fr_mm_min)); + motion.blocking_move(stow_2.where, MMM_TO_MMS(stow_2.fr_mm_min)); #endif #ifdef MAG_MOUNTED_STOW_3 constexpr mag_probe_move_t stow_3 = MAG_MOUNTED_STOW_3; - do_blocking_move_to(stow_3.where, MMM_TO_MMS(stow_3.fr_mm_min)); + motion.blocking_move(stow_3.where, MMM_TO_MMS(stow_3.fr_mm_min)); #endif #ifdef MAG_MOUNTED_STOW_4 constexpr mag_probe_move_t stow_4 = MAG_MOUNTED_STOW_4; - do_blocking_move_to(stow_4.where, MMM_TO_MMS(stow_4.fr_mm_min)); + motion.blocking_move(stow_4.where, MMM_TO_MMS(stow_4.fr_mm_min)); #endif #ifdef MAG_MOUNTED_STOW_5 constexpr mag_probe_move_t stow_5 = MAG_MOUNTED_STOW_5; - do_blocking_move_to(stow_5.where, MMM_TO_MMS(stow_5.fr_mm_min)); + motion.blocking_move(stow_5.where, MMM_TO_MMS(stow_5.fr_mm_min)); #endif #if HAS_MAG_MOUNTED_SERVO_PROBE servo[MAG_MOUNTED_PROBE_SERVO_NR].move(servo_angles[MAG_MOUNTED_PROBE_SERVO_NR][1]); @@ -356,14 +356,14 @@ xyz_pos_t Probe::offset; // Initialized by settings.load #if ENABLED(PROBING_STEPPERS_OFF) static main_axes_bits_t old_trusted; if (dopause) { - old_trusted = axes_trusted; + old_trusted = motion.axes_trusted; stepper.disable_axis(X_AXIS); stepper.disable_axis(Y_AXIS); } else { if (TEST(old_trusted, X_AXIS)) stepper.enable_axis(X_AXIS); if (TEST(old_trusted, Y_AXIS)) stepper.enable_axis(Y_AXIS); - axes_trusted = old_trusted; + motion.axes_trusted = old_trusted; } #endif if (dopause) safe_delay(_MAX(DELAY_BEFORE_PROBING, 25)); @@ -450,7 +450,7 @@ FORCE_INLINE void probe_specific_action(const bool deploy) { #elif ENABLED(RACK_AND_PINION_PROBE) - do_blocking_move_to_x(deploy ? Z_PROBE_DEPLOY_X : Z_PROBE_RETRACT_X); + motion.blocking_move_x(deploy ? Z_PROBE_DEPLOY_X : Z_PROBE_RETRACT_X); #elif DISABLED(PAUSE_BEFORE_DEPLOY_STOW) @@ -536,7 +536,7 @@ void Probe::probe_error_stop() { */ bool Probe::set_deployed(const bool deploy, const bool no_return/*=false*/) { if (DEBUGGING(LEVELING)) { - DEBUG_POS("Probe::set_deployed", current_position); + DEBUG_POS("Probe::set_deployed", motion.position); DEBUG_ECHOLNPGM("deploy=", deploy, " no_return=", no_return); } @@ -552,19 +552,19 @@ bool Probe::set_deployed(const bool deploy, const bool no_return/*=false*/) { #endif if (z_raise_wanted) { - const float zdest = DIFF_TERN(HAS_HOTEND_OFFSET, Z_CLEARANCE_DEPLOY_PROBE, hotend_offset[active_extruder].z); + const float zdest = DIFF_TERN(HAS_HOTEND_OFFSET, Z_CLEARANCE_DEPLOY_PROBE, hotend_offset[motion.extruder].z); if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("Raise Z to ", zdest); - do_z_clearance(zdest); + motion.do_z_clearance(zdest); } #if ANY(Z_PROBE_SLED, Z_PROBE_ALLEN_KEY) - if (homing_needed_error(TERN_(Z_PROBE_SLED, _BV(X_AXIS)))) { + if (motion.homing_needed_error(TERN_(Z_PROBE_SLED, _BV(X_AXIS)))) { probe_error_stop(); return true; } #endif - const xy_pos_t old_xy = current_position; // Remember location before probe deployment + const xy_pos_t old_xy = motion.position; // Remember location before probe deployment #if ENABLED(PROBE_TRIGGERED_WHEN_STOWED_TEST) @@ -594,7 +594,7 @@ bool Probe::set_deployed(const bool deploy, const bool no_return/*=false*/) { // TODO: Consider skipping this for things like M401, G34, etc. TERN_(PREHEAT_BEFORE_PROBING, if (deploy) preheat_for_probing(PROBING_NOZZLE_TEMP, PROBING_BED_TEMP)); - if (!no_return) do_blocking_move_to(old_xy); // Return to the original location unless handled externally + if (!no_return) motion.blocking_move(old_xy); // Return to the original location unless handled externally endstops.enable_z_probe(deploy); @@ -610,7 +610,7 @@ bool Probe::set_deployed(const bool deploy, const bool no_return/*=false*/) { * @return true to indicate an error * * @details Used by run_z_probe to get each bed Z height measurement. - * Sets current_position.z to the height where the probe triggered + * Sets motion.position.z to the height where the probe triggered * (according to the Z stepper count). The float Z is propagated * back to the planner.position to preempt any rounding error. * @@ -624,7 +624,7 @@ bool Probe::probe_down_to_z(const float z, const feedRate_t fr_mm_s) { #endif #if ALL(HAS_TEMP_HOTEND, WAIT_FOR_HOTEND) - thermalManager.wait_for_hotend_heating(active_extruder); + thermalManager.wait_for_hotend_heating(motion.extruder); #endif #if ENABLED(BLTOUCH) @@ -665,7 +665,7 @@ bool Probe::probe_down_to_z(const float z, const feedRate_t fr_mm_s) { TERN_(HAS_QUIET_PROBING, set_devices_paused_for_probing(true)); // Move down until the probe is triggered - do_blocking_move_to_z(z, fr_mm_s); + motion.blocking_move_z(z, fr_mm_s); // Check to see if the probe was triggered const bool probe_triggered = ( @@ -718,10 +718,10 @@ bool Probe::probe_down_to_z(const float z, const feedRate_t fr_mm_s) { endstops.hit_on_purpose(); // Get Z where the steppers were interrupted - set_current_from_steppers_for_axis(Z_AXIS); + motion.set_current_from_steppers_for_axis(Z_AXIS); // Tell the planner where we actually are - sync_plan_position(); + motion.sync_plan_position(); return !probe_triggered; } @@ -767,7 +767,7 @@ bool Probe::probe_down_to_z(const float z, const feedRate_t fr_mm_s) { * @brief Probe at the current XY (possibly more than once) to find the bed Z. * * @details Used by probe_at_point to get the bed Z height at the current XY. - * Leaves current_position.z at the height where the probe triggered. + * Leaves motion.position.z at the height where the probe triggered. * * @param sanity_check Flag to compare the probe result with the expected result * based on the probe Z offset. If the result is too far away @@ -780,7 +780,7 @@ bool Probe::probe_down_to_z(const float z, const feedRate_t fr_mm_s) { float Probe::run_z_probe(const bool sanity_check/*=true*/, const float z_min_point/*=Z_PROBE_LOW_POINT*/, const float z_clearance/*=Z_TWEEN_SAFE_CLEARANCE*/) { DEBUG_SECTION(log_probe, "Probe::run_z_probe", DEBUGGING(LEVELING)); - const float zoffs = SUM_TERN(HAS_HOTEND_OFFSET, -offset.z, hotend_offset[active_extruder].z); + const float zoffs = SUM_TERN(HAS_HOTEND_OFFSET, -offset.z, hotend_offset[motion.extruder].z); auto try_to_probe = [&](PGM_P const plbl, const float z_probe_low_point, const feedRate_t fr_mm_s, const bool scheck) -> bool { constexpr float error_tolerance = Z_PROBE_ERROR_TOLERANCE; @@ -794,7 +794,7 @@ float Probe::run_z_probe(const bool sanity_check/*=true*/, const float z_min_poi // Do a first probe at the fast speed const bool probe_fail = probe_down_to_z(z_probe_low_point, fr_mm_s), // No probe trigger? - early_fail = (scheck && current_position.z > zoffs + error_tolerance); // Probe triggered too high? + early_fail = (scheck && motion.position.z > zoffs + error_tolerance); // Probe triggered too high? #if ENABLED(DEBUG_LEVELING_FEATURE) if (DEBUGGING(LEVELING) && (probe_fail || early_fail)) { DEBUG_ECHOPGM(" Probe fail! - "); @@ -809,7 +809,7 @@ float Probe::run_z_probe(const bool sanity_check/*=true*/, const float z_min_poi // Stop the probe before it goes too low to prevent damage. // For known Z probe below the expected trigger point, otherwise -10mm lower. - const float z_probe_low_point = zoffs + z_min_point -float((!axis_is_trusted(Z_AXIS)) * 10); + const float z_probe_low_point = zoffs + z_min_point -float((!motion.axis_is_trusted(Z_AXIS)) * 10); if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("Probe Low Point: ", z_probe_low_point); // Double-probing does a fast probe followed by a slow probe @@ -821,21 +821,21 @@ float Probe::run_z_probe(const bool sanity_check/*=true*/, const float z_min_poi // Do a first probe at the fast speed if (try_to_probe(PSTR("FAST"), z_probe_low_point, z_probe_fast_mm_s, sanity_check)) return NAN; - const float z1 = DIFF_TERN(HAS_DELTA_SENSORLESS_PROBING, current_position.z, largest_sensorless_adj); + const float z1 = DIFF_TERN(HAS_DELTA_SENSORLESS_PROBING, motion.position.z, largest_sensorless_adj); if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("1st Probe Z:", z1); // Raise to give the probe clearance - do_z_clearance(z1 + (Z_CLEARANCE_MULTI_PROBE), false); + motion.do_z_clearance(z1 + (Z_CLEARANCE_MULTI_PROBE), false); #elif Z_PROBE_FEEDRATE_FAST != Z_PROBE_FEEDRATE_SLOW // If the nozzle is well over the travel height then // move down quickly before doing the slow probe const float z = (Z_CLEARANCE_DEPLOY_PROBE) + 5.0f + _MAX(zoffs, 0.0f); - if (current_position.z > z) { + if (motion.position.z > z) { // Probe down fast. If the probe never triggered, raise for probe clearance if (!probe_down_to_z(z, z_probe_fast_mm_s)) - do_z_clearance(z_clearance); + motion.do_z_clearance(z_clearance); } #endif @@ -863,7 +863,7 @@ float Probe::run_z_probe(const bool sanity_check/*=true*/, const float z_min_poi TERN_(MEASURE_BACKLASH_WHEN_PROBING, backlash.measure_with_probe()); - const float z = DIFF_TERN(HAS_DELTA_SENSORLESS_PROBING, current_position.z, largest_sensorless_adj); + const float z = DIFF_TERN(HAS_DELTA_SENSORLESS_PROBING, motion.position.z, largest_sensorless_adj); #if EXTRA_PROBING > 0 // Insert Z measurement into probes[]. Keep it sorted ascending. @@ -886,7 +886,7 @@ float Probe::run_z_probe(const bool sanity_check/*=true*/, const float z_min_poi #if EXTRA_PROBING > 0 < TOTAL_PROBING - 1 #endif - ) do_z_clearance(z + (Z_CLEARANCE_MULTI_PROBE), false); + ) motion.do_z_clearance(z + (Z_CLEARANCE_MULTI_PROBE), false); #endif } @@ -914,7 +914,7 @@ float Probe::run_z_probe(const bool sanity_check/*=true*/, const float z_min_poi #elif TOTAL_PROBING == 2 - const float z2 = DIFF_TERN(HAS_DELTA_SENSORLESS_PROBING, current_position.z, largest_sensorless_adj); + const float z2 = DIFF_TERN(HAS_DELTA_SENSORLESS_PROBING, motion.position.z, largest_sensorless_adj); if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("2nd Probe Z:", z2, " Discrepancy:", z1 - z2); @@ -924,11 +924,11 @@ float Probe::run_z_probe(const bool sanity_check/*=true*/, const float z_min_poi #else // Return the single probe result - const float measured_z = current_position.z; + const float measured_z = motion.position.z; #endif - return DIFF_TERN(HAS_HOTEND_OFFSET, measured_z, hotend_offset[active_extruder].z); + return DIFF_TERN(HAS_HOTEND_OFFSET, measured_z, hotend_offset[motion.extruder].z); } #if DO_TOOLCHANGE_FOR_PROBING @@ -945,9 +945,9 @@ float Probe::run_z_probe(const bool sanity_check/*=true*/, const float z_min_poi static bool old_state = false; if (probing == old_state) return; old_state = probing; - if (probing) old_tool = active_extruder; + if (probing) old_tool = motion.extruder; const uint8_t tool = probing ? PROBING_TOOL : old_tool; - if (tool != active_extruder) + if (tool != motion.extruder) tool_change(tool, ENABLED(PROBE_TOOLCHANGE_NO_MOVE)); } @@ -982,22 +982,22 @@ float Probe::probe_at_point( if (DEBUGGING(LEVELING)) { DEBUG_ECHOLNPGM( - "...(", LOGICAL_X_POSITION(rx), ", ", LOGICAL_Y_POSITION(ry), + "...(", motion.logical_x(rx), ", ", motion.logical_y(ry), ", ", raise_after == PROBE_PT_RAISE ? "raise" : raise_after == PROBE_PT_LAST_STOW ? "stow (last)" : raise_after == PROBE_PT_STOW ? "stow" : "none", ", ", verbose_level, ", ", probe_relative ? "probe" : "nozzle", "_relative)" ); - DEBUG_POS("", current_position); + DEBUG_POS("", motion.position); } // Use a safe Z height for the XY move - const float safe_z = _MAX(current_position.z, z_clearance); + const float safe_z = _MAX(motion.position.z, z_clearance); - // On delta keep Z below clip height or do_blocking_move_to will abort + // On delta keep Z below clip height or motion.blocking_move will abort xyz_pos_t npos = NUM_AXIS_ARRAY( rx, ry, TERN(DELTA, _MIN(delta_clip_start_height, safe_z), safe_z), - current_position.i, current_position.j, current_position.k, - current_position.u, current_position.v, current_position.w + motion.position.i, motion.position.j, motion.position.k, + motion.position.u, motion.position.v, motion.position.w ); if (!can_reach(npos, probe_relative)) { if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("Not Reachable"); @@ -1007,12 +1007,12 @@ float Probe::probe_at_point( if (DEBUGGING(LEVELING)) DEBUG_ECHOPGM("Move to probe"); if (probe_relative) { // Get the nozzle position, adjust for active hotend if not 0 if (DEBUGGING(LEVELING)) DEBUG_ECHOPGM("-relative"); - npos -= DIFF_TERN(HAS_HOTEND_OFFSET, offset_xy, xy_pos_t(hotend_offset[active_extruder])); + npos -= DIFF_TERN(HAS_HOTEND_OFFSET, offset_xy, xy_pos_t(hotend_offset[motion.extruder])); } if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM(" point"); // Move the probe to the starting XYZ - do_blocking_move_to(npos, feedRate_t(XY_PROBE_FEEDRATE_MM_S)); + motion.blocking_move(npos, feedRate_t(XY_PROBE_FEEDRATE_MM_S)); // Change Z motor current to homing current TERN_(PROBING_USE_CURRENT_HOME, set_homing_current(Z_AXIS)); @@ -1023,7 +1023,7 @@ float Probe::probe_at_point( safe_delay(4); - measured_z = current_position.z - bdl.read(); // Difference between Z-home-relative Z and sensor reading + measured_z = motion.position.z - bdl.read(); // Difference between Z-home-relative Z and sensor reading #else // !BD_SENSOR @@ -1043,9 +1043,9 @@ float Probe::probe_at_point( default: break; case PROBE_PT_RAISE: if (raise_after_is_rel) - do_z_clearance_by(z_clearance); + motion.do_z_clearance_by(z_clearance); else - do_z_clearance(z_clearance); + motion.do_z_clearance(z_clearance); break; case PROBE_PT_STOW: case PROBE_PT_LAST_STOW: if (stow()) measured_z = NAN; // Error on stow? @@ -1069,7 +1069,7 @@ float Probe::probe_at_point( TERN_(HAS_PTC, ptc.apply_compensation(measured_z)); TERN_(X_AXIS_TWIST_COMPENSATION, measured_z += xatc.compensation(npos + offset_xy)); if (verbose_level > 2 || DEBUGGING(LEVELING)) - SERIAL_ECHOLNPGM("Bed X: ", LOGICAL_X_POSITION(rx), " Y: ", LOGICAL_Y_POSITION(ry), " Z: ", measured_z); + SERIAL_ECHOLNPGM("Bed X: ", motion.logical_x(rx), " y: ", motion.logical_y(ry), " Z: ", measured_z); } #endif // !BD_SENSOR diff --git a/Marlin/src/module/probe.h b/Marlin/src/module/probe.h index d0f0ada34c..521b028592 100644 --- a/Marlin/src/module/probe.h +++ b/Marlin/src/module/probe.h @@ -111,18 +111,18 @@ public: // Note: This won't work on SCARA since the probe offset rotates with the arm. static bool can_reach(const float rx, const float ry, const bool probe_relative=true) { if (probe_relative) { - return position_is_reachable(rx - offset_xy.x, ry - offset_xy.y) // The nozzle can go where it needs to go? - && position_is_reachable(rx, ry, PROBING_MARGIN); // Can the probe also go near there? + return motion.can_reach(rx - offset_xy.x, ry - offset_xy.y) // The nozzle can go where it needs to go? + && motion.can_reach(rx, ry, PROBING_MARGIN); // Can the probe also go near there? } else { - return position_is_reachable(rx, ry) - && position_is_reachable(rx + offset_xy.x, ry + offset_xy.y, PROBING_MARGIN); + return motion.can_reach(rx, ry) + && motion.can_reach(rx + offset_xy.x, ry + offset_xy.y, PROBING_MARGIN); } } #else static bool can_reach(const float rx, const float ry, const bool=true) { - return position_is_reachable(rx, ry) - && position_is_reachable(rx, ry, PROBING_MARGIN); + return motion.can_reach(rx, ry) + && motion.can_reach(rx, ry, PROBING_MARGIN); } #endif @@ -163,14 +163,14 @@ public: */ static bool can_reach(const float rx, const float ry, const bool probe_relative=true) { if (probe_relative) { - return position_is_reachable(rx - offset_xy.x, ry - offset_xy.y) + return motion.can_reach(rx - offset_xy.x, ry - offset_xy.y) && COORDINATE_OKAY(rx, min_x() - fslop, max_x() + fslop) && COORDINATE_OKAY(ry, min_y() - fslop, max_y() + fslop) && obstacle_check(rx, ry) && obstacle_check(rx - offset_xy.x, ry - offset_xy.y); } else { - return position_is_reachable(rx, ry) + return motion.can_reach(rx, ry) && COORDINATE_OKAY(rx + offset_xy.x, min_x() - fslop, max_x() + fslop) && COORDINATE_OKAY(ry + offset_xy.y, min_y() - fslop, max_y() + fslop) && obstacle_check(rx, ry) @@ -211,7 +211,7 @@ public: static bool set_deployed(const bool, const bool=false) { return false; } - static bool can_reach(const float rx, const float ry, const bool=true) { return position_is_reachable(XY_LIST(rx, ry)); } + static bool can_reach(const float rx, const float ry, const bool=true) { return motion.can_reach(XY_LIST(rx, ry)); } #endif // !HAS_BED_PROBE @@ -220,7 +220,7 @@ public: static void move_z_after_probing() { DEBUG_SECTION(mzah, "move_z_after_probing", DEBUGGING(LEVELING)); #ifdef Z_AFTER_PROBING - do_z_clearance(Z_AFTER_PROBING, true, true); // Move down still permitted + motion.do_z_clearance(Z_AFTER_PROBING, true, true); // Move down still permitted #endif } @@ -288,10 +288,10 @@ public: ); } - static float min_x() { return _min_x() TERN_(NOZZLE_AS_PROBE, TERN_(HAS_HOME_OFFSET, - home_offset.x)); } - static float max_x() { return _max_x() TERN_(NOZZLE_AS_PROBE, TERN_(HAS_HOME_OFFSET, - home_offset.x)); } - static float min_y() { return _min_y() TERN_(NOZZLE_AS_PROBE, TERN_(HAS_HOME_OFFSET, - home_offset.y)); } - static float max_y() { return _max_y() TERN_(NOZZLE_AS_PROBE, TERN_(HAS_HOME_OFFSET, - home_offset.y)); } + static float min_x() { return _min_x() TERN_(NOZZLE_AS_PROBE, TERN_(HAS_HOME_OFFSET, - motion.home_offset.x)); } + static float max_x() { return _max_x() TERN_(NOZZLE_AS_PROBE, TERN_(HAS_HOME_OFFSET, - motion.home_offset.x)); } + static float min_y() { return _min_y() TERN_(NOZZLE_AS_PROBE, TERN_(HAS_HOME_OFFSET, - motion.home_offset.y)); } + static float max_y() { return _max_y() TERN_(NOZZLE_AS_PROBE, TERN_(HAS_HOME_OFFSET, - motion.home_offset.y)); } // constexpr helpers used in build-time static_asserts, relying on default probe offsets. class build_time { diff --git a/Marlin/src/module/scara.cpp b/Marlin/src/module/scara.cpp index 7d1f9ce2ca..abe21b87b4 100644 --- a/Marlin/src/module/scara.cpp +++ b/Marlin/src/module/scara.cpp @@ -53,8 +53,8 @@ float segments_per_second = DEFAULT_SEGMENTS_PER_SECOND; b_sin = sin(RADIANS(SUM_TERN(MP_SCARA, b, a))) * L2, b_cos = cos(RADIANS(SUM_TERN(MP_SCARA, b, a))) * L2; - cartes.x = a_cos + b_cos + scara_offset.x; // theta - cartes.y = a_sin + b_sin + scara_offset.y; // phi + motion.cartes.x = a_cos + b_cos + scara_offset.x; // theta + motion.cartes.y = a_sin + b_sin + scara_offset.y; // phi /* DEBUG_ECHOLNPGM( @@ -65,7 +65,7 @@ float segments_per_second = DEFAULT_SEGMENTS_PER_SECOND; " b_sin=", b_sin, " b_cos=", b_cos ); - DEBUG_ECHOLNPGM(" cartes (X,Y) = "(cartes.x, ", ", cartes.y, ")"); + DEBUG_ECHOLNPGM(" cartes (X,Y) = "(motion.cartes.x, ", ", motion.cartes.y, ")"); //*/ } @@ -75,23 +75,23 @@ float segments_per_second = DEFAULT_SEGMENTS_PER_SECOND; void scara_set_axis_is_at_home(const AxisEnum axis) { if (axis == Z_AXIS) - current_position.z = Z_HOME_POS; + motion.position.z = Z_HOME_POS; else { // MORGAN_SCARA uses a Cartesian XY home position xyz_pos_t homeposition = { X_HOME_POS, Y_HOME_POS, Z_HOME_POS }; //DEBUG_ECHOLNPGM_P(PSTR("homeposition X"), homeposition.x, SP_Y_LBL, homeposition.y); - delta = homeposition; - forward_kinematics(delta.a, delta.b); - current_position[axis] = cartes[axis]; + motion.delta = homeposition; + forward_kinematics(motion.delta.a, motion.delta.b); + motion.position[axis] = motion.cartes[axis]; - //DEBUG_ECHOLNPGM_P(PSTR("Cartesian X"), current_position.x, SP_Y_LBL, current_position.y); - update_software_endstops(axis); + //DEBUG_ECHOLNPGM_P(PSTR("Cartesian X"), motion.position.x, SP_Y_LBL, motion.position.y); + motion.update_software_endstops(axis); } } /** - * Morgan SCARA Inverse Kinematics. Results are stored in 'delta'. + * Morgan SCARA Inverse Kinematics. Results are stored in 'motion.delta'. * * See https://reprap.org/forum/read.php?185,283327 * @@ -126,11 +126,11 @@ float segments_per_second = DEFAULT_SEGMENTS_PER_SECOND; // Angle of Arm2 PSI = ATAN2(S2, C2); - delta.set(DEGREES(THETA), DEGREES(SUM_TERN(MORGAN_SCARA, PSI, THETA)), raw.z); + motion.delta.set(DEGREES(THETA), DEGREES(SUM_TERN(MORGAN_SCARA, PSI, THETA)), raw.z); /* DEBUG_POS("SCARA IK", raw); - DEBUG_POS("SCARA IK", delta); + DEBUG_POS("SCARA IK", motion.delta); DEBUG_ECHOLNPGM(" SCARA (x,y) ", sx, ",", sy, " C2=", C2, " S2=", S2, " Theta=", THETA, " Psi=", PSI); //*/ } @@ -139,7 +139,7 @@ float segments_per_second = DEFAULT_SEGMENTS_PER_SECOND; void scara_set_axis_is_at_home(const AxisEnum axis) { if (axis == Z_AXIS) - current_position.z = Z_HOME_POS; + motion.position.z = Z_HOME_POS; else { // MP_SCARA uses arm angles for AB home position #ifndef SCARA_OFFSET_THETA1 @@ -152,11 +152,11 @@ float segments_per_second = DEFAULT_SEGMENTS_PER_SECOND; //DEBUG_ECHOLNPGM("homeposition A:", homeposition.a, " B:", homeposition.b); inverse_kinematics(homeposition); - forward_kinematics(delta.a, delta.b); - current_position[axis] = cartes[axis]; + forward_kinematics(motion.delta.a, motion.delta.b); + motion.position[axis] = motion.cartes[axis]; - //DEBUG_ECHOLNPGM_P(PSTR("Cartesian X"), current_position.x, SP_Y_LBL, current_position.y); - update_software_endstops(axis); + //DEBUG_ECHOLNPGM_P(PSTR("Cartesian X"), motion.position.x, SP_Y_LBL, motion.position.y); + motion.update_software_endstops(axis); } } @@ -166,11 +166,11 @@ float segments_per_second = DEFAULT_SEGMENTS_PER_SECOND; THETA1 = THETA3 + ACOS((sq(c) + sq(L1) - sq(L2)) / (2.0f * c * L1)), THETA2 = THETA3 - ACOS((sq(c) + sq(L2) - sq(L1)) / (2.0f * c * L2)); - delta.set(DEGREES(THETA1), DEGREES(THETA2), raw.z); + motion.delta.set(DEGREES(THETA1), DEGREES(THETA2), raw.z); /* DEBUG_POS("SCARA IK", raw); - DEBUG_POS("SCARA IK", delta); + DEBUG_POS("SCARA IK", motion.delta); SERIAL_ECHOLNPGM(" SCARA (x,y) ", x, ",", y," Theta1=", THETA1, " Theta2=", THETA2); //*/ } @@ -238,32 +238,32 @@ float segments_per_second = DEFAULT_SEGMENTS_PER_SECOND; /** * Set an axis' current position to its home position (after homing). * - * TPARA must wait for YZ homing before setting current_position.Y/Z to home. + * TPARA must wait for YZ homing before setting motion.position.Y/Z to home. * Neither Y nor Z is home until both are at home. */ void scara_set_axis_is_at_home(const AxisEnum axis) { // Home position should be arm end position -+ offsets (+ tool offset - workspace offset), measured at home robot position - xyz_pos_t homeposition = { X_HOME_POS , Y_HOME_POS , Z_HOME_POS }; + xyz_pos_t homeposition = { X_HOME_POS, Y_HOME_POS, Z_HOME_POS }; //SERIAL_ECHOLNPGM("TPARA Set axis is at home: ", C(iaxis_codes[axis])); //SERIAL_XYZ("Home: ", homeposition); - //SERIAL_XYZ("Pos before IK: ", current_position); - //SERIAL_ECHOLNPGM("Angles Before: Theta: ", delta.a, " Phi: ", delta.b, " Psi: ", delta.c); + //SERIAL_XYZ("Pos before IK: ", motion.position); + //SERIAL_ECHOLNPGM("Angles Before: Theta: ", motion.delta.a, " Phi: ", motion.delta.b, " Psi: ", motion.delta.c); inverse_kinematics(homeposition); - //SERIAL_ECHOLNPGM("Angles After IK: Theta: ", delta.a, " Phi: ", delta.b, " Psi: ", delta.c); + //SERIAL_ECHOLNPGM("Angles After IK: Theta: ", motion.delta.a, " Phi: ", motion.delta.b, " Psi: ", motion.delta.c); - forward_kinematics(delta.a, delta.b, delta.c); - current_position[axis] = cartes[axis]; + forward_kinematics(motion.delta.a, motion.delta.b, motion.delta.c); + motion.position[axis] = motion.cartes[axis]; - //SERIAL_XYZ("'current' after FK: ", current_position); - //SERIAL_XYZ("'cartes' after FK: ", cartes); + //SERIAL_XYZ("'position' after FK: ", motion.position); + //SERIAL_XYZ("'cartes' after FK: ", motion.cartes); - update_software_endstops(axis); + motion.update_software_endstops(axis); - //SERIAL_ECHOLNPGM("Final Angles: Theta: ", delta.a, " Phi: ", delta.b, " Psi: ", delta.c); - //SERIAL_XYZ("Final Pos: ", current_position); + //SERIAL_ECHOLNPGM("Final Angles: Theta: ", motion.delta.a, " Phi: ", motion.delta.b, " Psi: ", motion.delta.c); + //SERIAL_XYZ("Final Pos: ", motion.position); //SERIAL_XYZ("Robot Offsets Shoulder:", robot_shoulder_offset); //SERIAL_XYZ("Robot Offsets Tool:", tool_offset); //SERIAL_XYZ("Robot Offsets Workspace:", robot_workspace_offset); @@ -279,27 +279,28 @@ float segments_per_second = DEFAULT_SEGMENTS_PER_SECOND; rho2 = L1_2 + L2_2 - 2.0f * L1 * L2 * cos(RADIANS(w)); const xyz_pos_t calculated_fk = xyz_pos_t({ x, y, SQRT(rho2 - sq(x) - sq(y)) }) ; - cartes = calculated_fk + robot_shoulder_offset + tool_offset - robot_workspace_offset; + motion.cartes = calculated_fk + robot_shoulder_offset + tool_offset - robot_workspace_offset; //SERIAL_ECHOPGM("TPARA FK Theta:", a, " Phi: ", b, " Psi: ", c); //SERIAL_ECHOPGM(" Calculated X':", calculated_fk.x, " Y':", calculated_fk.y, " Z':", calculated_fk.z); - //SERIAL_XYZ(" Workspace", cartes); + //SERIAL_XYZ(" Workspace", motion.cartes); + //SERIAL_EOL(); } // Home YZ together, then X (or all at once). Based on quick_home_xy & home_delta void home_TPARA() { // First Init the current position of all carriages to 0,0,0 - current_position.reset(); - destination.reset(); - sync_plan_position(); + motion.position.reset(); + motion.destination.reset(); + motion.sync_plan_position(); - //SERIAL_ECHOLNPGM("Reset and sync position to the assumed start position of the robot" ); + //SERIAL_ECHOLNPGM("Reset and sync position to the assumed start position of the robot"); // Set the assumed start position of the robot for homing, so it home ZY axis at same time preserving the B and C motor angle constexpr xyz_pos_t init_w_offset = apply_T_W_offset(xyz_pos_t({ L2, 0, 0 })); - current_position.set(init_w_offset.x, init_w_offset.y, init_w_offset.z); - destination.set(init_w_offset.x, init_w_offset.y, init_w_offset.z); - sync_plan_position(); + motion.position.set(init_w_offset.x, init_w_offset.y, init_w_offset.z); + motion.destination.set(init_w_offset.x, init_w_offset.y, init_w_offset.z); + motion.sync_plan_position(); // Disable stealthChop if used. Enable diag1 pin on driver. #if ENABLED(SENSORLESS_HOMING) @@ -320,9 +321,9 @@ float segments_per_second = DEFAULT_SEGMENTS_PER_SECOND; // Move to home, should move Z, Y, then X. Move X to near 0 (to avoid div by zero // and sign/angle stability around 0 for trigonometric functions), Y to 0 and Z to max_length constexpr xyz_pos_t homing_pos_dir = apply_T_W_offset(xyz_pos_t({ 1, 0, Z_MAX_LENGTH })); - current_position.set(homing_pos_dir.x, homing_pos_dir.y, homing_pos_dir.z); + motion.position.set(homing_pos_dir.x, homing_pos_dir.y, homing_pos_dir.z); - line_to_current_position(homing_feedrate(Z_AXIS)); + motion.goto_current_position(motion.homing_feedrate(Z_AXIS)); planner.synchronize(); // Restore the homing current for all motors @@ -339,21 +340,21 @@ float segments_per_second = DEFAULT_SEGMENTS_PER_SECOND; // At least one motor has reached its endstop. // Now re-home each motor separately. - TERN_(HOME_Z_FIRST, homeaxis(C_AXIS)); - homeaxis(TERN(HOME_Y_BEFORE_X, B_AXIS, A_AXIS)); - homeaxis(TERN(HOME_Y_BEFORE_X, A_AXIS, B_AXIS)); - IF_DISABLED(HOME_Z_FIRST, homeaxis(C_AXIS)); + TERN_(HOME_Z_FIRST, motion.homeaxis(C_AXIS)); + motion.homeaxis(TERN(HOME_Y_BEFORE_X, B_AXIS, A_AXIS)); + motion.homeaxis(TERN(HOME_Y_BEFORE_X, A_AXIS, B_AXIS)); + IF_DISABLED(HOME_Z_FIRST, motion.homeaxis(C_AXIS)); - //SERIAL_ECHOLNPGM("current_position After Homeaxis: ", current_position.x, ", ", current_position.y, ", ", current_position.z); + //SERIAL_XYZ("Position after homeaxis: ", motion.position); // Set all carriages to their home positions // Do this here all at once for Delta, because // XYZ isn't ABC. Applying this per-tower would // give the impression that they are the same. - LOOP_NUM_AXES(i) set_axis_is_at_home((AxisEnum)i); + LOOP_NUM_AXES(i) motion.set_axis_is_at_home((AxisEnum)i); //SERIAL_ECHOLNPGM("Sync_plan_position after home"); - sync_plan_position(); + motion.sync_plan_position(); } void inverse_kinematics(const xyz_pos_t &raw) { @@ -386,7 +387,7 @@ float segments_per_second = DEFAULT_SEGMENTS_PER_SECOND; // Elbow motor angle measured from horizontal, same reference frame as shoulder angle (r+) PSI = PHI + GAMMA; - delta.set(DEGREES(THETA), DEGREES(PHI), DEGREES(PSI)); + motion.delta.set(DEGREES(THETA), DEGREES(PHI), DEGREES(PSI)); //SERIAL_ECHOLNPGM(" TPARA IK raw(x,y,z) ", raw.x, ",", raw.y, ",", raw.z, " Robot pos(x,y,z) ", tpos.x, ",", tpos.y, ",", tpos.z + robot_shoulder_offset.z, " Rho^2=", RHO_2, " Theta=", DEGREES(THETA), " Phi=", DEGREES(PHI), " Psi=", DEGREES(PSI), " Gamma=", DEGREES(GAMMA)); } diff --git a/Marlin/src/module/settings.cpp b/Marlin/src/module/settings.cpp index 56c93bbcfc..455407105c 100644 --- a/Marlin/src/module/settings.cpp +++ b/Marlin/src/module/settings.cpp @@ -728,7 +728,7 @@ uint16_t MarlinSettings::datasize() { return sizeof(SettingsData); } #endif void MarlinSettings::postprocess() { - xyze_pos_t oldpos = current_position; + xyze_pos_t oldpos = motion.position; // steps per s2 needs to be updated to agree with units per s2 planner.refresh_acceleration_rates(); @@ -747,7 +747,7 @@ void MarlinSettings::postprocess() { #endif // Software endstops depend on home_offset - LOOP_NUM_AXES(i) update_software_endstops((AxisEnum)i); + LOOP_NUM_AXES(i) motion.update_software_endstops((AxisEnum)i); TERN_(ENABLE_LEVELING_FADE_HEIGHT, set_z_fade_height(new_z_fade_height, false)); // false = no report @@ -764,12 +764,12 @@ void MarlinSettings::postprocess() { TERN_(EXTENSIBLE_UI, ExtUI::onPostprocessSettings()); // Refresh mm_per_step with the reciprocal of axis_steps_per_mm - // and init stepper.count[], planner.position[] with current_position + // and init stepper.count[], planner.position[] with motion.position planner.refresh_positioning(); // Various factors can change the current position - if (oldpos != current_position) - report_current_position(); + if (oldpos != motion.position) + motion.report_position(); // Moved as last update due to interference with NeoPixel init TERN_(HAS_LCD_CONTRAST, ui.refresh_contrast()); @@ -942,14 +942,13 @@ void MarlinSettings::postprocess() { #if NUM_AXES { _FIELD_TEST(home_offset); - #if HAS_SCARA_OFFSET - EEPROM_WRITE(scara_home_offset); + EEPROM_WRITE(motion.scara_home_offset); + #elif HAS_HOME_OFFSET + EEPROM_WRITE(motion.home_offset); #else - #if !HAS_HOME_OFFSET - const xyz_pos_t home_offset{0}; - #endif - EEPROM_WRITE(home_offset); + const xyz_pos_t _home_offset{0}; + EEPROM_WRITE(_home_offset); #endif } #endif // NUM_AXES @@ -1388,7 +1387,7 @@ void MarlinSettings::postprocess() { // #if ENABLED(EDITABLE_HOMING_FEEDRATE) _FIELD_TEST(homing_feedrate_mm_m); - EEPROM_WRITE(homing_feedrate_mm_m); + EEPROM_WRITE(motion.homing_feedrate_mm_m); #endif // @@ -2014,14 +2013,13 @@ void MarlinSettings::postprocess() { #if NUM_AXES { _FIELD_TEST(home_offset); - #if HAS_SCARA_OFFSET - EEPROM_READ(scara_home_offset); + EEPROM_READ(motion.scara_home_offset); + #elif HAS_HOME_OFFSET + EEPROM_READ(motion.home_offset); #else - #if !HAS_HOME_OFFSET - xyz_pos_t home_offset; - #endif - EEPROM_READ(home_offset); + const xyz_pos_t _home_offset{0}; + EEPROM_READ(_home_offset); #endif } #endif // NUM_AXES @@ -2483,7 +2481,7 @@ void MarlinSettings::postprocess() { // #if ENABLED(EDITABLE_HOMING_FEEDRATE) _FIELD_TEST(homing_feedrate_mm_m); - EEPROM_READ(homing_feedrate_mm_m); + EEPROM_READ(motion.homing_feedrate_mm_m); #endif // @@ -3367,9 +3365,9 @@ void MarlinSettings::reset() { // Home Offset // #if HAS_SCARA_OFFSET - scara_home_offset.reset(); + motion.scara_home_offset.reset(); #elif HAS_HOME_OFFSET - home_offset.reset(); + motion.home_offset.reset(); #endif // @@ -3600,7 +3598,7 @@ void MarlinSettings::reset() { // // Homing Feedrate // - TERN_(EDITABLE_HOMING_FEEDRATE, homing_feedrate_mm_m = xyz_feedrate_t(HOMING_FEEDRATE_MM_M)); + TERN_(EDITABLE_HOMING_FEEDRATE, motion.homing_feedrate_mm_m = xyz_feedrate_t(HOMING_FEEDRATE_MM_M)); // // TMC Homing Current diff --git a/Marlin/src/module/stepper.cpp b/Marlin/src/module/stepper.cpp index bc049a3492..701d3f09b5 100644 --- a/Marlin/src/module/stepper.cpp +++ b/Marlin/src/module/stepper.cpp @@ -3104,7 +3104,7 @@ void Stepper::isr() { hal_timer_t Stepper::smooth_lin_adv_isr() { int32_t target_adv_steps = 0; if (current_block) { - const uint32_t stepper_ticks = extruder_advance_tau_ticks[E_INDEX_N(active_extruder)] + curr_timer_tick; + const uint32_t stepper_ticks = extruder_advance_tau_ticks[E_INDEX_N(motion.extruder)] + curr_timer_tick; target_adv_steps = MULT_Q(27, smooth_lin_adv_lookahead(stepper_ticks), planner.get_advance_k_q27()); } else { @@ -3119,7 +3119,7 @@ void Stepper::isr() { for (uint8_t i = 0; i < SMOOTH_LIN_ADV_EXP_ORDER; i++) { // Approximate Gaussian smoothing via higher order exponential smoothing - smoothed_vals[i] += MULT_Q(30, la_step_rate - smoothed_vals[i], extruder_advance_alpha_q30[E_INDEX_N(active_extruder)]); + smoothed_vals[i] += MULT_Q(30, la_step_rate - smoothed_vals[i], extruder_advance_alpha_q30[E_INDEX_N(motion.extruder)]); la_step_rate = smoothed_vals[i]; } diff --git a/Marlin/src/module/stepper.h b/Marlin/src/module/stepper.h index 18ab27ab3a..95d5eeb0df 100644 --- a/Marlin/src/module/stepper.h +++ b/Marlin/src/module/stepper.h @@ -409,7 +409,7 @@ class Stepper { #if ENABLED(SMOOTH_LIN_ADVANCE) static float extruder_advance_tau[DISTINCT_E]; // Smoothing time; also the lookahead time of the smoother - static void set_advance_tau(const float tau, const uint8_t e=active_extruder) { + static void set_advance_tau(const float tau, const uint8_t e=motion.extruder) { const uint8_t i = E_INDEX_N(e); extruder_advance_tau[i] = tau; extruder_advance_tau_ticks[i] = tau * STEPPER_TIMER_RATE; @@ -417,7 +417,7 @@ class Stepper { const float alpha_float = 1.0f - expf(-float(SMOOTH_LIN_ADV_INTERVAL) * (SMOOTH_LIN_ADV_EXP_ORDER) / extruder_advance_tau_ticks[i]); extruder_advance_alpha_q30[i] = int32_t(alpha_float * _BV32(30)); } - static float get_advance_tau(const uint8_t e=active_extruder) { + static float get_advance_tau(const uint8_t e=motion.extruder) { return extruder_advance_tau[E_INDEX_N(e)]; } #endif @@ -729,15 +729,15 @@ class Stepper { } static void mark_axis_enabled(const AxisEnum axis E_OPTARG(const uint8_t eindex=0)) { SBI(axis_enabled.bits, INDEX_OF_AXIS(axis, eindex)); - TERN_(HAS_Z_AXIS, if (axis == Z_AXIS) z_min_trusted = true); + TERN_(HAS_Z_AXIS, if (axis == Z_AXIS) motion.z_min_trusted = true); // TODO: DELTA should have "Z" state affect all (ABC) motors and treat "XY" on/off as meaningless } static void mark_axis_disabled(const AxisEnum axis E_OPTARG(const uint8_t eindex=0)) { CBI(axis_enabled.bits, INDEX_OF_AXIS(axis, eindex)); #if HAS_Z_AXIS if (TERN0(Z_CAN_FALL_DOWN, axis == Z_AXIS)) { - z_min_trusted = false; - current_position.z = 0; + motion.z_min_trusted = false; + motion.position.z = 0; } #endif // TODO: DELTA should have "Z" state affect all (ABC) motors and treat "XY" on/off as meaningless diff --git a/Marlin/src/module/stepper/indirection.h b/Marlin/src/module/stepper/indirection.h index f2004c88dd..ea162b4949 100644 --- a/Marlin/src/module/stepper/indirection.h +++ b/Marlin/src/module/stepper/indirection.h @@ -62,7 +62,7 @@ * ENABLE_AXIS_Q() DISABLE_AXIS_Q() * * E-Axis Stepper Control (0..n) - * For these macros the E index indicates a logical extruder (e.g., active_extruder). + * For these macros the E index indicates a logical extruder (e.g., motion.extruder). * * E_STEP_WRITE(E,V) FWD_E_DIR(E) REV_E_DIR(E) * @@ -998,7 +998,7 @@ void reset_stepper_drivers(); // Called by settings.load / settings.reset #if HAS_X_AXIS #define ENABLE_AXIS_X() if (SHOULD_ENABLE(x)) { ENABLE_STEPPER_X(); ENABLE_STEPPER_X2(); AFTER_CHANGE(x, true); } - #define DISABLE_AXIS_X() if (SHOULD_DISABLE(x)) { DISABLE_STEPPER_X(); DISABLE_STEPPER_X2(); AFTER_CHANGE(x, false); set_axis_untrusted(X_AXIS); } + #define DISABLE_AXIS_X() if (SHOULD_DISABLE(x)) { DISABLE_STEPPER_X(); DISABLE_STEPPER_X2(); AFTER_CHANGE(x, false); motion.set_axis_untrusted(X_AXIS); } #else #define ENABLE_AXIS_X() NOOP #define DISABLE_AXIS_X() NOOP @@ -1006,7 +1006,7 @@ void reset_stepper_drivers(); // Called by settings.load / settings.reset #if HAS_Y_AXIS #define ENABLE_AXIS_Y() if (SHOULD_ENABLE(y)) { ENABLE_STEPPER_Y(); ENABLE_STEPPER_Y2(); AFTER_CHANGE(y, true); } - #define DISABLE_AXIS_Y() if (SHOULD_DISABLE(y)) { DISABLE_STEPPER_Y(); DISABLE_STEPPER_Y2(); AFTER_CHANGE(y, false); set_axis_untrusted(Y_AXIS); } + #define DISABLE_AXIS_Y() if (SHOULD_DISABLE(y)) { DISABLE_STEPPER_Y(); DISABLE_STEPPER_Y2(); AFTER_CHANGE(y, false); motion.set_axis_untrusted(Y_AXIS); } #else #define ENABLE_AXIS_Y() NOOP #define DISABLE_AXIS_Y() NOOP @@ -1014,35 +1014,35 @@ void reset_stepper_drivers(); // Called by settings.load / settings.reset #if HAS_Z_AXIS #define ENABLE_AXIS_Z() if (SHOULD_ENABLE(z)) { ENABLE_STEPPER_Z(); ENABLE_STEPPER_Z2(); ENABLE_STEPPER_Z3(); ENABLE_STEPPER_Z4(); AFTER_CHANGE(z, true); } - #define DISABLE_AXIS_Z() if (SHOULD_DISABLE(z)) { DISABLE_STEPPER_Z(); DISABLE_STEPPER_Z2(); DISABLE_STEPPER_Z3(); DISABLE_STEPPER_Z4(); AFTER_CHANGE(z, false); set_axis_untrusted(Z_AXIS); Z_RESET(); TERN_(BD_SENSOR, bdl.config_state = BDS_IDLE); } + #define DISABLE_AXIS_Z() if (SHOULD_DISABLE(z)) { DISABLE_STEPPER_Z(); DISABLE_STEPPER_Z2(); DISABLE_STEPPER_Z3(); DISABLE_STEPPER_Z4(); AFTER_CHANGE(z, false); motion.set_axis_untrusted(Z_AXIS); Z_RESET(); TERN_(BD_SENSOR, bdl.config_state = BDS_IDLE); } #else #define ENABLE_AXIS_Z() NOOP #define DISABLE_AXIS_Z() NOOP #endif #ifdef Z_IDLE_HEIGHT - #define Z_RESET() do{ current_position.z = Z_IDLE_HEIGHT; sync_plan_position(); }while(0) + #define Z_RESET() do{ motion.position.z = Z_IDLE_HEIGHT; motion.sync_plan_position(); }while(0) #else #define Z_RESET() #endif #if HAS_I_AXIS #define ENABLE_AXIS_I() if (SHOULD_ENABLE(i)) { ENABLE_STEPPER_I(); AFTER_CHANGE(i, true); } - #define DISABLE_AXIS_I() if (SHOULD_DISABLE(i)) { DISABLE_STEPPER_I(); AFTER_CHANGE(i, false); set_axis_untrusted(I_AXIS); } + #define DISABLE_AXIS_I() if (SHOULD_DISABLE(i)) { DISABLE_STEPPER_I(); AFTER_CHANGE(i, false); motion.set_axis_untrusted(I_AXIS); } #else #define ENABLE_AXIS_I() NOOP #define DISABLE_AXIS_I() NOOP #endif #if HAS_J_AXIS #define ENABLE_AXIS_J() if (SHOULD_ENABLE(j)) { ENABLE_STEPPER_J(); AFTER_CHANGE(j, true); } - #define DISABLE_AXIS_J() if (SHOULD_DISABLE(j)) { DISABLE_STEPPER_J(); AFTER_CHANGE(j, false); set_axis_untrusted(J_AXIS); } + #define DISABLE_AXIS_J() if (SHOULD_DISABLE(j)) { DISABLE_STEPPER_J(); AFTER_CHANGE(j, false); motion.set_axis_untrusted(J_AXIS); } #else #define ENABLE_AXIS_J() NOOP #define DISABLE_AXIS_J() NOOP #endif #if HAS_K_AXIS #define ENABLE_AXIS_K() if (SHOULD_ENABLE(k)) { ENABLE_STEPPER_K(); AFTER_CHANGE(k, true); } - #define DISABLE_AXIS_K() if (SHOULD_DISABLE(k)) { DISABLE_STEPPER_K(); AFTER_CHANGE(k, false); set_axis_untrusted(K_AXIS); } + #define DISABLE_AXIS_K() if (SHOULD_DISABLE(k)) { DISABLE_STEPPER_K(); AFTER_CHANGE(k, false); motion.set_axis_untrusted(K_AXIS); } #else #define ENABLE_AXIS_K() NOOP #define DISABLE_AXIS_K() NOOP @@ -1050,21 +1050,21 @@ void reset_stepper_drivers(); // Called by settings.load / settings.reset #if HAS_U_AXIS #define ENABLE_AXIS_U() if (SHOULD_ENABLE(u)) { ENABLE_STEPPER_U(); AFTER_CHANGE(u, true); } - #define DISABLE_AXIS_U() if (SHOULD_DISABLE(u)) { DISABLE_STEPPER_U(); AFTER_CHANGE(u, false); set_axis_untrusted(U_AXIS); } + #define DISABLE_AXIS_U() if (SHOULD_DISABLE(u)) { DISABLE_STEPPER_U(); AFTER_CHANGE(u, false); motion.set_axis_untrusted(U_AXIS); } #else #define ENABLE_AXIS_U() NOOP #define DISABLE_AXIS_U() NOOP #endif #if HAS_V_AXIS #define ENABLE_AXIS_V() if (SHOULD_ENABLE(v)) { ENABLE_STEPPER_V(); AFTER_CHANGE(v, true); } - #define DISABLE_AXIS_V() if (SHOULD_DISABLE(v)) { DISABLE_STEPPER_V(); AFTER_CHANGE(v, false); set_axis_untrusted(V_AXIS); } + #define DISABLE_AXIS_V() if (SHOULD_DISABLE(v)) { DISABLE_STEPPER_V(); AFTER_CHANGE(v, false); motion.set_axis_untrusted(V_AXIS); } #else #define ENABLE_AXIS_V() NOOP #define DISABLE_AXIS_V() NOOP #endif #if HAS_W_AXIS #define ENABLE_AXIS_W() if (SHOULD_ENABLE(w)) { ENABLE_STEPPER_W(); AFTER_CHANGE(w, true); } - #define DISABLE_AXIS_W() if (SHOULD_DISABLE(w)) { DISABLE_STEPPER_W(); AFTER_CHANGE(w, false); set_axis_untrusted(W_AXIS); } + #define DISABLE_AXIS_W() if (SHOULD_DISABLE(w)) { DISABLE_STEPPER_W(); AFTER_CHANGE(w, false); motion.set_axis_untrusted(W_AXIS); } #else #define ENABLE_AXIS_W() NOOP #define DISABLE_AXIS_W() NOOP diff --git a/Marlin/src/module/temperature.cpp b/Marlin/src/module/temperature.cpp index a4744c2bad..89b35b6b34 100644 --- a/Marlin/src/module/temperature.cpp +++ b/Marlin/src/module/temperature.cpp @@ -481,7 +481,7 @@ PGMSTR(str_t_heating_failed, STR_T_HEATING_FAILED); NOMORE(speed, 255U); #if ENABLED(SINGLENOZZLE_STANDBY_FAN) - if (fan != active_extruder) { + if (fan != motion.extruder) { if (fan < EXTRUDERS) singlenozzle_fan_speed[fan] = speed; return; } @@ -934,7 +934,7 @@ void Temperature::factory_reset() { // Report heater states every 2 seconds if (ELAPSED(ms, next_temp_ms)) { #if HAS_TEMP_SENSOR - print_heater_states(heater_id < 0 ? active_extruder : (int8_t)heater_id); + print_heater_states(heater_id < 0 ? motion.extruder : (int8_t)heater_id); SERIAL_EOL(); #endif next_temp_ms = ms + 2000UL; @@ -1068,7 +1068,7 @@ void Temperature::factory_reset() { planner.sync_fan_speeds(fan_speed); #endif - do_z_clearance(MPC_TUNING_END_Z, false); + motion.do_z_clearance(MPC_TUNING_END_Z, false); #ifdef EVENT_GCODE_AFTER_MPC_TUNE gcode.process_subcommands_now(F(EVENT_GCODE_AFTER_MPC_TUNE)); @@ -1297,7 +1297,7 @@ void Temperature::factory_reset() { set_fan_speed(TERN(SINGLEFAN, 0, e), 255); planner.sync_fan_speeds(fan_speed); #endif - do_blocking_move_to(xyz_pos_t(MPC_TUNING_POS)); + motion.blocking_move(xyz_pos_t(MPC_TUNING_POS)); // Determine ambient temperature. SERIAL_ECHOLNPGM(STR_MPC_COOLING_TO_AMBIENT); @@ -1569,7 +1569,7 @@ inline void loud_kill(FSTR_P const lcd_msg, const heater_id_t heater_id) { buzzer.on(); #endif #if ENABLED(NOZZLE_PARK_FEATURE) - if (!homing_needed_error()) { + if (!motion.homing_needed_error()) { nozzle.park(0); planner.synchronize(); } @@ -1727,7 +1727,7 @@ void Temperature::mintemp_error(const heater_id_t heater_id OPTARG(ERR_INCLUDE_T #if ENABLED(PID_EXTRUSION_SCALING) out += tempinfo.pid.get_extrusion_scale_output( - extr == active_extruder, stepper.position(E_AXIS), planner.mm_per_step[E_AXIS], thermalManager.lpq_len + extr == motion.extruder, stepper.position(E_AXIS), planner.mm_per_step[E_AXIS], thermalManager.lpq_len ); #endif @@ -1781,7 +1781,7 @@ void Temperature::mintemp_error(const heater_id_t heater_id OPTARG(ERR_INCLUDE_T const float pid_output = is_idling ? 0 : hotend_pid[ee].get_pid_output(ee); #if ENABLED(PID_DEBUG) - if (ee == active_extruder) + if (ee == motion.extruder) hotend_pid[ee].debug(temp_hotend[ee].celsius, pid_output, F("E"), ee); #endif @@ -1799,7 +1799,7 @@ void Temperature::mintemp_error(const heater_id_t heater_id OPTARG(ERR_INCLUDE_T #if HOTENDS == 1 constexpr bool this_hotend = true; #else - const bool this_hotend = (ee == active_extruder); + const bool this_hotend = (ee == motion.extruder); #endif float ambient_xfer_coeff = mpc.ambient_xfer_coeff_fan0; @@ -4538,7 +4538,7 @@ void Temperature::isr() { AutoReporter Temperature::auto_reporter; void Temperature::AutoReportTemp::report() { if (marlin.is_heating()) return; - print_heater_states(active_extruder OPTARG(HAS_TEMP_REDUNDANT, ENABLED(AUTO_REPORT_REDUNDANT))); + print_heater_states(motion.extruder OPTARG(HAS_TEMP_REDUNDANT, ENABLED(AUTO_REPORT_REDUNDANT))); SERIAL_EOL(); } #endif @@ -4714,7 +4714,7 @@ void Temperature::isr() { #if ENABLED(AUTOTEMP) void Temperature::_autotemp_update_from_hotend() { - TERN_(AUTOTEMP_PROPORTIONAL, autotemp.update(degTargetHotend(active_extruder))); + TERN_(AUTOTEMP_PROPORTIONAL, autotemp.update(degTargetHotend(motion.extruder))); } /** @@ -4750,7 +4750,7 @@ void Temperature::isr() { */ void Temperature::autotemp_task() { if (!autotemp.enabled) return; - if (degTargetHotend(active_extruder) < autotemp.cfg.min - 2) return; // Below the min? + if (degTargetHotend(motion.extruder) < autotemp.cfg.min - 2) return; // Below the min? // Get a highest target proportion greater than zero float high = planner.get_high_e_speed(); @@ -4758,7 +4758,7 @@ void Temperature::isr() { // Calculate a new target, with weighted correction for a drop float t = autotemp.calculate(high); - _setTargetHotend(t, active_extruder); + _setTargetHotend(t, motion.extruder); } #endif // AUTOTEMP @@ -4811,7 +4811,7 @@ void Temperature::isr() { now = millis(); if (ELAPSED(now, next_temp_ms)) { //Print Temp Reading every 1 second while heating up. next_temp_ms = now + 1000UL; - print_heater_states(active_extruder); + print_heater_states(motion.extruder); #if TEMP_BED_RESIDENCY_TIME > 0 SString<20> s(F(" W:")); if (residency_start_ms) @@ -4924,7 +4924,7 @@ void Temperature::isr() { millis_t now = millis(); if (!next_temp_ms || ELAPSED(now, next_temp_ms)) { next_temp_ms = now + 10000UL; - print_heater_states(active_extruder); + print_heater_states(motion.extruder); SERIAL_EOL(); } @@ -5008,7 +5008,7 @@ void Temperature::isr() { now = millis(); if (ELAPSED(now, next_temp_ms)) { // Print Temp Reading every 1 second while heating up. next_temp_ms = now + 1000UL; - print_heater_states(active_extruder); + print_heater_states(motion.extruder); #if TEMP_CHAMBER_RESIDENCY_TIME > 0 SString<20> s(F(" W:")); if (residency_start_ms) @@ -5109,7 +5109,7 @@ void Temperature::isr() { now = millis(); if (ELAPSED(now, next_temp_ms)) { // Print Temp Reading every 1 second while heating up. next_temp_ms = now + 1000UL; - print_heater_states(active_extruder); + print_heater_states(motion.extruder); #if TEMP_COOLER_RESIDENCY_TIME > 0 SString<20> s(F(" W:")); if (residency_start_ms) diff --git a/Marlin/src/module/tool_change.cpp b/Marlin/src/module/tool_change.cpp index 93abeb7468..94e83983d9 100644 --- a/Marlin/src/module/tool_change.cpp +++ b/Marlin/src/module/tool_change.cpp @@ -150,7 +150,7 @@ // Move to position routines void _line_to_current(const AxisEnum fr_axis, const float fscale=1) { - line_to_current_position(planner.settings.max_feedrate_mm_s[fr_axis] * fscale); + motion.goto_current_position(planner.settings.max_feedrate_mm_s[fr_axis] * fscale); } void slow_line_to_current(const AxisEnum fr_axis) { _line_to_current(fr_axis, 0.2f); } void fast_line_to_current(const AxisEnum fr_axis) { _line_to_current(fr_axis, 0.5f); } @@ -169,11 +169,11 @@ void fast_line_to_current(const AxisEnum fr_axis) { _line_to_current(fr_axis, 0. inline void magnetic_parking_extruder_tool_change(const uint8_t new_tool) { - const float oldx = current_position.x, + const float oldx = motion.position.x, grabpos = mpe_settings.parking_xpos[new_tool] + (new_tool ? mpe_settings.grab_distance : -mpe_settings.grab_distance), - offsetcompensation = TERN0(HAS_HOTEND_OFFSET, hotend_offset[active_extruder].x * mpe_settings.compensation_factor); + offsetcompensation = TERN0(HAS_HOTEND_OFFSET, hotend_offset[motion.extruder].x * mpe_settings.compensation_factor); - if (homing_needed_error(_BV(X_AXIS))) return; + if (motion.homing_needed_error(_BV(X_AXIS))) return; /** * Z Lift and Nozzle Offset shift ar defined in caller method to work equal with any Multi Hotend realization @@ -189,22 +189,22 @@ void fast_line_to_current(const AxisEnum fr_axis) { _line_to_current(fr_axis, 0. // STEP 1 - current_position.x = mpe_settings.parking_xpos[new_tool] + offsetcompensation; + motion.position.x = mpe_settings.parking_xpos[new_tool] + offsetcompensation; DEBUG_ECHOPGM("(1) Move extruder ", new_tool); - DEBUG_POS(" to new extruder ParkPos", current_position); + DEBUG_POS(" to new extruder ParkPos", motion.position); - planner.buffer_line(current_position, mpe_settings.fast_feedrate, new_tool); + planner.buffer_line(motion.position, mpe_settings.fast_feedrate, new_tool); planner.synchronize(); // STEP 2 - current_position.x = grabpos + offsetcompensation; + motion.position.x = grabpos + offsetcompensation; DEBUG_ECHOPGM("(2) Couple extruder ", new_tool); - DEBUG_POS(" to new extruder GrabPos", current_position); + DEBUG_POS(" to new extruder GrabPos", motion.position); - planner.buffer_line(current_position, mpe_settings.slow_feedrate, new_tool); + planner.buffer_line(motion.position, mpe_settings.slow_feedrate, new_tool); planner.synchronize(); // Delay before moving tool, to allow magnetic coupling @@ -212,42 +212,42 @@ void fast_line_to_current(const AxisEnum fr_axis) { _line_to_current(fr_axis, 0. // STEP 3 - current_position.x = mpe_settings.parking_xpos[new_tool] + offsetcompensation; + motion.position.x = mpe_settings.parking_xpos[new_tool] + offsetcompensation; DEBUG_ECHOPGM("(3) Move extruder ", new_tool); - DEBUG_POS(" back to new extruder ParkPos", current_position); + DEBUG_POS(" back to new extruder ParkPos", motion.position); - planner.buffer_line(current_position, mpe_settings.slow_feedrate, new_tool); + planner.buffer_line(motion.position, mpe_settings.slow_feedrate, new_tool); planner.synchronize(); // STEP 4 - current_position.x = mpe_settings.parking_xpos[active_extruder] + (active_extruder == 0 ? MPE_TRAVEL_DISTANCE : -MPE_TRAVEL_DISTANCE) + offsetcompensation; + motion.position.x = mpe_settings.parking_xpos[motion.extruder] + (motion.extruder == 0 ? MPE_TRAVEL_DISTANCE : -MPE_TRAVEL_DISTANCE) + offsetcompensation; DEBUG_ECHOPGM("(4) Move extruder ", new_tool); - DEBUG_POS(" close to old extruder ParkPos", current_position); + DEBUG_POS(" close to old extruder ParkPos", motion.position); - planner.buffer_line(current_position, mpe_settings.fast_feedrate, new_tool); + planner.buffer_line(motion.position, mpe_settings.fast_feedrate, new_tool); planner.synchronize(); // STEP 5 - current_position.x = mpe_settings.parking_xpos[active_extruder] + offsetcompensation; + motion.position.x = mpe_settings.parking_xpos[motion.extruder] + offsetcompensation; DEBUG_ECHOPGM("(5) Park extruder ", new_tool); - DEBUG_POS(" at old extruder ParkPos", current_position); + DEBUG_POS(" at old extruder ParkPos", motion.position); - planner.buffer_line(current_position, mpe_settings.slow_feedrate, new_tool); + planner.buffer_line(motion.position, mpe_settings.slow_feedrate, new_tool); planner.synchronize(); // STEP 6 - current_position.x = oldx; + motion.position.x = oldx; DEBUG_ECHOPGM("(6) Move extruder ", new_tool); - DEBUG_POS(" to starting position", current_position); + DEBUG_POS(" to starting position", motion.position); - planner.buffer_line(current_position, mpe_settings.fast_feedrate, new_tool); + planner.buffer_line(motion.position, mpe_settings.fast_feedrate, new_tool); planner.synchronize(); DEBUG_ECHOLNPGM("Autopark done."); @@ -295,7 +295,7 @@ void fast_line_to_current(const AxisEnum fr_axis) { _line_to_current(fr_axis, 0. constexpr float parkingposx[] = PARKING_EXTRUDER_PARKING_X; #if HAS_HOTEND_OFFSET - const float x_offset = hotend_offset[active_extruder].x; + const float x_offset = hotend_offset[motion.extruder].x; #else constexpr float x_offset = 0; #endif @@ -314,14 +314,14 @@ void fast_line_to_current(const AxisEnum fr_axis) { _line_to_current(fr_axis, 0. // STEP 1 - DEBUG_POS("Start PE Tool-Change", current_position); + DEBUG_POS("Start PE Tool-Change", motion.position); - // Don't park the active_extruder unless unparked + // Don't park the motion.extruder unless unparked if (!extruder_parked) { - current_position.x = parkingposx[active_extruder] + x_offset; + motion.position.x = parkingposx[motion.extruder] + x_offset; - DEBUG_ECHOLNPGM("(1) Park extruder ", active_extruder); - DEBUG_POS("Moving ParkPos", current_position); + DEBUG_ECHOLNPGM("(1) Park extruder ", motion.extruder); + DEBUG_POS("Moving ParkPos", motion.position); fast_line_to_current(X_AXIS); @@ -329,14 +329,14 @@ void fast_line_to_current(const AxisEnum fr_axis) { _line_to_current(fr_axis, 0. planner.synchronize(); DEBUG_ECHOLNPGM("(2) Disengage magnet"); - pe_solenoid_magnet_off(active_extruder); + pe_solenoid_magnet_off(motion.extruder); // STEP 3 - current_position.x += active_extruder ? -10 : 10; // move 10mm away from parked extruder + motion.position.x += motion.extruder ? -10 : 10; // move 10mm away from parked extruder DEBUG_ECHOLNPGM("(3) Move near new extruder"); - DEBUG_POS("Move away from parked extruder", current_position); + DEBUG_POS("Move away from parked extruder", motion.position); fast_line_to_current(X_AXIS); } @@ -347,37 +347,37 @@ void fast_line_to_current(const AxisEnum fr_axis) { _line_to_current(fr_axis, 0. DEBUG_ECHOLNPGM("(4) Engage magnetic field"); // Just save power for inverted magnets - TERN_(PARKING_EXTRUDER_SOLENOIDS_INVERT, pe_solenoid_magnet_on(active_extruder)); + TERN_(PARKING_EXTRUDER_SOLENOIDS_INVERT, pe_solenoid_magnet_on(motion.extruder)); pe_solenoid_magnet_on(new_tool); // STEP 5 - current_position.x = grabpos + (new_tool ? -10 : 10); + motion.position.x = grabpos + (new_tool ? -10 : 10); fast_line_to_current(X_AXIS); - current_position.x = grabpos; + motion.position.x = grabpos; DEBUG_SYNCHRONIZE(); - DEBUG_POS("(5) Unpark extruder", current_position); + DEBUG_POS("(5) Unpark extruder", motion.position); slow_line_to_current(X_AXIS); // STEP 6 - current_position.x = DIFF_TERN(HAS_HOTEND_OFFSET, midpos, hotend_offset[new_tool].x); + motion.position.x = DIFF_TERN(HAS_HOTEND_OFFSET, midpos, hotend_offset[new_tool].x); DEBUG_SYNCHRONIZE(); - DEBUG_POS("(6) Move midway between hotends", current_position); + DEBUG_POS("(6) Move midway between hotends", motion.position); fast_line_to_current(X_AXIS); planner.synchronize(); // Always sync the final move - DEBUG_POS("PE Tool-Change done.", current_position); + DEBUG_POS("PE Tool-Change done.", motion.position); parking_extruder_set_parked(false); } else if (do_solenoid_activation) { // Deactivate current extruder solenoid - pe_solenoid_set_pin_state(active_extruder, !PARKING_EXTRUDER_SOLENOIDS_PINS_ACTIVE); + pe_solenoid_set_pin_state(motion.extruder, !PARKING_EXTRUDER_SOLENOIDS_PINS_ACTIVE); // Engage new extruder magnetic field pe_solenoid_set_pin_state(new_tool, PARKING_EXTRUDER_SOLENOIDS_PINS_ACTIVE); } @@ -501,10 +501,10 @@ void fast_line_to_current(const AxisEnum fr_axis) { _line_to_current(fr_axis, 0. if (no_move) return; constexpr float toolheadposx[] = SWITCHING_TOOLHEAD_X_POS; - const float placexpos = toolheadposx[active_extruder], + const float placexpos = toolheadposx[motion.extruder], grabxpos = toolheadposx[new_tool]; - (void)check_tool_sensor_stats(active_extruder, true); + (void)check_tool_sensor_stats(motion.extruder, true); /** * 1. Move to switch position of current toolhead @@ -515,19 +515,19 @@ void fast_line_to_current(const AxisEnum fr_axis) { _line_to_current(fr_axis, 0. // 1. Move to switch position of current toolhead - DEBUG_POS("Start ST Tool-Change", current_position); + DEBUG_POS("Start ST Tool-Change", motion.position); - current_position.x = placexpos; + motion.position.x = placexpos; - DEBUG_ECHOLNPGM("(1) Place old tool ", active_extruder); - DEBUG_POS("Move X SwitchPos", current_position); + DEBUG_ECHOLNPGM("(1) Place old tool ", motion.extruder); + DEBUG_POS("Move X SwitchPos", motion.position); fast_line_to_current(X_AXIS); - current_position.y = SWITCHING_TOOLHEAD_Y_POS - (SWITCHING_TOOLHEAD_Y_SECURITY); + motion.position.y = SWITCHING_TOOLHEAD_Y_POS - (SWITCHING_TOOLHEAD_Y_SECURITY); DEBUG_SYNCHRONIZE(); - DEBUG_POS("Move Y SwitchPos + Security", current_position); + DEBUG_POS("Move Y SwitchPos + Security", motion.position); slow_line_to_current(Y_AXIS); @@ -539,44 +539,44 @@ void fast_line_to_current(const AxisEnum fr_axis) { _line_to_current(fr_axis, 0. switching_toolhead_lock(false); safe_delay(500); - current_position.y = SWITCHING_TOOLHEAD_Y_POS; - DEBUG_POS("Move Y SwitchPos", current_position); + motion.position.y = SWITCHING_TOOLHEAD_Y_POS; + DEBUG_POS("Move Y SwitchPos", motion.position); slow_line_to_current(Y_AXIS); // Wait for move to complete, then another 0.2s planner.synchronize(); safe_delay(200); - current_position.y -= SWITCHING_TOOLHEAD_Y_CLEAR; - DEBUG_POS("Move back Y clear", current_position); + motion.position.y -= SWITCHING_TOOLHEAD_Y_CLEAR; + DEBUG_POS("Move back Y clear", motion.position); slow_line_to_current(Y_AXIS); // move away from docked toolhead - (void)check_tool_sensor_stats(active_extruder); + (void)check_tool_sensor_stats(motion.extruder); // 3. Move to the new toolhead - current_position.x = grabxpos; + motion.position.x = grabxpos; DEBUG_SYNCHRONIZE(); DEBUG_ECHOLNPGM("(3) Move to new toolhead position"); - DEBUG_POS("Move to new toolhead X", current_position); + DEBUG_POS("Move to new toolhead X", motion.position); fast_line_to_current(X_AXIS); - current_position.y = SWITCHING_TOOLHEAD_Y_POS - (SWITCHING_TOOLHEAD_Y_SECURITY); + motion.position.y = SWITCHING_TOOLHEAD_Y_POS - (SWITCHING_TOOLHEAD_Y_SECURITY); DEBUG_SYNCHRONIZE(); - DEBUG_POS("Move Y SwitchPos + Security", current_position); + DEBUG_POS("Move Y SwitchPos + Security", motion.position); slow_line_to_current(Y_AXIS); // 4. Grab and lock the new toolhead - current_position.y = SWITCHING_TOOLHEAD_Y_POS; + motion.position.y = SWITCHING_TOOLHEAD_Y_POS; DEBUG_SYNCHRONIZE(); DEBUG_ECHOLNPGM("(4) Grab and lock new toolhead"); - DEBUG_POS("Move Y SwitchPos", current_position); + DEBUG_POS("Move Y SwitchPos", motion.position); slow_line_to_current(Y_AXIS); @@ -589,14 +589,14 @@ void fast_line_to_current(const AxisEnum fr_axis) { _line_to_current(fr_axis, 0. switching_toolhead_lock(true); safe_delay(500); - current_position.y -= SWITCHING_TOOLHEAD_Y_CLEAR; - DEBUG_POS("Move back Y clear", current_position); + motion.position.y -= SWITCHING_TOOLHEAD_Y_CLEAR; + DEBUG_POS("Move back Y clear", motion.position); slow_line_to_current(Y_AXIS); // Move away from docked toolhead planner.synchronize(); // Always sync the final move (void)check_tool_sensor_stats(new_tool, true, true); - DEBUG_POS("ST Tool-Change done.", current_position); + DEBUG_POS("ST Tool-Change done.", motion.position); } #elif ENABLED(MAGNETIC_SWITCHING_TOOLHEAD) @@ -607,8 +607,8 @@ void fast_line_to_current(const AxisEnum fr_axis) { _line_to_current(fr_axis, 0. constexpr float toolheadposx[] = SWITCHING_TOOLHEAD_X_POS, toolheadclearx[] = SWITCHING_TOOLHEAD_X_SECURITY; - const float placexpos = toolheadposx[active_extruder], - placexclear = toolheadclearx[active_extruder], + const float placexpos = toolheadposx[motion.extruder], + placexclear = toolheadclearx[motion.extruder], grabxpos = toolheadposx[new_tool], grabxclear = toolheadclearx[new_tool]; @@ -619,61 +619,61 @@ void fast_line_to_current(const AxisEnum fr_axis) { _line_to_current(fr_axis, 0. * 4. Grab the new toolhead and move to security position */ - DEBUG_POS("Start MST Tool-Change", current_position); + DEBUG_POS("Start MST Tool-Change", motion.position); // 1. Move to switch position current toolhead - current_position.y = SWITCHING_TOOLHEAD_Y_POS + SWITCHING_TOOLHEAD_Y_CLEAR; + motion.position.y = SWITCHING_TOOLHEAD_Y_POS + SWITCHING_TOOLHEAD_Y_CLEAR; - SERIAL_ECHOLNPGM("(1) Place old tool ", active_extruder); - DEBUG_POS("Move Y SwitchPos + Security", current_position); + SERIAL_ECHOLNPGM("(1) Place old tool ", motion.extruder); + DEBUG_POS("Move Y SwitchPos + Security", motion.position); fast_line_to_current(Y_AXIS); - current_position.x = placexclear; + motion.position.x = placexclear; DEBUG_SYNCHRONIZE(); - DEBUG_POS("Move X SwitchPos + Security", current_position); + DEBUG_POS("Move X SwitchPos + Security", motion.position); fast_line_to_current(X_AXIS); - current_position.y = SWITCHING_TOOLHEAD_Y_POS; + motion.position.y = SWITCHING_TOOLHEAD_Y_POS; DEBUG_SYNCHRONIZE(); - DEBUG_POS("Move Y SwitchPos", current_position); + DEBUG_POS("Move Y SwitchPos", motion.position); fast_line_to_current(Y_AXIS); - current_position.x = placexpos; + motion.position.x = placexpos; DEBUG_SYNCHRONIZE(); - DEBUG_POS("Move X SwitchPos", current_position); + DEBUG_POS("Move X SwitchPos", motion.position); - line_to_current_position(planner.settings.max_feedrate_mm_s[X_AXIS] * 0.25f); + motion.goto_current_position(planner.settings.max_feedrate_mm_s[X_AXIS] * 0.25f); // 2. Release and place toolhead in the dock DEBUG_SYNCHRONIZE(); DEBUG_ECHOLNPGM("(2) Release and Place Toolhead"); - current_position.y = SWITCHING_TOOLHEAD_Y_POS + SWITCHING_TOOLHEAD_Y_RELEASE; - DEBUG_POS("Move Y SwitchPos + Release", current_position); - line_to_current_position(planner.settings.max_feedrate_mm_s[Y_AXIS] * 0.1f); + motion.position.y = SWITCHING_TOOLHEAD_Y_POS + SWITCHING_TOOLHEAD_Y_RELEASE; + DEBUG_POS("Move Y SwitchPos + Release", motion.position); + motion.goto_current_position(planner.settings.max_feedrate_mm_s[Y_AXIS] * 0.1f); - current_position.y = SWITCHING_TOOLHEAD_Y_POS + SWITCHING_TOOLHEAD_Y_SECURITY; + motion.position.y = SWITCHING_TOOLHEAD_Y_POS + SWITCHING_TOOLHEAD_Y_SECURITY; DEBUG_SYNCHRONIZE(); - DEBUG_POS("Move Y SwitchPos + Security", current_position); + DEBUG_POS("Move Y SwitchPos + Security", motion.position); - line_to_current_position(planner.settings.max_feedrate_mm_s[Y_AXIS]); + motion.goto_current_position(planner.settings.max_feedrate_mm_s[Y_AXIS]); // 3. Move to new toolhead position DEBUG_SYNCHRONIZE(); DEBUG_ECHOLNPGM("(3) Move to new toolhead position"); - current_position.x = grabxpos; - DEBUG_POS("Move to new toolhead X", current_position); + motion.position.x = grabxpos; + DEBUG_POS("Move to new toolhead X", motion.position); fast_line_to_current(X_AXIS); // 4. Grab the new toolhead and move to security position @@ -681,43 +681,43 @@ void fast_line_to_current(const AxisEnum fr_axis) { _line_to_current(fr_axis, 0. DEBUG_SYNCHRONIZE(); DEBUG_ECHOLNPGM("(4) Grab new toolhead, move to security position"); - current_position.y = SWITCHING_TOOLHEAD_Y_POS + SWITCHING_TOOLHEAD_Y_RELEASE; - DEBUG_POS("Move Y SwitchPos + Release", current_position); - line_to_current_position(planner.settings.max_feedrate_mm_s[Y_AXIS]); + motion.position.y = SWITCHING_TOOLHEAD_Y_POS + SWITCHING_TOOLHEAD_Y_RELEASE; + DEBUG_POS("Move Y SwitchPos + Release", motion.position); + motion.goto_current_position(planner.settings.max_feedrate_mm_s[Y_AXIS]); - current_position.y = SWITCHING_TOOLHEAD_Y_POS; + motion.position.y = SWITCHING_TOOLHEAD_Y_POS; DEBUG_SYNCHRONIZE(); - DEBUG_POS("Move Y SwitchPos", current_position); + DEBUG_POS("Move Y SwitchPos", motion.position); _line_to_current(Y_AXIS, 0.2f); #if ENABLED(PRIME_BEFORE_REMOVE) && (SWITCHING_TOOLHEAD_PRIME_MM || SWITCHING_TOOLHEAD_RETRACT_MM) #if SWITCHING_TOOLHEAD_PRIME_MM - current_position.e += SWITCHING_TOOLHEAD_PRIME_MM; - planner.buffer_line(current_position, MMM_TO_MMS(SWITCHING_TOOLHEAD_PRIME_FEEDRATE), new_tool); + motion.position.e += SWITCHING_TOOLHEAD_PRIME_MM; + planner.buffer_line(motion.position, MMM_TO_MMS(SWITCHING_TOOLHEAD_PRIME_FEEDRATE), new_tool); #endif #if SWITCHING_TOOLHEAD_RETRACT_MM - current_position.e -= SWITCHING_TOOLHEAD_RETRACT_MM; - planner.buffer_line(current_position, MMM_TO_MMS(SWITCHING_TOOLHEAD_RETRACT_FEEDRATE), new_tool); + motion.position.e -= SWITCHING_TOOLHEAD_RETRACT_MM; + planner.buffer_line(motion.position, MMM_TO_MMS(SWITCHING_TOOLHEAD_RETRACT_FEEDRATE), new_tool); #endif #else planner.synchronize(); safe_delay(100); // Give switch time to settle #endif - current_position.x = grabxclear; - DEBUG_POS("Move to new toolhead X + Security", current_position); + motion.position.x = grabxclear; + DEBUG_POS("Move to new toolhead X + Security", motion.position); _line_to_current(X_AXIS, 0.1f); planner.synchronize(); safe_delay(100); // Give switch time to settle - current_position.y += SWITCHING_TOOLHEAD_Y_CLEAR; - DEBUG_POS("Move back Y clear", current_position); + motion.position.y += SWITCHING_TOOLHEAD_Y_CLEAR; + DEBUG_POS("Move back Y clear", motion.position); fast_line_to_current(Y_AXIS); // move away from docked toolhead planner.synchronize(); // Always sync last tool-change move - DEBUG_POS("MST Tool-Change done.", current_position); + DEBUG_POS("MST Tool-Change done.", motion.position); } #elif ENABLED(ELECTROMAGNETIC_SWITCHING_TOOLHEAD) @@ -730,9 +730,9 @@ void fast_line_to_current(const AxisEnum fr_axis) { _line_to_current(fr_axis, 0. if (no_move) return; constexpr float toolheadposx[] = SWITCHING_TOOLHEAD_X_POS; - const float placexpos = toolheadposx[active_extruder], + const float placexpos = toolheadposx[motion.extruder], grabxpos = toolheadposx[new_tool]; - const xyz_pos_t &hoffs = hotend_offset[active_extruder]; + const xyz_pos_t &hoffs = hotend_offset[motion.extruder]; /** * 1. Raise Z-Axis to give enough clearance @@ -746,31 +746,31 @@ void fast_line_to_current(const AxisEnum fr_axis) { _line_to_current(fr_axis, 0. * 9. Apply Z hotend offset to current position */ - DEBUG_POS("Start EMST Tool-Change", current_position); + DEBUG_POS("Start EMST Tool-Change", motion.position); // 1. Raise Z-Axis to give enough clearance - current_position.z += SWITCHING_TOOLHEAD_Z_HOP; - DEBUG_POS("(1) Raise Z-Axis ", current_position); + motion.position.z += SWITCHING_TOOLHEAD_Z_HOP; + DEBUG_POS("(1) Raise Z-Axis ", motion.position); fast_line_to_current(Z_AXIS); // 2. Move to position near active extruder parking DEBUG_SYNCHRONIZE(); - DEBUG_ECHOLNPGM("(2) Move near active extruder parking", active_extruder); - DEBUG_POS("Moving ParkPos", current_position); + DEBUG_ECHOLNPGM("(2) Move near active extruder parking", motion.extruder); + DEBUG_POS("Moving ParkPos", motion.position); - current_position.set(hoffs.x + placexpos, + motion.position.set(hoffs.x + placexpos, hoffs.y + SWITCHING_TOOLHEAD_Y_POS + SWITCHING_TOOLHEAD_Y_CLEAR); fast_line_to_current(X_AXIS); // 3. Move gently to park position of active extruder DEBUG_SYNCHRONIZE(); - SERIAL_ECHOLNPGM("(3) Move gently to park position of active extruder", active_extruder); - DEBUG_POS("Moving ParkPos", current_position); + SERIAL_ECHOLNPGM("(3) Move gently to park position of active extruder", motion.extruder); + DEBUG_POS("Moving ParkPos", motion.position); - current_position.y -= SWITCHING_TOOLHEAD_Y_CLEAR; + motion.position.y -= SWITCHING_TOOLHEAD_Y_CLEAR; slow_line_to_current(Y_AXIS); // 4. Disengage magnetic field, wait for delay @@ -782,17 +782,17 @@ void fast_line_to_current(const AxisEnum fr_axis) { _line_to_current(fr_axis, 0. // 5. Leave extruder and move to position near new extruder parking DEBUG_ECHOLNPGM("(5) Move near new extruder parking"); - DEBUG_POS("Moving ParkPos", current_position); + DEBUG_POS("Moving ParkPos", motion.position); - current_position.y += SWITCHING_TOOLHEAD_Y_CLEAR; + motion.position.y += SWITCHING_TOOLHEAD_Y_CLEAR; slow_line_to_current(Y_AXIS); - current_position.set(hoffs.x + grabxpos, + motion.position.set(hoffs.x + grabxpos, hoffs.y + SWITCHING_TOOLHEAD_Y_POS + SWITCHING_TOOLHEAD_Y_CLEAR); fast_line_to_current(X_AXIS); // 6. Move gently to park position of new extruder - current_position.y -= SWITCHING_TOOLHEAD_Y_CLEAR; + motion.position.y -= SWITCHING_TOOLHEAD_Y_CLEAR; if (DEBUGGING(LEVELING)) { planner.synchronize(); DEBUG_ECHOLNPGM("(6) Move near new extruder"); @@ -807,17 +807,17 @@ void fast_line_to_current(const AxisEnum fr_axis) { _line_to_current(fr_axis, 0. // 8. Unpark extruder - current_position.y += SWITCHING_TOOLHEAD_Y_CLEAR; + motion.position.y += SWITCHING_TOOLHEAD_Y_CLEAR; DEBUG_ECHOLNPGM("(8) Unpark extruder"); slow_line_to_current(X_AXIS); planner.synchronize(); // Always sync the final move // 9. Apply Z hotend offset to current position - DEBUG_POS("(9) Applying Z-offset", current_position); - current_position.z += hoffs.z - hotend_offset[new_tool].z; + DEBUG_POS("(9) Applying Z-offset", motion.position); + motion.position.z += hoffs.z - hotend_offset[new_tool].z; - DEBUG_POS("EMST Tool-Change done.", current_position); + DEBUG_POS("EMST Tool-Change done.", motion.position); } #endif // ELECTROMAGNETIC_SWITCHING_TOOLHEAD @@ -850,33 +850,33 @@ void fast_line_to_current(const AxisEnum fr_axis) { _line_to_current(fr_axis, 0. } // Get the home position of the currently-active tool - const float xhome = x_home_pos(active_extruder); + const float xhome = x_home_pos(motion.extruder); if (dual_x_carriage_mode == DXC_AUTO_PARK_MODE // If Auto-Park mode is enabled && marlin.isRunning() && !no_move // ...and movement is permitted - && (delayed_move_time || current_position.x != xhome) // ...and delayed_move_time is set OR not "already parked"... + && (delayed_move_time || motion.position.x != xhome) // ...and delayed_move_time is set OR not "already parked"... ) { DEBUG_ECHOLNPGM("MoveX to ", xhome); - current_position.x = xhome; - line_to_current_position(planner.settings.max_feedrate_mm_s[X_AXIS]); // Park the current head + motion.position.x = xhome; + motion.goto_current_position(planner.settings.max_feedrate_mm_s[X_AXIS]); // Park the current head planner.synchronize(); } - // Activate the new extruder ahead of calling set_axis_is_at_home! - active_extruder = new_tool; + // Activate the new extruder ahead of calling motion.set_axis_is_at_home! + motion.extruder = new_tool; // This function resets the max/min values - the current position may be overwritten below. - set_axis_is_at_home(X_AXIS); + motion.set_axis_is_at_home(X_AXIS); - DEBUG_POS("New Extruder", current_position); + DEBUG_POS("New Extruder", motion.position); switch (dual_x_carriage_mode) { case DXC_FULL_CONTROL_MODE: // New current position is the position of the activated extruder - current_position.x = inactive_extruder_x; - // Save the inactive extruder's position (from the old current_position) - inactive_extruder_x = destination.x; - DEBUG_ECHOLNPGM("DXC Full Control curr.x=", current_position.x, " dest.x=", destination.x); + motion.position.x = inactive_extruder_x; + // Save the inactive extruder's position (from the old motion.position) + inactive_extruder_x = motion.destination.x; + DEBUG_ECHOLNPGM("DXC Full Control curr.x=", motion.position.x, " dest.x=", motion.destination.x); break; case DXC_AUTO_PARK_MODE: idex_set_parked(); @@ -889,7 +889,7 @@ void fast_line_to_current(const AxisEnum fr_axis) { _line_to_current(fr_axis, 0. stepper.apply_directions(); DEBUG_ECHOLNPGM("Active extruder parked: ", active_extruder_parked ? "yes" : "no"); - DEBUG_POS("New extruder (parked)", current_position); + DEBUG_POS("New extruder (parked)", motion.position); } #endif // DUAL_X_CARRIAGE @@ -935,20 +935,18 @@ void fast_line_to_current(const AxisEnum fr_axis) { _line_to_current(fr_axis, 0. /** * Cutting recovery -- Recover from cutting retraction that occurs at the end of nozzle priming * - * If the active_extruder is up to temp (!too_cold): + * If the motion.extruder is up to temp (!too_cold): * Extrude filament distance = toolchange_settings.extra_resume + toolchange_settings.wipe_retract - * current_position.e = e; - * sync_plan_position_e(); + * set_and_sync_e(e); */ void extruder_cutting_recover(const float e) { - if (too_cold(active_extruder)) return; + if (too_cold(motion.extruder)) return; const float dist = toolchange_settings.extra_resume + toolchange_settings.wipe_retract; DEBUG_ECHOLNPGM("Performing Cutting Recover | Distance: ", dist, " | Speed: ", MMM_TO_MMS(toolchange_settings.unretract_speed), "mm/s"); - unscaled_e_move(dist, MMM_TO_MMS(toolchange_settings.unretract_speed)); + motion.unscaled_e_move(dist, MMM_TO_MMS(toolchange_settings.unretract_speed)); DEBUG_ECHOLNPGM("Set E position: ", e); - current_position.e = e; - sync_plan_position_e(); // Resume new E Position + motion.set_and_sync_e(e); // Resume new E Position } /** @@ -960,27 +958,27 @@ void fast_line_to_current(const AxisEnum fr_axis) { _line_to_current(fr_axis, 0. * If cooling fan is enabled, calls filament_swap_cooling(); */ void extruder_prime() { - if (too_cold(active_extruder)) { + if (too_cold(motion.extruder)) { DEBUG_ECHOLNPGM("Priming Aborted - Nozzle Too Cold!"); return; // Extruder too cold to prime } feedRate_t fr_mm_s = MMM_TO_MMS(toolchange_settings.unretract_speed); // Set default speed for unretract - const float resume_current_e = current_position.e; + const float resume_current_e = motion.position.e; #if ENABLED(TOOLCHANGE_FS_SLOW_FIRST_PRIME) /** * Perform first unretract movement at the slower Prime_Speed to avoid breakage on first prime */ static Flags extruder_did_first_prime; // Extruders first priming status - if (!extruder_did_first_prime[active_extruder]) { - extruder_did_first_prime.set(active_extruder); // Log first prime complete + if (!extruder_did_first_prime[motion.extruder]) { + extruder_did_first_prime.set(motion.extruder); // Log first prime complete // new nozzle - prime at user-specified speed. const feedRate_t prime_mm_s = MMM_TO_MMS(toolchange_settings.prime_speed); - DEBUG_ECHOLNPGM("First time priming T", active_extruder, ", reducing speed from ", fr_mm_s, " to ", prime_mm_s, "mm/s"); + DEBUG_ECHOLNPGM("First time priming T", motion.extruder, ", reducing speed from ", fr_mm_s, " to ", prime_mm_s, "mm/s"); fr_mm_s = prime_mm_s; - unscaled_e_move(0, fr_mm_s); // Init planner with 0 length move + motion.unscaled_e_move(0, fr_mm_s); // Init planner with 0 length move } #endif @@ -988,12 +986,12 @@ void fast_line_to_current(const AxisEnum fr_axis) { _line_to_current(fr_axis, 0. if (toolchange_settings.extra_prime >= 0) { // Positive extra_prime value // - Return filament at speed (fr_mm_s) then extra_prime at prime speed - DEBUG_ECHOLNPGM("Loading Filament for T", active_extruder, " | Distance: ", toolchange_settings.swap_length, " | Speed: ", fr_mm_s, "mm/s"); - unscaled_e_move(toolchange_settings.swap_length, fr_mm_s); // Prime (Unretract) filament by extruding equal to Swap Length (Unretract) + DEBUG_ECHOLNPGM("Loading Filament for T", motion.extruder, " | Distance: ", toolchange_settings.swap_length, " | Speed: ", fr_mm_s, "mm/s"); + motion.unscaled_e_move(toolchange_settings.swap_length, fr_mm_s); // Prime (Unretract) filament by extruding equal to Swap Length (Unretract) if (toolchange_settings.extra_prime > 0) { - DEBUG_ECHOLNPGM("Performing Extra Priming for T", active_extruder, " | Distance: ", toolchange_settings.extra_prime, " | Speed: ", MMM_TO_MMS(toolchange_settings.prime_speed), "mm/s"); - unscaled_e_move(toolchange_settings.extra_prime, MMM_TO_MMS(toolchange_settings.prime_speed)); // Extra Prime Distance + DEBUG_ECHOLNPGM("Performing Extra Priming for T", motion.extruder, " | Distance: ", toolchange_settings.extra_prime, " | Speed: ", MMM_TO_MMS(toolchange_settings.prime_speed), "mm/s"); + motion.unscaled_e_move(toolchange_settings.extra_prime, MMM_TO_MMS(toolchange_settings.prime_speed)); // Extra Prime Distance } } else { @@ -1001,21 +999,20 @@ void fast_line_to_current(const AxisEnum fr_axis) { _line_to_current(fr_axis, 0. // - Unretract distance (swap length) is reduced by the value of extra_prime const float eswap = toolchange_settings.swap_length + toolchange_settings.extra_prime; DEBUG_ECHOLNPGM("Negative ExtraPrime value - Swap Return Length has been reduced from ", toolchange_settings.swap_length, " to ", eswap); - DEBUG_ECHOLNPGM("Loading Filament for T", active_extruder, " | Distance: ", eswap, " | Speed: ", fr_mm_s, "mm/s"); - unscaled_e_move(eswap, fr_mm_s); + DEBUG_ECHOLNPGM("Loading Filament for T", motion.extruder, " | Distance: ", eswap, " | Speed: ", fr_mm_s, "mm/s"); + motion.unscaled_e_move(eswap, fr_mm_s); } - extruder_was_primed.set(active_extruder); // Log that this extruder has been primed + extruder_was_primed.set(motion.extruder); // Log that this extruder has been primed // Cutting retraction #if TOOLCHANGE_FS_WIPE_RETRACT DEBUG_ECHOLNPGM("Performing Cutting Retraction | Distance: ", -toolchange_settings.wipe_retract, " | Speed: ", MMM_TO_MMS(toolchange_settings.retract_speed), "mm/s"); - unscaled_e_move(-toolchange_settings.wipe_retract, MMM_TO_MMS(toolchange_settings.retract_speed)); + motion.unscaled_e_move(-toolchange_settings.wipe_retract, MMM_TO_MMS(toolchange_settings.retract_speed)); #endif // Leave E unchanged when priming - current_position.e = resume_current_e; - sync_plan_position_e(); + motion.set_and_sync_e(resume_current_e); // Cool down with fan filament_swap_cooling(); @@ -1029,10 +1026,10 @@ void fast_line_to_current(const AxisEnum fr_axis) { _line_to_current(fr_axis, 0. DEBUG_SECTION(tcp, "tool_change_prime", true); - if (!too_cold(active_extruder)) { - destination = current_position; // Remember the old position + if (!too_cold(motion.extruder)) { + motion.destination = motion.position; // Remember the old position - const bool ok = TERN0(TOOLCHANGE_PARK, all_axes_homed() && toolchange_settings.enable_park); + const bool ok = TERN0(TOOLCHANGE_PARK, motion.all_axes_homed() && toolchange_settings.enable_park); #if HAS_FAN && TOOLCHANGE_FS_FAN >= 0 // Store and stop fan. Restored on any exit. @@ -1042,8 +1039,8 @@ void fast_line_to_current(const AxisEnum fr_axis) { _line_to_current(fr_axis, 0. // Z raise if (ok) { // Do a small lift to avoid the workpiece in the move back (below) - current_position.z += toolchange_settings.z_raise; - TERN_(HAS_SOFTWARE_ENDSTOPS, NOMORE(current_position.z, soft_endstop.max.z)); + motion.position.z += toolchange_settings.z_raise; + TERN_(HAS_SOFTWARE_ENDSTOPS, NOMORE(motion.position.z, motion.soft_endstop.max.z)); fast_line_to_current(Z_AXIS); planner.synchronize(); } @@ -1051,19 +1048,19 @@ void fast_line_to_current(const AxisEnum fr_axis) { _line_to_current(fr_axis, 0. // Park #if ENABLED(TOOLCHANGE_PARK) if (ok) { - IF_DISABLED(TOOLCHANGE_PARK_Y_ONLY, current_position.x = toolchange_settings.change_point.x); - IF_DISABLED(TOOLCHANGE_PARK_X_ONLY, current_position.y = toolchange_settings.change_point.y); + IF_DISABLED(TOOLCHANGE_PARK_Y_ONLY, motion.position.x = toolchange_settings.change_point.x); + IF_DISABLED(TOOLCHANGE_PARK_X_ONLY, motion.position.y = toolchange_settings.change_point.y); #if NONE(TOOLCHANGE_PARK_X_ONLY, TOOLCHANGE_PARK_Y_ONLY) SECONDARY_AXIS_CODE( - current_position.i = toolchange_settings.change_point.i, - current_position.j = toolchange_settings.change_point.j, - current_position.k = toolchange_settings.change_point.k, - current_position.u = toolchange_settings.change_point.u, - current_position.v = toolchange_settings.change_point.v, - current_position.w = toolchange_settings.change_point.w + motion.position.i = toolchange_settings.change_point.i, + motion.position.j = toolchange_settings.change_point.j, + motion.position.k = toolchange_settings.change_point.k, + motion.position.u = toolchange_settings.change_point.u, + motion.position.v = toolchange_settings.change_point.v, + motion.position.w = toolchange_settings.change_point.w ); #endif - planner.buffer_line(current_position, MMM_TO_MMS(TOOLCHANGE_PARK_XY_FEEDRATE), active_extruder); + planner.buffer_line(motion.position, MMM_TO_MMS(TOOLCHANGE_PARK_XY_FEEDRATE), motion.extruder); planner.synchronize(); } #endif @@ -1075,29 +1072,29 @@ void fast_line_to_current(const AxisEnum fr_axis) { _line_to_current(fr_axis, 0. #if ENABLED(TOOLCHANGE_PARK) if (ok) { #if ENABLED(TOOLCHANGE_NO_RETURN) - destination.x = current_position.x; - destination.y = current_position.y; + motion.destination.x = motion.position.x; + motion.destination.y = motion.position.y; #endif - do_blocking_move_to_xy(destination, MMM_TO_MMS(TOOLCHANGE_PARK_XY_FEEDRATE)); - do_blocking_move_to_z(destination.z, planner.settings.max_feedrate_mm_s[Z_AXIS]); + motion.blocking_move_xy(motion.destination, MMM_TO_MMS(TOOLCHANGE_PARK_XY_FEEDRATE)); + motion.blocking_move_z(motion.destination.z, planner.settings.max_feedrate_mm_s[Z_AXIS]); planner.synchronize(); } #endif // Clone previous position - extruder_cutting_recover(destination.e); // Cutting recover + extruder_cutting_recover(motion.destination.e); // Cutting recover // Retract if previously retracted #if ENABLED(FWRETRACT) - if (fwretract.retracted[active_extruder]) - unscaled_e_move(-fwretract.settings.retract_length, fwretract.settings.retract_feedrate_mm_s); + if (fwretract.retracted[motion.extruder]) + motion.unscaled_e_move(-fwretract.settings.retract_length, fwretract.settings.retract_feedrate_mm_s); #endif // If resume_position is negative - if (current_position.e < 0) unscaled_e_move(current_position.e, MMM_TO_MMS(toolchange_settings.retract_speed)); + if (motion.position.e < 0) motion.unscaled_e_move(motion.position.e, MMM_TO_MMS(toolchange_settings.retract_speed)); planner.synchronize(); - planner.set_e_position_mm(current_position.e); // Extruder primed and ready + planner.set_e_position_mm(motion.position.e); // Extruder primed and ready } } @@ -1109,7 +1106,7 @@ void fast_line_to_current(const AxisEnum fr_axis) { _line_to_current(fr_axis, 0. */ void tool_change(const uint8_t new_tool, bool no_move/*=false*/) { - if (TERN0(MAGNETIC_SWITCHING_TOOLHEAD, new_tool == active_extruder)) + if (TERN0(MAGNETIC_SWITCHING_TOOLHEAD, new_tool == motion.extruder)) return; #if ENABLED(MIXING_EXTRUDER) @@ -1160,7 +1157,7 @@ void tool_change(const uint8_t new_tool, bool no_move/*=false*/) { if (new_tool >= EXTRUDERS) return invalid_extruder_error(new_tool); - if (!no_move && homing_needed()) { + if (!no_move && motion.homing_needed()) { no_move = true; DEBUG_ECHOLNPGM("No move (not homed)"); } @@ -1173,7 +1170,7 @@ void tool_change(const uint8_t new_tool, bool no_move/*=false*/) { constexpr bool idex_full_control = false; #endif - const uint8_t old_tool = active_extruder; + const uint8_t old_tool = motion.extruder; const bool can_move_away = !no_move && !idex_full_control; #if ENABLED(AUTO_BED_LEVELING_UBL) @@ -1190,7 +1187,7 @@ void tool_change(const uint8_t new_tool, bool no_move/*=false*/) { #endif if (new_tool != old_tool || TERN0(PARKING_EXTRUDER, extruder_parked)) { // PARKING_EXTRUDER may need to attach old_tool when homing - destination = current_position; + motion.destination = motion.position; #if ALL(TOOLCHANGE_FILAMENT_SWAP, HAS_FAN) && TOOLCHANGE_FS_FAN >= 0 // Store and stop fan. Restored on any exit. @@ -1201,8 +1198,8 @@ void tool_change(const uint8_t new_tool, bool no_move/*=false*/) { #if ENABLED(TOOLCHANGE_ZRAISE_BEFORE_RETRACT) && !HAS_SWITCHING_NOZZLE if (can_move_away && TERN1(TOOLCHANGE_PARK, toolchange_settings.enable_park)) { // Do a small lift to avoid the workpiece in the move back (below) - current_position.z += toolchange_settings.z_raise; - TERN_(HAS_SOFTWARE_ENDSTOPS, NOMORE(current_position.z, soft_endstop.max.z)); + motion.position.z += toolchange_settings.z_raise; + TERN_(HAS_SOFTWARE_ENDSTOPS, NOMORE(motion.position.z, motion.soft_endstop.max.z)); fast_line_to_current(Z_AXIS); planner.synchronize(); } @@ -1214,18 +1211,18 @@ void tool_change(const uint8_t new_tool, bool no_move/*=false*/) { if (should_swap) { if (too_cold(old_tool)) { // If SingleNozzle setup is too cold, unable to perform tool_change. - if (ENABLED(SINGLENOZZLE)) { active_extruder = new_tool; return; } + if (ENABLED(SINGLENOZZLE)) { motion.extruder = new_tool; return; } } else if (extruder_was_primed[old_tool]) { // Retract the old extruder if it was previously primed // To-Do: Should SingleNozzle always retract? DEBUG_ECHOLNPGM("Retracting Filament for T", old_tool, ". | Distance: ", toolchange_settings.swap_length, " | Speed: ", MMM_TO_MMS(toolchange_settings.retract_speed), "mm/s"); - unscaled_e_move(-toolchange_settings.swap_length, MMM_TO_MMS(toolchange_settings.retract_speed)); + motion.unscaled_e_move(-toolchange_settings.swap_length, MMM_TO_MMS(toolchange_settings.retract_speed)); } } #endif - REMEMBER(fr, feedrate_mm_s, XY_PROBE_FEEDRATE_MM_S); + REMEMBER(fr, motion.feedrate_mm_s, XY_PROBE_FEEDRATE_MM_S); #if HAS_SOFTWARE_ENDSTOPS #if HAS_HOTEND_OFFSET @@ -1233,18 +1230,18 @@ void tool_change(const uint8_t new_tool, bool no_move/*=false*/) { #else #define _EXT_ARGS #endif - update_software_endstops(X_AXIS _EXT_ARGS); + motion.update_software_endstops(X_AXIS _EXT_ARGS); #if DISABLED(DUAL_X_CARRIAGE) - update_software_endstops(Y_AXIS _EXT_ARGS); - update_software_endstops(Z_AXIS _EXT_ARGS); + motion.update_software_endstops(Y_AXIS _EXT_ARGS); + motion.update_software_endstops(Z_AXIS _EXT_ARGS); #endif #endif #if NONE(TOOLCHANGE_ZRAISE_BEFORE_RETRACT, HAS_SWITCHING_NOZZLE) if (can_move_away && TERN1(TOOLCHANGE_PARK, toolchange_settings.enable_park)) { // Do a small lift to avoid the workpiece in the move back (below) - current_position.z += toolchange_settings.z_raise; - TERN_(HAS_SOFTWARE_ENDSTOPS, NOMORE(current_position.z, soft_endstop.max.z)); + motion.position.z += toolchange_settings.z_raise; + TERN_(HAS_SOFTWARE_ENDSTOPS, NOMORE(motion.position.z, motion.soft_endstop.max.z)); fast_line_to_current(Z_AXIS); } #endif @@ -1252,19 +1249,19 @@ void tool_change(const uint8_t new_tool, bool no_move/*=false*/) { // Toolchange park #if ENABLED(TOOLCHANGE_PARK) && !HAS_SWITCHING_NOZZLE if (can_move_away && toolchange_settings.enable_park) { - IF_DISABLED(TOOLCHANGE_PARK_Y_ONLY, current_position.x = toolchange_settings.change_point.x); - IF_DISABLED(TOOLCHANGE_PARK_X_ONLY, current_position.y = toolchange_settings.change_point.y); + IF_DISABLED(TOOLCHANGE_PARK_Y_ONLY, motion.position.x = toolchange_settings.change_point.x); + IF_DISABLED(TOOLCHANGE_PARK_X_ONLY, motion.position.y = toolchange_settings.change_point.y); #if NONE(TOOLCHANGE_PARK_X_ONLY, TOOLCHANGE_PARK_Y_ONLY) SECONDARY_AXIS_CODE( - current_position.i = toolchange_settings.change_point.i, - current_position.j = toolchange_settings.change_point.j, - current_position.k = toolchange_settings.change_point.k, - current_position.u = toolchange_settings.change_point.u, - current_position.v = toolchange_settings.change_point.v, - current_position.w = toolchange_settings.change_point.w + motion.position.i = toolchange_settings.change_point.i, + motion.position.j = toolchange_settings.change_point.j, + motion.position.k = toolchange_settings.change_point.k, + motion.position.u = toolchange_settings.change_point.u, + motion.position.v = toolchange_settings.change_point.v, + motion.position.w = toolchange_settings.change_point.w ); #endif - planner.buffer_line(current_position, MMM_TO_MMS(TOOLCHANGE_PARK_XY_FEEDRATE), old_tool); + planner.buffer_line(motion.position, MMM_TO_MMS(TOOLCHANGE_PARK_XY_FEEDRATE), old_tool); planner.synchronize(); } #endif @@ -1293,11 +1290,11 @@ void tool_change(const uint8_t new_tool, bool no_move/*=false*/) { // SWITCHING_NOZZLE_TWO_SERVOS, as both nozzles will lift instead. TERN_(SWITCHING_NOZZLE_TWO_SERVOS, raise_nozzle(old_tool)); if (!no_move) { - const float newz = current_position.z + _MAX(-diff.z, 0.0); + const float newz = motion.position.z + _MAX(-diff.z, 0.0); // Check if Z has space to compensate at least z_offset, and if not, just abort now - const float maxz = _MIN(TERN(HAS_SOFTWARE_ENDSTOPS, soft_endstop.max.z, Z_MAX_POS), Z_MAX_POS); + const float maxz = _MIN(TERN(HAS_SOFTWARE_ENDSTOPS, motion.soft_endstop.max.z, Z_MAX_POS), Z_MAX_POS); if (newz > maxz) return; - current_position.z = _MIN(newz + toolchange_settings.z_raise, maxz); + motion.position.z = _MIN(newz + toolchange_settings.z_raise, maxz); fast_line_to_current(Z_AXIS); } #if SWITCHING_NOZZLE_TWO_SERVOS // Switching Nozzle with two servos @@ -1307,27 +1304,27 @@ void tool_change(const uint8_t new_tool, bool no_move/*=false*/) { #endif #elif ANY(MECHANICAL_SWITCHING_EXTRUDER, MECHANICAL_SWITCHING_NOZZLE) if (!no_move) { - current_position.z = _MIN(current_position.z + toolchange_settings.z_raise, _MIN(TERN(HAS_SOFTWARE_ENDSTOPS, soft_endstop.max.z, Z_MAX_POS), Z_MAX_POS)); + motion.position.z = _MIN(motion.position.z + toolchange_settings.z_raise, _MIN(TERN(HAS_SOFTWARE_ENDSTOPS, motion.soft_endstop.max.z, Z_MAX_POS), Z_MAX_POS)); fast_line_to_current(Z_AXIS); } #endif - IF_DISABLED(DUAL_X_CARRIAGE, active_extruder = new_tool); // Set the new active extruder + IF_DISABLED(DUAL_X_CARRIAGE, motion.extruder = new_tool); // Set the new active extruder TERN_(TOOL_SENSOR, tool_sensor_disabled = false); - (void)check_tool_sensor_stats(active_extruder, true); + (void)check_tool_sensor_stats(motion.extruder, true); // The newly-selected extruder XYZ is actually at... DEBUG_ECHOLNPGM("Offset Tool XYZ by { ", diff.x, ", ", diff.y, ", ", diff.z, " }"); - current_position += diff; + motion.position += diff; // Tell the planner the new "current position" - sync_plan_position(); + motion.sync_plan_position(); #if ENABLED(DELTA) - //LOOP_NUM_AXES(i) update_software_endstops(i); // or modify the constrain function - const bool safe_to_move = current_position.z < delta_clip_start_height - 1; + //LOOP_NUM_AXES(i) motion.update_software_endstops(i); // or modify the constrain function + const bool safe_to_move = motion.position.z < delta_clip_start_height - 1; #else constexpr bool safe_to_move = true; #endif @@ -1341,20 +1338,20 @@ void tool_change(const uint8_t new_tool, bool no_move/*=false*/) { #endif #if ENABLED(TOOLCHANGE_FILAMENT_SWAP) - if (should_swap && !too_cold(active_extruder)) + if (should_swap && !too_cold(motion.extruder)) extruder_prime(); // Prime selected Extruder #endif // Prevent a move outside physical bounds #if ENABLED(MAGNETIC_SWITCHING_TOOLHEAD) // If the original position is within tool store area, go to X origin at once - if (destination.y < SWITCHING_TOOLHEAD_Y_POS + SWITCHING_TOOLHEAD_Y_CLEAR) { - current_position.x = X_MIN_POS; - planner.buffer_line(current_position, planner.settings.max_feedrate_mm_s[X_AXIS], new_tool); + if (motion.destination.y < SWITCHING_TOOLHEAD_Y_POS + SWITCHING_TOOLHEAD_Y_CLEAR) { + motion.position.x = X_MIN_POS; + planner.buffer_line(motion.position, planner.settings.max_feedrate_mm_s[X_AXIS], new_tool); planner.synchronize(); } #else - apply_motion_limits(destination); + motion.apply_limits(motion.destination); #endif // Should the nozzle move back to the old position? @@ -1364,27 +1361,27 @@ void tool_change(const uint8_t new_tool, bool no_move/*=false*/) { DEBUG_ECHOLNPGM("Move back Z only"); if (TERN1(TOOLCHANGE_PARK, toolchange_settings.enable_park)) - do_blocking_move_to_z(destination.z, planner.settings.max_feedrate_mm_s[Z_AXIS]); + motion.blocking_move_z(motion.destination.z, planner.settings.max_feedrate_mm_s[Z_AXIS]); #else // Move back to the original (or adjusted) position - DEBUG_POS("Move back", destination); + DEBUG_POS("Move back", motion.destination); #if ENABLED(TOOLCHANGE_PARK) - if (toolchange_settings.enable_park) do_blocking_move_to_xy_z(destination, destination.z, MMM_TO_MMS(TOOLCHANGE_PARK_XY_FEEDRATE)); + if (toolchange_settings.enable_park) motion.blocking_move_xy_z(motion.destination, motion.destination.z, MMM_TO_MMS(TOOLCHANGE_PARK_XY_FEEDRATE)); #else - do_blocking_move_to_xy(destination, planner.settings.max_feedrate_mm_s[X_AXIS]* 0.5f); + motion.blocking_move_xy(motion.destination, planner.settings.max_feedrate_mm_s[X_AXIS]* 0.5f); // If using MECHANICAL_SWITCHING extruder/nozzle, set HOTEND_OFFSET in Z axis after running EVENT_GCODE_TOOLCHANGE below. #if NONE(MECHANICAL_SWITCHING_EXTRUDER, MECHANICAL_SWITCHING_NOZZLE) - do_blocking_move_to_z(destination.z, planner.settings.max_feedrate_mm_s[Z_AXIS]); + motion.blocking_move_z(motion.destination.z, planner.settings.max_feedrate_mm_s[Z_AXIS]); SECONDARY_AXIS_CODE( - do_blocking_move_to_i(destination.i, planner.settings.max_feedrate_mm_s[I_AXIS]), - do_blocking_move_to_j(destination.j, planner.settings.max_feedrate_mm_s[J_AXIS]), - do_blocking_move_to_k(destination.k, planner.settings.max_feedrate_mm_s[K_AXIS]), - do_blocking_move_to_u(destination.u, planner.settings.max_feedrate_mm_s[U_AXIS]), - do_blocking_move_to_v(destination.v, planner.settings.max_feedrate_mm_s[V_AXIS]), - do_blocking_move_to_w(destination.w, planner.settings.max_feedrate_mm_s[W_AXIS]) + motion.blocking_move_i(motion.destination.i, planner.settings.max_feedrate_mm_s[I_AXIS]), + motion.blocking_move_j(motion.destination.j, planner.settings.max_feedrate_mm_s[J_AXIS]), + motion.blocking_move_k(motion.destination.k, planner.settings.max_feedrate_mm_s[K_AXIS]), + motion.blocking_move_u(motion.destination.u, planner.settings.max_feedrate_mm_s[U_AXIS]), + motion.blocking_move_v(motion.destination.v, planner.settings.max_feedrate_mm_s[V_AXIS]), + motion.blocking_move_w(motion.destination.w, planner.settings.max_feedrate_mm_s[W_AXIS]) ); #endif #endif @@ -1395,7 +1392,7 @@ void tool_change(const uint8_t new_tool, bool no_move/*=false*/) { else DEBUG_ECHOLNPGM("Move back skipped"); #if ENABLED(TOOLCHANGE_FILAMENT_SWAP) - if (should_swap && !too_cold(active_extruder)) { + if (should_swap && !too_cold(motion.extruder)) { extruder_cutting_recover(0); // New extruder primed and set to 0 // Restart Fan @@ -1411,7 +1408,7 @@ void tool_change(const uint8_t new_tool, bool no_move/*=false*/) { #if HAS_SWITCHING_NOZZLE // Move back down. (Including when the new tool is higher.) if (!should_move) - do_blocking_move_to_z(destination.z, planner.settings.max_feedrate_mm_s[Z_AXIS]); + motion.blocking_move_z(motion.destination.z, planner.settings.max_feedrate_mm_s[Z_AXIS]); #endif } // (new_tool != old_tool) @@ -1426,7 +1423,7 @@ void tool_change(const uint8_t new_tool, bool no_move/*=false*/) { #if ENABLED(EXT_SOLENOID) && DISABLED(PARKING_EXTRUDER) disable_all_solenoids(); - enable_solenoid(active_extruder); + enable_solenoid(motion.extruder); #endif #if HAS_PRUSA_MMU1 @@ -1436,10 +1433,10 @@ void tool_change(const uint8_t new_tool, bool no_move/*=false*/) { #if DO_SWITCH_EXTRUDER planner.synchronize(); - move_extruder_servo(active_extruder); + move_extruder_servo(motion.extruder); #endif - TERN_(HAS_FANMUX, fanmux_switch(active_extruder)); + TERN_(HAS_FANMUX, fanmux_switch(motion.extruder)); if (ENABLED(EVENT_GCODE_TOOLCHANGE_ALWAYS_RUN) || !no_move) { @@ -1448,11 +1445,11 @@ void tool_change(const uint8_t new_tool, bool no_move/*=false*/) { // Shift the workspace to make custom moves relative to T0. xyz_pos_t old_workspace_offset; if (new_tool > 0) { - old_workspace_offset = workspace_offset; + old_workspace_offset = motion.workspace_offset; const xyz_pos_t &he = hotend_offset[new_tool]; - TERN_(TC_GCODE_USE_GLOBAL_X, workspace_offset.x -= he.x); - TERN_(TC_GCODE_USE_GLOBAL_Y, workspace_offset.y -= he.y); - TERN_(TC_GCODE_USE_GLOBAL_Z, workspace_offset.z -= he.z); + TERN_(TC_GCODE_USE_GLOBAL_X, motion.workspace_offset.x -= he.x); + TERN_(TC_GCODE_USE_GLOBAL_Y, motion.workspace_offset.y -= he.y); + TERN_(TC_GCODE_USE_GLOBAL_Z, motion.workspace_offset.z -= he.z); } #endif @@ -1485,7 +1482,7 @@ void tool_change(const uint8_t new_tool, bool no_move/*=false*/) { } #if ANY(TC_GCODE_USE_GLOBAL_X, TC_GCODE_USE_GLOBAL_Y, TC_GCODE_USE_GLOBAL_Z) - if (new_tool > 0) workspace_offset = old_workspace_offset; + if (new_tool > 0) motion.workspace_offset = old_workspace_offset; #endif // If using MECHANICAL_SWITCHING extruder/nozzle, set HOTEND_OFFSET in Z axis after running EVENT_GCODE_TOOLCHANGE @@ -1500,12 +1497,12 @@ void tool_change(const uint8_t new_tool, bool no_move/*=false*/) { if (!no_move) { // Move to new hotend Z offset and reverse Z_RAISE - do_blocking_move_to_z( + motion.blocking_move_z( _MIN( - _MAX((destination.z - diff.z) - toolchange_settings.z_raise, - _MAX(TERN(HAS_SOFTWARE_ENDSTOPS, soft_endstop.min.z, Z_MIN_POS), Z_MIN_POS) + _MAX((motion.destination.z - diff.z) - toolchange_settings.z_raise, + _MAX(TERN(HAS_SOFTWARE_ENDSTOPS, motion.soft_endstop.min.z, Z_MIN_POS), Z_MIN_POS) ), - _MIN(TERN(HAS_SOFTWARE_ENDSTOPS, soft_endstop.max.z, Z_MAX_POS), Z_MAX_POS)), + _MIN(TERN(HAS_SOFTWARE_ENDSTOPS, motion.soft_endstop.max.z, Z_MAX_POS), Z_MAX_POS)), planner.settings.max_feedrate_mm_s[Z_AXIS] ); } @@ -1518,7 +1515,7 @@ void tool_change(const uint8_t new_tool, bool no_move/*=false*/) { } // !no_move - SERIAL_ECHOLNPGM(STR_ACTIVE_EXTRUDER, active_extruder); + SERIAL_ECHOLNPGM(STR_ACTIVE_EXTRUDER, motion.extruder); #endif // HAS_MULTI_EXTRUDER } @@ -1530,33 +1527,33 @@ void tool_change(const uint8_t new_tool, bool no_move/*=false*/) { bool extruder_migration() { - if (thermalManager.targetTooColdToExtrude(active_extruder)) { + if (thermalManager.targetTooColdToExtrude(motion.extruder)) { DEBUG_ECHOLNPGM("Migration Source Too Cold"); return false; } // No auto-migration or specified target? - if (!migration.target && active_extruder >= migration.last) { + if (!migration.target && motion.extruder >= migration.last) { DEBUG_ECHO_MSG("No Migration Target"); - DEBUG_ECHO_MSG("Target: ", migration.target, " Last: ", migration.last, " Active: ", active_extruder); + DEBUG_ECHO_MSG("Target: ", migration.target, " Last: ", migration.last, " Active: ", motion.extruder); migration.automode = false; return false; } // Migrate to a target or the next extruder - uint8_t migration_extruder = active_extruder; + uint8_t migration_extruder = motion.extruder; if (migration.target) { DEBUG_ECHOLNPGM("Migration using fixed target"); // Specified target ok? const int16_t t = migration.target - 1; - if (t != active_extruder) migration_extruder = t; + if (t != motion.extruder) migration_extruder = t; } else if (migration.automode && migration_extruder < migration.last && migration_extruder < EXTRUDERS - 1) migration_extruder++; - if (migration_extruder == active_extruder) { + if (migration_extruder == motion.extruder) { DEBUG_ECHOLNPGM("Migration source matches active"); return false; } @@ -1568,26 +1565,26 @@ void tool_change(const uint8_t new_tool, bool no_move/*=false*/) { planner.synchronize(); // Remember position before migration - const float resume_current_e = current_position.e; + const float resume_current_e = motion.position.e; // Migrate the flow - planner.set_flow(migration_extruder, planner.flow_percentage[active_extruder]); + planner.set_flow(migration_extruder, planner.flow_percentage[motion.extruder]); // Migrate the retracted state #if ENABLED(FWRETRACT) - fwretract.retracted.set(migration_extruder, fwretract.retracted[active_extruder]); + fwretract.retracted.set(migration_extruder, fwretract.retracted[motion.extruder]); #endif // Migrate the temperature to the new hotend #if HAS_MULTI_HOTEND - thermalManager.setTargetHotend(thermalManager.degTargetHotend(active_extruder), migration_extruder); + thermalManager.setTargetHotend(thermalManager.degTargetHotend(motion.extruder), migration_extruder); TERN_(AUTOTEMP, thermalManager.autotemp_update()); thermalManager.set_heating_message(0); - thermalManager.wait_for_hotend(active_extruder); + thermalManager.wait_for_hotend(motion.extruder); #endif // Migrate Linear Advance K factor to the new extruder - TERN_(HAS_LIN_ADVANCE_K, planner.set_advance_k(planner.get_advance_k(migration_extruder), active_extruder)); + TERN_(HAS_LIN_ADVANCE_K, planner.set_advance_k(planner.get_advance_k(migration_extruder), motion.extruder)); // Temporary migration toolchange_settings restored on exit. i.e., before next tool_change(). #if defined(MIGRATION_FS_EXTRA_PRIME) \ @@ -1622,23 +1619,23 @@ void tool_change(const uint8_t new_tool, bool no_move/*=false*/) { // Retract if previously retracted #if ENABLED(FWRETRACT) - if (fwretract.retracted[active_extruder]) - unscaled_e_move(-fwretract.settings.retract_length, fwretract.settings.retract_feedrate_mm_s); + if (fwretract.retracted[motion.extruder]) + motion.unscaled_e_move(-fwretract.settings.retract_length, fwretract.settings.retract_feedrate_mm_s); #endif // If resume_position is negative - if (resume_current_e < 0) unscaled_e_move(resume_current_e, MMM_TO_MMS(toolchange_settings.retract_speed)); + if (resume_current_e < 0) motion.unscaled_e_move(resume_current_e, MMM_TO_MMS(toolchange_settings.retract_speed)); // If no available extruder - if (EXTRUDERS < 2 || active_extruder >= EXTRUDERS - 2 || active_extruder == migration.last) + if (EXTRUDERS < 2 || motion.extruder >= EXTRUDERS - 2 || motion.extruder == migration.last) migration.automode = false; migration.in_progress = false; - current_position.e = resume_current_e; + motion.position.e = resume_current_e; planner.synchronize(); - planner.set_e_position_mm(current_position.e); // New extruder primed and ready + planner.set_e_position_mm(motion.position.e); // New extruder primed and ready DEBUG_ECHOLNPGM("Migration Complete"); return true;