Skip to content

Commit 2774073

Browse files
committed
♻️ Motion encapsulation
1 parent ade6dbf commit 2774073

File tree

182 files changed

+2568
-2641
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

182 files changed

+2568
-2641
lines changed

Marlin/src/HAL/STM32F1/eeprom/eeprom_flash.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,14 @@ static uint8_t ram_eeprom[MARLIN_EEPROM_SIZE] __attribute__((aligned(4))) = {0};
4747
static bool eeprom_dirty = false;
4848

4949
bool PersistentStore::access_start() {
50-
const uint32_t *source = reinterpret_cast<const uint32_t*>(EEPROM_PAGE0_BASE);
51-
uint32_t *destination = reinterpret_cast<uint32_t*>(ram_eeprom);
50+
const uint32_t *src = reinterpret_cast<const uint32_t*>(EEPROM_PAGE0_BASE);
51+
uint32_t *dst = reinterpret_cast<uint32_t*>(ram_eeprom);
5252

5353
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
5454
constexpr size_t eeprom_size_u32 = (MARLIN_EEPROM_SIZE) / 4;
5555

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

5959
eeprom_dirty = false;
6060
return true;

Marlin/src/MarlinCore.cpp

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ void startOrResumeJob() {
361361
if (!printingIsPaused()) {
362362
TERN_(GCODE_REPEAT_MARKERS, repeat.reset());
363363
TERN_(CANCEL_OBJECTS, cancelable.reset());
364-
TERN_(LCD_SHOW_E_TOTAL, e_move_accumulator = 0);
364+
TERN_(LCD_SHOW_E_TOTAL, motion.e_move_accumulator = 0);
365365
TERN_(SET_REMAINING_TIME, ui.reset_remaining_time());
366366
TERN_(HAS_PRUSA_MMU3, MMU3::operation_statistics.reset_per_print_stats());
367367
}
@@ -375,7 +375,7 @@ void startOrResumeJob() {
375375
card.abortFilePrintNow(TERN_(SD_RESORT, true));
376376

377377
queue.clear();
378-
quickstop_stepper();
378+
motion.quickstop_stepper();
379379

380380
print_job_timer.abort();
381381

@@ -686,18 +686,18 @@ inline void manage_inactivity(const bool no_stepper_sleep=false) {
686686
#endif
687687

688688
#if ENABLED(EXTRUDER_RUNOUT_PREVENT)
689-
if (thermalManager.degHotend(active_extruder) > (EXTRUDER_RUNOUT_MINTEMP)
689+
if (thermalManager.degHotend(motion.extruder) > (EXTRUDER_RUNOUT_MINTEMP)
690690
&& ELAPSED(ms, gcode.previous_move_ms, SEC_TO_MS(EXTRUDER_RUNOUT_SECONDS))
691691
&& !planner.has_blocks_queued()
692692
) {
693-
const int8_t e_stepper = TERN(HAS_SWITCHING_EXTRUDER, active_extruder >> 1, active_extruder);
693+
const int8_t e_stepper = TERN(HAS_SWITCHING_EXTRUDER, motion.extruder >> 1, motion.extruder);
694694
const bool e_off = !stepper.AXIS_IS_ENABLED(E_AXIS, e_stepper);
695695
if (e_off) stepper.ENABLE_EXTRUDER(e_stepper);
696696

697-
const float olde = current_position.e;
698-
current_position.e += EXTRUDER_RUNOUT_EXTRUDE;
699-
line_to_current_position(MMM_TO_MMS(EXTRUDER_RUNOUT_SPEED));
700-
current_position.e = olde;
697+
const float olde = motion.position.e;
698+
motion.position.e += EXTRUDER_RUNOUT_EXTRUDE;
699+
motion.line_to_current_position(MMM_TO_MMS(EXTRUDER_RUNOUT_SPEED));
700+
motion.position.e = olde;
701701
planner.set_e_position_mm(olde);
702702
planner.synchronize();
703703

@@ -712,8 +712,8 @@ inline void manage_inactivity(const bool no_stepper_sleep=false) {
712712
if (delayed_move_time && ELAPSED(ms, delayed_move_time) && IsRunning()) {
713713
// travel moves have been received so enact them
714714
delayed_move_time = 0xFFFFFFFFUL; // force moves to be done
715-
destination = current_position;
716-
prepare_line_to_destination();
715+
motion.destination = motion.position;
716+
motion.prepare_line_to_destination();
717717
planner.synchronize();
718718
}
719719
#endif
@@ -792,7 +792,7 @@ void idle(const bool no_stepper_sleep/*=false*/) {
792792
if (marlin_state == MarlinState::MF_INITIALIZING) goto IDLE_DONE;
793793

794794
// TODO: Still causing errors
795-
TERN_(TOOL_SENSOR, (void)check_tool_sensor_stats(active_extruder, true));
795+
TERN_(TOOL_SENSOR, (void)check_tool_sensor_stats(motion.extruder, true));
796796

797797
// Handle filament runout sensors
798798
#if HAS_FILAMENT_SENSOR
@@ -856,7 +856,7 @@ void idle(const bool no_stepper_sleep/*=false*/) {
856856
TERN_(AUTO_REPORT_TEMPERATURES, thermalManager.auto_reporter.tick());
857857
TERN_(AUTO_REPORT_FANS, fan_check.auto_reporter.tick());
858858
TERN_(AUTO_REPORT_SD_STATUS, card.auto_reporter.tick());
859-
TERN_(AUTO_REPORT_POSITION, position_auto_reporter.tick());
859+
TERN_(AUTO_REPORT_POSITION, motion.position_auto_reporter.tick());
860860
TERN_(BUFFER_MONITORING, queue.auto_report_buffer_statistics());
861861
}
862862
#endif
@@ -1385,9 +1385,9 @@ void setup() {
13851385
SETUP_RUN(touchBt.init());
13861386
#endif
13871387

1388-
TERN_(HAS_HOME_OFFSET, current_position += home_offset); // Init current position based on home_offset
1388+
TERN_(HAS_HOME_OFFSET, motion.position += home_offset); // Init current position based on home_offset
13891389

1390-
sync_plan_position(); // Vital to init stepper/planner equivalent for current_position
1390+
motion.sync_plan_position(); // Vital to init stepper/planner equivalent for motion.position
13911391

13921392
SETUP_RUN(thermalManager.init()); // Initialize temperature loop
13931393

Marlin/src/core/debug_section.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,6 @@ class SectionLog {
4141
SERIAL_ECHO(fpre);
4242
if (the_msg) SERIAL_ECHO(C(' '), the_msg);
4343
SERIAL_CHAR(' ');
44-
print_xyz(xyz_pos_t(current_position));
44+
print_xyz(xyz_pos_t(motion.position));
4545
}
4646
};

Marlin/src/core/types.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,7 @@ typedef ab_float_t ab_pos_t;
485485
typedef abc_float_t abc_pos_t;
486486
typedef abce_float_t abce_pos_t;
487487

488-
// External conversion methods
488+
// External conversion methods (motion.h)
489489
void toLogical(xy_pos_t &raw);
490490
void toLogical(xyz_pos_t &raw);
491491
void toLogical(xyze_pos_t &raw);

Marlin/src/core/utility.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -143,19 +143,19 @@ void safe_delay(millis_t ms) {
143143
SERIAL_ECHOPGM("ABL Adjustment");
144144
LOOP_NUM_AXES(a) {
145145
SERIAL_ECHOPGM_P((PGM_P)pgm_read_ptr(&SP_AXIS_STR[a]));
146-
serial_offset(planner.get_axis_position_mm(AxisEnum(a)) - current_position[a]);
146+
serial_offset(planner.get_axis_position_mm(AxisEnum(a)) - motion.position[a]);
147147
}
148148
#else
149149
#if ENABLED(AUTO_BED_LEVELING_UBL)
150150
SERIAL_ECHOPGM("UBL Adjustment Z");
151151
#elif ENABLED(AUTO_BED_LEVELING_BILINEAR)
152152
SERIAL_ECHOPGM("ABL Adjustment Z");
153153
#endif
154-
const float rz = bedlevel.get_z_correction(current_position);
154+
const float rz = bedlevel.get_z_correction(motion.position);
155155
SERIAL_ECHO(ftostr43sign(rz, '+'));
156156
#if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
157157
if (planner.z_fade_height)
158-
SERIAL_ECHO(F(" ("), ftostr43sign(rz * planner.fade_scaling_factor_for_z(current_position.z), '+'), C(')'));
158+
SERIAL_ECHO(F(" ("), ftostr43sign(rz * planner.fade_scaling_factor_for_z(motion.position.z), '+'), C(')'));
159159
#endif
160160
#endif
161161
}
@@ -170,11 +170,11 @@ void safe_delay(millis_t ms) {
170170
if (planner.leveling_active) {
171171
SERIAL_ECHOLNPGM(" (enabled)");
172172
const float z_offset = bedlevel.get_z_offset(),
173-
z_correction = bedlevel.get_z_correction(current_position);
173+
z_correction = bedlevel.get_z_correction(motion.position);
174174
SERIAL_ECHOPGM("MBL Adjustment Z", ftostr43sign(z_offset + z_correction, '+'));
175175
#if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
176176
if (planner.z_fade_height) {
177-
SERIAL_ECHO(F(" ("), ftostr43sign(z_offset + z_correction * planner.fade_scaling_factor_for_z(current_position.z), '+'), C(')'));
177+
SERIAL_ECHO(F(" ("), ftostr43sign(z_offset + z_correction * planner.fade_scaling_factor_for_z(motion.position.z), '+'), C(')'));
178178
}
179179
#endif
180180
}

Marlin/src/feature/babystep.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727
#include "babystep.h"
2828
#include "../MarlinCore.h"
29-
#include "../module/motion.h" // for axes_should_home(), BABYSTEP_ALLOWED
29+
#include "../module/motion.h" // for axis_should_home(), BABYSTEP_ALLOWED
3030
#include "../module/planner.h" // for axis_steps_per_mm[]
3131
#include "../module/stepper.h"
3232

@@ -60,7 +60,7 @@ void Babystep::add_mm(const AxisEnum axis, const_float_t mm) {
6060

6161
#if ENABLED(BD_SENSOR)
6262
void Babystep::set_mm(const AxisEnum axis, const_float_t mm) {
63-
//if (DISABLED(BABYSTEP_WITHOUT_HOMING) && axis_should_home(axis)) return;
63+
//if (DISABLED(BABYSTEP_WITHOUT_HOMING) && motion.axis_should_home(axis)) return;
6464
const int16_t distance = mm * planner.settings.axis_steps_per_mm[axis];
6565
accum = distance; // Count up babysteps for the UI
6666
steps[BS_AXIS_IND(axis)] = distance;
@@ -71,7 +71,7 @@ void Babystep::add_mm(const AxisEnum axis, const_float_t mm) {
7171
#endif
7272

7373
bool Babystep::can_babystep(const AxisEnum axis) {
74-
return (ENABLED(BABYSTEP_WITHOUT_HOMING) || !axis_should_home(axis));
74+
return (ENABLED(BABYSTEP_WITHOUT_HOMING) || !motion.axis_should_home(axis));
7575
}
7676

7777
void Babystep::add_steps(const AxisEnum axis, const int16_t distance) {

Marlin/src/feature/backlash.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -224,12 +224,12 @@ class Backlash::StepAdjuster {
224224
void Backlash::measure_with_probe() {
225225
if (measured_count.z == 255) return;
226226

227-
const float start_height = current_position.z;
228-
while (current_position.z < (start_height + BACKLASH_MEASUREMENT_LIMIT) && PROBE_TRIGGERED())
229-
do_blocking_move_to_z(current_position.z + BACKLASH_MEASUREMENT_RESOLUTION, MMM_TO_MMS(BACKLASH_MEASUREMENT_FEEDRATE));
227+
const float start_height = motion.position.z;
228+
while (motion.position.z < (start_height + BACKLASH_MEASUREMENT_LIMIT) && PROBE_TRIGGERED())
229+
motion.blocking_move_z(motion.position.z + BACKLASH_MEASUREMENT_RESOLUTION, MMM_TO_MMS(BACKLASH_MEASUREMENT_FEEDRATE));
230230

231231
// The backlash from all probe points is averaged, so count the number of measurements
232-
measured_mm.z += current_position.z - start_height;
232+
measured_mm.z += motion.position.z - start_height;
233233
measured_count.z++;
234234
}
235235

Marlin/src/feature/bedlevel/abl/bbl.cpp

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -371,21 +371,21 @@ float LevelingBilinear::get_z_correction(const xy_pos_t &raw) {
371371
*/
372372
void LevelingBilinear::line_to_destination(const_feedRate_t scaled_fr_mm_s, uint16_t x_splits, uint16_t y_splits) {
373373
// Get current and destination cells for this line
374-
xy_int_t c1 { CELL_INDEX(x, current_position.x), CELL_INDEX(y, current_position.y) },
375-
c2 { CELL_INDEX(x, destination.x), CELL_INDEX(y, destination.y) };
374+
xy_int_t c1 { CELL_INDEX(x, motion.position.x), CELL_INDEX(y, motion.position.y) },
375+
c2 { CELL_INDEX(x, motion.destination.x), CELL_INDEX(y, motion.destination.y) };
376376
LIMIT(c1.x, 0, ABL_BG_POINTS_X - 2);
377377
LIMIT(c1.y, 0, ABL_BG_POINTS_Y - 2);
378378
LIMIT(c2.x, 0, ABL_BG_POINTS_X - 2);
379379
LIMIT(c2.y, 0, ABL_BG_POINTS_Y - 2);
380380

381381
// Start and end in the same cell? No split needed.
382382
if (c1 == c2) {
383-
current_position = destination;
384-
line_to_current_position(scaled_fr_mm_s);
383+
motion.position = motion.destination;
384+
motion.line_to_current_position(scaled_fr_mm_s);
385385
return;
386386
}
387387

388-
#define LINE_SEGMENT_END(A) (current_position.A + (destination.A - current_position.A) * normalized_dist)
388+
#define LINE_SEGMENT_END(A) (motion.position.A + (motion.destination.A - motion.position.A) * normalized_dist)
389389

390390
float normalized_dist;
391391
xyze_pos_t end;
@@ -396,36 +396,36 @@ float LevelingBilinear::get_z_correction(const xy_pos_t &raw) {
396396
if (c2.x != c1.x && TEST(x_splits, gc.x)) {
397397
// Split on the X grid line
398398
CBI(x_splits, gc.x);
399-
end = destination;
400-
destination.x = grid_start.x + ABL_BG_SPACING(x) * gc.x;
401-
normalized_dist = (destination.x - current_position.x) / (end.x - current_position.x);
402-
destination.y = LINE_SEGMENT_END(y);
399+
end = motion.destination;
400+
motion.destination.x = grid_start.x + ABL_BG_SPACING(x) * gc.x;
401+
normalized_dist = (motion.destination.x - motion.position.x) / (end.x - motion.position.x);
402+
motion.destination.y = LINE_SEGMENT_END(y);
403403
}
404404
// Crosses on the Y and not already split on this Y?
405405
else if (c2.y != c1.y && TEST(y_splits, gc.y)) {
406406
// Split on the Y grid line
407407
CBI(y_splits, gc.y);
408-
end = destination;
409-
destination.y = grid_start.y + ABL_BG_SPACING(y) * gc.y;
410-
normalized_dist = (destination.y - current_position.y) / (end.y - current_position.y);
411-
destination.x = LINE_SEGMENT_END(x);
408+
end = motion.destination;
409+
motion.destination.y = grid_start.y + ABL_BG_SPACING(y) * gc.y;
410+
normalized_dist = (motion.destination.y - motion.position.y) / (end.y - motion.position.y);
411+
motion.destination.x = LINE_SEGMENT_END(x);
412412
}
413413
else {
414414
// Must already have been split on these border(s)
415415
// This should be a rare case.
416-
current_position = destination;
417-
line_to_current_position(scaled_fr_mm_s);
416+
motion.position = motion.destination;
417+
motion.line_to_current_position(scaled_fr_mm_s);
418418
return;
419419
}
420420

421-
destination.z = LINE_SEGMENT_END(z);
422-
destination.e = LINE_SEGMENT_END(e);
421+
motion.destination.z = LINE_SEGMENT_END(z);
422+
motion.destination.e = LINE_SEGMENT_END(e);
423423

424424
// Do the split and look for more borders
425425
line_to_destination(scaled_fr_mm_s, x_splits, y_splits);
426426

427427
// Restore destination from stack
428-
destination = end;
428+
motion.destination = end;
429429
line_to_destination(scaled_fr_mm_s, x_splits, y_splits);
430430
}
431431

Marlin/src/feature/bedlevel/bdl/bdl.cpp

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ void BDS_Leveling::init(uint8_t _sda, uint8_t _scl, uint16_t delay_s) {
7373
config_state = BDS_IDLE;
7474
const int ret = BD_I2C_SENSOR.i2c_init(_sda, _scl, BD_SENSOR_I2C_ADDR, delay_s);
7575
if (ret != 1) SERIAL_ECHOLNPGM("BD Sensor Init Fail (", ret, ")");
76-
sync_plan_position();
77-
pos_zero_offset = planner.get_axis_position_mm(Z_AXIS) - current_position.z;
76+
motion.sync_plan_position();
77+
pos_zero_offset = planner.get_axis_position_mm(Z_AXIS) - motion.position.z;
7878
SERIAL_ECHOLNPGM("BD Sensor Zero Offset:", pos_zero_offset);
7979
}
8080

@@ -120,27 +120,27 @@ void BDS_Leveling::process() {
120120

121121
uint16_t tmp = 0;
122122
const float cur_z = planner.get_axis_position_mm(Z_AXIS) - pos_zero_offset;
123-
static float old_cur_z = cur_z, old_buf_z = current_position.z;
123+
static float old_cur_z = cur_z, old_buf_z = motion.position.z;
124124
tmp = BD_I2C_SENSOR.BD_i2c_read();
125125
if (BD_I2C_SENSOR.BD_Check_OddEven(tmp) && good_data(tmp)) {
126126
const float z_sensor = interpret(tmp);
127127
#if ENABLED(BABYSTEPPING)
128128
if (config_state > 0) {
129129
if (cur_z < config_state * 0.1f
130130
&& old_cur_z == cur_z
131-
&& old_buf_z == current_position.z
131+
&& old_buf_z == motion.position.z
132132
&& z_sensor < (MAX_BD_HEIGHT) - 0.1f
133133
) {
134134
babystep.set_mm(Z_AXIS, cur_z - z_sensor);
135-
DEBUG_ECHOLNPGM("BD:", z_sensor, ", Z:", cur_z, "|", current_position.z);
135+
DEBUG_ECHOLNPGM("BD:", z_sensor, ", Z:", cur_z, "|", motion.position.z);
136136
}
137137
else
138138
babystep.set_mm(Z_AXIS, 0);
139139
}
140140
#endif
141141

142142
old_cur_z = cur_z;
143-
old_buf_z = current_position.z;
143+
old_buf_z = motion.position.z;
144144
endstops.bdp_state_update(z_sensor <= BD_SENSOR_HOME_Z_POSITION);
145145

146146
#if HAS_STATUS_MESSAGE
@@ -159,7 +159,7 @@ void BDS_Leveling::process() {
159159
kill(F("BDsensor connect Err!"));
160160
}
161161

162-
DEBUG_ECHOLNPGM("BD:", tmp & 0x3FF, " Z:", cur_z, "|", current_position.z);
162+
DEBUG_ECHOLNPGM("BD:", tmp & 0x3FF, " Z:", cur_z, "|", motion.position.z);
163163
if (TERN0(DEBUG_OUT_BD, BD_I2C_SENSOR.BD_Check_OddEven(tmp) == 0)) DEBUG_ECHOLNPGM("CRC error");
164164

165165
if (!good_data(tmp)) {
@@ -205,15 +205,15 @@ void BDS_Leveling::process() {
205205
SERIAL_ECHOLNPGM("c_z0:", planner.get_axis_position_mm(Z_AXIS), "-", pos_zero_offset);
206206

207207
// Move the z axis instead of enabling the Z axis with M17
208-
// TODO: Use do_blocking_move_to_z for synchronized move.
209-
current_position.z = 0;
210-
sync_plan_position();
208+
// TODO: Use motion.blocking_move_z for synchronized move.
209+
motion.position.z = 0;
210+
motion.sync_plan_position();
211211
gcode.process_subcommands_now(F("G1Z0.05"));
212212
safe_delay(300);
213213
gcode.process_subcommands_now(F("G1Z0.00"));
214214
safe_delay(300);
215-
current_position.z = 0;
216-
sync_plan_position();
215+
motion.position.z = 0;
216+
motion.sync_plan_position();
217217
//safe_delay(1000);
218218

219219
while ((planner.get_axis_position_mm(Z_AXIS) - pos_zero_offset) > 0.00001f) {
@@ -236,10 +236,10 @@ void BDS_Leveling::process() {
236236
}
237237
else {
238238
char tmp_1[32];
239-
// TODO: Use prepare_internal_move_to_destination to guarantee machine space
239+
// TODO: Use motion.prepare_internal_move_to_destination to guarantee machine space
240240
sprintf_P(tmp_1, PSTR("G1Z%d.%d"), int(zpos), int(zpos * 10) % 10);
241241
gcode.process_subcommands_now(tmp_1);
242-
SERIAL_ECHO(tmp_1); SERIAL_ECHOLNPGM(", Z:", current_position.z);
242+
SERIAL_ECHO(tmp_1); SERIAL_ECHOLNPGM(", Z:", motion.position.z);
243243
uint16_t failcount = 300;
244244
for (float tmp_k = 0; abs(zpos - tmp_k) > 0.006f && failcount--;) {
245245
tmp_k = planner.get_axis_position_mm(Z_AXIS) - pos_zero_offset;

0 commit comments

Comments
 (0)