Operate in Native Machine Space

This commit is contained in:
Scott Lahteine
2017-11-02 23:59:42 -05:00
parent 31f112cf58
commit f8393a0908
36 changed files with 449 additions and 489 deletions

View File

@ -72,7 +72,7 @@ void recalc_delta_settings(const float radius, const float diagonal_rod, const f
/**
* Delta Inverse Kinematics
*
* Calculate the tower positions for a given logical
* Calculate the tower positions for a given machine
* position, storing the result in the delta[] array.
*
* This is an expensive calculation, requiring 3 square
@ -117,8 +117,8 @@ void recalc_delta_settings(const float radius, const float diagonal_rod, const f
SERIAL_ECHOLNPAIR(" C:", delta[C_AXIS]); \
}while(0)
void inverse_kinematics(const float logical[XYZ]) {
DELTA_LOGICAL_IK();
void inverse_kinematics(const float raw[XYZ]) {
DELTA_RAW_IK();
// DELTA_DEBUG();
}
@ -127,14 +127,10 @@ void inverse_kinematics(const float logical[XYZ]) {
* effector has the full range of XY motion.
*/
float delta_safe_distance_from_top() {
float cartesian[XYZ] = {
LOGICAL_X_POSITION(0),
LOGICAL_Y_POSITION(0),
LOGICAL_Z_POSITION(0)
};
float cartesian[XYZ] = { 0, 0, 0 };
inverse_kinematics(cartesian);
float distance = delta[A_AXIS];
cartesian[Y_AXIS] = LOGICAL_Y_POSITION(DELTA_PRINTABLE_RADIUS);
cartesian[Y_AXIS] = DELTA_PRINTABLE_RADIUS;
inverse_kinematics(cartesian);
return FABS(distance - delta[A_AXIS]);
}

View File

@ -47,7 +47,7 @@ void recalc_delta_settings(const float radius, const float diagonal_rod, const f
/**
* Delta Inverse Kinematics
*
* Calculate the tower positions for a given logical
* Calculate the tower positions for a given machine
* position, storing the result in the delta[] array.
*
* This is an expensive calculation, requiring 3 square
@ -88,16 +88,7 @@ void recalc_delta_settings(const float radius, const float diagonal_rod, const f
delta[C_AXIS] = DELTA_Z(C_AXIS); \
}while(0)
#define DELTA_LOGICAL_IK() do { \
const float raw[XYZ] = { \
RAW_X_POSITION(logical[X_AXIS]), \
RAW_Y_POSITION(logical[Y_AXIS]), \
RAW_Z_POSITION(logical[Z_AXIS]) \
}; \
DELTA_RAW_IK(); \
}while(0)
void inverse_kinematics(const float logical[XYZ]);
void inverse_kinematics(const float raw[XYZ]);
/**
* Calculate the highest Z position where the

View File

@ -73,7 +73,7 @@ bool relative_mode = false;
/**
* Cartesian Current Position
* Used to track the logical position as moves are queued.
* Used to track the native machine position as moves are queued.
* Used by 'line_to_current_position' to do a move after changing it.
* Used by 'SYNC_PLAN_POSITION_KINEMATIC' to update 'planner.position'.
*/
@ -197,20 +197,16 @@ void get_cartesian_from_steppers() {
stepper.get_axis_position_mm(B_AXIS),
stepper.get_axis_position_mm(C_AXIS)
);
cartes[X_AXIS] += LOGICAL_X_POSITION(0);
cartes[Y_AXIS] += LOGICAL_Y_POSITION(0);
cartes[Z_AXIS] += LOGICAL_Z_POSITION(0);
#elif IS_SCARA
forward_kinematics_SCARA(
stepper.get_axis_position_degrees(A_AXIS),
stepper.get_axis_position_degrees(B_AXIS)
);
cartes[X_AXIS] += LOGICAL_X_POSITION(0);
cartes[Y_AXIS] += LOGICAL_Y_POSITION(0);
cartes[Z_AXIS] = stepper.get_axis_position_mm(Z_AXIS);
#else
cartes[X_AXIS] = stepper.get_axis_position_mm(X_AXIS);
cartes[Y_AXIS] = stepper.get_axis_position_mm(Y_AXIS);
#if IS_SCARA
forward_kinematics_SCARA(
stepper.get_axis_position_degrees(A_AXIS),
stepper.get_axis_position_degrees(B_AXIS)
);
#else
cartes[X_AXIS] = stepper.get_axis_position_mm(X_AXIS);
cartes[Y_AXIS] = stepper.get_axis_position_mm(Y_AXIS);
#endif
cartes[Z_AXIS] = stepper.get_axis_position_mm(Z_AXIS);
#endif
}
@ -288,16 +284,16 @@ void line_to_destination(const float fr_mm_s) {
* Plan a move to (X, Y, Z) and set the current_position
* The final current_position may not be the one that was requested
*/
void do_blocking_move_to(const float &lx, const float &ly, const float &lz, const float &fr_mm_s/*=0.0*/) {
void do_blocking_move_to(const float &rx, const float &ry, const float &rz, const float &fr_mm_s/*=0.0*/) {
const float old_feedrate_mm_s = feedrate_mm_s;
#if ENABLED(DEBUG_LEVELING_FEATURE)
if (DEBUGGING(LEVELING)) print_xyz(PSTR(">>> do_blocking_move_to"), NULL, lx, ly, lz);
if (DEBUGGING(LEVELING)) print_xyz(PSTR(">>> do_blocking_move_to"), NULL, rx, ry, rz);
#endif
#if ENABLED(DELTA)
if (!position_is_reachable_xy(lx, ly)) return;
if (!position_is_reachable(rx, ry)) return;
feedrate_mm_s = fr_mm_s ? fr_mm_s : XY_PROBE_FEEDRATE_MM_S;
@ -309,10 +305,10 @@ void do_blocking_move_to(const float &lx, const float &ly, const float &lz, cons
// when in the danger zone
if (current_position[Z_AXIS] > delta_clip_start_height) {
if (lz > delta_clip_start_height) { // staying in the danger zone
destination[X_AXIS] = lx; // move directly (uninterpolated)
destination[Y_AXIS] = ly;
destination[Z_AXIS] = lz;
if (rz > delta_clip_start_height) { // staying in the danger zone
destination[X_AXIS] = rx; // move directly (uninterpolated)
destination[Y_AXIS] = ry;
destination[Z_AXIS] = rz;
prepare_uninterpolated_move_to_destination(); // set_current_from_destination()
#if ENABLED(DEBUG_LEVELING_FEATURE)
if (DEBUGGING(LEVELING)) DEBUG_POS("danger zone move", current_position);
@ -328,23 +324,23 @@ void do_blocking_move_to(const float &lx, const float &ly, const float &lz, cons
}
}
if (lz > current_position[Z_AXIS]) { // raising?
destination[Z_AXIS] = lz;
if (rz > current_position[Z_AXIS]) { // raising?
destination[Z_AXIS] = rz;
prepare_uninterpolated_move_to_destination(); // set_current_from_destination()
#if ENABLED(DEBUG_LEVELING_FEATURE)
if (DEBUGGING(LEVELING)) DEBUG_POS("z raise move", current_position);
#endif
}
destination[X_AXIS] = lx;
destination[Y_AXIS] = ly;
destination[X_AXIS] = rx;
destination[Y_AXIS] = ry;
prepare_move_to_destination(); // set_current_from_destination()
#if ENABLED(DEBUG_LEVELING_FEATURE)
if (DEBUGGING(LEVELING)) DEBUG_POS("xy move", current_position);
#endif
if (lz < current_position[Z_AXIS]) { // lowering?
destination[Z_AXIS] = lz;
if (rz < current_position[Z_AXIS]) { // lowering?
destination[Z_AXIS] = rz;
prepare_uninterpolated_move_to_destination(); // set_current_from_destination()
#if ENABLED(DEBUG_LEVELING_FEATURE)
if (DEBUGGING(LEVELING)) DEBUG_POS("z lower move", current_position);
@ -353,44 +349,44 @@ void do_blocking_move_to(const float &lx, const float &ly, const float &lz, cons
#elif IS_SCARA
if (!position_is_reachable_xy(lx, ly)) return;
if (!position_is_reachable(rx, ry)) return;
set_destination_from_current();
// If Z needs to raise, do it before moving XY
if (destination[Z_AXIS] < lz) {
destination[Z_AXIS] = lz;
if (destination[Z_AXIS] < rz) {
destination[Z_AXIS] = rz;
prepare_uninterpolated_move_to_destination(fr_mm_s ? fr_mm_s : homing_feedrate(Z_AXIS));
}
destination[X_AXIS] = lx;
destination[Y_AXIS] = ly;
destination[X_AXIS] = rx;
destination[Y_AXIS] = ry;
prepare_uninterpolated_move_to_destination(fr_mm_s ? fr_mm_s : XY_PROBE_FEEDRATE_MM_S);
// If Z needs to lower, do it after moving XY
if (destination[Z_AXIS] > lz) {
destination[Z_AXIS] = lz;
if (destination[Z_AXIS] > rz) {
destination[Z_AXIS] = rz;
prepare_uninterpolated_move_to_destination(fr_mm_s ? fr_mm_s : homing_feedrate(Z_AXIS));
}
#else
// If Z needs to raise, do it before moving XY
if (current_position[Z_AXIS] < lz) {
if (current_position[Z_AXIS] < rz) {
feedrate_mm_s = fr_mm_s ? fr_mm_s : homing_feedrate(Z_AXIS);
current_position[Z_AXIS] = lz;
current_position[Z_AXIS] = rz;
line_to_current_position();
}
feedrate_mm_s = fr_mm_s ? fr_mm_s : XY_PROBE_FEEDRATE_MM_S;
current_position[X_AXIS] = lx;
current_position[Y_AXIS] = ly;
current_position[X_AXIS] = rx;
current_position[Y_AXIS] = ry;
line_to_current_position();
// If Z needs to lower, do it after moving XY
if (current_position[Z_AXIS] > lz) {
if (current_position[Z_AXIS] > rz) {
feedrate_mm_s = fr_mm_s ? fr_mm_s : homing_feedrate(Z_AXIS);
current_position[Z_AXIS] = lz;
current_position[Z_AXIS] = rz;
line_to_current_position();
}
@ -404,14 +400,14 @@ void do_blocking_move_to(const float &lx, const float &ly, const float &lz, cons
if (DEBUGGING(LEVELING)) SERIAL_ECHOLNPGM("<<< do_blocking_move_to");
#endif
}
void do_blocking_move_to_x(const float &lx, const float &fr_mm_s/*=0.0*/) {
do_blocking_move_to(lx, current_position[Y_AXIS], current_position[Z_AXIS], fr_mm_s);
void do_blocking_move_to_x(const float &rx, const float &fr_mm_s/*=0.0*/) {
do_blocking_move_to(rx, current_position[Y_AXIS], current_position[Z_AXIS], fr_mm_s);
}
void do_blocking_move_to_z(const float &lz, const float &fr_mm_s/*=0.0*/) {
do_blocking_move_to(current_position[X_AXIS], current_position[Y_AXIS], lz, fr_mm_s);
void do_blocking_move_to_z(const float &rz, const float &fr_mm_s/*=0.0*/) {
do_blocking_move_to(current_position[X_AXIS], current_position[Y_AXIS], rz, fr_mm_s);
}
void do_blocking_move_to_xy(const float &lx, const float &ly, const float &fr_mm_s/*=0.0*/) {
do_blocking_move_to(lx, ly, current_position[Z_AXIS], fr_mm_s);
void do_blocking_move_to_xy(const float &rx, const float &ry, const float &fr_mm_s/*=0.0*/) {
do_blocking_move_to(rx, ry, current_position[Z_AXIS], fr_mm_s);
}
//
@ -521,26 +517,26 @@ float soft_endstop_min[XYZ] = { X_MIN_BED, Y_MIN_BED, Z_MIN_POS },
* This calls planner.buffer_line several times, adding
* small incremental moves for DELTA or SCARA.
*/
inline bool prepare_kinematic_move_to(float ltarget[XYZE]) {
inline bool prepare_kinematic_move_to(float rtarget[XYZE]) {
// Get the top feedrate of the move in the XY plane
const float _feedrate_mm_s = MMS_SCALED(feedrate_mm_s);
// If the move is only in Z/E don't split up the move
if (ltarget[X_AXIS] == current_position[X_AXIS] && ltarget[Y_AXIS] == current_position[Y_AXIS]) {
planner.buffer_line_kinematic(ltarget, _feedrate_mm_s, active_extruder);
if (rtarget[X_AXIS] == current_position[X_AXIS] && rtarget[Y_AXIS] == current_position[Y_AXIS]) {
planner.buffer_line_kinematic(rtarget, _feedrate_mm_s, active_extruder);
return false;
}
// Fail if attempting move outside printable radius
if (!position_is_reachable_xy(ltarget[X_AXIS], ltarget[Y_AXIS])) return true;
if (!position_is_reachable(rtarget[X_AXIS], rtarget[Y_AXIS])) return true;
// Get the cartesian distances moved in XYZE
const float difference[XYZE] = {
ltarget[X_AXIS] - current_position[X_AXIS],
ltarget[Y_AXIS] - current_position[Y_AXIS],
ltarget[Z_AXIS] - current_position[Z_AXIS],
ltarget[E_AXIS] - current_position[E_AXIS]
rtarget[X_AXIS] - current_position[X_AXIS],
rtarget[Y_AXIS] - current_position[Y_AXIS],
rtarget[Z_AXIS] - current_position[Z_AXIS],
rtarget[E_AXIS] - current_position[E_AXIS]
};
// Get the linear distance in XYZ
@ -588,9 +584,9 @@ float soft_endstop_min[XYZ] = { X_MIN_BED, Y_MIN_BED, Z_MIN_POS },
oldB = stepper.get_axis_position_degrees(B_AXIS);
#endif
// Get the logical current position as starting point
float logical[XYZE];
COPY(logical, current_position);
// Get the current position as starting point
float raw[XYZE];
COPY(raw, current_position);
// Drop one segment so the last move is to the exact target.
// If there's only 1 segment, loops will be skipped entirely.
@ -598,25 +594,25 @@ float soft_endstop_min[XYZ] = { X_MIN_BED, Y_MIN_BED, Z_MIN_POS },
// Calculate and execute the segments
for (uint16_t s = segments + 1; --s;) {
LOOP_XYZE(i) logical[i] += segment_distance[i];
LOOP_XYZE(i) raw[i] += segment_distance[i];
#if ENABLED(DELTA)
DELTA_LOGICAL_IK(); // Delta can inline its kinematics
DELTA_RAW_IK(); // Delta can inline its kinematics
#else
inverse_kinematics(logical);
inverse_kinematics(raw);
#endif
ADJUST_DELTA(logical); // Adjust Z if bed leveling is enabled
ADJUST_DELTA(raw); // Adjust Z if bed leveling is enabled
#if IS_SCARA && ENABLED(SCARA_FEEDRATE_SCALING)
// For SCARA scale the feed rate from mm/s to degrees/s
// Use ratio between the length of the move and the larger angle change
const float adiff = abs(delta[A_AXIS] - oldA),
bdiff = abs(delta[B_AXIS] - oldB);
planner.buffer_line(delta[A_AXIS], delta[B_AXIS], delta[C_AXIS], logical[E_AXIS], max(adiff, bdiff) * feed_factor, active_extruder);
planner.buffer_line(delta[A_AXIS], delta[B_AXIS], delta[C_AXIS], raw[E_AXIS], max(adiff, bdiff) * feed_factor, active_extruder);
oldA = delta[A_AXIS];
oldB = delta[B_AXIS];
#else
planner.buffer_line(delta[A_AXIS], delta[B_AXIS], delta[C_AXIS], logical[E_AXIS], _feedrate_mm_s, active_extruder);
planner.buffer_line(delta[A_AXIS], delta[B_AXIS], delta[C_AXIS], raw[E_AXIS], _feedrate_mm_s, active_extruder);
#endif
}
@ -626,13 +622,13 @@ float soft_endstop_min[XYZ] = { X_MIN_BED, Y_MIN_BED, Z_MIN_POS },
#if IS_SCARA && ENABLED(SCARA_FEEDRATE_SCALING)
// For SCARA scale the feed rate from mm/s to degrees/s
// With segments > 1 length is 1 segment, otherwise total length
inverse_kinematics(ltarget);
ADJUST_DELTA(ltarget);
inverse_kinematics(rtarget);
ADJUST_DELTA(rtarget);
const float adiff = abs(delta[A_AXIS] - oldA),
bdiff = abs(delta[B_AXIS] - oldB);
planner.buffer_line(delta[A_AXIS], delta[B_AXIS], delta[C_AXIS], logical[E_AXIS], max(adiff, bdiff) * feed_factor, active_extruder);
planner.buffer_line(delta[A_AXIS], delta[B_AXIS], delta[C_AXIS], raw[E_AXIS], max(adiff, bdiff) * feed_factor, active_extruder);
#else
planner.buffer_line_kinematic(ltarget, _feedrate_mm_s, active_extruder);
planner.buffer_line_kinematic(rtarget, _feedrate_mm_s, active_extruder);
#endif
return false;
@ -687,7 +683,7 @@ float soft_endstop_min[XYZ] = { X_MIN_BED, Y_MIN_BED, Z_MIN_POS },
float x_home_pos(const int extruder) {
if (extruder == 0)
return LOGICAL_X_POSITION(base_home_pos(X_AXIS));
return base_home_pos(X_AXIS);
else
/**
* In dual carriage mode the extruder offset provides an override of the
@ -695,7 +691,7 @@ float soft_endstop_min[XYZ] = { X_MIN_BED, Y_MIN_BED, Z_MIN_POS },
* This allows soft recalibration of the second extruder home position
* without firmware reflash (through the M218 command).
*/
return LOGICAL_X_POSITION(hotend_offset[X_AXIS][1] > 0 ? hotend_offset[X_AXIS][1] : X2_HOME_POS);
return hotend_offset[X_AXIS][1] > 0 ? hotend_offset[X_AXIS][1] : X2_HOME_POS;
}
/**
@ -740,13 +736,13 @@ float soft_endstop_min[XYZ] = { X_MIN_BED, Y_MIN_BED, Z_MIN_POS },
if (active_extruder == 0) {
#if ENABLED(DEBUG_LEVELING_FEATURE)
if (DEBUGGING(LEVELING)) {
SERIAL_ECHOPAIR("Set planner X", LOGICAL_X_POSITION(inactive_extruder_x_pos));
SERIAL_ECHOPAIR("Set planner X", inactive_extruder_x_pos);
SERIAL_ECHOLNPAIR(" ... Line to X", current_position[X_AXIS] + duplicate_extruder_x_offset);
}
#endif
// move duplicate extruder into correct duplication position.
planner.set_position_mm(
LOGICAL_X_POSITION(inactive_extruder_x_pos),
inactive_extruder_x_pos,
current_position[Y_AXIS],
current_position[Z_AXIS],
current_position[E_AXIS]
@ -970,7 +966,7 @@ void set_axis_is_at_home(const AxisEnum axis) {
#if ENABLED(MORGAN_SCARA)
scara_set_axis_is_at_home(axis);
#else
current_position[axis] = LOGICAL_POSITION(base_home_pos(axis), axis);
current_position[axis] = base_home_pos(axis);
#endif
/**

View File

@ -217,14 +217,14 @@ void homeaxis(const AxisEnum axis);
#define WORKSPACE_OFFSET(AXIS) 0
#endif
#define LOGICAL_POSITION(POS, AXIS) ((POS) + WORKSPACE_OFFSET(AXIS))
#define RAW_POSITION(POS, AXIS) ((POS) - WORKSPACE_OFFSET(AXIS))
#define NATIVE_TO_LOGICAL(POS, AXIS) ((POS) + WORKSPACE_OFFSET(AXIS))
#define LOGICAL_TO_NATIVE(POS, AXIS) ((POS) - WORKSPACE_OFFSET(AXIS))
#if HAS_POSITION_SHIFT || DISABLED(DELTA)
#define LOGICAL_X_POSITION(POS) LOGICAL_POSITION(POS, X_AXIS)
#define LOGICAL_Y_POSITION(POS) LOGICAL_POSITION(POS, Y_AXIS)
#define RAW_X_POSITION(POS) RAW_POSITION(POS, X_AXIS)
#define RAW_Y_POSITION(POS) RAW_POSITION(POS, Y_AXIS)
#define LOGICAL_X_POSITION(POS) NATIVE_TO_LOGICAL(POS, X_AXIS)
#define LOGICAL_Y_POSITION(POS) NATIVE_TO_LOGICAL(POS, Y_AXIS)
#define RAW_X_POSITION(POS) LOGICAL_TO_NATIVE(POS, X_AXIS)
#define RAW_Y_POSITION(POS) LOGICAL_TO_NATIVE(POS, Y_AXIS)
#else
#define LOGICAL_X_POSITION(POS) (POS)
#define LOGICAL_Y_POSITION(POS) (POS)
@ -232,9 +232,8 @@ void homeaxis(const AxisEnum axis);
#define RAW_Y_POSITION(POS) (POS)
#endif
#define LOGICAL_Z_POSITION(POS) LOGICAL_POSITION(POS, Z_AXIS)
#define RAW_Z_POSITION(POS) RAW_POSITION(POS, Z_AXIS)
#define RAW_CURRENT_POSITION(A) RAW_##A##_POSITION(current_position[A##_AXIS])
#define LOGICAL_Z_POSITION(POS) NATIVE_TO_LOGICAL(POS, Z_AXIS)
#define RAW_Z_POSITION(POS) LOGICAL_TO_NATIVE(POS, Z_AXIS)
/**
* position_is_reachable family of functions
@ -242,7 +241,7 @@ void homeaxis(const AxisEnum axis);
#if IS_KINEMATIC // (DELTA or SCARA)
inline bool position_is_reachable_raw_xy(const float &rx, const float &ry) {
inline bool position_is_reachable(const float &rx, const float &ry) {
#if ENABLED(DELTA)
return HYPOT2(rx, ry) <= sq(DELTA_PRINTABLE_RADIUS);
#elif IS_SCARA
@ -257,24 +256,24 @@ void homeaxis(const AxisEnum axis);
#endif
}
inline bool position_is_reachable_by_probe_raw_xy(const float &rx, const float &ry) {
inline bool position_is_reachable_by_probe(const float &rx, const float &ry) {
// Both the nozzle and the probe must be able to reach the point.
// This won't work on SCARA since the probe offset rotates with the arm.
return position_is_reachable_raw_xy(rx, ry)
&& position_is_reachable_raw_xy(rx - X_PROBE_OFFSET_FROM_EXTRUDER, ry - Y_PROBE_OFFSET_FROM_EXTRUDER);
return position_is_reachable(rx, ry)
&& position_is_reachable(rx - X_PROBE_OFFSET_FROM_EXTRUDER, ry - Y_PROBE_OFFSET_FROM_EXTRUDER);
}
#else // CARTESIAN
inline bool position_is_reachable_raw_xy(const float &rx, const float &ry) {
inline bool position_is_reachable(const float &rx, const float &ry) {
// Add 0.001 margin to deal with float imprecision
return WITHIN(rx, X_MIN_POS - 0.001, X_MAX_POS + 0.001)
&& WITHIN(ry, Y_MIN_POS - 0.001, Y_MAX_POS + 0.001);
}
inline bool position_is_reachable_by_probe_raw_xy(const float &rx, const float &ry) {
inline bool position_is_reachable_by_probe(const float &rx, const float &ry) {
// Add 0.001 margin to deal with float imprecision
return WITHIN(rx, MIN_PROBE_X - 0.001, MAX_PROBE_X + 0.001)
&& WITHIN(ry, MIN_PROBE_Y - 0.001, MAX_PROBE_Y + 0.001);
@ -282,14 +281,6 @@ void homeaxis(const AxisEnum axis);
#endif // CARTESIAN
FORCE_INLINE bool position_is_reachable_by_probe_xy(const float &lx, const float &ly) {
return position_is_reachable_by_probe_raw_xy(RAW_X_POSITION(lx), RAW_Y_POSITION(ly));
}
FORCE_INLINE bool position_is_reachable_xy(const float &lx, const float &ly) {
return position_is_reachable_raw_xy(RAW_X_POSITION(lx), RAW_Y_POSITION(ly));
}
/**
* Dual X Carriage / Dual Nozzle
*/

View File

@ -132,7 +132,7 @@ float Planner::min_feedrate_mm_s,
#if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
float Planner::z_fade_height, // Initialized by settings.load()
Planner::inverse_z_fade_height,
Planner::last_raw_lz;
Planner::last_fade_z;
#endif
#if ENABLED(AUTOTEMP)
@ -552,14 +552,14 @@ void Planner::calculate_volumetric_multipliers() {
#if PLANNER_LEVELING
/**
* lx, ly, lz - logical (cartesian, not delta) positions in mm
* rx, ry, rz - Cartesian positions in mm
*/
void Planner::apply_leveling(float &lx, float &ly, float &lz) {
void Planner::apply_leveling(float &rx, float &ry, float &rz) {
if (!planner.leveling_active) return;
#if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
const float fade_scaling_factor = fade_scaling_factor_for_z(lz);
const float fade_scaling_factor = fade_scaling_factor_for_z(rz);
if (!fade_scaling_factor) return;
#else
constexpr float fade_scaling_factor = 1.0;
@ -567,11 +567,11 @@ void Planner::calculate_volumetric_multipliers() {
#if ENABLED(AUTO_BED_LEVELING_UBL)
lz += ubl.get_z_correction(lx, ly) * fade_scaling_factor;
rz += ubl.get_z_correction(rx, ry) * fade_scaling_factor;
#elif ENABLED(MESH_BED_LEVELING)
lz += mbl.get_z(RAW_X_POSITION(lx), RAW_Y_POSITION(ly)
rz += mbl.get_z(rx, ry
#if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
, fade_scaling_factor
#endif
@ -581,42 +581,38 @@ void Planner::calculate_volumetric_multipliers() {
UNUSED(fade_scaling_factor);
float dx = RAW_X_POSITION(lx) - (X_TILT_FULCRUM),
dy = RAW_Y_POSITION(ly) - (Y_TILT_FULCRUM),
dz = RAW_Z_POSITION(lz);
float dx = rx - (X_TILT_FULCRUM),
dy = ry - (Y_TILT_FULCRUM);
apply_rotation_xyz(bed_level_matrix, dx, dy, dz);
apply_rotation_xyz(bed_level_matrix, dx, dy, rz);
lx = LOGICAL_X_POSITION(dx + X_TILT_FULCRUM);
ly = LOGICAL_Y_POSITION(dy + Y_TILT_FULCRUM);
lz = LOGICAL_Z_POSITION(dz);
rx = dx + X_TILT_FULCRUM;
ry = dy + Y_TILT_FULCRUM;
#elif ENABLED(AUTO_BED_LEVELING_BILINEAR)
float tmp[XYZ] = { lx, ly, 0 };
lz += bilinear_z_offset(tmp) * fade_scaling_factor;
float tmp[XYZ] = { rx, ry, 0 };
rz += bilinear_z_offset(tmp) * fade_scaling_factor;
#endif
}
void Planner::unapply_leveling(float logical[XYZ]) {
void Planner::unapply_leveling(float raw[XYZ]) {
if (!planner.leveling_active) return;
#if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
if (z_fade_height && RAW_Z_POSITION(logical[Z_AXIS]) >= z_fade_height) return;
if (z_fade_height && raw[Z_AXIS] >= z_fade_height) return;
#endif
#if ENABLED(AUTO_BED_LEVELING_UBL)
const float z_physical = RAW_Z_POSITION(logical[Z_AXIS]),
z_correct = ubl.get_z_correction(logical[X_AXIS], logical[Y_AXIS]),
z_virtual = z_physical - z_correct;
float z_logical = LOGICAL_Z_POSITION(z_virtual);
const float z_correct = ubl.get_z_correction(raw[X_AXIS], raw[Y_AXIS]);
float z_raw = raw[Z_AXIS] - z_correct;
#if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
// for P=physical_z, L=logical_z, M=mesh_z, H=fade_height,
// for P=physical_z, L=raw_z, M=mesh_z, H=fade_height,
// Given P=L+M(1-L/H) (faded mesh correction formula for L<H)
// then L=P-M(1-L/H)
// so L=P-M+ML/H
@ -625,46 +621,46 @@ void Planner::calculate_volumetric_multipliers() {
// so L=(P-M)/(1-M/H) for L<H
if (planner.z_fade_height) {
if (z_logical >= planner.z_fade_height)
z_logical = LOGICAL_Z_POSITION(z_physical);
if (z_raw >= planner.z_fade_height)
z_raw = raw[Z_AXIS];
else
z_logical /= 1.0 - z_correct * planner.inverse_z_fade_height;
z_raw /= 1.0 - z_correct * planner.inverse_z_fade_height;
}
#endif // ENABLE_LEVELING_FADE_HEIGHT
logical[Z_AXIS] = z_logical;
raw[Z_AXIS] = z_raw;
#elif ENABLED(MESH_BED_LEVELING)
#if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
const float c = mbl.get_z(RAW_X_POSITION(logical[X_AXIS]), RAW_Y_POSITION(logical[Y_AXIS]), 1.0);
logical[Z_AXIS] = (z_fade_height * (RAW_Z_POSITION(logical[Z_AXIS]) - c)) / (z_fade_height - c);
const float c = mbl.get_z(raw[X_AXIS], raw[Y_AXIS], 1.0);
raw[Z_AXIS] = (z_fade_height * (raw[Z_AXIS] - c)) / (z_fade_height - c);
#else
logical[Z_AXIS] -= mbl.get_z(RAW_X_POSITION(logical[X_AXIS]), RAW_Y_POSITION(logical[Y_AXIS]));
raw[Z_AXIS] -= mbl.get_z(raw[X_AXIS], raw[Y_AXIS]);
#endif
#elif ABL_PLANAR
matrix_3x3 inverse = matrix_3x3::transpose(bed_level_matrix);
float dx = RAW_X_POSITION(logical[X_AXIS]) - (X_TILT_FULCRUM),
dy = RAW_Y_POSITION(logical[Y_AXIS]) - (Y_TILT_FULCRUM),
dz = RAW_Z_POSITION(logical[Z_AXIS]);
float dx = raw[X_AXIS] - (X_TILT_FULCRUM),
dy = raw[Y_AXIS] - (Y_TILT_FULCRUM),
dz = raw[Z_AXIS];
apply_rotation_xyz(inverse, dx, dy, dz);
logical[X_AXIS] = LOGICAL_X_POSITION(dx + X_TILT_FULCRUM);
logical[Y_AXIS] = LOGICAL_Y_POSITION(dy + Y_TILT_FULCRUM);
logical[Z_AXIS] = LOGICAL_Z_POSITION(dz);
raw[X_AXIS] = dx + X_TILT_FULCRUM;
raw[Y_AXIS] = dy + Y_TILT_FULCRUM;
raw[Z_AXIS] = dz;
#elif ENABLED(AUTO_BED_LEVELING_BILINEAR)
#if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
const float c = bilinear_z_offset(logical);
logical[Z_AXIS] = (z_fade_height * (RAW_Z_POSITION(logical[Z_AXIS]) - c)) / (z_fade_height - c);
const float c = bilinear_z_offset(raw);
raw[Z_AXIS] = (z_fade_height * (raw[Z_AXIS]) - c) / (z_fade_height - c);
#else
logical[Z_AXIS] -= bilinear_z_offset(logical);
raw[Z_AXIS] -= bilinear_z_offset(raw);
#endif
#endif

View File

@ -202,7 +202,7 @@ class Planner {
static uint32_t cutoff_long;
#if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
static float last_raw_lz;
static float last_fade_z;
#endif
#if ENABLED(DISABLE_INACTIVE_EXTRUDER)
@ -275,21 +275,20 @@ class Planner {
* Returns 1.0 if planner.z_fade_height is 0.0.
* Returns 0.0 if Z is past the specified 'Fade Height'.
*/
inline static float fade_scaling_factor_for_z(const float &lz) {
inline static float fade_scaling_factor_for_z(const float &rz) {
static float z_fade_factor = 1.0;
if (z_fade_height) {
const float raw_lz = RAW_Z_POSITION(lz);
if (raw_lz >= z_fade_height) return 0.0;
if (last_raw_lz != raw_lz) {
last_raw_lz = raw_lz;
z_fade_factor = 1.0 - raw_lz * inverse_z_fade_height;
if (rz >= z_fade_height) return 0.0;
if (last_fade_z != rz) {
last_fade_z = rz;
z_fade_factor = 1.0 - rz * inverse_z_fade_height;
}
return z_fade_factor;
}
return 1.0;
}
FORCE_INLINE static void force_fade_recalc() { last_raw_lz = -999.999; }
FORCE_INLINE static void force_fade_recalc() { last_fade_z = -999.999; }
FORCE_INLINE static void set_z_fade_height(const float &zfh) {
z_fade_height = zfh > 0 ? zfh : 0;
@ -297,40 +296,40 @@ class Planner {
force_fade_recalc();
}
FORCE_INLINE static bool leveling_active_at_z(const float &lz) {
return !z_fade_height || RAW_Z_POSITION(lz) < z_fade_height;
FORCE_INLINE static bool leveling_active_at_z(const float &rz) {
return !z_fade_height || rz < z_fade_height;
}
#else
FORCE_INLINE static float fade_scaling_factor_for_z(const float &lz) {
UNUSED(lz);
FORCE_INLINE static float fade_scaling_factor_for_z(const float &rz) {
UNUSED(rz);
return 1.0;
}
FORCE_INLINE static bool leveling_active_at_z(const float &lz) { UNUSED(lz); return true; }
FORCE_INLINE static bool leveling_active_at_z(const float &rz) { UNUSED(rz); return true; }
#endif
#if PLANNER_LEVELING
#define ARG_X float lx
#define ARG_Y float ly
#define ARG_Z float lz
#define ARG_X float rx
#define ARG_Y float ry
#define ARG_Z float rz
/**
* Apply leveling to transform a cartesian position
* as it will be given to the planner and steppers.
*/
static void apply_leveling(float &lx, float &ly, float &lz);
static void apply_leveling(float logical[XYZ]) { apply_leveling(logical[X_AXIS], logical[Y_AXIS], logical[Z_AXIS]); }
static void unapply_leveling(float logical[XYZ]);
static void apply_leveling(float &rx, float &ry, float &rz);
static void apply_leveling(float raw[XYZ]) { apply_leveling(raw[X_AXIS], raw[Y_AXIS], raw[Z_AXIS]); }
static void unapply_leveling(float raw[XYZ]);
#else
#define ARG_X const float &lx
#define ARG_Y const float &ly
#define ARG_Z const float &lz
#define ARG_X const float &rx
#define ARG_Y const float &ry
#define ARG_Z const float &rz
#endif
@ -357,15 +356,15 @@ class Planner {
* Kinematic machines should call buffer_line_kinematic (for leveled moves).
* (Cartesians may also call buffer_line_kinematic.)
*
* lx,ly,lz,e - target position in mm or degrees
* rx,ry,rz,e - target position in mm or degrees
* fr_mm_s - (target) speed of the move (mm/s)
* extruder - target extruder
*/
static FORCE_INLINE void buffer_line(ARG_X, ARG_Y, ARG_Z, const float &e, const float &fr_mm_s, const uint8_t extruder) {
#if PLANNER_LEVELING && IS_CARTESIAN
apply_leveling(lx, ly, lz);
apply_leveling(rx, ry, rz);
#endif
_buffer_line(lx, ly, lz, e, fr_mm_s, extruder);
_buffer_line(rx, ry, rz, e, fr_mm_s, extruder);
}
/**
@ -373,22 +372,22 @@ class Planner {
* The target is cartesian, it's translated to delta/scara if
* needed.
*
* ltarget - x,y,z,e CARTESIAN target in mm
* rtarget - x,y,z,e CARTESIAN target in mm
* fr_mm_s - (target) speed of the move (mm/s)
* extruder - target extruder
*/
static FORCE_INLINE void buffer_line_kinematic(const float ltarget[XYZE], const float &fr_mm_s, const uint8_t extruder) {
static FORCE_INLINE void buffer_line_kinematic(const float rtarget[XYZE], const float &fr_mm_s, const uint8_t extruder) {
#if PLANNER_LEVELING
float lpos[XYZ] = { ltarget[X_AXIS], ltarget[Y_AXIS], ltarget[Z_AXIS] };
float lpos[XYZ] = { rtarget[X_AXIS], rtarget[Y_AXIS], rtarget[Z_AXIS] };
apply_leveling(lpos);
#else
const float * const lpos = ltarget;
const float * const lpos = rtarget;
#endif
#if IS_KINEMATIC
inverse_kinematics(lpos);
_buffer_line(delta[A_AXIS], delta[B_AXIS], delta[C_AXIS], ltarget[E_AXIS], fr_mm_s, extruder);
_buffer_line(delta[A_AXIS], delta[B_AXIS], delta[C_AXIS], rtarget[E_AXIS], fr_mm_s, extruder);
#else
_buffer_line(lpos[X_AXIS], lpos[Y_AXIS], lpos[Z_AXIS], ltarget[E_AXIS], fr_mm_s, extruder);
_buffer_line(lpos[X_AXIS], lpos[Y_AXIS], lpos[Z_AXIS], rtarget[E_AXIS], fr_mm_s, extruder);
#endif
}
@ -403,9 +402,9 @@ class Planner {
*/
static FORCE_INLINE void set_position_mm(ARG_X, ARG_Y, ARG_Z, const float &e) {
#if PLANNER_LEVELING && IS_CARTESIAN
apply_leveling(lx, ly, lz);
apply_leveling(rx, ry, rz);
#endif
_set_position_mm(lx, ly, lz, e);
_set_position_mm(rx, ry, rz, e);
}
static void set_position_mm_kinematic(const float position[NUM_AXIS]);
static void set_position_mm(const AxisEnum axis, const float &v);

View File

@ -106,8 +106,8 @@ inline void do_probe_raise(const float z_raise) {
#elif ENABLED(Z_PROBE_ALLEN_KEY)
FORCE_INLINE void do_blocking_move_to(const float logical[XYZ], const float &fr_mm_s) {
do_blocking_move_to(logical[X_AXIS], logical[Y_AXIS], logical[Z_AXIS], fr_mm_s);
FORCE_INLINE void do_blocking_move_to(const float raw[XYZ], const float &fr_mm_s) {
do_blocking_move_to(raw[X_AXIS], raw[Y_AXIS], raw[Z_AXIS], fr_mm_s);
}
void run_deploy_moves_script() {
@ -564,7 +564,7 @@ static float run_z_probe(const bool short_move=true) {
}
#endif
return RAW_CURRENT_POSITION(Z) + zprobe_zoffset
return current_position[Z_AXIS] + zprobe_zoffset
#if ENABLED(DELTA)
+ home_offset[Z_AXIS] // Account for delta height adjustment
#endif
@ -580,22 +580,22 @@ static float run_z_probe(const bool short_move=true) {
* - Raise to the BETWEEN height
* - Return the probed Z position
*/
float probe_pt(const float &lx, const float &ly, const bool stow, const uint8_t verbose_level, const bool printable/*=true*/) {
float probe_pt(const float &rx, const float &ry, const bool stow, const uint8_t verbose_level, const bool printable/*=true*/) {
#if ENABLED(DEBUG_LEVELING_FEATURE)
if (DEBUGGING(LEVELING)) {
SERIAL_ECHOPAIR(">>> probe_pt(", lx);
SERIAL_ECHOPAIR(", ", ly);
SERIAL_ECHOPAIR(">>> probe_pt(", LOGICAL_X_POSITION(rx));
SERIAL_ECHOPAIR(", ", LOGICAL_Y_POSITION(ry));
SERIAL_ECHOPAIR(", ", stow ? "" : "no ");
SERIAL_ECHOLNPGM("stow)");
DEBUG_POS("", current_position);
}
#endif
const float nx = lx - (X_PROBE_OFFSET_FROM_EXTRUDER), ny = ly - (Y_PROBE_OFFSET_FROM_EXTRUDER);
const float nx = rx - (X_PROBE_OFFSET_FROM_EXTRUDER), ny = ry - (Y_PROBE_OFFSET_FROM_EXTRUDER);
if (printable
? !position_is_reachable_xy(nx, ny)
: !position_is_reachable_by_probe_xy(lx, ly)
? !position_is_reachable(nx, ny)
: !position_is_reachable_by_probe(rx, ry)
) return NAN;
@ -634,9 +634,9 @@ float probe_pt(const float &lx, const float &ly, const bool stow, const uint8_t
if (verbose_level > 2) {
SERIAL_PROTOCOLPGM("Bed X: ");
SERIAL_PROTOCOL_F(lx, 3);
SERIAL_PROTOCOL_F(LOGICAL_X_POSITION(rx), 3);
SERIAL_PROTOCOLPGM(" Y: ");
SERIAL_PROTOCOL_F(ly, 3);
SERIAL_PROTOCOL_F(LOGICAL_Y_POSITION(ry), 3);
SERIAL_PROTOCOLPGM(" Z: ");
SERIAL_PROTOCOL_F(measured_z, 3);
SERIAL_EOL();

View File

@ -30,7 +30,7 @@
#include "../inc/MarlinConfig.h"
bool set_probe_deployed(const bool deploy);
float probe_pt(const float &lx, const float &ly, const bool, const uint8_t, const bool printable=true);
float probe_pt(const float &rx, const float &ry, const bool, const uint8_t, const bool printable=true);
#if HAS_BED_PROBE
extern float zprobe_zoffset;

View File

@ -36,14 +36,14 @@ float delta_segments_per_second = SCARA_SEGMENTS_PER_SECOND;
void scara_set_axis_is_at_home(const AxisEnum axis) {
if (axis == Z_AXIS)
current_position[Z_AXIS] = LOGICAL_POSITION(Z_HOME_POS, Z_AXIS);
current_position[Z_AXIS] = Z_HOME_POS;
else {
/**
* SCARA homes XY at the same time
*/
float homeposition[XYZ];
LOOP_XYZ(i) homeposition[i] = LOGICAL_POSITION(base_home_pos((AxisEnum)i), i);
LOOP_XYZ(i) homeposition[i] = base_home_pos((AxisEnum)i);
// SERIAL_ECHOPAIR("homeposition X:", homeposition[X_AXIS]);
// SERIAL_ECHOLNPAIR(" Y:", homeposition[Y_AXIS]);
@ -58,7 +58,7 @@ void scara_set_axis_is_at_home(const AxisEnum axis) {
// SERIAL_ECHOPAIR("Cartesian X:", cartes[X_AXIS]);
// SERIAL_ECHOLNPAIR(" Y:", cartes[Y_AXIS]);
current_position[axis] = LOGICAL_POSITION(cartes[axis], axis);
current_position[axis] = cartes[axis];
/**
* SCARA home positions are based on configuration since the actual
@ -104,12 +104,12 @@ void forward_kinematics_SCARA(const float &a, const float &b) {
* Maths and first version by QHARLEY.
* Integrated into Marlin and slightly restructured by Joachim Cerny.
*/
void inverse_kinematics(const float logical[XYZ]) {
void inverse_kinematics(const float raw[XYZ]) {
static float C2, S2, SK1, SK2, THETA, PSI;
float sx = RAW_X_POSITION(logical[X_AXIS]) - SCARA_OFFSET_X, // Translate SCARA to standard X Y
sy = RAW_Y_POSITION(logical[Y_AXIS]) - SCARA_OFFSET_Y; // With scaling factor.
float sx = raw[X_AXIS] - SCARA_OFFSET_X, // Translate SCARA to standard X Y
sy = raw[Y_AXIS] - SCARA_OFFSET_Y; // With scaling factor.
if (L1 == L2)
C2 = HYPOT2(sx, sy) / L1_2_2 - 1;
@ -132,10 +132,10 @@ void inverse_kinematics(const float logical[XYZ]) {
delta[A_AXIS] = DEGREES(THETA); // theta is support arm angle
delta[B_AXIS] = DEGREES(THETA + PSI); // equal to sub arm angle (inverted motor)
delta[C_AXIS] = logical[Z_AXIS];
delta[C_AXIS] = raw[Z_AXIS];
/*
DEBUG_POS("SCARA IK", logical);
DEBUG_POS("SCARA IK", raw);
DEBUG_POS("SCARA IK", delta);
SERIAL_ECHOPAIR(" SCARA (x,y) ", sx);
SERIAL_ECHOPAIR(",", sy);

View File

@ -38,7 +38,7 @@ float constexpr L1 = SCARA_LINKAGE_1, L2 = SCARA_LINKAGE_2,
void scara_set_axis_is_at_home(const AxisEnum axis);
void inverse_kinematics(const float logical[XYZ]);
void inverse_kinematics(const float raw[XYZ]);
void forward_kinematics_SCARA(const float &a, const float &b);
void scara_report_positions();

View File

@ -240,9 +240,9 @@ void tool_change(const uint8_t tmp_extruder, const float fr_mm_s/*=0.0*/, bool n
switch (dual_x_carriage_mode) {
case DXC_FULL_CONTROL_MODE:
// New current position is the position of the activated extruder
current_position[X_AXIS] = LOGICAL_X_POSITION(inactive_extruder_x_pos);
current_position[X_AXIS] = inactive_extruder_x_pos;
// Save the inactive extruder's position (from the old current_position)
inactive_extruder_x_pos = RAW_X_POSITION(destination[X_AXIS]);
inactive_extruder_x_pos = destination[X_AXIS];
break;
case DXC_AUTO_PARK_MODE:
// record raised toolhead position for use by unpark
@ -260,10 +260,10 @@ void tool_change(const uint8_t tmp_extruder, const float fr_mm_s/*=0.0*/, bool n
active_extruder_parked = (active_extruder == 0);
if (active_extruder_parked)
current_position[X_AXIS] = LOGICAL_X_POSITION(inactive_extruder_x_pos);
current_position[X_AXIS] = inactive_extruder_x_pos;
else
current_position[X_AXIS] = destination[X_AXIS] + duplicate_extruder_x_offset;
inactive_extruder_x_pos = RAW_X_POSITION(destination[X_AXIS]);
inactive_extruder_x_pos = destination[X_AXIS];
extruder_duplication_enabled = false;
#if ENABLED(DEBUG_LEVELING_FEATURE)
if (DEBUGGING(LEVELING)) {