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

@ -48,24 +48,31 @@
// 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
// 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
// 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.
if (bit_istrue(settings.flags,BITFLAG_SOFT_LIMIT_ENABLE)) {
if( (x> settings.mm_soft_limit[X_AXIS])||(y>settings.mm_soft_limit[Y_AXIS])||(z>settings.mm_soft_limit[Z_AXIS])) {
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
}
}
// TODO: Eventually move the soft limit check into limits.c.
if (bit_istrue(settings.flags,BITFLAG_SOFT_LIMIT_ENABLE)) {
uint8_t i;
for (i=0; i<N_AXIS; i++) {
if ((target[i] < 0) || (target[i] > settings.max_travel[i])) {
// TODO: Need to make this more in-line with the rest of the alarm and runtime execution handling.
// Not quite right. Also this should force Grbl to feed hold and exit, rather than stopping and alarm
// 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 (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
if (sys.abort) { return; } // Bail, if system abort.
} 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
// 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
// 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.
// 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(); }
}
@ -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_1] = center_axis1 + r_axis1;
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.
if (sys.abort) { return; }
}
}
// 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.
// This provides some initial clearance off the switches and should also help prevent them
// from falsely tripping when hard limits are enabled.
int8_t x_dir, y_dir, z_dir;
x_dir = y_dir = z_dir = 0;
float target[N_AXIS];
target[X_AXIS] = target[Y_AXIS] = target[Z_AXIS] = settings.homing_pulloff;
if (HOMING_LOCATE_CYCLE & (1<<X_AXIS)) {
if (settings.homing_dir_mask & (1<<X_DIRECTION_BIT)) { x_dir = 1; }
else { x_dir = -1; }
if (bit_isfalse(settings.homing_dir_mask,(1<<X_DIRECTION_BIT))) { target[X_AXIS] *= -1; }
}
if (HOMING_LOCATE_CYCLE & (1<<Y_AXIS)) {
if (settings.homing_dir_mask & (1<<Y_DIRECTION_BIT)) { y_dir = 1; }
else { y_dir = -1; }
if (bit_isfalse(settings.homing_dir_mask,(1<<Y_DIRECTION_BIT))) { target[Y_AXIS] *= -1; }
}
if (HOMING_LOCATE_CYCLE & (1<<Z_AXIS)) {
if (settings.homing_dir_mask & (1<<Z_DIRECTION_BIT)) { z_dir = 1; }
else { z_dir = -1; }
if (bit_isfalse(settings.homing_dir_mask,(1<<Z_DIRECTION_BIT))) { target[Z_AXIS] *= -1; }
}
mc_line(x_dir*settings.homing_pulloff, y_dir*settings.homing_pulloff,
z_dir*settings.homing_pulloff, settings.homing_seek_rate, false);
mc_line(target, settings.homing_seek_rate, false);
st_cycle_start(); // Move it. Nothing should be in the buffer except this motion.
plan_synchronize(); // Make sure the motion completes.