From e455764079ccfa9ae277a8fa0078b0dbb36f3a51 Mon Sep 17 00:00:00 2001 From: chamnit Date: Sat, 28 Jan 2017 17:13:06 -0700 Subject: [PATCH 1/3] v1.1f. Parking override control. Spindle enable pin option. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit [ver] v1.1f update due to tweaks to interface from new parking override control. [new] Parking motion override control via new `M56 P0` and `M56 P1` command, which disables and enables the parking motion, respectively. Requires ENABLE_PARKING_OVERRIDE_CONTROL and PARKING_ENABLE enabled in config.h. Primarily for OEMs. [new] `M56` appears in the $G report when enabled. [new] Five new build info identification letters. Some were missing and a couple are new. Updated the CSV and documentation to reflect these new items. [new] Spindle enable pin configuration option to alter its behavior based on how certain lasers work. By default, Grbl treats the enable pin separately and leaves it on when S is 0. The new option turns the enable pin on and off with S>0 and S=0. This only is in effect when a user enables the USE_SPINDLE_DIR_AS_ENABLE_PIN option. [fix] M4 is now allowed to work when USE_SPINDLE_DIR_AS_ENABLE_PIN is enabled. Previously this was blocked and was problematic for laser folks using M4. [fix] Properly declared system variables as extern. Not sure how that went unnoticed or why it worked up until now but it has. [fix] EXTREMELY RARE. When AMASS is intentionally disabled and sent a motion command that is _one step_ in length, Grbl would not actuate the step due to numerical round-off. Applied a fix to prevent the round-off issue. [fix] Added a compile-time check for AMASS settings to make sure that the numerical round-off issue doesn’t effect it. This would only happen if someone set AMASS max levels to zero. It does not effect AMASS with its current defaults. [fix] Wrapped the mc_parking_motion() function in an ifdef for porting purposes. [fix] Fixed an issue when in inverse time mode and G0’s would require a F word. This was not correct. [fix] Added a note in the defaults.h file that MAX_TRAVEL values must be positive. Some users were setting this negative and it was causing issues. --- doc/csv/build_option_codes_en_US.csv | 7 +++- doc/log/commit_log_v1.1.txt | 17 ++++++++ doc/markdown/change_summary.md | 4 +- doc/markdown/commands.md | 5 ++- doc/markdown/interface.md | 11 +++-- doc/markdown/laser_mode.md | 14 +++---- grbl/config.h | 17 +++++++- grbl/defaults.h | 60 ++++++++++++++-------------- grbl/gcode.c | 35 +++++++++++----- grbl/gcode.h | 10 +++-- grbl/grbl.h | 15 ++++++- grbl/main.c | 7 ++++ grbl/motion_control.c | 55 +++++++++++++++---------- grbl/motion_control.h | 3 ++ grbl/protocol.c | 18 ++++++++- grbl/report.c | 22 ++++++++++ grbl/spindle_control.c | 26 +++++++++--- grbl/stepper.c | 20 ++++++---- grbl/system.h | 19 +++++---- 19 files changed, 261 insertions(+), 104 deletions(-) diff --git a/doc/csv/build_option_codes_en_US.csv b/doc/csv/build_option_codes_en_US.csv index 49761e3..5653440 100644 --- a/doc/csv/build_option_codes_en_US.csv +++ b/doc/csv/build_option_codes_en_US.csv @@ -8,9 +8,14 @@ "H","Homing single axis commands","Enabled" "L","Two limit switches on axis","Enabled" "A","Allow feed rate overrides in probe cycles","Enabled" +"D","Use spindle direction as enable pin","Enabled" +"0","Spindle enable off when speed is zero","Enabled" +"S","Software limit pin debouncing","Enabled" +"R","Parking override control","Enabled" "*","Restore all EEPROM command","Disabled" "$","Restore EEPROM `$` settings command","Disabled" "#","Restore EEPROM parameter data command","Disabled" "I","Build info write user string command","Disabled" "E","Force sync upon EEPROM write","Disabled" -"W","Force sync upon work coordinate offset change","Disabled" \ No newline at end of file +"W","Force sync upon work coordinate offset change","Disabled" +"L","Homing initialization auto-lock","Disabled" \ No newline at end of file diff --git a/doc/log/commit_log_v1.1.txt b/doc/log/commit_log_v1.1.txt index f1cdcfc..7fa209d 100644 --- a/doc/log/commit_log_v1.1.txt +++ b/doc/log/commit_log_v1.1.txt @@ -1,3 +1,20 @@ +---------------- +Date: 2017-01-14 +Author: Sonny Jeon +Subject: Tool number bug fix. Updated documentation. + +- [fix] Tool numbers were not being tracked and reported correctly. Now +shows tool number values in $G when programmed. + +- [fix] Added a max tool number value check to the g-code parser. + +- [doc] Added a new error code for invalid tool number. Updated CSV and +interface documents. + +- [doc] Added a implementation note for buffer state in status reports. +Don’t rely on this data for streaming. + + ---------------- Date: 2017-01-03 Author: Sonny Jeon diff --git a/doc/markdown/change_summary.md b/doc/markdown/change_summary.md index f3bd328..7825676 100644 --- a/doc/markdown/change_summary.md +++ b/doc/markdown/change_summary.md @@ -109,4 +109,6 @@ On a final note, these interface tweaks came about out of necessity, because mor - `$J=line` New jogging commands. This command behaves much like a normal G1 command, but there are some key differences. Jog commands don't alter the g-code parser state, meaning a GUI doesn't have to manage it anymore. Jog commands may be queued and cancelled at any time, where they are automatically flushed from the planner buffer without requiring a reset. See the jogging documentation on how they work and how they may be used to implement a low-latency joystick or rotary dial. - Laser mode `$` setting - When enabled, laser mode will move through consecutive G1, G2, and G3 motion commands that have different spindle speed values without stopping. A spindle speed of zero will disable the laser without stopping as well. However, when spindle states change, like M3 or M5, stops are still enforced. - - NOTE: Parking motions are automatically disabled when laser mode is enabled to prevent burning. \ No newline at end of file + - NOTE: Parking motions are automatically disabled when laser mode is enabled to prevent burning. + +- `G56 P1` and `G56 P0` - When enabled in config.h with Grbl's parking motion, these commands enable and disable, respectively, the parking motion. Like all override control commands, these commands are modal and are part of the g-code stream. \ No newline at end of file diff --git a/doc/markdown/commands.md b/doc/markdown/commands.md index b0f7c27..5facba9 100644 --- a/doc/markdown/commands.md +++ b/doc/markdown/commands.md @@ -64,7 +64,7 @@ This command prints all of the active gcode modes in Grbl's G-code parser. When These active modes determine how the next G-code block or command will be interpreted by Grbl's G-code parser. For those new to G-code and CNC machining, modes sets the parser into a particular state so you don't have to constantly tell the parser how to parse it. These modes are organized into sets called "modal groups" that cannot be logically active at the same time. For example, the units modal group sets whether your G-code program is interpreted in inches or in millimeters. -A short list of the modal groups, supported by Grbl, is shown below, but more complete and detailed descriptions can be found at LinuxCNC's [website](http://www.linuxcnc.org/docs/2.4/html/gcode_overview.html#sec:Modal-Groups). The G-code commands in **bold** indicate the default modes upon powering-up Grbl or resetting it. +A short list of the modal groups, supported by Grbl, is shown below, but more complete and detailed descriptions can be found at LinuxCNC's [website](http://www.linuxcnc.org/docs/2.4/html/gcode_overview.html#sec:Modal-Groups). The G-code commands in **bold** indicate the default modes upon powering-up Grbl or resetting it. The commands in _italics_ indicate a special Grbl-only command. | Modal Group Meaning | Member Words | |:----:|:----:| @@ -80,6 +80,9 @@ A short list of the modal groups, supported by Grbl, is shown below, but more co |Program Mode | **M0**, M1, M2, M30| |Spindle State |M3, M4, **M5**| |Coolant State | M7, M8, **M9** | +|Override Control | _M56_ | + +Grbl supports a special _M56_ override control command, where this enables and disables Grbl's parking motion when a `P1` or a `P0` is passed with `M56`, respectively. This command is only available when both parking and this particular option is enabled. In addition to the G-code parser modes, Grbl will report the active `T` tool number, `S` spindle speed, and `F` feed rate, which all default to 0 upon a reset. For those that are curious, these don't quite fit into nice modal groups, but are just as important for determining the parser state. diff --git a/doc/markdown/interface.md b/doc/markdown/interface.md index 51402ec..850d9d2 100644 --- a/doc/markdown/interface.md +++ b/doc/markdown/interface.md @@ -62,11 +62,9 @@ The real-time control commands, `~` cycle start/resume, `!` feed hold, `^X` sof One important note are the override command characters. These are defined in the extended-ASCII character space and are generally not type-able on a keyboard. A GUI must be able to send these 8-bit values to support overrides. #### EEPROM Issues -EEPROM access on the Arduino AVR CPUs turns off all of the interrupts while the CPU reads and writes to EEPROM. This poses a problem for certain features in Grbl, particularly if a user is streaming and running a g-code program, since it can pause the main step generator interrupt from executing on time. Most of the EEPROM access is restricted by Grbl when it's in certain states, but there are some things that developers need to know. +EEPROM access on the Arduino AVR CPUs turns off all of the interrupts while the CPU _writes_ to EEPROM. This poses a problem for certain features in Grbl, particularly if a user is streaming and running a g-code program, since it can pause the main step generator interrupt from executing on time. Most of the EEPROM access is restricted by Grbl when it's in certain states, but there are some things that developers need to know. -* Settings should not be streamed with the character-counting streaming protocols. Only the simple send-response protocol works. This is because during the EEPROM write, the AVR CPU also shuts-down the serial RX interrupt, which means data can get corrupted or lost. - -* When changing work coordinates or accessing the `G28`/`G30` predefined positions, Grbl has to fetch them from EEPROM. There is a small chance this access can pause the stepper or serial receive interrupt long enough to cause motion issues, but since it only fetches 12 bytes at a time at 2 cycles per fetch, the chances are very small that this will do anything to how Grbl runs. We just suggest keeping an eye on this and report to us any issues you might think are related to this. +* Settings should not be streamed with the character-counting streaming protocols. Only the simple send-response protocol works. This is because during the EEPROM write, the AVR CPU also shuts-down the serial RX interrupt, which means data can get corrupted or lost. This is safe with the send-response protocol, because it's not sending data after commanding Grbl to save data. For reference: * Grbl's EEPROM write commands: `G10 L2`, `G10 L20`, `G28.1`, `G30.1`, `$x=`, `$I=`, `$Nx=`, `$RST=` @@ -429,6 +427,10 @@ Feedback messages provide non-critical information on what Grbl is doing, what i | **`Z`** | Homing force origin enabled | | **`H`** | Homing single axis enabled | | **`L`** | Two limit switches on axis enabled | +| **`D`** | Spindle direction pin used as enable pin | +| **`0`** | Spindle enable off when speed is zero enabled | +| **`S`** | Software limit pin debouncing enabled | +| **`R`** | Parking override control enabled | | **`A`** | Allow feed rate overrides in probe cycles | | **`*`** | Restore all EEPROM disabled | | **`$`** | Restore EEPROM `$` settings disabled | @@ -436,6 +438,7 @@ Feedback messages provide non-critical information on what Grbl is doing, what i | **`I`** | Build info write user string disabled | | **`E`** | Force sync upon EEPROM write disabled | | **`W`** | Force sync upon work coordinate offset change disabled | +| **`L`** | Homing initialization auto-lock disabled | - `[echo:]` : Indicates an automated line echo from a command just prior to being parsed and executed. May be enabled only by a config.h option. Often used for debugging communication issues. A typical line echo message is shown below. A separate `ok` will eventually appear to confirm the line has been parsed and executed, but may not be immediate as with any line command containing motions. ``` diff --git a/doc/markdown/laser_mode.md b/doc/markdown/laser_mode.md index d1b362d..4e42ba3 100644 --- a/doc/markdown/laser_mode.md +++ b/doc/markdown/laser_mode.md @@ -4,7 +4,7 @@ ---- -Outlined in this document is how Grbl alters its running conditions for the new laser mode to provide both improved performance and enforcing some basic user safety precautions. +Outlined in this document is how Grbl alters its running conditions for the new laser mode to provide both improved performance and attempting to enforce some basic user safety precautions. ## Laser Mode Overview @@ -29,16 +29,16 @@ The laser is enabled with the `M3` spindle CW and `M4` spindle CCW commands. The - **`M3` Constant Laser Power Mode:** - - Constant laser power mode simply keeps the laser power as programmed, regardless if the machine is moving, accelerating, or stopped. This provides better control of the laser state. With a good g-code program, this can lead to more consistent cuts in more difficult materials. + - Constant laser power mode simply keeps the laser power as programmed, regardless if the machine is moving, accelerating, or stopped. This provides better control of the laser state. With a good G-code program, this can lead to more consistent cuts in more difficult materials. - For a clean cut and prevent scorching with `M3` constant power mode, it's a good idea to add lead-in and lead-out motions around the line you want to cut to give some space for the machine to accelerate and decelerate. - NOTE: `M3` can be used to keep the laser on for focusing. - **`M4` Dynamic Laser Power Mode:** - - Dynamic laser power mode will automatically adjust laser power based on the current speed relative to the programmed rate. It'll essentially ensures the amount of laser energy along a cut is consistent even though the machine may be stopped or actively accelerating. This is very useful for clean, precise engraving and cutting on simple materials across a large range of g-code generation methods by CAM programs. It will generally run faster and may be all you need to use. + - Dynamic laser power mode will automatically adjust laser power based on the current speed relative to the programmed rate. It essentially ensures the amount of laser energy along a cut is consistent even though the machine may be stopped or actively accelerating. This is very useful for clean, precise engraving and cutting on simple materials across a large range of G-code generation methods by CAM programs. It will generally run faster and may be all you need to use. - - Grbl calculates laser power based on the assumption that laser power is linear with speed and the material. Often, this is not the case. Lasers can cut differently at varying power levels and some materials may not cut well at a particular speed and/power. In short, this means that dynamic power mode may not work for all situations. Always do a test piece prior to using this with a new material or machine. + - Grbl calculates laser power based on the assumption that laser power is linear with speed and the material. Often, this is not the case. Lasers can cut differently at varying power levels and some materials may not cut well at a particular speed and/power. In short, this means that dynamic power mode may not work for all situations. Always do a test piece prior to using this with a new material or machine. - When not in motion, `M4` dynamic mode turns off the laser. It only turns on when the machine moves. This generally makes the laser safer to operate, because, unlike `M3`, it will never burn a hole through your table, if you stop and forget to turn `M3` off in time. @@ -70,7 +70,7 @@ Describe below are the operational changes to Grbl when laser mode is enabled. P - To have the laser powered during a jog motion, first enable a valid motion mode and spindle state. The following jog motions will inherit and maintain the previous laser state. Please use with caution though. This ability is primarily to allow turning on the laser on a _very low_ power to use the laser dot to jog and visibly locate the start position of a job. -- A `S0` spindle speed of zero will turn off the laser. When programmed with a valid laser motion, Grbl will disable the laser instantaneously without stopping for the duration of that motion and future motions until set greater than zero.. +- An `S0` spindle speed of zero will turn off the laser. When programmed with a valid laser motion, Grbl will disable the laser instantaneously without stopping for the duration of that motion and future motions until set greater than zero.. - `M3` constant laser mode, this is a great way to turn off the laser power while continuously moving between a `G1` laser motion and a `G0` rapid motion without having to stop. Program a short `G1 S0` motion right before the `G0` motion and a `G1 Sxxx` motion is commanded right after to go back to cutting. @@ -78,12 +78,12 @@ Describe below are the operational changes to Grbl when laser mode is enabled. P ----- ###CAM Developer Implementation Notes -TODO: Add some suggestions on how to write laser g-code for Grbl. +TODO: Add some suggestions on how to write laser G-code for Grbl. - When using `M3` constant laser power mode, try to avoid force-sync conditions during a job whenever possible. Basically every spindle speed change must be accompanied by a valid motion. Any motion is fine, since Grbl will automatically enable and disable the laser based on the modal state. Avoid a `G0` and `G1` command with no axis words in this mode and in the middle of a job. - Ensure smooth motions throughout by turning the laser on and off without an `M3 M4 M5` spindle state command. There are two ways to do this: - - _Program a zero spindle speed `S0`_: `S0` is valid g-code and turns off the spindle/laser without changing the spindle state. In laser mode, Grbl will smoothly move through consecutive motions and turn off the spindle. Conversely, you can turn on the laser with a spindle speed `S` greater than zero. Remember that `M3` constant power mode requires any spindle speed `S` change to be programmed with a motion to allow continuous motion, while `M4` dynamic power mode does not. + - _Program a zero spindle speed `S0`_: `S0` is valid G-code and turns off the spindle/laser without changing the spindle state. In laser mode, Grbl will smoothly move through consecutive motions and turn off the spindle. Conversely, you can turn on the laser with a spindle speed `S` greater than zero. Remember that `M3` constant power mode requires any spindle speed `S` change to be programmed with a motion to allow continuous motion, while `M4` dynamic power mode does not. - _Program an unpowered motion between powered motions_: If you are traversing between parts of a raster job that don't need to have the laser powered, program a `G0` rapid between them. `G0` enforces the laser to be disabled automatically. The last spindle speed programmed doesn't change, so if a valid powered motion, like a `G1` is executed after, it'll immediately re-power the laser with the last programmed spindle speed when executing that motion. diff --git a/grbl/config.h b/grbl/config.h index 6697735..83d072b 100644 --- a/grbl/config.h +++ b/grbl/config.h @@ -353,12 +353,20 @@ // preserve I/O pins. For certain setups, these may need to be separate pins. This configure option uses // the spindle direction pin(D13) as a separate spindle enable pin along with spindle speed PWM on pin D11. // NOTE: This configure option only works with VARIABLE_SPINDLE enabled and a 328p processor (Uno). -// NOTE: With no direction pin, the spindle clockwise M4 g-code command will be removed. M3 and M5 still work. +// NOTE: Without a direction pin, M4 will not have a pin output to indicate a difference with M3. // NOTE: BEWARE! The Arduino bootloader toggles the D13 pin when it powers up. If you flash Grbl with // a programmer (you can use a spare Arduino as "Arduino as ISP". Search the web on how to wire this.), // this D13 LED toggling should go away. We haven't tested this though. Please report how it goes! // #define USE_SPINDLE_DIR_AS_ENABLE_PIN // Default disabled. Uncomment to enable. +// Alters the behavior of the spindle enable pin with the USE_SPINDLE_DIR_AS_ENABLE_PIN option . By default, +// Grbl will not disable the enable pin if spindle speed is zero and M3/4 is active, but still sets the PWM +// output to zero. This allows the users to know if the spindle is active and use it as an additional control +// input. However, in some use cases, user may want the enable pin to disable with a zero spindle speed and +// re-enable when spindle speed is greater than zero. This option does that. +// NOTE: Requires USE_SPINDLE_DIR_AS_ENABLE_PIN to be enabled. +// #define SPINDLE_ENABLE_OFF_WITH_ZERO_SPEED // Default disabled. Uncomment to enable. + // With this enabled, Grbl sends back an echo of the line it has received, which has been pre-parsed (spaces // removed, capitalized letters, no comments) and is to be immediately executed by Grbl. Echoes will not be // sent upon a line buffer overflow, but should for all normal lines sent to Grbl. For example, if a user @@ -563,6 +571,13 @@ #define PARKING_PULLOUT_INCREMENT 5.0 // Spindle pull-out and plunge distance in mm. Incremental distance. // Must be positive value or equal to zero. +// Enables a special set of M-code commands that enables and disables the parking motion. +// These are controlled by `M56`, `M56 P1`, or `M56 Px` to enable and `M56 P0` to disable. +// The command is modal and will be set after a planner sync. Since it is g-code, it is +// executed in sync with g-code commands. It is not a real-time command. +// NOTE: PARKING_ENABLE is required. +// #define ENABLE_PARKING_OVERRIDE_CONTROL // Default disabled. Uncomment to enable + // This option will automatically disable the laser during a feed hold by invoking a spindle stop // override immediately after coming to a stop. However, this also means that the laser still may // be reenabled by disabling the spindle stop override, if needed. This is purely a safety feature diff --git a/grbl/defaults.h b/grbl/defaults.h index 480d875..84508f2 100644 --- a/grbl/defaults.h +++ b/grbl/defaults.h @@ -38,9 +38,9 @@ #define DEFAULT_X_ACCELERATION (10.0*60*60) // 10*60*60 mm/min^2 = 10 mm/sec^2 #define DEFAULT_Y_ACCELERATION (10.0*60*60) // 10*60*60 mm/min^2 = 10 mm/sec^2 #define DEFAULT_Z_ACCELERATION (10.0*60*60) // 10*60*60 mm/min^2 = 10 mm/sec^2 - #define DEFAULT_X_MAX_TRAVEL 200.0 // mm - #define DEFAULT_Y_MAX_TRAVEL 200.0 // mm - #define DEFAULT_Z_MAX_TRAVEL 200.0 // mm + #define DEFAULT_X_MAX_TRAVEL 200.0 // mm NOTE: Must be a positive value. + #define DEFAULT_Y_MAX_TRAVEL 200.0 // mm NOTE: Must be a positive value. + #define DEFAULT_Z_MAX_TRAVEL 200.0 // mm NOTE: Must be a positive value. #define DEFAULT_SPINDLE_RPM_MAX 1000.0 // rpm #define DEFAULT_SPINDLE_RPM_MIN 0.0 // rpm #define DEFAULT_STEP_PULSE_MICROSECONDS 10 @@ -80,9 +80,9 @@ #define DEFAULT_X_ACCELERATION (50.0*60*60) // 50*60*60 mm/min^2 = 50 mm/sec^2 #define DEFAULT_Y_ACCELERATION (50.0*60*60) // 50*60*60 mm/min^2 = 50 mm/sec^2 #define DEFAULT_Z_ACCELERATION (50.0*60*60) // 50*60*60 mm/min^2 = 50 mm/sec^2 - #define DEFAULT_X_MAX_TRAVEL 225.0 // mm - #define DEFAULT_Y_MAX_TRAVEL 125.0 // mm - #define DEFAULT_Z_MAX_TRAVEL 170.0 // mm + #define DEFAULT_X_MAX_TRAVEL 225.0 // mm NOTE: Must be a positive value. + #define DEFAULT_Y_MAX_TRAVEL 125.0 // mm NOTE: Must be a positive value. + #define DEFAULT_Z_MAX_TRAVEL 170.0 // mm NOTE: Must be a positive value. #define DEFAULT_SPINDLE_RPM_MAX 2800.0 // rpm #define DEFAULT_SPINDLE_RPM_MIN 0.0 // rpm #define DEFAULT_STEP_PULSE_MICROSECONDS 10 @@ -125,9 +125,9 @@ #define DEFAULT_X_ACCELERATION (15.0*60*60) // 15*60*60 mm/min^2 = 15 mm/sec^2 #define DEFAULT_Y_ACCELERATION (15.0*60*60) // 15*60*60 mm/min^2 = 15 mm/sec^2 #define DEFAULT_Z_ACCELERATION (15.0*60*60) // 15*60*60 mm/min^2 = 15 mm/sec^2 - #define DEFAULT_X_MAX_TRAVEL 200.0 // mm - #define DEFAULT_Y_MAX_TRAVEL 200.0 // mm - #define DEFAULT_Z_MAX_TRAVEL 200.0 // mm + #define DEFAULT_X_MAX_TRAVEL 200.0 // mm NOTE: Must be a positive value. + #define DEFAULT_Y_MAX_TRAVEL 200.0 // mm NOTE: Must be a positive value. + #define DEFAULT_Z_MAX_TRAVEL 200.0 // mm NOTE: Must be a positive value. #define DEFAULT_SPINDLE_RPM_MAX 10000.0 // rpm #define DEFAULT_SPINDLE_RPM_MIN 0.0 // rpm #define DEFAULT_STEP_PULSE_MICROSECONDS 10 @@ -170,9 +170,9 @@ #define DEFAULT_X_ACCELERATION (250.0*60*60) // 25*60*60 mm/min^2 = 25 mm/sec^2 #define DEFAULT_Y_ACCELERATION (250.0*60*60) // 25*60*60 mm/min^2 = 25 mm/sec^2 #define DEFAULT_Z_ACCELERATION (50.0*60*60) // 25*60*60 mm/min^2 = 25 mm/sec^2 - #define DEFAULT_X_MAX_TRAVEL 290.0 // mm - #define DEFAULT_Y_MAX_TRAVEL 290.0 // mm - #define DEFAULT_Z_MAX_TRAVEL 100.0 // mm + #define DEFAULT_X_MAX_TRAVEL 290.0 // mm NOTE: Must be a positive value. + #define DEFAULT_Y_MAX_TRAVEL 290.0 // mm NOTE: Must be a positive value. + #define DEFAULT_Z_MAX_TRAVEL 100.0 // mm NOTE: Must be a positive value. #define DEFAULT_SPINDLE_RPM_MAX 10000.0 // rpm #define DEFAULT_SPINDLE_RPM_MIN 0.0 // rpm #define DEFAULT_STEP_PULSE_MICROSECONDS 10 @@ -214,9 +214,9 @@ #define DEFAULT_X_ACCELERATION (400.0*60*60) // 400*60*60 mm/min^2 = 400 mm/sec^2 #define DEFAULT_Y_ACCELERATION (400.0*60*60) // 400*60*60 mm/min^2 = 400 mm/sec^2 #define DEFAULT_Z_ACCELERATION (400.0*60*60) // 400*60*60 mm/min^2 = 400 mm/sec^2 - #define DEFAULT_X_MAX_TRAVEL 425.0 // mm - #define DEFAULT_Y_MAX_TRAVEL 465.0 // mm - #define DEFAULT_Z_MAX_TRAVEL 80.0 // mm + #define DEFAULT_X_MAX_TRAVEL 425.0 // mm NOTE: Must be a positive value. + #define DEFAULT_Y_MAX_TRAVEL 465.0 // mm NOTE: Must be a positive value. + #define DEFAULT_Z_MAX_TRAVEL 80.0 // mm NOTE: Must be a positive value. #define DEFAULT_SPINDLE_RPM_MAX 10000.0 // rpm #define DEFAULT_SPINDLE_RPM_MIN 0.0 // rpm #define DEFAULT_STEP_PULSE_MICROSECONDS 10 @@ -259,9 +259,9 @@ #define DEFAULT_X_ACCELERATION (500.0*60*60) // 25*60*60 mm/min^2 = 25 mm/sec^2 #define DEFAULT_Y_ACCELERATION (500.0*60*60) // 25*60*60 mm/min^2 = 25 mm/sec^2 #define DEFAULT_Z_ACCELERATION (50.0*60*60) // 25*60*60 mm/min^2 = 25 mm/sec^2 - #define DEFAULT_X_MAX_TRAVEL 290.0 // mm - #define DEFAULT_Y_MAX_TRAVEL 290.0 // mm - #define DEFAULT_Z_MAX_TRAVEL 100.0 // mm + #define DEFAULT_X_MAX_TRAVEL 290.0 // mm NOTE: Must be a positive value. + #define DEFAULT_Y_MAX_TRAVEL 290.0 // mm NOTE: Must be a positive value. + #define DEFAULT_Z_MAX_TRAVEL 100.0 // mm NOTE: Must be a positive value. #define DEFAULT_SPINDLE_RPM_MAX 10000.0 // rpm #define DEFAULT_SPINDLE_RPM_MIN 0.0 // rpm #define DEFAULT_STEP_PULSE_MICROSECONDS 10 @@ -304,9 +304,9 @@ #define DEFAULT_X_ACCELERATION (500.0*60*60) // 25*60*60 mm/min^2 = 25 mm/sec^2 #define DEFAULT_Y_ACCELERATION (500.0*60*60) // 25*60*60 mm/min^2 = 25 mm/sec^2 #define DEFAULT_Z_ACCELERATION (50.0*60*60) // 25*60*60 mm/min^2 = 25 mm/sec^2 - #define DEFAULT_X_MAX_TRAVEL 740.0 // mm - #define DEFAULT_Y_MAX_TRAVEL 790.0 // mm - #define DEFAULT_Z_MAX_TRAVEL 100.0 // mm + #define DEFAULT_X_MAX_TRAVEL 740.0 // mm NOTE: Must be a positive value. + #define DEFAULT_Y_MAX_TRAVEL 790.0 // mm NOTE: Must be a positive value. + #define DEFAULT_Z_MAX_TRAVEL 100.0 // mm NOTE: Must be a positive value. #define DEFAULT_SPINDLE_RPM_MAX 10000.0 // rpm #define DEFAULT_SPINDLE_RPM_MIN 0.0 // rpm #define DEFAULT_STEP_PULSE_MICROSECONDS 10 @@ -347,9 +347,9 @@ #define DEFAULT_X_ACCELERATION (600.0*60*60) // 600*60*60 mm/min^2 = 600 mm/sec^2 #define DEFAULT_Y_ACCELERATION (600.0*60*60) // 600*60*60 mm/min^2 = 600 mm/sec^2 #define DEFAULT_Z_ACCELERATION (600.0*60*60) // 600*60*60 mm/min^2 = 600 mm/sec^2 - #define DEFAULT_X_MAX_TRAVEL 190.0 // mm - #define DEFAULT_Y_MAX_TRAVEL 180.0 // mm - #define DEFAULT_Z_MAX_TRAVEL 150.0 // mm + #define DEFAULT_X_MAX_TRAVEL 190.0 // mm NOTE: Must be a positive value. + #define DEFAULT_Y_MAX_TRAVEL 180.0 // mm NOTE: Must be a positive value. + #define DEFAULT_Z_MAX_TRAVEL 150.0 // mm NOTE: Must be a positive value. #define DEFAULT_SPINDLE_RPM_MAX 10000.0 // rpm #define DEFAULT_SPINDLE_RPM_MIN 0.0 // rpm #define DEFAULT_STEP_PULSE_MICROSECONDS 10 @@ -386,9 +386,9 @@ #define DEFAULT_X_ACCELERATION (10.0*60*60) // 10*60*60 mm/min^2 = 10 mm/sec^2 #define DEFAULT_Y_ACCELERATION (10.0*60*60) // 10*60*60 mm/min^2 = 10 mm/sec^2 #define DEFAULT_Z_ACCELERATION (10.0*60*60) // 10*60*60 mm/min^2 = 10 mm/sec^2 - #define DEFAULT_X_MAX_TRAVEL 500.0 // mm - #define DEFAULT_Y_MAX_TRAVEL 750.0 // mm - #define DEFAULT_Z_MAX_TRAVEL 80.0 // mm + #define DEFAULT_X_MAX_TRAVEL 500.0 // mm NOTE: Must be a positive value. + #define DEFAULT_Y_MAX_TRAVEL 750.0 // mm NOTE: Must be a positive value. + #define DEFAULT_Z_MAX_TRAVEL 80.0 // mm NOTE: Must be a positive value. #define DEFAULT_SPINDLE_RPM_MAX 1000.0 // rpm #define DEFAULT_SPINDLE_RPM_MIN 0.0 // rpm #define DEFAULT_STEP_PULSE_MICROSECONDS 10 @@ -425,9 +425,9 @@ #define DEFAULT_X_ACCELERATION (100.0*60*60) // 10*60*60 mm/min^2 = 10 mm/sec^2 #define DEFAULT_Y_ACCELERATION (100.0*60*60) // 10*60*60 mm/min^2 = 10 mm/sec^2 #define DEFAULT_Z_ACCELERATION (100.0*60*60) // 10*60*60 mm/min^2 = 10 mm/sec^2 - #define DEFAULT_X_MAX_TRAVEL 1000.0 // mm - #define DEFAULT_Y_MAX_TRAVEL 1000.0 // mm - #define DEFAULT_Z_MAX_TRAVEL 1000.0 // mm + #define DEFAULT_X_MAX_TRAVEL 1000.0 // mm NOTE: Must be a positive value. + #define DEFAULT_Y_MAX_TRAVEL 1000.0 // mm NOTE: Must be a positive value. + #define DEFAULT_Z_MAX_TRAVEL 1000.0 // mm NOTE: Must be a positive value. #define DEFAULT_SPINDLE_RPM_MAX 1000.0 // rpm #define DEFAULT_SPINDLE_RPM_MIN 0.0 // rpm #define DEFAULT_STEP_PULSE_MICROSECONDS 10 diff --git a/grbl/gcode.c b/grbl/gcode.c index 172bced..b456833 100644 --- a/grbl/gcode.c +++ b/grbl/gcode.c @@ -252,16 +252,11 @@ uint8_t gc_execute_line(char *line) default: gc_block.modal.program_flow = int_value; // Program end and reset } break; - #ifndef USE_SPINDLE_DIR_AS_ENABLE_PIN - case 4: - #endif - case 3: case 5: + case 3: case 4: case 5: word_bit = MODAL_GROUP_M7; switch(int_value) { case 3: gc_block.modal.spindle = SPINDLE_ENABLE_CW; break; - #ifndef USE_SPINDLE_DIR_AS_ENABLE_PIN - case 4: gc_block.modal.spindle = SPINDLE_ENABLE_CCW; break; - #endif + case 4: gc_block.modal.spindle = SPINDLE_ENABLE_CCW; break; case 5: gc_block.modal.spindle = SPINDLE_DISABLE; break; } break; @@ -279,6 +274,12 @@ uint8_t gc_execute_line(char *line) case 9: gc_block.modal.coolant = COOLANT_DISABLE; break; } break; + #ifdef ENABLE_PARKING_OVERRIDE_CONTROL + case 56: + word_bit = MODAL_GROUP_M9; + gc_block.modal.override = OVERRIDE_PARKING_MOTION; + break; + #endif default: FAIL(STATUS_GCODE_UNSUPPORTED_COMMAND); // [Unsupported M command] } @@ -395,7 +396,7 @@ uint8_t gc_execute_line(char *line) if (gc_block.modal.feed_rate == FEED_RATE_MODE_INVERSE_TIME) { // = G93 // NOTE: G38 can also operate in inverse time, but is undefined as an error. Missing F word check added here. if (axis_command == AXIS_COMMAND_MOTION_MODE) { - if ((gc_block.modal.motion != MOTION_MODE_NONE) || (gc_block.modal.motion != MOTION_MODE_SEEK)) { + if ((gc_block.modal.motion != MOTION_MODE_NONE) && (gc_block.modal.motion != MOTION_MODE_SEEK)) { if (bit_isfalse(value_words,bit(WORD_F))) { FAIL(STATUS_GCODE_UNDEFINED_FEED_RATE); } // [F word missing] } } @@ -434,7 +435,15 @@ uint8_t gc_execute_line(char *line) // [6. Change tool ]: N/A // [7. Spindle control ]: N/A // [8. Coolant control ]: N/A - // [9. Enable/disable feed rate or spindle overrides ]: NOT SUPPORTED. + // [9. Override control ]: Not supported except for a Grbl-only parking motion override control. + #ifdef ENABLE_PARKING_OVERRIDE_CONTROL + if (gc_block.modal.override == OVERRIDE_PARKING_MOTION) { + if (bit_istrue(value_words,bit(WORD_P))) { + if (gc_block.values.p == 0.0) { gc_block.modal.override = OVERRIDE_DISABLED; } + bit_false(value_words,bit(WORD_P)); + } + } + #endif // [10. Dwell ]: P value missing. P is negative (done.) NOTE: See below. if (gc_block.non_modal_command == NON_MODAL_DWELL) { @@ -949,7 +958,13 @@ uint8_t gc_execute_line(char *line) } pl_data->condition |= gc_state.modal.coolant; // Set condition flag for planner use. - // [9. Enable/disable feed rate or spindle overrides ]: NOT SUPPORTED. Always enabled. + // [9. Override control ]: NOT SUPPORTED. Always enabled. Except for a Grbl-only parking control. + #ifdef ENABLE_PARKING_OVERRIDE_CONTROL + if (gc_state.modal.override != gc_block.modal.override) { + gc_state.modal.override = gc_block.modal.override; + mc_override_ctrl_update(gc_state.modal.override); + } + #endif // [10. Dwell ]: if (gc_block.non_modal_command == NON_MODAL_DWELL) { mc_dwell(gc_block.values.p); } diff --git a/grbl/gcode.h b/grbl/gcode.h index 2fae1de..6cedf5f 100644 --- a/grbl/gcode.h +++ b/grbl/gcode.h @@ -44,10 +44,7 @@ #define MODAL_GROUP_M4 11 // [M0,M1,M2,M30] Stopping #define MODAL_GROUP_M7 12 // [M3,M4,M5] Spindle turning #define MODAL_GROUP_M8 13 // [M7,M8,M9] Coolant control - -// #define OTHER_INPUT_F 14 -// #define OTHER_INPUT_S 15 -// #define OTHER_INPUT_T 16 +#define MODAL_GROUP_M9 14 // [M56] Override control // Define command actions for within execution-type modal groups (motion, stopping, non-modal). Used // internally by the parser to know which command to execute. @@ -126,6 +123,10 @@ #define TOOL_LENGTH_OFFSET_CANCEL 0 // G49 (Default: Must be zero) #define TOOL_LENGTH_OFFSET_ENABLE_DYNAMIC 1 // G43.1 +// Modal Group M9: Override control +#define OVERRIDE_DISABLED 0 // None (Default: Must be zero) +#define OVERRIDE_PARKING_MOTION 1 // G56 (Default: Must be zero) + // Modal Group G12: Active work coordinate system // N/A: Stores coordinate system value (54-59) to change to. @@ -187,6 +188,7 @@ typedef struct { uint8_t program_flow; // {M0,M1,M2,M30} uint8_t coolant; // {M7,M8,M9} uint8_t spindle; // {M3,M4,M5} + uint8_t override; // {M56} } gc_modal_t; typedef struct { diff --git a/grbl/grbl.h b/grbl/grbl.h index d052e6f..221cb43 100644 --- a/grbl/grbl.h +++ b/grbl/grbl.h @@ -22,8 +22,8 @@ #define grbl_h // Grbl versioning system -#define GRBL_VERSION "1.1e" -#define GRBL_VERSION_BUILD "20170114" +#define GRBL_VERSION "1.1f" +#define GRBL_VERSION_BUILD "20170128" // Define standard libraries used by Grbl. #include @@ -76,12 +76,22 @@ #error "USE_SPINDLE_DIR_AS_ENABLE_PIN may only be used with a 328p processor" #endif +#if !defined(USE_SPINDLE_DIR_AS_ENABLE_PIN) && defined(SPINDLE_ENABLE_OFF_WITH_ZERO_SPEED) + #error "SPINDLE_ENABLE_OFF_WITH_ZERO_SPEED may only be used with USE_SPINDLE_DIR_AS_ENABLE_PIN enabled" +#endif + #if defined(PARKING_ENABLE) #if defined(HOMING_FORCE_SET_ORIGIN) #error "HOMING_FORCE_SET_ORIGIN is not supported with PARKING_ENABLE at this time." #endif #endif +#if defined(ENABLE_PARKING_OVERRIDE_CONTROL) + #if !defined(PARKING_ENABLE) + #error "ENABLE_PARKING_OVERRIDE_CONTROL must be enabled with PARKING_ENABLE." + #endif +#endif + #if defined(SPINDLE_PWM_MIN_VALUE) #if !(SPINDLE_PWM_MIN_VALUE > 0) #error "SPINDLE_PWM_MIN_VALUE must be greater than zero." @@ -100,6 +110,7 @@ #if (REPORT_OVR_REFRESH_IDLE_COUNT < 1) #error "Override refresh must be greater than zero." #endif + // --------------------------------------------------------------------------------------- #endif diff --git a/grbl/main.c b/grbl/main.c index be0b4ac..0085c2d 100644 --- a/grbl/main.c +++ b/grbl/main.c @@ -24,6 +24,13 @@ // Declare system global variable structure system_t sys; +int32_t sys_position[N_AXIS]; // Real-time machine (aka home) position vector in steps. +int32_t sys_probe_position[N_AXIS]; // Last probe position in machine coordinates and steps. +volatile uint8_t sys_probe_state; // Probing state value. Used to coordinate the probing cycle with stepper ISR. +volatile uint8_t sys_rt_exec_state; // Global realtime executor bitflag variable for state management. See EXEC bitmasks. +volatile uint8_t sys_rt_exec_alarm; // Global realtime executor bitflag variable for setting various alarms. +volatile uint8_t sys_rt_exec_motion_override; // Global realtime executor bitflag variable for motion-based overrides. +volatile uint8_t sys_rt_exec_accessory_override; // Global realtime executor bitflag variable for spindle/coolant overrides. int main(void) diff --git a/grbl/motion_control.c b/grbl/motion_control.c index 4127106..28c5573 100644 --- a/grbl/motion_control.c +++ b/grbl/motion_control.c @@ -313,29 +313,42 @@ uint8_t mc_probe_cycle(float *target, plan_line_data_t *pl_data, uint8_t parser_ // Plans and executes the single special motion case for parking. Independent of main planner buffer. // NOTE: Uses the always free planner ring buffer head to store motion parameters for execution. -void mc_parking_motion(float *parking_target, plan_line_data_t *pl_data) -{ - if (sys.abort) { return; } // Block during abort. - - uint8_t plan_status = plan_buffer_line(parking_target, pl_data); - - if (plan_status) { - bit_true(sys.step_control, STEP_CONTROL_EXECUTE_SYS_MOTION); - bit_false(sys.step_control, STEP_CONTROL_END_MOTION); // Allow parking motion to execute, if feed hold is active. - st_parking_setup_buffer(); // Setup step segment buffer for special parking motion case - st_prep_buffer(); - st_wake_up(); - do { - protocol_exec_rt_system(); - if (sys.abort) { return; } - } while (sys.step_control & STEP_CONTROL_EXECUTE_SYS_MOTION); - st_parking_restore_buffer(); // Restore step segment buffer to normal run state. - } else { - bit_false(sys.step_control, STEP_CONTROL_EXECUTE_SYS_MOTION); - protocol_exec_rt_system(); +#ifdef PARKING_ENABLE + void mc_parking_motion(float *parking_target, plan_line_data_t *pl_data) + { + if (sys.abort) { return; } // Block during abort. + + uint8_t plan_status = plan_buffer_line(parking_target, pl_data); + + if (plan_status) { + bit_true(sys.step_control, STEP_CONTROL_EXECUTE_SYS_MOTION); + bit_false(sys.step_control, STEP_CONTROL_END_MOTION); // Allow parking motion to execute, if feed hold is active. + st_parking_setup_buffer(); // Setup step segment buffer for special parking motion case + st_prep_buffer(); + st_wake_up(); + do { + protocol_exec_rt_system(); + if (sys.abort) { return; } + } while (sys.step_control & STEP_CONTROL_EXECUTE_SYS_MOTION); + st_parking_restore_buffer(); // Restore step segment buffer to normal run state. + } else { + bit_false(sys.step_control, STEP_CONTROL_EXECUTE_SYS_MOTION); + protocol_exec_rt_system(); + } + } +#endif -} + +#ifdef ENABLE_PARKING_OVERRIDE_CONTROL + void mc_override_ctrl_update(uint8_t override_state) + { + // Finish all queued commands before altering override control state + protocol_buffer_synchronize(); + if (sys.abort) { return; } + sys.override_ctrl = override_state; + } +#endif // Method to ready the system to reset by setting the realtime reset command and killing any diff --git a/grbl/motion_control.h b/grbl/motion_control.h index 307afeb..0f7531e 100644 --- a/grbl/motion_control.h +++ b/grbl/motion_control.h @@ -54,6 +54,9 @@ void mc_homing_cycle(uint8_t cycle_mask); // Perform tool length probe cycle. Requires probe switch. uint8_t mc_probe_cycle(float *target, plan_line_data_t *pl_data, uint8_t parser_flags); +// Handles updating the override control state. +void mc_override_ctrl_update(uint8_t override_state); + // Plans and executes the single special motion case for parking. Independent of main planner buffer. void mc_parking_motion(float *parking_target, plan_line_data_t *pl_data); diff --git a/grbl/protocol.c b/grbl/protocol.c index 2d5b8d1..bce9f5e 100644 --- a/grbl/protocol.c +++ b/grbl/protocol.c @@ -575,10 +575,16 @@ static void protocol_exec_rt_suspend() // Execute slow pull-out parking retract motion. Parking requires homing enabled, the // current location not exceeding the parking target location, and laser mode disabled. // NOTE: State is will remain DOOR, until the de-energizing and retract is complete. + #ifdef ENABLE_PARKING_OVERRIDE_CONTROL + if ((bit_istrue(settings.flags,BITFLAG_HOMING_ENABLE)) && + (parking_target[PARKING_AXIS] < PARKING_TARGET) && + bit_isfalse(settings.flags,BITFLAG_LASER_MODE) && + !sys.override_ctrl) { + #else if ((bit_istrue(settings.flags,BITFLAG_HOMING_ENABLE)) && (parking_target[PARKING_AXIS] < PARKING_TARGET) && bit_isfalse(settings.flags,BITFLAG_LASER_MODE)) { - + #endif // Retract spindle by pullout distance. Ensure retraction motion moves away from // the workpiece and waypoint motion doesn't exceed the parking target location. if (parking_target[PARKING_AXIS] < retract_waypoint) { @@ -642,7 +648,12 @@ static void protocol_exec_rt_suspend() #ifdef PARKING_ENABLE // Execute fast restore motion to the pull-out position. Parking requires homing enabled. // NOTE: State is will remain DOOR, until the de-energizing and retract is complete. + #ifdef ENABLE_PARKING_OVERRIDE_CONTROL + if (((settings.flags & (BITFLAG_HOMING_ENABLE|BITFLAG_LASER_MODE)) == BITFLAG_HOMING_ENABLE) && + !sys.override_ctrl) { + #else if ((settings.flags & (BITFLAG_HOMING_ENABLE|BITFLAG_LASER_MODE)) == BITFLAG_HOMING_ENABLE) { + #endif // Check to ensure the motion doesn't move below pull-out position. if (parking_target[PARKING_AXIS] <= PARKING_TARGET) { parking_target[PARKING_AXIS] = retract_waypoint; @@ -676,7 +687,12 @@ static void protocol_exec_rt_suspend() #ifdef PARKING_ENABLE // Execute slow plunge motion from pull-out position to resume position. + #ifdef ENABLE_PARKING_OVERRIDE_CONTROL + if (((settings.flags & (BITFLAG_HOMING_ENABLE|BITFLAG_LASER_MODE)) == BITFLAG_HOMING_ENABLE) && + !sys.override_ctrl) { + #else if ((settings.flags & (BITFLAG_HOMING_ENABLE|BITFLAG_LASER_MODE)) == BITFLAG_HOMING_ENABLE) { + #endif // Block if safety door re-opened during prior restore actions. if (bit_isfalse(sys.suspend,SUSPEND_RESTART_RETRACT)) { // Regardless if the retract parking motion was a valid/safe motion or not, the diff --git a/grbl/report.c b/grbl/report.c index 7dd26af..8ca39d5 100644 --- a/grbl/report.c +++ b/grbl/report.c @@ -327,6 +327,13 @@ void report_gcode_modes() else { serial_write('9'); } #endif + #ifdef ENABLE_PARKING_OVERRIDE_CONTROL + if (sys.override_ctrl) { + report_util_gcode_modes_M(); + print_uint8_base10(56); + } + #endif + printPgmString(PSTR(" T")); print_uint8_base10(gc_state.tool); @@ -393,6 +400,18 @@ void report_build_info(char *line) #ifdef ALLOW_FEED_OVERRIDE_DURING_PROBE_CYCLES serial_write('A'); #endif + #ifdef USE_SPINDLE_DIR_AS_ENABLE_PIN + serial_write('D'); + #endif + #ifdef SPINDLE_ENABLE_OFF_WITH_ZERO_SPEED + serial_write('0'); + #endif + #ifdef ENABLE_SOFTWARE_DEBOUNCE + serial_write('S'); + #endif + #ifdef ENABLE_PARKING_OVERRIDE_CONTROL + serial_write('R'); + #endif #ifndef ENABLE_RESTORE_EEPROM_WIPE_ALL // NOTE: Shown when disabled. serial_write('*'); #endif @@ -411,6 +430,9 @@ void report_build_info(char *line) #ifndef FORCE_BUFFER_SYNC_DURING_WCO_CHANGE // NOTE: Shown when disabled. serial_write('W'); #endif + #ifndef HOMING_INIT_LOCK + serial_write('L'); + #endif // NOTE: Compiled values, like override increments/max/min values, may be added at some point later. // These will likely have a comma delimiter to separate them. diff --git a/grbl/spindle_control.c b/grbl/spindle_control.c index 159b77d..a66a868 100644 --- a/grbl/spindle_control.c +++ b/grbl/spindle_control.c @@ -116,11 +116,24 @@ void spindle_stop() void spindle_set_speed(uint8_t pwm_value) { SPINDLE_OCR_REGISTER = pwm_value; // Set PWM output level. - if (pwm_value == SPINDLE_PWM_OFF_VALUE) { - SPINDLE_TCCRA_REGISTER &= ~(1<direction_bits = pl_block->direction_bits; uint8_t idx; #ifndef ADAPTIVE_MULTI_AXIS_STEP_SMOOTHING - for (idx=0; idxsteps[idx] = pl_block->steps[idx]; } - st_prep_block->step_event_count = pl_block->step_event_count; + for (idx=0; idxsteps[idx] = (pl_block->steps[idx] << 1); } + st_prep_block->step_event_count = (pl_block->step_event_count << 1); #else // With AMASS enabled, simply bit-shift multiply all Bresenham data by the max AMASS // level, such that we never divide beyond the original data anywhere in the algorithm. diff --git a/grbl/system.h b/grbl/system.h index 0cbea6b..4d4f612 100644 --- a/grbl/system.h +++ b/grbl/system.h @@ -137,6 +137,9 @@ typedef struct { uint8_t spindle_stop_ovr; // Tracks spindle stop override states uint8_t report_ovr_counter; // Tracks when to add override data to status reports. uint8_t report_wco_counter; // Tracks when to add work coordinate offset data to status reports. + #ifdef ENABLE_PARKING_OVERRIDE_CONTROL + uint8_t override_ctrl; // Tracks override control states. + #endif #ifdef VARIABLE_SPINDLE float spindle_speed; #endif @@ -144,18 +147,18 @@ typedef struct { extern system_t sys; // NOTE: These position variables may need to be declared as volatiles, if problems arise. -int32_t sys_position[N_AXIS]; // Real-time machine (aka home) position vector in steps. -int32_t sys_probe_position[N_AXIS]; // Last probe position in machine coordinates and steps. +extern int32_t sys_position[N_AXIS]; // Real-time machine (aka home) position vector in steps. +extern int32_t sys_probe_position[N_AXIS]; // Last probe position in machine coordinates and steps. -volatile uint8_t sys_probe_state; // Probing state value. Used to coordinate the probing cycle with stepper ISR. -volatile uint8_t sys_rt_exec_state; // Global realtime executor bitflag variable for state management. See EXEC bitmasks. -volatile uint8_t sys_rt_exec_alarm; // Global realtime executor bitflag variable for setting various alarms. -volatile uint8_t sys_rt_exec_motion_override; // Global realtime executor bitflag variable for motion-based overrides. -volatile uint8_t sys_rt_exec_accessory_override; // Global realtime executor bitflag variable for spindle/coolant overrides. +extern volatile uint8_t sys_probe_state; // Probing state value. Used to coordinate the probing cycle with stepper ISR. +extern volatile uint8_t sys_rt_exec_state; // Global realtime executor bitflag variable for state management. See EXEC bitmasks. +extern volatile uint8_t sys_rt_exec_alarm; // Global realtime executor bitflag variable for setting various alarms. +extern volatile uint8_t sys_rt_exec_motion_override; // Global realtime executor bitflag variable for motion-based overrides. +extern volatile uint8_t sys_rt_exec_accessory_override; // Global realtime executor bitflag variable for spindle/coolant overrides. #ifdef DEBUG #define EXEC_DEBUG_REPORT bit(0) - volatile uint8_t sys_rt_exec_debug; + extern volatile uint8_t sys_rt_exec_debug; #endif // Initialize the serial protocol From beaa40583c241f42035e8cadd5fba4319e3d0618 Mon Sep 17 00:00:00 2001 From: Sonny Jeon Date: Sun, 29 Jan 2017 11:35:51 -0700 Subject: [PATCH 2/3] Tidying up parking override control implementation [new] Added a default configuration for the parking override control upon a reset or power-up. By default, parking is enabled, but this may be disabled via a config.h option. [fix] Parking override control should be checking if the command word is passed, rather than the value. --- doc/log/commit_log_v1.1.txt | 53 +++++++++++++++++++++++++++++++++++++ grbl/config.h | 4 ++- grbl/gcode.c | 12 ++++++--- grbl/gcode.h | 9 +++++-- grbl/grbl.h | 2 +- grbl/protocol.c | 6 ++--- grbl/report.c | 2 +- 7 files changed, 77 insertions(+), 11 deletions(-) diff --git a/doc/log/commit_log_v1.1.txt b/doc/log/commit_log_v1.1.txt index 7fa209d..36f1e5e 100644 --- a/doc/log/commit_log_v1.1.txt +++ b/doc/log/commit_log_v1.1.txt @@ -1,3 +1,56 @@ +---------------- +Date: 2017-01-28 +Author: chamnit +Subject: v1.1f. Parking override control. Spindle enable pin option. + +[ver] v1.1f update due to tweaks to interface from new parking override +control. + +[new] Parking motion override control via new `M56 P0` and `M56 P1` +command, which disables and enables the parking motion, respectively. +Requires ENABLE_PARKING_OVERRIDE_CONTROL and PARKING_ENABLE enabled in +config.h. Primarily for OEMs. + +[new] `M56` appears in the $G report when enabled. + +[new] Five new build info identification letters. Some were missing and +a couple are new. Updated the CSV and documentation to reflect these +new items. + +[new] Spindle enable pin configuration option to alter its behavior +based on how certain lasers work. By default, Grbl treats the enable +pin separately and leaves it on when S is 0. The new option turns the +enable pin on and off with S>0 and S=0. This only is in effect when a +user enables the USE_SPINDLE_DIR_AS_ENABLE_PIN option. + +[fix] M4 is now allowed to work when USE_SPINDLE_DIR_AS_ENABLE_PIN is +enabled. Previously this was blocked and was problematic for laser +folks using M4. + +[fix] Properly declared system variables as extern. Not sure how that +went unnoticed or why it worked up until now but it has. + +[fix] EXTREMELY RARE. When AMASS is intentionally disabled and sent a +motion command that is _one step_ in length, Grbl would not actuate the +step due to numerical round-off. Applied a fix to prevent the round-off +issue. + +[fix] Added a compile-time check for AMASS settings to make sure that +the numerical round-off issue doesn’t effect it. This would only happen +if someone set AMASS max levels to zero. It does not effect AMASS with +its current defaults. + +[fix] Wrapped the mc_parking_motion() function in an ifdef for porting +purposes. + +[fix] Fixed an issue when in inverse time mode and G0’s would require a +F word. This was not correct. + +[fix] Added a note in the defaults.h file that MAX_TRAVEL values must +be positive. Some users were setting this negative and it was causing +issues. + + ---------------- Date: 2017-01-14 Author: Sonny Jeon diff --git a/grbl/config.h b/grbl/config.h index 83d072b..063e676 100644 --- a/grbl/config.h +++ b/grbl/config.h @@ -575,8 +575,10 @@ // These are controlled by `M56`, `M56 P1`, or `M56 Px` to enable and `M56 P0` to disable. // The command is modal and will be set after a planner sync. Since it is g-code, it is // executed in sync with g-code commands. It is not a real-time command. -// NOTE: PARKING_ENABLE is required. +// NOTE: PARKING_ENABLE is required. By default, M56 is active upon initialization. Use +// DEACTIVATE_PARKING_UPON_INIT to set M56 P0 as the power-up default. // #define ENABLE_PARKING_OVERRIDE_CONTROL // Default disabled. Uncomment to enable +// #define DEACTIVATE_PARKING_UPON_INIT // Default disabled. Uncomment to enable. // This option will automatically disable the laser during a feed hold by invoking a spindle stop // override immediately after coming to a stop. However, this also means that the laser still may diff --git a/grbl/gcode.c b/grbl/gcode.c index b456833..6075250 100644 --- a/grbl/gcode.c +++ b/grbl/gcode.c @@ -437,7 +437,7 @@ uint8_t gc_execute_line(char *line) // [8. Coolant control ]: N/A // [9. Override control ]: Not supported except for a Grbl-only parking motion override control. #ifdef ENABLE_PARKING_OVERRIDE_CONTROL - if (gc_block.modal.override == OVERRIDE_PARKING_MOTION) { + if (bit_istrue(command_words,bit(MODAL_GROUP_M9))) { // Already set as enabled in parser. if (bit_istrue(value_words,bit(WORD_P))) { if (gc_block.values.p == 0.0) { gc_block.modal.override = OVERRIDE_DISABLED; } bit_false(value_words,bit(WORD_P)); @@ -1102,7 +1102,13 @@ uint8_t gc_execute_line(char *line) gc_state.modal.coord_select = 0; // G54 gc_state.modal.spindle = SPINDLE_DISABLE; gc_state.modal.coolant = COOLANT_DISABLE; - // gc_state.modal.override = OVERRIDE_DISABLE; // Not supported. + #ifdef ENABLE_PARKING_OVERRIDE_CONTROL + #ifdef DEACTIVATE_PARKING_UPON_INIT + gc_state.modal.override = OVERRIDE_DISABLED; + #else + gc_state.modal.override = OVERRIDE_PARKING_MOTION; + #endif + #endif #ifdef RESTORE_OVERRIDES_AFTER_PROGRAM_END sys.f_override = DEFAULT_FEED_OVERRIDE; @@ -1148,7 +1154,7 @@ uint8_t gc_execute_line(char *line) group 7 = {G41, G42} cutter radius compensation (G40 is supported) group 8 = {G43} tool length offset (G43.1/G49 are supported) group 8 = {M7*} enable mist coolant (* Compile-option) - group 9 = {M48, M49} enable/disable feed and speed override switches + group 9 = {M48, M49, M56*} enable/disable override switches (* Compile-option) group 10 = {G98, G99} return mode canned cycles group 13 = {G61.1, G64} path control mode (G61 is supported) */ diff --git a/grbl/gcode.h b/grbl/gcode.h index 6cedf5f..6cdc61b 100644 --- a/grbl/gcode.h +++ b/grbl/gcode.h @@ -124,8 +124,13 @@ #define TOOL_LENGTH_OFFSET_ENABLE_DYNAMIC 1 // G43.1 // Modal Group M9: Override control -#define OVERRIDE_DISABLED 0 // None (Default: Must be zero) -#define OVERRIDE_PARKING_MOTION 1 // G56 (Default: Must be zero) +#ifdef DEACTIVATE_PARKING_UPON_INIT + #define OVERRIDE_DISABLED 0 // (Default: Must be zero) + #define OVERRIDE_PARKING_MOTION 1 // M56 +#else + #define OVERRIDE_PARKING_MOTION 0 // M56 (Default: Must be zero) + #define OVERRIDE_DISABLED 1 // Parking disabled. +#endif // Modal Group G12: Active work coordinate system // N/A: Stores coordinate system value (54-59) to change to. diff --git a/grbl/grbl.h b/grbl/grbl.h index 221cb43..67bf295 100644 --- a/grbl/grbl.h +++ b/grbl/grbl.h @@ -23,7 +23,7 @@ // Grbl versioning system #define GRBL_VERSION "1.1f" -#define GRBL_VERSION_BUILD "20170128" +#define GRBL_VERSION_BUILD "20170129" // Define standard libraries used by Grbl. #include diff --git a/grbl/protocol.c b/grbl/protocol.c index bce9f5e..09b2ac8 100644 --- a/grbl/protocol.c +++ b/grbl/protocol.c @@ -579,7 +579,7 @@ static void protocol_exec_rt_suspend() if ((bit_istrue(settings.flags,BITFLAG_HOMING_ENABLE)) && (parking_target[PARKING_AXIS] < PARKING_TARGET) && bit_isfalse(settings.flags,BITFLAG_LASER_MODE) && - !sys.override_ctrl) { + (sys.override_ctrl == OVERRIDE_PARKING_MOTION)) { #else if ((bit_istrue(settings.flags,BITFLAG_HOMING_ENABLE)) && (parking_target[PARKING_AXIS] < PARKING_TARGET) && @@ -650,7 +650,7 @@ static void protocol_exec_rt_suspend() // NOTE: State is will remain DOOR, until the de-energizing and retract is complete. #ifdef ENABLE_PARKING_OVERRIDE_CONTROL if (((settings.flags & (BITFLAG_HOMING_ENABLE|BITFLAG_LASER_MODE)) == BITFLAG_HOMING_ENABLE) && - !sys.override_ctrl) { + (sys.override_ctrl == OVERRIDE_PARKING_MOTION)) { #else if ((settings.flags & (BITFLAG_HOMING_ENABLE|BITFLAG_LASER_MODE)) == BITFLAG_HOMING_ENABLE) { #endif @@ -689,7 +689,7 @@ static void protocol_exec_rt_suspend() // Execute slow plunge motion from pull-out position to resume position. #ifdef ENABLE_PARKING_OVERRIDE_CONTROL if (((settings.flags & (BITFLAG_HOMING_ENABLE|BITFLAG_LASER_MODE)) == BITFLAG_HOMING_ENABLE) && - !sys.override_ctrl) { + (sys.override_ctrl == OVERRIDE_PARKING_MOTION)) { #else if ((settings.flags & (BITFLAG_HOMING_ENABLE|BITFLAG_LASER_MODE)) == BITFLAG_HOMING_ENABLE) { #endif diff --git a/grbl/report.c b/grbl/report.c index 8ca39d5..7a0bde2 100644 --- a/grbl/report.c +++ b/grbl/report.c @@ -328,7 +328,7 @@ void report_gcode_modes() #endif #ifdef ENABLE_PARKING_OVERRIDE_CONTROL - if (sys.override_ctrl) { + if (sys.override_ctrl == OVERRIDE_PARKING_MOTION) { report_util_gcode_modes_M(); print_uint8_base10(56); } From f51268e8556354a4851a8bdac2b6be7b8d7d5a03 Mon Sep 17 00:00:00 2001 From: Sonny Jeon Date: Tue, 31 Jan 2017 18:46:20 -0700 Subject: [PATCH 3/3] Additional build info in the $I printout. - [new] Added total available planner buffer blocks (15 shown, but there are 16. one is used by the ring buffer and to execute system motions) and serial RX buffer bytes. This information is useful for GUIs to setup and optimize their streaming protocols easily. [doc] Updated the interface document to reflect the change. --- doc/log/commit_log_v1.1.txt | 13 +++++++++++++ doc/markdown/interface.md | 10 +++++----- grbl/grbl.h | 2 +- grbl/report.c | 8 ++++++-- 4 files changed, 25 insertions(+), 8 deletions(-) diff --git a/doc/log/commit_log_v1.1.txt b/doc/log/commit_log_v1.1.txt index 36f1e5e..4cd8e89 100644 --- a/doc/log/commit_log_v1.1.txt +++ b/doc/log/commit_log_v1.1.txt @@ -1,3 +1,16 @@ +---------------- +Date: 2017-01-29 +Author: Sonny Jeon +Subject: Tidying up parking override control implementation + +[new] Added a default configuration for the parking override control +upon a reset or power-up. By default, parking is enabled, but this may +be disabled via a config.h option. + +[fix] Parking override control should be checking if the command word +is passed, rather than the value. + + ---------------- Date: 2017-01-28 Author: chamnit diff --git a/doc/markdown/interface.md b/doc/markdown/interface.md index 850d9d2..ccb063f 100644 --- a/doc/markdown/interface.md +++ b/doc/markdown/interface.md @@ -408,16 +408,16 @@ Feedback messages provide non-critical information on what Grbl is doing, what i - `[VER:]` and `[OPT:]`: Indicates build info data from a `$I` user query. These build info messages are followed by an `ok` to confirm the `$I` was executed, like so: ``` - [VER:v1.1d.20161014:Some string] - [OPT:VL] + [VER:v1.1f.20170131:Some string] + [OPT:VL,16,128] ok ``` - The first line `[VER:]` contains the build version and date. - A string may appear after the second `:` colon. It is a stored EEPROM string a user via a `$I=line` command or OEM can place there for personal use or tracking purposes. - - The `[OPT:]` line follows immediately after and contains character codes for compile-time options that were either enabled or disabled. The codes are defined below and a CSV file is also provided for quick parsing. This is generally only used for quickly diagnosing firmware bugs or compatibility issues. + - The `[OPT:]` line follows immediately after and contains character codes for compile-time options that were either enabled or disabled and two values separated by commas, which indicates the total usable planner blocks and serial RX buffer bytes, respectively. The codes are defined below and a CSV file is also provided for quick parsing. This is generally only used for quickly diagnosing firmware bugs or compatibility issues. - | `OPT` Code | Setting Description, Units | + | `OPT` Code | Setting Description, Units | |:-------------:|----| | **`V`** | Variable spindle enabled | | **`N`** | Line numbers enabled | @@ -439,7 +439,7 @@ Feedback messages provide non-critical information on what Grbl is doing, what i | **`E`** | Force sync upon EEPROM write disabled | | **`W`** | Force sync upon work coordinate offset change disabled | | **`L`** | Homing initialization auto-lock disabled | - + - `[echo:]` : Indicates an automated line echo from a command just prior to being parsed and executed. May be enabled only by a config.h option. Often used for debugging communication issues. A typical line echo message is shown below. A separate `ok` will eventually appear to confirm the line has been parsed and executed, but may not be immediate as with any line command containing motions. ``` [echo:G1X0.540Y10.4F100] diff --git a/grbl/grbl.h b/grbl/grbl.h index 67bf295..48ef599 100644 --- a/grbl/grbl.h +++ b/grbl/grbl.h @@ -23,7 +23,7 @@ // Grbl versioning system #define GRBL_VERSION "1.1f" -#define GRBL_VERSION_BUILD "20170129" +#define GRBL_VERSION_BUILD "20170131" // Define standard libraries used by Grbl. #include diff --git a/grbl/report.c b/grbl/report.c index 7a0bde2..5a541fb 100644 --- a/grbl/report.c +++ b/grbl/report.c @@ -433,9 +433,13 @@ void report_build_info(char *line) #ifndef HOMING_INIT_LOCK serial_write('L'); #endif + // NOTE: Compiled values, like override increments/max/min values, may be added at some point later. - // These will likely have a comma delimiter to separate them. - + serial_write(','); + print_uint8_base10(BLOCK_BUFFER_SIZE-1); + serial_write(','); + print_uint8_base10(RX_BUFFER_SIZE); + report_util_feedback_line_feed(); }