Wipe tower now doesn't print sparse layers, it is instead lower than the object

This commit is contained in:
Lukas Matena 2019-09-19 14:58:04 +02:00
parent b241ba16ed
commit 04f051ff61
2 changed files with 37 additions and 12 deletions

View file

@ -274,7 +274,7 @@ static inline Point wipe_tower_point_to_object_point(GCode &gcodegen, const Vec2
return Point(scale_(wipe_tower_pt.x() - gcodegen.origin()(0)), scale_(wipe_tower_pt.y() - gcodegen.origin()(1))); return Point(scale_(wipe_tower_pt.x() - gcodegen.origin()(0)), scale_(wipe_tower_pt.y() - gcodegen.origin()(1)));
} }
std::string WipeTowerIntegration::append_tcr(GCode &gcodegen, const WipeTower::ToolChangeResult &tcr, int new_extruder_id) const std::string WipeTowerIntegration::append_tcr(GCode &gcodegen, const WipeTower::ToolChangeResult &tcr, int new_extruder_id, double z) const
{ {
if (new_extruder_id != -1 && new_extruder_id != tcr.new_tool) if (new_extruder_id != -1 && new_extruder_id != tcr.new_tool)
throw std::invalid_argument("Error: WipeTowerIntegration::append_tcr was asked to do a toolchange it didn't expect."); throw std::invalid_argument("Error: WipeTowerIntegration::append_tcr was asked to do a toolchange it didn't expect.");
@ -310,6 +310,12 @@ std::string WipeTowerIntegration::append_tcr(GCode &gcodegen, const WipeTower::T
gcode += gcodegen.unretract(); gcode += gcodegen.unretract();
} }
double current_z = gcodegen.writer().get_position().z();
if (z == -1.) // in case no specific z was provided, print at current_z pos
z = current_z;
if (! is_approx(z, current_z))
gcode += gcodegen.writer().travel_to_z(z, "Travel down to the last wipe tower layer.");
// Process the end filament gcode. // Process the end filament gcode.
std::string end_filament_gcode_str; std::string end_filament_gcode_str;
@ -376,16 +382,23 @@ std::string WipeTowerIntegration::append_tcr(GCode &gcodegen, const WipeTower::T
// A phony move to the end position at the wipe tower. // A phony move to the end position at the wipe tower.
gcodegen.writer().travel_to_xy(end_pos.cast<double>()); gcodegen.writer().travel_to_xy(end_pos.cast<double>());
gcodegen.set_last_pos(wipe_tower_point_to_object_point(gcodegen, end_pos)); gcodegen.set_last_pos(wipe_tower_point_to_object_point(gcodegen, end_pos));
if (! is_approx(z, current_z)) {
gcode += gcodegen.writer().retract();
gcode += gcodegen.writer().travel_to_z(current_z, "Travel back up to the topmost object layer.");
gcode += gcodegen.writer().unretract();
}
// Prepare a future wipe. else {
gcodegen.m_wipe.path.points.clear(); // Prepare a future wipe.
if (new_extruder_id >= 0) { gcodegen.m_wipe.path.points.clear();
// Start the wipe at the current position. if (new_extruder_id >= 0) {
gcodegen.m_wipe.path.points.emplace_back(wipe_tower_point_to_object_point(gcodegen, end_pos)); // Start the wipe at the current position.
// Wipe end point: Wipe direction away from the closer tower edge to the further tower edge. gcodegen.m_wipe.path.points.emplace_back(wipe_tower_point_to_object_point(gcodegen, end_pos));
gcodegen.m_wipe.path.points.emplace_back(wipe_tower_point_to_object_point(gcodegen, // Wipe end point: Wipe direction away from the closer tower edge to the further tower edge.
Vec2f((std::abs(m_left - end_pos.x()) < std::abs(m_right - end_pos.x())) ? m_right : m_left, gcodegen.m_wipe.path.points.emplace_back(wipe_tower_point_to_object_point(gcodegen,
end_pos.y()))); Vec2f((std::abs(m_left - end_pos.x()) < std::abs(m_right - end_pos.x())) ? m_right : m_left,
end_pos.y())));
}
} }
// Let the planner know we are traveling between objects. // Let the planner know we are traveling between objects.
@ -511,7 +524,18 @@ std::string WipeTowerIntegration::tool_change(GCode &gcodegen, int extruder_id,
if (m_layer_idx < (int)m_tool_changes.size()) { if (m_layer_idx < (int)m_tool_changes.size()) {
if (! (size_t(m_tool_change_idx) < m_tool_changes[m_layer_idx].size())) if (! (size_t(m_tool_change_idx) < m_tool_changes[m_layer_idx].size()))
throw std::runtime_error("Wipe tower generation failed, possibly due to empty first layer."); throw std::runtime_error("Wipe tower generation failed, possibly due to empty first layer.");
gcode += append_tcr(gcodegen, m_tool_changes[m_layer_idx][m_tool_change_idx++], extruder_id);
double wipe_tower_z = m_last_wipe_tower_print_z;
bool is_sparse_layer = (m_brim_done && m_tool_changes[m_layer_idx].size() == 1 && m_tool_changes[m_layer_idx].front().initial_tool == m_tool_changes[m_layer_idx].front().new_tool);
if (m_tool_change_idx == 0 && ! is_sparse_layer)
wipe_tower_z = m_last_wipe_tower_print_z + m_tool_changes[m_layer_idx].front().layer_height;
if (! is_sparse_layer) {
gcode += append_tcr(gcodegen, m_tool_changes[m_layer_idx][m_tool_change_idx++], extruder_id, wipe_tower_z);
m_last_wipe_tower_print_z = wipe_tower_z;
}
} }
m_brim_done = true; m_brim_done = true;
} }

View file

@ -110,7 +110,7 @@ public:
private: private:
WipeTowerIntegration& operator=(const WipeTowerIntegration&); WipeTowerIntegration& operator=(const WipeTowerIntegration&);
std::string append_tcr(GCode &gcodegen, const WipeTower::ToolChangeResult &tcr, int new_extruder_id) const; std::string append_tcr(GCode &gcodegen, const WipeTower::ToolChangeResult &tcr, int new_extruder_id, double z = -1.) const;
// Postprocesses gcode: rotates and moves G1 extrusions and returns result // Postprocesses gcode: rotates and moves G1 extrusions and returns result
std::string post_process_wipe_tower_moves(const WipeTower::ToolChangeResult& tcr, const Vec2f& translation, float angle) const; std::string post_process_wipe_tower_moves(const WipeTower::ToolChangeResult& tcr, const Vec2f& translation, float angle) const;
@ -131,6 +131,7 @@ private:
int m_tool_change_idx; int m_tool_change_idx;
bool m_brim_done; bool m_brim_done;
bool i_have_brim = false; bool i_have_brim = false;
double m_last_wipe_tower_print_z = 0.f;
}; };
class GCode { class GCode {