New feature: BED_SKEW_CORRECTION

This commit is contained in:
Scott Lahteine
2017-12-01 16:42:23 -06:00
parent 082ab8fcab
commit 0154e3480c
12 changed files with 394 additions and 46 deletions

View File

@@ -36,13 +36,13 @@
*
*/
#define EEPROM_VERSION "V45"
#define EEPROM_VERSION "V46"
// Change EEPROM version if these are changed:
#define EEPROM_OFFSET 100
/**
* V45 EEPROM Layout:
* V46 EEPROM Layout:
*
* 100 Version (char x4)
* 104 EEPROM CRC16 (uint16_t)
@@ -166,8 +166,13 @@
* CNC_COORDINATE_SYSTEMS 108 bytes
* 602 G54-G59.3 coordinate_system (float x 27)
*
* 710 Minimum end-point
* 2239 (710 + 208 + 36 + 9 + 288 + 988) Maximum end-point
* SKEW_CORRECTION: 12 bytes
* 710 M852 I planner.xy_skew_factor (float)
* 714 M852 J planner.xz_skew_factor (float)
* 718 M852 K planner.yz_skew_factor (float)
*
* 722 Minimum end-point
* 2251 (722 + 208 + 36 + 9 + 288 + 988) Maximum end-point
*
* ========================================================================
* meshes_begin (between max and min end-point, directly above)
@@ -633,6 +638,10 @@ void MarlinSettings::postprocess() {
for (uint8_t q = 3; q--;) EEPROM_WRITE(dummyui32);
#endif
//
// CNC Coordinate Systems
//
#if ENABLED(CNC_COORDINATE_SYSTEMS)
EEPROM_WRITE(coordinate_system); // 27 floats
#else
@@ -640,6 +649,19 @@ void MarlinSettings::postprocess() {
for (uint8_t q = 27; q--;) EEPROM_WRITE(dummy);
#endif
//
// Skew correction factors
//
#if ENABLED(SKEW_CORRECTION)
EEPROM_WRITE(planner.xy_skew_factor);
EEPROM_WRITE(planner.xz_skew_factor);
EEPROM_WRITE(planner.yz_skew_factor);
#else
dummy = 0.0f;
for (uint8_t q = 3; q--;) EEPROM_WRITE(dummy);
#endif
if (!eeprom_error) {
#if ENABLED(EEPROM_CHITCHAT)
const int eeprom_size = eeprom_index;
@@ -1078,6 +1100,23 @@ void MarlinSettings::postprocess() {
for (uint8_t q = 27; q--;) EEPROM_READ(dummy);
#endif
//
// Skew correction factors
//
#if ENABLED(SKEW_CORRECTION_GCODE)
EEPROM_READ(planner.xy_skew_factor);
#if ENABLED(SKEW_CORRECTION_FOR_Z)
EEPROM_READ(planner.xz_skew_factor);
EEPROM_READ(planner.yz_skew_factor);
#else
EEPROM_READ(dummy);
EEPROM_READ(dummy);
#endif
#else
for (uint8_t q = 3; q--;) EEPROM_READ(dummy);
#endif
if (working_crc == stored_crc) {
postprocess();
#if ENABLED(EEPROM_CHITCHAT)
@@ -1463,6 +1502,14 @@ void MarlinSettings::reset() {
ubl.reset();
#endif
#if ENABLED(SKEW_CORRECTION_GCODE)
planner.xy_skew_factor = XY_SKEW_FACTOR;
#if ENABLED(SKEW_CORRECTION_FOR_Z)
planner.xz_skew_factor = XZ_SKEW_FACTOR;
planner.yz_skew_factor = YZ_SKEW_FACTOR;
#endif
#endif
postprocess();
#if ENABLED(EEPROM_CHITCHAT)
@@ -1887,6 +1934,24 @@ void MarlinSettings::reset() {
SERIAL_ECHOLNPAIR(" M851 Z", LINEAR_UNIT(zprobe_zoffset));
#endif
/**
* Bed Skew Correction
*/
#if ENABLED(SKEW_CORRECTION_GCODE)
if (!forReplay) {
CONFIG_ECHO_START;
SERIAL_ECHOLNPGM("Skew Factor: ");
}
CONFIG_ECHO_START;
#if ENABLED(SKEW_CORRECTION_FOR_Z)
SERIAL_ECHOPAIR(" M852 I", LINEAR_UNIT(planner.xy_skew_factor));
SERIAL_ECHOPAIR(" J", LINEAR_UNIT(planner.xz_skew_factor));
SERIAL_ECHOLNPAIR(" K", LINEAR_UNIT(planner.yz_skew_factor));
#else
SERIAL_ECHOLNPAIR(" M852 S", LINEAR_UNIT(planner.xy_skew_factor));
#endif
#endif
/**
* TMC2130 stepper driver current
*/

View File

@@ -135,6 +135,20 @@ float Planner::min_feedrate_mm_s,
#endif
#endif
#if ENABLED(SKEW_CORRECTION)
#if ENABLED(SKEW_CORRECTION_GCODE)
// Initialized by settings.load()
float Planner::xy_skew_factor;
#if ENABLED(SKEW_CORRECTION_FOR_Z)
float Planner::xz_skew_factor, Planner::yz_skew_factor;
#else
constexpr float Planner::xz_skew_factor, Planner::yz_skew_factor;
#endif
#else
constexpr float Planner::xy_skew_factor, Planner::xz_skew_factor, Planner::yz_skew_factor;
#endif
#endif
#if ENABLED(AUTOTEMP)
float Planner::autotemp_max = 250,
Planner::autotemp_min = 210,
@@ -565,6 +579,19 @@ void Planner::calculate_volumetric_multipliers() {
*/
void Planner::apply_leveling(float &rx, float &ry, float &rz) {
#if ENABLED(SKEW_CORRECTION)
if (WITHIN(rx, X_MIN_POS + 1, X_MAX_POS) && WITHIN(ry, Y_MIN_POS + 1, Y_MAX_POS)) {
const float tempry = ry - (rz * planner.yz_skew_factor),
temprx = rx - (ry * planner.xy_skew_factor) - (rz * (planner.xz_skew_factor - (planner.xy_skew_factor * planner.yz_skew_factor)));
if (WITHIN(temprx, X_MIN_POS, X_MAX_POS) && WITHIN(tempry, Y_MIN_POS, Y_MAX_POS)) {
rx = temprx;
ry = tempry;
}
else
SERIAL_ECHOLN(MSG_SKEW_WARN);
}
#endif
if (!leveling_active) return;
#if ABL_PLANAR
@@ -611,45 +638,56 @@ void Planner::calculate_volumetric_multipliers() {
void Planner::unapply_leveling(float raw[XYZ]) {
if (!leveling_active) return;
#if ABL_PLANAR
matrix_3x3 inverse = matrix_3x3::transpose(bed_level_matrix);
float dx = raw[X_AXIS] - (X_TILT_FULCRUM),
dy = raw[Y_AXIS] - (Y_TILT_FULCRUM);
apply_rotation_xyz(inverse, dx, dy, raw[Z_AXIS]);
raw[X_AXIS] = dx + X_TILT_FULCRUM;
raw[Y_AXIS] = dy + Y_TILT_FULCRUM;
#if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
const float fade_scaling_factor = fade_scaling_factor_for_z(raw[Z_AXIS]);
#else
constexpr float fade_scaling_factor = 1.0;
#endif
#if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
const float fade_scaling_factor = fade_scaling_factor_for_z(raw[Z_AXIS]);
if (!fade_scaling_factor) return;
#elif HAS_MESH
constexpr float fade_scaling_factor = 1.0;
#endif
if (leveling_active && fade_scaling_factor) {
raw[Z_AXIS] -= (
#if ENABLED(AUTO_BED_LEVELING_UBL)
ubl.get_z_correction(raw[X_AXIS], raw[Y_AXIS]) * fade_scaling_factor
#elif ENABLED(MESH_BED_LEVELING)
mbl.get_z(raw[X_AXIS], raw[Y_AXIS]
#if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
, fade_scaling_factor
#endif
)
#elif ENABLED(AUTO_BED_LEVELING_BILINEAR)
bilinear_z_offset(raw) * fade_scaling_factor
#else
0
#endif
);
#if ABL_PLANAR
matrix_3x3 inverse = matrix_3x3::transpose(bed_level_matrix);
float dx = raw[X_AXIS] - (X_TILT_FULCRUM),
dy = raw[Y_AXIS] - (Y_TILT_FULCRUM);
apply_rotation_xyz(inverse, dx, dy, raw[Z_AXIS]);
raw[X_AXIS] = dx + X_TILT_FULCRUM;
raw[Y_AXIS] = dy + Y_TILT_FULCRUM;
#else // !ABL_PLANAR
raw[Z_AXIS] -= (
#if ENABLED(AUTO_BED_LEVELING_UBL)
ubl.get_z_correction(raw[X_AXIS], raw[Y_AXIS]) * fade_scaling_factor
#elif ENABLED(MESH_BED_LEVELING)
mbl.get_z(raw[X_AXIS], raw[Y_AXIS]
#if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
, fade_scaling_factor
#endif
)
#elif ENABLED(AUTO_BED_LEVELING_BILINEAR)
bilinear_z_offset(raw) * fade_scaling_factor
#else
0
#endif
);
#endif // !ABL_PLANAR
}
#if ENABLED(SKEW_CORRECTION)
if (WITHIN(raw[X_AXIS], X_MIN_POS, X_MAX_POS) && WITHIN(raw[Y_AXIS], Y_MIN_POS, Y_MAX_POS)) {
const float temprx = raw[X_AXIS] + raw[Y_AXIS] * planner.xy_skew_factor + raw[Z_AXIS] * planner.xz_skew_factor,
tempry = raw[Y_AXIS] + raw[Z_AXIS] * planner.yz_skew_factor;
if (WITHIN(temprx, X_MIN_POS, X_MAX_POS) && WITHIN(tempry, Y_MIN_POS, Y_MAX_POS)) {
raw[X_AXIS] = temprx;
raw[Y_AXIS] = tempry;
}
}
#endif
}
@@ -658,13 +696,13 @@ void Planner::calculate_volumetric_multipliers() {
/**
* Planner::_buffer_line
*
* Add a new linear movement to the buffer.
* Add a new linear movement to the buffer in axis units.
*
* Leveling and kinematics should be applied ahead of calling this.
*
* a,b,c,e - target positions in mm or degrees
* fr_mm_s - (target) speed of the move
* extruder - target extruder
* a,b,c,e - target positions in mm and/or degrees
* fr_mm_s - (target) speed of the move
* extruder - target extruder
*/
void Planner::_buffer_line(const float &a, const float &b, const float &c, const float &e, float fr_mm_s, const uint8_t extruder) {
@@ -713,6 +751,10 @@ void Planner::_buffer_line(const float &a, const float &b, const float &c, const
SERIAL_EOL();
//*/
// DRYRUN ignores all temperature constraints and assures that the extruder is instantly satisfied
if (DEBUGGING(DRYRUN))
position[E_AXIS] = target[E_AXIS];
int32_t de = target[E_AXIS] - position[E_AXIS];
#if ENABLED(PREVENT_COLD_EXTRUSION) || ENABLED(PREVENT_LENGTHY_EXTRUDE)
@@ -736,6 +778,10 @@ void Planner::_buffer_line(const float &a, const float &b, const float &c, const
}
#endif // PREVENT_COLD_EXTRUSION || PREVENT_LENGTHY_EXTRUDE
#if ENABLED(LIN_ADVANCE)
float de_float = de * steps_to_mm[E_AXIS_N];
#endif
// Compute direction bit-mask for this block
uint8_t dm = 0;
#if CORE_IS_XY
@@ -1332,6 +1378,7 @@ void Planner::_buffer_line(const float &a, const float &b, const float &c, const
previous_safe_speed = safe_speed;
#if ENABLED(LIN_ADVANCE)
/**
*
* Use LIN_ADVANCE for blocks if all these are true:

View File

@@ -180,6 +180,23 @@ class Planner {
static float extruder_advance_k, advance_ed_ratio;
#endif
#if ENABLED(SKEW_CORRECTION)
#if ENABLED(SKEW_CORRECTION_GCODE)
static float xy_skew_factor;
#else
static constexpr float xy_skew_factor = XY_SKEW_FACTOR;
#endif
#if ENABLED(SKEW_CORRECTION_FOR_Z)
#if ENABLED(SKEW_CORRECTION_GCODE)
static float xz_skew_factor, yz_skew_factor;
#else
static constexpr float xz_skew_factor = XZ_SKEW_FACTOR, yz_skew_factor = YZ_SKEW_FACTOR;
#endif
#else
static constexpr float xz_skew_factor = 0, yz_skew_factor = 0;
#endif
#endif
private:
/**