Minor updates, improvements, and bug fixes.

- Allowed status_message function to be called by others. This is to
centralize all feedback into protocol.c.

- Fixed a bug where line number words 'N' were causing the parser to
error out.

- Allowed homing routine feed rates to move slower than the
MINIMUM_STEP_RATE parameter in config.h.

- Homing performs idle lock at the end of the routine.

- Stepper idle lock time will now not disable the steppers when the
value is set at 255. This is accomodate users who prefer to keep their
axes enabled at all times.

- Moved some defines around to where they need to be.
This commit is contained in:
Sonny Jeon 2012-10-13 13:11:43 -06:00
parent 00701ff24e
commit 34f6d2eb4b
10 changed files with 81 additions and 15 deletions

View File

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

View File

@ -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<<STEPPERS_DISABLE_BIT);
// Jog all axes toward home to engage their limit switches at faster homing seek rate.
homing_cycle(false, false, true, true, false, settings.homing_seek_rate); // First jog the z axis
homing_cycle(true, true, false, true, false, settings.homing_seek_rate); // Then jog the x and y axis
homing_cycle(false, false, true, true, false, settings.homing_seek_rate); // First jog the z axis
homing_cycle(true, true, false, true, false, settings.homing_seek_rate); // Then jog the x and y axis
delay_ms(settings.homing_debounce_delay); // Delay to debounce signal
// Now in proximity of all limits. Carefully leave and approach switches in multiple cycles
@ -183,6 +186,9 @@ void limits_go_home()
}
}
delay_ms(settings.stepper_idle_lock_time);
// Disable steppers by setting stepper disable
STEPPERS_DISABLE_PORT |= (1<<STEPPERS_DISABLE_BIT);
if (settings.stepper_idle_lock_time != 0xff) {
STEPPERS_DISABLE_PORT |= (1<<STEPPERS_DISABLE_BIT);
}
}

View File

@ -21,6 +21,8 @@
#ifndef limits_h
#define limits_h
#define LIMIT_MASK ((1<<X_LIMIT_BIT)|(1<<Y_LIMIT_BIT)|(1<<Z_LIMIT_BIT)) // All limit bits
// initialize the limits module
void limits_init();

View File

@ -419,6 +419,12 @@ void plan_buffer_line(float x, float y, float z, float feed_rate, uint8_t invert
// path width or max_jerk in the previous grbl version. This approach does not actually deviate
// from path, but used as a robust way to compute cornering speeds, as it takes into account the
// nonlinearities of both the junction angle and junction velocity.
// NOTE: This is basically an exact path mode (G61), but it doesn't come to a complete stop unless
// the junction deviation value is high. In the future, if continuous mode (G64) is desired, the
// math here is exactly the same. Instead of motioning all the way to junction point, the machine
// will just need to follow the arc circle defined above and check if the arc radii are no longer
// than half of either line segment to ensure no overlapping. Right now, the Arduino likely doesn't
// have the horsepower to do these calculations at high feed rates.
float vmax_junction = MINIMUM_PLANNER_SPEED; // Set default max junction speed
// Skip first block or when previous_nominal_speed is used as a flag for homing and offset cycles.

View File

@ -32,13 +32,11 @@
#include "stepper.h"
#include "planner.h"
#define LINE_BUFFER_SIZE 50
static char line[LINE_BUFFER_SIZE]; // Line to be executed. Zero-terminated.
static uint8_t char_counter; // Last character counter in line variable.
static uint8_t iscomment; // Comment/block delete flag for processor to ignore comment characters.
static void status_message(int status_code)
void protocol_status_message(int8_t status_code)
{
if (status_code == 0) {
printPgmString(PSTR("ok\r\n"));
@ -220,10 +218,10 @@ void protocol_process()
if (char_counter > 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

View File

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

View File

@ -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, &parameter)) {
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() {
@ -256,3 +288,14 @@ void settings_init() {
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));
// }

View File

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

View File

@ -114,7 +114,9 @@ void st_go_idle()
// stop and not drift from residual inertial forces at the end of the last movement.
delay_ms(settings.stepper_idle_lock_time);
// Disable steppers by setting stepper disable
STEPPERS_DISABLE_PORT |= (1<<STEPPERS_DISABLE_BIT);
if (settings.stepper_idle_lock_time != 0xff) {
STEPPERS_DISABLE_PORT |= (1<<STEPPERS_DISABLE_BIT);
}
}
// This function determines an acceleration velocity change every CYCLES_PER_ACCELERATION_TICK by

View File

@ -26,7 +26,6 @@
#include <avr/sleep.h>
// Some useful constants
#define LIMIT_MASK ((1<<X_LIMIT_BIT)|(1<<Y_LIMIT_BIT)|(1<<Z_LIMIT_BIT)) // All limit bits
#define STEP_MASK ((1<<X_STEP_BIT)|(1<<Y_STEP_BIT)|(1<<Z_STEP_BIT)) // All step bits
#define DIRECTION_MASK ((1<<X_DIRECTION_BIT)|(1<<Y_DIRECTION_BIT)|(1<<Z_DIRECTION_BIT)) // All direction bits
#define STEPPING_MASK (STEP_MASK | DIRECTION_MASK) // All stepping-related bits (step/direction)