Browse Source

Merge pull request #4651 from thinkyhead/rc_homing_vs_leveling_z

Improvements to homing / leveling
pull/1/head
Scott Lahteine 8 years ago
committed by GitHub
parent
commit
4d4c00d69c
  1. 2
      Marlin/Configuration.h
  2. 1
      Marlin/Marlin.h
  3. 130
      Marlin/Marlin_main.cpp
  4. 7
      Marlin/SanityCheck.h
  5. 3
      Marlin/configuration_store.cpp
  6. 2
      Marlin/example_configurations/Cartesio/Configuration.h
  7. 2
      Marlin/example_configurations/Felix/Configuration.h
  8. 2
      Marlin/example_configurations/Felix/DUAL/Configuration.h
  9. 2
      Marlin/example_configurations/Hephestos/Configuration.h
  10. 2
      Marlin/example_configurations/Hephestos_2/Configuration.h
  11. 2
      Marlin/example_configurations/K8200/Configuration.h
  12. 2
      Marlin/example_configurations/K8400/Configuration.h
  13. 2
      Marlin/example_configurations/K8400/Dual-head/Configuration.h
  14. 2
      Marlin/example_configurations/RepRapWorld/Megatronics/Configuration.h
  15. 2
      Marlin/example_configurations/RigidBot/Configuration.h
  16. 2
      Marlin/example_configurations/SCARA/Configuration.h
  17. 2
      Marlin/example_configurations/TAZ4/Configuration.h
  18. 2
      Marlin/example_configurations/WITBOX/Configuration.h
  19. 2
      Marlin/example_configurations/adafruit/ST7565/Configuration.h
  20. 2
      Marlin/example_configurations/makibox/Configuration.h
  21. 2
      Marlin/example_configurations/tvrrug/Round2/Configuration.h

2
Marlin/Configuration.h

@ -689,7 +689,7 @@
// Set the number of grid points per dimension.
// You probably don't need more than 3 (squared=9).
#define AUTO_BED_LEVELING_GRID_POINTS 2
#define AUTO_BED_LEVELING_GRID_POINTS 3
#else // !AUTO_BED_LEVELING_GRID

1
Marlin/Marlin.h

@ -379,6 +379,7 @@ extern uint8_t active_extruder;
extern float mixing_factor[MIXING_STEPPERS];
#endif
void update_software_endstops(AxisEnum axis);
void calculate_volumetric_multipliers();
// Buzzer

130
Marlin/Marlin_main.cpp

@ -1470,7 +1470,7 @@ XYZ_CONSTS_FROM_CONFIG(signed char, home_dir, HOME_DIR);
* the software endstop positions must be refreshed to remain
* at the same positions relative to the machine.
*/
static void update_software_endstops(AxisEnum axis) {
void update_software_endstops(AxisEnum axis) {
float offs = LOGICAL_POSITION(0, axis);
#if ENABLED(DUAL_X_CARRIAGE)
@ -1530,7 +1530,7 @@ static void set_home_offset(AxisEnum axis, float v) {
static void set_axis_is_at_home(AxisEnum axis) {
#if ENABLED(DEBUG_LEVELING_FEATURE)
if (DEBUGGING(LEVELING)) {
SERIAL_ECHOPAIR(">>> set_axis_is_at_home(", axis);
SERIAL_ECHOPAIR(">>> set_axis_is_at_home(", axis_codes[axis]);
SERIAL_ECHOLNPGM(")");
}
#endif
@ -1606,7 +1606,7 @@ static void set_axis_is_at_home(AxisEnum axis) {
}
#if ENABLED(DEBUG_LEVELING_FEATURE)
if (DEBUGGING(LEVELING)) {
SERIAL_ECHOPAIR("<<< set_axis_is_at_home(", axis);
SERIAL_ECHOPAIR("<<< set_axis_is_at_home(", axis_codes[axis]);
SERIAL_ECHOLNPGM(")");
}
#endif
@ -1638,15 +1638,6 @@ inline void line_to_z(float zPosition) {
planner.buffer_line(current_position[X_AXIS], current_position[Y_AXIS], zPosition, current_position[E_AXIS], feedrate_mm_s, active_extruder);
}
inline void line_to_axis_pos(AxisEnum axis, float where, float fr_mm_s = 0.0) {
float old_feedrate_mm_s = feedrate_mm_s;
current_position[axis] = where;
feedrate_mm_s = (fr_mm_s != 0.0) ? fr_mm_s : homing_feedrate_mm_s[axis];
planner.buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], feedrate_mm_s, active_extruder);
stepper.synchronize();
feedrate_mm_s = old_feedrate_mm_s;
}
//
// line_to_destination
// Move the planner, not necessarily synced with current_position
@ -2127,10 +2118,36 @@ static void clean_up_after_endstop_or_probe_move() {
return false;
}
static void do_probe_move(float z, float fr_mm_m) {
#if ENABLED(DEBUG_LEVELING_FEATURE)
if (DEBUGGING(LEVELING)) DEBUG_POS(">>> do_probe_move", current_position);
#endif
// Move down until probe triggered
do_blocking_move_to_z(LOGICAL_Z_POSITION(z), MMM_TO_MMS(fr_mm_m));
// Clear endstop flags
endstops.hit_on_purpose();
// Get Z where the steppers were interrupted
set_current_from_steppers_for_axis(Z_AXIS);
// Tell the planner where we actually are
SYNC_PLAN_POSITION_KINEMATIC();
#if ENABLED(DEBUG_LEVELING_FEATURE)
if (DEBUGGING(LEVELING)) DEBUG_POS("<<< do_probe_move", current_position);
#endif
}
// Do a single Z probe and return with current_position[Z_AXIS]
// at the height where the probe triggered.
static float run_z_probe() {
#if ENABLED(DEBUG_LEVELING_FEATURE)
if (DEBUGGING(LEVELING)) DEBUG_POS(">>> run_z_probe", current_position);
#endif
// Prevent stepper_inactive_time from running out and EXTRUDER_RUNOUT_PREVENT from extruding
refresh_cmd_timeout();
@ -2139,26 +2156,27 @@ static void clean_up_after_endstop_or_probe_move() {
#endif
#if ENABLED(PROBE_DOUBLE_TOUCH)
do_blocking_move_to_z(-(Z_MAX_LENGTH + 10), MMM_TO_MMS(Z_PROBE_SPEED_FAST));
endstops.hit_on_purpose();
set_current_from_steppers_for_axis(Z_AXIS);
SYNC_PLAN_POSITION_KINEMATIC();
// move up the retract distance
// Do a first probe at the fast speed
do_probe_move(-(Z_MAX_LENGTH) - 10, Z_PROBE_SPEED_FAST);
// move up by the bump distance
do_blocking_move_to_z(current_position[Z_AXIS] + home_bump_mm(Z_AXIS), MMM_TO_MMS(Z_PROBE_SPEED_FAST));
#else
// move fast, close to the bed
do_blocking_move_to_z(home_bump_mm(Z_AXIS), MMM_TO_MMS(Z_PROBE_SPEED_FAST));
float z = LOGICAL_Z_POSITION(home_bump_mm(Z_AXIS));
if (zprobe_zoffset < 0) z -= zprobe_zoffset;
do_blocking_move_to_z(z, MMM_TO_MMS(Z_PROBE_SPEED_FAST));
#endif
// move down slowly to find bed
do_blocking_move_to_z(current_position[Z_AXIS] -2.0*home_bump_mm(Z_AXIS), MMM_TO_MMS(Z_PROBE_SPEED_SLOW));
endstops.hit_on_purpose();
set_current_from_steppers_for_axis(Z_AXIS);
SYNC_PLAN_POSITION_KINEMATIC();
do_probe_move(-10, Z_PROBE_SPEED_SLOW);
#if ENABLED(DEBUG_LEVELING_FEATURE)
if (DEBUGGING(LEVELING)) DEBUG_POS("run_z_probe", current_position);
if (DEBUGGING(LEVELING)) DEBUG_POS("<<< run_z_probe", current_position);
#endif
return current_position[Z_AXIS];
@ -2393,6 +2411,15 @@ static void clean_up_after_endstop_or_probe_move() {
* Home an individual axis
*/
static void do_homing_move(AxisEnum axis, float where, float fr_mm_s = 0.0) {
float old_feedrate_mm_s = feedrate_mm_s;
current_position[axis] = where;
feedrate_mm_s = (fr_mm_s != 0.0) ? fr_mm_s : homing_feedrate_mm_s[axis];
planner.buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], feedrate_mm_s, active_extruder);
stepper.synchronize();
feedrate_mm_s = old_feedrate_mm_s;
}
#define HOMEAXIS(LETTER) homeaxis(LETTER##_AXIS)
static void homeaxis(AxisEnum axis) {
@ -2403,7 +2430,7 @@ static void homeaxis(AxisEnum axis) {
#if ENABLED(DEBUG_LEVELING_FEATURE)
if (DEBUGGING(LEVELING)) {
SERIAL_ECHOPAIR(">>> homeaxis(", axis);
SERIAL_ECHOPAIR(">>> homeaxis(", axis_codes[axis]);
SERIAL_ECHOLNPGM(")");
}
#endif
@ -2415,8 +2442,8 @@ static void homeaxis(AxisEnum axis) {
home_dir(axis);
// Homing Z towards the bed? Deploy the Z probe or endstop.
#if HAS_BED_PROBE && DISABLED(Z_MIN_PROBE_ENDSTOP)
if (axis == Z_AXIS && axis_home_dir < 0) {
#if HAS_BED_PROBE && Z_HOME_DIR < 0 && DISABLED(Z_MIN_PROBE_ENDSTOP)
if (axis == Z_AXIS) {
#if ENABLED(DEBUG_LEVELING_FEATURE)
if (DEBUGGING(LEVELING)) SERIAL_ECHOPGM("> ");
#endif
@ -2434,17 +2461,17 @@ static void homeaxis(AxisEnum axis) {
#endif
// Move towards the endstop until an endstop is triggered
line_to_axis_pos(axis, 1.5 * max_length(axis) * axis_home_dir);
do_homing_move(axis, 1.5 * max_length(axis) * axis_home_dir);
// Set the axis position as setup for the move
current_position[axis] = 0;
sync_plan_position();
// Move away from the endstop by the axis HOME_BUMP_MM
line_to_axis_pos(axis, -home_bump_mm(axis) * axis_home_dir);
do_homing_move(axis, -home_bump_mm(axis) * axis_home_dir);
// Move slowly towards the endstop until triggered
line_to_axis_pos(axis, 2 * home_bump_mm(axis) * axis_home_dir, get_homing_bump_feedrate(axis));
do_homing_move(axis, 2 * home_bump_mm(axis) * axis_home_dir, get_homing_bump_feedrate(axis));
// reset current_position to 0 to reflect hitting endpoint
current_position[axis] = 0;
@ -2468,7 +2495,7 @@ static void homeaxis(AxisEnum axis) {
if (lockZ1) stepper.set_z_lock(true); else stepper.set_z2_lock(true);
// Move to the adjusted endstop height
line_to_axis_pos(axis, adj);
do_homing_move(axis, adj);
if (lockZ1) stepper.set_z_lock(false); else stepper.set_z2_lock(false);
stepper.set_homing_flag(false);
@ -2477,14 +2504,14 @@ static void homeaxis(AxisEnum axis) {
#if ENABLED(DELTA)
// retrace by the amount specified in endstop_adj
if (endstop_adj[axis] * axis_home_dir < 0) {
if (endstop_adj[axis] * Z_HOME_DIR < 0) {
#if ENABLED(DEBUG_LEVELING_FEATURE)
if (DEBUGGING(LEVELING)) {
SERIAL_ECHOPAIR("> endstop_adj = ", endstop_adj[axis]);
DEBUG_POS("", current_position);
}
#endif
line_to_axis_pos(axis, endstop_adj[axis]);
do_homing_move(axis, endstop_adj[axis]);
}
#endif
@ -2503,8 +2530,8 @@ static void homeaxis(AxisEnum axis) {
axis_homed[axis] = true;
// Put away the Z probe
#if HAS_BED_PROBE && DISABLED(Z_MIN_PROBE_ENDSTOP)
if (axis == Z_AXIS && axis_home_dir < 0) {
#if HAS_BED_PROBE && Z_HOME_DIR < 0 && DISABLED(Z_MIN_PROBE_ENDSTOP)
if (axis == Z_AXIS) {
#if ENABLED(DEBUG_LEVELING_FEATURE)
if (DEBUGGING(LEVELING)) SERIAL_ECHOPGM("> ");
#endif
@ -2514,11 +2541,11 @@ static void homeaxis(AxisEnum axis) {
#if ENABLED(DEBUG_LEVELING_FEATURE)
if (DEBUGGING(LEVELING)) {
SERIAL_ECHOPAIR("<<< homeaxis(", axis);
SERIAL_ECHOPAIR("<<< homeaxis(", axis_codes[axis]);
SERIAL_ECHOLNPGM(")");
}
#endif
}
} // homeaxis()
#if ENABLED(FWRETRACT)
@ -3475,7 +3502,7 @@ inline void gcode_G28() {
int verbose_level = code_seen('V') ? code_value_int() : 1;
if (verbose_level < 0 || verbose_level > 4) {
SERIAL_ECHOLNPGM("?(V)erbose Level is implausible (0-4).");
SERIAL_PROTOCOLLNPGM("?(V)erbose Level is implausible (0-4).");
return;
}
@ -3587,12 +3614,12 @@ inline void gcode_G28() {
#if ENABLED(AUTO_BED_LEVELING_GRID)
// probe at the points of a lattice grid
const int xGridSpacing = (right_probe_bed_position - left_probe_bed_position) / (auto_bed_leveling_grid_points - 1),
yGridSpacing = (back_probe_bed_position - front_probe_bed_position) / (auto_bed_leveling_grid_points - 1);
const float xGridSpacing = (right_probe_bed_position - left_probe_bed_position) / (auto_bed_leveling_grid_points - 1),
yGridSpacing = (back_probe_bed_position - front_probe_bed_position) / (auto_bed_leveling_grid_points - 1);
#if ENABLED(DELTA)
delta_grid_spacing[0] = xGridSpacing;
delta_grid_spacing[1] = yGridSpacing;
delta_grid_spacing[X_AXIS] = xGridSpacing;
delta_grid_spacing[Y_AXIS] = yGridSpacing;
float zoffset = zprobe_zoffset;
if (code_seen('Z')) zoffset += code_value_axis_units(Z_AXIS);
#else // !DELTA
@ -3614,10 +3641,11 @@ inline void gcode_G28() {
#endif // !DELTA
int probePointCounter = 0;
bool zig = (auto_bed_leveling_grid_points & 1) ? true : false; //always end at [RIGHT_PROBE_BED_POSITION, BACK_PROBE_BED_POSITION]
bool zig = auto_bed_leveling_grid_points & 1; //always end at [RIGHT_PROBE_BED_POSITION, BACK_PROBE_BED_POSITION]
for (int yCount = 0; yCount < auto_bed_leveling_grid_points; yCount++) {
double yProbe = front_probe_bed_position + yGridSpacing * yCount;
float yBase = front_probe_bed_position + yGridSpacing * yCount,
yProbe = floor(yProbe + (yProbe < 0 ? 0 : 0.5));
int xStart, xStop, xInc;
if (zig) {
@ -3634,13 +3662,13 @@ inline void gcode_G28() {
zig = !zig;
for (int xCount = xStart; xCount != xStop; xCount += xInc) {
double xProbe = left_probe_bed_position + xGridSpacing * xCount;
float xBase = left_probe_bed_position + xGridSpacing * xCount,
xProbe = floor(xProbe + (xProbe < 0 ? 0 : 0.5));
#if ENABLED(DELTA)
// Avoid probing the corners (outside the round or hexagon print surface) on a delta printer.
float distance_from_center = HYPOT(xProbe, yProbe);
if (distance_from_center > DELTA_PROBEABLE_RADIUS) continue;
#endif //DELTA
// Avoid probing outside the round or hexagonal area of a delta printer
if (sq(xProbe) + sq(yProbe) > sq(DELTA_PROBEABLE_RADIUS)) continue;
#endif
float measured_z = probe_pt(xProbe, yProbe, stow_probe_after_each, verbose_level);
@ -7875,12 +7903,12 @@ void clamp_to_software_endstops(float target[3]) {
// Adjust print surface height by linear interpolation over the bed_level array.
void adjust_delta(float cartesian[3]) {
if (delta_grid_spacing[0] == 0 || delta_grid_spacing[1] == 0) return; // G29 not done!
if (delta_grid_spacing[X_AXIS] == 0 || delta_grid_spacing[Y_AXIS] == 0) return; // G29 not done!
int half = (AUTO_BED_LEVELING_GRID_POINTS - 1) / 2;
float h1 = 0.001 - half, h2 = half - 0.001,
grid_x = max(h1, min(h2, RAW_X_POSITION(cartesian[X_AXIS]) / delta_grid_spacing[0])),
grid_y = max(h1, min(h2, RAW_Y_POSITION(cartesian[Y_AXIS]) / delta_grid_spacing[1]));
grid_x = max(h1, min(h2, RAW_X_POSITION(cartesian[X_AXIS]) / delta_grid_spacing[X_AXIS])),
grid_y = max(h1, min(h2, RAW_Y_POSITION(cartesian[Y_AXIS]) / delta_grid_spacing[Y_AXIS]));
int floor_x = floor(grid_x), floor_y = floor(grid_y);
float ratio_x = grid_x - floor_x, ratio_y = grid_y - floor_y,
z1 = bed_level[floor_x + half][floor_y + half],

7
Marlin/SanityCheck.h

@ -191,6 +191,13 @@
#if DISABLED(USE_XMAX_PLUG) && DISABLED(USE_YMAX_PLUG) && DISABLED(USE_ZMAX_PLUG)
#error "You probably want to use Max Endstops for DELTA!"
#endif
#if ENABLED(AUTO_BED_LEVELING_GRID)
#if (AUTO_BED_LEVELING_GRID_POINTS & 1) == 0
#error "DELTA requires an odd value for AUTO_BED_LEVELING_GRID_POINTS."
#elif AUTO_BED_LEVELING_GRID_POINTS < 3
#error "DELTA requires at least 3 AUTO_BED_LEVELING_GRID_POINTS."
#endif
#endif
#endif
/**

3
Marlin/configuration_store.cpp

@ -186,6 +186,9 @@ void Config_Postprocess() {
#endif
calculate_volumetric_multipliers();
// Software endstops depend on home_offset
LOOP_XYZ(i) update_software_endstops((AxisEnum)i);
}
#if ENABLED(EEPROM_SETTINGS)

2
Marlin/example_configurations/Cartesio/Configuration.h

@ -689,7 +689,7 @@
// Set the number of grid points per dimension.
// You probably don't need more than 3 (squared=9).
#define AUTO_BED_LEVELING_GRID_POINTS 2
#define AUTO_BED_LEVELING_GRID_POINTS 3
#else // !AUTO_BED_LEVELING_GRID

2
Marlin/example_configurations/Felix/Configuration.h

@ -671,7 +671,7 @@
// Set the number of grid points per dimension.
// You probably don't need more than 3 (squared=9).
#define AUTO_BED_LEVELING_GRID_POINTS 2
#define AUTO_BED_LEVELING_GRID_POINTS 3
#else // !AUTO_BED_LEVELING_GRID

2
Marlin/example_configurations/Felix/DUAL/Configuration.h

@ -669,7 +669,7 @@
// Set the number of grid points per dimension.
// You probably don't need more than 3 (squared=9).
#define AUTO_BED_LEVELING_GRID_POINTS 2
#define AUTO_BED_LEVELING_GRID_POINTS 3
#else // !AUTO_BED_LEVELING_GRID

2
Marlin/example_configurations/Hephestos/Configuration.h

@ -681,7 +681,7 @@
// Set the number of grid points per dimension.
// You probably don't need more than 3 (squared=9).
#define AUTO_BED_LEVELING_GRID_POINTS 2
#define AUTO_BED_LEVELING_GRID_POINTS 3
#else // !AUTO_BED_LEVELING_GRID

2
Marlin/example_configurations/Hephestos_2/Configuration.h

@ -683,7 +683,7 @@
// Set the number of grid points per dimension.
// You probably don't need more than 3 (squared=9).
#define AUTO_BED_LEVELING_GRID_POINTS 2
#define AUTO_BED_LEVELING_GRID_POINTS 3
#else // !AUTO_BED_LEVELING_GRID

2
Marlin/example_configurations/K8200/Configuration.h

@ -706,7 +706,7 @@
// Set the number of grid points per dimension.
// You probably don't need more than 3 (squared=9).
#define AUTO_BED_LEVELING_GRID_POINTS 2
#define AUTO_BED_LEVELING_GRID_POINTS 3
#else // !AUTO_BED_LEVELING_GRID

2
Marlin/example_configurations/K8400/Configuration.h

@ -689,7 +689,7 @@
// Set the number of grid points per dimension.
// You probably don't need more than 3 (squared=9).
#define AUTO_BED_LEVELING_GRID_POINTS 2
#define AUTO_BED_LEVELING_GRID_POINTS 3
#else // !AUTO_BED_LEVELING_GRID

2
Marlin/example_configurations/K8400/Dual-head/Configuration.h

@ -689,7 +689,7 @@
// Set the number of grid points per dimension.
// You probably don't need more than 3 (squared=9).
#define AUTO_BED_LEVELING_GRID_POINTS 2
#define AUTO_BED_LEVELING_GRID_POINTS 3
#else // !AUTO_BED_LEVELING_GRID

2
Marlin/example_configurations/RepRapWorld/Megatronics/Configuration.h

@ -689,7 +689,7 @@
// Set the number of grid points per dimension.
// You probably don't need more than 3 (squared=9).
#define AUTO_BED_LEVELING_GRID_POINTS 2
#define AUTO_BED_LEVELING_GRID_POINTS 3
#else // !AUTO_BED_LEVELING_GRID

2
Marlin/example_configurations/RigidBot/Configuration.h

@ -686,7 +686,7 @@
// Set the number of grid points per dimension.
// You probably don't need more than 3 (squared=9).
#define AUTO_BED_LEVELING_GRID_POINTS 2
#define AUTO_BED_LEVELING_GRID_POINTS 3
#else // !AUTO_BED_LEVELING_GRID

2
Marlin/example_configurations/SCARA/Configuration.h

@ -697,7 +697,7 @@
// Set the number of grid points per dimension.
// You probably don't need more than 3 (squared=9).
#define AUTO_BED_LEVELING_GRID_POINTS 2
#define AUTO_BED_LEVELING_GRID_POINTS 3
#else // !AUTO_BED_LEVELING_GRID

2
Marlin/example_configurations/TAZ4/Configuration.h

@ -710,7 +710,7 @@
// Set the number of grid points per dimension.
// You probably don't need more than 3 (squared=9).
#define AUTO_BED_LEVELING_GRID_POINTS 2
#define AUTO_BED_LEVELING_GRID_POINTS 3
#else // !AUTO_BED_LEVELING_GRID

2
Marlin/example_configurations/WITBOX/Configuration.h

@ -681,7 +681,7 @@
// Set the number of grid points per dimension.
// You probably don't need more than 3 (squared=9).
#define AUTO_BED_LEVELING_GRID_POINTS 2
#define AUTO_BED_LEVELING_GRID_POINTS 3
#else // !AUTO_BED_LEVELING_GRID

2
Marlin/example_configurations/adafruit/ST7565/Configuration.h

@ -689,7 +689,7 @@
// Set the number of grid points per dimension.
// You probably don't need more than 3 (squared=9).
#define AUTO_BED_LEVELING_GRID_POINTS 2
#define AUTO_BED_LEVELING_GRID_POINTS 3
#else // !AUTO_BED_LEVELING_GRID

2
Marlin/example_configurations/makibox/Configuration.h

@ -692,7 +692,7 @@
// Set the number of grid points per dimension.
// You probably don't need more than 3 (squared=9).
#define AUTO_BED_LEVELING_GRID_POINTS 2
#define AUTO_BED_LEVELING_GRID_POINTS 3
#else // !AUTO_BED_LEVELING_GRID

2
Marlin/example_configurations/tvrrug/Round2/Configuration.h

@ -679,7 +679,7 @@
// Set the number of grid points per dimension.
// You probably don't need more than 3 (squared=9).
#define AUTO_BED_LEVELING_GRID_POINTS 2
#define AUTO_BED_LEVELING_GRID_POINTS 3
#else // !AUTO_BED_LEVELING_GRID

Loading…
Cancel
Save