Esempio n. 1
0
void checkHitEndstops() {
  if (endstop_hit_bits) {
    ECHO_SM(DB, MSG_ENDSTOPS_HIT);
    if (endstop_hit_bits & BIT(X_MIN)) {
      ECHO_MV(MSG_ENDSTOP_X, (float)endstops_trigsteps[X_AXIS] / axis_steps_per_unit[X_AXIS]);
      LCD_MESSAGEPGM(MSG_ENDSTOPS_HIT MSG_ENDSTOP_XS);
    }
    if (endstop_hit_bits & BIT(Y_MIN)) {
      ECHO_MV(MSG_ENDSTOP_Y, (float)endstops_trigsteps[Y_AXIS] / axis_steps_per_unit[Y_AXIS]);
      LCD_MESSAGEPGM(MSG_ENDSTOPS_HIT MSG_ENDSTOP_YS);
    }
    if (endstop_hit_bits & BIT(Z_MIN)) {
      ECHO_MV(MSG_ENDSTOP_Z, (float)endstops_trigsteps[Z_AXIS] / axis_steps_per_unit[Z_AXIS]);
      LCD_MESSAGEPGM(MSG_ENDSTOPS_HIT MSG_ENDSTOP_ZS);
    }
    #ifdef Z_PROBE_ENDSTOP
    if (endstop_hit_bits & BIT(Z_PROBE)) {
      ECHO_MV(MSG_ENDSTOP_ZPS, (float)endstops_trigsteps[Z_AXIS] / axis_steps_per_unit[Z_AXIS]);
      LCD_MESSAGEPGM(MSG_ENDSTOPS_HIT MSG_ENDSTOP_ZPS);
    }
    #endif
    #ifdef NPR2
    if (endstop_hit_bits & BIT(E_MIN)) {
      ECHO_MV(MSG_ENDSTOP_E, (float)endstops_trigsteps[E_AXIS] / axis_steps_per_unit[E_AXIS]);
      LCD_MESSAGEPGM(MSG_ENDSTOPS_HIT MSG_ENDSTOP_ES);
    }
    #endif
    ECHO_E;

    endstops_hit_on_purpose();

    #if defined(ABORT_ON_ENDSTOP_HIT_FEATURE_ENABLED) && defined(SDSUPPORT)
      if (abort_on_endstop_hit) {
        card.sdprinting = false;
        card.closeFile();
        quickStop();
        disable_all_heaters(); // switch off all heaters.
      }
    #endif
  }
}
Esempio n. 2
0
void checkHitEndstops() {
  if (endstop_hit_bits) {
    SERIAL_ECHO_START;
    SERIAL_ECHOPGM(MSG_ENDSTOPS_HIT);
    if (endstop_hit_bits & BIT(X_MIN)) {
      SERIAL_ECHOPAIR(" X:", (float)endstops_trigsteps[X_AXIS] / axis_steps_per_unit[X_AXIS]);
      LCD_MESSAGEPGM(MSG_ENDSTOPS_HIT "X");
    }
    if (endstop_hit_bits & BIT(Y_MIN)) {
      SERIAL_ECHOPAIR(" Y:", (float)endstops_trigsteps[Y_AXIS] / axis_steps_per_unit[Y_AXIS]);
      LCD_MESSAGEPGM(MSG_ENDSTOPS_HIT "Y");
    }
    if (endstop_hit_bits & BIT(Z_MIN)) {
      SERIAL_ECHOPAIR(" Z:", (float)endstops_trigsteps[Z_AXIS] / axis_steps_per_unit[Z_AXIS]);
      LCD_MESSAGEPGM(MSG_ENDSTOPS_HIT "Z");
    }
    #ifdef Z_PROBE_ENDSTOP
    if (endstop_hit_bits & BIT(Z_PROBE)) {
      SERIAL_ECHOPAIR(" Z_PROBE:", (float)endstops_trigsteps[Z_AXIS] / axis_steps_per_unit[Z_AXIS]);
      LCD_MESSAGEPGM(MSG_ENDSTOPS_HIT "ZP");
    }
    #endif
    SERIAL_EOL;

    endstops_hit_on_purpose();

    #if defined(ABORT_ON_ENDSTOP_HIT_FEATURE_ENABLED) && defined(SDSUPPORT)
      if (abort_on_endstop_hit) {
        card.sdprinting = false;
        card.closefile();
        quickStop();
        disable_all_heaters(); // switch off all heaters.
      }
    #endif
  }
}
Esempio n. 3
0
void PID_autotune(float temp, int extruder, int ncycles)
{
  float input = 0.0;
  int cycles = 0;
  bool heating = true;

  millis_t temp_ms = millis(), t1 = temp_ms, t2 = temp_ms;
  long t_high = 0, t_low = 0;

  long bias, d;
  float Ku, Tu;
  float Kp, Ki, Kd;
  float max = 0, min = 10000;

  #if HAS_AUTO_FAN
    millis_t next_auto_fan_check_ms = temp_ms + 2500;
  #endif

  if (extruder >= EXTRUDERS
    #if !HAS_TEMP_BED
       || extruder < 0
    #endif
  ) {
    SERIAL_ECHOLN(MSG_PID_BAD_EXTRUDER_NUM);
    return;
  }
  
  SERIAL_ECHOLN(MSG_PID_AUTOTUNE_START);

  disable_all_heaters(); // switch off all heaters.

  if (extruder < 0)
    soft_pwm_bed = bias = d = MAX_BED_POWER / 2;
  else
    soft_pwm[extruder] = bias = d = PID_MAX / 2;

  // PID Tuning loop
  for (;;) {

    millis_t ms = millis();

    if (temp_meas_ready) { // temp sample ready
      updateTemperaturesFromRawValues();

      input = (extruder<0)?current_temperature_bed:current_temperature[extruder];

      max = max(max, input);
      min = min(min, input);

      #if HAS_AUTO_FAN
        if (ms > next_auto_fan_check_ms) {
          checkExtruderAutoFans();
          next_auto_fan_check_ms = ms + 2500;
        }
      #endif

      if (heating && input > temp) {
        if (ms > t2 + 5000) {
          heating = false;
          if (extruder < 0)
            soft_pwm_bed = (bias - d) >> 1;
          else
            soft_pwm[extruder] = (bias - d) >> 1;
          t1 = ms;
          t_high = t1 - t2;
          max = temp;
        }
      }

      if (!heating && input < temp) {
        if (ms > t1 + 5000) {
          heating = true;
          t2 = ms;
          t_low = t2 - t1;
          if (cycles > 0) {
            long max_pow = extruder < 0 ? MAX_BED_POWER : PID_MAX;
            bias += (d*(t_high - t_low))/(t_low + t_high);
            bias = constrain(bias, 20, max_pow - 20);
            d = (bias > max_pow / 2) ? max_pow - 1 - bias : bias;

            SERIAL_PROTOCOLPGM(MSG_BIAS); SERIAL_PROTOCOL(bias);
            SERIAL_PROTOCOLPGM(MSG_D);    SERIAL_PROTOCOL(d);
            SERIAL_PROTOCOLPGM(MSG_T_MIN);  SERIAL_PROTOCOL(min);
            SERIAL_PROTOCOLPGM(MSG_T_MAX);  SERIAL_PROTOCOLLN(max);
            if (cycles > 2) {
              Ku = (4.0 * d) / (3.14159265 * (max - min) / 2.0);
              Tu = ((float)(t_low + t_high) / 1000.0);
              SERIAL_PROTOCOLPGM(MSG_KU); SERIAL_PROTOCOL(Ku);
              SERIAL_PROTOCOLPGM(MSG_TU); SERIAL_PROTOCOLLN(Tu);
              Kp = 0.6 * Ku;
              Ki = 2 * Kp / Tu;
              Kd = Kp * Tu / 8;
              SERIAL_PROTOCOLLNPGM(MSG_CLASSIC_PID);
              SERIAL_PROTOCOLPGM(MSG_KP); SERIAL_PROTOCOLLN(Kp);
              SERIAL_PROTOCOLPGM(MSG_KI); SERIAL_PROTOCOLLN(Ki);
              SERIAL_PROTOCOLPGM(MSG_KD); SERIAL_PROTOCOLLN(Kd);
              /*
              Kp = 0.33*Ku;
              Ki = Kp/Tu;
              Kd = Kp*Tu/3;
              SERIAL_PROTOCOLLNPGM(" Some overshoot ");
              SERIAL_PROTOCOLPGM(" Kp: "); SERIAL_PROTOCOLLN(Kp);
              SERIAL_PROTOCOLPGM(" Ki: "); SERIAL_PROTOCOLLN(Ki);
              SERIAL_PROTOCOLPGM(" Kd: "); SERIAL_PROTOCOLLN(Kd);
              Kp = 0.2*Ku;
              Ki = 2*Kp/Tu;
              Kd = Kp*Tu/3;
              SERIAL_PROTOCOLLNPGM(" No overshoot ");
              SERIAL_PROTOCOLPGM(" Kp: "); SERIAL_PROTOCOLLN(Kp);
              SERIAL_PROTOCOLPGM(" Ki: "); SERIAL_PROTOCOLLN(Ki);
              SERIAL_PROTOCOLPGM(" Kd: "); SERIAL_PROTOCOLLN(Kd);
              */
            }
          }
          if (extruder < 0)
            soft_pwm_bed = (bias + d) >> 1;
          else
            soft_pwm[extruder] = (bias + d) >> 1;
          cycles++;
          min = temp;
        }
Esempio n. 4
0
void CardReader::closeFile(bool store_location /*=false*/) {
  file.sync();
  file.close();
  saving = false;

  if (store_location) {
    char bufferFilerestart[50];
    char bufferX[11];
    char bufferY[11];
    char bufferZ[11];
    char bufferE[11];
    char bufferCoord[50];
    char bufferCoord1[50];
    char bufferCoord2[50];
    char bufferSdpos[11];
    char nameFile[15];
    snprintf(bufferSdpos, sizeof bufferSdpos, "%lu", (unsigned long)sdpos);

    strcpy(nameFile, "restart.gcode");
    if (!fileRestart.exists(nameFile)) {
      fileRestart.createContiguous(&workDir, nameFile, 1);
      fileRestart.close();
    }

    fileRestart.open(&workDir, nameFile, O_WRITE);
    fileRestart.truncate(0);

    dtostrf(current_position[X_AXIS], 1, 3, bufferX);
    dtostrf(current_position[Y_AXIS], 1, 3, bufferY);
    dtostrf(current_position[Z_AXIS], 1, 3, bufferZ);
    dtostrf(current_position[E_AXIS], 1, 3, bufferE);

    #if MECH(DELTA)
      strcpy(bufferCoord1, "G1 Z");
      strcat(bufferCoord1, bufferZ);
      strcat(bufferCoord1, " F8000");
    #else
      strcpy(bufferCoord1, "G92 Z");
      strcat(bufferCoord1, bufferZ);
    #endif

    strcpy(bufferCoord, "G1 X");
    strcat(bufferCoord, bufferX);
    strcat(bufferCoord, " Y");
    strcat(bufferCoord, bufferY);
    strcat(bufferCoord, " Z");
    strcat(bufferCoord, bufferZ);
    strcat(bufferCoord, " F3600");
    strcpy(bufferCoord2, "G92 E");
    strcat(bufferCoord2, bufferE);

    for (int8_t i = 0; i < (int8_t)strlen(fullName); i++)
      fullName[i] = tolower(fullName[i]);

    strcpy(bufferFilerestart, "M34 S");
    strcat(bufferFilerestart, bufferSdpos);
    strcat(bufferFilerestart, " @");
    strcat(bufferFilerestart, fullName);

    #if MECH(DELTA)
      fileRestart.write("G28\n");
    #else
      fileRestart.write(bufferCoord1);
      fileRestart.write("\n");
      fileRestart.write("G28 X Y\n");
    #endif

    if (degTargetBed() > 0) {
      char Bedtemp[15];
      sprintf(Bedtemp, "M190 S%i\n", (int)degTargetBed());
      fileRestart.write(Bedtemp);
    }

    char CurrHotend[10];
    sprintf(CurrHotend, "T%i\n", active_extruder);
    fileRestart.write(CurrHotend);

    for (uint8_t h = 0; h < HOTENDS; h++) {
      if (degTargetHotend(h) > 0) {
        char Hotendtemp[15];
        sprintf(Hotendtemp, "M109 T%i S%i\n", h, (int)degTargetHotend(h));
        fileRestart.write(Hotendtemp);
      }
    }

    #if MECH(DELTA)
      fileRestart.write(bufferCoord1);
      fileRestart.write("\n");
    #endif

    fileRestart.write(bufferCoord);
    fileRestart.write("\n");

   	if (fanSpeed > 0) {
      char fanSp[15];
      sprintf(fanSp, "M106 S%i\n", fanSpeed);
      fileRestart.write(fanSp);
    }

    fileRestart.write(bufferCoord2);
    fileRestart.write("\n");
    fileRestart.write(bufferFilerestart);
    fileRestart.write("\n");

    fileRestart.sync();
    fileRestart.close();

    HAL::delayMilliseconds(200);

    #if MECH(DELTA)
      enqueue_and_echo_commands_P(PSTR("G28"));
    #else
      enqueue_and_echo_commands_P(PSTR("G28 X0 Y0"));
    #endif

    disable_all_heaters();
    disable_all_coolers();
    fanSpeed = 0;
  }
}
Esempio n. 5
0
  void PID_autotune(float temp, int hotend, int ncycles) {
    float input = 0.0;
    int cycles = 0;
    bool heating = true;

    millis_t temp_ms = millis(), t1 = temp_ms, t2 = temp_ms;
    long t_high = 0, t_low = 0;

    long bias, d;
    float Ku, Tu;
    float Kp_temp, Ki_temp, Kd_temp;
    float max = 0, min = 10000;

    #if HAS_AUTO_FAN
      millis_t next_auto_fan_check_ms = temp_ms + 2500;
    #endif

    if (hotend >= HOTENDS
      #if !HAS_TEMP_BED
         || hotend < 0
      #endif
    ) {
      ECHO_LM(ER, MSG_PID_BAD_EXTRUDER_NUM);
      return;
    }

    ECHO_LM(DB, MSG_PID_AUTOTUNE_START);
    if (hotend < 0) {
      ECHO_SM(DB, "BED");
    }
    else {
        ECHO_SMV(DB, "Hotend: ", hotend);
    }
    ECHO_MV(" Temp: ", temp);
    ECHO_EMV(" Cycles: ", ncycles);

    disable_all_heaters(); // switch off all heaters.

    if (hotend < 0)
      soft_pwm_bed = bias = d = MAX_BED_POWER / 2;
    else
      soft_pwm[hotend] = bias = d = PID_MAX / 2;

    // PID Tuning loop
    for (;;) {

      millis_t ms = millis();

      if (temp_meas_ready) { // temp sample ready
        updateTemperaturesFromRawValues();

        input = (hotend<0)?current_temperature_bed:current_temperature[hotend];

        max = max(max, input);
        min = min(min, input);

        #if HAS_AUTO_FAN
          if (ms > next_auto_fan_check_ms) {
            checkExtruderAutoFans();
            next_auto_fan_check_ms = ms + 2500;
          }
        #endif

        if (heating && input > temp) {
          if (ms > t2 + 5000) {
            heating = false;
            if (hotend < 0)
              soft_pwm_bed = (bias - d) >> 1;
            else
              soft_pwm[hotend] = (bias - d) >> 1;
            t1 = ms;
            t_high = t1 - t2;
            max = temp;
          }
        }

        if (!heating && input < temp) {
          if (ms > t1 + 5000) {
            heating = true;
            t2 = ms;
            t_low = t2 - t1;
            if (cycles > 0) {
              long max_pow = hotend < 0 ? MAX_BED_POWER : PID_MAX;
              bias += (d*(t_high - t_low))/(t_low + t_high);
              bias = constrain(bias, 20, max_pow - 20);
              d = (bias > max_pow / 2) ? max_pow - 1 - bias : bias;

              ECHO_MV(MSG_BIAS, bias);
              ECHO_MV(MSG_D, d);
              ECHO_MV(MSG_T_MIN, min);
              ECHO_MV(MSG_T_MAX, max);
              if (cycles > 2) {
                Ku = (4.0 * d) / (3.14159265 * (max - min) / 2.0);
                Tu = ((float)(t_low + t_high) / 1000.0);
                ECHO_MV(MSG_KU, Ku);
                ECHO_EMV(MSG_TU, Tu);
                Kp_temp = 0.6 * Ku;
                Ki_temp = 2 * Kp_temp / Tu;
                Kd_temp = Kp_temp * Tu / 8;
                
                ECHO_EM(MSG_CLASSIC_PID);
                ECHO_MV(MSG_KP, Kp_temp);
                ECHO_MV(MSG_KI, Ki_temp);
                ECHO_EMV(MSG_KD, Kd_temp);
              }
              else {
                ECHO_E;
              }
            }
            if (hotend < 0)
              soft_pwm_bed = (bias + d) >> 1;
            else
              soft_pwm[hotend] = (bias + d) >> 1;
            cycles++;
            min = temp;
          }