示例#1
0
  /**
   * Guess diameter 1) user defined environment variable 2) comments in GCODE file 3) Fallback to
   * some very rough calculation
   *
   * @return diameter
   */
  private float guessDiameter() {
    // Read user defined environment variable if exists
    try {
      String dia = System.getenv("FILAMENT_DIAMETER");
      if (dia != null) {
        // System.out.println("Use env value FILAMENT_DIAMETER="+dia);
        return Float.parseFloat(dia);
      }
    } catch (NumberFormatException e1) {
    }

    // get diameter from comments in gcode file
    try {
      GCodeStore codes = getGcodes();
      for (GCode gCode : codes) {
        // Ignore comments behind gcodes
        if (gCode.isComment()) {
          // System.out.println("COMMENT"+gCode.getComment());
          if (gCode.getComment().matches(".*FILAMENT_DIAMETER\\s=.*")) { // SLICER
            // System.out.println("MATCHES:"+gCode.getComment());
            String[] res = gCode.getComment().split("=");
            return Float.parseFloat(res[1]);
          } else if (gCode.getComment().matches(".*FILAMENT_DIAMETER_.*")) { // SKEINFORGE
            // System.out.println("MATCHES:"+gCode.getComment());
            String[] res = gCode.getComment().split("[:<]");
            return Float.parseFloat(res[2]);
          }
        }
      }
    } catch (Exception e) {
      // Comment parsing failed
    }
    //	System.err.println("Failed to parse GCODE comments for filament diameter. Fallback to
    // guessing.");
    // Fallback ... no comments found
    isguessed = true;
    // Tried many formulars but there is no good way to guess the diameter (too many unknowns)
    //
    float exRadius = getAvgLayerHeight() / 2;
    float WOT = 2.1f; // Assume a wide over thickness value of ~2.1 (heavily depends on nozzel size)
    double extrArea = exRadius * (exRadius * WOT) * Math.PI; // Fläche extruded mm2
    double menge = extrArea * getDistance();
    double sizeArea = menge / getExtrusion();
    double guessedDia = Math.sqrt(sizeArea / Math.PI) * 2;
    //	System.out.println("Extr menge mm3:"+menge/1000+" Estimate dia:"+guessedDia);

    // Either take 1.75 or 3mm
    if (guessedDia > 2.45f) {
      return 3;
    } else if (guessedDia < 2.05f) {
      return 1.75f;
    }
    // use 3
    System.out.println(
        "Unable to detect diameter - Fallback to 3mm.\nPlease set environment variable FILAMENT_DIAMETER");
    return 3;
  }
示例#2
0
 public String getModelComments() {
   StringBuilder buf = new StringBuilder(500);
   buf.append("--------- Slicer Comments------------\n");
   int max = 500; // max to avoid OOM
   for (GCode gCode : gcodes) {
     // Ignore comments behind gcodes
     if (max > 0 && gCode.isComment()) {
       // System.out.println(gCode.getComment());
       buf.append(gCode.getComment());
       buf.append(Constants.newlinec);
       max--;
     }
   }
   return buf.toString();
 }