Browse Source

Allow Edit menu to call fn after edit; Fix PID Ki and Kd display in menus; Actually use changed PID and Max Accel values

Add new 'callback' edit-menu types that call a function after the edit is done. Use this to display and edit Ki and Kd correctly (removing the scaling first and reapplying it after). Also use it to reset maximum stepwise acceleration rates, after updating mm/s^2 rates via menus. (Previously, changes did nothing to affect planner unless saved back to EEPROM, and the machine reset).

Add calls to updatePID() so that PID loop uses updated values whether set by gcode (it already did this), or by restoring defaults, or loading from EEPROM (it didn't do those last two). Similarly, update the maximum step/s^2 accel rates when the mm/s^2 values are changed - whether by menu edits, restore defaults, or EEPROM read.

Refactor the acceleration rate update logic, and the PID scaling logic, into new functions that can be called from wherever, including the callbacks.

Add menu items to allow the z jerk and e jerk to be viewed/edited in the Control->Motion menu, as per xy jerk.

Conflicts:
	Marlin/language.h
Simon Oliver 11 years ago
parent
commit
93f0463b21

+ 61
- 44
Marlin/ConfigurationStore.cpp View File

@@ -3,26 +3,26 @@
3 3
 #include "temperature.h"
4 4
 #include "ultralcd.h"
5 5
 #include "ConfigurationStore.h"
6
-
7
-void _EEPROM_writeData(int &pos, uint8_t* value, uint8_t size)
8
-{
9
-    do
10
-    {
11
-        eeprom_write_byte((unsigned char*)pos, *value);
12
-        pos++;
13
-        value++;
6
+
7
+void _EEPROM_writeData(int &pos, uint8_t* value, uint8_t size)
8
+{
9
+    do
10
+    {
11
+        eeprom_write_byte((unsigned char*)pos, *value);
12
+        pos++;
13
+        value++;
14 14
     }while(--size);
15
-}
15
+}
16 16
 #define EEPROM_WRITE_VAR(pos, value) _EEPROM_writeData(pos, (uint8_t*)&value, sizeof(value))
17
-void _EEPROM_readData(int &pos, uint8_t* value, uint8_t size)
18
-{
19
-    do
20
-    {
21
-        *value = eeprom_read_byte((unsigned char*)pos);
22
-        pos++;
23
-        value++;
17
+void _EEPROM_readData(int &pos, uint8_t* value, uint8_t size)
18
+{
19
+    do
20
+    {
21
+        *value = eeprom_read_byte((unsigned char*)pos);
22
+        pos++;
23
+        value++;
24 24
     }while(--size);
25
-}
25
+}
26 26
 #define EEPROM_READ_VAR(pos, value) _EEPROM_readData(pos, (uint8_t*)&value, sizeof(value))
27 27
 //======================================================================================
28 28
 
@@ -43,7 +43,7 @@ void _EEPROM_readData(int &pos, uint8_t* value, uint8_t size)
43 43
 void Config_StoreSettings() 
44 44
 {
45 45
   char ver[4]= "000";
46
-  int i=EEPROM_OFFSET;
46
+  int i=EEPROM_OFFSET;
47 47
   EEPROM_WRITE_VAR(i,ver); // invalidate data first 
48 48
   EEPROM_WRITE_VAR(i,axis_steps_per_unit);  
49 49
   EEPROM_WRITE_VAR(i,max_feedrate);  
@@ -58,8 +58,8 @@ void Config_StoreSettings()
58 58
   EEPROM_WRITE_VAR(i,max_e_jerk);
59 59
   EEPROM_WRITE_VAR(i,add_homeing);
60 60
   #ifndef ULTIPANEL
61
-  int plaPreheatHotendTemp = PLA_PREHEAT_HOTEND_TEMP, plaPreheatHPBTemp = PLA_PREHEAT_HPB_TEMP, plaPreheatFanSpeed = PLA_PREHEAT_FAN_SPEED;
62
-  int absPreheatHotendTemp = ABS_PREHEAT_HOTEND_TEMP, absPreheatHPBTemp = ABS_PREHEAT_HPB_TEMP, absPreheatFanSpeed = ABS_PREHEAT_FAN_SPEED;
61
+  int plaPreheatHotendTemp = PLA_PREHEAT_HOTEND_TEMP, plaPreheatHPBTemp = PLA_PREHEAT_HPB_TEMP, plaPreheatFanSpeed = PLA_PREHEAT_FAN_SPEED;
62
+  int absPreheatHotendTemp = ABS_PREHEAT_HOTEND_TEMP, absPreheatHPBTemp = ABS_PREHEAT_HPB_TEMP, absPreheatFanSpeed = ABS_PREHEAT_FAN_SPEED;
63 63
   #endif
64 64
   EEPROM_WRITE_VAR(i,plaPreheatHotendTemp);
65 65
   EEPROM_WRITE_VAR(i,plaPreheatHPBTemp);
@@ -75,7 +75,7 @@ void Config_StoreSettings()
75 75
     EEPROM_WRITE_VAR(i,3000);
76 76
     EEPROM_WRITE_VAR(i,0);
77 77
     EEPROM_WRITE_VAR(i,0);
78
-  #endif
78
+  #endif
79 79
   char ver2[4]=EEPROM_VERSION;
80 80
   i=EEPROM_OFFSET;
81 81
   EEPROM_WRITE_VAR(i,ver2); // validate data
@@ -105,7 +105,7 @@ void Config_PrintSettings()
105 105
     SERIAL_ECHOPAIR(" Z", max_feedrate[2] ); 
106 106
     SERIAL_ECHOPAIR(" E", max_feedrate[3]);
107 107
     SERIAL_ECHOLN("");
108
-
108
+
109 109
     SERIAL_ECHO_START;
110 110
     SERIAL_ECHOLNPGM("Maximum Acceleration (mm/s2):");
111 111
     SERIAL_ECHO_START;
@@ -120,9 +120,9 @@ void Config_PrintSettings()
120 120
     SERIAL_ECHOPAIR("  M204 S",acceleration ); 
121 121
     SERIAL_ECHOPAIR(" T" ,retract_acceleration);
122 122
     SERIAL_ECHOLN("");
123
-
123
+
124 124
     SERIAL_ECHO_START;
125
-    SERIAL_ECHOLNPGM("Advanced variables: S=Min feedrate (mm/s), T=Min travel feedrate (mm/s), B=minimum segment time (ms), X=maximum xY jerk (mm/s),  Z=maximum Z jerk (mm/s)");
125
+    SERIAL_ECHOLNPGM("Advanced variables: S=Min feedrate (mm/s), T=Min travel feedrate (mm/s), B=minimum segment time (ms), X=maximum XY jerk (mm/s),  Z=maximum Z jerk (mm/s),  E=maximum E jerk (mm/s)");
126 126
     SERIAL_ECHO_START;
127 127
     SERIAL_ECHOPAIR("  M205 S",minimumfeedrate ); 
128 128
     SERIAL_ECHOPAIR(" T" ,mintravelfeedrate ); 
@@ -131,7 +131,7 @@ void Config_PrintSettings()
131 131
     SERIAL_ECHOPAIR(" Z" ,max_z_jerk);
132 132
     SERIAL_ECHOPAIR(" E" ,max_e_jerk);
133 133
     SERIAL_ECHOLN(""); 
134
-
134
+
135 135
     SERIAL_ECHO_START;
136 136
     SERIAL_ECHOLNPGM("Home offset (mm):");
137 137
     SERIAL_ECHO_START;
@@ -144,8 +144,8 @@ void Config_PrintSettings()
144 144
     SERIAL_ECHOLNPGM("PID settings:");
145 145
     SERIAL_ECHO_START;
146 146
     SERIAL_ECHOPAIR("   M301 P",Kp); 
147
-    SERIAL_ECHOPAIR(" I" ,Ki/PID_dT); 
148
-    SERIAL_ECHOPAIR(" D" ,Kd*PID_dT);
147
+    SERIAL_ECHOPAIR(" I" ,unscalePID_i(Ki)); 
148
+    SERIAL_ECHOPAIR(" D" ,unscalePID_d(Kd));
149 149
     SERIAL_ECHOLN(""); 
150 150
 #endif
151 151
 } 
@@ -161,11 +161,15 @@ void Config_RetrieveSettings()
161 161
     EEPROM_READ_VAR(i,stored_ver); //read stored version
162 162
     //  SERIAL_ECHOLN("Version: [" << ver << "] Stored version: [" << stored_ver << "]");
163 163
     if (strncmp(ver,stored_ver,3) == 0)
164
-    {
164
+    {
165 165
         // version number match
166 166
         EEPROM_READ_VAR(i,axis_steps_per_unit);  
167 167
         EEPROM_READ_VAR(i,max_feedrate);  
168 168
         EEPROM_READ_VAR(i,max_acceleration_units_per_sq_second);
169
+        
170
+        // steps per sq second need to be updated to agree with the units per sq second (as they are what is used in the planner)
171
+		reset_acceleration_rates();
172
+        
169 173
         EEPROM_READ_VAR(i,acceleration);
170 174
         EEPROM_READ_VAR(i,retract_acceleration);
171 175
         EEPROM_READ_VAR(i,minimumfeedrate);
@@ -176,36 +180,37 @@ void Config_RetrieveSettings()
176 180
         EEPROM_READ_VAR(i,max_e_jerk);
177 181
         EEPROM_READ_VAR(i,add_homeing);
178 182
         #ifndef ULTIPANEL
179
-        int plaPreheatHotendTemp, plaPreheatHPBTemp, plaPreheatFanSpeed;
180
-        int absPreheatHotendTemp, absPreheatHPBTemp, absPreheatFanSpeed;
183
+        int plaPreheatHotendTemp, plaPreheatHPBTemp, plaPreheatFanSpeed;
184
+        int absPreheatHotendTemp, absPreheatHPBTemp, absPreheatFanSpeed;
181 185
         #endif
182 186
         EEPROM_READ_VAR(i,plaPreheatHotendTemp);
183 187
         EEPROM_READ_VAR(i,plaPreheatHPBTemp);
184 188
         EEPROM_READ_VAR(i,plaPreheatFanSpeed);
185 189
         EEPROM_READ_VAR(i,absPreheatHotendTemp);
186 190
         EEPROM_READ_VAR(i,absPreheatHPBTemp);
187
-        EEPROM_READ_VAR(i,absPreheatFanSpeed);
191
+        EEPROM_READ_VAR(i,absPreheatFanSpeed);
188 192
         #ifndef PIDTEMP
189 193
         float Kp,Ki,Kd;
190 194
         #endif
195
+        // do not need to scale PID values as the values in EEPROM are already scaled		
191 196
         EEPROM_READ_VAR(i,Kp);
192 197
         EEPROM_READ_VAR(i,Ki);
193 198
         EEPROM_READ_VAR(i,Kd);
194 199
 
200
+		// Call updatePID (similar to when we have processed M301)
201
+		updatePID();
195 202
         SERIAL_ECHO_START;
196
-        SERIAL_ECHOLNPGM("Stored settings retreived:");
203
+        SERIAL_ECHOLNPGM("Stored settings retrieved");
204
+    }
205
+    else
206
+    {
207
+        Config_ResetDefault();
197 208
     }
198
-    else
199
-    {
200
-        Config_ResetDefault();
201
-        SERIAL_ECHO_START;
202
-        SERIAL_ECHOLN("Using Default settings:");
203
-    }
204 209
     Config_PrintSettings();
205 210
 }
206
-#endif
207
-
208
-void Config_ResetDefault()
211
+#endif
212
+
213
+void Config_ResetDefault()
209 214
 {
210 215
     float tmp1[]=DEFAULT_AXIS_STEPS_PER_UNIT;
211 216
     float tmp2[]=DEFAULT_MAX_FEEDRATE;
@@ -216,6 +221,10 @@ void Config_ResetDefault()
216 221
         max_feedrate[i]=tmp2[i];  
217 222
         max_acceleration_units_per_sq_second[i]=tmp3[i];
218 223
     }
224
+    
225
+    // steps per sq second need to be updated to agree with the units per sq second
226
+    reset_acceleration_rates();
227
+    
219 228
     acceleration=DEFAULT_ACCELERATION;
220 229
     retract_acceleration=DEFAULT_RETRACT_ACCELERATION;
221 230
     minimumfeedrate=DEFAULT_MINIMUMFEEDRATE;
@@ -234,11 +243,19 @@ void Config_ResetDefault()
234 243
     absPreheatFanSpeed = ABS_PREHEAT_FAN_SPEED;
235 244
 #endif
236 245
 #ifdef PIDTEMP
237
-    Kp = DEFAULT_Kp;
238
-    Ki = (DEFAULT_Ki*PID_dT);
239
-    Kd = (DEFAULT_Kd/PID_dT);
246
+    Kp = DEFAULT_Kp;
247
+    Ki = scalePID_i(DEFAULT_Ki);
248
+    Kd = scalePID_d(DEFAULT_Kd);
249
+    
250
+    // call updatePID (similar to when we have processed M301)
251
+    updatePID();
252
+    
240 253
 #ifdef PID_ADD_EXTRUSION_RATE
241 254
     Kc = DEFAULT_Kc;
242 255
 #endif//PID_ADD_EXTRUSION_RATE
243 256
 #endif//PIDTEMP
257
+
258
+SERIAL_ECHO_START;
259
+SERIAL_ECHOLNPGM("Hardcoded Default Settings Loaded");
260
+
244 261
 }

+ 18
- 17
Marlin/Marlin_main.cpp View File

@@ -363,13 +363,8 @@ void setup()
363 363
     fromsd[i] = false;
364 364
   }
365 365
   
366
-  Config_RetrieveSettings(); // loads data from EEPROM if available
367
-
368
-  for(int8_t i=0; i < NUM_AXIS; i++)
369
-  {
370
-    axis_steps_per_sqr_second[i] = max_acceleration_units_per_sq_second[i] * axis_steps_per_unit[i];
371
-  }
372
-
366
+  // loads data from EEPROM if available else uses defaults (and resets step acceleration rate)
367
+  Config_RetrieveSettings(); 
373 368
 
374 369
   tp_init();    // Initialize temperature loop 
375 370
   plan_init();  // Initialize planner;
@@ -1323,9 +1318,10 @@ void process_commands()
1323 1318
         if(code_seen(axis_codes[i]))
1324 1319
         {
1325 1320
           max_acceleration_units_per_sq_second[i] = code_value();
1326
-          axis_steps_per_sqr_second[i] = code_value() * axis_steps_per_unit[i];
1327 1321
         }
1328 1322
       }
1323
+      // steps per sq second need to be updated to agree with the units per sq second (as they are what is used in the planner)
1324
+	  reset_acceleration_rates();
1329 1325
       break;
1330 1326
     #if 0 // Not used for Sprinter/grbl gen6
1331 1327
     case 202: // M202
@@ -1468,22 +1464,25 @@ void process_commands()
1468 1464
     case 301: // M301
1469 1465
       {
1470 1466
         if(code_seen('P')) Kp = code_value();
1471
-        if(code_seen('I')) Ki = code_value()*PID_dT;
1472
-        if(code_seen('D')) Kd = code_value()/PID_dT;
1467
+        if(code_seen('I')) Ki = scalePID_i(code_value());
1468
+        if(code_seen('D')) Kd = scalePID_d(code_value());
1469
+
1473 1470
         #ifdef PID_ADD_EXTRUSION_RATE
1474 1471
         if(code_seen('C')) Kc = code_value();
1475 1472
         #endif
1473
+        
1476 1474
         updatePID();
1477 1475
         SERIAL_PROTOCOL(MSG_OK);
1478 1476
 		SERIAL_PROTOCOL(" p:");
1479 1477
         SERIAL_PROTOCOL(Kp);
1480 1478
         SERIAL_PROTOCOL(" i:");
1481
-        SERIAL_PROTOCOL(Ki/PID_dT);
1479
+        SERIAL_PROTOCOL(unscalePID_i(Ki));
1482 1480
         SERIAL_PROTOCOL(" d:");
1483
-        SERIAL_PROTOCOL(Kd*PID_dT);
1481
+        SERIAL_PROTOCOL(unscalePID_d(Kd));
1484 1482
         #ifdef PID_ADD_EXTRUSION_RATE
1485 1483
         SERIAL_PROTOCOL(" c:");
1486
-        SERIAL_PROTOCOL(Kc*PID_dT);
1484
+        //Kc does not have scaling applied above, or in resetting defaults
1485
+        SERIAL_PROTOCOL(Kc);
1487 1486
         #endif
1488 1487
         SERIAL_PROTOCOLLN("");
1489 1488
       }
@@ -1493,16 +1492,18 @@ void process_commands()
1493 1492
     case 304: // M304
1494 1493
       {
1495 1494
         if(code_seen('P')) bedKp = code_value();
1496
-        if(code_seen('I')) bedKi = code_value()*PID_dT;
1497
-        if(code_seen('D')) bedKd = code_value()/PID_dT;
1495
+        if(code_seen('I')) bedKi = scalePID_i(code_value());
1496
+        if(code_seen('D')) bedKd = scalePID_d(code_value());
1497
+        // Scale the Bed PID values by PID_dT
1498
+        scaleBedPID();
1498 1499
         updatePID();
1499 1500
         SERIAL_PROTOCOL(MSG_OK);
1500 1501
 		SERIAL_PROTOCOL(" p:");
1501 1502
         SERIAL_PROTOCOL(bedKp);
1502 1503
         SERIAL_PROTOCOL(" i:");
1503
-        SERIAL_PROTOCOL(bedKi/PID_dT);
1504
+        SERIAL_PROTOCOL(unscalePID_i(bedKi));
1504 1505
         SERIAL_PROTOCOL(" d:");
1505
-        SERIAL_PROTOCOL(bedKd*PID_dT);
1506
+        SERIAL_PROTOCOL(unscalePID_d(bedKd));
1506 1507
         SERIAL_PROTOCOLLN("");
1507 1508
       }
1508 1509
       break;

+ 20
- 3
Marlin/language.h View File

@@ -75,7 +75,9 @@
75 75
 	#define MSG_PID_D "PID-D"
76 76
 	#define MSG_PID_C "PID-C"
77 77
 	#define MSG_ACC  "Accel"
78
-	#define MSG_VXY_JERK "Vxy-jerk"
78
+	#define MSG_VXY_JERK "Vxy-jerk"
79
+	#define MSG_VZ_JERK "Vz-jerk"
80
+	#define MSG_VE_JERK "Ve-jerk"
79 81
 	#define MSG_VMAX "Vmax "
80 82
 	#define MSG_X "x"
81 83
 	#define MSG_Y "y"
@@ -233,6 +235,8 @@
233 235
 	#define MSG_PID_C "PID-C"
234 236
 	#define MSG_ACC  "Acc"
235 237
 	#define MSG_VXY_JERK "Zryw Vxy"
238
+	#define MSG_VZ_JERK "Zryw Vz"
239
+	#define MSG_VE_JERK "Zryw Ve"
236 240
 	#define MSG_VMAX "Vmax"
237 241
 	#define MSG_X "x"
238 242
 	#define MSG_Y "y"
@@ -391,7 +395,9 @@
391 395
 #define MSG_PID_D " PID-D: "
392 396
 #define MSG_PID_C " PID-C: "
393 397
 #define MSG_ACC " Acc:"
394
-#define MSG_VXY_JERK " Vxy-jerk: "
398
+#define MSG_VXY_JERK "Vxy-jerk"
399
+#define MSG_VZ_JERK "Vz-jerk"
400
+#define MSG_VE_JERK "Ve-jerk"
395 401
 #define MSG_VMAX " Vmax "
396 402
 #define MSG_X "x:"
397 403
 #define MSG_Y "y:"
@@ -555,6 +561,8 @@
555 561
 	#define MSG_PID_C            "PID-C"
556 562
 	#define MSG_ACC              "Acc"
557 563
 	#define MSG_VXY_JERK         "Vxy-jerk"
564
+	#define MSG_VZ_JERK          "Vz-jerk"
565
+	#define MSG_VE_JERK          "Ve-jerk"
558 566
 	#define MSG_VMAX             "Vmax "
559 567
 	#define MSG_X                "x"
560 568
 	#define MSG_Y                "y"
@@ -713,6 +721,8 @@
713 721
 #define MSG_PID_C " PID-C: "
714 722
 #define MSG_ACC  " Acc:"
715 723
 #define MSG_VXY_JERK " Vxy-jerk: "
724
+#define MSG_VZ_JERK "Vz-jerk"
725
+#define MSG_VE_JERK "Ve-jerk"
716 726
 #define MSG_VMAX " Vmax "
717 727
 #define MSG_X "x:"
718 728
 #define MSG_Y "y:"
@@ -871,6 +881,8 @@
871 881
 #define MSG_PID_C							" PID-C: "
872 882
 #define MSG_ACC								" Acc:"
873 883
 #define MSG_VXY_JERK						" Vxy-jerk: "
884
+#define MSG_VZ_JERK                         "Vz-jerk"
885
+#define MSG_VE_JERK                         "Ve-jerk"
874 886
 #define MSG_VMAX							" Vmax "
875 887
 #define MSG_X								"x:"
876 888
 #define MSG_Y								"y:"
@@ -1024,6 +1036,8 @@
1024 1036
 	#define MSG_PID_C                "PID-C"
1025 1037
 	#define MSG_ACC                  "Accel"
1026 1038
 	#define MSG_VXY_JERK             "Vxy-jerk"
1039
+	#define MSG_VZ_JERK              "Vz-jerk"
1040
+	#define MSG_VE_JERK              "Ve-jerk"
1027 1041
 	#define MSG_VMAX                 "Vmax"
1028 1042
 	#define MSG_X                    "x"
1029 1043
 	#define MSG_Y                    "y"
@@ -1184,6 +1198,8 @@
1184 1198
 	#define MSG_PID_C " PID-C: "
1185 1199
 	#define MSG_ACC  " Acc:"
1186 1200
 	#define MSG_VXY_JERK " Vxy-jerk: "
1201
+	#define MSG_VZ_JERK "Vz-jerk"
1202
+	#define MSG_VE_JERK "Ve-jerk"
1187 1203
 	#define MSG_VMAX " Vmax "
1188 1204
 	#define MSG_X "x:"
1189 1205
 	#define MSG_Y "y:"
@@ -1350,6 +1366,8 @@
1350 1366
 	#define MSG_PID_C "PID-C"
1351 1367
 	#define MSG_ACC  "Kiihtyv"
1352 1368
 	#define MSG_VXY_JERK "Vxy-jerk"
1369
+	#define MSG_VZ_JERK "Vz-jerk"
1370
+	#define MSG_VE_JERK "Ve-jerk"
1353 1371
 	#define MSG_VMAX "Vmax "
1354 1372
 	#define MSG_X "x"
1355 1373
 	#define MSG_Y "y"
@@ -1465,4 +1483,3 @@
1465 1483
 
1466 1484
 #endif
1467 1485
 #endif // ifndef LANGUAGE_H
1468
-

+ 9
- 1
Marlin/planner.cpp View File

@@ -478,7 +478,7 @@ void check_axes_activity()
478 478
           tail_fan_speed = 255;
479 479
       } else {
480 480
         fan_kick_end = 0;
481
-      }
481
+      }
482 482
     #endif//FAN_KICKSTART_TIME
483 483
     analogWrite(FAN_PIN,tail_fan_speed);
484 484
   #endif//!FAN_SOFT_PWM
@@ -895,3 +895,11 @@ void allow_cold_extrudes(bool allow)
895 895
 #endif
896 896
 }
897 897
 
898
+// Calculate the steps/s^2 acceleration rates, based on the mm/s^s
899
+void reset_acceleration_rates()
900
+{
901
+	for(int8_t i=0; i < NUM_AXIS; i++)
902
+        {
903
+        axis_steps_per_sqr_second[i] = max_acceleration_units_per_sq_second[i] * axis_steps_per_unit[i];
904
+        }
905
+}

+ 2
- 0
Marlin/planner.h View File

@@ -136,4 +136,6 @@ FORCE_INLINE bool blocks_queued()
136 136
 }
137 137
 
138 138
 void allow_cold_extrudes(bool allow);
139
+
140
+void reset_acceleration_rates();
139 141
 #endif

+ 28
- 0
Marlin/temperature.cpp View File

@@ -1128,3 +1128,31 @@ ISR(TIMER0_COMPB_vect)
1128 1128
 #endif
1129 1129
   }  
1130 1130
 }
1131
+
1132
+#ifdef PIDTEMP
1133
+// Apply the scale factors to the PID values
1134
+
1135
+
1136
+float scalePID_i(float i)
1137
+{
1138
+	return i*PID_dT;
1139
+}
1140
+
1141
+float unscalePID_i(float i)
1142
+{
1143
+	return i/PID_dT;
1144
+}
1145
+
1146
+float scalePID_d(float d)
1147
+{
1148
+    return d/PID_dT;
1149
+}
1150
+
1151
+float unscalePID_d(float d)
1152
+{
1153
+	return d*PID_dT;
1154
+}
1155
+
1156
+#endif //PIDTEMP
1157
+
1158
+

+ 7
- 2
Marlin/temperature.h View File

@@ -31,8 +31,8 @@
31 31
 void tp_init();  //initialise the heating
32 32
 void manage_heater(); //it is critical that this is called periodically.
33 33
 
34
-//low leven conversion routines
35
-// do not use this routines and variables outsie of temperature.cpp
34
+// low level conversion routines
35
+// do not use these routines and variables outside of temperature.cpp
36 36
 extern int target_temperature[EXTRUDERS];  
37 37
 extern float current_temperature[EXTRUDERS];
38 38
 extern int target_temperature_bed;
@@ -40,6 +40,11 @@ extern float current_temperature_bed;
40 40
 
41 41
 #ifdef PIDTEMP
42 42
   extern float Kp,Ki,Kd,Kc;
43
+  float scalePID_i(float i);
44
+  float scalePID_d(float d);
45
+  float unscalePID_i(float i);
46
+  float unscalePID_d(float d);
47
+
43 48
 #endif
44 49
 #ifdef PIDTEMPBED
45 50
   extern float bedKp,bedKi,bedKd;

+ 78
- 7
Marlin/ultralcd.cpp View File

@@ -31,6 +31,10 @@ char lcd_status_message[LCD_WIDTH+1] = WELCOME_MSG;
31 31
 #endif
32 32
 
33 33
 /** forward declerations **/
34
+
35
+void copy_and_scalePID_i();
36
+void copy_and_scalePID_d();
37
+
34 38
 /* Different menus */
35 39
 static void lcd_status_screen();
36 40
 #ifdef ULTIPANEL
@@ -63,6 +67,14 @@ static void menu_action_setting_edit_float5(const char* pstr, float* ptr, float
63 67
 static void menu_action_setting_edit_float51(const char* pstr, float* ptr, float minValue, float maxValue);
64 68
 static void menu_action_setting_edit_float52(const char* pstr, float* ptr, float minValue, float maxValue);
65 69
 static void menu_action_setting_edit_long5(const char* pstr, unsigned long* ptr, unsigned long minValue, unsigned long maxValue);
70
+static void menu_action_setting_edit_callback_bool(const char* pstr, bool* ptr, menuFunc_t callbackFunc);
71
+static void menu_action_setting_edit_callback_int3(const char* pstr, int* ptr, int minValue, int maxValue, menuFunc_t callbackFunc);
72
+static void menu_action_setting_edit_callback_float3(const char* pstr, float* ptr, float minValue, float maxValue, menuFunc_t callbackFunc);
73
+static void menu_action_setting_edit_callback_float32(const char* pstr, float* ptr, float minValue, float maxValue, menuFunc_t callbackFunc);
74
+static void menu_action_setting_edit_callback_float5(const char* pstr, float* ptr, float minValue, float maxValue, menuFunc_t callbackFunc);
75
+static void menu_action_setting_edit_callback_float51(const char* pstr, float* ptr, float minValue, float maxValue, menuFunc_t callbackFunc);
76
+static void menu_action_setting_edit_callback_float52(const char* pstr, float* ptr, float minValue, float maxValue, menuFunc_t callbackFunc);
77
+static void menu_action_setting_edit_callback_long5(const char* pstr, unsigned long* ptr, unsigned long minValue, unsigned long maxValue, menuFunc_t callbackFunc);
66 78
 
67 79
 #define ENCODER_STEPS_PER_MENU_ITEM 5
68 80
 
@@ -93,6 +105,7 @@ static void menu_action_setting_edit_long5(const char* pstr, unsigned long* ptr,
93 105
 } while(0)
94 106
 #define MENU_ITEM_DUMMY() do { _menuItemNr++; } while(0)
95 107
 #define MENU_ITEM_EDIT(type, label, args...) MENU_ITEM(setting_edit_ ## type, label, PSTR(label) , ## args )
108
+#define MENU_ITEM_EDIT_CALLBACK(type, label, args...) MENU_ITEM(setting_edit_callback_ ## type, label, PSTR(label) , ## args )
96 109
 #define END_MENU() \
97 110
     if (encoderPosition / ENCODER_STEPS_PER_MENU_ITEM >= _menuItemNr) encoderPosition = _menuItemNr * ENCODER_STEPS_PER_MENU_ITEM - 1; \
98 111
     if ((uint8_t)(encoderPosition / ENCODER_STEPS_PER_MENU_ITEM) >= currentMenuViewOffset + LCD_HEIGHT) { currentMenuViewOffset = (encoderPosition / ENCODER_STEPS_PER_MENU_ITEM) - LCD_HEIGHT + 1; lcdDrawUpdate = 1; _lineNr = currentMenuViewOffset - 1; _drawLineNr = -1; } \
@@ -123,6 +136,10 @@ uint16_t prevEncoderPosition;
123 136
 const char* editLabel;
124 137
 void* editValue;
125 138
 int32_t minEditValue, maxEditValue;
139
+menuFunc_t callbackFunc;
140
+
141
+// placeholders for Ki and Kd edits
142
+float raw_Ki, raw_Kd;
126 143
 
127 144
 /* Main status screen. It's up to the implementation specific part to show what is needed. As this is very display dependend */
128 145
 static void lcd_status_screen()
@@ -442,6 +459,10 @@ static void lcd_control_menu()
442 459
 
443 460
 static void lcd_control_temperature_menu()
444 461
 {
462
+	// set up temp variables - undo the default scaling
463
+	raw_Ki = unscalePID_i(Ki);
464
+	raw_Kd = unscalePID_d(Kd);
465
+	
445 466
     START_MENU();
446 467
     MENU_ITEM(back, MSG_CONTROL, lcd_control_menu);
447 468
     MENU_ITEM_EDIT(int3, MSG_NOZZLE, &target_temperature[0], 0, HEATER_0_MAXTEMP - 15);
@@ -463,9 +484,9 @@ static void lcd_control_temperature_menu()
463 484
 #endif
464 485
 #ifdef PIDTEMP
465 486
     MENU_ITEM_EDIT(float52, MSG_PID_P, &Kp, 1, 9990);
466
-//TODO, I and D should have a PID_dT multiplier (Ki = PID_I * PID_dT, Kd = PID_D / PID_dT)
467
-    MENU_ITEM_EDIT(float52, MSG_PID_I, &Ki, 1, 9990);
468
-    MENU_ITEM_EDIT(float52, MSG_PID_D, &Kd, 1, 9990);
487
+	// i is typically a small value so allows values below 1
488
+    MENU_ITEM_EDIT_CALLBACK(float52, MSG_PID_I, &raw_Ki, 0.01, 9990, copy_and_scalePID_i);
489
+    MENU_ITEM_EDIT_CALLBACK(float52, MSG_PID_D, &raw_Kd, 1, 9990, copy_and_scalePID_d);
469 490
 # ifdef PID_ADD_EXTRUSION_RATE
470 491
     MENU_ITEM_EDIT(float3, MSG_PID_C, &Kc, 1, 9990);
471 492
 # endif//PID_ADD_EXTRUSION_RATE
@@ -511,16 +532,18 @@ static void lcd_control_motion_menu()
511 532
     MENU_ITEM(back, MSG_CONTROL, lcd_control_menu);
512 533
     MENU_ITEM_EDIT(float5, MSG_ACC, &acceleration, 500, 99000);
513 534
     MENU_ITEM_EDIT(float3, MSG_VXY_JERK, &max_xy_jerk, 1, 990);
535
+    MENU_ITEM_EDIT(float52, MSG_VZ_JERK, &max_z_jerk, 0.1, 990);
536
+    MENU_ITEM_EDIT(float3, MSG_VE_JERK, &max_e_jerk, 1, 990);
514 537
     MENU_ITEM_EDIT(float3, MSG_VMAX MSG_X, &max_feedrate[X_AXIS], 1, 999);
515 538
     MENU_ITEM_EDIT(float3, MSG_VMAX MSG_Y, &max_feedrate[Y_AXIS], 1, 999);
516 539
     MENU_ITEM_EDIT(float3, MSG_VMAX MSG_Z, &max_feedrate[Z_AXIS], 1, 999);
517 540
     MENU_ITEM_EDIT(float3, MSG_VMAX MSG_E, &max_feedrate[E_AXIS], 1, 999);
518 541
     MENU_ITEM_EDIT(float3, MSG_VMIN, &minimumfeedrate, 0, 999);
519 542
     MENU_ITEM_EDIT(float3, MSG_VTRAV_MIN, &mintravelfeedrate, 0, 999);
520
-    MENU_ITEM_EDIT(long5, MSG_AMAX MSG_X, &max_acceleration_units_per_sq_second[X_AXIS], 100, 99000);
521
-    MENU_ITEM_EDIT(long5, MSG_AMAX MSG_Y, &max_acceleration_units_per_sq_second[Y_AXIS], 100, 99000);
522
-    MENU_ITEM_EDIT(long5, MSG_AMAX MSG_Z, &max_acceleration_units_per_sq_second[Z_AXIS], 100, 99000);
523
-    MENU_ITEM_EDIT(long5, MSG_AMAX MSG_E, &max_acceleration_units_per_sq_second[E_AXIS], 100, 99000);
543
+    MENU_ITEM_EDIT_CALLBACK(long5, MSG_AMAX MSG_X, &max_acceleration_units_per_sq_second[X_AXIS], 100, 99000, reset_acceleration_rates);
544
+    MENU_ITEM_EDIT_CALLBACK(long5, MSG_AMAX MSG_Y, &max_acceleration_units_per_sq_second[Y_AXIS], 100, 99000, reset_acceleration_rates);
545
+    MENU_ITEM_EDIT_CALLBACK(long5, MSG_AMAX MSG_Z, &max_acceleration_units_per_sq_second[Z_AXIS], 100, 99000, reset_acceleration_rates);
546
+    MENU_ITEM_EDIT_CALLBACK(long5, MSG_AMAX MSG_E, &max_acceleration_units_per_sq_second[E_AXIS], 100, 99000, reset_acceleration_rates);
524 547
     MENU_ITEM_EDIT(float5, MSG_A_RETRACT, &retract_acceleration, 100, 99000);
525 548
     MENU_ITEM_EDIT(float52, MSG_XSTEPS, &axis_steps_per_unit[X_AXIS], 5, 9999);
526 549
     MENU_ITEM_EDIT(float52, MSG_YSTEPS, &axis_steps_per_unit[Y_AXIS], 5, 9999);
@@ -610,6 +633,23 @@ void lcd_sdcard_menu()
610 633
             encoderPosition = prevEncoderPosition; \
611 634
         } \
612 635
     } \
636
+    void menu_edit_callback_ ## _name () \
637
+    { \
638
+        if ((int32_t)encoderPosition < minEditValue) \
639
+            encoderPosition = minEditValue; \
640
+        if ((int32_t)encoderPosition > maxEditValue) \
641
+            encoderPosition = maxEditValue; \
642
+        if (lcdDrawUpdate) \
643
+            lcd_implementation_drawedit(editLabel, _strFunc(((_type)encoderPosition) / scale)); \
644
+        if (LCD_CLICKED) \
645
+        { \
646
+            *((_type*)editValue) = ((_type)encoderPosition) / scale; \
647
+            lcd_quick_feedback(); \
648
+            currentMenu = prevMenu; \
649
+            encoderPosition = prevEncoderPosition; \
650
+            (*callbackFunc)();\
651
+        } \
652
+    } \
613 653
     static void menu_action_setting_edit_ ## _name (const char* pstr, _type* ptr, _type minValue, _type maxValue) \
614 654
     { \
615 655
         prevMenu = currentMenu; \
@@ -623,6 +663,21 @@ void lcd_sdcard_menu()
623 663
         minEditValue = minValue * scale; \
624 664
         maxEditValue = maxValue * scale; \
625 665
         encoderPosition = (*ptr) * scale; \
666
+    }\
667
+    static void menu_action_setting_edit_callback_ ## _name (const char* pstr, _type* ptr, _type minValue, _type maxValue, menuFunc_t callback) \
668
+    { \
669
+        prevMenu = currentMenu; \
670
+        prevEncoderPosition = encoderPosition; \
671
+         \
672
+        lcdDrawUpdate = 2; \
673
+        currentMenu = menu_edit_callback_ ## _name; \
674
+         \
675
+        editLabel = pstr; \
676
+        editValue = ptr; \
677
+        minEditValue = minValue * scale; \
678
+        maxEditValue = maxValue * scale; \
679
+        encoderPosition = (*ptr) * scale; \
680
+        callbackFunc = callback;\
626 681
     }
627 682
 menu_edit_type(int, int3, itostr3, 1)
628 683
 menu_edit_type(float, float3, ftostr3, 1)
@@ -1070,4 +1125,20 @@ char *ftostr52(const float &x)
1070 1125
   return conv;
1071 1126
 }
1072 1127
 
1128
+// Callback for after editing PID i value
1129
+// grab the pid i value out of the temp variable; scale it; then update the PID driver
1130
+void copy_and_scalePID_i()
1131
+{
1132
+  Ki = scalePID_i(raw_Ki);
1133
+  updatePID();
1134
+}	
1135
+
1136
+// Callback for after editing PID d value
1137
+// grab the pid d value out of the temp variable; scale it; then update the PID driver
1138
+void copy_and_scalePID_d()
1139
+{
1140
+  Kd = scalePID_d(raw_Kd);
1141
+  updatePID();
1142
+}	
1143
+	
1073 1144
 #endif //ULTRA_LCD

+ 20
- 0
Marlin/ultralcd_implementation_hitachi_HD44780.h View File

@@ -376,6 +376,26 @@ static void lcd_implementation_drawmenu_setting_edit_generic_P(uint8_t row, cons
376 376
 #define lcd_implementation_drawmenu_setting_edit_long5(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, ' ', ftostr5(*(data)))
377 377
 #define lcd_implementation_drawmenu_setting_edit_bool_selected(row, pstr, pstr2, data) lcd_implementation_drawmenu_setting_edit_generic_P(row, pstr, '>', (*(data))?PSTR(MSG_ON):PSTR(MSG_OFF))
378 378
 #define lcd_implementation_drawmenu_setting_edit_bool(row, pstr, pstr2, data) lcd_implementation_drawmenu_setting_edit_generic_P(row, pstr, ' ', (*(data))?PSTR(MSG_ON):PSTR(MSG_OFF))
379
+
380
+//Add version for callback functions
381
+#define lcd_implementation_drawmenu_setting_edit_callback_int3_selected(row, pstr, pstr2, data, minValue, maxValue, callback) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, '>', itostr3(*(data)))
382
+#define lcd_implementation_drawmenu_setting_edit_callback_int3(row, pstr, pstr2, data, minValue, maxValue, callback) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, ' ', itostr3(*(data)))
383
+#define lcd_implementation_drawmenu_setting_edit_callback_float3_selected(row, pstr, pstr2, data, minValue, maxValue, callback) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, '>', ftostr3(*(data)))
384
+#define lcd_implementation_drawmenu_setting_edit_callback_float3(row, pstr, pstr2, data, minValue, maxValue, callback) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, ' ', ftostr3(*(data)))
385
+#define lcd_implementation_drawmenu_setting_edit_callback_float32_selected(row, pstr, pstr2, data, minValue, maxValue, callback) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, '>', ftostr32(*(data)))
386
+#define lcd_implementation_drawmenu_setting_edit_callback_float32(row, pstr, pstr2, data, minValue, maxValue, callback) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, ' ', ftostr32(*(data)))
387
+#define lcd_implementation_drawmenu_setting_edit_callback_float5_selected(row, pstr, pstr2, data, minValue, maxValue, callback) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, '>', ftostr5(*(data)))
388
+#define lcd_implementation_drawmenu_setting_edit_callback_float5(row, pstr, pstr2, data, minValue, maxValue, callback) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, ' ', ftostr5(*(data)))
389
+#define lcd_implementation_drawmenu_setting_edit_callback_float52_selected(row, pstr, pstr2, data, minValue, maxValue, callback) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, '>', ftostr52(*(data)))
390
+#define lcd_implementation_drawmenu_setting_edit_callback_float52(row, pstr, pstr2, data, minValue, maxValue, callback) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, ' ', ftostr52(*(data)))
391
+#define lcd_implementation_drawmenu_setting_edit_callback_float51_selected(row, pstr, pstr2, data, minValue, maxValue, callback) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, '>', ftostr51(*(data)))
392
+#define lcd_implementation_drawmenu_setting_edit_callback_float51(row, pstr, pstr2, data, minValue, maxValue, callback) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, ' ', ftostr51(*(data)))
393
+#define lcd_implementation_drawmenu_setting_edit_callback_long5_selected(row, pstr, pstr2, data, minValue, maxValue, callback) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, '>', ftostr5(*(data)))
394
+#define lcd_implementation_drawmenu_setting_edit_callback_long5(row, pstr, pstr2, data, minValue, maxValue, callback) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, ' ', ftostr5(*(data)))
395
+#define lcd_implementation_drawmenu_setting_edit_callback_bool_selected(row, pstr, pstr2, data, callback) lcd_implementation_drawmenu_setting_edit_generic_P(row, pstr, '>', (*(data))?PSTR(MSG_ON):PSTR(MSG_OFF))
396
+#define lcd_implementation_drawmenu_setting_edit_callback_bool(row, pstr, pstr2, data, callback) lcd_implementation_drawmenu_setting_edit_generic_P(row, pstr, ' ', (*(data))?PSTR(MSG_ON):PSTR(MSG_OFF))
397
+
398
+
379 399
 void lcd_implementation_drawedit(const char* pstr, char* value)
380 400
 {
381 401
     lcd.setCursor(1, 1);

Loading…
Cancel
Save