Minor changes and added notes to soft limits routines.

- Changed up mc_line to accept an array rather than individual x,y,z
coordinates. Makes some of the position data handling more effective,
especially for a 4th-axis later on.

- Changed up some soft limits variable names.
This commit is contained in:
Sonny Jeon 2013-03-01 09:55:10 -07:00
parent 7951b83294
commit 74b2af3c2f
6 changed files with 47 additions and 42 deletions

View File

@ -321,14 +321,14 @@ uint8_t gc_execute_line(char *line)
target[i] = gc.position[i]; target[i] = gc.position[i];
} }
} }
mc_line(target[X_AXIS], target[Y_AXIS], target[Z_AXIS], -1.0, false); mc_line(target, -1.0, false);
} }
// Retreive G28/30 go-home position data (in machine coordinates) from EEPROM // Retreive G28/30 go-home position data (in machine coordinates) from EEPROM
float coord_data[N_AXIS]; float coord_data[N_AXIS];
uint8_t home_select = SETTING_INDEX_G28; uint8_t home_select = SETTING_INDEX_G28;
if (non_modal_action == NON_MODAL_GO_HOME_1) { home_select = SETTING_INDEX_G30; } if (non_modal_action == NON_MODAL_GO_HOME_1) { home_select = SETTING_INDEX_G30; }
if (!settings_read_coord_data(home_select,coord_data)) { return(STATUS_SETTING_READ_FAIL); } if (!settings_read_coord_data(home_select,coord_data)) { return(STATUS_SETTING_READ_FAIL); }
mc_line(coord_data[X_AXIS], coord_data[Y_AXIS], coord_data[Z_AXIS], -1.0, false); mc_line(coord_data, -1.0, false);
memcpy(gc.position, coord_data, sizeof(coord_data)); // gc.position[] = coord_data[]; memcpy(gc.position, coord_data, sizeof(coord_data)); // gc.position[] = coord_data[];
axis_words = 0; // Axis words used. Lock out from motion modes by clearing flags. axis_words = 0; // Axis words used. Lock out from motion modes by clearing flags.
break; break;
@ -399,7 +399,7 @@ uint8_t gc_execute_line(char *line)
break; break;
case MOTION_MODE_SEEK: case MOTION_MODE_SEEK:
if (!axis_words) { FAIL(STATUS_INVALID_STATEMENT);} if (!axis_words) { FAIL(STATUS_INVALID_STATEMENT);}
else { mc_line(target[X_AXIS], target[Y_AXIS], target[Z_AXIS], -1.0, false); } else { mc_line(target, -1.0, false); }
break; break;
case MOTION_MODE_LINEAR: case MOTION_MODE_LINEAR:
// TODO: Inverse time requires F-word with each statement. Need to do a check. Also need // TODO: Inverse time requires F-word with each statement. Need to do a check. Also need
@ -407,8 +407,7 @@ uint8_t gc_execute_line(char *line)
// and after an inverse time move and then check for non-zero feed rate each time. This // and after an inverse time move and then check for non-zero feed rate each time. This
// should be efficient and effective. // should be efficient and effective.
if (!axis_words) { FAIL(STATUS_INVALID_STATEMENT);} if (!axis_words) { FAIL(STATUS_INVALID_STATEMENT);}
else { mc_line(target[X_AXIS], target[Y_AXIS], target[Z_AXIS], else { mc_line(target, (gc.inverse_feed_rate_mode) ? inverse_feed_rate : gc.feed_rate, gc.inverse_feed_rate_mode); }
(gc.inverse_feed_rate_mode) ? inverse_feed_rate : gc.feed_rate, gc.inverse_feed_rate_mode); }
break; break;
case MOTION_MODE_CW_ARC: case MOTION_MODE_CCW_ARC: case MOTION_MODE_CW_ARC: case MOTION_MODE_CCW_ARC:
// Check if at least one of the axes of the selected plane has been specified. If in center // Check if at least one of the axes of the selected plane has been specified. If in center

View File

@ -48,24 +48,31 @@
// However, this keeps the memory requirements lower since it doesn't have to call and hold two // However, this keeps the memory requirements lower since it doesn't have to call and hold two
// plan_buffer_lines in memory. Grbl only has to retain the original line input variables during a // plan_buffer_lines in memory. Grbl only has to retain the original line input variables during a
// backlash segment(s). // backlash segment(s).
void mc_line(float x, float y, float z, float feed_rate, uint8_t invert_feed_rate) void mc_line(float *target, float feed_rate, uint8_t invert_feed_rate)
{ {
// TO TEST: Perform soft limit check here. Just check if the target x,y,z values are outside the // TO TEST: Perform soft limit check here. Just check if the target x,y,z values are outside the
// work envelope. Should be straightforward and efficient. By placing it here, rather than in // work envelope. Should be straightforward and efficient. By placing it here, rather than in
// the g-code parser, it directly picks up motions from everywhere in Grbl. // the g-code parser, it directly picks up motions from everywhere in Grbl.
if (bit_istrue(settings.flags,BITFLAG_SOFT_LIMIT_ENABLE)) { // TODO: Eventually move the soft limit check into limits.c.
if( (x> settings.mm_soft_limit[X_AXIS])||(y>settings.mm_soft_limit[Y_AXIS])||(z>settings.mm_soft_limit[Z_AXIS])) { if (bit_istrue(settings.flags,BITFLAG_SOFT_LIMIT_ENABLE)) {
if (sys.state != STATE_ALARM) { uint8_t i;
if (bit_isfalse(sys.execute,EXEC_ALARM)) { for (i=0; i<N_AXIS; i++) {
mc_reset(); // Initiate system kill. if ((target[i] < 0) || (target[i] > settings.max_travel[i])) {
report_alarm_message(ALARM_SOFT_LIMIT); // TODO: Need to make this more in-line with the rest of the alarm and runtime execution handling.
sys.state = STATE_ALARM; // Not quite right. Also this should force Grbl to feed hold and exit, rather than stopping and alarm
sys.execute |= EXEC_CRIT_EVENT; // Indicate hard limit critical event // out. This would help retain machine position, but is this really required?
} if (sys.state != STATE_ALARM) {
} if (bit_isfalse(sys.execute,EXEC_ALARM)) {
mc_reset(); // Initiate system kill.
report_alarm_message(ALARM_SOFT_LIMIT);
sys.state = STATE_ALARM;
sys.execute |= EXEC_CRIT_EVENT; // Indicate hard limit critical event
}
} }
}
}
} }
// If in check gcode mode, prevent motion by blocking planner. // If in check gcode mode, prevent motion by blocking planner.
if (sys.state == STATE_CHECK_MODE) { return; } if (sys.state == STATE_CHECK_MODE) { return; }
@ -82,7 +89,7 @@ void mc_line(float x, float y, float z, float feed_rate, uint8_t invert_feed_rat
protocol_execute_runtime(); // Check for any run-time commands protocol_execute_runtime(); // Check for any run-time commands
if (sys.abort) { return; } // Bail, if system abort. if (sys.abort) { return; } // Bail, if system abort.
} while ( plan_check_full_buffer() ); } while ( plan_check_full_buffer() );
plan_buffer_line(x, y, z, feed_rate, invert_feed_rate); plan_buffer_line(target[X_AXIS], target[Y_AXIS], target[Z_AXIS], feed_rate, invert_feed_rate);
// If idle, indicate to the system there is now a planned block in the buffer ready to cycle // If idle, indicate to the system there is now a planned block in the buffer ready to cycle
// start. Otherwise ignore and continue on. // start. Otherwise ignore and continue on.
@ -96,6 +103,9 @@ void mc_line(float x, float y, float z, float feed_rate, uint8_t invert_feed_rat
// when the buffer is completely full and primed; auto-starting, if there was only one g-code // when the buffer is completely full and primed; auto-starting, if there was only one g-code
// command sent during manual operation; or if a system is prone to buffer starvation, auto-start // command sent during manual operation; or if a system is prone to buffer starvation, auto-start
// helps make sure it minimizes any dwelling/motion hiccups and keeps the cycle going. // helps make sure it minimizes any dwelling/motion hiccups and keeps the cycle going.
// NOTE: Moved into main loop and plan_check_full_buffer() as a test. This forces Grbl to process
// all of the commands in the serial read buffer or until the planner buffer is full before auto
// cycle starting. Will eventually need to remove the following command.
// if (sys.auto_start) { st_cycle_start(); } // if (sys.auto_start) { st_cycle_start(); }
} }
@ -204,14 +214,14 @@ void mc_arc(float *position, float *target, float *offset, uint8_t axis_0, uint8
arc_target[axis_0] = center_axis0 + r_axis0; arc_target[axis_0] = center_axis0 + r_axis0;
arc_target[axis_1] = center_axis1 + r_axis1; arc_target[axis_1] = center_axis1 + r_axis1;
arc_target[axis_linear] += linear_per_segment; arc_target[axis_linear] += linear_per_segment;
mc_line(arc_target[X_AXIS], arc_target[Y_AXIS], arc_target[Z_AXIS], feed_rate, invert_feed_rate); mc_line(arc_target, feed_rate, invert_feed_rate);
// Bail mid-circle on system abort. Runtime command check already performed by mc_line. // Bail mid-circle on system abort. Runtime command check already performed by mc_line.
if (sys.abort) { return; } if (sys.abort) { return; }
} }
} }
// Ensure last segment arrives at target location. // Ensure last segment arrives at target location.
mc_line(target[X_AXIS], target[Y_AXIS], target[Z_AXIS], feed_rate, invert_feed_rate); mc_line(target, feed_rate, invert_feed_rate);
} }
@ -252,22 +262,18 @@ void mc_go_home()
// Pull-off axes (that have been homed) from limit switches before continuing motion. // Pull-off axes (that have been homed) from limit switches before continuing motion.
// This provides some initial clearance off the switches and should also help prevent them // This provides some initial clearance off the switches and should also help prevent them
// from falsely tripping when hard limits are enabled. // from falsely tripping when hard limits are enabled.
int8_t x_dir, y_dir, z_dir; float target[N_AXIS];
x_dir = y_dir = z_dir = 0; target[X_AXIS] = target[Y_AXIS] = target[Z_AXIS] = settings.homing_pulloff;
if (HOMING_LOCATE_CYCLE & (1<<X_AXIS)) { if (HOMING_LOCATE_CYCLE & (1<<X_AXIS)) {
if (settings.homing_dir_mask & (1<<X_DIRECTION_BIT)) { x_dir = 1; } if (bit_isfalse(settings.homing_dir_mask,(1<<X_DIRECTION_BIT))) { target[X_AXIS] *= -1; }
else { x_dir = -1; }
} }
if (HOMING_LOCATE_CYCLE & (1<<Y_AXIS)) { if (HOMING_LOCATE_CYCLE & (1<<Y_AXIS)) {
if (settings.homing_dir_mask & (1<<Y_DIRECTION_BIT)) { y_dir = 1; } if (bit_isfalse(settings.homing_dir_mask,(1<<Y_DIRECTION_BIT))) { target[Y_AXIS] *= -1; }
else { y_dir = -1; }
} }
if (HOMING_LOCATE_CYCLE & (1<<Z_AXIS)) { if (HOMING_LOCATE_CYCLE & (1<<Z_AXIS)) {
if (settings.homing_dir_mask & (1<<Z_DIRECTION_BIT)) { z_dir = 1; } if (bit_isfalse(settings.homing_dir_mask,(1<<Z_DIRECTION_BIT))) { target[Z_AXIS] *= -1; }
else { z_dir = -1; }
} }
mc_line(x_dir*settings.homing_pulloff, y_dir*settings.homing_pulloff, mc_line(target, settings.homing_seek_rate, false);
z_dir*settings.homing_pulloff, settings.homing_seek_rate, false);
st_cycle_start(); // Move it. Nothing should be in the buffer except this motion. st_cycle_start(); // Move it. Nothing should be in the buffer except this motion.
plan_synchronize(); // Make sure the motion completes. plan_synchronize(); // Make sure the motion completes.

View File

@ -28,7 +28,7 @@
// Execute linear motion in absolute millimeter coordinates. Feed rate given in millimeters/second // Execute linear motion in absolute millimeter coordinates. Feed rate given in millimeters/second
// unless invert_feed_rate is true. Then the feed_rate means that the motion should be completed in // unless invert_feed_rate is true. Then the feed_rate means that the motion should be completed in
// (1 minute)/feed_rate time. // (1 minute)/feed_rate time.
void mc_line(float x, float y, float z, float feed_rate, uint8_t invert_feed_rate); void mc_line(float *target, float feed_rate, uint8_t invert_feed_rate);
// Execute an arc in offset mode format. position == current xyz, target == target xyz, // Execute an arc in offset mode format. position == current xyz, target == target xyz,
// offset == offset from current xyz, axis_XXX defines circle plane in tool space, axis_linear is // offset == offset from current xyz, axis_XXX defines circle plane in tool space, axis_linear is

View File

@ -174,11 +174,11 @@ void report_grbl_settings() {
printPgmString(PSTR(" (homing feed, mm/min)\r\n$23=")); printFloat(settings.homing_seek_rate); printPgmString(PSTR(" (homing feed, mm/min)\r\n$23=")); printFloat(settings.homing_seek_rate);
printPgmString(PSTR(" (homing seek, mm/min)\r\n$24=")); printInteger(settings.homing_debounce_delay); printPgmString(PSTR(" (homing seek, mm/min)\r\n$24=")); printInteger(settings.homing_debounce_delay);
printPgmString(PSTR(" (homing debounce, msec)\r\n$25=")); printFloat(settings.homing_pulloff); printPgmString(PSTR(" (homing debounce, msec)\r\n$25=")); printFloat(settings.homing_pulloff);
printPgmString(PSTR(" (homing pull-off, mm)\r\n$26=")); printFloat(settings.mm_soft_limit[X_AXIS]); printPgmString(PSTR(" (homing pull-off, mm)\r\n$26=")); printFloat(settings.max_travel[X_AXIS]);
printPgmString(PSTR(" (x, max travel)\r\n$27=")); printFloat(settings.mm_soft_limit[Y_AXIS]); printPgmString(PSTR(" (x travel, mm)\r\n$27=")); printFloat(settings.max_travel[Y_AXIS]);
printPgmString(PSTR(" (y, max travel)\r\n$28=")); printFloat(settings.mm_soft_limit[Z_AXIS]); printPgmString(PSTR(" (y travel, mm)\r\n$28=")); printFloat(settings.max_travel[Z_AXIS]);
printPgmString(PSTR(" (z, max travel)\r\n$29=")); printInteger(bit_istrue(settings.flags,BITFLAG_SOFT_LIMIT_ENABLE)); printPgmString(PSTR(" (z travel, mm)\r\n$29=")); printInteger(bit_istrue(settings.flags,BITFLAG_SOFT_LIMIT_ENABLE));
printPgmString(PSTR(" (soft limits enabled, bool)\r\n")); printPgmString(PSTR(" (soft limits, bool)\r\n"));
} }

View File

@ -201,10 +201,10 @@ uint8_t settings_store_global_setting(int parameter, float value) {
case 24: settings.homing_debounce_delay = round(value); break; case 24: settings.homing_debounce_delay = round(value); break;
case 25: settings.homing_pulloff = value; break; case 25: settings.homing_pulloff = value; break;
case 26: case 27: case 28: case 26: case 27: case 28:
if (value <= 0.0) { return(STATUS_SETTING_VALUE_NEG); } if (value <= 0.0) { return(STATUS_SETTING_VALUE_NEG); }
settings.mm_soft_limit[parameter-26] = value; break; settings.max_travel[parameter-26] = value; break;
case 29: case 29:
if (value) { settings.flags |= BITFLAG_SOFT_LIMIT_ENABLE; } if (value) { settings.flags |= BITFLAG_SOFT_LIMIT_ENABLE; }
else { settings.flags &= ~BITFLAG_SOFT_LIMIT_ENABLE; } else { settings.flags &= ~BITFLAG_SOFT_LIMIT_ENABLE; }
break; break;
default: default:

View File

@ -36,8 +36,8 @@
#define BITFLAG_AUTO_START bit(1) #define BITFLAG_AUTO_START bit(1)
#define BITFLAG_INVERT_ST_ENABLE bit(2) #define BITFLAG_INVERT_ST_ENABLE bit(2)
#define BITFLAG_HARD_LIMIT_ENABLE bit(3) #define BITFLAG_HARD_LIMIT_ENABLE bit(3)
#define BITFLAG_HOMING_ENABLE bit(4) #define BITFLAG_SOFT_LIMIT_ENABLE bit(4)
#define BITFLAG_SOFT_LIMIT_ENABLE bit(5) #define BITFLAG_HOMING_ENABLE bit(5)
// Define EEPROM memory address location values for Grbl settings and parameters // Define EEPROM memory address location values for Grbl settings and parameters
// NOTE: The Atmega328p has 1KB EEPROM. The upper half is reserved for parameters and // NOTE: The Atmega328p has 1KB EEPROM. The upper half is reserved for parameters and
@ -75,7 +75,7 @@ typedef struct {
uint8_t stepper_idle_lock_time; // If max value 255, steppers do not disable. uint8_t stepper_idle_lock_time; // If max value 255, steppers do not disable.
uint8_t decimal_places; uint8_t decimal_places;
float max_velocity[N_AXIS]; float max_velocity[N_AXIS];
float mm_soft_limit[N_AXIS]; float max_travel[N_AXIS];
// uint8_t status_report_mask; // Mask to indicate desired report data. // uint8_t status_report_mask; // Mask to indicate desired report data.
} settings_t; } settings_t;
extern settings_t settings; extern settings_t settings;