Skip to content

Commit

Permalink
Merge branch 'bugfix-2.0.x' into pr/24560
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkyhead committed Jul 29, 2022
2 parents fb30e7b + 4b8175c commit 2356e57
Show file tree
Hide file tree
Showing 97 changed files with 834 additions and 667 deletions.
9 changes: 6 additions & 3 deletions Marlin/Configuration_adv.h
Original file line number Diff line number Diff line change
Expand Up @@ -923,9 +923,12 @@
*/
//#define Z_STEPPER_AUTO_ALIGN
#if ENABLED(Z_STEPPER_AUTO_ALIGN)
// Define probe X and Y positions for Z1, Z2 [, Z3 [, Z4]]
// If not defined, probe limits will be used.
// Override with 'M422 S<index> X<pos> Y<pos>'
/**
* Define probe X and Y positions for Z1, Z2 [, Z3 [, Z4]]
* These positions are machine-relative and do not shift with the M206 home offset!
* If not defined, probe limits will be used.
* Override with 'M422 S<index> X<pos> Y<pos>'.
*/
//#define Z_STEPPER_ALIGN_XY { { 10, 190 }, { 100, 10 }, { 190, 190 } }

/**
Expand Down
4 changes: 2 additions & 2 deletions Marlin/src/HAL/STM32/tft/tft_ltdc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -372,9 +372,9 @@ void TFT_LTDC::TransmitDMA(uint32_t MemoryIncrease, uint16_t *Data, uint16_t Cou
if (MemoryIncrease == DMA_PINC_ENABLE) {
DrawImage(x_min, y_cur, x_min + width, y_cur + height, Data);
Data += width * height;
} else {
DrawRect(x_min, y_cur, x_min + width, y_cur + height, *Data);
}
else
DrawRect(x_min, y_cur, x_min + width, y_cur + height, *Data);
y_cur += height;
}

Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/core/serial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ PGMSTR(SP_P_STR, " P"); PGMSTR(SP_T_STR, " T"); PGMSTR(NUL_STR, "");

#define _N_STR(N) PGMSTR(N##_STR, STR_##N);
#define _N_LBL(N) PGMSTR(N##_LBL, STR_##N ":");
#define _SP_N_STR(N) PGMSTR(SP_##N##_STR, STR_##N ":");
#define _SP_N_STR(N) PGMSTR(SP_##N##_STR, " " STR_##N);
#define _SP_N_LBL(N) PGMSTR(SP_##N##_LBL, " " STR_##N ":");
MAP(_N_STR, LOGICAL_AXIS_NAMES); MAP(_SP_N_STR, LOGICAL_AXIS_NAMES);
MAP(_N_LBL, LOGICAL_AXIS_NAMES); MAP(_SP_N_LBL, LOGICAL_AXIS_NAMES);
Expand Down
3 changes: 1 addition & 2 deletions Marlin/src/core/utility.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,7 @@ constexpr uint8_t ui8_to_percent(const uint8_t i) { return (int(i) * 100 + 127)

// Axis names for G-code parsing, reports, etc.
const xyze_char_t axis_codes LOGICAL_AXIS_ARRAY('E', 'X', 'Y', 'Z', AXIS4_NAME, AXIS5_NAME, AXIS6_NAME);

#if LINEAR_AXES <= XYZ
#if LINEAR_AXES <= XYZ && !HAS_EXTRUDERS
#define AXIS_CHAR(A) ((char)('X' + A))
#define IAXIS_CHAR AXIS_CHAR
#else
Expand Down
45 changes: 25 additions & 20 deletions Marlin/src/feature/backlash.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,32 +162,37 @@ int32_t Backlash::get_applied_steps(const AxisEnum axis) {
}

class Backlash::StepAdjuster {
xyz_long_t applied_steps;
public:
StepAdjuster() {
LOOP_LINEAR_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_LINEAR_AXES(axis) residual_error[axis] += backlash.get_applied_steps((AxisEnum)axis) - applied_steps[axis];
}
private:
xyz_long_t applied_steps;
public:
StepAdjuster() {
LOOP_LINEAR_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_LINEAR_AXES(axis) residual_error[axis] += backlash.get_applied_steps((AxisEnum)axis) - applied_steps[axis];
}
};

void Backlash::set_correction_uint8(const uint8_t v) {
StepAdjuster adjuster;
correction = v;
}
#if ENABLED(BACKLASH_GCODE)

void Backlash::set_distance_mm(const AxisEnum axis, const float v) {
StepAdjuster adjuster;
distance_mm[axis] = v;
}
void Backlash::set_correction_uint8(const uint8_t v) {
StepAdjuster adjuster;
correction = v;
}

#ifdef BACKLASH_SMOOTHING_MM
void Backlash::set_smoothing_mm(const float v) {
void Backlash::set_distance_mm(const AxisEnum axis, const float v) {
StepAdjuster adjuster;
smoothing_mm = v;
distance_mm[axis] = v;
}

#ifdef BACKLASH_SMOOTHING_MM
void Backlash::set_smoothing_mm(const float v) {
StepAdjuster adjuster;
smoothing_mm = v;
}
#endif

#endif

#if ENABLED(MEASURE_BACKLASH_WHEN_PROBING)
Expand Down
18 changes: 16 additions & 2 deletions Marlin/src/feature/bedlevel/ubl/ubl_motion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,18 @@
#include "../../../MarlinCore.h"
#include <math.h>

//#define DEBUG_UBL_MOTION
#define DEBUG_OUT ENABLED(DEBUG_UBL_MOTION)
#include "../../../core/debug_out.h"

#if !UBL_SEGMENTED

// TODO: The first and last parts of a move might result in very short segment(s)
// after getting split on the cell boundary, so moves like that should not
// get split. This will be most common for moves that start/end near the
// corners of cells. To fix the issue, simply check if the start/end of the line
// is very close to a cell boundary in advance and don't split the line there.

void unified_bed_leveling::line_to_destination_cartesian(const_feedRate_t scaled_fr_mm_s, const uint8_t extruder) {
/**
* Much of the nozzle movement will be within the same cell. So we will do as little computation
Expand Down Expand Up @@ -175,7 +185,9 @@
dest.z += z0;
planner.buffer_segment(dest, scaled_fr_mm_s, extruder);

} //else printf("FIRST MOVE PRUNED ");
}
else
DEBUG_ECHOLNPGM("[ubl] skip Y segment");
}

// At the final destination? Usually not, but when on a Y Mesh Line it's completed.
Expand Down Expand Up @@ -224,7 +236,9 @@
dest.z += z0;
if (!planner.buffer_segment(dest, scaled_fr_mm_s, extruder)) break;

} //else printf("FIRST MOVE PRUNED ");
}
else
DEBUG_ECHOLNPGM("[ubl] skip Y segment");
}

if (xy_pos_t(current_position) != xy_pos_t(end))
Expand Down
19 changes: 10 additions & 9 deletions Marlin/src/feature/direct_stepping.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,14 +143,16 @@ namespace DirectStepping {
// special case for 8-bit, check if rolled back to 0
if (Cfg::DIRECTIONAL || !write_page_size) { // full 256 bytes
if (write_byte_idx) return true;
} else {
if (write_byte_idx < write_page_size) return true;
}
} else if (Cfg::DIRECTIONAL) {
if (write_byte_idx != Cfg::PAGE_SIZE) return true;
} else {
if (write_byte_idx < write_page_size) return true;
else if (write_byte_idx < write_page_size)
return true;
}
else if (Cfg::DIRECTIONAL) {
if (write_byte_idx != Cfg::PAGE_SIZE)
return true;
}
else if (write_byte_idx < write_page_size)
return true;

state = State::CHECKSUM;
return true;
Expand All @@ -161,11 +163,10 @@ namespace DirectStepping {
return true;
}
case State::UNFAIL:
if (c == 0) {
if (c == 0)
set_page_state(write_page_idx, PageState::FREE);
} else {
else
fatal_error = true;
}
state = State::MONITOR;
return true;
}
Expand Down
44 changes: 22 additions & 22 deletions Marlin/src/feature/encoder_i2c.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ void I2CPositionEncoder::init(const uint8_t address, const AxisEnum axis) {

initialized = true;

SERIAL_ECHOLNPGM("Setting up encoder on ", AS_CHAR(axis_codes[encoderAxis]), " axis, addr = ", address);
SERIAL_ECHOLNPGM("Setting up encoder on ", AS_CHAR(AXIS_CHAR(encoderAxis)), " axis, addr = ", address);

position = get_position();
}
Expand All @@ -67,7 +67,7 @@ void I2CPositionEncoder::update() {
/*
if (trusted) { //commented out as part of the note below
trusted = false;
SERIAL_ECHOLNPGM("Fault detected on ", AS_CHAR(axis_codes[encoderAxis]), " axis encoder. Disengaging error correction until module is trusted again.");
SERIAL_ECHOLNPGM("Fault detected on ", AS_CHAR(AXIS_CHAR(encoderAxis)), " axis encoder. Disengaging error correction until module is trusted again.");
}
*/
return;
Expand All @@ -92,7 +92,7 @@ void I2CPositionEncoder::update() {
if (millis() - lastErrorTime > I2CPE_TIME_TRUSTED) {
trusted = true;

SERIAL_ECHOLNPGM("Untrusted encoder module on ", AS_CHAR(axis_codes[encoderAxis]), " axis has been fault-free for set duration, reinstating error correction.");
SERIAL_ECHOLNPGM("Untrusted encoder module on ", AS_CHAR(AXIS_CHAR(encoderAxis)), " axis has been fault-free for set duration, reinstating error correction.");

//the encoder likely lost its place when the error occurred, so we'll reset and use the printer's
//idea of where it the axis is to re-initialize
Expand Down Expand Up @@ -172,7 +172,7 @@ void I2CPositionEncoder::update() {
float sumP = 0;
LOOP_L_N(i, I2CPE_ERR_PRST_ARRAY_SIZE) sumP += errPrst[i];
const int32_t errorP = int32_t(sumP * RECIPROCAL(I2CPE_ERR_PRST_ARRAY_SIZE));
SERIAL_CHAR(axis_codes[encoderAxis]);
SERIAL_CHAR(AXIS_CHAR(encoderAxis));
SERIAL_ECHOLNPGM(" : CORRECT ERR ", errorP * planner.mm_per_step[encoderAxis], "mm");
babystep.add_steps(encoderAxis, -LROUND(errorP));
errPrstIdx = 0;
Expand All @@ -192,7 +192,7 @@ void I2CPositionEncoder::update() {
if (ABS(error) > I2CPE_ERR_CNT_THRESH * planner.settings.axis_steps_per_mm[encoderAxis]) {
const millis_t ms = millis();
if (ELAPSED(ms, nextErrorCountTime)) {
SERIAL_CHAR(axis_codes[encoderAxis]);
SERIAL_CHAR(AXIS_CHAR(encoderAxis));
SERIAL_ECHOLNPGM(" : LARGE ERR ", error, "; diffSum=", diffSum);
errorCount++;
nextErrorCountTime = ms + I2CPE_ERR_CNT_DEBOUNCE_MS;
Expand All @@ -212,7 +212,7 @@ void I2CPositionEncoder::set_homed() {
homed = trusted = true;

#ifdef I2CPE_DEBUG
SERIAL_CHAR(axis_codes[encoderAxis]);
SERIAL_CHAR(AXIS_CHAR(encoderAxis));
SERIAL_ECHOLNPGM(" axis encoder homed, offset of ", zeroOffset, " ticks.");
#endif
}
Expand All @@ -223,15 +223,15 @@ void I2CPositionEncoder::set_unhomed() {
homed = trusted = false;

#ifdef I2CPE_DEBUG
SERIAL_CHAR(axis_codes[encoderAxis]);
SERIAL_CHAR(AXIS_CHAR(encoderAxis));
SERIAL_ECHOLNPGM(" axis encoder unhomed.");
#endif
}

bool I2CPositionEncoder::passes_test(const bool report) {
if (report) {
if (H != I2CPE_MAG_SIG_GOOD) SERIAL_ECHOPGM("Warning. ");
SERIAL_CHAR(axis_codes[encoderAxis]);
SERIAL_CHAR(AXIS_CHAR(encoderAxis));
serial_ternary(H == I2CPE_MAG_SIG_BAD, F(" axis "), F("magnetic strip "), F("encoder "));
switch (H) {
case I2CPE_MAG_SIG_GOOD:
Expand All @@ -252,7 +252,7 @@ float I2CPositionEncoder::get_axis_error_mm(const bool report) {
error = ABS(diff) > 10000 ? 0 : diff; // Huge error is a bad reading

if (report) {
SERIAL_CHAR(axis_codes[encoderAxis]);
SERIAL_CHAR(AXIS_CHAR(encoderAxis));
SERIAL_ECHOLNPGM(" axis target=", target, "mm; actual=", actual, "mm; err=", error, "mm");
}

Expand All @@ -262,7 +262,7 @@ float I2CPositionEncoder::get_axis_error_mm(const bool report) {
int32_t I2CPositionEncoder::get_axis_error_steps(const bool report) {
if (!active) {
if (report) {
SERIAL_CHAR(axis_codes[encoderAxis]);
SERIAL_CHAR(AXIS_CHAR(encoderAxis));
SERIAL_ECHOLNPGM(" axis encoder not active!");
}
return 0;
Expand All @@ -287,7 +287,7 @@ int32_t I2CPositionEncoder::get_axis_error_steps(const bool report) {
errorPrev = error;

if (report) {
SERIAL_CHAR(axis_codes[encoderAxis]);
SERIAL_CHAR(AXIS_CHAR(encoderAxis));
SERIAL_ECHOLNPGM(" axis target=", target, "; actual=", encoderCountInStepperTicksScaled, "; err=", error);
}

Expand Down Expand Up @@ -657,7 +657,7 @@ void I2CPositionEncodersMgr::report_position(const int8_t idx, const bool units,
else {
if (noOffset) {
const int32_t raw_count = encoders[idx].get_raw_count();
SERIAL_CHAR(axis_codes[encoders[idx].get_axis()], ' ');
SERIAL_CHAR(AXIS_CHAR(encoders[idx).get_axis()], ' ');

for (uint8_t j = 31; j > 0; j--)
SERIAL_ECHO((bool)(0x00000001 & (raw_count >> j)));
Expand Down Expand Up @@ -712,7 +712,7 @@ void I2CPositionEncodersMgr::change_module_address(const uint8_t oldaddr, const
// and enable it (it will likely have failed initialization on power-up, before the address change).
const int8_t idx = idx_from_addr(newaddr);
if (idx >= 0 && !encoders[idx].get_active()) {
SERIAL_CHAR(axis_codes[encoders[idx].get_axis()]);
SERIAL_CHAR(AXIS_CHAR(encoders[idx).get_axis()]);
SERIAL_ECHOLNPGM(" axis encoder was not detected on printer startup. Trying again.");
encoders[idx].set_active(encoders[idx].passes_test(true));
}
Expand Down Expand Up @@ -814,7 +814,7 @@ void I2CPositionEncodersMgr::M860() {

if (I2CPE_idx == 0xFF) {
LOOP_LOGICAL_AXES(i) {
if (!I2CPE_anyaxis || parser.seen_test(axis_codes[i])) {
if (!I2CPE_anyaxis || parser.seen_test(AXIS_CHAR(i))) {
const uint8_t idx = idx_from_axis(AxisEnum(i));
if ((int8_t)idx >= 0) report_position(idx, hasU, hasO);
}
Expand All @@ -841,7 +841,7 @@ void I2CPositionEncodersMgr::M861() {

if (I2CPE_idx == 0xFF) {
LOOP_LOGICAL_AXES(i) {
if (!I2CPE_anyaxis || parser.seen(axis_codes[i])) {
if (!I2CPE_anyaxis || parser.seen(AXIS_CHAR(i))) {
const uint8_t idx = idx_from_axis(AxisEnum(i));
if ((int8_t)idx >= 0) report_status(idx);
}
Expand Down Expand Up @@ -869,7 +869,7 @@ void I2CPositionEncodersMgr::M862() {

if (I2CPE_idx == 0xFF) {
LOOP_LOGICAL_AXES(i) {
if (!I2CPE_anyaxis || parser.seen(axis_codes[i])) {
if (!I2CPE_anyaxis || parser.seen(AXIS_CHAR(i))) {
const uint8_t idx = idx_from_axis(AxisEnum(i));
if ((int8_t)idx >= 0) test_axis(idx);
}
Expand Down Expand Up @@ -900,7 +900,7 @@ void I2CPositionEncodersMgr::M863() {

if (I2CPE_idx == 0xFF) {
LOOP_LOGICAL_AXES(i) {
if (!I2CPE_anyaxis || parser.seen(axis_codes[i])) {
if (!I2CPE_anyaxis || parser.seen(AXIS_CHAR(i))) {
const uint8_t idx = idx_from_axis(AxisEnum(i));
if ((int8_t)idx >= 0) calibrate_steps_mm(idx, iterations);
}
Expand Down Expand Up @@ -976,7 +976,7 @@ void I2CPositionEncodersMgr::M865() {

if (!I2CPE_addr) {
LOOP_LOGICAL_AXES(i) {
if (!I2CPE_anyaxis || parser.seen(axis_codes[i])) {
if (!I2CPE_anyaxis || parser.seen(AXIS_CHAR(i))) {
const uint8_t idx = idx_from_axis(AxisEnum(i));
if ((int8_t)idx >= 0) report_module_firmware(encoders[idx].get_address());
}
Expand Down Expand Up @@ -1007,7 +1007,7 @@ void I2CPositionEncodersMgr::M866() {

if (I2CPE_idx == 0xFF) {
LOOP_LOGICAL_AXES(i) {
if (!I2CPE_anyaxis || parser.seen(axis_codes[i])) {
if (!I2CPE_anyaxis || parser.seen(AXIS_CHAR(i))) {
const uint8_t idx = idx_from_axis(AxisEnum(i));
if ((int8_t)idx >= 0) {
if (hasR)
Expand Down Expand Up @@ -1045,7 +1045,7 @@ void I2CPositionEncodersMgr::M867() {

if (I2CPE_idx == 0xFF) {
LOOP_LOGICAL_AXES(i) {
if (!I2CPE_anyaxis || parser.seen(axis_codes[i])) {
if (!I2CPE_anyaxis || parser.seen(AXIS_CHAR(i))) {
const uint8_t idx = idx_from_axis(AxisEnum(i));
if ((int8_t)idx >= 0) {
const bool ena = onoff == -1 ? !encoders[I2CPE_idx].get_ec_enabled() : !!onoff;
Expand Down Expand Up @@ -1081,7 +1081,7 @@ void I2CPositionEncodersMgr::M868() {

if (I2CPE_idx == 0xFF) {
LOOP_LOGICAL_AXES(i) {
if (!I2CPE_anyaxis || parser.seen(axis_codes[i])) {
if (!I2CPE_anyaxis || parser.seen(AXIS_CHAR(i))) {
const uint8_t idx = idx_from_axis(AxisEnum(i));
if ((int8_t)idx >= 0) {
if (newThreshold != -9999)
Expand Down Expand Up @@ -1115,7 +1115,7 @@ void I2CPositionEncodersMgr::M869() {

if (I2CPE_idx == 0xFF) {
LOOP_LOGICAL_AXES(i) {
if (!I2CPE_anyaxis || parser.seen(axis_codes[i])) {
if (!I2CPE_anyaxis || parser.seen(AXIS_CHAR(i))) {
const uint8_t idx = idx_from_axis(AxisEnum(i));
if ((int8_t)idx >= 0) report_error(idx);
}
Expand Down
Loading

0 comments on commit 2356e57

Please sign in to comment.