diff --git a/src/libslic3r/GCode/GCodeProcessor.cpp b/src/libslic3r/GCode/GCodeProcessor.cpp index baf2bb46b9..a874ac2a60 100644 --- a/src/libslic3r/GCode/GCodeProcessor.cpp +++ b/src/libslic3r/GCode/GCodeProcessor.cpp @@ -5467,6 +5467,13 @@ void GCodeProcessor::process_G1(const std::array, 4>& axes if (!is_extrusion_only_move(delta_pos)) curr.enter_direction = curr.enter_direction / norm; curr.exit_direction = curr.enter_direction; + // Orca: a smooth arc meets the moves around it along its tangents, not along its end chords. + if (m_smooth_arc) { + if (m_smooth_arc->first_chord) + curr.enter_direction = m_smooth_arc->start_tangent; + if (m_smooth_arc->last_chord) + curr.exit_direction = m_smooth_arc->end_tangent; + } curr.jd_unit_vec = Vec4f(static_cast(delta_pos[X]), static_cast(delta_pos[Y]), static_cast(delta_pos[Z]), @@ -5489,7 +5496,11 @@ void GCodeProcessor::process_G1(const std::array, 4>& axes //BBS: limite the cruise according to centripetal acceleration //Only need to handle when both prev and curr segment has movement in x-y plane - if (m_flavor != gcfKlipper && (prev.exit_direction(0) != 0.0f || prev.exit_direction(1) != 0.0f) && + // Orca: a smooth arc takes its own radius. The estimate below would read the turn from the previous + // move into the arc's first chord as its curvature. + if (m_smooth_arc) + curr.feedrate = std::min(curr.feedrate, std::sqrt(get_acceleration(static_cast(i)) * m_smooth_arc->radius)); + else if (m_flavor != gcfKlipper && (prev.exit_direction(0) != 0.0f || prev.exit_direction(1) != 0.0f) && (curr.enter_direction(0) != 0.0f || curr.enter_direction(1) != 0.0f)) { Vec3f v1 = prev.exit_direction; v1(2, 0) = 0.0f; @@ -5610,7 +5621,10 @@ void GCodeProcessor::process_G1(const std::array, 4>& axes // calculates block entry feedrate float vmax_junction = use_junction_deviation ? vmax_junction_jd : curr.safe_feedrate; - if (!use_junction_deviation && has_prev_move) { + // Orca: the chords of a smooth arc do not meet at jerk limited corners. + if (!use_junction_deviation && has_prev_move && m_smooth_arc && !m_smooth_arc->first_chord) + vmax_junction = std::min(prev.feedrate, block.feedrate_profile.cruise); + else if (!use_junction_deviation && has_prev_move) { bool prev_speed_larger = prev.feedrate > block.feedrate_profile.cruise; float smaller_speed_factor = prev_speed_larger ? (block.feedrate_profile.cruise / prev.feedrate) : (prev.feedrate / block.feedrate_profile.cruise); // Pick the smaller of the nominal speeds. Higher speed shall not be achieved at the junction during coasting. @@ -6257,6 +6271,14 @@ void GCodeProcessor::process_G2_G3(const GCodeReader::GCodeLine& line, bool cloc return ret; }; + // Orca: see m_smooth_arc. Other firmware splits an arc into segments it plans like any other moves. + if (s_IsBBLPrinter && m_flavor != gcfKlipper) { + const auto tangent = [clockwise](const Vec3d& radial) { + return Vec3f(clockwise ? Vec3f(radial.y(), -radial.x(), 0.0f) : Vec3f(-radial.y(), radial.x(), 0.0f)).normalized(); + }; + m_smooth_arc = SmoothArc{ float(arc.start_radius()), tangent(rel_arc_start), tangent(rel_arc_end), true, false }; + } + auto internal_only_g1_line = [this](const AxisCoords& target, bool has_z, const std::optional& feedrate, const std::optional& extrusion, const std::optional& remaining_internal_g1_lines = std::nullopt) { std::array, 4> g1_axes = { target[X], target[Y], std::nullopt, std::nullopt }; @@ -6267,7 +6289,11 @@ void GCodeProcessor::process_G2_G3(const GCodeReader::GCodeLine& line, bool cloc g1_axes[E] = target[E]; if (feedrate.has_value()) g1_feedrate = (double)*feedrate / MMMIN_TO_MMSEC; + if (m_smooth_arc) + m_smooth_arc->last_chord = !remaining_internal_g1_lines.has_value(); process_G1(g1_axes, g1_feedrate, G1DiscretizationOrigin::G2G3, remaining_internal_g1_lines); + if (m_smooth_arc) + m_smooth_arc->first_chord = false; }; if (m_flavor == gcfMarlinFirmware) { @@ -6405,6 +6431,8 @@ void GCodeProcessor::process_G2_G3(const GCodeReader::GCodeLine& line, bool cloc internal_only_g1_line(adjust_target(end_position, prev_target), arc.delta_z() != 0.0, (segments == 1) ? feedrate : std::nullopt, extrusion); } + m_smooth_arc.reset(); + // Internal linearized arc segments inherit the arc's starting certainty. // Only the original absolute command may establish a newly known endpoint. update_position_known_from_move(line); diff --git a/src/libslic3r/GCode/GCodeProcessor.hpp b/src/libslic3r/GCode/GCodeProcessor.hpp index 22c2d45a99..e24fb61a82 100644 --- a/src/libslic3r/GCode/GCodeProcessor.hpp +++ b/src/libslic3r/GCode/GCodeProcessor.hpp @@ -1336,6 +1336,18 @@ inline constexpr float DEFAULT_FILAMENT_DENSITY = 1.245f; unsigned int m_line_id; unsigned int m_last_line_id; float m_feedrate; // mm/s + // Orca: Bambu Lab firmware runs a G2/G3 as one smooth arc. While process_G2_G3() times such an arc as + // chords, this describes it, so the chords take the arc's own speed limit and neither meet each other + // nor the moves around the arc at jerk limited corners. + struct SmoothArc + { + float radius; // mm + Vec3f start_tangent; + Vec3f end_tangent; + bool first_chord; + bool last_chord; + }; + std::optional m_smooth_arc; float m_width; // mm float m_height; // mm float m_forced_width; // mm diff --git a/tests/fff_print/test_gcode_timing.cpp b/tests/fff_print/test_gcode_timing.cpp index cb1b2c4062..7c4e5c8240 100644 --- a/tests/fff_print/test_gcode_timing.cpp +++ b/tests/fff_print/test_gcode_timing.cpp @@ -701,6 +701,75 @@ TEST_CASE("How fast a corner is taken does not depend on how much is extruded th } } +// The estimator splits a G2/G3 into chords. Bambu Lab firmware runs the arc as one smooth path, which +// arc-fitted gyroid infill relies on: timed as jerk-limited chords it came out hours too long. +namespace { + +constexpr double arc_e_per_mm = 0.03; + +// A clockwise half circle from (x, y) around the point `radius` to its right. It starts heading +Y. +std::string half_circle(double x, double y, double radius, double feedrate) +{ + std::ostringstream os; + os << std::fixed << std::setprecision(4) << "G2 X" << x + 2.0 * radius << " Y" << y << " I" << radius + << " J0 E" << M_PI * radius * arc_e_per_mm << " F" << feedrate << "\n"; + return os.str(); +} + +// A straight move from (x, y) along +Y, the half circle's starting tangent. +std::string straight_up(double x, double y, double length, double feedrate) +{ + std::ostringstream os; + os << std::fixed << std::setprecision(4) << "G1 X" << x << " Y" << y + length << " E" << length * arc_e_per_mm + << " F" << feedrate << "\n"; + return os.str(); +} + +// Time of `move` after a 40mm extrusion at 150mm/s reaching its start (x, y) heading `heading_deg`. +double time_after_lead_in(double x, double y, double heading_deg, const std::string& move, bool is_bbl_printer, + double jerk) +{ + const double len = 40.0; + const double a = heading_deg * M_PI / 180.0; + std::ostringstream os; + os << std::fixed << std::setprecision(4) << "M83\nG1 Z0.2 F1200\n" + << "G1 X" << x - len * std::cos(a) << " Y" << y - len * std::sin(a) << " F9000\n" + << "G1 X" << x << " Y" << y << " E" << len * arc_e_per_mm << " F9000\n" + << move; + GCodeProcessor proc; + run_processor(proc, make_junction_config(gcfMarlinLegacy, jerk, 0.0), os.str().c_str(), is_bbl_printer); + return proc.get_time(PrintEstimatedStatistics::ETimeMode::Normal); +} + +} // namespace + +TEST_CASE("A Bambu Lab arc is timed as one smooth move rather than as jerk-limited chords", "[GCodeTiming][Regression]") +{ + // Entered along its tangent, the arc has no corner at its start or between its chords, where a 1mm/s jerk + // would nearly stop the toolhead. A 50mm radius keeps the centripetal limit, sqrt(1000 * 50) = 224mm/s, + // above the commanded 150mm/s, so the half circle takes as long as a straight move of its length. + const double radius = 50.0; + const double jerk = 1.0; + const double straight = time_after_lead_in(10.0, 60.0, 90.0, straight_up(10.0, 60.0, M_PI * radius, 9000.0), true, jerk); + REQUIRE_THAT(time_after_lead_in(10.0, 60.0, 90.0, half_circle(10.0, 60.0, radius, 9000.0), true, jerk), + WithinRel(straight, 0.01)); + // Other printers keep planning the chords as the firmware's own arc segments. + REQUIRE(time_after_lead_in(10.0, 60.0, 90.0, half_circle(10.0, 60.0, radius, 9000.0), false, jerk) > 1.5 * straight); +} + +TEST_CASE("A Bambu Lab arc is limited by its own radius however it is entered", "[GCodeTiming][Regression]") +{ + // A 5mm radius limits the arc to sqrt(1000 * 5) = 70.7mm/s. Entered at a 25 degree corner, it takes as long + // as a straight move at that speed turning the same corner: the corner is not read as the arc's curvature. + // A 100mm/s jerk lets both take the corner at that speed. + const double radius = 5.0; + const double jerk = 100.0; + const double limit = std::sqrt(1000.0 * radius) * 60.0; // mm/min + const double straight = time_after_lead_in(55.0, 60.0, 65.0, straight_up(55.0, 60.0, M_PI * radius, limit), true, jerk); + REQUIRE_THAT(time_after_lead_in(55.0, 60.0, 65.0, half_circle(55.0, 60.0, radius, 9000.0), true, jerk), + WithinRel(straight, 0.01)); +} + // Expected times are Klipper's own planner math (klippy/toolhead.py). For a move from rest to rest, // LookAheadQueue.flush() reduces to cruise_v2 = min(vmax^2, d * accel, d * pseudo_accel) with // pseudo_accel = accel * (1 - minimum_cruise_ratio), and Move.set_junction() to a trapezoid at accel;