Преглед изворни кода

Merge pull request #3202 from thinkyhead/rc_menu_item_M303_redo

Add Menu Items to initiate M303
Scott Lahteine пре 9 година
родитељ
комит
02f466e633
6 измењених фајлова са 85 додато и 23 уклоњено
  1. 1
    0
      Marlin/Marlin.h
  2. 16
    5
      Marlin/Marlin_main.cpp
  3. 1
    1
      Marlin/cardreader.cpp
  4. 19
    1
      Marlin/temperature.cpp
  5. 1
    1
      Marlin/temperature.h
  6. 47
    15
      Marlin/ultralcd.cpp

+ 1
- 0
Marlin/Marlin.h Прегледај датотеку

@@ -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);

+ 16
- 5
Marlin/Marlin_main.cpp Прегледај датотеку

@@ -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,20 +5139,27 @@ 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;
5144 5150
   int c = code_seen('C') ? code_value_short() : 5;
5151
+  bool u = code_seen('U') && code_value_short() != 0;
5152
+  
5145 5153
   float temp = code_seen('S') ? code_value() : (e < 0 ? 70.0 : 150.0);
5146 5154
 
5147
-  if (e >=0 && e < EXTRUDERS)
5155
+  if (e >= 0 && e < EXTRUDERS)
5148 5156
     target_extruder = e;
5149 5157
 
5150
-  KEEPALIVE_STATE(NOT_BUSY);
5151
-  PID_autotune(temp, e, c);
5158
+  KEEPALIVE_STATE(NOT_BUSY); // don't send "busy: processing" messages during autotune output
5159
+
5160
+  PID_autotune(temp, e, c, u);
5161
+
5162
+  KEEPALIVE_STATE(IN_HANDLER);
5152 5163
 }
5153 5164
 
5154 5165
 #if ENABLED(SCARA)

+ 1
- 1
Marlin/cardreader.cpp Прегледај датотеку

@@ -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
 

+ 19
- 1
Marlin/temperature.cpp Прегледај датотеку

@@ -199,7 +199,7 @@ static void updateTemperaturesFromRawValues();
199 199
 //================================ Functions ================================
200 200
 //===========================================================================
201 201
 
202
-void PID_autotune(float temp, int extruder, int ncycles) {
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,6 +346,24 @@ void PID_autotune(float temp, int extruder, int ncycles) {
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
+
350
+      // Use the result? (As with "M303 U1")
351
+      if (set_result) {
352
+        if (extruder < 0) {
353
+          #if ENABLED(PIDTEMPBED)
354
+            bedKp = Kp;
355
+            bedKi = scalePID_i(Ki);
356
+            bedKd = scalePID_d(Kd);
357
+            updatePID();
358
+          #endif
359
+        }
360
+        else {
361
+          PID_PARAM(Kp, extruder) = Kp;
362
+          PID_PARAM(Ki, e) = scalePID_i(Ki);
363
+          PID_PARAM(Kd, e) = scalePID_d(Kd);
364
+          updatePID();
365
+        }
366
+      }
349 367
       return;
350 368
     }
351 369
     lcd_update();

+ 1
- 1
Marlin/temperature.h Прегледај датотеку

@@ -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);
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();

+ 47
- 15
Marlin/ultralcd.cpp Прегледај датотеку

@@ -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
@@ -1176,15 +1204,15 @@ static void lcd_control_temperature_menu() {
1176 1204
   #endif
1177 1205
 
1178 1206
   //
1179
-  // PID-P, PID-I, PID-D, PID-C
1180
-  // PID-P E1, PID-I E1, PID-D E1, PID-C E1
1181
-  // PID-P E2, PID-I E2, PID-D E2, PID-C E2
1182
-  // PID-P E3, PID-I E3, PID-D E3, PID-C E3
1183
-  // PID-P E4, PID-I E4, PID-D E4, PID-C E4
1207
+  // PID-P, PID-I, PID-D, PID-C, PID Autotune
1208
+  // PID-P E1, PID-I E1, PID-D E1, PID-C E1, PID Autotune E1
1209
+  // PID-P E2, PID-I E2, PID-D E2, PID-C E2, PID Autotune E2
1210
+  // PID-P E3, PID-I E3, PID-D E3, PID-C E3, PID Autotune E3
1211
+  // PID-P E4, PID-I E4, PID-D E4, PID-C E4, PID Autotune E4
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); \
@@ -1192,13 +1220,17 @@ static void lcd_control_temperature_menu() {
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) \
1196
-        _PID_MENU_ITEMS(ELABEL, eindex); \
1223
+      #define _PID_MENU_ITEMS(ELABEL, eindex) \
1224
+        _PID_BASE_MENU_ITEMS(ELABEL, eindex); \
1197 1225
         MENU_ITEM_EDIT(float3, MSG_PID_C ELABEL, &PID_PARAM(Kc, eindex), 1, 9990)
1198 1226
     #else
1199
-      #define PID_MENU_ITEMS(ELABEL, eindex) _PID_MENU_ITEMS(ELABEL, eindex)
1227
+      #define _PID_MENU_ITEMS(ELABEL, eindex) _PID_BASE_MENU_ITEMS(ELABEL, eindex)
1200 1228
     #endif
1201 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
+
1202 1234
     #if ENABLED(PID_PARAMS_PER_EXTRUDER) && EXTRUDERS > 1
1203 1235
       PID_MENU_ITEMS(MSG_E1, 0);
1204 1236
       PID_MENU_ITEMS(MSG_E2, 1);

Loading…
Откажи
Сачувај