// Perform homing cycle to locate and set machine zero. Only '$H' executes this command. // NOTE: There should be no motions in the buffer and Grbl must be in an idle state before // executing the homing cycle. This prevents incorrect buffered plans after homing. void mc_homing_cycle() { sys.state = STATE_HOMING; // Set system state variable limits_disable(); // Disable hard limits pin change register for cycle duration // ------------------------------------------------------------------------------------- // Perform homing routine. NOTE: Special motion case. Only system reset works. // Search to engage all axes limit switches at faster homing seek rate. limits_go_home(HOMING_CYCLE_0); // Homing cycle 0 #ifdef HOMING_CYCLE_1 limits_go_home(HOMING_CYCLE_1); // Homing cycle 1 #endif #ifdef HOMING_CYCLE_2 limits_go_home(HOMING_CYCLE_2); // Homing cycle 2 #endif protocol_execute_runtime(); // Check for reset and set system abort. if (sys.abort) { return; } // Did not complete. Alarm state set by mc_alarm. // Homing cycle complete! Setup system for normal operation. // ------------------------------------------------------------------------------------- // Gcode parser position was circumvented by the limits_go_home() routine, so sync position now. gc_sync_position(); // Set idle state after homing completes and before returning to main program. sys.state = STATE_IDLE; st_go_idle(); // Set idle state after homing completes // If hard limits feature enabled, re-enable hard limits pin change register after homing cycle. limits_init(); }
// Perform homing cycle to locate and set machine zero. Only '$H' executes this command. // NOTE: There should be no motions in the buffer and Grbl must be in an idle state before // executing the homing cycle. This prevents incorrect buffered plans after homing. void mc_homing_cycle(uint8_t cycle_mask) { // Check and abort homing cycle, if hard limits are already enabled. Helps prevent problems // with machines with limits wired on both ends of travel to one limit pin. // TODO: Move the pin-specific LIMIT_PIN call to limits.c as a function. #ifdef LIMITS_TWO_SWITCHES_ON_AXES if (limits_get_state()) { mc_reset(); // Issue system reset and ensure spindle and coolant are shutdown. system_set_exec_alarm(EXEC_ALARM_HARD_LIMIT); return; } #endif limits_disable(); // Disable hard limits pin change register for cycle duration // ------------------------------------------------------------------------------------- // Perform homing routine. NOTE: Special motion case. Only system reset works. #ifdef HOMING_SINGLE_AXIS_COMMANDS if (cycle_mask) { limits_go_home(cycle_mask); } // Perform homing cycle based on mask. else #endif { // Search to engage all axes limit switches at faster homing seek rate. limits_go_home(HOMING_CYCLE_0); // Homing cycle 0 #ifdef HOMING_CYCLE_1 limits_go_home(HOMING_CYCLE_1); // Homing cycle 1 #endif #ifdef HOMING_CYCLE_2 limits_go_home(HOMING_CYCLE_2); // Homing cycle 2 #endif } protocol_execute_realtime(); // Check for reset and set system abort. if (sys.abort) { return; } // Did not complete. Alarm state set by mc_alarm. // Homing cycle complete! Setup system for normal operation. // ------------------------------------------------------------------------------------- // Sync gcode parser and planner positions to homed position. gc_sync_position(); plan_sync_position(); // If hard limits feature enabled, re-enable hard limits pin change register after homing cycle. limits_init(); }
// TODO: Update limits and homing cycle subprograms for better integration with new features. void mc_go_home() { limits_go_home(); // Upon completion, reset all internal position vectors (g-code parser, planner, system) gc_clear_position(); plan_clear_position(); clear_vector_double(sys.position); }
// Perform homing cycle to locate and set machine zero. Only '$H' executes this command. // NOTE: There should be no motions in the buffer and Grbl must be in an idle state before // executing the homing cycle. This prevents incorrect buffered plans after homing. void mc_go_home() { sys.state = STATE_HOMING; // Set system state variable LIMIT_PCMSK &= ~LIMIT_MASK; // Disable hard limits pin change register for cycle duration limits_go_home(); // Perform homing routine. protocol_execute_runtime(); // Check for reset and set system abort. if (sys.abort) { return; } // Did not complete. Alarm state set by mc_alarm. // The machine should now be homed and machine zero has been located. Upon completion, // reset system position and sync internal position vectors. clear_vector_float(sys.position); // Set machine zero sys_sync_current_position(); sys.state = STATE_IDLE; // Set system state to IDLE to complete motion and indicate homed. // 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. /// 8c1 int8_t x_dir, y_dir, z_dir, t_dir; x_dir = y_dir = z_dir = t_dir = 0; if (HOMING_LOCATE_CYCLE & (1<<X_AXIS)) { if (settings.homing_dir_mask & (1<<X_DIRECTION_BIT)) x_dir = 1; else x_dir = -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 (HOMING_LOCATE_CYCLE & (1<<Z_AXIS)) { if (settings.homing_dir_mask & (1<<Z_DIRECTION_BIT)) { z_dir = 1; } else { z_dir = -1; } } /// 8c1 if (HOMING_LOCATE_CYCLE & (1<<T_AXIS)) { if (settings.homing_dir_mask & (1<<T_DIRECTION_BIT)) { t_dir = 1; } else { t_dir = -1; } } /// 8c1 : line mc_line(x_dir*settings.homing_pulloff, y_dir*settings.homing_pulloff, z_dir*settings.homing_pulloff, t_dir*settings.homing_pulloff, settings.homing_seek_rate, false, C_LINE); st_cycle_start(); // Move it. Nothing should be in the buffer except this motion. plan_synchronize(); // Make sure the motion completes. // The gcode parser position circumvented by the pull-off maneuver, so sync position vectors. sys_sync_current_position(); // If hard limits feature enabled, re-enable hard limits pin change register after homing cycle. if (bit_istrue(settings.flags,BITFLAG_HARD_LIMIT_ENABLE)) LIMIT_PCMSK |= LIMIT_MASK; // Finished! }
// Perform homing cycle to locate and set machine zero. Only '$H' executes this command. // NOTE: There should be no motions in the buffer and Grbl must be in an idle state before // executing the homing cycle. This prevents incorrect buffered plans after homing. void mc_go_home() { sys.state = STATE_HOMING; // Set system state variable LIMIT_PCMSK &= ~LIMIT_MASK; // Disable hard limits pin change register for cycle duration limits_go_home(); // Perform homing routine. protocol_execute_runtime(); // Check for reset and set system abort. if (sys.abort) { return; } // Did not complete. Alarm state set by mc_alarm. // The machine should now be homed and machine limits have been located. By default, // grbl defines machine space as all negative, as do most CNCs. Since limit switches // can be on either side of an axes, check and set machine zero appropriately. // At the same time, set up pull-off maneuver from axes limit switches that have been homed. // This provides some initial clearance off the switches and should also help prevent them // from falsely tripping when hard limits are enabled. // TODO: Need to improve dir_mask[] to be more axes independent. float pulloff_target[N_AXIS]; clear_vector_float(pulloff_target); // Zero pulloff target. clear_vector_long(sys.position); // Zero current position for now. uint8_t dir_mask[N_AXIS]; dir_mask[X_AXIS] = (1<<X_DIRECTION_BIT); dir_mask[Y_AXIS] = (1<<Y_DIRECTION_BIT); dir_mask[Z_AXIS] = (1<<Z_DIRECTION_BIT); uint8_t i; for (i=0; i<N_AXIS; i++) { // Set up pull off targets and machine positions for limit switches homed in the negative // direction, rather than the traditional positive. Leave non-homed positions as zero and // do not move them. if (HOMING_LOCATE_CYCLE & bit(i)) { if (settings.homing_dir_mask & dir_mask[i]) { pulloff_target[i] = settings.homing_pulloff-settings.max_travel[i]; sys.position[i] = -lround(settings.max_travel[i]*settings.steps_per_mm[i]); } else { pulloff_target[i] = -settings.homing_pulloff; } } } sys_sync_current_position(); sys.state = STATE_IDLE; // Set system state to IDLE to complete motion and indicate homed. mc_line(pulloff_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. // The gcode parser position circumvented by the pull-off maneuver, so sync position vectors. sys_sync_current_position(); // If hard limits feature enabled, re-enable hard limits pin change register after homing cycle. if (bit_istrue(settings.flags,BITFLAG_HARD_LIMIT_ENABLE)) { LIMIT_PCMSK |= LIMIT_MASK; } // Finished! }
// Perform homing cycle to locate and set machine zero. Only '$H' executes this command. // NOTE: There should be no motions in the buffer and Grbl must be in an idle state before // executing the homing cycle. This prevents incorrect buffered plans after homing. void mc_homing_cycle() { // Check and abort homing cycle, if hard limits are already enabled. Helps prevent problems // with machines with limits wired on both ends of travel to one limit pin. // TODO: Move the pin-specific LIMIT_PIN call to limits.c as a function. #ifdef LIMITS_TWO_SWITCHES_ON_AXES if (limits_get_state()) { mc_reset(); // Issue system reset and ensure spindle and coolant are shutdown. bit_true_atomic(sys_rt_exec_alarm, (EXEC_ALARM_HARD_LIMIT|EXEC_CRITICAL_EVENT)); return; } #endif limits_disable(); // Disable hard limits pin change register for cycle duration // ------------------------------------------------------------------------------------- // Perform homing routine. NOTE: Special motion case. Only system reset works. // Search to engage all axes limit switches at faster homing seek rate. limits_go_home(HOMING_CYCLE_0); // Homing cycle 0 #ifdef HOMING_CYCLE_1 limits_go_home(HOMING_CYCLE_1); // Homing cycle 1 #endif #ifdef HOMING_CYCLE_2 limits_go_home(HOMING_CYCLE_2); // Homing cycle 2 #endif protocol_execute_realtime(); // Check for reset and set system abort. if (sys.abort) { return; } // Did not complete. Alarm state set by mc_alarm. // Homing cycle complete! Setup system for normal operation. // ------------------------------------------------------------------------------------- // Gcode parser position was circumvented by the limits_go_home() routine, so sync position now. gc_sync_position(); // If hard limits feature enabled, re-enable hard limits pin change register after homing cycle. limits_init(); }