Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
f36465d
Basically working retraction during travel
wawanbreton Feb 3, 2025
2250fa1
Basically working priming during travel
wawanbreton Feb 4, 2025
103d1f5
Fix some multi-segment travel with retraction/prime issues
wawanbreton Feb 4, 2025
83fd0b3
Clean code and add documentation
wawanbreton Feb 5, 2025
3908251
Apply clang-format
wawanbreton Feb 5, 2025
6196437
Complete documentation and figure out missing files
wawanbreton Feb 5, 2025
3284964
Merge remote-tracking branch 'origin/CURA-11978_retract-and-unretract…
wawanbreton Feb 5, 2025
a24ed92
Make sure z-hop won't change retract when not supposed to
wawanbreton Feb 5, 2025
270b1b5
Add algorithm documentation
wawanbreton Feb 5, 2025
84be5f5
Merge remote-tracking branch 'origin/main' into CURA-11978_retract-an…
wawanbreton Feb 5, 2025
ea67713
Apply clang-format
wawanbreton Feb 5, 2025
c77c30c
Disable retract during travel for printers that handle retraction
wawanbreton Feb 5, 2025
4426c45
Merge remote-tracking branch 'origin/CURA-11978_retract-and-unretract…
wawanbreton Feb 5, 2025
c833194
Properly apply retraction limitations during travel
wawanbreton Feb 5, 2025
b157550
Apply suggestions from code review
wawanbreton Feb 10, 2025
75e2cff
Apply clang-format
wawanbreton Feb 10, 2025
9a2c5d3
Remove useless variable initialization
wawanbreton Feb 10, 2025
9143ec5
Merge remote-tracking branch 'origin/CURA-11978_retract-and-unretract…
wawanbreton Feb 10, 2025
5940d31
Add unit test for anti-oozing amounts calculation
wawanbreton Feb 11, 2025
2c5bd6d
Harmless optimization
wawanbreton Feb 11, 2025
6405aaa
Use accumulate to make code more explicit
wawanbreton Feb 11, 2025
4a2cd81
Apply clang-format
wawanbreton Feb 11, 2025
c1eba8b
Merge branch 'main' into CURA-11978_retract-and-unretract-in-a-travel
HellAholic Feb 12, 2025
cfdf96b
Merge branch 'main' into CURA-11978_retract-and-unretract-in-a-travel
wawanbreton Feb 19, 2025
576209a
Fix possibly uninitialized split position
wawanbreton Feb 20, 2025
3ccf8b3
Apply clang-format
wawanbreton Feb 20, 2025
a3c56e1
Merge remote-tracking branch 'origin/main' into CURA-11978_retract-an…
wawanbreton May 21, 2025
00f0cd3
Apply clang-format
wawanbreton May 21, 2025
fd181b8
Reduce retract/prime if there is not enough time to process during tr…
wawanbreton May 23, 2025
e02d0a4
Add feature type to distinguish (un)retracting moves
wawanbreton May 26, 2025
7d215dd
Make retraction test more explicit
wawanbreton May 27, 2025
6a49e9d
Apply clang-format
wawanbreton May 27, 2025
ba9a413
Merge branch 'main' into CURA-11978_retract-and-unretract-in-a-travel
HellAholic Jun 10, 2025
fd309cf
Fix unit tests
wawanbreton Jun 11, 2025
a1159f4
Fix build with emscripten
wawanbreton Jun 12, 2025
2dc147c
Fix wrong travel position after extruder switch
wawanbreton Jun 12, 2025
4537b6d
Apply keep_retracting_during_travel
wawanbreton Jun 12, 2025
3723f72
Fix wrong time estimations regarding retraction during travel
wawanbreton Jun 13, 2025
a9e57d9
Fix case where the retract/prime ratio was incorrect
wawanbreton Jun 13, 2025
b83d9b1
Add missing new print feature types
wawanbreton Jun 13, 2025
43bb4f8
Merge branch 'main' into CURA-11978_retract-and-unretract-in-a-travel
HellAholic Jun 20, 2025
d0a8857
Update Cura.proto
HellAholic Jun 20, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ if (EMSCRIPTEN)
"SHELL:-sERROR_ON_UNDEFINED_SYMBOLS=0"
"SHELL:-sWASM_BIGINT=1"
"SHELL:-sSTACK_SIZE=196608"
$<$<CONFIG:Debug>:SHELL:-sASSERTIONS=2>
$<$<CONFIG:Debug>:SHELL:-sASSERTIONS=2>
$<$<CONFIG:Debug>:SHELL:-sSAFE_HEAP=1>
$<$<CONFIG:Debug>:SHELL:-sSTACK_OVERFLOW_CHECK=2>
$<$<CONFIG:Debug>:SHELL:-g3>
Expand Down
8 changes: 6 additions & 2 deletions Cura.proto
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,14 @@ message Polygon {
SkirtType = 5;
InfillType = 6;
SupportInfillType = 7;
MoveCombingType = 8;
MoveRetractionType = 9;
MoveUnretracted = 8;
MoveRetracted = 9;
SupportInterfaceType = 10;
PrimeTowerType = 11;
MoveWhileRetracting = 12;
MoveWhileUnretracting = 13;
StationaryRetractUnretract = 14;
NumPrintFeatureTypes = 15;
}
Type type = 1; // Type of move
bytes points = 2; // The points of the polygon, or two points if only a line segment (Currently only line segments are used)
Expand Down
106 changes: 105 additions & 1 deletion include/LayerPlan.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ class LayerPlan : public NoCopy
#ifdef BUILD_TESTS
friend class AddTravelTest;
friend class FffGcodeWriterTest_SurfaceGetsExtraInfillLinesUnderIt_Test;
friend class AntiOozeAmountsTest;
FRIEND_TEST(AntiOozeAmountsTest, ComputeAntiOozeAmounts);
#endif

public:
Expand Down Expand Up @@ -86,6 +88,36 @@ class LayerPlan : public NoCopy
Point3LL coasting_start_pos;
};

struct TravelDurations
{
Duration z_hop; //!< The duration of the Z hop start and end
Duration travel; //!< The duration of the full travel
};

struct AntiOozeSettings
{
double distance;
Velocity speed;
Ratio during_travel_ratio;
};

struct AntiOozeIntermediateAmounts
{
Ratio actual_during_travel_ratio;
Duration total_expected_duration;
Duration expected_duration_during_travel;
double expected_amount_during_travel;
double actual_amount_during_travel;
};

enum class TravelRetractionState
{
None, // There is no retraction/prime
Retracting, // We are retracting while traveling
Travelling, // We are traveling, but neither retracting nor priming, just moving
Priming, // We are priming while traveling
};

const SliceDataStorage& storage_; //!< The polygon data obtained from FffPolygonProcessor
const LayerIndex layer_nr_; //!< The layer number of this layer plan
const bool is_initial_layer_; //!< Whether this is the first layer (which might be raft)
Expand Down Expand Up @@ -858,9 +890,15 @@ class LayerPlan : public NoCopy
* @param position The position to move to. The Z coordinate is an offset to the current layer position
* @param speed The actual used speed
* @param path_z_offset The global path Z offset to be applied
* @param retract_distance The absolute retraction distance to be reached during this travel move, or nullopt to leave it unchanged
* @note This function is to be used when dealing with 3D coordinates. If you have 2D coordinates, just call gcode.writeTravel()
*/
void writeTravelRelativeZ(GCodeExport& gcode, const Point3LL& position, const Velocity& speed, const coord_t path_z_offset);
void writeTravelRelativeZ(
GCodeExport& gcode,
const Point3LL& position,
const Velocity& speed,
const coord_t path_z_offset,
const std::optional<double> retract_distance = std::nullopt);

/*!
* \brief Write an extrusion move and properly apply the various Z offsets
Expand Down Expand Up @@ -1042,6 +1080,72 @@ class LayerPlan : public NoCopy
* \return The distance from the start of the current wall line to the first bridge segment
*/
coord_t computeDistanceToBridgeStart(const ExtrusionLine& wall, const size_t current_index, const coord_t min_bridge_line_len) const;

/*!
* Compute the Z-hop and travel duration for the given travel path
* @param gcode The gcode exporter, which we need to get the current nozzle position
* @param extruder The current extruder, for which we need the settings
* @param path The travel path we want the durations of
* @param z_hop_height The Z-hop height
* @return The computed path durations
*/
static TravelDurations computeTravelDurations(const GCodeExport& gcode, const ExtruderTrain& extruder, const GCodePath& path, const coord_t z_hop_height);

/*!
* Compute the anti-ooze (retraction and priming) amounts to be processed during stationary/Z-hop/travel steps
* @param gcode The gcode exporter
* @param extruder The current extruder
* @param path The raw travel path to be exported
* @param z_hop_height The Z-hop height
* @param retraction_config The retraction/priming configuration to be used
* @param retraction_amounts The retraction amounts to be set
* @param priming_amounts The priming amounts to be set
*/
static void computeAntiOozeAmounts(
const GCodeExport& gcode,
const ExtruderTrain& extruder,
const GCodePath& path,
const coord_t z_hop_height,
const RetractionAndWipeConfig* retraction_config,
std::optional<TravelAntiOozing>& retraction_amounts,
std::optional<TravelAntiOozing>& priming_amounts);

/*!
* Compute the anti-ooze amounts to be processed during stationary/Z-hop/travel steps for either a retraction or a priming
* @param travel_durations The pre-calculated travel durations
* @param gcode The gcode exporter
* @param path The raw travel path to be exported
* @param settings The anti-ooze settings to be applied
* @param reversed Indicates if we should process the path forwards (retraction at the beginning) or backwards (prime at the end)
*/
static void computeAntiOozeTravelSplit(
const GCodeExport& gcode,
const GCodePath& path,
const Velocity& speed,
const double amount_during_travel,
const bool reversed,
TravelAntiOozing& anti_oozing);

/*!
* Write a single travel segment, taking care of the retraction and priming during travel
* @param travel_retraction_state The current travel retraction state, which may be updated
* @param gcode The gcode exporter
* @param path The full travel path being written
* @param retraction_amounts The pre-calculated retraction amounts to be processed during this travel move
* @param priming_amounts The pre-calculated priming amounts to be processed during this travel move
* @param speed The travel speed
* @param point_index The index of the current point in the path to be written
* @warning When travel_retraction_state is None, retraction_amounts and priming_amounts may be std::nullopt, however if it is anything different,
* it is assumed that they both have a value.
*/
void writeTravelSegment(
TravelRetractionState& travel_retraction_state,
GCodeExport& gcode,
const GCodePath& path,
const std::optional<TravelAntiOozing>& retraction_amounts,
const std::optional<TravelAntiOozing>& priming_amounts,
const Velocity& speed,
const size_t point_index);
};

} // namespace cura
Expand Down
13 changes: 7 additions & 6 deletions include/PrintFeature.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
namespace cura
{

enum class PrintFeatureType: unsigned char
enum class PrintFeatureType : unsigned char
{
NoneType = 0, // used to mark unspecified jumps in polygons. libArcus depends on it
OuterWall = 1,
Expand All @@ -14,18 +14,19 @@ enum class PrintFeatureType: unsigned char
SkirtBrim = 5,
Infill = 6,
SupportInfill = 7,
MoveCombing = 8,
MoveRetraction = 9,
MoveUnretracted = 8, // Travel move while filament not retracted
MoveRetracted = 9, // Travel move while filament retracted
SupportInterface = 10,
PrimeTower = 11,
NumPrintFeatureTypes = 12 // this number MUST be the last one because other modules will
MoveWhileRetracting = 12, // Travel move while retracting filament at the same time
MoveWhileUnretracting = 13, // Travel move while unretracting filament at the same time
StationaryRetractUnretract = 14, // Filament being (un)retracted with stationary nozzle
NumPrintFeatureTypes = 15 // this number MUST be the last one because other modules will
// use this symbol to get the total number of types, which can
// be used to create an array or so
};




} // namespace cura

#endif // PRINT_FEATURE
6 changes: 5 additions & 1 deletion include/RetractionConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#ifndef RETRACTION_CONFIG_H
#define RETRACTION_CONFIG_H

#include "settings/types/Ratio.h"
#include "settings/types/Velocity.h"
#include "utils/Coord_t.h"

Expand All @@ -17,6 +18,9 @@ class RetractionConfig
{
public:
double distance; //!< The distance retracted (in mm)
Ratio retract_during_travel; //!< The ratio of retraction to be performed while traveling
bool keep_retracting_during_travel; //! Whether we should spread the retraction over the whole travel move
Ratio prime_during_travel; //!< The ratio of priming to be performed while traveling
Velocity speed; //!< The speed with which to retract (in mm/s)
Velocity primeSpeed; //!< the speed with which to unretract (in mm/s)
double prime_volume; //!< the amount of material primed after unretracting (in mm^3)
Expand All @@ -27,6 +31,6 @@ class RetractionConfig
};


}//namespace cura
} // namespace cura

#endif // RETRACTION_CONFIG_H
30 changes: 30 additions & 0 deletions include/TravelAntiOozing.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Copyright (c) 2023 UltiMaker
// CuraEngine is released under the terms of the AGPLv3 or higher

#ifndef TRAVELANTIOOZING_H
#define TRAVELANTIOOZING_H

#include "geometry/Point2LL.h"
#include "settings/types/Ratio.h"

namespace cura
{

struct ZHopAntiOozing
{
double amount{ 0 }; //!< The absolute amount of retracted material (in mm) to be reached while the nozzle is moved up/down
Ratio ratio; //!< The ratio of the full z-hop move that contains a retract/prime
};

struct TravelAntiOozing
{
double amount_while_still{ 0 }; //!< The absolute amount of retracted material (in mm) to be reached while the nozzle is still
ZHopAntiOozing z_hop; //!< The amount and ratio of retracted material to be processed during z-hop move
double amount_while_travel{ 0 }; //!< The absolute amount of retracted material (in mm) to be reached while the nozzle is traveling
Point2LL segment_split_position; //!< The intermediate position on the last/first segment that contains a retract/prime, where it should actually stop/start
std::vector<double> amount_by_segment; //!< For each intermediate segment containing a retraction/prime, this is the absolute amount to be reached at the end of the segment
};

} // namespace cura

#endif /* TRAVELANTIOOZING_H */
Loading
Loading