Skip to content

Commit

Permalink
Make sure z-hop won't change retract when not supposed to
Browse files Browse the repository at this point in the history
  • Loading branch information
wawanbreton committed Feb 5, 2025
1 parent 3284964 commit a24ed92
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
12 changes: 6 additions & 6 deletions include/gcodeExport.h
Original file line number Diff line number Diff line change
Expand Up @@ -531,9 +531,9 @@ class GCodeExport : public NoCopy
* Start or end a z hop
* \param speed The speed used for moving, or 0 to take the default speed
* \param height The actual height to be reached, relative to the current layer height
* \param retract_distance The absolute retraction distance to be reached while doing the z-hop move
* \param retract_distance The absolute retraction distance to be reached while doing the z-hop move, or nullopt to leave it unchanged
*/
void writeZhop(Velocity speed = 0.0, const coord_t height = 0, const double retract_distance = 0.0);
void writeZhop(Velocity speed = 0.0, const coord_t height = 0, const std::optional<double> retract_distance = std::nullopt);

public:
/*!
Expand All @@ -560,21 +560,21 @@ class GCodeExport : public NoCopy
*
* \param hop_height The height to move above the current layer.
* \param speed The speed used for moving.
* \param retract_distance The absolute retract distance to be reached during the z-hop move
* \param retract_distance The absolute retract distance to be reached during the z-hop move, or nullopt to leave it unchanged
* \param retract_ratio This is the ratio of the complete z-hop move that should be used to process the retraction. If >0 and <1 then the z-hop move
* will actually be split in two part, one with retraction and one without.
*/
void writeZhopStart(const coord_t hop_height, Velocity speed = 0.0, double retract_distance = 0.0, const Ratio& retract_ratio = 0.0_r);
void writeZhopStart(const coord_t hop_height, Velocity speed = 0.0, std::optional<double> retract_distance = std::nullopt, const Ratio& retract_ratio = 0.0_r);

/*!
* End a z hop: go back to the layer height
*
* \param speed The speed used for moving.
* \param prime_distance The absolute prime distance to be reached during the z-hop move
* \param prime_distance The absolute prime distance to be reached during the z-hop move, or nullopt to leave it unchanged
* \param prime_ratio This is the ratio of the complete z-hop move that should be used to process the priming. If >0 and <1 then the z-hop move
* will actually be split in two part, one without priming and one with.
*/
void writeZhopEnd(Velocity speed = 0.0, const coord_t height = 0, const double prime_distance = 0.0, const Ratio& prime_ratio = 0.0_r);
void writeZhopEnd(Velocity speed = 0.0, const coord_t height = 0, const std::optional<double> prime_distance = std::nullopt, const Ratio& prime_ratio = 0.0_r);

/*!
* Start the new_extruder:
Expand Down
16 changes: 10 additions & 6 deletions src/gcodeExport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1298,9 +1298,9 @@ void GCodeExport::writeRetraction(const RetractionConfig& config, bool force, bo
extr_attr.prime_volume_ += config.prime_volume;
}

void GCodeExport::writeZhopStart(const coord_t hop_height, Velocity speed /*= 0*/, const double retract_distance, const Ratio& retract_ratio)
void GCodeExport::writeZhopStart(const coord_t hop_height, Velocity speed /*= 0*/, const std::optional<double> retract_distance, const Ratio& retract_ratio)
{
if (retract_ratio > 0.0 && retract_ratio < 1.0)
if (retract_distance.has_value() && retract_ratio > 0.0 && retract_ratio < 1.0)
{
// We have to split the z-hop move in two sub-moves, one with retraction and one without
writeZhopStart(hop_height * retract_ratio, speed, retract_distance, 0.0);
Expand All @@ -1314,7 +1314,7 @@ void GCodeExport::writeZhopStart(const coord_t hop_height, Velocity speed /*= 0*
}
}

void GCodeExport::writeZhopEnd(Velocity speed /*= 0*/, const coord_t height, const double prime_distance, const Ratio& prime_ratio)
void GCodeExport::writeZhopEnd(Velocity speed /*= 0*/, const coord_t height, const std::optional<double> prime_distance, const Ratio& prime_ratio)
{
if (z_hop_prime_leftover_.has_value())
{
Expand All @@ -1325,7 +1325,7 @@ void GCodeExport::writeZhopEnd(Velocity speed /*= 0*/, const coord_t height, con

if (is_z_hopped_)
{
if (prime_ratio > 0.0 && prime_ratio < 1.0)
if (prime_distance.has_value() && prime_ratio > 0.0 && prime_ratio < 1.0)
{
// We have to split the z-hop move in two sub-moves, one without prime and one with
writeZhopEnd(speed, is_z_hopped_ * prime_ratio, extruder_attr_[current_extruder_].retraction_e_amount_current_, 0.0);
Expand All @@ -1338,15 +1338,19 @@ void GCodeExport::writeZhopEnd(Velocity speed /*= 0*/, const coord_t height, con
}
}

void GCodeExport::writeZhop(Velocity speed /*= 0*/, const coord_t height, const double retract_distance)
void GCodeExport::writeZhop(Velocity speed /*= 0*/, const coord_t height, const std::optional<double> retract_distance)
{
if (speed == 0)
{
const ExtruderTrain& extruder = Application::getInstance().current_slice_->scene.extruders[current_extruder_];
speed = extruder.settings_.get<Velocity>("speed_z_hop");
}

RetractionAmounts retraction_amounts = computeRetractionAmounts(extruder_attr_[current_extruder_], retract_distance);
RetractionAmounts retraction_amounts;
if (retract_distance.has_value())
{
retraction_amounts = computeRetractionAmounts(extruder_attr_[current_extruder_], *retract_distance);
}

is_z_hopped_ = height;
const coord_t target_z = current_layer_z_ + is_z_hopped_;
Expand Down

0 comments on commit a24ed92

Please sign in to comment.