diff options
author | Jaime van Kessel <nallath@gmail.com> | 2022-05-18 17:32:53 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-05-18 17:32:53 +0300 |
commit | a7f8b390d6d438612ffb9a8e64645c420017cd5c (patch) | |
tree | e0dd1fad6cb00aa85f7cff7bdb6779e3bd16e8c4 | |
parent | ac0aae947fbbead4861830e8ba65b6cd1de2098b (diff) | |
parent | 94a656d8e29d9603d01dad9b3a9b610faea90c10 (diff) |
Merge pull request #1661 from Ultimaker/CURA-8708_remove_travel_acceleration_jerk
Implement option to add or remove acceleration or jerk command specific to travels
-rw-r--r-- | src/LayerPlan.cpp | 56 | ||||
-rw-r--r-- | src/LayerPlan.h | 2 | ||||
-rw-r--r-- | src/LayerPlanBuffer.cpp | 3 |
3 files changed, 59 insertions, 2 deletions
diff --git a/src/LayerPlan.cpp b/src/LayerPlan.cpp index 74b946293..c63e51789 100644 --- a/src/LayerPlan.cpp +++ b/src/LayerPlan.cpp @@ -515,6 +515,10 @@ void LayerPlan::addExtrusionMove(Point p, const GCodePathConfig& config, SpaceFi GCodePath* path = getLatestPathWithConfig(config, space_fill_type, flow, width_factor, spiralize, speed_factor); path->points.push_back(p); path->setFanSpeed(fan_speed); + if(!static_cast<bool>(first_extrusion_acc_jerk)) + { + first_extrusion_acc_jerk = std::make_pair(path->config->getAcceleration(), path->config->getJerk()); + } last_planned_position = p; } @@ -1634,7 +1638,9 @@ void LayerPlan::writeGCode(GCodeExport& gcode) size_t extruder_nr = gcode.getExtruderNr(); const bool acceleration_enabled = mesh_group_settings.get<bool>("acceleration_enabled"); + const bool acceleration_travel_enabled = mesh_group_settings.get<bool>("acceleration_travel_enabled"); const bool jerk_enabled = mesh_group_settings.get<bool>("jerk_enabled"); + const bool jerk_travel_enabled = mesh_group_settings.get<bool>("jerk_travel_enabled"); std::string current_mesh = "NONMESH"; for(size_t extruder_plan_idx = 0; extruder_plan_idx < extruder_plans.size(); extruder_plan_idx++) @@ -1730,11 +1736,39 @@ void LayerPlan::writeGCode(GCodeExport& gcode) continue; } + //In some cases we want to find the next non-travel move. + size_t next_extrusion_idx = path_idx + 1; + if((acceleration_enabled && !acceleration_travel_enabled) || (jerk_enabled && !jerk_travel_enabled)) + { + while(next_extrusion_idx < paths.size() && paths[next_extrusion_idx].config->isTravelPath()) + { + ++next_extrusion_idx; + } + } + if (acceleration_enabled) { if (path.config->isTravelPath()) { - gcode.writeTravelAcceleration(path.config->getAcceleration()); + if(acceleration_travel_enabled) + { + gcode.writeTravelAcceleration(path.config->getAcceleration()); + } + else + { + //Use the acceleration of the first non-travel move *after* the travel. + if(next_extrusion_idx >= paths.size()) //Only travel moves for the remainder of the layer. + { + if(static_cast<bool>(next_layer_acc_jerk)) + { + gcode.writeTravelAcceleration(next_layer_acc_jerk->first); + } //If the next layer has no extruded move, just keep the old acceleration. Should be very rare to have an empty layer. + } + else + { + gcode.writeTravelAcceleration(paths[next_extrusion_idx].config->getAcceleration()); + } + } } else { @@ -1743,7 +1777,25 @@ void LayerPlan::writeGCode(GCodeExport& gcode) } if (jerk_enabled) { - gcode.writeJerk(path.config->getJerk()); + if(jerk_travel_enabled) + { + gcode.writeJerk(path.config->getJerk()); + } + else + { + //Use the jerk of the first non-travel move *after* the travel. + if(next_extrusion_idx >= paths.size()) //Only travel moves for the remainder of the layer. + { + if(static_cast<bool>(next_layer_acc_jerk)) + { + gcode.writeJerk(next_layer_acc_jerk->second); + } //If the next layer has no extruded move, just keep the old jerk. Should be very rare to have an empty layer. + } + else + { + gcode.writeJerk(paths[next_extrusion_idx].config->getJerk()); + } + } } if (path.retract) diff --git a/src/LayerPlan.h b/src/LayerPlan.h index 6a0619900..24c678063 100644 --- a/src/LayerPlan.h +++ b/src/LayerPlan.h @@ -255,6 +255,8 @@ private: std::optional<Point> first_travel_destination; //!< The destination of the first (travel) move (if this layer is not empty) bool first_travel_destination_is_inside; //!< Whether the destination of the first planned travel move is inside a layer part + std::optional<std::pair<Acceleration, Velocity>> first_extrusion_acc_jerk; //!< The acceleration and jerk rates of the first extruded move (if this layer is not empty). + std::optional<std::pair<Acceleration, Velocity>> next_layer_acc_jerk; //!< If there is a next layer, the first acceleration and jerk it starts with. bool was_inside; //!< Whether the last planned (extrusion) move was inside a layer part bool is_inside; //!< Whether the destination of the next planned travel move is inside a layer part Polygons comb_boundary_minimum; //!< The minimum boundary within which to comb, or to move into when performing a retraction. diff --git a/src/LayerPlanBuffer.cpp b/src/LayerPlanBuffer.cpp index 4e91981e9..d5faaf8b9 100644 --- a/src/LayerPlanBuffer.cpp +++ b/src/LayerPlanBuffer.cpp @@ -107,6 +107,9 @@ void LayerPlanBuffer::addConnectingTravelMove(LayerPlan* prev_layer, const Layer path.retract = true; } } + + //If not using travel-specific jerk and acceleration, the layer plan needs to know the jerk/acc of the first extrusion move of the next layer. + prev_layer->next_layer_acc_jerk = newest_layer->first_extrusion_acc_jerk; } void LayerPlanBuffer::processFanSpeedLayerTime() |