Operate in Native Machine Space
This commit is contained in:
@ -56,8 +56,8 @@ void GcodeSuite::G42() {
|
||||
#endif
|
||||
|
||||
set_destination_from_current();
|
||||
if (hasI) destination[X_AXIS] = LOGICAL_X_POSITION(_GET_MESH_X(ix));
|
||||
if (hasJ) destination[Y_AXIS] = LOGICAL_Y_POSITION(_GET_MESH_Y(iy));
|
||||
if (hasI) destination[X_AXIS] = _GET_MESH_X(ix);
|
||||
if (hasJ) destination[Y_AXIS] = _GET_MESH_Y(iy);
|
||||
if (parser.boolval('P')) {
|
||||
if (hasI) destination[X_AXIS] -= X_PROBE_OFFSET_FROM_EXTRUDER;
|
||||
if (hasJ) destination[Y_AXIS] -= Y_PROBE_OFFSET_FROM_EXTRUDER;
|
||||
|
@ -258,28 +258,28 @@ void GcodeSuite::G29() {
|
||||
return;
|
||||
}
|
||||
|
||||
const float z = parser.floatval('Z', RAW_CURRENT_POSITION(Z));
|
||||
if (!WITHIN(z, -10, 10)) {
|
||||
const float rz = parser.seenval('Z') ? RAW_Z_POSITION(parser.value_linear_units()) : current_position[Z_AXIS];
|
||||
if (!WITHIN(rz, -10, 10)) {
|
||||
SERIAL_ERROR_START();
|
||||
SERIAL_ERRORLNPGM("Bad Z value");
|
||||
return;
|
||||
}
|
||||
|
||||
const float x = parser.floatval('X', NAN),
|
||||
y = parser.floatval('Y', NAN);
|
||||
const float rx = RAW_X_POSITION(parser.linearval('X', NAN)),
|
||||
ry = RAW_Y_POSITION(parser.linearval('Y', NAN));
|
||||
int8_t i = parser.byteval('I', -1),
|
||||
j = parser.byteval('J', -1);
|
||||
|
||||
if (!isnan(x) && !isnan(y)) {
|
||||
// Get nearest i / j from x / y
|
||||
i = (x - LOGICAL_X_POSITION(bilinear_start[X_AXIS]) + 0.5 * xGridSpacing) / xGridSpacing;
|
||||
j = (y - LOGICAL_Y_POSITION(bilinear_start[Y_AXIS]) + 0.5 * yGridSpacing) / yGridSpacing;
|
||||
if (!isnan(rx) && !isnan(ry)) {
|
||||
// Get nearest i / j from rx / ry
|
||||
i = (rx - bilinear_start[X_AXIS] + 0.5 * xGridSpacing) / xGridSpacing;
|
||||
j = (ry - bilinear_start[Y_AXIS] + 0.5 * yGridSpacing) / yGridSpacing;
|
||||
i = constrain(i, 0, GRID_MAX_POINTS_X - 1);
|
||||
j = constrain(j, 0, GRID_MAX_POINTS_Y - 1);
|
||||
}
|
||||
if (WITHIN(i, 0, GRID_MAX_POINTS_X - 1) && WITHIN(j, 0, GRID_MAX_POINTS_Y)) {
|
||||
set_bed_leveling_enabled(false);
|
||||
z_values[i][j] = z;
|
||||
z_values[i][j] = rz;
|
||||
#if ENABLED(ABL_BILINEAR_SUBDIVISION)
|
||||
bed_level_virt_interpolate();
|
||||
#endif
|
||||
@ -340,36 +340,36 @@ void GcodeSuite::G29() {
|
||||
|
||||
xy_probe_feedrate_mm_s = MMM_TO_MMS(parser.linearval('S', XY_PROBE_SPEED));
|
||||
|
||||
left_probe_bed_position = (int)parser.linearval('L', LOGICAL_X_POSITION(LEFT_PROBE_BED_POSITION));
|
||||
right_probe_bed_position = (int)parser.linearval('R', LOGICAL_X_POSITION(RIGHT_PROBE_BED_POSITION));
|
||||
front_probe_bed_position = (int)parser.linearval('F', LOGICAL_Y_POSITION(FRONT_PROBE_BED_POSITION));
|
||||
back_probe_bed_position = (int)parser.linearval('B', LOGICAL_Y_POSITION(BACK_PROBE_BED_POSITION));
|
||||
|
||||
const bool left_out_l = left_probe_bed_position < LOGICAL_X_POSITION(MIN_PROBE_X),
|
||||
left_probe_bed_position = parser.seenval('L') ? (int)RAW_X_POSITION(parser.value_linear_units()) : LEFT_PROBE_BED_POSITION;
|
||||
right_probe_bed_position = parser.seenval('R') ? (int)RAW_X_POSITION(parser.value_linear_units()) : RIGHT_PROBE_BED_POSITION;
|
||||
front_probe_bed_position = parser.seenval('F') ? (int)RAW_Y_POSITION(parser.value_linear_units()) : FRONT_PROBE_BED_POSITION;
|
||||
back_probe_bed_position = parser.seenval('B') ? (int)RAW_Y_POSITION(parser.value_linear_units()) : BACK_PROBE_BED_POSITION;
|
||||
|
||||
const bool left_out_l = left_probe_bed_position < MIN_PROBE_X,
|
||||
left_out = left_out_l || left_probe_bed_position > right_probe_bed_position - (MIN_PROBE_EDGE),
|
||||
right_out_r = right_probe_bed_position > LOGICAL_X_POSITION(MAX_PROBE_X),
|
||||
right_out_r = right_probe_bed_position > MAX_PROBE_X,
|
||||
right_out = right_out_r || right_probe_bed_position < left_probe_bed_position + MIN_PROBE_EDGE,
|
||||
front_out_f = front_probe_bed_position < LOGICAL_Y_POSITION(MIN_PROBE_Y),
|
||||
front_out_f = front_probe_bed_position < MIN_PROBE_Y,
|
||||
front_out = front_out_f || front_probe_bed_position > back_probe_bed_position - (MIN_PROBE_EDGE),
|
||||
back_out_b = back_probe_bed_position > LOGICAL_Y_POSITION(MAX_PROBE_Y),
|
||||
back_out_b = back_probe_bed_position > MAX_PROBE_Y,
|
||||
back_out = back_out_b || back_probe_bed_position < front_probe_bed_position + MIN_PROBE_EDGE;
|
||||
|
||||
if (left_out || right_out || front_out || back_out) {
|
||||
if (left_out) {
|
||||
out_of_range_error(PSTR("(L)eft"));
|
||||
left_probe_bed_position = left_out_l ? LOGICAL_X_POSITION(MIN_PROBE_X) : right_probe_bed_position - (MIN_PROBE_EDGE);
|
||||
left_probe_bed_position = left_out_l ? MIN_PROBE_X : right_probe_bed_position - (MIN_PROBE_EDGE);
|
||||
}
|
||||
if (right_out) {
|
||||
out_of_range_error(PSTR("(R)ight"));
|
||||
right_probe_bed_position = right_out_r ? LOGICAL_Y_POSITION(MAX_PROBE_X) : left_probe_bed_position + MIN_PROBE_EDGE;
|
||||
right_probe_bed_position = right_out_r ? MAX_PROBE_X : left_probe_bed_position + MIN_PROBE_EDGE;
|
||||
}
|
||||
if (front_out) {
|
||||
out_of_range_error(PSTR("(F)ront"));
|
||||
front_probe_bed_position = front_out_f ? LOGICAL_Y_POSITION(MIN_PROBE_Y) : back_probe_bed_position - (MIN_PROBE_EDGE);
|
||||
front_probe_bed_position = front_out_f ? MIN_PROBE_Y : back_probe_bed_position - (MIN_PROBE_EDGE);
|
||||
}
|
||||
if (back_out) {
|
||||
out_of_range_error(PSTR("(B)ack"));
|
||||
back_probe_bed_position = back_out_b ? LOGICAL_Y_POSITION(MAX_PROBE_Y) : front_probe_bed_position + MIN_PROBE_EDGE;
|
||||
back_probe_bed_position = back_out_b ? MAX_PROBE_Y : front_probe_bed_position + MIN_PROBE_EDGE;
|
||||
}
|
||||
return;
|
||||
}
|
||||
@ -416,8 +416,8 @@ void GcodeSuite::G29() {
|
||||
#endif
|
||||
if ( xGridSpacing != bilinear_grid_spacing[X_AXIS]
|
||||
|| yGridSpacing != bilinear_grid_spacing[Y_AXIS]
|
||||
|| left_probe_bed_position != LOGICAL_X_POSITION(bilinear_start[X_AXIS])
|
||||
|| front_probe_bed_position != LOGICAL_Y_POSITION(bilinear_start[Y_AXIS])
|
||||
|| left_probe_bed_position != bilinear_start[X_AXIS]
|
||||
|| front_probe_bed_position != bilinear_start[Y_AXIS]
|
||||
) {
|
||||
if (dryrun) {
|
||||
// Before reset bed level, re-enable to correct the position
|
||||
@ -429,8 +429,8 @@ void GcodeSuite::G29() {
|
||||
// Initialize a grid with the given dimensions
|
||||
bilinear_grid_spacing[X_AXIS] = xGridSpacing;
|
||||
bilinear_grid_spacing[Y_AXIS] = yGridSpacing;
|
||||
bilinear_start[X_AXIS] = RAW_X_POSITION(left_probe_bed_position);
|
||||
bilinear_start[Y_AXIS] = RAW_Y_POSITION(front_probe_bed_position);
|
||||
bilinear_start[X_AXIS] = left_probe_bed_position;
|
||||
bilinear_start[Y_AXIS] = front_probe_bed_position;
|
||||
|
||||
// Can't re-enable (on error) until the new grid is written
|
||||
abl_should_enable = false;
|
||||
@ -555,7 +555,7 @@ void GcodeSuite::G29() {
|
||||
#endif
|
||||
|
||||
// Keep looping till a reachable point is found
|
||||
if (position_is_reachable_xy(xProbe, yProbe)) break;
|
||||
if (position_is_reachable(xProbe, yProbe)) break;
|
||||
++abl_probe_index;
|
||||
}
|
||||
|
||||
@ -585,8 +585,8 @@ void GcodeSuite::G29() {
|
||||
|
||||
// Probe at 3 arbitrary points
|
||||
if (abl_probe_index < 3) {
|
||||
xProbe = LOGICAL_X_POSITION(points[abl_probe_index].x);
|
||||
yProbe = LOGICAL_Y_POSITION(points[abl_probe_index].y);
|
||||
xProbe = points[abl_probe_index].x;
|
||||
yProbe = points[abl_probe_index].y;
|
||||
#if HAS_SOFTWARE_ENDSTOPS
|
||||
// Disable software endstops to allow manual adjustment
|
||||
// If G29 is not completed, they will not be re-enabled
|
||||
@ -663,7 +663,7 @@ void GcodeSuite::G29() {
|
||||
|
||||
#if IS_KINEMATIC
|
||||
// Avoid probing outside the round or hexagonal area
|
||||
if (!position_is_reachable_by_probe_xy(xProbe, yProbe)) continue;
|
||||
if (!position_is_reachable_by_probe(xProbe, yProbe)) continue;
|
||||
#endif
|
||||
|
||||
measured_z = faux ? 0.001 * random(-100, 101) : probe_pt(xProbe, yProbe, stow_probe_after_each, verbose_level);
|
||||
@ -701,8 +701,8 @@ void GcodeSuite::G29() {
|
||||
|
||||
for (uint8_t i = 0; i < 3; ++i) {
|
||||
// Retain the last probe position
|
||||
xProbe = LOGICAL_X_POSITION(points[i].x);
|
||||
yProbe = LOGICAL_Y_POSITION(points[i].y);
|
||||
xProbe = points[i].x;
|
||||
yProbe = points[i].y;
|
||||
measured_z = faux ? 0.001 * random(-100, 101) : probe_pt(xProbe, yProbe, stow_probe_after_each, verbose_level);
|
||||
if (isnan(measured_z)) {
|
||||
planner.leveling_active = abl_should_enable;
|
||||
|
@ -46,7 +46,7 @@ void mesh_probing_done() {
|
||||
gcode.home_all_axes();
|
||||
set_bed_leveling_enabled(true);
|
||||
#if ENABLED(MESH_G28_REST_ORIGIN)
|
||||
current_position[Z_AXIS] = LOGICAL_Z_POSITION(Z_MIN_POS);
|
||||
current_position[Z_AXIS] = Z_MIN_POS;
|
||||
set_destination_from_current();
|
||||
line_to_destination(homing_feedrate(Z_AXIS));
|
||||
stepper.synchronize();
|
||||
@ -139,7 +139,7 @@ void GcodeSuite::G29() {
|
||||
}
|
||||
else {
|
||||
// One last "return to the bed" (as originally coded) at completion
|
||||
current_position[Z_AXIS] = LOGICAL_Z_POSITION(Z_MIN_POS) + MANUAL_PROBE_HEIGHT;
|
||||
current_position[Z_AXIS] = Z_MIN_POS + MANUAL_PROBE_HEIGHT;
|
||||
line_to_current_position();
|
||||
stepper.synchronize();
|
||||
|
||||
|
@ -86,8 +86,8 @@
|
||||
/**
|
||||
* Move the Z probe (or just the nozzle) to the safe homing point
|
||||
*/
|
||||
destination[X_AXIS] = LOGICAL_X_POSITION(Z_SAFE_HOMING_X_POINT);
|
||||
destination[Y_AXIS] = LOGICAL_Y_POSITION(Z_SAFE_HOMING_Y_POINT);
|
||||
destination[X_AXIS] = Z_SAFE_HOMING_X_POINT;
|
||||
destination[Y_AXIS] = Z_SAFE_HOMING_Y_POINT;
|
||||
destination[Z_AXIS] = current_position[Z_AXIS]; // Z is already at the right height
|
||||
|
||||
#if HOMING_Z_WITH_PROBE
|
||||
@ -95,7 +95,7 @@
|
||||
destination[Y_AXIS] -= Y_PROBE_OFFSET_FROM_EXTRUDER;
|
||||
#endif
|
||||
|
||||
if (position_is_reachable_xy(destination[X_AXIS], destination[Y_AXIS])) {
|
||||
if (position_is_reachable(destination[X_AXIS], destination[Y_AXIS])) {
|
||||
|
||||
#if ENABLED(DEBUG_LEVELING_FEATURE)
|
||||
if (DEBUGGING(LEVELING)) DEBUG_POS("Z_SAFE_HOMING", destination);
|
||||
@ -209,7 +209,7 @@ void GcodeSuite::G28(const bool always_home_all) {
|
||||
|
||||
if (home_all || homeX || homeY) {
|
||||
// Raise Z before homing any other axes and z is not already high enough (never lower z)
|
||||
destination[Z_AXIS] = LOGICAL_Z_POSITION(Z_HOMING_HEIGHT);
|
||||
destination[Z_AXIS] = Z_HOMING_HEIGHT;
|
||||
if (destination[Z_AXIS] > current_position[Z_AXIS]) {
|
||||
|
||||
#if ENABLED(DEBUG_LEVELING_FEATURE)
|
||||
@ -251,7 +251,7 @@ void GcodeSuite::G28(const bool always_home_all) {
|
||||
HOMEAXIS(X);
|
||||
|
||||
// Remember this extruder's position for later tool change
|
||||
inactive_extruder_x_pos = RAW_X_POSITION(current_position[X_AXIS]);
|
||||
inactive_extruder_x_pos = current_position[X_AXIS];
|
||||
|
||||
// Home the 1st (left) extruder
|
||||
active_extruder = 0;
|
||||
|
@ -459,7 +459,7 @@ void GcodeSuite::G33() {
|
||||
LOOP_CAL_RAD(axis) {
|
||||
const float a = RADIANS(210 + (360 / NPP) * (axis - 1)),
|
||||
r = delta_calibration_radius * (1 + (_7p_9_centre ? 0.1 : 0.0));
|
||||
if (!position_is_reachable_xy(cos(a) * r, sin(a) * r)) {
|
||||
if (!position_is_reachable(cos(a) * r, sin(a) * r)) {
|
||||
SERIAL_PROTOCOLLNPGM("?(M665 B)ed radius is implausible.");
|
||||
return;
|
||||
}
|
||||
|
@ -82,16 +82,16 @@ void GcodeSuite::M48() {
|
||||
Y_probe_location = parser.linearval('Y', Y_current + Y_PROBE_OFFSET_FROM_EXTRUDER);
|
||||
|
||||
#if DISABLED(DELTA)
|
||||
if (!WITHIN(X_probe_location, LOGICAL_X_POSITION(MIN_PROBE_X), LOGICAL_X_POSITION(MAX_PROBE_X))) {
|
||||
if (!WITHIN(X_probe_location, MIN_PROBE_X, MAX_PROBE_X)) {
|
||||
out_of_range_error(PSTR("X"));
|
||||
return;
|
||||
}
|
||||
if (!WITHIN(Y_probe_location, LOGICAL_Y_POSITION(MIN_PROBE_Y), LOGICAL_Y_POSITION(MAX_PROBE_Y))) {
|
||||
if (!WITHIN(Y_probe_location, MIN_PROBE_Y, MAX_PROBE_Y)) {
|
||||
out_of_range_error(PSTR("Y"));
|
||||
return;
|
||||
}
|
||||
#else
|
||||
if (!position_is_reachable_by_probe_xy(X_probe_location, Y_probe_location)) {
|
||||
if (!position_is_reachable_by_probe(X_probe_location, Y_probe_location)) {
|
||||
SERIAL_PROTOCOLLNPGM("? (X,Y) location outside of probeable radius.");
|
||||
return;
|
||||
}
|
||||
@ -184,7 +184,7 @@ void GcodeSuite::M48() {
|
||||
#else
|
||||
// If we have gone out too far, we can do a simple fix and scale the numbers
|
||||
// back in closer to the origin.
|
||||
while (!position_is_reachable_by_probe_xy(X_current, Y_current)) {
|
||||
while (!position_is_reachable_by_probe(X_current, Y_current)) {
|
||||
X_current *= 0.8;
|
||||
Y_current *= 0.8;
|
||||
if (verbose_level > 3) {
|
||||
|
@ -89,7 +89,7 @@ bool GcodeSuite::get_target_extruder_from_command() {
|
||||
void GcodeSuite::get_destination_from_command() {
|
||||
LOOP_XYZE(i) {
|
||||
if (parser.seen(axis_codes[i]))
|
||||
destination[i] = parser.value_axis_units((AxisEnum)i) + (axis_relative_modes[i] || relative_mode ? current_position[i] : 0);
|
||||
destination[i] = LOGICAL_TO_NATIVE(parser.value_axis_units((AxisEnum)i) + (axis_relative_modes[i] || relative_mode ? current_position[i] : 0), i);
|
||||
else
|
||||
destination[i] = current_position[i];
|
||||
}
|
||||
|
@ -67,7 +67,7 @@ void GcodeSuite::M428() {
|
||||
LOOP_XYZ(i) {
|
||||
if (axis_homed[i]) {
|
||||
const float base = (current_position[i] > (soft_endstop_min[i] + soft_endstop_max[i]) * 0.5) ? base_home_pos((AxisEnum)i) : 0,
|
||||
diff = base - RAW_POSITION(current_position[i], i);
|
||||
diff = base - current_position[i];
|
||||
if (WITHIN(diff, -20, 20)) {
|
||||
set_home_offset((AxisEnum)i, diff);
|
||||
}
|
||||
|
@ -46,11 +46,15 @@
|
||||
stepper.synchronize();
|
||||
|
||||
SERIAL_PROTOCOLPGM("\nLogical:");
|
||||
report_xyze(current_position);
|
||||
const float logical[XYZ] = {
|
||||
LOGICAL_X_POSITION(current_position[X_AXIS]),
|
||||
LOGICAL_Y_POSITION(current_position[Y_AXIS]),
|
||||
LOGICAL_Z_POSITION(current_position[Z_AXIS])
|
||||
};
|
||||
report_xyze(logical);
|
||||
|
||||
SERIAL_PROTOCOLPGM("Raw: ");
|
||||
const float raw[XYZ] = { RAW_X_POSITION(current_position[X_AXIS]), RAW_Y_POSITION(current_position[Y_AXIS]), RAW_Z_POSITION(current_position[Z_AXIS]) };
|
||||
report_xyz(raw);
|
||||
report_xyz(current_position);
|
||||
|
||||
SERIAL_PROTOCOLPGM("Leveled:");
|
||||
float leveled[XYZ] = { current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS] };
|
||||
|
@ -44,7 +44,7 @@
|
||||
* options for G2/G3 arc generation. In future these options may be GCode tunable.
|
||||
*/
|
||||
void plan_arc(
|
||||
float logical[XYZE], // Destination position
|
||||
float rtarget[XYZE], // Destination position
|
||||
float *offset, // Center of rotation relative to current_position
|
||||
uint8_t clockwise // Clockwise?
|
||||
) {
|
||||
@ -65,10 +65,10 @@ void plan_arc(
|
||||
const float radius = HYPOT(r_P, r_Q),
|
||||
center_P = current_position[p_axis] - r_P,
|
||||
center_Q = current_position[q_axis] - r_Q,
|
||||
rt_X = logical[p_axis] - center_P,
|
||||
rt_Y = logical[q_axis] - center_Q,
|
||||
linear_travel = logical[l_axis] - current_position[l_axis],
|
||||
extruder_travel = logical[E_AXIS] - current_position[E_AXIS];
|
||||
rt_X = rtarget[p_axis] - center_P,
|
||||
rt_Y = rtarget[q_axis] - center_Q,
|
||||
linear_travel = rtarget[l_axis] - current_position[l_axis],
|
||||
extruder_travel = rtarget[E_AXIS] - current_position[E_AXIS];
|
||||
|
||||
// CCW angle of rotation between position and target from the circle center. Only one atan2() trig computation required.
|
||||
float angular_travel = ATAN2(r_P * rt_Y - r_Q * rt_X, r_P * rt_X + r_Q * rt_Y);
|
||||
@ -76,7 +76,7 @@ void plan_arc(
|
||||
if (clockwise) angular_travel -= RADIANS(360);
|
||||
|
||||
// Make a circle if the angular rotation is 0 and the target is current position
|
||||
if (angular_travel == 0 && current_position[p_axis] == logical[p_axis] && current_position[q_axis] == logical[q_axis])
|
||||
if (angular_travel == 0 && current_position[p_axis] == rtarget[p_axis] && current_position[q_axis] == rtarget[q_axis])
|
||||
angular_travel = RADIANS(360);
|
||||
|
||||
const float mm_of_travel = HYPOT(angular_travel * radius, FABS(linear_travel));
|
||||
@ -176,7 +176,7 @@ void plan_arc(
|
||||
}
|
||||
|
||||
// Ensure last segment arrives at target location.
|
||||
planner.buffer_line_kinematic(logical, fr_mm_s, active_extruder);
|
||||
planner.buffer_line_kinematic(rtarget, fr_mm_s, active_extruder);
|
||||
|
||||
// As far as the parser is concerned, the position is now == target. In reality the
|
||||
// motion control system might still be processing the action and the real tool position
|
||||
|
@ -42,7 +42,7 @@ void GcodeSuite::G30() {
|
||||
const float xpos = parser.linearval('X', current_position[X_AXIS] + X_PROBE_OFFSET_FROM_EXTRUDER),
|
||||
ypos = parser.linearval('Y', current_position[Y_AXIS] + Y_PROBE_OFFSET_FROM_EXTRUDER);
|
||||
|
||||
if (!position_is_reachable_by_probe_xy(xpos, ypos)) return;
|
||||
if (!position_is_reachable_by_probe(xpos, ypos)) return;
|
||||
|
||||
// Disable leveling so the planner won't mess with us
|
||||
#if HAS_LEVELING
|
||||
|
@ -32,8 +32,8 @@
|
||||
inline bool SCARA_move_to_cal(const uint8_t delta_a, const uint8_t delta_b) {
|
||||
if (IsRunning()) {
|
||||
forward_kinematics_SCARA(delta_a, delta_b);
|
||||
destination[X_AXIS] = LOGICAL_X_POSITION(cartes[X_AXIS]);
|
||||
destination[Y_AXIS] = LOGICAL_Y_POSITION(cartes[Y_AXIS]);
|
||||
destination[X_AXIS] = cartes[X_AXIS];
|
||||
destination[Y_AXIS] = cartes[Y_AXIS];
|
||||
destination[Z_AXIS] = current_position[Z_AXIS];
|
||||
prepare_move_to_destination();
|
||||
return true;
|
||||
|
Reference in New Issue
Block a user