Make Autotune options into Menu Edit Items

master
Scott Lahteine 9 years ago
parent e3f583a3be
commit 04fa9d4f47

@ -228,6 +228,7 @@ inline bool IsRunning() { return Running; }
inline bool IsStopped() { return !Running; } inline bool IsStopped() { return !Running; }
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 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
void enqueue_and_echo_command_now(const char* cmd); // enqueue now, only return when the command has been enqueued
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 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
void prepare_arc_move(char isclockwise); void prepare_arc_move(char isclockwise);

@ -549,6 +549,10 @@ inline bool _enqueuecommand(const char* cmd, bool say_ok=false) {
return true; return true;
} }
void enqueue_and_echo_command_now(const char* cmd) {
while (!enqueue_and_echo_command(cmd)) idle();
}
/** /**
* Enqueue with Serial Echo * Enqueue with Serial Echo
*/ */
@ -5135,9 +5139,11 @@ inline void gcode_M226() {
/** /**
* M303: PID relay autotune * M303: PID relay autotune
* S<temperature> sets the target temperature. (default target temperature = 150C) *
* E<extruder> (-1 for the bed) * S<temperature> sets the target temperature. (default 150C)
* E<extruder> (-1 for the bed) (default 0)
* C<cycles> * C<cycles>
* U<bool> with a non-zero value will apply the result to current settings
*/ */
inline void gcode_M303() { inline void gcode_M303() {
int e = code_seen('E') ? code_value_short() : 0; int e = code_seen('E') ? code_value_short() : 0;
@ -5149,8 +5155,11 @@ inline void gcode_M303() {
if (e >= 0 && e < EXTRUDERS) if (e >= 0 && e < EXTRUDERS)
target_extruder = e; target_extruder = e;
KEEPALIVE_STATE(NOT_BUSY); KEEPALIVE_STATE(NOT_BUSY); // don't send "busy: processing" messages during autotune output
PID_autotune(temp, e, c, u); PID_autotune(temp, e, c, u);
KEEPALIVE_STATE(IN_HANDLER);
} }
#if ENABLED(SCARA) #if ENABLED(SCARA)

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

@ -346,7 +346,8 @@ void PID_autotune(float temp, int extruder, int ncycles, bool set_result /* = fa
SERIAL_PROTOCOLPGM("#define DEFAULT_"); SERIAL_PROTOCOL(estring); SERIAL_PROTOCOLPGM("Kp "); SERIAL_PROTOCOLLN(Kp); SERIAL_PROTOCOLPGM("#define DEFAULT_"); SERIAL_PROTOCOL(estring); SERIAL_PROTOCOLPGM("Kp "); SERIAL_PROTOCOLLN(Kp);
SERIAL_PROTOCOLPGM("#define DEFAULT_"); SERIAL_PROTOCOL(estring); SERIAL_PROTOCOLPGM("Ki "); SERIAL_PROTOCOLLN(Ki); SERIAL_PROTOCOLPGM("#define DEFAULT_"); SERIAL_PROTOCOL(estring); SERIAL_PROTOCOLPGM("Ki "); SERIAL_PROTOCOLLN(Ki);
SERIAL_PROTOCOLPGM("#define DEFAULT_"); SERIAL_PROTOCOL(estring); SERIAL_PROTOCOLPGM("Kd "); SERIAL_PROTOCOLLN(Kd); SERIAL_PROTOCOLPGM("#define DEFAULT_"); SERIAL_PROTOCOL(estring); SERIAL_PROTOCOLPGM("Kd "); SERIAL_PROTOCOLLN(Kd);
//Uses the result if set_result is true
// Use the result? (As with "M303 U1")
if (set_result) { if (set_result) {
if (extruder < 0) { if (extruder < 0) {
#if ENABLED(PIDTEMPBED) #if ENABLED(PIDTEMPBED)

@ -1067,6 +1067,33 @@ static void lcd_control_menu() {
* *
*/ */
#if ENABLED(PIDTEMP) || ENABLED(PIDTEMPBED)
#if ENABLED(PIDTEMP)
int autotune_temp[EXTRUDERS] = { 150 };
const int heater_maxtemp[EXTRUDERS] = ARRAY_BY_EXTRUDERS(HEATER_0_MAXTEMP, HEATER_1_MAXTEMP, HEATER_2_MAXTEMP, HEATER_3_MAXTEMP);
#endif
#if ENABLED(PIDTEMPBED)
int autotune_temp_bed = 70;
#endif
static void _lcd_autotune(int e) {
char cmd[30];
sprintf_P(cmd, PSTR("M303 U1 E%d S%d"), e,
#if ENABLED(PIDTEMP) && ENABLED(PIDTEMPBED)
e < 0 ? autotune_temp_bed : autotune_temp[e]
#elif ENABLED(PIDTEMPBED)
autotune_temp_bed
#else
autotune_temp[e]
#endif
);
enqueue_and_echo_command_now(cmd);
}
#endif PIDTEMP || PIDTEMPBED
#if ENABLED(PIDTEMP) #if ENABLED(PIDTEMP)
// Helpers for editing PID Ki & Kd values // Helpers for editing PID Ki & Kd values
@ -1079,18 +1106,19 @@ static void lcd_control_menu() {
PID_PARAM(Kd, e) = scalePID_d(raw_Kd); PID_PARAM(Kd, e) = scalePID_d(raw_Kd);
updatePID(); updatePID();
} }
#define COPY_AND_SCALE(eindex) \ #define _PIDTEMP_FUNCTIONS(eindex) \
void copy_and_scalePID_i_E ## eindex() { copy_and_scalePID_i(eindex); } \ void copy_and_scalePID_i_E ## eindex() { copy_and_scalePID_i(eindex); } \
void copy_and_scalePID_d_E ## eindex() { copy_and_scalePID_d(eindex); } void copy_and_scalePID_d_E ## eindex() { copy_and_scalePID_d(eindex); } \
void lcd_autotune_callback_E ## eindex() { _lcd_autotune(eindex); }
COPY_AND_SCALE(0); _PIDTEMP_FUNCTIONS(0);
#if ENABLED(PID_PARAMS_PER_EXTRUDER) #if ENABLED(PID_PARAMS_PER_EXTRUDER)
#if EXTRUDERS > 1 #if EXTRUDERS > 1
COPY_AND_SCALE(1); _PIDTEMP_FUNCTIONS(1);
#if EXTRUDERS > 2 #if EXTRUDERS > 2
COPY_AND_SCALE(2); _PIDTEMP_FUNCTIONS(2);
#if EXTRUDERS > 3 #if EXTRUDERS > 3
COPY_AND_SCALE(3); _PIDTEMP_FUNCTIONS(3);
#endif //EXTRUDERS > 3 #endif //EXTRUDERS > 3
#endif //EXTRUDERS > 2 #endif //EXTRUDERS > 2
#endif //EXTRUDERS > 1 #endif //EXTRUDERS > 1
@ -1184,7 +1212,7 @@ static void lcd_control_temperature_menu() {
// //
#if ENABLED(PIDTEMP) #if ENABLED(PIDTEMP)
#define _PID_MENU_ITEMS(ELABEL, eindex) \ #define _PID_BASE_MENU_ITEMS(ELABEL, eindex) \
raw_Ki = unscalePID_i(PID_PARAM(Ki, eindex)); \ raw_Ki = unscalePID_i(PID_PARAM(Ki, eindex)); \
raw_Kd = unscalePID_d(PID_PARAM(Kd, eindex)); \ raw_Kd = unscalePID_d(PID_PARAM(Kd, eindex)); \
MENU_ITEM_EDIT(float52, MSG_PID_P ELABEL, &PID_PARAM(Kp, eindex), 1, 9990); \ MENU_ITEM_EDIT(float52, MSG_PID_P ELABEL, &PID_PARAM(Kp, eindex), 1, 9990); \
@ -1192,27 +1220,28 @@ static void lcd_control_temperature_menu() {
MENU_ITEM_EDIT_CALLBACK(float52, MSG_PID_D ELABEL, &raw_Kd, 1, 9990, copy_and_scalePID_d_E ## eindex) MENU_ITEM_EDIT_CALLBACK(float52, MSG_PID_D ELABEL, &raw_Kd, 1, 9990, copy_and_scalePID_d_E ## eindex)
#if ENABLED(PID_ADD_EXTRUSION_RATE) #if ENABLED(PID_ADD_EXTRUSION_RATE)
#define PID_MENU_ITEMS(ELABEL, eindex, AUTOTUNE_CMD) \ #define _PID_MENU_ITEMS(ELABEL, eindex) \
_PID_MENU_ITEMS(ELABEL, eindex); \ _PID_BASE_MENU_ITEMS(ELABEL, eindex); \
MENU_ITEM_EDIT(float3, MSG_PID_C ELABEL, &PID_PARAM(Kc, eindex), 1, 9990); \ MENU_ITEM_EDIT(float3, MSG_PID_C ELABEL, &PID_PARAM(Kc, eindex), 1, 9990)
MENU_ITEM(gcode, MSG_PID_AUTOTUNE ELABEL, PSTR(AUTOTUNE_CMD))
#else #else
#define PID_MENU_ITEMS(ELABEL, eindex, AUTOTUNE_CMD) \ #define _PID_MENU_ITEMS(ELABEL, eindex) _PID_BASE_MENU_ITEMS(ELABEL, eindex)
_PID_MENU_ITEMS(ELABEL, eindex); \
MENU_ITEM(gcode, MSG_PID_AUTOTUNE ELABEL, PSTR(AUTOTUNE_CMD))
#endif #endif
#define PID_MENU_ITEMS(ELABEL, eindex) \
_PID_MENU_ITEMS(ELABEL, eindex); \
MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_PID_AUTOTUNE ELABEL, &autotune_temp[eindex], 150, heater_maxtemp[eindex] - 15, lcd_autotune_callback_E ## eindex)
#if ENABLED(PID_PARAMS_PER_EXTRUDER) && EXTRUDERS > 1 #if ENABLED(PID_PARAMS_PER_EXTRUDER) && EXTRUDERS > 1
PID_MENU_ITEMS(MSG_E1, 0, "M303 U1"); PID_MENU_ITEMS(MSG_E1, 0);
PID_MENU_ITEMS(MSG_E2, 1, "M303 U1 E1"); PID_MENU_ITEMS(MSG_E2, 1);
#if EXTRUDERS > 2 #if EXTRUDERS > 2
PID_MENU_ITEMS(MSG_E3, 2, "M303 U1 E2"); PID_MENU_ITEMS(MSG_E3, 2);
#if EXTRUDERS > 3 #if EXTRUDERS > 3
PID_MENU_ITEMS(MSG_E4, 3, "M303 U1 E3"); PID_MENU_ITEMS(MSG_E4, 3);
#endif //EXTRUDERS > 3 #endif //EXTRUDERS > 3
#endif //EXTRUDERS > 2 #endif //EXTRUDERS > 2
#else //!PID_PARAMS_PER_EXTRUDER || EXTRUDERS == 1 #else //!PID_PARAMS_PER_EXTRUDER || EXTRUDERS == 1
PID_MENU_ITEMS("", 0, "M303 U1"); PID_MENU_ITEMS("", 0);
#endif //!PID_PARAMS_PER_EXTRUDER || EXTRUDERS == 1 #endif //!PID_PARAMS_PER_EXTRUDER || EXTRUDERS == 1
#endif //PIDTEMP #endif //PIDTEMP

Loading…
Cancel
Save