Keep the Plate Offset When Swapping in the Belt Writer

The belt writer replaced the plate-offset-carrying writer mid-export, so belt G-code for any plate but the first kept the plate origin and long-travel clipping used the wrong frame. GCode now remembers the offset and hands it to the new writer, and the writer's first-layer probes use the plate-local point it emits.
This commit is contained in:
Hanif Koh
2026-09-11 15:59:19 +08:00
parent bb0ed1dcf7
commit 5de5cdd8f8
3 changed files with 8 additions and 4 deletions

View File

@@ -15,6 +15,7 @@ void BeltGCode::init_belt_writer(Print &print, bool is_bbl_printers)
// Axis remap and build volume max are set by base GCode after init_belt_writer returns.
belt_writer->set_belt_back_transform(print.config());
belt_writer->set_machine_frame_transform(print.config());
belt_writer->set_xy_offset(m_gcode_offset.x(), m_gcode_offset.y());
m_writer = std::move(belt_writer);
}

View File

@@ -85,7 +85,7 @@ std::string BeltGCodeWriter::travel_to_xy(const Vec2d &point, const std::string
w.emit_xyz(machine);
const bool first_layer_for_point = belt_point_on_first_layer(
m_first_layer_plane, m_first_layer_thickness_mm, m_is_first_layer,
Vec3d(point.x(), point.y(), m_pos.z()));
Vec3d(point_on_plate.x(), point_on_plate.y(), m_pos.z()));
auto speed = first_layer_for_point
? this->config.get_abs_value_at("initial_layer_travel_speed", m_cached_extruder_idx)
: this->config.travel_speed.get_at(m_cached_extruder_idx);
@@ -115,7 +115,7 @@ std::string BeltGCodeWriter::_travel_to_z(double z, const std::string &comment)
if (speed == 0.) {
const bool first_layer_for_point = belt_point_on_first_layer(
m_first_layer_plane, m_first_layer_thickness_mm, m_is_first_layer,
Vec3d(m_pos.x(), m_pos.y(), z));
Vec3d(m_pos.x() - m_x_offset, m_pos.y() - m_y_offset, z));
speed = first_layer_for_point ? this->config.get_abs_value_at("initial_layer_travel_speed", m_cached_extruder_idx)
: this->config.travel_speed.get_at(m_cached_extruder_idx);
}
@@ -181,7 +181,8 @@ std::string BeltGCodeWriter::travel_to_xyz(const Vec3d &point, const std::string
Vec3d dest_point = point;
const bool first_layer_for_point = belt_point_on_first_layer(
m_first_layer_plane, m_first_layer_thickness_mm, m_is_first_layer, point);
m_first_layer_plane, m_first_layer_thickness_mm, m_is_first_layer,
Vec3d(point.x() - m_x_offset, point.y() - m_y_offset, point.z()));
auto travel_speed =
first_layer_for_point ? this->config.get_abs_value_at("initial_layer_travel_speed", m_cached_extruder_idx)
: this->config.travel_speed.get_at(m_cached_extruder_idx);

View File

@@ -228,7 +228,7 @@ public:
void do_export(Print* print, const char* path, GCodeProcessorResult* result = nullptr, ThumbnailsGeneratorCallback thumbnail_cb = nullptr);
void export_layer_filaments(GCodeProcessorResult* result);
//BBS: set offset for gcode writer
void set_gcode_offset(double x, double y) { m_writer->set_xy_offset(x, y); m_processor.set_xy_offset(x, y);}
void set_gcode_offset(double x, double y) { m_gcode_offset = Vec2d(x, y); m_writer->set_xy_offset(x, y); m_processor.set_xy_offset(x, y);}
// Exported for the helper classes (OozePrevention, Wipe) and for the Perl binding for unit tests.
const Vec2d& origin() const { return m_origin; }
@@ -767,6 +767,8 @@ protected:
// printers without a Z-axis shear; in that case all per-path plane
// checks short-circuit to the legacy Layer::id() == 0 path.
std::unique_ptr<FirstLayerPlane> m_first_layer_plane;
// Plate origin, kept so a writer replaced during export can be given it again.
Vec2d m_gcode_offset{ Vec2d::Zero() };
std::unique_ptr<PressureEqualizer> m_pressure_equalizer;