mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-05-17 02:22:17 +00:00
ENH: refine time estimation in filament change
1.Add sync command. Now gcode and dirrectly add time sync command 2.Add support for ceil and floor in placeholder 3.Update change filament gcode for H2D jira: NONE Signed-off-by: xun.zhang <xun.zhang@bambulab.com> Change-Id: I6dd97cbd96bae1c2751c08357ff64947876d7471 (cherry picked from commit c99fcd454c2499b0c0e3ed9402a2182c00a9bffa)
This commit is contained in:
@@ -2724,6 +2724,29 @@ void GCodeProcessor::process_gcode_line(const GCodeReader::GCodeLine& line, bool
|
||||
case 'T':
|
||||
process_T(line); // Select Tool
|
||||
break;
|
||||
case 'S':
|
||||
switch (cmd.size()) {
|
||||
case 4:
|
||||
switch (cmd[1]){
|
||||
case 'Y':
|
||||
switch (cmd[2]){
|
||||
case 'N':
|
||||
switch (cmd[3]){
|
||||
case 'C':
|
||||
process_SYNC(line);
|
||||
break;
|
||||
default: break;
|
||||
}
|
||||
break;
|
||||
default: break;
|
||||
}
|
||||
break;
|
||||
default: break;
|
||||
}
|
||||
break;
|
||||
default: break;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@@ -4152,8 +4175,69 @@ void GCodeProcessor::process_VG1(const GCodeReader::GCodeLine& line)
|
||||
return;
|
||||
|
||||
EMoveType type = move_type(delta_pos);
|
||||
// BBS: now we only support virtual flush
|
||||
if (EMoveType::Unretract == type && m_virtual_flushing) {
|
||||
if (type == EMoveType::Extrude) {
|
||||
float delta_xyz = std::sqrt(sqr(delta_pos[X]) + sqr(delta_pos[Y]) + sqr(delta_pos[Z]));
|
||||
float volume_extruded_filament = area_filament_cross_section * delta_pos[E];
|
||||
float area_toolpath_cross_section = volume_extruded_filament / delta_xyz;
|
||||
|
||||
if(m_extrusion_role == ExtrusionRole::erSupportMaterial || m_extrusion_role == ExtrusionRole::erSupportMaterialInterface || m_extrusion_role ==ExtrusionRole::erSupportTransition)
|
||||
m_used_filaments.increase_support_caches(volume_extruded_filament);
|
||||
else if (m_extrusion_role==ExtrusionRole::erWipeTower) {
|
||||
m_used_filaments.increase_wipe_tower_caches(volume_extruded_filament);
|
||||
}
|
||||
else {
|
||||
// save extruded volume to the cache
|
||||
m_used_filaments.increase_model_caches(volume_extruded_filament);
|
||||
}
|
||||
// volume extruded filament / tool displacement = area toolpath cross section
|
||||
m_mm3_per_mm = area_toolpath_cross_section;
|
||||
#if ENABLE_GCODE_VIEWER_DATA_CHECKING
|
||||
m_mm3_per_mm_compare.update(area_toolpath_cross_section, m_extrusion_role);
|
||||
#endif // ENABLE_GCODE_VIEWER_DATA_CHECKING
|
||||
|
||||
if (m_forced_height > 0.0f)
|
||||
m_height = m_forced_height;
|
||||
else {
|
||||
if (m_end_position[Z] > m_extruded_last_z + EPSILON)
|
||||
m_height = m_end_position[Z] - m_extruded_last_z;
|
||||
}
|
||||
|
||||
if (m_height == 0.0f)
|
||||
m_height = DEFAULT_TOOLPATH_HEIGHT;
|
||||
|
||||
if (m_end_position[Z] == 0.0f)
|
||||
m_end_position[Z] = m_height;
|
||||
|
||||
m_extruded_last_z = m_end_position[Z];
|
||||
m_options_z_corrector.update(m_height);
|
||||
|
||||
#if ENABLE_GCODE_VIEWER_DATA_CHECKING
|
||||
m_height_compare.update(m_height, m_extrusion_role);
|
||||
#endif // ENABLE_GCODE_VIEWER_DATA_CHECKING
|
||||
|
||||
if (m_forced_width > 0.0f)
|
||||
m_width = m_forced_width;
|
||||
else if (m_extrusion_role == erExternalPerimeter)
|
||||
// cross section: rectangle
|
||||
m_width = delta_pos[E] * static_cast<float>(M_PI * sqr(1.05f * filament_radius)) / (delta_xyz * m_height);
|
||||
else if (m_extrusion_role == erBridgeInfill || m_extrusion_role == erNone)
|
||||
// cross section: circle
|
||||
m_width = static_cast<float>(m_result.filament_diameters[filament_id]) * std::sqrt(delta_pos[E] / delta_xyz);
|
||||
else
|
||||
// cross section: rectangle + 2 semicircles
|
||||
m_width = delta_pos[E] * static_cast<float>(M_PI * sqr(filament_radius)) / (delta_xyz * m_height) + static_cast<float>(1.0 - 0.25 * M_PI) * m_height;
|
||||
|
||||
if (m_width == 0.0f)
|
||||
m_width = DEFAULT_TOOLPATH_WIDTH;
|
||||
|
||||
// clamp width to avoid artifacts which may arise from wrong values of m_height
|
||||
m_width = std::min(m_width, std::max(2.0f, 4.0f * m_height));
|
||||
|
||||
#if ENABLE_GCODE_VIEWER_DATA_CHECKING
|
||||
m_width_compare.update(m_width, m_extrusion_role);
|
||||
#endif // ENABLE_GCODE_VIEWER_DATA_CHECKING
|
||||
}
|
||||
else if (EMoveType::Unretract == type && m_virtual_flushing) {
|
||||
int extruder_id = get_extruder_id();
|
||||
float volume_flushed_filament = area_filament_cross_section * delta_pos[E];
|
||||
if (m_remaining_volume[extruder_id] > volume_flushed_filament)
|
||||
@@ -5348,6 +5432,16 @@ void GCodeProcessor::process_M702(const GCodeReader::GCodeLine& line)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void GCodeProcessor::process_SYNC(const GCodeReader::GCodeLine& line)
|
||||
{
|
||||
float time = 0;
|
||||
if (line.has_value('T', time) ) {
|
||||
simulate_st_synchronize(time);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void GCodeProcessor::process_T(const GCodeReader::GCodeLine& line)
|
||||
{
|
||||
process_T(line.cmd());
|
||||
|
||||
@@ -993,6 +993,8 @@ class Print;
|
||||
// Unload the current filament into the MK3 MMU2 unit at the end of print.
|
||||
void process_M702(const GCodeReader::GCodeLine& line);
|
||||
|
||||
void process_SYNC(const GCodeReader::GCodeLine& line);
|
||||
|
||||
// Processes T line (Select Tool)
|
||||
void process_T(const GCodeReader::GCodeLine& line);
|
||||
void process_T(const std::string_view command);
|
||||
|
||||
@@ -386,6 +386,36 @@ namespace client
|
||||
return expr();
|
||||
}
|
||||
|
||||
expr floor(const Iterator start_pos)const
|
||||
{
|
||||
switch (this->type()) {
|
||||
case TYPE_INT:
|
||||
return expr(this->i(), start_pos, this->it_range.end());
|
||||
case TYPE_DOUBLE:
|
||||
return expr(static_cast<int>(std::floor(this->d())), start_pos, this->it_range.end());
|
||||
default:
|
||||
this->throw_exception("Cannot floor a non-numeric value.");
|
||||
}
|
||||
assert(false);
|
||||
// Suppress compiler warnings.
|
||||
return expr();
|
||||
}
|
||||
|
||||
expr ceil(const Iterator start_pos)const
|
||||
{
|
||||
switch (this->type()) {
|
||||
case TYPE_INT:
|
||||
return expr(this->i(), start_pos, this->it_range.end());
|
||||
case TYPE_DOUBLE:
|
||||
return expr(static_cast<int>(std::ceil(this->d())), start_pos, this->it_range.end());
|
||||
default:
|
||||
this->throw_exception("Cannot ceil a non-numeric value.");
|
||||
}
|
||||
assert(false);
|
||||
// Suppress compiler warnings.
|
||||
return expr();
|
||||
}
|
||||
|
||||
expr unary_not(const Iterator start_pos) const
|
||||
{
|
||||
switch (this->type()) {
|
||||
@@ -1926,6 +1956,10 @@ namespace client
|
||||
{ out = value.unary_integer(out.it_range.begin()); }
|
||||
static void round(expr &value, expr &out)
|
||||
{ out = value.round(out.it_range.begin()); }
|
||||
static void floor(expr &value, expr &out)
|
||||
{ out = value.floor(out.it_range.begin()); }
|
||||
static void ceil(expr &value, expr &out)
|
||||
{ out = value.ceil(out.it_range.begin());}
|
||||
// For indicating "no optional parameter".
|
||||
static void noexpr(expr &out) { out.reset(); }
|
||||
};
|
||||
@@ -2176,6 +2210,8 @@ namespace client
|
||||
[ px::bind(&expr::digits<true>, _val, _2, _3) ]
|
||||
| (kw["int"] > '(' > conditional_expression(_r1) > ')') [ px::bind(&FactorActions::to_int, _1, _val) ]
|
||||
| (kw["round"] > '(' > conditional_expression(_r1) > ')') [ px::bind(&FactorActions::round, _1, _val) ]
|
||||
| (kw["ceil"] > '(' > conditional_expression(_r1) > ')') [ px::bind(&FactorActions::ceil, _1, _val) ]
|
||||
| (kw["floor"] > '(' > conditional_expression(_r1) > ')') [ px::bind(&FactorActions::floor, _1, _val) ]
|
||||
| (kw["is_nil"] > '(' > variable_reference(_r1) > ')') [px::bind(&MyContext::is_nil_test, _r1, _1, _val)]
|
||||
| (kw["one_of"] > '(' > one_of(_r1) > ')') [ _val = _1 ]
|
||||
| (kw["empty"] > '(' > variable_reference(_r1) > ')') [px::bind(&MyContext::is_vector_empty, _r1, _1, _val)]
|
||||
@@ -2256,6 +2292,8 @@ namespace client
|
||||
("filament_change")
|
||||
("repeat")
|
||||
("round")
|
||||
("floor")
|
||||
("ceil")
|
||||
("not")
|
||||
("one_of")
|
||||
("or")
|
||||
|
||||
Reference in New Issue
Block a user