Add custom types for position (#15204)
This commit is contained in:
		@@ -35,7 +35,7 @@
 | 
			
		||||
  #include "../../module/stepper.h"
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
extern float destination[XYZE];
 | 
			
		||||
extern xyze_pos_t destination;
 | 
			
		||||
 | 
			
		||||
#if ENABLED(VARIABLE_G0_FEEDRATE)
 | 
			
		||||
  feedRate_t fast_move_feedrate = MMM_TO_MMS(G0_FEEDRATE);
 | 
			
		||||
@@ -87,12 +87,12 @@ void GcodeSuite::G0_G1(
 | 
			
		||||
      if (MIN_AUTORETRACT <= MAX_AUTORETRACT) {
 | 
			
		||||
        // When M209 Autoretract is enabled, convert E-only moves to firmware retract/recover moves
 | 
			
		||||
        if (fwretract.autoretract_enabled && parser.seen('E') && !(parser.seen('X') || parser.seen('Y') || parser.seen('Z'))) {
 | 
			
		||||
          const float echange = destination[E_AXIS] - current_position[E_AXIS];
 | 
			
		||||
          const float echange = destination.e - current_position.e;
 | 
			
		||||
          // Is this a retract or recover move?
 | 
			
		||||
          if (WITHIN(ABS(echange), MIN_AUTORETRACT, MAX_AUTORETRACT) && fwretract.retracted[active_extruder] == (echange > 0.0)) {
 | 
			
		||||
            current_position[E_AXIS] = destination[E_AXIS]; // Hide a G1-based retract/recover from calculations
 | 
			
		||||
            sync_plan_position_e();                         // AND from the planner
 | 
			
		||||
            return fwretract.retract(echange < 0.0);        // Firmware-based retract/recover (double-retract ignored)
 | 
			
		||||
            current_position.e = destination.e;       // Hide a G1-based retract/recover from calculations
 | 
			
		||||
            sync_plan_position_e();                   // AND from the planner
 | 
			
		||||
            return fwretract.retract(echange < 0.0);  // Firmware-based retract/recover (double-retract ignored)
 | 
			
		||||
          }
 | 
			
		||||
        }
 | 
			
		||||
      }
 | 
			
		||||
 
 | 
			
		||||
@@ -50,9 +50,9 @@
 | 
			
		||||
 * options for G2/G3 arc generation. In future these options may be GCode tunable.
 | 
			
		||||
 */
 | 
			
		||||
void plan_arc(
 | 
			
		||||
  const float (&cart)[XYZE],  // Destination position
 | 
			
		||||
  const float (&offset)[2],   // Center of rotation relative to current_position
 | 
			
		||||
  const uint8_t clockwise     // Clockwise?
 | 
			
		||||
  const xyze_pos_t &cart,   // Destination position
 | 
			
		||||
  const ab_float_t &offset, // Center of rotation relative to current_position
 | 
			
		||||
  const uint8_t clockwise   // Clockwise?
 | 
			
		||||
) {
 | 
			
		||||
  #if ENABLED(CNC_WORKSPACE_PLANES)
 | 
			
		||||
    AxisEnum p_axis, q_axis, l_axis;
 | 
			
		||||
@@ -67,21 +67,21 @@ void plan_arc(
 | 
			
		||||
  #endif
 | 
			
		||||
 | 
			
		||||
  // Radius vector from center to current location
 | 
			
		||||
  float r_P = -offset[0], r_Q = -offset[1];
 | 
			
		||||
  ab_float_t rvec = -offset;
 | 
			
		||||
 | 
			
		||||
  const float radius = HYPOT(r_P, r_Q),
 | 
			
		||||
  const float radius = HYPOT(rvec.a, rvec.b),
 | 
			
		||||
              #if ENABLED(AUTO_BED_LEVELING_UBL)
 | 
			
		||||
                start_L  = current_position[l_axis],
 | 
			
		||||
              #endif
 | 
			
		||||
              center_P = current_position[p_axis] - r_P,
 | 
			
		||||
              center_Q = current_position[q_axis] - r_Q,
 | 
			
		||||
              center_P = current_position[p_axis] - rvec.a,
 | 
			
		||||
              center_Q = current_position[q_axis] - rvec.b,
 | 
			
		||||
              rt_X = cart[p_axis] - center_P,
 | 
			
		||||
              rt_Y = cart[q_axis] - center_Q,
 | 
			
		||||
              linear_travel = cart[l_axis] - current_position[l_axis],
 | 
			
		||||
              extruder_travel = cart[E_AXIS] - current_position[E_AXIS];
 | 
			
		||||
              extruder_travel = cart.e - current_position.e;
 | 
			
		||||
 | 
			
		||||
  // 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);
 | 
			
		||||
  float angular_travel = ATAN2(rvec.a * rt_Y - rvec.b * rt_X, rvec.a * rt_X + rvec.b * rt_Y);
 | 
			
		||||
  if (angular_travel < 0) angular_travel += RADIANS(360);
 | 
			
		||||
  #ifdef MIN_ARC_SEGMENTS
 | 
			
		||||
    uint16_t min_segments = CEIL((MIN_ARC_SEGMENTS) * (angular_travel / RADIANS(360)));
 | 
			
		||||
@@ -133,7 +133,7 @@ void plan_arc(
 | 
			
		||||
   * This is important when there are successive arc motions.
 | 
			
		||||
   */
 | 
			
		||||
  // Vector rotation matrix values
 | 
			
		||||
  float raw[XYZE];
 | 
			
		||||
  xyze_pos_t raw;
 | 
			
		||||
  const float theta_per_segment = angular_travel / segments,
 | 
			
		||||
              linear_per_segment = linear_travel / segments,
 | 
			
		||||
              extruder_per_segment = extruder_travel / segments,
 | 
			
		||||
@@ -144,7 +144,7 @@ void plan_arc(
 | 
			
		||||
  raw[l_axis] = current_position[l_axis];
 | 
			
		||||
 | 
			
		||||
  // Initialize the extruder axis
 | 
			
		||||
  raw[E_AXIS] = current_position[E_AXIS];
 | 
			
		||||
  raw.e = current_position.e;
 | 
			
		||||
 | 
			
		||||
  const feedRate_t scaled_fr_mm_s = MMS_SCALED(feedrate_mm_s);
 | 
			
		||||
 | 
			
		||||
@@ -168,10 +168,10 @@ void plan_arc(
 | 
			
		||||
 | 
			
		||||
    #if N_ARC_CORRECTION > 1
 | 
			
		||||
      if (--arc_recalc_count) {
 | 
			
		||||
        // Apply vector rotation matrix to previous r_P / 1
 | 
			
		||||
        const float r_new_Y = r_P * sin_T + r_Q * cos_T;
 | 
			
		||||
        r_P = r_P * cos_T - r_Q * sin_T;
 | 
			
		||||
        r_Q = r_new_Y;
 | 
			
		||||
        // Apply vector rotation matrix to previous rvec.a / 1
 | 
			
		||||
        const float r_new_Y = rvec.a * sin_T + rvec.b * cos_T;
 | 
			
		||||
        rvec.a = rvec.a * cos_T - rvec.b * sin_T;
 | 
			
		||||
        rvec.b = r_new_Y;
 | 
			
		||||
      }
 | 
			
		||||
      else
 | 
			
		||||
    #endif
 | 
			
		||||
@@ -185,20 +185,20 @@ void plan_arc(
 | 
			
		||||
      // To reduce stuttering, the sin and cos could be computed at different times.
 | 
			
		||||
      // For now, compute both at the same time.
 | 
			
		||||
      const float cos_Ti = cos(i * theta_per_segment), sin_Ti = sin(i * theta_per_segment);
 | 
			
		||||
      r_P = -offset[0] * cos_Ti + offset[1] * sin_Ti;
 | 
			
		||||
      r_Q = -offset[0] * sin_Ti - offset[1] * cos_Ti;
 | 
			
		||||
      rvec.a = -offset[0] * cos_Ti + offset[1] * sin_Ti;
 | 
			
		||||
      rvec.b = -offset[0] * sin_Ti - offset[1] * cos_Ti;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // Update raw location
 | 
			
		||||
    raw[p_axis] = center_P + r_P;
 | 
			
		||||
    raw[q_axis] = center_Q + r_Q;
 | 
			
		||||
    raw[p_axis] = center_P + rvec.a;
 | 
			
		||||
    raw[q_axis] = center_Q + rvec.b;
 | 
			
		||||
    #if ENABLED(AUTO_BED_LEVELING_UBL)
 | 
			
		||||
      raw[l_axis] = start_L;
 | 
			
		||||
      UNUSED(linear_per_segment);
 | 
			
		||||
    #else
 | 
			
		||||
      raw[l_axis] += linear_per_segment;
 | 
			
		||||
    #endif
 | 
			
		||||
    raw[E_AXIS] += extruder_per_segment;
 | 
			
		||||
    raw.e += extruder_per_segment;
 | 
			
		||||
 | 
			
		||||
    apply_motion_limits(raw);
 | 
			
		||||
 | 
			
		||||
@@ -215,7 +215,7 @@ void plan_arc(
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  // Ensure last segment arrives at target location.
 | 
			
		||||
  COPY(raw, cart);
 | 
			
		||||
  raw = cart;
 | 
			
		||||
  #if ENABLED(AUTO_BED_LEVELING_UBL)
 | 
			
		||||
    raw[l_axis] = start_L;
 | 
			
		||||
  #endif
 | 
			
		||||
@@ -235,7 +235,7 @@ void plan_arc(
 | 
			
		||||
  #if ENABLED(AUTO_BED_LEVELING_UBL)
 | 
			
		||||
    raw[l_axis] = start_L;
 | 
			
		||||
  #endif
 | 
			
		||||
  COPY(current_position, raw);
 | 
			
		||||
  current_position = raw;
 | 
			
		||||
} // plan_arc
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
@@ -278,32 +278,27 @@ void GcodeSuite::G2_G3(const bool clockwise) {
 | 
			
		||||
      relative_mode = relative_mode_backup;
 | 
			
		||||
    #endif
 | 
			
		||||
 | 
			
		||||
    float arc_offset[2] = { 0, 0 };
 | 
			
		||||
    ab_float_t arc_offset = { 0, 0 };
 | 
			
		||||
    if (parser.seenval('R')) {
 | 
			
		||||
      const float r = parser.value_linear_units();
 | 
			
		||||
      if (r) {
 | 
			
		||||
        const float p1 = current_position[X_AXIS], q1 = current_position[Y_AXIS],
 | 
			
		||||
                    p2 = destination[X_AXIS], q2 = destination[Y_AXIS];
 | 
			
		||||
        if (p2 != p1 || q2 != q1) {
 | 
			
		||||
          const float e = clockwise ^ (r < 0) ? -1 : 1,            // clockwise -1/1, counterclockwise 1/-1
 | 
			
		||||
                      dx = p2 - p1, dy = q2 - q1,                  // X and Y differences
 | 
			
		||||
                      d = HYPOT(dx, dy),                           // Linear distance between the points
 | 
			
		||||
                      dinv = 1/d,                                  // Inverse of d
 | 
			
		||||
                      h = SQRT(sq(r) - sq(d * 0.5f)),              // Distance to the arc pivot-point
 | 
			
		||||
                      mx = (p1 + p2) * 0.5f, my = (q1 + q2) * 0.5f,// Point between the two points
 | 
			
		||||
                      sx = -dy * dinv, sy = dx * dinv,             // Slope of the perpendicular bisector
 | 
			
		||||
                      cx = mx + e * h * sx, cy = my + e * h * sy;  // Pivot-point of the arc
 | 
			
		||||
          arc_offset[0] = cx - p1;
 | 
			
		||||
          arc_offset[1] = cy - q1;
 | 
			
		||||
        const xy_pos_t p1 = current_position, p2 = destination;
 | 
			
		||||
        if (p1 != p2) {
 | 
			
		||||
          const xy_pos_t d = p2 - p1, m = (p1 + p2) * 0.5f;   // XY distance and midpoint
 | 
			
		||||
          const float e = clockwise ^ (r < 0) ? -1 : 1,       // clockwise -1/1, counterclockwise 1/-1
 | 
			
		||||
                      len = d.magnitude(),                    // Total move length
 | 
			
		||||
                      h = SQRT(sq(r) - sq(len * 0.5f));       // Distance to the arc pivot-point
 | 
			
		||||
          const xy_pos_t s = { d.x, -d.y };                   // Inverse Slope of the perpendicular bisector
 | 
			
		||||
          arc_offset = m + s * RECIPROCAL(len) * e * h - p1;  // The calculated offset
 | 
			
		||||
        }
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
    else {
 | 
			
		||||
      if (parser.seenval('I')) arc_offset[0] = parser.value_linear_units();
 | 
			
		||||
      if (parser.seenval('J')) arc_offset[1] = parser.value_linear_units();
 | 
			
		||||
      if (parser.seenval('I')) arc_offset.a = parser.value_linear_units();
 | 
			
		||||
      if (parser.seenval('J')) arc_offset.b = parser.value_linear_units();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if (arc_offset[0] || arc_offset[1]) {
 | 
			
		||||
    if (arc_offset) {
 | 
			
		||||
 | 
			
		||||
      #if ENABLED(ARC_P_CIRCLES)
 | 
			
		||||
        // P indicates number of circles to do
 | 
			
		||||
 
 | 
			
		||||
@@ -27,11 +27,6 @@
 | 
			
		||||
#include "../../module/motion.h"
 | 
			
		||||
#include "../../module/planner_bezier.h"
 | 
			
		||||
 | 
			
		||||
void plan_cubic_move(const float (&cart)[XYZE], const float (&offset)[4]) {
 | 
			
		||||
  cubic_b_spline(current_position, cart, offset, MMS_SCALED(feedrate_mm_s), active_extruder);
 | 
			
		||||
  COPY(current_position, cart);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Parameters interpreted according to:
 | 
			
		||||
 * http://linuxcnc.org/docs/2.6/html/gcode/parser.html#sec:G5-Cubic-Spline
 | 
			
		||||
@@ -57,14 +52,13 @@ void GcodeSuite::G5() {
 | 
			
		||||
 | 
			
		||||
    get_destination_from_command();
 | 
			
		||||
 | 
			
		||||
    const float offset[4] = {
 | 
			
		||||
      parser.linearval('I'),
 | 
			
		||||
      parser.linearval('J'),
 | 
			
		||||
      parser.linearval('P'),
 | 
			
		||||
      parser.linearval('Q')
 | 
			
		||||
    const xy_pos_t offsets[2] = {
 | 
			
		||||
      { parser.linearval('I'), parser.linearval('J') },
 | 
			
		||||
      { parser.linearval('P'), parser.linearval('Q') }
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    plan_cubic_move(destination, offset);
 | 
			
		||||
    cubic_b_spline(current_position, destination, offsets, MMS_SCALED(feedrate_mm_s), active_extruder);
 | 
			
		||||
    current_position = destination;
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -40,21 +40,21 @@
 | 
			
		||||
 | 
			
		||||
#if ENABLED(BABYSTEP_ZPROBE_OFFSET)
 | 
			
		||||
 | 
			
		||||
  FORCE_INLINE void mod_zprobe_zoffset(const float &offs) {
 | 
			
		||||
  FORCE_INLINE void mod_probe_offset(const float &offs) {
 | 
			
		||||
    if (true
 | 
			
		||||
      #if ENABLED(BABYSTEP_HOTEND_Z_OFFSET)
 | 
			
		||||
        && active_extruder == 0
 | 
			
		||||
      #endif
 | 
			
		||||
    ) {
 | 
			
		||||
      probe_offset[Z_AXIS] += offs;
 | 
			
		||||
      probe_offset.z += offs;
 | 
			
		||||
      SERIAL_ECHO_START();
 | 
			
		||||
      SERIAL_ECHOLNPAIR(MSG_PROBE_OFFSET MSG_Z ": ", probe_offset[Z_AXIS]);
 | 
			
		||||
      SERIAL_ECHOLNPAIR(MSG_PROBE_OFFSET MSG_Z ": ", probe_offset.z);
 | 
			
		||||
    }
 | 
			
		||||
    else {
 | 
			
		||||
      #if ENABLED(BABYSTEP_HOTEND_Z_OFFSET)
 | 
			
		||||
        hotend_offset[Z_AXIS][active_extruder] -= offs;
 | 
			
		||||
        hotend_offset[active_extruder].z -= offs;
 | 
			
		||||
        SERIAL_ECHO_START();
 | 
			
		||||
        SERIAL_ECHOLNPAIR(MSG_PROBE_OFFSET MSG_Z ": ", hotend_offset[Z_AXIS][active_extruder]);
 | 
			
		||||
        SERIAL_ECHOLNPAIR(MSG_PROBE_OFFSET MSG_Z ": ", hotend_offset[active_extruder].z);
 | 
			
		||||
      #endif
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
@@ -81,7 +81,7 @@ void GcodeSuite::M290() {
 | 
			
		||||
        const float offs = constrain(parser.value_axis_units((AxisEnum)a), -2, 2);
 | 
			
		||||
        babystep.add_mm((AxisEnum)a, offs);
 | 
			
		||||
        #if ENABLED(BABYSTEP_ZPROBE_OFFSET)
 | 
			
		||||
          if (a == Z_AXIS && (!parser.seen('P') || parser.value_bool())) mod_zprobe_zoffset(offs);
 | 
			
		||||
          if (a == Z_AXIS && (!parser.seen('P') || parser.value_bool())) mod_probe_offset(offs);
 | 
			
		||||
        #endif
 | 
			
		||||
      }
 | 
			
		||||
  #else
 | 
			
		||||
@@ -89,7 +89,7 @@ void GcodeSuite::M290() {
 | 
			
		||||
      const float offs = constrain(parser.value_axis_units(Z_AXIS), -2, 2);
 | 
			
		||||
      babystep.add_mm(Z_AXIS, offs);
 | 
			
		||||
      #if ENABLED(BABYSTEP_ZPROBE_OFFSET)
 | 
			
		||||
        if (!parser.seen('P') || parser.value_bool()) mod_zprobe_zoffset(offs);
 | 
			
		||||
        if (!parser.seen('P') || parser.value_bool()) mod_probe_offset(offs);
 | 
			
		||||
      #endif
 | 
			
		||||
    }
 | 
			
		||||
  #endif
 | 
			
		||||
@@ -98,17 +98,17 @@ void GcodeSuite::M290() {
 | 
			
		||||
    SERIAL_ECHO_START();
 | 
			
		||||
 | 
			
		||||
    #if ENABLED(BABYSTEP_ZPROBE_OFFSET)
 | 
			
		||||
      SERIAL_ECHOLNPAIR(MSG_PROBE_OFFSET " " MSG_Z, probe_offset[Z_AXIS]);
 | 
			
		||||
      SERIAL_ECHOLNPAIR(MSG_PROBE_OFFSET " " MSG_Z, probe_offset.z);
 | 
			
		||||
    #endif
 | 
			
		||||
 | 
			
		||||
    #if ENABLED(BABYSTEP_HOTEND_Z_OFFSET)
 | 
			
		||||
    {
 | 
			
		||||
      SERIAL_ECHOLNPAIR("Hotend ", int(active_extruder), "Offset"
 | 
			
		||||
        #if ENABLED(BABYSTEP_XY)
 | 
			
		||||
          " X", hotend_offset[X_AXIS][active_extruder],
 | 
			
		||||
          " Y", hotend_offset[Y_AXIS][active_extruder],
 | 
			
		||||
          " X", hotend_offset[active_extruder].x,
 | 
			
		||||
          " Y", hotend_offset[active_extruder].y,
 | 
			
		||||
        #endif
 | 
			
		||||
        " Z", hotend_offset[Z_AXIS][active_extruder]
 | 
			
		||||
        " Z", hotend_offset[active_extruder].z
 | 
			
		||||
      );
 | 
			
		||||
    }
 | 
			
		||||
    #endif
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user