Skip to content

Commit

Permalink
Add travel_slope option (SoftFever#5873)
Browse files Browse the repository at this point in the history
* Add travel_slope option

* Merge branch 'main' into travel-slope-pr
  • Loading branch information
vovodroid authored Jun 29, 2024
1 parent f5c5f32 commit a13152c
Show file tree
Hide file tree
Showing 10 changed files with 30 additions and 12 deletions.
5 changes: 5 additions & 0 deletions src/libslic3r/Extruder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,4 +203,9 @@ double Extruder::retract_restart_extra_toolchange() const
return m_config->retract_restart_extra_toolchange.get_at(m_id);
}

double Extruder::travel_slope() const
{
return m_config->travel_slope.get_at(m_id) * PI / 180;
}

}
1 change: 1 addition & 0 deletions src/libslic3r/Extruder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ class Extruder
double retract_restart_extra() const;
double retract_length_toolchange() const;
double retract_restart_extra_toolchange() const;
double travel_slope() const;

bool use_firmware_retraction() const;

Expand Down
2 changes: 1 addition & 1 deletion src/libslic3r/GCode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5894,7 +5894,7 @@ bool GCode::needs_retraction(const Polyline &travel, ExtrusionRole role, LiftTyp
float max_z_hop = 0.f;
for (int i = 0; i < m_config.z_hop.size(); i++)
max_z_hop = std::max(max_z_hop, (float)m_config.z_hop.get_at(i));
float travel_len_thresh = scale_(max_z_hop / tan(GCodeWriter::slope_threshold));
float travel_len_thresh = scale_(max_z_hop / tan(this->writer().extruder()->travel_slope()));
float accum_len = 0.f;
Polyline clipped_travel;

Expand Down
7 changes: 3 additions & 4 deletions src/libslic3r/GCodeWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
namespace Slic3r {

bool GCodeWriter::full_gcode_comment = true;
const double GCodeWriter::slope_threshold = 3 * PI / 180;

bool GCodeWriter::supports_separate_travel_acceleration(GCodeFlavor flavor)
{
Expand Down Expand Up @@ -458,19 +457,19 @@ std::string GCodeWriter::travel_to_xyz(const Vec3d &point, const std::string &co
//BBS: SpiralLift
if (m_to_lift_type == LiftType::SpiralLift && this->is_current_position_clear()) {
//BBS: todo: check the arc move all in bed area, if not, then use lazy lift
double radius = delta(2) / (2 * PI * atan(GCodeWriter::slope_threshold));
double radius = delta(2) / (2 * PI * atan(this->extruder()->travel_slope()));
Vec2d ij_offset = radius * delta_no_z.normalized();
ij_offset = { -ij_offset(1), ij_offset(0) };
slop_move = this->_spiral_travel_to_z(target(2), ij_offset, "spiral lift Z");
}
//BBS: LazyLift
else if (m_to_lift_type == LiftType::LazyLift &&
this->is_current_position_clear() &&
atan2(delta(2), delta_no_z.norm()) < GCodeWriter::slope_threshold) {
atan2(delta(2), delta_no_z.norm()) < this->extruder()->travel_slope()) {
//BBS: check whether we can make a travel like
// _____
// / to make the z list early to avoid to hit some warping place when travel is long.
Vec2d temp = delta_no_z.normalized() * delta(2) / tan(GCodeWriter::slope_threshold);
Vec2d temp = delta_no_z.normalized() * delta(2) / tan(this->extruder()->travel_slope());
Vec3d slope_top_point = Vec3d(temp(0), temp(1), delta(2)) + source;
GCodeG1Formatter w0;
w0.emit_xyz(slope_top_point);
Expand Down
2 changes: 0 additions & 2 deletions src/libslic3r/GCodeWriter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,6 @@ class GCodeWriter {
bool is_current_position_clear() const { return m_is_current_pos_clear; };
//BBS:
static bool full_gcode_comment;
//Radian threshold of slope for lazy lift and spiral lift;
static const double slope_threshold;
//SoftFever
void set_is_bbl_machine(bool bval) {m_is_bbl_printers = bval;}
const bool is_bbl_printers() const {return m_is_bbl_printers;}
Expand Down
2 changes: 1 addition & 1 deletion src/libslic3r/Preset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -866,7 +866,7 @@ static std::vector<std::string> s_Preset_printer_options {
"silent_mode",
// BBS
"scan_first_layer", "machine_load_filament_time", "machine_unload_filament_time","time_cost", "machine_pause_gcode", "template_custom_gcode",
"nozzle_type", "nozzle_hrc","auxiliary_fan", "nozzle_volume","upward_compatible_machine", "z_hop_types", "retract_lift_enforce","support_chamber_temp_control","support_air_filtration","printer_structure",
"nozzle_type", "nozzle_hrc","auxiliary_fan", "nozzle_volume","upward_compatible_machine", "z_hop_types", "travel_slope", "retract_lift_enforce","support_chamber_temp_control","support_air_filtration","printer_structure",
"best_object_pos","head_wrap_detect_zone",
//SoftFever
"host_type", "print_host", "printhost_apikey", "bbl_use_printhost",
Expand Down
3 changes: 2 additions & 1 deletion src/libslic3r/Print.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,8 @@ bool Print::invalidate_state_by_config_options(const ConfigOptionResolver & /* n
"retract_when_changing_layer",
"retraction_length",
"retract_length_toolchange",
"z_hop",
"z_hop",
"travel_slope",
"retract_lift_above",
"retract_lift_below",
"retract_lift_enforce",
Expand Down
14 changes: 12 additions & 2 deletions src/libslic3r/PrintConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3557,6 +3557,15 @@ void PrintConfigDef::init_fff_params()
def->mode = comAdvanced;
def->set_default_value(new ConfigOptionEnumsGeneric{ ZHopType::zhtSlope });

def = this->add("travel_slope", coFloats);
def->label = L("Traveling angle");
def->tooltip = L("Traveling angle for Slope and Spiral Z hop type. Setting it to 90° results in Normal Lift");
def->sidetext = L("°");
def->mode = comAdvanced;
def->min = 1;
def->max = 90;
def->set_default_value(new ConfigOptionFloats { 3 });

def = this->add("retract_lift_above", coFloats);
def->label = L("Only lift Z above");
def->tooltip = L("If you set this to a positive value, Z lift will only take place above the specified absolute Z.");
Expand Down Expand Up @@ -5113,7 +5122,7 @@ void PrintConfigDef::init_extruder_option_keys()
// ConfigOptionFloats, ConfigOptionPercents, ConfigOptionBools, ConfigOptionStrings
m_extruder_option_keys = {
"nozzle_diameter", "min_layer_height", "max_layer_height", "extruder_offset",
"retraction_length", "z_hop", "z_hop_types", "retract_lift_above", "retract_lift_below", "retract_lift_enforce", "retraction_speed", "deretraction_speed",
"retraction_length", "z_hop", "z_hop_types", "travel_slope", "retract_lift_above", "retract_lift_below", "retract_lift_enforce", "retraction_speed", "deretraction_speed",
"retract_before_wipe", "retract_restart_extra", "retraction_minimum_travel", "wipe", "wipe_distance",
"retract_when_changing_layer", "retract_length_toolchange", "retract_restart_extra_toolchange", "extruder_colour",
"default_filament_profile","retraction_distances_when_cut","long_retractions_when_cut"
Expand All @@ -5135,7 +5144,8 @@ void PrintConfigDef::init_extruder_option_keys()
"wipe",
"wipe_distance",
"z_hop",
"z_hop_types"
"z_hop_types",
"travel_slope"
};
assert(std::is_sorted(m_extruder_retract_keys.begin(), m_extruder_retract_keys.end()));
}
Expand Down
1 change: 1 addition & 0 deletions src/libslic3r/PrintConfig.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1060,6 +1060,7 @@ PRINT_CONFIG_CLASS_DEFINE(
((ConfigOptionFloats, z_hop))
// BBS
((ConfigOptionEnumsGeneric, z_hop_types))
((ConfigOptionFloats, travel_slope))
((ConfigOptionFloats, retract_lift_above))
((ConfigOptionFloats, retract_lift_below))
((ConfigOptionEnumsGeneric, retract_lift_enforce))
Expand Down
5 changes: 4 additions & 1 deletion src/slic3r/GUI/Tab.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3092,7 +3092,7 @@ void TabFilament::add_filament_overrides_page()

for (const std::string opt_key : { "filament_retraction_length",
"filament_z_hop",
"filament_z_hop_types",
"filament_z_hop_types",
"filament_retract_lift_above",
"filament_retract_lift_below",
"filament_retract_lift_enforce",
Expand Down Expand Up @@ -4157,6 +4157,7 @@ if (is_marlin_flavor)
optgroup->append_single_option_line("retract_restart_extra", "", extruder_idx);
optgroup->append_single_option_line("z_hop", "", extruder_idx);
optgroup->append_single_option_line("z_hop_types", "", extruder_idx);
optgroup->append_single_option_line("travel_slope", "", extruder_idx);
optgroup->append_single_option_line("retraction_speed", "", extruder_idx);
optgroup->append_single_option_line("deretraction_speed", "", extruder_idx);
optgroup->append_single_option_line("retraction_minimum_travel", "", extruder_idx);
Expand Down Expand Up @@ -4421,6 +4422,8 @@ void TabPrinter::toggle_options()
toggle_option("long_retractions_when_cut", !use_firmware_retraction && m_config->opt_int("enable_long_retraction_when_cut"),i);
toggle_line("retraction_distances_when_cut#0", m_config->opt_bool("long_retractions_when_cut", i));
//toggle_option("retraction_distances_when_cut", m_config->opt_bool("long_retractions_when_cut",i),i);

toggle_option("travel_slope", m_config->opt_enum("z_hop_types", i) != ZHopType::zhtNormal, i);
}

if (m_active_page->title() == L("Motion ability")) {
Expand Down

0 comments on commit a13152c

Please sign in to comment.