// This method accepts &point in print coordinates. std::string GCode::travel_to(const Point &point, ExtrusionRole role, std::string comment) { /* Define the travel move as a line between current position and the taget point. This is expressed in print coordinates, so it will need to be translated by $self->origin in order to get G-code coordinates. */ Polyline travel; travel.append(this->last_pos()); travel.append(point); // check whether a straight travel move would need retraction bool needs_retraction = this->needs_retraction(travel, role); // if a retraction would be needed, try to use avoid_crossing_perimeters to plan a // multi-hop travel path inside the configuration space if (needs_retraction && this->config.avoid_crossing_perimeters && !this->avoid_crossing_perimeters.disable_once) { travel = this->avoid_crossing_perimeters.travel_to(*this, point); // check again whether the new travel path still needs a retraction needs_retraction = this->needs_retraction(travel, role); } // Re-allow avoid_crossing_perimeters for the next travel moves this->avoid_crossing_perimeters.disable_once = false; this->avoid_crossing_perimeters.use_external_mp_once = false; // generate G-code for the travel move std::string gcode; if (needs_retraction) gcode += this->retract(); // use G1 because we rely on paths being straight (G0 may make round paths) Lines lines = travel.lines(); for (Lines::const_iterator line = lines.begin(); line != lines.end(); ++line) gcode += this->writer.travel_to_xy(this->point_to_gcode(line->b), comment); return gcode; }
// This method accepts &point in print coordinates. std::string GCode::travel_to(const Point &point, ExtrusionRole role, std::string comment) { /* Define the travel move as a line between current position and the taget point. This is expressed in print coordinates, so it will need to be translated by this->origin in order to get G-code coordinates. */ Polyline travel; travel.append(this->last_pos()); travel.append(point); std::string gcode; // check whether a straight travel move would need retraction bool needs_retraction = this->needs_retraction(travel, role); std::stringstream ss; ss << ";needs retr 1: " << needs_retraction << "\n"; gcode += ss.str(); // if a retraction would be needed, try to use avoid_crossing_perimeters to plan a // multi-hop travel path inside the configuration space if (needs_retraction && this->config.avoid_crossing_perimeters && !this->avoid_crossing_perimeters.disable_once) { travel = this->avoid_crossing_perimeters.travel_to(*this, point); gcode += ";HERE!!!!!\n"; // check again whether the new travel path still needs a retraction needs_retraction = this->needs_retraction(travel, role); std::stringstream ss; ss << ";needs retr 2: " << needs_retraction << "\n"; gcode += ss.str(); //if (needs_retraction && this->layer_index > 1) exit(0); } //needs_retraction = true; //vladi //if (this->first_layer) needs_retraction = false;//vladi // Re-allow avoid_crossing_perimeters for the next travel moves this->avoid_crossing_perimeters.disable_once = false; this->avoid_crossing_perimeters.use_external_mp_once = false; // generate G-code for the travel move //if (travel.lines().begin()->length() * SCALING_FACTOR > 2 && this->first_layer) needs_retraction = true; //std::size_t found = comment.find("infill"); bool willDoInfill = (comment.find("infill") != std::string::npos); //if (comment.find("infill") != std::string::npos && this->first_layer) needs_retraction = false; if (needs_retraction) gcode += this->retract(); // use G1 because we rely on paths being straight (G0 may make round paths) Lines lines = travel.lines(); double path_length = 0; for (Lines::const_iterator line = lines.begin(); line != lines.end(); ++line) { const double line_length = line->length() * SCALING_FACTOR; path_length += line_length; std::stringstream ss1; ss1 << ";Will Travel: " << line_length << ", on layer height: " << this->layer->print_z << ", id" << this->layer->id() << "\n"; gcode += ss1.str(); if (this->first_layer && line_length > 3 && !willDoInfill) { if (needs_retraction) { gcode += this->unretract(); gcode += this->writer.travel_to_z(this->layer->print_z, "extrude move on layer height"); } else { gcode += this->writer.travel_to_z(0.1, "extrude move 333"); } double fil_sq = 3.14f *1.75f*1.75f/4; double exr_line = 0.1f*0.4f; double e = exr_line *line_length/fil_sq; //double e_per_mm = this->writer.extruder()->e_per_mm3 * path.mm3_per_mm; // gcode += "G1 F6000\n"; gcode += this->writer.extrude_to_xy(this->point_to_gcode(line->b), e, comment); gcode += this->writer.travel_to_z(this->layer->print_z, "return"); lowerSpeed = true; } else { gcode += this->writer.travel_to_xy(this->point_to_gcode(line->b), comment); } } if (this->config.cooling) this->elapsed_time += path_length / this->config.get_abs_value("travel_speed"); return gcode; }