Skip to content

Commit dda8cea

Browse files
authored
CURA-11978 Retract and unretract in a travel (#2204)
2 parents c4663ef + d0a8857 commit dda8cea

21 files changed

+1273
-143
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ if (EMSCRIPTEN)
295295
"SHELL:-sERROR_ON_UNDEFINED_SYMBOLS=0"
296296
"SHELL:-sWASM_BIGINT=1"
297297
"SHELL:-sSTACK_SIZE=196608"
298-
$<$<CONFIG:Debug>:SHELL:-sASSERTIONS=2>
298+
$<$<CONFIG:Debug>:SHELL:-sASSERTIONS=2>
299299
$<$<CONFIG:Debug>:SHELL:-sSAFE_HEAP=1>
300300
$<$<CONFIG:Debug>:SHELL:-sSTACK_OVERFLOW_CHECK=2>
301301
$<$<CONFIG:Debug>:SHELL:-g3>

Cura.proto

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,14 @@ message Polygon {
8383
SkirtType = 5;
8484
InfillType = 6;
8585
SupportInfillType = 7;
86-
MoveCombingType = 8;
87-
MoveRetractionType = 9;
86+
MoveUnretracted = 8;
87+
MoveRetracted = 9;
8888
SupportInterfaceType = 10;
8989
PrimeTowerType = 11;
90+
MoveWhileRetracting = 12;
91+
MoveWhileUnretracting = 13;
92+
StationaryRetractUnretract = 14;
93+
NumPrintFeatureTypes = 15;
9094
}
9195
Type type = 1; // Type of move
9296
bytes points = 2; // The points of the polygon, or two points if only a line segment (Currently only line segments are used)

include/LayerPlan.h

Lines changed: 105 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ class LayerPlan : public NoCopy
5757
#ifdef BUILD_TESTS
5858
friend class AddTravelTest;
5959
friend class FffGcodeWriterTest_SurfaceGetsExtraInfillLinesUnderIt_Test;
60+
friend class AntiOozeAmountsTest;
61+
FRIEND_TEST(AntiOozeAmountsTest, ComputeAntiOozeAmounts);
6062
#endif
6163

6264
public:
@@ -86,6 +88,36 @@ class LayerPlan : public NoCopy
8688
Point3LL coasting_start_pos;
8789
};
8890

91+
struct TravelDurations
92+
{
93+
Duration z_hop; //!< The duration of the Z hop start and end
94+
Duration travel; //!< The duration of the full travel
95+
};
96+
97+
struct AntiOozeSettings
98+
{
99+
double distance;
100+
Velocity speed;
101+
Ratio during_travel_ratio;
102+
};
103+
104+
struct AntiOozeIntermediateAmounts
105+
{
106+
Ratio actual_during_travel_ratio;
107+
Duration total_expected_duration;
108+
Duration expected_duration_during_travel;
109+
double expected_amount_during_travel;
110+
double actual_amount_during_travel;
111+
};
112+
113+
enum class TravelRetractionState
114+
{
115+
None, // There is no retraction/prime
116+
Retracting, // We are retracting while traveling
117+
Travelling, // We are traveling, but neither retracting nor priming, just moving
118+
Priming, // We are priming while traveling
119+
};
120+
89121
const SliceDataStorage& storage_; //!< The polygon data obtained from FffPolygonProcessor
90122
const LayerIndex layer_nr_; //!< The layer number of this layer plan
91123
const bool is_initial_layer_; //!< Whether this is the first layer (which might be raft)
@@ -858,9 +890,15 @@ class LayerPlan : public NoCopy
858890
* @param position The position to move to. The Z coordinate is an offset to the current layer position
859891
* @param speed The actual used speed
860892
* @param path_z_offset The global path Z offset to be applied
893+
* @param retract_distance The absolute retraction distance to be reached during this travel move, or nullopt to leave it unchanged
861894
* @note This function is to be used when dealing with 3D coordinates. If you have 2D coordinates, just call gcode.writeTravel()
862895
*/
863-
void writeTravelRelativeZ(GCodeExport& gcode, const Point3LL& position, const Velocity& speed, const coord_t path_z_offset);
896+
void writeTravelRelativeZ(
897+
GCodeExport& gcode,
898+
const Point3LL& position,
899+
const Velocity& speed,
900+
const coord_t path_z_offset,
901+
const std::optional<double> retract_distance = std::nullopt);
864902

865903
/*!
866904
* \brief Write an extrusion move and properly apply the various Z offsets
@@ -1042,6 +1080,72 @@ class LayerPlan : public NoCopy
10421080
* \return The distance from the start of the current wall line to the first bridge segment
10431081
*/
10441082
coord_t computeDistanceToBridgeStart(const ExtrusionLine& wall, const size_t current_index, const coord_t min_bridge_line_len) const;
1083+
1084+
/*!
1085+
* Compute the Z-hop and travel duration for the given travel path
1086+
* @param gcode The gcode exporter, which we need to get the current nozzle position
1087+
* @param extruder The current extruder, for which we need the settings
1088+
* @param path The travel path we want the durations of
1089+
* @param z_hop_height The Z-hop height
1090+
* @return The computed path durations
1091+
*/
1092+
static TravelDurations computeTravelDurations(const GCodeExport& gcode, const ExtruderTrain& extruder, const GCodePath& path, const coord_t z_hop_height);
1093+
1094+
/*!
1095+
* Compute the anti-ooze (retraction and priming) amounts to be processed during stationary/Z-hop/travel steps
1096+
* @param gcode The gcode exporter
1097+
* @param extruder The current extruder
1098+
* @param path The raw travel path to be exported
1099+
* @param z_hop_height The Z-hop height
1100+
* @param retraction_config The retraction/priming configuration to be used
1101+
* @param retraction_amounts The retraction amounts to be set
1102+
* @param priming_amounts The priming amounts to be set
1103+
*/
1104+
static void computeAntiOozeAmounts(
1105+
const GCodeExport& gcode,
1106+
const ExtruderTrain& extruder,
1107+
const GCodePath& path,
1108+
const coord_t z_hop_height,
1109+
const RetractionAndWipeConfig* retraction_config,
1110+
std::optional<TravelAntiOozing>& retraction_amounts,
1111+
std::optional<TravelAntiOozing>& priming_amounts);
1112+
1113+
/*!
1114+
* Compute the anti-ooze amounts to be processed during stationary/Z-hop/travel steps for either a retraction or a priming
1115+
* @param travel_durations The pre-calculated travel durations
1116+
* @param gcode The gcode exporter
1117+
* @param path The raw travel path to be exported
1118+
* @param settings The anti-ooze settings to be applied
1119+
* @param reversed Indicates if we should process the path forwards (retraction at the beginning) or backwards (prime at the end)
1120+
*/
1121+
static void computeAntiOozeTravelSplit(
1122+
const GCodeExport& gcode,
1123+
const GCodePath& path,
1124+
const Velocity& speed,
1125+
const double amount_during_travel,
1126+
const bool reversed,
1127+
TravelAntiOozing& anti_oozing);
1128+
1129+
/*!
1130+
* Write a single travel segment, taking care of the retraction and priming during travel
1131+
* @param travel_retraction_state The current travel retraction state, which may be updated
1132+
* @param gcode The gcode exporter
1133+
* @param path The full travel path being written
1134+
* @param retraction_amounts The pre-calculated retraction amounts to be processed during this travel move
1135+
* @param priming_amounts The pre-calculated priming amounts to be processed during this travel move
1136+
* @param speed The travel speed
1137+
* @param point_index The index of the current point in the path to be written
1138+
* @warning When travel_retraction_state is None, retraction_amounts and priming_amounts may be std::nullopt, however if it is anything different,
1139+
* it is assumed that they both have a value.
1140+
*/
1141+
void writeTravelSegment(
1142+
TravelRetractionState& travel_retraction_state,
1143+
GCodeExport& gcode,
1144+
const GCodePath& path,
1145+
const std::optional<TravelAntiOozing>& retraction_amounts,
1146+
const std::optional<TravelAntiOozing>& priming_amounts,
1147+
const Velocity& speed,
1148+
const size_t point_index);
10451149
};
10461150

10471151
} // namespace cura

include/PrintFeature.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
namespace cura
55
{
66

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

2629

27-
28-
2930
} // namespace cura
3031

3132
#endif // PRINT_FEATURE

include/RetractionConfig.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#ifndef RETRACTION_CONFIG_H
55
#define RETRACTION_CONFIG_H
66

7+
#include "settings/types/Ratio.h"
78
#include "settings/types/Velocity.h"
89
#include "utils/Coord_t.h"
910

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

2933

30-
}//namespace cura
34+
} // namespace cura
3135

3236
#endif // RETRACTION_CONFIG_H

include/TravelAntiOozing.h

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Copyright (c) 2023 UltiMaker
2+
// CuraEngine is released under the terms of the AGPLv3 or higher
3+
4+
#ifndef TRAVELANTIOOZING_H
5+
#define TRAVELANTIOOZING_H
6+
7+
#include "geometry/Point2LL.h"
8+
#include "settings/types/Ratio.h"
9+
10+
namespace cura
11+
{
12+
13+
struct ZHopAntiOozing
14+
{
15+
double amount{ 0 }; //!< The absolute amount of retracted material (in mm) to be reached while the nozzle is moved up/down
16+
Ratio ratio; //!< The ratio of the full z-hop move that contains a retract/prime
17+
};
18+
19+
struct TravelAntiOozing
20+
{
21+
double amount_while_still{ 0 }; //!< The absolute amount of retracted material (in mm) to be reached while the nozzle is still
22+
ZHopAntiOozing z_hop; //!< The amount and ratio of retracted material to be processed during z-hop move
23+
double amount_while_travel{ 0 }; //!< The absolute amount of retracted material (in mm) to be reached while the nozzle is traveling
24+
Point2LL segment_split_position; //!< The intermediate position on the last/first segment that contains a retract/prime, where it should actually stop/start
25+
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
26+
};
27+
28+
} // namespace cura
29+
30+
#endif /* TRAVELANTIOOZING_H */

0 commit comments

Comments
 (0)