diff --git a/gcode.c b/gcode.c index d83fc5a..c59bac7 100755 --- a/gcode.c +++ b/gcode.c @@ -104,6 +104,8 @@ void gc_init() gc.feed_rate = settings.default_feed_rate; select_plane(X_AXIS, Y_AXIS, Z_AXIS); gc.absolute_mode = true; + +// protocol_status_message(settings_execute_startup()); } // Sets g-code parser position in mm. Input in steps. Called by the system abort routine. @@ -180,6 +182,7 @@ uint8_t gc_execute_line(char *line) case 20: gc.inches_mode = true; break; case 21: gc.inches_mode = false; break; case 28: case 30: + // NOTE: G28.1, G30.1 sets home position parameters. Not currently supported. if (bit_istrue(settings.flags,FLAG_BIT_HOMING_ENABLE)) { non_modal_action = NON_MODAL_GO_HOME; } else { @@ -259,7 +262,7 @@ uint8_t gc_execute_line(char *line) char_counter = 0; while(next_statement(&letter, &value, line, &char_counter)) { switch(letter) { - case 'G': case 'M': break; // Ignore command statements + case 'G': case 'M': case 'N': break; // Ignore command statements and line numbers case 'F': if (value <= 0) { FAIL(STATUS_INVALID_COMMAND); } // Must be greater than zero if (gc.inverse_feed_rate_mode) { diff --git a/limits.c b/limits.c index d1cd7a9..da36409 100755 --- a/limits.c +++ b/limits.c @@ -30,6 +30,7 @@ #include "motion_control.h" #include "planner.h" #include "protocol.h" +#include "limits.h" #define MICROSECONDS_PER_ACCELERATION_TICK (1000000/ACCELERATION_TICKS_PER_SECOND) @@ -76,9 +77,11 @@ static void homing_cycle(bool x_axis, bool y_axis, bool z_axis, int8_t pos_dir, // Nominal and initial time increment per step. Nominal should always be greater then 3 // usec, since they are based on the same parameters as the main stepper routine. Initial - // is based on the MINIMUM_STEPS_PER_MINUTE config. + // is based on the MINIMUM_STEPS_PER_MINUTE config. Since homing feed can be very slow, + // disable acceleration when rates are below MINIMUM_STEPS_PER_MINUTE. uint32_t dt_min = lround(1000000*60/(ds*homing_rate)); // Cruising (usec/step) uint32_t dt = 1000000*60/MINIMUM_STEPS_PER_MINUTE; // Initial (usec/step) + if (dt > dt_min) { dt = dt_min; } // Disable acceleration for very slow rates. // Set default out_bits. uint8_t out_bits0 = settings.invert_mask; @@ -164,8 +167,8 @@ void limits_go_home() STEPPERS_DISABLE_PORT &= ~(1< 0) {// Line is complete. Then execute! line[char_counter] = 0; // Terminate string - status_message(protocol_execute_line(line)); + protocol_status_message(protocol_execute_line(line)); } else { // Empty or comment line. Skip block. - status_message(STATUS_OK); // Send status message for syncing purposes. + protocol_status_message(STATUS_OK); // Send status message for syncing purposes. } char_counter = 0; // Reset line buffer index iscomment = false; // Reset comment flag diff --git a/protocol.h b/protocol.h index 2a43c95..559560c 100755 --- a/protocol.h +++ b/protocol.h @@ -30,6 +30,8 @@ #define STATUS_INVALID_COMMAND 6 #define STATUS_SETTING_DISABLED 7 +#define LINE_BUFFER_SIZE 50 + // Initialize the serial protocol void protocol_init(); @@ -43,4 +45,7 @@ uint8_t protocol_execute_line(char *line); // Checks and executes a runtime command at various stop points in main program void protocol_execute_runtime(); +// Prints g-code parser status message. +void protocol_status_message(int8_t status_code); + #endif diff --git a/settings.c b/settings.c index 92c8226..e012c5c 100755 --- a/settings.c +++ b/settings.c @@ -105,6 +105,10 @@ void settings_reset(bool reset_all) { settings.decimal_places = DEFAULT_DECIMAL_PLACES; } +// static void settings_startup_string(char *buf) { +// memcpy_from_eeprom_with_checksum((char*)buf,512, 4); +// } + void settings_dump() { printPgmString(PSTR("$0 = ")); printFloat(settings.steps_per_mm[X_AXIS]); printPgmString(PSTR(" (steps/mm x)\r\n$1 = ")); printFloat(settings.steps_per_mm[Y_AXIS]); @@ -124,12 +128,18 @@ void settings_dump() { printPgmString(PSTR(" (milliseconds homing debounce delay)\r\n$14 = ")); printInteger(settings.stepper_idle_lock_time); printPgmString(PSTR(" (milliseconds stepper idle lock time)\r\n$15 = ")); printInteger(settings.decimal_places); printPgmString(PSTR(" (float decimal places)")); + +// char buf[4]; +// settings_startup_string((char *)buf); +// printPgmString(PSTR("\r\n Startup: ")); printString(buf); + printPgmString(PSTR("\r\n'$x=value' to set parameter or just '$' to dump current settings\r\n")); } // Parameter lines are on the form '$4=374.3' or '$' to dump current settings uint8_t settings_execute_line(char *line) { uint8_t char_counter = 1; +// unsigned char letter; float parameter, value; if(line[0] != '$') { return(STATUS_UNSUPPORTED_STATEMENT); @@ -137,6 +147,23 @@ uint8_t settings_execute_line(char *line) { if(line[char_counter] == 0) { settings_dump(); return(STATUS_OK); } +// if(line[char_counter] >= 'A' || line[char_counter] <= 'Z') { +// letter = line[char_counter++]; +// if(line[char_counter++] != '=') { +// return(STATUS_UNSUPPORTED_STATEMENT); +// } +// for (char_counter = 0; char_counter < LINE_BUFFER_SIZE-3; char_counter++) { +// line[char_counter] = line[char_counter+3]; +// } +// uint8_t status = gc_execute_line(line); +// if (status) { return(status); } +// else { settings_store_startup_line(line); } +// +// +// // Opt stop and block delete are referred to as switches. +// // How to store home position and work offsets real-time?? +// +// } else { if(!read_float(line, &char_counter, ¶meter)) { return(STATUS_BAD_NUMBER_FORMAT); }; @@ -151,11 +178,16 @@ uint8_t settings_execute_line(char *line) { } settings_store_setting(parameter, value); return(STATUS_OK); +// } } void write_settings() { eeprom_put_char(0, SETTINGS_VERSION); memcpy_to_eeprom_with_checksum(1, (char*)&settings, sizeof(settings_t)); +// +// char buf[4]; buf[0] = 'G'; buf[1] = '2'; buf[2] = '0'; buf[3] = 0; +// memcpy_to_eeprom_with_checksum(512, (char*)buf, 4); +// } int read_settings() { @@ -254,5 +286,16 @@ void settings_init() { settings_reset(true); write_settings(); settings_dump(); - } + } } + +// int8_t settings_execute_startup() { +// +// char buf[4]; +// settings_startup_string((char *)buf); +// uint8_t i = 0; +// while (i < 4) { +// serial_write(buf[i++]); +// } +// return(gc_execute_line(buf)); +// } diff --git a/settings.h b/settings.h index cb15bd6..64aba96 100755 --- a/settings.h +++ b/settings.h @@ -29,7 +29,7 @@ // Version of the EEPROM data. Will be used to migrate existing data from older versions of Grbl // when firmware is upgraded. Always stored in byte 0 of eeprom -#define SETTINGS_VERSION 52 +#define SETTINGS_VERSION 53 // Define bit flag masks in settings.flag. #define FLAG_BIT_HOMING_ENABLE bit(0) @@ -68,4 +68,6 @@ uint8_t settings_execute_line(char *line); // A helper method to set new settings from command line void settings_store_setting(int parameter, float value); +// int8_t settings_execute_startup(); + #endif diff --git a/stepper.c b/stepper.c index 148d29f..54f3fd9 100755 --- a/stepper.c +++ b/stepper.c @@ -112,9 +112,11 @@ void st_go_idle() TIMSK1 &= ~(1< // Some useful constants -#define LIMIT_MASK ((1<