Skip to content

Commit

Permalink
Arduino IDE compatibility and minor homing fixes
Browse files Browse the repository at this point in the history
- Added an include in the right spot, if a user tries to compile and
upload Grbl through the Arduino IDE with the old way.

- Fixed a minor bug with homing max travel calculations. It was causing
simultaneous axes homing to move slow than it did before.
  • Loading branch information
chamnit committed Mar 4, 2015
1 parent 85b0c7a commit 7673017
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 12 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,5 +82,5 @@ List of Supported G-Codes in Grbl v0.9
-------------
Grbl is an open-source project and fueled by the free-time of our intrepid administrators and altruistic users. If you'd like to donate, all proceeds will be used to help fund supporting hardware and testing equipment. Thank you!

[![Donate](https://www.paypalobjects.com/en_US/i/btn/btn_donate_LG.gif)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=EBQWAWQAAT878)
[![Donate](https://www.paypalobjects.com/en_US/i/btn/btn_donate_LG.gif)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=CUGXJHXA36BYW)

1 change: 1 addition & 0 deletions grbl/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

#ifndef config_h
#define config_h
#include "grbl.h" // For Arduino IDE compatibility.


// Default settings. Used when resetting EEPROM. Change to desired name in defaults.h
Expand Down
2 changes: 1 addition & 1 deletion grbl/grbl.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

// Grbl versioning system
#define GRBL_VERSION "0.9i"
#define GRBL_VERSION_BUILD "20150223"
#define GRBL_VERSION_BUILD "20150302"

// Define standard libraries used by Grbl.
#include <avr/io.h>
Expand Down
25 changes: 15 additions & 10 deletions grbl/limits.c
Original file line number Diff line number Diff line change
Expand Up @@ -134,14 +134,22 @@ void limits_go_home(uint8_t cycle_mask)
float target[N_AXIS];

uint8_t limit_pin[N_AXIS], step_pin[N_AXIS];
float max_travel;

float max_travel = 0.0;
for (idx=0; idx<N_AXIS; idx++) {
// Initialize limit and step pin masks
limit_pin[idx] = get_limit_pin_mask(idx);
step_pin[idx] = get_step_pin_mask(idx);
#ifdef COREXY
if ((idx==A_MOTOR)||(idx==B_MOTOR)) { step_pin[idx] = (get_step_pin_mask(X_AXIS)|get_step_pin_mask(Y_AXIS)); }
#endif

if (bit_istrue(cycle_mask,bit(idx))) {
// Set target based on max_travel setting. Ensure homing switches engaged with search scalar.
// NOTE: settings.max_travel[] is stored as a negative value.
max_travel = max(max_travel,(-HOMING_AXIS_SEARCH_SCALAR)*settings.max_travel[idx]);
}

}

plan_reset(); // Reset planner buffer to zero planner current position and to clear previous motions.
Expand All @@ -153,25 +161,22 @@ void limits_go_home(uint8_t cycle_mask)
else { invert_pin = !approach; }

// Initialize and declare variables needed for homing routine.
uint8_t n_active_axis = 0;
uint8_t axislock = 0;

uint8_t n_active_axis = 0;
system_convert_array_steps_to_mpos(target,sys.position);
for (idx=0; idx<N_AXIS; idx++) {
// Set target location for active axes and setup computation for homing rate.
if (bit_istrue(cycle_mask,bit(idx))) {
n_active_axis++;
// Set target based on max_travel setting. Ensure homing switches engaged with search scalar.
// NOTE: settings.max_travel[] is stored as a negative value.
max_travel = (-HOMING_AXIS_SEARCH_SCALAR)*settings.max_travel[idx];
if (bit_istrue(settings.homing_dir_mask,bit(idx))) { max_travel = -max_travel; }
if (!approach) { max_travel = -max_travel; }
target[idx] += max_travel;

// Apply axislock to the step port pins active in this cycle.
axislock |= step_pin[idx];
}

// Apply axislock to the step port pins active in this cycle.
if (bit_istrue(cycle_mask,bit(idx))) { axislock |= step_pin[idx]; }
}
}
homing_rate *= sqrt(n_active_axis); // [sqrt(N_AXIS)] Adjust so individual axes all move at homing rate.
sys.homing_axis_lock = axislock;

Expand All @@ -197,9 +202,9 @@ void limits_go_home(uint8_t cycle_mask)
}
sys.homing_axis_lock = axislock;
st_prep_buffer(); // Check and prep segment buffer. NOTE: Should take no longer than 200us.
// Check only for user reset. No time to run protocol_execute_realtime() in this loop.

// Exit routines: User abort homing and alarm upon safety door or no limit switch found.
// No time to run protocol_execute_realtime() in this loop.
if (sys.rt_exec_state & (EXEC_SAFETY_DOOR | EXEC_RESET | EXEC_CYCLE_STOP)) {
if (sys.rt_exec_state & (EXEC_SAFETY_DOOR | EXEC_CYCLE_STOP)) { mc_reset(); }
protocol_execute_realtime();
Expand Down
4 changes: 4 additions & 0 deletions grbl/protocol.c
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,10 @@ void protocol_execute_realtime()
// to do what is needed before resetting, like killing the incoming stream. The
// same could be said about soft limits. While the position is not lost, the incoming
// stream could be still engaged and cause a serious crash if it continues afterwards.
// if (sys.rt_exec_state & EXEC_STATUS_REPORT) {
// report_realtime_status();
// bit_false_atomic(sys.rt_exec_state,EXEC_STATUS_REPORT);
// }
} while (bit_isfalse(sys.rt_exec_state,EXEC_RESET));
}
bit_false_atomic(sys.rt_exec_alarm,0xFF); // Clear all alarm flags
Expand Down

0 comments on commit 7673017

Please sign in to comment.