From d85238cc9b70abc94fd4f07e720f8090468d383c Mon Sep 17 00:00:00 2001 From: Sonny Jeon Date: Sun, 18 Nov 2012 19:52:16 -0700 Subject: [PATCH] Homing search sequence now compile-time option. New defaults.h file. Tidying up. - The homing sequence is now a compile-time option, where a user can choose which axes(s) move in sequence during the search phase. Up to 3 sequences. Works with the locating phase and the pull-off maneuver. - New defaults.h file to store user generated default settings for different machines. Mainly to be used as a central repo, but each set may be select to be compiled in as a config.h define. --- config.h | 48 ++++++++----------- defaults.h | 122 +++++++++++++++++++++++++++++++++++++++++++++++ gcode.c | 16 ++++--- limits.c | 56 +++++++++++++--------- motion_control.c | 66 ++++++++++++++----------- nuts_bolts.h | 1 + 6 files changed, 224 insertions(+), 85 deletions(-) create mode 100644 defaults.h diff --git a/config.h b/config.h index b193850..c0bffa4 100755 --- a/config.h +++ b/config.h @@ -24,6 +24,10 @@ // IMPORTANT: Any changes here requires a full re-compiling of the source code to propagate them. +// Default settings. Used when resetting EEPROM. Change to desired name in defaults.h +#define DEFAULTS_GENERIC + +// Serial baud rate #define BAUD_RATE 9600 // Define pin-assignments @@ -90,34 +94,6 @@ #define PINOUT_PCMSK PCMSK1 // Pin change interrupt register #define PINOUT_MASK ((1<. +*/ + +/* The defaults.h file serves as a central default settings file for different machine + types, from DIY CNC mills to CNC conversions of off-the-shelf machines. The settings + here are supplied by users, so your results may vary. However, this should give you + a good starting point as you get to know your machine and tweak the settings for your + our nefarious needs. */ + +#ifndef defaults_h +#define defaults_h + +#ifdef DEFAULTS_GENERIC + // Grbl generic default settings. Should work across different machines. + #define DEFAULT_X_STEPS_PER_MM 250 + #define DEFAULT_Y_STEPS_PER_MM 250 + #define DEFAULT_Z_STEPS_PER_MM 250 + #define DEFAULT_STEP_PULSE_MICROSECONDS 10 + #define DEFAULT_MM_PER_ARC_SEGMENT 0.1 + #define DEFAULT_RAPID_FEEDRATE 500.0 // mm/min + #define DEFAULT_FEEDRATE 250.0 + #define DEFAULT_ACCELERATION 10*60*60 // 10 mm/sec^2 + #define DEFAULT_JUNCTION_DEVIATION 0.05 // mm + #define DEFAULT_STEPPING_INVERT_MASK ((1< 0) { if (limit_state & (1< 0) { if (limit_state & (1< 0) { if (limit_state & (1< 0) { // Re-approach all switches to re-engage them. - homing_cycle(true, true, true, true, false, settings.homing_feed_rate); + homing_cycle(HOMING_LOCATE_CYCLE, true, false, settings.homing_feed_rate); delay_ms(settings.homing_debounce_delay); } } diff --git a/motion_control.c b/motion_control.c index d5ba8c9..2d595c8 100755 --- a/motion_control.c +++ b/motion_control.c @@ -49,6 +49,13 @@ // backlash segment(s). void mc_line(float x, float y, float z, float feed_rate, uint8_t invert_feed_rate) { + // TODO: 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 in check gcode mode, prevent motion by blocking planner. + if (sys.state == STATE_CHECK_MODE) { return; } + // TODO: Backlash compensation may be installed here. Only need direction info to track when // to insert a backlash line motion(s) before the intended line motion. Requires its own // plan_check_full_buffer() and check for system abort loop. Also for position reporting @@ -62,25 +69,21 @@ 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() ); - - // If in check gcode mode, prevent motion by blocking planner. - if (sys.state != STATE_CHECK_MODE) { - plan_buffer_line(x, y, z, 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. - if (!sys.state) { sys.state = STATE_QUEUED; } - - // Auto-cycle start immediately after planner finishes. Enabled/disabled by grbl settings. During - // a feed hold, auto-start is disabled momentarily until the cycle is resumed by the cycle-start - // runtime command. - // NOTE: This is allows the user to decide to exclusively use the cycle start runtime command to - // begin motion or let grbl auto-start it for them. This is useful when: manually cycle-starting - // 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. - if (sys.auto_start) { st_cycle_start(); } - } + plan_buffer_line(x, y, z, 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. + if (!sys.state) { sys.state = STATE_QUEUED; } + + // Auto-cycle start immediately after planner finishes. Enabled/disabled by grbl settings. During + // a feed hold, auto-start is disabled momentarily until the cycle is resumed by the cycle-start + // runtime command. + // NOTE: This is allows the user to decide to exclusively use the cycle start runtime command to + // begin motion or let grbl auto-start it for them. This is useful when: manually cycle-starting + // 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. + if (sys.auto_start) { st_cycle_start(); } } @@ -223,20 +226,29 @@ void mc_go_home() sys_sync_current_position(); sys.state = STATE_IDLE; // Set system state to IDLE to complete motion and indicate homed. - // Pull-off all axes 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. + // 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 = -1; - if (bit_istrue(settings.homing_dir_mask,bit(X_DIRECTION_BIT))) { x_dir = 1; } - if (bit_istrue(settings.homing_dir_mask,bit(Y_DIRECTION_BIT))) { y_dir = 1; } - if (bit_istrue(settings.homing_dir_mask,bit(Z_DIRECTION_BIT))) { z_dir = 1; } + x_dir = y_dir = z_dir = 0; + if (HOMING_LOCATE_CYCLE & (1< #include #include "config.h" +#include "defaults.h" #define false 0 #define true 1