Sfoglia il codice sorgente

Make Autotune options into Menu Edit Items

Scott Lahteine 9 anni fa
parent
commit
04fa9d4f47
6 ha cambiato i file con 68 aggiunte e 28 eliminazioni
  1. 1
    0
      Marlin/Marlin.h
  2. 13
    4
      Marlin/Marlin_main.cpp
  3. 1
    1
      Marlin/cardreader.cpp
  4. 3
    2
      Marlin/temperature.cpp
  5. 1
    1
      Marlin/temperature.h
  6. 49
    20
      Marlin/ultralcd.cpp

+ 1
- 0
Marlin/Marlin.h Vedi File

@@ -228,6 +228,7 @@ inline bool IsRunning() { return  Running; }
228 228
 inline bool IsStopped() { return !Running; }
229 229
 
230 230
 bool enqueue_and_echo_command(const char* cmd, bool say_ok=false); //put a single ASCII command at the end of the current buffer or return false when it is full
231
+void enqueue_and_echo_command_now(const char* cmd); // enqueue now, only return when the command has been enqueued
231 232
 void enqueue_and_echo_commands_P(const char* cmd); //put one or many ASCII commands at the end of the current buffer, read from flash
232 233
 
233 234
 void prepare_arc_move(char isclockwise);

+ 13
- 4
Marlin/Marlin_main.cpp Vedi File

@@ -549,6 +549,10 @@ inline bool _enqueuecommand(const char* cmd, bool say_ok=false) {
549 549
   return true;
550 550
 }
551 551
 
552
+void enqueue_and_echo_command_now(const char* cmd) {
553
+  while (!enqueue_and_echo_command(cmd)) idle();
554
+}
555
+
552 556
 /**
553 557
  * Enqueue with Serial Echo
554 558
  */
@@ -5135,9 +5139,11 @@ inline void gcode_M226() {
5135 5139
 
5136 5140
 /**
5137 5141
  * M303: PID relay autotune
5138
- *       S<temperature> sets the target temperature. (default target temperature = 150C)
5139
- *       E<extruder> (-1 for the bed)
5142
+ *
5143
+ *       S<temperature> sets the target temperature. (default 150C)
5144
+ *       E<extruder> (-1 for the bed) (default 0)
5140 5145
  *       C<cycles>
5146
+ *       U<bool> with a non-zero value will apply the result to current settings
5141 5147
  */
5142 5148
 inline void gcode_M303() {
5143 5149
   int e = code_seen('E') ? code_value_short() : 0;
@@ -5146,11 +5152,14 @@ inline void gcode_M303() {
5146 5152
   
5147 5153
   float temp = code_seen('S') ? code_value() : (e < 0 ? 70.0 : 150.0);
5148 5154
 
5149
-  if (e >=0 && e < EXTRUDERS)
5155
+  if (e >= 0 && e < EXTRUDERS)
5150 5156
     target_extruder = e;
5151 5157
 
5152
-  KEEPALIVE_STATE(NOT_BUSY);
5158
+  KEEPALIVE_STATE(NOT_BUSY); // don't send "busy: processing" messages during autotune output
5159
+
5153 5160
   PID_autotune(temp, e, c, u);
5161
+
5162
+  KEEPALIVE_STATE(IN_HANDLER);
5154 5163
 }
5155 5164
 
5156 5165
 #if ENABLED(SCARA)

+ 1
- 1
Marlin/cardreader.cpp Vedi File

@@ -247,7 +247,7 @@ void CardReader::openAndPrintFile(const char *name) {
247 247
   char cmd[4 + (FILENAME_LENGTH + 1) * MAX_DIR_DEPTH + 2]; // Room for "M23 ", names with slashes, a null, and one extra
248 248
   sprintf_P(cmd, PSTR("M23 %s"), name);
249 249
   for (char *c = &cmd[4]; *c; c++) *c = tolower(*c);
250
-  enqueue_and_echo_command(cmd);
250
+  enqueue_and_echo_command_now(cmd);
251 251
   enqueue_and_echo_commands_P(PSTR("M24"));
252 252
 }
253 253
 

+ 3
- 2
Marlin/temperature.cpp Vedi File

@@ -199,7 +199,7 @@ static void updateTemperaturesFromRawValues();
199 199
 //================================ Functions ================================
200 200
 //===========================================================================
201 201
 
202
-void PID_autotune(float temp, int extruder, int ncycles, bool set_result /* = false */) {
202
+void PID_autotune(float temp, int extruder, int ncycles, bool set_result/*=false*/) {
203 203
   float input = 0.0;
204 204
   int cycles = 0;
205 205
   bool heating = true;
@@ -346,7 +346,8 @@ void PID_autotune(float temp, int extruder, int ncycles, bool set_result /* = fa
346 346
       SERIAL_PROTOCOLPGM("#define  DEFAULT_"); SERIAL_PROTOCOL(estring); SERIAL_PROTOCOLPGM("Kp "); SERIAL_PROTOCOLLN(Kp);
347 347
       SERIAL_PROTOCOLPGM("#define  DEFAULT_"); SERIAL_PROTOCOL(estring); SERIAL_PROTOCOLPGM("Ki "); SERIAL_PROTOCOLLN(Ki);
348 348
       SERIAL_PROTOCOLPGM("#define  DEFAULT_"); SERIAL_PROTOCOL(estring); SERIAL_PROTOCOLPGM("Kd "); SERIAL_PROTOCOLLN(Kd);
349
-      //Uses the result if set_result is true
349
+
350
+      // Use the result? (As with "M303 U1")
350 351
       if (set_result) {
351 352
         if (extruder < 0) {
352 353
           #if ENABLED(PIDTEMPBED)

+ 1
- 1
Marlin/temperature.h Vedi File

@@ -141,7 +141,7 @@ int getHeaterPower(int heater);
141 141
 void disable_all_heaters();
142 142
 void updatePID();
143 143
 
144
-void PID_autotune(float temp, int extruder, int ncycles, bool set_result = false);
144
+void PID_autotune(float temp, int extruder, int ncycles, bool set_result=false);
145 145
 
146 146
 void setExtruderAutoFanState(int pin, bool state);
147 147
 void checkExtruderAutoFans();

+ 49
- 20
Marlin/ultralcd.cpp Vedi File

@@ -1067,6 +1067,33 @@ static void lcd_control_menu() {
1067 1067
  *
1068 1068
  */
1069 1069
 
1070
+#if ENABLED(PIDTEMP) || ENABLED(PIDTEMPBED)
1071
+
1072
+  #if ENABLED(PIDTEMP)
1073
+    int autotune_temp[EXTRUDERS] = { 150 };
1074
+    const int heater_maxtemp[EXTRUDERS] = ARRAY_BY_EXTRUDERS(HEATER_0_MAXTEMP, HEATER_1_MAXTEMP, HEATER_2_MAXTEMP, HEATER_3_MAXTEMP);
1075
+  #endif
1076
+
1077
+  #if ENABLED(PIDTEMPBED)
1078
+    int autotune_temp_bed = 70;
1079
+  #endif
1080
+
1081
+  static void _lcd_autotune(int e) {
1082
+    char cmd[30];
1083
+    sprintf_P(cmd, PSTR("M303 U1 E%d S%d"), e,
1084
+      #if ENABLED(PIDTEMP) && ENABLED(PIDTEMPBED)
1085
+        e < 0 ? autotune_temp_bed : autotune_temp[e]
1086
+      #elif ENABLED(PIDTEMPBED)
1087
+        autotune_temp_bed
1088
+      #else
1089
+        autotune_temp[e]
1090
+      #endif
1091
+    );
1092
+    enqueue_and_echo_command_now(cmd);
1093
+  }
1094
+
1095
+#endif PIDTEMP || PIDTEMPBED
1096
+
1070 1097
 #if ENABLED(PIDTEMP)
1071 1098
 
1072 1099
   // Helpers for editing PID Ki & Kd values
@@ -1079,18 +1106,19 @@ static void lcd_control_menu() {
1079 1106
     PID_PARAM(Kd, e) = scalePID_d(raw_Kd);
1080 1107
     updatePID();
1081 1108
   }
1082
-  #define COPY_AND_SCALE(eindex) \
1109
+  #define _PIDTEMP_FUNCTIONS(eindex) \
1083 1110
     void copy_and_scalePID_i_E ## eindex() { copy_and_scalePID_i(eindex); } \
1084
-    void copy_and_scalePID_d_E ## eindex() { copy_and_scalePID_d(eindex); }
1111
+    void copy_and_scalePID_d_E ## eindex() { copy_and_scalePID_d(eindex); } \
1112
+    void lcd_autotune_callback_E ## eindex() { _lcd_autotune(eindex); }
1085 1113
 
1086
-  COPY_AND_SCALE(0);
1114
+  _PIDTEMP_FUNCTIONS(0);
1087 1115
   #if ENABLED(PID_PARAMS_PER_EXTRUDER)
1088 1116
     #if EXTRUDERS > 1
1089
-      COPY_AND_SCALE(1);
1117
+      _PIDTEMP_FUNCTIONS(1);
1090 1118
       #if EXTRUDERS > 2
1091
-        COPY_AND_SCALE(2);
1119
+        _PIDTEMP_FUNCTIONS(2);
1092 1120
         #if EXTRUDERS > 3
1093
-          COPY_AND_SCALE(3);
1121
+          _PIDTEMP_FUNCTIONS(3);
1094 1122
         #endif //EXTRUDERS > 3
1095 1123
       #endif //EXTRUDERS > 2
1096 1124
     #endif //EXTRUDERS > 1
@@ -1184,35 +1212,36 @@ static void lcd_control_temperature_menu() {
1184 1212
   //
1185 1213
   #if ENABLED(PIDTEMP)
1186 1214
 
1187
-    #define _PID_MENU_ITEMS(ELABEL, eindex) \
1215
+    #define _PID_BASE_MENU_ITEMS(ELABEL, eindex) \
1188 1216
       raw_Ki = unscalePID_i(PID_PARAM(Ki, eindex)); \
1189 1217
       raw_Kd = unscalePID_d(PID_PARAM(Kd, eindex)); \
1190 1218
       MENU_ITEM_EDIT(float52, MSG_PID_P ELABEL, &PID_PARAM(Kp, eindex), 1, 9990); \
1191 1219
       MENU_ITEM_EDIT_CALLBACK(float52, MSG_PID_I ELABEL, &raw_Ki, 0.01, 9990, copy_and_scalePID_i_E ## eindex); \
1192 1220
       MENU_ITEM_EDIT_CALLBACK(float52, MSG_PID_D ELABEL, &raw_Kd, 1, 9990, copy_and_scalePID_d_E ## eindex)
1193
-      
1221
+
1194 1222
     #if ENABLED(PID_ADD_EXTRUSION_RATE)
1195
-      #define PID_MENU_ITEMS(ELABEL, eindex, AUTOTUNE_CMD) \
1196
-        _PID_MENU_ITEMS(ELABEL, eindex); \
1197
-        MENU_ITEM_EDIT(float3, MSG_PID_C ELABEL, &PID_PARAM(Kc, eindex), 1, 9990); \
1198
-        MENU_ITEM(gcode, MSG_PID_AUTOTUNE ELABEL, PSTR(AUTOTUNE_CMD))
1223
+      #define _PID_MENU_ITEMS(ELABEL, eindex) \
1224
+        _PID_BASE_MENU_ITEMS(ELABEL, eindex); \
1225
+        MENU_ITEM_EDIT(float3, MSG_PID_C ELABEL, &PID_PARAM(Kc, eindex), 1, 9990)
1199 1226
     #else
1200
-      #define PID_MENU_ITEMS(ELABEL, eindex, AUTOTUNE_CMD) \
1201
-        _PID_MENU_ITEMS(ELABEL, eindex); \
1202
-        MENU_ITEM(gcode, MSG_PID_AUTOTUNE ELABEL, PSTR(AUTOTUNE_CMD))
1227
+      #define _PID_MENU_ITEMS(ELABEL, eindex) _PID_BASE_MENU_ITEMS(ELABEL, eindex)
1203 1228
     #endif
1204 1229
 
1230
+    #define PID_MENU_ITEMS(ELABEL, eindex) \
1231
+      _PID_MENU_ITEMS(ELABEL, eindex); \
1232
+      MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_PID_AUTOTUNE ELABEL, &autotune_temp[eindex], 150, heater_maxtemp[eindex] - 15, lcd_autotune_callback_E ## eindex)
1233
+
1205 1234
     #if ENABLED(PID_PARAMS_PER_EXTRUDER) && EXTRUDERS > 1
1206
-      PID_MENU_ITEMS(MSG_E1, 0, "M303 U1");
1207
-      PID_MENU_ITEMS(MSG_E2, 1, "M303 U1 E1");
1235
+      PID_MENU_ITEMS(MSG_E1, 0);
1236
+      PID_MENU_ITEMS(MSG_E2, 1);
1208 1237
       #if EXTRUDERS > 2
1209
-        PID_MENU_ITEMS(MSG_E3, 2, "M303 U1 E2");
1238
+        PID_MENU_ITEMS(MSG_E3, 2);
1210 1239
         #if EXTRUDERS > 3
1211
-          PID_MENU_ITEMS(MSG_E4, 3, "M303 U1 E3");
1240
+          PID_MENU_ITEMS(MSG_E4, 3);
1212 1241
         #endif //EXTRUDERS > 3
1213 1242
       #endif //EXTRUDERS > 2
1214 1243
     #else //!PID_PARAMS_PER_EXTRUDER || EXTRUDERS == 1
1215
-      PID_MENU_ITEMS("", 0, "M303 U1");
1244
+      PID_MENU_ITEMS("", 0);
1216 1245
     #endif //!PID_PARAMS_PER_EXTRUDER || EXTRUDERS == 1
1217 1246
 
1218 1247
   #endif //PIDTEMP

Loading…
Annulla
Salva