Skip to content

♻️ Motion encapsulation #27866

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: bugfix-2.1.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions .github/workflows/ci-build-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -208,13 +208,6 @@ jobs:
sudo apt-get install libsdl2-net-dev
sudo apt-get install libglm-dev

- name: Checkout Configurations
uses: actions/checkout@v4
with:
repository: MarlinFirmware/Configurations
ref: ${{ env.CONFIG_BRANCH }}
path: ConfigurationsRepo

- name: Run ${{ matrix.test-platform }} Tests
run: |
make tests-single-ci TEST_TARGET=${{ matrix.test-platform }}
8 changes: 4 additions & 4 deletions Marlin/src/HAL/STM32F1/eeprom/eeprom_flash.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,14 @@ static uint8_t ram_eeprom[MARLIN_EEPROM_SIZE] __attribute__((aligned(4))) = {0};
static bool eeprom_dirty = false;

bool PersistentStore::access_start() {
const uint32_t *source = reinterpret_cast<const uint32_t*>(EEPROM_PAGE0_BASE);
uint32_t *destination = reinterpret_cast<uint32_t*>(ram_eeprom);
const uint32_t *src = reinterpret_cast<const uint32_t*>(EEPROM_PAGE0_BASE);
uint32_t *dst = reinterpret_cast<uint32_t*>(ram_eeprom);

static_assert(0 == (MARLIN_EEPROM_SIZE) % 4, "MARLIN_EEPROM_SIZE is corrupted. (Must be a multiple of 4.)"); // Ensure copying as uint32_t is safe
constexpr size_t eeprom_size_u32 = (MARLIN_EEPROM_SIZE) / 4;

for (size_t i = 0; i < eeprom_size_u32; ++i, ++destination, ++source)
*destination = *source;
for (size_t i = 0; i < eeprom_size_u32; ++i, ++dst, ++src)
*dst = *src;

eeprom_dirty = false;
return true;
Expand Down
28 changes: 14 additions & 14 deletions Marlin/src/MarlinCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ void 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());
}
Expand All @@ -375,7 +375,7 @@ void startOrResumeJob() {
card.abortFilePrintNow(TERN_(SD_RESORT, true));

queue.clear();
quickstop_stepper();
motion.quickstop_stepper();

print_job_timer.abort();

Expand Down Expand Up @@ -686,18 +686,18 @@ inline void 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 >> 1, 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.line_to_current_position(MMM_TO_MMS(EXTRUDER_RUNOUT_SPEED));
motion.position.e = olde;
planner.set_e_position_mm(olde);
planner.synchronize();

Expand All @@ -712,8 +712,8 @@ inline void 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 = 0xFFFFFFFFUL; // force moves to be done
destination = current_position;
prepare_line_to_destination();
motion.destination = motion.position;
motion.prepare_line_to_destination();
planner.synchronize();
}
#endif
Expand Down Expand Up @@ -792,7 +792,7 @@ void idle(const bool no_stepper_sleep/*=false*/) {
if (marlin_state == MarlinState::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
Expand Down Expand Up @@ -856,7 +856,7 @@ void 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
Expand Down Expand Up @@ -1385,9 +1385,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

Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/core/debug_section.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,6 @@ class SectionLog {
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));
}
};
2 changes: 1 addition & 1 deletion Marlin/src/core/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ typedef ab_float_t ab_pos_t;
typedef abc_float_t abc_pos_t;
typedef abce_float_t abce_pos_t;

// External conversion methods
// External conversion methods (motion.h)
void toLogical(xy_pos_t &raw);
void toLogical(xyz_pos_t &raw);
void toLogical(xyze_pos_t &raw);
Expand Down
10 changes: 5 additions & 5 deletions Marlin/src/core/utility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,19 +143,19 @@ void safe_delay(millis_t ms) {
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)
SERIAL_ECHOPGM("UBL Adjustment Z");
#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
}
Expand All @@ -170,11 +170,11 @@ void safe_delay(millis_t ms) {
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
}
Expand Down
8 changes: 4 additions & 4 deletions Marlin/src/feature/babystep.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

#include "babystep.h"
#include "../MarlinCore.h"
#include "../module/motion.h" // for axes_should_home(), BABYSTEP_ALLOWED
#include "../module/motion.h" // for axis_should_home(), BABYSTEP_ALLOWED
#include "../module/planner.h" // for axis_steps_per_mm[]
#include "../module/stepper.h"

Expand All @@ -49,7 +49,7 @@ int16_t Babystep::accum;
void Babystep::step_axis(const AxisEnum axis) {
const int16_t curTodo = steps[BS_AXIS_IND(axis)]; // get rid of volatile for performance
if (curTodo) {
stepper.do_babystep((AxisEnum)axis, curTodo > 0);
stepper.do_babystep(axis, curTodo > 0);
if (curTodo > 0) steps[BS_AXIS_IND(axis)]--; else steps[BS_AXIS_IND(axis)]++;
}
}
Expand All @@ -60,7 +60,7 @@ void Babystep::add_mm(const AxisEnum axis, const_float_t mm) {

#if ENABLED(BD_SENSOR)
void Babystep::set_mm(const AxisEnum axis, const_float_t 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;
Expand All @@ -71,7 +71,7 @@ void Babystep::add_mm(const AxisEnum axis, const_float_t 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) {
Expand Down
12 changes: 6 additions & 6 deletions Marlin/src/feature/backlash.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,11 +187,11 @@ class Backlash::StepAdjuster {
xyz_long_t applied_steps;
public:
StepAdjuster() {
LOOP_NUM_AXES(axis) applied_steps[axis] = backlash.get_applied_steps((AxisEnum)axis);
LOOP_NUM_AXES(axis) applied_steps[axis] = backlash.get_applied_steps(AxisEnum(axis));
}
~StepAdjuster() {
// after backlash compensation parameter changes, ensure applied step count does not change
LOOP_NUM_AXES(axis) residual_error[axis] += backlash.get_applied_steps((AxisEnum)axis) - applied_steps[axis];
LOOP_NUM_AXES(axis) residual_error[axis] += backlash.get_applied_steps(AxisEnum(axis)) - applied_steps[axis];
}
};

Expand Down Expand Up @@ -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++;
}

Expand Down
36 changes: 18 additions & 18 deletions Marlin/src/feature/bedlevel/abl/bbl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -371,21 +371,21 @@ 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);
LIMIT(c2.y, 0, ABL_BG_POINTS_Y - 2);

// 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.line_to_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;
Expand All @@ -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.line_to_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);
}

Expand Down
Loading