Wipe tower changes to reduce wiping volumes where appropriate

This commit is contained in:
Lukas Matena 2018-05-24 17:24:37 +02:00
parent 95795f249a
commit 132a67edb2
4 changed files with 57 additions and 92 deletions

View file

@ -217,6 +217,8 @@ void ToolOrdering::reorder_extruders(unsigned int last_extruder_id)
}
}
void ToolOrdering::fill_wipe_tower_partitions(const PrintConfig &config, coordf_t object_bottom_z)
{
if (m_layer_tools.empty())

View file

@ -557,7 +557,7 @@ WipeTower::ToolChangeResult WipeTowerPrusaMM::tool_change(unsigned int tool, boo
{
for (const auto &b : m_layer_info->tool_changes)
if ( b.new_tool == tool ) {
wipe_volume = wipe_volumes[b.old_tool][b.new_tool];
wipe_volume = b.wipe_volume;
if (tool == m_layer_info->tool_changes.back().new_tool)
last_change_in_layer = true;
wipe_area = b.required_depth * m_layer_info->extra_spacing;
@ -1051,7 +1051,7 @@ WipeTower::ToolChangeResult WipeTowerPrusaMM::finish_layer()
}
// Appends a toolchange into m_plan and calculates neccessary depth of the corresponding box
void WipeTowerPrusaMM::plan_toolchange(float z_par, float layer_height_par, unsigned int old_tool, unsigned int new_tool,bool brim)
void WipeTowerPrusaMM::plan_toolchange(float z_par, float layer_height_par, unsigned int old_tool, unsigned int new_tool, bool brim, float wiping_volume_reduction)
{
assert(m_plan.back().z <= z_par + WT_EPSILON ); // refuses to add a layer below the last one
@ -1076,13 +1076,14 @@ void WipeTowerPrusaMM::plan_toolchange(float z_par, float layer_height_par, unsi
float ramming_depth = depth;
length_to_extrude = width*((length_to_extrude / width)-int(length_to_extrude / width)) - width;
float first_wipe_line = -length_to_extrude;
length_to_extrude += volume_to_length(wipe_volumes[old_tool][new_tool], m_perimeter_width, layer_height_par);
float wipe_volume = wipe_volumes[old_tool][new_tool] - wiping_volume_reduction;
length_to_extrude += volume_to_length(wipe_volume, m_perimeter_width, layer_height_par);
length_to_extrude = std::max(length_to_extrude,0.f);
depth += (int(length_to_extrude / width) + 1) * m_perimeter_width;
depth *= m_extra_spacing;
m_plan.back().tool_changes.push_back(WipeTowerInfo::ToolChange(old_tool, new_tool, depth, ramming_depth,first_wipe_line));
m_plan.back().tool_changes.push_back(WipeTowerInfo::ToolChange(old_tool, new_tool, depth, ramming_depth, first_wipe_line, wipe_volume));
}
@ -1122,7 +1123,7 @@ void WipeTowerPrusaMM::save_on_last_wipe()
float width = m_wipe_tower_width - 3*m_perimeter_width; // width we draw into
float length_to_save = 2*(m_wipe_tower_width+m_wipe_tower_depth) + (!layer_finished() ? finish_layer().total_extrusion_length_in_plane() : 0.f);
float length_to_wipe = volume_to_length(wipe_volumes[m_layer_info->tool_changes.back().old_tool][m_layer_info->tool_changes.back().new_tool],
float length_to_wipe = volume_to_length(m_layer_info->tool_changes.back().wipe_volume,
m_perimeter_width,m_layer_info->height) - m_layer_info->tool_changes.back().first_wipe_line - length_to_save;
length_to_wipe = std::max(length_to_wipe,0.f);

View file

@ -44,7 +44,7 @@ public:
// wipe_area -- space available for one toolchange in mm
WipeTowerPrusaMM(float x, float y, float width, float rotation_angle, float cooling_tube_retraction,
float cooling_tube_length, float parking_pos_retraction, float extra_loading_move, float bridging,
const std::vector<float>& wiping_matrix, unsigned int initial_tool) :
const std::vector<std::vector<float>>& wiping_matrix, unsigned int initial_tool) :
m_wipe_tower_pos(x, y),
m_wipe_tower_width(width),
m_wipe_tower_rotation_angle(rotation_angle),
@ -56,12 +56,9 @@ public:
m_parking_pos_retraction(parking_pos_retraction),
m_extra_loading_move(extra_loading_move),
m_bridging(bridging),
m_current_tool(initial_tool)
{
unsigned int number_of_extruders = (unsigned int)(sqrt(wiping_matrix.size())+WT_EPSILON);
for (unsigned int i = 0; i<number_of_extruders; ++i)
wipe_volumes.push_back(std::vector<float>(wiping_matrix.begin()+i*number_of_extruders,wiping_matrix.begin()+(i+1)*number_of_extruders));
}
m_current_tool(initial_tool),
wipe_volumes(wiping_matrix)
{}
virtual ~WipeTowerPrusaMM() {}
@ -99,7 +96,7 @@ public:
// Appends into internal structure m_plan containing info about the future wipe tower
// to be used before building begins. The entries must be added ordered in z.
void plan_toolchange(float z_par, float layer_height_par, unsigned int old_tool, unsigned int new_tool, bool brim);
void plan_toolchange(float z_par, float layer_height_par, unsigned int old_tool, unsigned int new_tool, bool brim, float wiping_volume_reduction = 0.f);
// Iterates through prepared m_plan, generates ToolChangeResults and appends them to "result"
void generate(std::vector<std::vector<WipeTower::ToolChangeResult>> &result);
@ -238,7 +235,7 @@ private:
// A fill-in direction (positive Y, negative Y) alternates with each layer.
wipe_shape m_current_shape = SHAPE_NORMAL;
unsigned int m_current_tool = 0;
std::vector<std::vector<float>> wipe_volumes;
const std::vector<std::vector<float>> wipe_volumes;
float m_depth_traversed = 0.f; // Current y position at the wipe tower.
bool m_left_to_right = true;
@ -255,7 +252,7 @@ private:
// Calculates length of extrusion line to extrude given volume
float volume_to_length(float volume, float line_width, float layer_height) const {
return volume / (layer_height * (line_width - layer_height * (1. - M_PI / 4.)));
return std::max(0., volume / (layer_height * (line_width - layer_height * (1. - M_PI / 4.))));
}
// Calculates depth for all layers and propagates them downwards
@ -308,8 +305,9 @@ private:
float required_depth;
float ramming_depth;
float first_wipe_line;
ToolChange(unsigned int old,unsigned int newtool,float depth=0.f,float ramming_depth=0.f,float fwl=0.f)
: old_tool{old}, new_tool{newtool}, required_depth{depth}, ramming_depth{ramming_depth},first_wipe_line{fwl} {}
float wipe_volume;
ToolChange(unsigned int old, unsigned int newtool, float depth=0.f, float ramming_depth=0.f, float fwl=0.f, float wv=0.f)
: old_tool{old}, new_tool{newtool}, required_depth{depth}, ramming_depth{ramming_depth}, first_wipe_line{fwl}, wipe_volume{wv} {}
};
float z; // z position of the layer
float height; // layer height

View file

@ -1037,25 +1037,13 @@ void Print::_make_wipe_tower()
if (! this->has_wipe_tower())
return;
int wiping_extruder = 0;
for (size_t i = 0; i < objects.size(); ++ i) {
for (Layer* lay : objects[i]->layers) {
for (LayerRegion* reg : lay->regions) {
ExtrusionEntityCollection& eec = reg->fills;
for (ExtrusionEntity* ee : eec.entities) {
auto* fill = dynamic_cast<ExtrusionEntityCollection*>(ee);
/*if (fill->total_volume() > 1.)*/ {
fill->set_extruder_override(wiping_extruder);
if (++wiping_extruder > 3)
wiping_extruder = 0;
}
}
}
}
}
// Get wiping matrix to get number of extruders and convert vector<double> to vector<float>:
std::vector<float> wiping_matrix((this->config.wiping_volumes_matrix.values).begin(),(this->config.wiping_volumes_matrix.values).end());
// Extract purging volumes for each extruder pair:
std::vector<std::vector<float>> wipe_volumes;
const unsigned int number_of_extruders = (unsigned int)(sqrt(wiping_matrix.size())+EPSILON);
for (unsigned int i = 0; i<number_of_extruders; ++i)
wipe_volumes.push_back(std::vector<float>(wiping_matrix.begin()+i*number_of_extruders, wiping_matrix.begin()+(i+1)*number_of_extruders));
// Let the ToolOrdering class know there will be initial priming extrusions at the start of the print.
m_tool_ordering = ToolOrdering(*this, (unsigned int)-1, true);
@ -1101,23 +1089,20 @@ void Print::_make_wipe_tower()
}
}
// Get wiping matrix to get number of extruders and convert vector<double> to vector<float>:
std::vector<float> wiping_volumes((this->config.wiping_volumes_matrix.values).begin(),(this->config.wiping_volumes_matrix.values).end());
// Initialize the wipe tower.
WipeTowerPrusaMM wipe_tower(
float(this->config.wipe_tower_x.value), float(this->config.wipe_tower_y.value),
float(this->config.wipe_tower_width.value),
float(this->config.wipe_tower_rotation_angle.value), float(this->config.cooling_tube_retraction.value),
float(this->config.cooling_tube_length.value), float(this->config.parking_pos_retraction.value),
float(this->config.extra_loading_move.value), float(this->config.wipe_tower_bridging), wiping_volumes,
float(this->config.extra_loading_move.value), float(this->config.wipe_tower_bridging), wipe_volumes,
m_tool_ordering.first_extruder());
//wipe_tower.set_retract();
//wipe_tower.set_zhop();
// Set the extruder & material properties at the wipe tower object.
for (size_t i = 0; i < (int)(sqrt(wiping_volumes.size())+EPSILON); ++ i)
for (size_t i = 0; i < number_of_extruders; ++ i)
wipe_tower.set_extruder(
i,
WipeTowerPrusaMM::parse_material(this->config.filament_type.get_at(i).c_str()),
@ -1151,7 +1136,36 @@ void Print::_make_wipe_tower()
wipe_tower.plan_toolchange(layer_tools.print_z, layer_tools.wipe_tower_layer_height, current_extruder_id, current_extruder_id,false);
for (const auto extruder_id : layer_tools.extruders) {
if ((first_layer && extruder_id == m_tool_ordering.all_extruders().back()) || extruder_id != current_extruder_id) {
wipe_tower.plan_toolchange(layer_tools.print_z, layer_tools.wipe_tower_layer_height, current_extruder_id, extruder_id, first_layer && extruder_id == m_tool_ordering.all_extruders().back());
// Toolchange from old_extruder to new_extruder.
// Check how much volume needs to be wiped and keep marking infills until
// we run out of the volume (or infills)
const float min_infill_volume = 0.f;
if (config.filament_soluble.get_at(extruder_id)) // soluble filament cannot be wiped in a random infill
continue;
float volume_to_wipe = wipe_volumes[current_extruder_id][extruder_id];
for (size_t i = 0; i < objects.size(); ++ i) { // Let's iterate through all objects...
for (Layer* lay : objects[i]->layers) {
for (LayerRegion* reg : lay->regions) { // and all regions
ExtrusionEntityCollection& eec = reg->fills;
for (ExtrusionEntity* ee : eec.entities) { // and all infill Collections
auto* fill = dynamic_cast<ExtrusionEntityCollection*>(ee);
if (volume_to_wipe > 0.f && !fill->is_extruder_overridden() && fill->total_volume() > min_infill_volume) { // this infill will be used to wipe this extruder
fill->set_extruder_override(extruder_id);
volume_to_wipe -= fill->total_volume();
}
}
}
}
}
float saved_material = wipe_volumes[current_extruder_id][extruder_id] - std::max(0.f, volume_to_wipe);
std::cout << volume_to_wipe << "\t(saved " << saved_material << ")" << std::endl;
wipe_tower.plan_toolchange(layer_tools.print_z, layer_tools.wipe_tower_layer_height, current_extruder_id, extruder_id, first_layer && extruder_id == m_tool_ordering.all_extruders().back(), saved_material);
current_extruder_id = extruder_id;
}
}
@ -1160,60 +1174,10 @@ void Print::_make_wipe_tower()
}
}
// Generate the wipe tower layers.
m_wipe_tower_tool_changes.reserve(m_tool_ordering.layer_tools().size());
wipe_tower.generate(m_wipe_tower_tool_changes);
// Set current_extruder_id to the last extruder primed.
/*unsigned int current_extruder_id = m_tool_ordering.all_extruders().back();
for (const ToolOrdering::LayerTools &layer_tools : m_tool_ordering.layer_tools()) {
if (! layer_tools.has_wipe_tower)
// This is a support only layer, or the wipe tower does not reach to this height.
continue;
bool first_layer = &layer_tools == &m_tool_ordering.front();
bool last_layer = &layer_tools == &m_tool_ordering.back() || (&layer_tools + 1)->wipe_tower_partitions == 0;
wipe_tower.set_layer(
float(layer_tools.print_z),
float(layer_tools.wipe_tower_layer_height),
layer_tools.wipe_tower_partitions,
first_layer,
last_layer);
std::vector<WipeTower::ToolChangeResult> tool_changes;
for (unsigned int extruder_id : layer_tools.extruders)
// Call the wipe_tower.tool_change() at the first layer for the initial extruder
// to extrude the wipe tower brim,
if ((first_layer && extruder_id == m_tool_ordering.all_extruders().back()) ||
// or when an extruder shall be switched.
extruder_id != current_extruder_id) {
tool_changes.emplace_back(wipe_tower.tool_change(extruder_id, extruder_id == layer_tools.extruders.back(), WipeTower::PURPOSE_EXTRUDE));
current_extruder_id = extruder_id;
}
if (! wipe_tower.layer_finished()) {
tool_changes.emplace_back(wipe_tower.finish_layer(WipeTower::PURPOSE_EXTRUDE));
if (tool_changes.size() > 1) {
// Merge the two last tool changes into one.
WipeTower::ToolChangeResult &tc1 = tool_changes[tool_changes.size() - 2];
WipeTower::ToolChangeResult &tc2 = tool_changes.back();
if (tc1.end_pos != tc2.start_pos) {
// Add a travel move from tc1.end_pos to tc2.start_pos.
char buf[2048];
sprintf(buf, "G1 X%.3f Y%.3f F7200\n", tc2.start_pos.x, tc2.start_pos.y);
tc1.gcode += buf;
}
tc1.gcode += tc2.gcode;
append(tc1.extrusions, tc2.extrusions);
tc1.end_pos = tc2.end_pos;
tool_changes.pop_back();
}
}
m_wipe_tower_tool_changes.emplace_back(std::move(tool_changes));
if (last_layer)
break;
}*/
// Unload the current filament over the purge tower.
coordf_t layer_height = this->objects.front()->config.layer_height.value;
if (m_tool_ordering.back().wipe_tower_partitions > 0) {