Add conditionals for kinematics, leveling

2.0.x
Scott Lahteine 8 years ago
parent 21514568fd
commit 6ab54c60b1

@ -61,12 +61,16 @@
#define NORMAL_AXIS X_AXIS
#endif
#define IS_SCARA (ENABLED(MORGAN_SCARA) || ENABLED(MAKERARM_SCARA))
#define IS_KINEMATIC (ENABLED(DELTA) || IS_SCARA)
#define IS_CARTESIAN !IS_KINEMATIC
/**
* SCARA
* SCARA cannot use SLOWDOWN and requires QUICKHOME
*/
#if ENABLED(SCARA)
#if IS_SCARA
#undef SLOWDOWN
#define QUICK_HOME //SCARA needs Quickhome
#define QUICK_HOME
#endif
/**
@ -132,12 +136,6 @@
#define HOMING_Z_WITH_PROBE (HAS_BED_PROBE && Z_HOME_DIR < 0 && ENABLED(Z_MIN_PROBE_USES_Z_MIN_ENDSTOP_PIN))
// Boundaries for probing based on set limits
#define MIN_PROBE_X (max(X_MIN_POS, X_MIN_POS + X_PROBE_OFFSET_FROM_EXTRUDER))
#define MAX_PROBE_X (min(X_MAX_POS, X_MAX_POS + X_PROBE_OFFSET_FROM_EXTRUDER))
#define MIN_PROBE_Y (max(Y_MIN_POS, Y_MIN_POS + Y_PROBE_OFFSET_FROM_EXTRUDER))
#define MAX_PROBE_Y (min(Y_MAX_POS, Y_MAX_POS + Y_PROBE_OFFSET_FROM_EXTRUDER))
#define HAS_Z_SERVO_ENDSTOP (defined(Z_ENDSTOP_SERVO_NR) && Z_ENDSTOP_SERVO_NR >= 0)
/**
@ -657,17 +655,27 @@
#ifndef DELTA_DIAGONAL_ROD_TRIM_TOWER_3
#define DELTA_DIAGONAL_ROD_TRIM_TOWER_3 0.0
#endif
#if ENABLED(AUTO_BED_LEVELING_GRID)
#define DELTA_BED_LEVELING_GRID
#endif
#endif
/**
* When not using other bed leveling...
* Specify the exact style of auto bed leveling
*
* 3POINT - 3 Point Probing with the least-squares solution.
* LINEAR - Grid Probing with the least-squares solution.
* NONLINEAR - Grid Probing with a mesh solution. Best for large beds.
*/
#if ENABLED(AUTO_BED_LEVELING_FEATURE) && DISABLED(AUTO_BED_LEVELING_GRID) && DISABLED(DELTA_BED_LEVELING_GRID)
#if ENABLED(AUTO_BED_LEVELING_FEATURE)
#if DISABLED(AUTO_BED_LEVELING_GRID)
#define AUTO_BED_LEVELING_LINEAR
#define AUTO_BED_LEVELING_3POINT
#elif IS_KINEMATIC
#define AUTO_BED_LEVELING_NONLINEAR
#else
#define AUTO_BED_LEVELING_LINEAR
#endif
#endif
#define PLANNER_LEVELING (ENABLED(MESH_BED_LEVELING) || ENABLED(AUTO_BED_LEVELING_LINEAR))
/**
* Buzzer/Speaker
@ -702,4 +710,18 @@
#define Z_PROBE_TRAVEL_HEIGHT Z_HOMING_HEIGHT
#endif
#if IS_KINEMATIC
// Check for this in the code instead
#define MIN_PROBE_X X_MIN_POS
#define MAX_PROBE_X X_MAX_POS
#define MIN_PROBE_Y Y_MIN_POS
#define MAX_PROBE_Y Y_MAX_POS
#else
// Boundaries for probing based on set limits
#define MIN_PROBE_X (max(X_MIN_POS, X_MIN_POS + X_PROBE_OFFSET_FROM_EXTRUDER))
#define MAX_PROBE_X (min(X_MAX_POS, X_MAX_POS + X_PROBE_OFFSET_FROM_EXTRUDER))
#define MIN_PROBE_Y (max(Y_MIN_POS, Y_MIN_POS + Y_PROBE_OFFSET_FROM_EXTRUDER))
#define MAX_PROBE_Y (min(Y_MAX_POS, Y_MAX_POS + Y_PROBE_OFFSET_FROM_EXTRUDER))
#endif
#endif // CONDITIONALS_POST_H

@ -313,7 +313,7 @@ float code_value_temp_diff();
extern int delta_grid_spacing[2];
void adjust_delta(float cartesian[XYZ]);
#endif
#elif ENABLED(SCARA)
#elif IS_SCARA
extern float delta[ABC];
extern float axis_scaling[ABC]; // Build size scaling
void inverse_kinematics(const float cartesian[XYZ]);

@ -36,12 +36,11 @@
#if ENABLED(AUTO_BED_LEVELING_FEATURE)
#include "vector_3.h"
#if ENABLED(AUTO_BED_LEVELING_GRID)
#include "qr_solve.h"
#endif
#endif // AUTO_BED_LEVELING_FEATURE
#endif
#if ENABLED(MESH_BED_LEVELING)
#if ENABLED(AUTO_BED_LEVELING_LINEAR)
#include "qr_solve.h"
#elif ENABLED(MESH_BED_LEVELING)
#include "mesh_bed_leveling.h"
#endif
@ -497,7 +496,12 @@ static uint8_t target_extruder;
#endif
#if ENABLED(SCARA)
#if IS_SCARA
// Float constants for SCARA calculations
const float L1 = SCARA_LINKAGE_1, L2 = SCARA_LINKAGE_2,
L1_2 = sq(float(L1)), L1_2_2 = 2.0 * L1_2,
L2_2 = sq(float(L2));
float delta_segments_per_second = SCARA_SEGMENTS_PER_SECOND,
delta[ABC],
axis_scaling[ABC] = { 1, 1, 1 }, // Build size scaling, default to 1
@ -651,7 +655,7 @@ inline void sync_plan_position() {
}
inline void sync_plan_position_e() { planner.set_e_position_mm(current_position[E_AXIS]); }
#if ENABLED(DELTA) || ENABLED(SCARA)
#if IS_KINEMATIC
inline void sync_plan_position_delta() {
#if ENABLED(DEBUG_LEVELING_FEATURE)
if (DEBUGGING(LEVELING)) DEBUG_POS("sync_plan_position_delta", current_position);
@ -2161,7 +2165,7 @@ static void clean_up_after_endstop_or_probe_move() {
// Prevent stepper_inactive_time from running out and EXTRUDER_RUNOUT_PREVENT from extruding
refresh_cmd_timeout();
#if ENABLED(AUTO_BED_LEVELING_FEATURE)
#if ENABLED(AUTO_BED_LEVELING_LINEAR)
planner.bed_level_matrix.set_to_identity();
#endif
@ -2272,7 +2276,7 @@ static void clean_up_after_endstop_or_probe_move() {
#if ENABLED(AUTO_BED_LEVELING_FEATURE)
#if DISABLED(DELTA)
#if ENABLED(AUTO_BED_LEVELING_LINEAR)
/**
* Get the stepper positions, apply the rotation matrix
@ -2302,9 +2306,7 @@ static void clean_up_after_endstop_or_probe_move() {
return pos;
}
#endif // !DELTA
#if ENABLED(DELTA)
#elif ENABLED(AUTO_BED_LEVELING_NONLINEAR)
/**
* All DELTA leveling in the Marlin uses NONLINEAR_BED_LEVELING
@ -2870,7 +2872,7 @@ inline void gcode_G4() {
SERIAL_ECHOPGM("Machine Type: ");
#if ENABLED(DELTA)
SERIAL_ECHOLNPGM("Delta");
#elif ENABLED(SCARA)
#elif IS_SCARA
SERIAL_ECHOLNPGM("SCARA");
#elif ENABLED(COREXY) || ENABLED(COREXZ) || ENABLED(COREYZ)
SERIAL_ECHOLNPGM("Core");
@ -2947,11 +2949,12 @@ inline void gcode_G28() {
stepper.synchronize();
// For auto bed leveling, clear the level matrix
#if ENABLED(AUTO_BED_LEVELING_FEATURE)
#if ENABLED(AUTO_BED_LEVELING_LINEAR)
planner.bed_level_matrix.set_to_identity();
#if ENABLED(DELTA)
reset_bed_level();
#endif
#if ENABLED(AUTO_BED_LEVELING_NONLINEAR)
reset_bed_level();
#endif
// Always home with tool 0 active
@ -3533,7 +3536,7 @@ inline void gcode_G28() {
#if ENABLED(AUTO_BED_LEVELING_GRID)
#if DISABLED(DELTA)
#if ENABLED(AUTO_BED_LEVELING_LINEAR)
bool do_topography_map = verbose_level > 2 || code_seen('T');
#endif
@ -3544,7 +3547,7 @@ inline void gcode_G28() {
int auto_bed_leveling_grid_points = AUTO_BED_LEVELING_GRID_POINTS;
#if DISABLED(DELTA)
#if ENABLED(AUTO_BED_LEVELING_LINEAR)
if (code_seen('P')) auto_bed_leveling_grid_points = code_value_int();
if (auto_bed_leveling_grid_points < 2) {
SERIAL_PROTOCOLLNPGM("?Number of probed (P)oints is implausible (2 minimum).");
@ -3594,17 +3597,19 @@ inline void gcode_G28() {
if (!dryrun) {
#if ENABLED(AUTO_BED_LEVELING_LINEAR)
// Reset the bed_level_matrix because leveling
// needs to be done without leveling enabled.
planner.bed_level_matrix.set_to_identity();
#endif
//
// Re-orient the current position without leveling
// based on where the steppers are positioned.
//
#if ENABLED(DELTA) || ENABLED(SCARA)
#if IS_KINEMATIC
#if ENABLED(DELTA)
#if ENABLED(AUTO_BED_LEVELING_NONLINEAR)
reset_bed_level();
#endif
@ -3639,12 +3644,14 @@ inline void gcode_G28() {
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)
#if ENABLED(AUTO_BED_LEVELING_NONLINEAR)
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
#elif ENABLED(AUTO_BED_LEVELING_LINEAR)
/**
* solve the plane equation ax + by + d = z
* A is the matrix with rows [x y 1] for all the probed points
@ -3660,7 +3667,8 @@ inline void gcode_G28() {
eqnBVector[abl2], // "B" vector of Z points
mean = 0.0;
int8_t indexIntoAB[auto_bed_leveling_grid_points][auto_bed_leveling_grid_points];
#endif // !DELTA
#endif // AUTO_BED_LEVELING_LINEAR
int probePointCounter = 0;
bool zig = auto_bed_leveling_grid_points & 1; //always end at [RIGHT_PROBE_BED_POSITION, BACK_PROBE_BED_POSITION]
@ -3694,16 +3702,19 @@ inline void gcode_G28() {
float measured_z = probe_pt(xProbe, yProbe, stow_probe_after_each, verbose_level);
#if DISABLED(DELTA)
mean += measured_z;
#if ENABLED(AUTO_BED_LEVELING_LINEAR)
mean += measured_z;
eqnBVector[probePointCounter] = measured_z;
eqnAMatrix[probePointCounter + 0 * abl2] = xProbe;
eqnAMatrix[probePointCounter + 1 * abl2] = yProbe;
eqnAMatrix[probePointCounter + 2 * abl2] = 1;
indexIntoAB[xCount][yCount] = probePointCounter;
#else
#elif ENABLED(AUTO_BED_LEVELING_NONLINEAR)
bed_level[xCount][yCount] = measured_z + zoffset;
#endif
probePointCounter++;
@ -3713,7 +3724,7 @@ inline void gcode_G28() {
} //xProbe
} //yProbe
#else // !AUTO_BED_LEVELING_GRID
#elif ENABLED(AUTO_BED_LEVELING_3POINT)
#if ENABLED(DEBUG_LEVELING_FEATURE)
if (DEBUGGING(LEVELING)) SERIAL_ECHOLNPGM("> 3-point Leveling");
@ -3759,12 +3770,12 @@ inline void gcode_G28() {
// Calculate leveling, print reports, correct the position
#if ENABLED(AUTO_BED_LEVELING_GRID)
#if ENABLED(DELTA)
#if ENABLED(AUTO_BED_LEVELING_NONLINEAR)
if (!dryrun) extrapolate_unprobed_bed_level();
print_bed_level();
#else // !DELTA
#elif ENABLED(AUTO_BED_LEVELING_LINEAR)
// solve lsq problem
double plane_equation_coefficients[3];
@ -3860,11 +3871,11 @@ inline void gcode_G28() {
}
} //do_topography_map
#endif //!DELTA
#endif // AUTO_BED_LEVELING_LINEAR
#endif // AUTO_BED_LEVELING_GRID
#if DISABLED(DELTA)
#if ENABLED(AUTO_BED_LEVELING_LINEAR)
if (verbose_level > 0)
planner.bed_level_matrix.debug("\n\nBed Level Correction Matrix:");
@ -4358,10 +4369,10 @@ inline void gcode_M42() {
if (verbose_level > 2)
SERIAL_PROTOCOLLNPGM("Positioning the probe...");
#if ENABLED(DELTA)
#if ENABLED(AUTO_BED_LEVELING_NONLINEAR)
// we don't do bed level correction in M48 because we want the raw data when we probe
reset_bed_level();
#elif ENABLED(AUTO_BED_LEVELING_FEATURE)
#elif ENABLED(AUTO_BED_LEVELING_LINEAR)
// we don't do bed level correction in M48 because we want the raw data when we probe
planner.bed_level_matrix.set_to_identity();
#endif
@ -6361,7 +6372,7 @@ inline void gcode_M503() {
lastpos[i] = destination[i] = current_position[i];
// Define runplan for move axes
#if ENABLED(DELTA)
#if IS_KINEMATIC
#define RUNPLAN(RATE_MM_S) inverse_kinematics(destination); \
planner.buffer_line(delta[X_AXIS], delta[Y_AXIS], delta[Z_AXIS], destination[E_AXIS], RATE_MM_S, active_extruder);
#else
@ -6482,7 +6493,7 @@ inline void gcode_M503() {
destination[E_AXIS] = lastpos[E_AXIS];
planner.set_e_position_mm(current_position[E_AXIS]);
#if ENABLED(DELTA)
#if IS_KINEMATIC
// Move XYZ to starting position, then E
inverse_kinematics(lastpos);
planner.buffer_line(delta[X_AXIS], delta[Y_AXIS], delta[Z_AXIS], destination[E_AXIS], FILAMENT_CHANGE_XY_FEEDRATE, active_extruder);
@ -6925,7 +6936,7 @@ void tool_change(const uint8_t tmp_extruder, const float fr_mm_s/*=0.0*/, bool n
* Z software endstop. But this is technically correct (and
* there is no viable alternative).
*/
#if ENABLED(AUTO_BED_LEVELING_FEATURE)
#if ENABLED(AUTO_BED_LEVELING_LINEAR)
// Offset extruder, make sure to apply the bed level rotation matrix
vector_3 tmp_offset_vec = vector_3(hotend_offset[X_AXIS][tmp_extruder],
hotend_offset[Y_AXIS][tmp_extruder],
@ -7961,7 +7972,7 @@ void ok_to_send() {
stepper.get_axis_position_mm(C_AXIS));
}
#if ENABLED(AUTO_BED_LEVELING_FEATURE)
#if ENABLED(AUTO_BED_LEVELING_NONLINEAR)
// Adjust print surface height by linear interpolation over the bed_level array.
void adjust_delta(float cartesian[XYZ]) {
@ -8001,7 +8012,7 @@ void ok_to_send() {
SERIAL_ECHOPGM(" offset="); SERIAL_ECHOLN(offset);
*/
}
#endif // AUTO_BED_LEVELING_FEATURE
#endif // AUTO_BED_LEVELING_NONLINEAR
#endif // DELTA
@ -8076,7 +8087,7 @@ void mesh_line_to_destination(float fr_mm_s, uint8_t x_splits = 0xff, uint8_t y_
}
#endif // MESH_BED_LEVELING
#if ENABLED(DELTA) || ENABLED(SCARA)
#if IS_KINEMATIC
inline bool prepare_kinematic_move_to(float target[NUM_AXIS]) {
float difference[NUM_AXIS];
@ -8103,7 +8114,7 @@ void mesh_line_to_destination(float fr_mm_s, uint8_t x_splits = 0xff, uint8_t y_
inverse_kinematics(target);
#if ENABLED(DELTA) && ENABLED(AUTO_BED_LEVELING_FEATURE)
#if ENABLED(DELTA) && ENABLED(AUTO_BED_LEVELING_NONLINEAR)
if (!bed_leveling_in_progress) adjust_delta(target);
#endif
@ -8115,7 +8126,7 @@ void mesh_line_to_destination(float fr_mm_s, uint8_t x_splits = 0xff, uint8_t y_
return true;
}
#endif // DELTA || SCARA
#endif // IS_KINEMATIC
#if ENABLED(DUAL_X_CARRIAGE)
@ -8161,7 +8172,7 @@ void mesh_line_to_destination(float fr_mm_s, uint8_t x_splits = 0xff, uint8_t y_
#endif // DUAL_X_CARRIAGE
#if DISABLED(DELTA) && DISABLED(SCARA)
#if !IS_KINEMATIC
inline bool prepare_move_to_destination_cartesian() {
// Do not use feedrate_percentage for E or Z only moves
@ -8181,7 +8192,7 @@ void mesh_line_to_destination(float fr_mm_s, uint8_t x_splits = 0xff, uint8_t y_
return true;
}
#endif // !DELTA && !SCARA
#endif // !IS_KINEMATIC
#if ENABLED(PREVENT_COLD_EXTRUSION)
@ -8220,7 +8231,7 @@ void prepare_move_to_destination() {
prevent_dangerous_extrude(current_position[E_AXIS], destination[E_AXIS]);
#endif
#if ENABLED(DELTA) || ENABLED(SCARA)
#if IS_KINEMATIC
if (!prepare_kinematic_move_to(destination)) return;
#else
#if ENABLED(DUAL_X_CARRIAGE)
@ -8356,9 +8367,9 @@ void prepare_move_to_destination() {
clamp_to_software_endstops(arc_target);
#if ENABLED(DELTA) || ENABLED(SCARA)
#if IS_KINEMATIC
inverse_kinematics(arc_target);
#if ENABLED(DELTA) && ENABLED(AUTO_BED_LEVELING_FEATURE)
#if ENABLED(DELTA) && ENABLED(AUTO_BED_LEVELING_NONLINEAR)
adjust_delta(arc_target);
#endif
planner.buffer_line(delta[X_AXIS], delta[Y_AXIS], delta[Z_AXIS], arc_target[E_AXIS], fr_mm_s, active_extruder);
@ -8368,9 +8379,9 @@ void prepare_move_to_destination() {
}
// Ensure last segment arrives at target location.
#if ENABLED(DELTA) || ENABLED(SCARA)
#if IS_KINEMATIC
inverse_kinematics(target);
#if ENABLED(DELTA) && ENABLED(AUTO_BED_LEVELING_FEATURE)
#if ENABLED(DELTA) && ENABLED(AUTO_BED_LEVELING_NONLINEAR)
adjust_delta(target);
#endif
planner.buffer_line(delta[X_AXIS], delta[Y_AXIS], delta[Z_AXIS], target[E_AXIS], fr_mm_s, active_extruder);

@ -330,7 +330,7 @@ void Config_StoreSettings() {
#endif
EEPROM_WRITE(lcd_contrast);
#if ENABLED(SCARA)
#if IS_SCARA
EEPROM_WRITE(axis_scaling); // 3 floats
#else
dummy = 1.0f;
@ -520,7 +520,7 @@ void Config_RetrieveSettings() {
#endif
EEPROM_READ(lcd_contrast);
#if ENABLED(SCARA)
#if IS_SCARA
EEPROM_READ(axis_scaling); // 3 floats
#else
EEPROM_READ(dummy);
@ -584,7 +584,7 @@ void Config_ResetDefault() {
planner.axis_steps_per_mm[i] = tmp1[i];
planner.max_feedrate_mm_s[i] = tmp2[i];
planner.max_acceleration_mm_per_s2[i] = tmp3[i];
#if ENABLED(SCARA)
#if IS_SCARA
if (i < COUNT(axis_scaling))
axis_scaling[i] = 1;
#endif
@ -716,7 +716,7 @@ void Config_PrintSettings(bool forReplay) {
CONFIG_ECHO_START;
#if ENABLED(SCARA)
#if IS_SCARA
if (!forReplay) {
SERIAL_ECHOLNPGM("Scaling factors:");
CONFIG_ECHO_START;

@ -98,7 +98,7 @@ float Planner::min_feedrate_mm_s,
Planner::max_e_jerk,
Planner::min_travel_feedrate_mm_s;
#if ENABLED(AUTO_BED_LEVELING_FEATURE)
#if ENABLED(AUTO_BED_LEVELING_LINEAR)
matrix_3x3 Planner::bed_level_matrix; // Transform to compensate for bed level
#endif
@ -138,7 +138,7 @@ void Planner::init() {
memset(position, 0, sizeof(position)); // clear position
LOOP_XYZE(i) previous_speed[i] = 0.0;
previous_nominal_speed = 0.0;
#if ENABLED(AUTO_BED_LEVELING_FEATURE)
#if ENABLED(AUTO_BED_LEVELING_LINEAR)
bed_level_matrix.set_to_identity();
#endif
}
@ -521,7 +521,7 @@ void Planner::check_axes_activity() {
#endif
}
#if ENABLED(AUTO_BED_LEVELING_FEATURE) || ENABLED(MESH_BED_LEVELING)
#if PLANNER_LEVELING
void Planner::apply_leveling(
#if ENABLED(MESH_BED_LEVELING)
@ -551,7 +551,7 @@ void Planner::check_axes_activity() {
#endif
}
#endif
#endif // PLANNER_LEVELING
/**
* Planner::buffer_line
@ -1193,7 +1193,7 @@ void Planner::reset_acceleration_rates() {
// Recalculate position, steps_to_mm if axis_steps_per_mm changes!
void Planner::refresh_positioning() {
LOOP_XYZE(i) steps_to_mm[i] = 1.0 / axis_steps_per_mm[i];
#if ENABLED(DELTA) || ENABLED(SCARA)
#if IS_KINEMATIC
inverse_kinematics(current_position);
set_position_mm(delta[X_AXIS], delta[Y_AXIS], delta[Z_AXIS], current_position[E_AXIS]);
#else

@ -188,7 +188,7 @@ void cubic_b_spline(const float position[NUM_AXIS], const float target[NUM_AXIS]
bez_target[E_AXIS] = interp(position[E_AXIS], target[E_AXIS], t);
clamp_to_software_endstops(bez_target);
#if ENABLED(DELTA) || ENABLED(SCARA)
#if IS_KINEMATIC
inverse_kinematics(bez_target);
#if ENABLED(DELTA) && ENABLED(AUTO_BED_LEVELING_FEATURE)
adjust_delta(bez_target);

@ -22,7 +22,7 @@
#include "qr_solve.h"
#if ENABLED(AUTO_BED_LEVELING_GRID)
#if ENABLED(AUTO_BED_LEVELING_LINEAR)
#include <stdlib.h>
#include <math.h>

@ -1418,7 +1418,7 @@ void kill_screen(const char* lcd_msg) {
*
*/
#if ENABLED(DELTA) || ENABLED(SCARA)
#if IS_KINEMATIC
#define _MOVE_XYZ_ALLOWED (axis_homed[X_AXIS] && axis_homed[Y_AXIS] && axis_homed[Z_AXIS])
#else
#define _MOVE_XYZ_ALLOWED true
@ -1823,7 +1823,7 @@ void kill_screen(const char* lcd_msg) {
#if ENABLED(ABORT_ON_ENDSTOP_HIT_FEATURE_ENABLED)
MENU_ITEM_EDIT(bool, MSG_ENDSTOP_ABORT, &stepper.abort_on_endstop_hit);
#endif
#if ENABLED(SCARA)
#if IS_SCARA
MENU_ITEM_EDIT(float74, MSG_XSCALE, &axis_scaling[X_AXIS], 0.5, 2);
MENU_ITEM_EDIT(float74, MSG_YSCALE, &axis_scaling[Y_AXIS], 0.5, 2);
#endif

Loading…
Cancel
Save