浏览代码

Make Autotune options into Menu Edit Items

Scott Lahteine 9 年前
父节点
当前提交
04fa9d4f47
共有 6 个文件被更改,包括 68 次插入28 次删除
  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 查看文件

228
 inline bool IsStopped() { return !Running; }
228
 inline bool IsStopped() { return !Running; }
229
 
229
 
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
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
 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
 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
 void prepare_arc_move(char isclockwise);
234
 void prepare_arc_move(char isclockwise);

+ 13
- 4
Marlin/Marlin_main.cpp 查看文件

549
   return true;
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
  * Enqueue with Serial Echo
557
  * Enqueue with Serial Echo
554
  */
558
  */
5135
 
5139
 
5136
 /**
5140
 /**
5137
  * M303: PID relay autotune
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
  *       C<cycles>
5145
  *       C<cycles>
5146
+ *       U<bool> with a non-zero value will apply the result to current settings
5141
  */
5147
  */
5142
 inline void gcode_M303() {
5148
 inline void gcode_M303() {
5143
   int e = code_seen('E') ? code_value_short() : 0;
5149
   int e = code_seen('E') ? code_value_short() : 0;
5146
   
5152
   
5147
   float temp = code_seen('S') ? code_value() : (e < 0 ? 70.0 : 150.0);
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
     target_extruder = e;
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
   PID_autotune(temp, e, c, u);
5160
   PID_autotune(temp, e, c, u);
5161
+
5162
+  KEEPALIVE_STATE(IN_HANDLER);
5154
 }
5163
 }
5155
 
5164
 
5156
 #if ENABLED(SCARA)
5165
 #if ENABLED(SCARA)

+ 1
- 1
Marlin/cardreader.cpp 查看文件

247
   char cmd[4 + (FILENAME_LENGTH + 1) * MAX_DIR_DEPTH + 2]; // Room for "M23 ", names with slashes, a null, and one extra
247
   char cmd[4 + (FILENAME_LENGTH + 1) * MAX_DIR_DEPTH + 2]; // Room for "M23 ", names with slashes, a null, and one extra
248
   sprintf_P(cmd, PSTR("M23 %s"), name);
248
   sprintf_P(cmd, PSTR("M23 %s"), name);
249
   for (char *c = &cmd[4]; *c; c++) *c = tolower(*c);
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
   enqueue_and_echo_commands_P(PSTR("M24"));
251
   enqueue_and_echo_commands_P(PSTR("M24"));
252
 }
252
 }
253
 
253
 

+ 3
- 2
Marlin/temperature.cpp 查看文件

199
 //================================ Functions ================================
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
   float input = 0.0;
203
   float input = 0.0;
204
   int cycles = 0;
204
   int cycles = 0;
205
   bool heating = true;
205
   bool heating = true;
346
       SERIAL_PROTOCOLPGM("#define  DEFAULT_"); SERIAL_PROTOCOL(estring); SERIAL_PROTOCOLPGM("Kp "); SERIAL_PROTOCOLLN(Kp);
346
       SERIAL_PROTOCOLPGM("#define  DEFAULT_"); SERIAL_PROTOCOL(estring); SERIAL_PROTOCOLPGM("Kp "); SERIAL_PROTOCOLLN(Kp);
347
       SERIAL_PROTOCOLPGM("#define  DEFAULT_"); SERIAL_PROTOCOL(estring); SERIAL_PROTOCOLPGM("Ki "); SERIAL_PROTOCOLLN(Ki);
347
       SERIAL_PROTOCOLPGM("#define  DEFAULT_"); SERIAL_PROTOCOL(estring); SERIAL_PROTOCOLPGM("Ki "); SERIAL_PROTOCOLLN(Ki);
348
       SERIAL_PROTOCOLPGM("#define  DEFAULT_"); SERIAL_PROTOCOL(estring); SERIAL_PROTOCOLPGM("Kd "); SERIAL_PROTOCOLLN(Kd);
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
       if (set_result) {
351
       if (set_result) {
351
         if (extruder < 0) {
352
         if (extruder < 0) {
352
           #if ENABLED(PIDTEMPBED)
353
           #if ENABLED(PIDTEMPBED)

+ 1
- 1
Marlin/temperature.h 查看文件

141
 void disable_all_heaters();
141
 void disable_all_heaters();
142
 void updatePID();
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
 void setExtruderAutoFanState(int pin, bool state);
146
 void setExtruderAutoFanState(int pin, bool state);
147
 void checkExtruderAutoFans();
147
 void checkExtruderAutoFans();

+ 49
- 20
Marlin/ultralcd.cpp 查看文件

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
 #if ENABLED(PIDTEMP)
1097
 #if ENABLED(PIDTEMP)
1071
 
1098
 
1072
   // Helpers for editing PID Ki & Kd values
1099
   // Helpers for editing PID Ki & Kd values
1079
     PID_PARAM(Kd, e) = scalePID_d(raw_Kd);
1106
     PID_PARAM(Kd, e) = scalePID_d(raw_Kd);
1080
     updatePID();
1107
     updatePID();
1081
   }
1108
   }
1082
-  #define COPY_AND_SCALE(eindex) \
1109
+  #define _PIDTEMP_FUNCTIONS(eindex) \
1083
     void copy_and_scalePID_i_E ## eindex() { copy_and_scalePID_i(eindex); } \
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
   #if ENABLED(PID_PARAMS_PER_EXTRUDER)
1115
   #if ENABLED(PID_PARAMS_PER_EXTRUDER)
1088
     #if EXTRUDERS > 1
1116
     #if EXTRUDERS > 1
1089
-      COPY_AND_SCALE(1);
1117
+      _PIDTEMP_FUNCTIONS(1);
1090
       #if EXTRUDERS > 2
1118
       #if EXTRUDERS > 2
1091
-        COPY_AND_SCALE(2);
1119
+        _PIDTEMP_FUNCTIONS(2);
1092
         #if EXTRUDERS > 3
1120
         #if EXTRUDERS > 3
1093
-          COPY_AND_SCALE(3);
1121
+          _PIDTEMP_FUNCTIONS(3);
1094
         #endif //EXTRUDERS > 3
1122
         #endif //EXTRUDERS > 3
1095
       #endif //EXTRUDERS > 2
1123
       #endif //EXTRUDERS > 2
1096
     #endif //EXTRUDERS > 1
1124
     #endif //EXTRUDERS > 1
1184
   //
1212
   //
1185
   #if ENABLED(PIDTEMP)
1213
   #if ENABLED(PIDTEMP)
1186
 
1214
 
1187
-    #define _PID_MENU_ITEMS(ELABEL, eindex) \
1215
+    #define _PID_BASE_MENU_ITEMS(ELABEL, eindex) \
1188
       raw_Ki = unscalePID_i(PID_PARAM(Ki, eindex)); \
1216
       raw_Ki = unscalePID_i(PID_PARAM(Ki, eindex)); \
1189
       raw_Kd = unscalePID_d(PID_PARAM(Kd, eindex)); \
1217
       raw_Kd = unscalePID_d(PID_PARAM(Kd, eindex)); \
1190
       MENU_ITEM_EDIT(float52, MSG_PID_P ELABEL, &PID_PARAM(Kp, eindex), 1, 9990); \
1218
       MENU_ITEM_EDIT(float52, MSG_PID_P ELABEL, &PID_PARAM(Kp, eindex), 1, 9990); \
1191
       MENU_ITEM_EDIT_CALLBACK(float52, MSG_PID_I ELABEL, &raw_Ki, 0.01, 9990, copy_and_scalePID_i_E ## eindex); \
1219
       MENU_ITEM_EDIT_CALLBACK(float52, MSG_PID_I ELABEL, &raw_Ki, 0.01, 9990, copy_and_scalePID_i_E ## eindex); \
1192
       MENU_ITEM_EDIT_CALLBACK(float52, MSG_PID_D ELABEL, &raw_Kd, 1, 9990, copy_and_scalePID_d_E ## eindex)
1220
       MENU_ITEM_EDIT_CALLBACK(float52, MSG_PID_D ELABEL, &raw_Kd, 1, 9990, copy_and_scalePID_d_E ## eindex)
1193
-      
1221
+
1194
     #if ENABLED(PID_ADD_EXTRUSION_RATE)
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
     #else
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
     #endif
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
     #if ENABLED(PID_PARAMS_PER_EXTRUDER) && EXTRUDERS > 1
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
       #if EXTRUDERS > 2
1237
       #if EXTRUDERS > 2
1209
-        PID_MENU_ITEMS(MSG_E3, 2, "M303 U1 E2");
1238
+        PID_MENU_ITEMS(MSG_E3, 2);
1210
         #if EXTRUDERS > 3
1239
         #if EXTRUDERS > 3
1211
-          PID_MENU_ITEMS(MSG_E4, 3, "M303 U1 E3");
1240
+          PID_MENU_ITEMS(MSG_E4, 3);
1212
         #endif //EXTRUDERS > 3
1241
         #endif //EXTRUDERS > 3
1213
       #endif //EXTRUDERS > 2
1242
       #endif //EXTRUDERS > 2
1214
     #else //!PID_PARAMS_PER_EXTRUDER || EXTRUDERS == 1
1243
     #else //!PID_PARAMS_PER_EXTRUDER || EXTRUDERS == 1
1215
-      PID_MENU_ITEMS("", 0, "M303 U1");
1244
+      PID_MENU_ITEMS("", 0);
1216
     #endif //!PID_PARAMS_PER_EXTRUDER || EXTRUDERS == 1
1245
     #endif //!PID_PARAMS_PER_EXTRUDER || EXTRUDERS == 1
1217
 
1246
 
1218
   #endif //PIDTEMP
1247
   #endif //PIDTEMP

正在加载...
取消
保存