void GCodePlanner::forceMinimalLayerTime(double minTime, double minimalSpeed, double travelTime, double extrudeTime) { double totalTime = travelTime + extrudeTime; if (totalTime < minTime && extrudeTime > 0.0) { double minExtrudeTime = minTime - travelTime; if (minExtrudeTime < 1) minExtrudeTime = 1; double factor = extrudeTime / minExtrudeTime; for(unsigned int n=0; n<paths.size(); n++) { GCodePath* path = &paths[n]; if (path->getExtrusionMM3perMM() == 0) continue; double speed = path->config->getSpeed() * factor; if (speed < minimalSpeed) factor = minimalSpeed / path->config->getSpeed(); } //Only slow down with the minimal time if that will be slower then a factor already set. First layer slowdown also sets the speed factor. if (factor < getExtrudeSpeedFactor()) setExtrudeSpeedFactor(factor); else factor = getExtrudeSpeedFactor(); if (minTime - (extrudeTime / factor) - travelTime > 0.1) { this->extraTime = minTime - (extrudeTime / factor) - travelTime; } this->totalPrintTime = (extrudeTime / factor) + travelTime; }else{ this->totalPrintTime = totalTime; } }
void MergeInfillLines::writeCompensatedMove(Point& to, double speed, GCodePath& last_path, int64_t new_line_width) { double old_line_width = INT2MM(last_path.config->getLineWidth()); double new_line_width_mm = INT2MM(new_line_width); double extrusion_mod = new_line_width_mm / old_line_width; double new_speed = speed; if (speed_equalize_flow_enabled) { double speed_mod = old_line_width / new_line_width_mm; new_speed = std::min(speed * speed_mod, speed_equalize_flow_max); } sendLineTo(last_path.config->type, to, last_path.getLineWidthForLayerView(), last_path.config->getLayerThickness(), new_speed); gcode.writeExtrusion(to, new_speed, last_path.getExtrusionMM3perMM() * extrusion_mod, last_path.config->type); }
void MergeInfillLines::writeCompensatedMove(Point& to, double speed, GCodePath& last_path, int64_t new_line_width) { double old_line_width = INT2MM(last_path.config->getLineWidth()); double new_line_width_mm = INT2MM(new_line_width); double speed_mod = old_line_width / new_line_width_mm; double extrusion_mod = new_line_width_mm / old_line_width; gcode.writeMove(to, speed * speed_mod, last_path.getExtrusionMM3perMM() * extrusion_mod); }
void MergeInfillLines::writeCompensatedMove(Point& to, double speed, GCodePath& last_path, int64_t new_line_width) { double old_line_width = INT2MM(last_path.config->getLineWidth()); double new_line_width_mm = INT2MM(new_line_width); double speed_mod = old_line_width / new_line_width_mm; double extrusion_mod = new_line_width_mm / old_line_width; double new_speed = std::min(speed * speed_mod, 150.0); // TODO: hardcoded value: max extrusion speed is 150 mm/s = 9000 mm/min gcode.writeMove(to, new_speed, last_path.getExtrusionMM3perMM() * extrusion_mod); }
void GCodePlanner::getNaiveTimeEstimates(double& travelTime, double& extrudeTime) { travelTime = 0.0; extrudeTime = 0.0; Point p0 = gcode.getPositionXY(); for(unsigned int n=0; n<paths.size(); n++) { GCodePath* path = &paths[n]; for(unsigned int i=0; i<path->points.size(); i++) { double thisTime = vSizeMM(p0 - path->points[i]) / path->config->getSpeed(); if (path->getExtrusionMM3perMM() != 0) extrudeTime += thisTime; else travelTime += thisTime; p0 = path->points[i]; } } }
bool GCodePlanner::writePathWithCoasting(GCodePath& path, GCodePath& path_next, int64_t layerThickness, double coasting_volume, double coasting_speed, double coasting_min_volume, bool extruder_switch_retract) { int64_t coasting_min_dist_considered = 100; // hardcoded setting for when to not perform coasting double extrude_speed = path.config->getSpeed() * getExtrudeSpeedFactor(); // travel speed int64_t coasting_dist = MM2INT(MM2_2INT(coasting_volume) / layerThickness) / path.config->getLineWidth(); // closing brackets of MM2INT at weird places for precision issues int64_t coasting_min_dist = MM2INT(MM2_2INT(coasting_min_volume) / layerThickness) / path.config->getLineWidth(); // closing brackets of MM2INT at weird places for precision issues std::vector<int64_t> accumulated_dist_per_point; // the first accumulated dist is that of the last point! (that of the last point is always zero...) accumulated_dist_per_point.push_back(0); int64_t accumulated_dist = 0; bool length_is_less_than_min_dist = true; unsigned int acc_dist_idx_gt_coast_dist = NO_INDEX; // the index of the first point with accumulated_dist more than coasting_dist (= index into accumulated_dist_per_point) // == the point printed BEFORE the start point for coasting Point* last = &path.points[path.points.size() - 1]; for (unsigned int backward_point_idx = 1; backward_point_idx < path.points.size(); backward_point_idx++) { Point& point = path.points[path.points.size() - 1 - backward_point_idx]; int64_t dist = vSize(point - *last); accumulated_dist += dist; accumulated_dist_per_point.push_back(accumulated_dist); if (acc_dist_idx_gt_coast_dist == NO_INDEX && accumulated_dist >= coasting_dist) { acc_dist_idx_gt_coast_dist = backward_point_idx; // the newly added point } if (accumulated_dist >= coasting_min_dist) { length_is_less_than_min_dist = false; break; } last = &point; } if (accumulated_dist < coasting_min_dist_considered) { return false; } int64_t actual_coasting_dist = coasting_dist; if (length_is_less_than_min_dist) { // in this case accumulated_dist is the length of the whole path actual_coasting_dist = accumulated_dist * coasting_dist / coasting_min_dist; for (acc_dist_idx_gt_coast_dist = 0 ; acc_dist_idx_gt_coast_dist < accumulated_dist_per_point.size() ; acc_dist_idx_gt_coast_dist++) { // search for the correct coast_dist_idx if (accumulated_dist_per_point[acc_dist_idx_gt_coast_dist] > actual_coasting_dist) { break; } } } if (acc_dist_idx_gt_coast_dist == NO_INDEX) { // something has gone wrong; coasting_min_dist < coasting_dist ? return false; } unsigned int point_idx_before_start = path.points.size() - 1 - acc_dist_idx_gt_coast_dist; Point start; { // computation of begin point of coasting int64_t residual_dist = actual_coasting_dist - accumulated_dist_per_point[acc_dist_idx_gt_coast_dist - 1]; Point& a = path.points[point_idx_before_start]; Point& b = path.points[point_idx_before_start + 1]; start = b + normal(a-b, residual_dist); } { // write normal extrude path: for(unsigned int point_idx = 0; point_idx <= point_idx_before_start; point_idx++) { gcode.writeMove(path.points[point_idx], extrude_speed, path.getExtrusionMM3perMM()); } gcode.writeMove(start, extrude_speed, path.getExtrusionMM3perMM()); } if (path_next.retract) { writeRetraction(extruder_switch_retract, path.config->retraction_config); } for (unsigned int point_idx = point_idx_before_start + 1; point_idx < path.points.size(); point_idx++) { gcode.writeMove(path.points[point_idx], coasting_speed * path.config->getSpeed(), 0); } gcode.setLastCoastedAmountMM3(path.getExtrusionMM3perMM() * INT2MM(actual_coasting_dist)); return true; }