Skip to content

Commit

Permalink
misc cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkyhead committed Dec 3, 2021
1 parent 7eca497 commit 17e77c3
Show file tree
Hide file tree
Showing 15 changed files with 166 additions and 126 deletions.
22 changes: 10 additions & 12 deletions Marlin/Configuration_adv.h
Original file line number Diff line number Diff line change
Expand Up @@ -1271,20 +1271,18 @@
#endif

#if ENABLED(AUTO_BED_LEVELING_BILINEAR)
// Add a calibration procedure in the probe offsets menu to compensate
// for the X-axis twist
#define X_AXIS_TWIST_COMPENSATION
// Add a calibration procedure in the Probe Offsets menu
// to compensate for twist in the X-axis.
//#define X_AXIS_TWIST_COMPENSATION
#if ENABLED(X_AXIS_TWIST_COMPENSATION)
//
// Enable to init the Probe Z-Offset when starting the Wizard.
// Use a height slightly above the estimated nozzle-to-probe Z offset.
// For example, with an offset of -5, consider a starting height of -4.
//
/**
* Enable to init the Probe Z-Offset when starting the Wizard.
* Use a height slightly above the estimated nozzle-to-probe Z offset.
* For example, with an offset of -5, consider a starting height of -4.
*/
#define XATC_START_Z 0.0
// Number of points to probe in the wizard.
#define XATC_MAX_POINTS 3
// Y position to probe
#define XATC_Y_POSITION Y_CENTER
#define XATC_MAX_POINTS 3 // Number of points to probe in the wizard
#define XATC_Y_POSITION Y_CENTER // (mm) Y position to probe
#endif
#endif
#endif
Expand Down
38 changes: 28 additions & 10 deletions Marlin/src/feature/bedlevel/abl/x_axis_twist_compensation.cpp
Original file line number Diff line number Diff line change
@@ -1,15 +1,35 @@
/**
* Marlin 3D Printer Firmware
* Copyright (c) 2021 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/
#include "../../../inc/MarlinConfig.h"

#if ENABLED(X_AXIS_TWIST_COMPENSATION)

#include "../bedlevel.h"

xatc_points xatc_z_values;
float xatc_spacing;
float xatc_start;
float xatc_spacing, xatc_start;

void print_xatc_points(){
SERIAL_ECHOLNPGM(" XATC correction values:");
void print_xatc_points() {
SERIAL_ECHOLNPGM(" X-Twist Correction:");
LOOP_L_N(x, XATC_MAX_POINTS) {
SERIAL_CHAR(' ');
if (!isnan(xatc_z_values[x])) {
Expand All @@ -24,16 +44,14 @@ void print_xatc_points(){
SERIAL_EOL();
}

float lerp(float t, float a, float b){
return a + t * (b - a);
}
float lerp(const_float_t t, const_float_t a, const_float_t b) { return a + t * (b - a); }

float x_axis_twist_compensation(const xy_pos_t &raw){
float x_axis_twist_compensation(const xy_pos_t &raw) {
float t = (raw.x - xatc_start) / xatc_spacing;
int i = FLOOR(t);
LIMIT(i, 0, XATC_MAX_POINTS - 2);
t = t - i;
t -= i;
return lerp(t, xatc_z_values[i], xatc_z_values[i + 1]);
}

#endif //PROBE_OFFSET_MESH
#endif // X_AXIS_TWIST_COMPENSATION
23 changes: 22 additions & 1 deletion Marlin/src/feature/bedlevel/abl/x_axis_twist_compensation.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,24 @@
/**
* Marlin 3D Printer Firmware
* Copyright (c) 2021 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/
#pragma once

#include "../../../inc/MarlinConfigPre.h"
Expand All @@ -8,4 +29,4 @@ extern float xatc_spacing;
extern float xatc_start;

float x_axis_twist_compensation(const xy_pos_t &raw);
void print_xatc_points();
void print_xatc_points();
2 changes: 1 addition & 1 deletion Marlin/src/gcode/bedlevel/abl/G29.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -662,7 +662,7 @@ G29_TYPE GcodeSuite::G29() {
#elif ENABLED(AUTO_BED_LEVELING_BILINEAR)

const float z = abl.measured_z + abl.Z_offset;
z_values[abl.meshCount.x][abl.meshCount.y] = z + TERN0( X_AXIS_TWIST_COMPENSATION, x_axis_twist_compensation(abl.probePos) );
z_values[abl.meshCount.x][abl.meshCount.y] = z PLUS_TERN0(X_AXIS_TWIST_COMPENSATION, x_axis_twist_compensation(abl.probePos));
TERN_(EXTENSIBLE_UI, ExtUI::onMeshUpdate(abl.meshCount, z));

#endif
Expand Down
7 changes: 7 additions & 0 deletions Marlin/src/lcd/menu/menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,13 @@
///////////// Global Variables /////////////
////////////////////////////////////////////

#if HAS_LEVELING && ANY(LEVEL_BED_CORNERS, PROBE_OFFSET_WIZARD, X_AXIS_TWIST_COMPENSATION)
bool leveling_was_active; // = false
#endif
#if ANY(PROBE_MANUALLY, MESH_BED_LEVELING, X_AXIS_TWIST_COMPENSATION)
uint8_t manual_probe_index; // = 0
#endif

// Menu Navigation
int8_t encoderTopLine, encoderLine, screen_items;

Expand Down
8 changes: 8 additions & 0 deletions Marlin/src/lcd/menu/menu.h
Original file line number Diff line number Diff line change
Expand Up @@ -254,3 +254,11 @@ extern uint8_t screen_history_depth;
inline void clear_menu_history() { screen_history_depth = 0; }

#define STICKY_SCREEN(S) []{ ui.defer_status_screen(); ui.goto_screen(S); }

#if HAS_LEVELING && ANY(LEVEL_BED_CORNERS, PROBE_OFFSET_WIZARD, X_AXIS_TWIST_COMPENSATION)
extern bool leveling_was_active;
#endif

#if ANY(PROBE_MANUALLY, MESH_BED_LEVELING, X_AXIS_TWIST_COMPENSATION)
extern uint8_t manual_probe_index;
#endif
4 changes: 0 additions & 4 deletions Marlin/src/lcd/menu/menu_bed_corners.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,6 @@

static_assert(LEVEL_CORNERS_Z_HOP >= 0, "LEVEL_CORNERS_Z_HOP must be >= 0. Please update your configuration.");

#if HAS_LEVELING
static bool leveling_was_active = false;
#endif

#ifndef LEVEL_CORNERS_LEVELING_ORDER
#define LEVEL_CORNERS_LEVELING_ORDER { LF, RF, LB, RB } // Default
//#define LEVEL_CORNERS_LEVELING_ORDER { LF, LB, RF } // 3 hard-coded points
Expand Down
2 changes: 0 additions & 2 deletions Marlin/src/lcd/menu/menu_bed_leveling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@
// Motion > Level Bed handlers
//

static uint8_t manual_probe_index;

// LCD probed points are from defaults
constexpr uint8_t total_probe_points = TERN(AUTO_BED_LEVELING_3POINT, 3, GRID_MAX_POINTS);

Expand Down
9 changes: 9 additions & 0 deletions Marlin/src/lcd/menu/menu_motion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,15 @@ void lcd_move_x() { _lcd_move_xyz(GET_TEXT(MSG_MOVE_X), X_AXIS); }

#endif // E_MANUAL

#if EITHER(PROBE_OFFSET_WIZARD, X_AXIS_TWIST_COMPENSATION)

void _goto_manual_move_z(const_float_t scale) {
ui.manual_move.menu_scale = scale;
ui.goto_screen(lcd_move_z);
}

#endif

//
// "Motion" > "Move Xmm" > "Move XYZ" submenu
//
Expand Down
11 changes: 2 additions & 9 deletions Marlin/src/lcd/menu/menu_probe_offset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,11 @@
#include "../../feature/bedlevel/bedlevel.h"
#endif

void _goto_manual_move_z(const_float_t);

// Global storage
float z_offset_backup, calculated_z_offset, z_offset_ref;

#if HAS_LEVELING
bool leveling_was_active;
#endif

inline void z_clearance_move() {
do_z_clearance(
#ifdef Z_AFTER_HOMING
Expand All @@ -65,11 +63,6 @@ void set_offset_and_go_back(const_float_t z) {
ui.goto_previous_screen_no_defer();
}

void _goto_manual_move_z(const_float_t scale) {
ui.manual_move.menu_scale = scale;
ui.goto_screen(lcd_move_z);
}

void probe_offset_wizard_menu() {
START_MENU();
calculated_z_offset = probe.offset.z + current_position.z - z_offset_ref;
Expand Down
Loading

0 comments on commit 17e77c3

Please sign in to comment.