25 #ifndef HOMING_AXIS_SEARCH_SCALAR
26 #define HOMING_AXIS_SEARCH_SCALAR 1.5
28 #ifndef HOMING_AXIS_LOCATE_SCALAR
29 #define HOMING_AXIS_LOCATE_SCALAR 5.0
34 LIMIT_DDR &= ~(LIMIT_MASK);
36 #ifdef DISABLE_LIMIT_PIN_PULL_UP
37 LIMIT_PORT &= ~(LIMIT_MASK);
39 LIMIT_PORT |= (LIMIT_MASK);
43 LIMIT_PCMSK |= LIMIT_MASK;
44 PCICR |= (1 << LIMIT_INT);
49 #ifdef ENABLE_SOFTWARE_DEBOUNCE
51 WDTCSR |= (1<<WDCE) | (1<<WDE);
59 LIMIT_PCMSK &= ~LIMIT_MASK;
60 PCICR &= ~(1 << LIMIT_INT);
68 uint8_t limit_state = 0;
69 uint8_t pin = (LIMIT_PIN & LIMIT_MASK);
70 #ifdef INVERT_LIMIT_PIN_MASK
71 pin ^= INVERT_LIMIT_PIN_MASK;
76 for (idx=0; idx<
N_AXIS; idx++) {
95 #ifndef ENABLE_SOFTWARE_DEBOUNCE
105 #ifdef HARD_LIMIT_FORCE_STATE_CHECK
119 // Upon limit pin change, enable watchdog timer to create a short delay.
120 ISR(LIMIT_INT_vect) {
if (!(WDTCSR & (1<<WDIE))) { WDTCSR |= (1<<WDIE); } }
123 WDTCSR &= ~(1<<WDIE);
160 float max_travel = 0.0;
162 for (idx=0; idx<
N_AXIS; idx++) {
178 bool approach =
true;
181 uint8_t limit_state, axislock, n_active_axis;
189 for (idx=0; idx<
N_AXIS; idx++) {
195 int32_t axis_position = system_convert_corexy_to_y_axis_steps(
sys_position);
198 }
else if (idx ==
Y_AXIS) {
199 int32_t axis_position = system_convert_corexy_to_x_axis_steps(
sys_position);
211 if (approach) { target[idx] = -max_travel; }
212 else { target[idx] = max_travel; }
214 if (approach) { target[idx] = max_travel; }
215 else { target[idx] = -max_travel; }
218 axislock |= step_pin[idx];
222 homing_rate *= sqrt(n_active_axis);
236 for (idx=0; idx<
N_AXIS; idx++) {
237 if (axislock & step_pin[idx]) {
238 if (limit_state & (1 << idx)) {
241 else { axislock &= ~(step_pin[A_MOTOR]|step_pin[B_MOTOR]); }
243 axislock &= ~(step_pin[idx]);
276 }
while (STEP_MASK & axislock);
282 approach = !approach;
293 }
while (n_cycle-- > 0);
301 int32_t set_axis_position;
303 for (idx=0; idx<
N_AXIS; idx++) {
306 if (cycle_mask &
bit(idx)) {
307 #ifdef HOMING_FORCE_SET_ORIGIN
308 set_axis_position = 0;
319 int32_t off_axis_position = system_convert_corexy_to_y_axis_steps(
sys_position);
320 sys_position[A_MOTOR] = set_axis_position + off_axis_position;
321 sys_position[B_MOTOR] = set_axis_position - off_axis_position;
323 int32_t off_axis_position = system_convert_corexy_to_x_axis_steps(
sys_position);
324 sys_position[A_MOTOR] = off_axis_position + set_axis_position;
325 sys_position[B_MOTOR] = off_axis_position - set_axis_position;
#define N_AXIS
Axis array index values. Must start with 0 and be continuous.
uint8_t plan_buffer_line(float *target, plan_line_data_t *pl_data)
Add a new linear movement to the buffer. target[N_AXIS] is the signed, absolute target position in mi...
void limits_init()
Initialize the limits module.
void limits_disable()
Disables hard limits.
void system_convert_array_steps_to_mpos(float *position, int32_t *steps)
Updates a machine 'position' array based on the 'step' array sent.
#define HOMING_AXIS_SEARCH_SCALAR
Homing axis search distance multiplier. Computed by this value times the cycle travel.
void system_set_exec_state_flag(uint8_t mask)
Special handlers for setting and clearing Grbl's real-time execution flags.
Planner data prototype. Must be used when passing new motions to the planner.
#define EXEC_CYCLE_STOP
bitmask 00000100
#define EXEC_ALARM_HOMING_FAIL_DOOR
#define EXEC_ALARM_HOMING_FAIL_APPROACH
volatile uint8_t sys_rt_exec_alarm
Global realtime executor bitflag variable for setting various alarms.
uint8_t state
Tracks the current system state of Grbl.
#define HOMING_AXIS_LOCATE_SCALAR
Must be > 1 to ensure limit switch is cleared.
void limits_go_home(uint8_t cycle_mask)
NOTE: Only the abort realtime command can interrupt this process.
#define EXEC_RESET
bitmask 00010000
#define EXEC_SAFETY_DOOR
bitmask 00100000
#define PL_COND_FLAG_SYSTEM_MOTION
Single motion. Circumvents planner state. Used by home/park.
#define X_AXIS
Axis indexing value.
#define bit(n)
Bit field and masking macros.
uint8_t abort
System abort flag. Forces exit back to main loop for reset.
#define EXEC_ALARM_HOMING_FAIL_RESET
void limits_soft_check(float *target)
Performs a soft limit check. Called from mc_line() only. Assumes the machine has been homed...
#define EXEC_ALARM_SOFT_LIMIT
#define STATE_CYCLE
Cycle is running or motions are being executed.
uint8_t flags
Contains default boolean settings.
#define STATE_ALARM
In alarm state. Locks out all g-code processes. Allows settings access.
system_t sys
Declare system global variable structure.
uint8_t soft_limit
Tracks soft limit errors for the state machine. (boolean)
uint16_t homing_debounce_delay
int32_t sys_position[N_AXIS]
NOTE: These position variables may need to be declared as volatiles, if problems arise.
#define EXEC_ALARM_HOMING_FAIL_PULLOFF
float steps_per_mm[N_AXIS]
void system_clear_exec_state_flag(uint8_t mask)
#define bit_isfalse(x, mask)
uint8_t system_check_travel_limits(float *target)
CoreXY calculation only. Returns x or y-axis "steps" based on CoreXY motor steps. ...
uint8_t step_control
Governs the step segment generator depending on system state.
void st_prep_buffer()
Prepares step segment buffer. Continuously called from main program.
void st_wake_up()
BLOCK VELOCITY PROFILE DEFINITION.
int32_t line_number
Desired line number to report when executing.
uint8_t get_step_pin_mask(uint8_t axis_idx)
Returns step pin mask according to Grbl internal axis indexing.
uint8_t get_limit_pin_mask(uint8_t axis_idx)
Returns limit pin mask according to Grbl internal axis indexing.
#define BITFLAG_HARD_LIMIT_ENABLE
#define EXEC_ALARM_HARD_LIMIT
Alarm executor codes. Valid values (1-255). Zero is reserved.
volatile uint8_t sys_rt_exec_state
Global realtime executor bitflag variable for state management. See EXEC bitmasks.
memset(pl_data, 0, sizeof(plan_line_data_t))
Zero pl_data struct.
uint8_t homing_axis_lock
Locks axes when limits engage. Used as an axis motion mask in the stepper ISR.
#define EXEC_FEED_HOLD
bitmask 00001000
#define STEP_CONTROL_NORMAL_OP
Define step segment generator state flags.
#define HOMING_CYCLE_LINE_NUMBER
System motion commands must have a line number of zero.
#define PL_COND_FLAG_NO_FEED_OVERRIDE
Motion does not honor feed override.
plan_line_data_t plan_data
STEP 4: EXECUTE!! Assumes that all error-checking has been completed and no failure modes exist...
#define N_HOMING_LOCATE_CYCLE
NOTE: The following are two examples to setup homing for 2-axis machines.
void protocol_execute_realtime()
This function is the general interface to Grbl's real-time command execution system. It is called.
float feed_rate
Desired feed rate for line motion. Value is ignored, if rapid motion.
#define BITFLAG_INVERT_LIMIT_PINS
void system_set_exec_alarm(uint8_t code)
uint8_t condition
Bitflag variable to indicate planner conditions. See defines above.
void mc_reset()
Method to ready the system to reset by setting the realtime reset command and killing any...
#define STEP_CONTROL_EXECUTE_SYS_MOTION
void delay_ms(uint16_t ms)
Delays variable defined milliseconds. Compiler compatibility fix for _delay_ms(),.
plan_line_data_t * pl_data
void st_reset()
Reset and clear stepper subsystem variables.
ISR(LIMIT_INT_vect)
This is the Limit Pin Change Interrupt, which handles the hard limit feature. A bouncing.
uint8_t limits_get_state()
Returns limit state as a bit-wise uint8 variable. Each bit indicates an axis limit, where.
#define STATE_IDLE
Define system state bit map. The state variable primarily tracks the individual functions.
#define bit_istrue(x, mask)