├── .gitignore ├── COPYING ├── Makefile ├── README.md ├── build └── .gitignore ├── doc ├── csv │ ├── alarm_codes_en_US.csv │ ├── build_option_codes_en_US.csv │ ├── error_codes_en_US.csv │ └── setting_codes_en_US.csv ├── log │ ├── commit_log_v0.7.txt │ ├── commit_log_v0.8c.txt │ ├── commit_log_v0.9g.txt │ ├── commit_log_v0.9i.txt │ ├── commit_log_v0.9j.txt │ ├── commit_log_v1.0b.txt │ ├── commit_log_v1.0c.txt │ └── commit_log_v1.1.txt ├── markdown │ ├── change_summary.md │ ├── commands.md │ ├── interface.md │ ├── jogging.md │ ├── laser_mode.md │ └── settings.md ├── media │ ├── COPYING │ ├── Grbl Logo 150px.png │ ├── Grbl Logo 250px.png │ ├── Grbl Logo 320px.png │ ├── Grbl Logo 640px.png │ ├── Grbl Logo.pdf │ └── Grbl Logo.svg └── script │ ├── simple_stream.py │ └── stream.py ├── grbl 0.8 with SpindleControl ├── config.h ├── coolant_control.cpp ├── coolant_control.h ├── defaults.h ├── eeprom.cpp ├── eeprom.h ├── examples │ └── GRBLtoArduino │ │ └── GRBLtoArduino.ino ├── gcode.cpp ├── gcode.h ├── grblmain.cpp ├── grblmain.h ├── limits.cpp ├── limits.h ├── motion_control.cpp ├── motion_control.h ├── nuts_bolts.cpp ├── nuts_bolts.h ├── planner.cpp ├── planner.h ├── print.cpp ├── print.h ├── protocol.cpp ├── protocol.h ├── report.cpp ├── report.h ├── serial.cpp ├── serial.h ├── settings.cpp ├── settings.h ├── spindle_control.cpp ├── spindle_control.h ├── stepper.cpp └── stepper.h ├── grbl.zip └── grbl ├── config.h ├── coolant_control.c ├── coolant_control.h ├── cpu_map.h ├── cpu_map ├── cpu_map_atmega2560.h └── cpu_map_atmega328p.h ├── defaults.h ├── defaults ├── defaults_generic.h ├── defaults_oxcnc.h ├── defaults_shapeoko.h ├── defaults_shapeoko2.h ├── defaults_shapeoko3.h ├── defaults_sherline.h ├── defaults_simulator.h ├── defaults_x_carve_1000mm.h ├── defaults_x_carve_500mm.h └── defaults_zen_toolworks_7x7.h ├── eeprom.c ├── eeprom.h ├── examples ├── grblUpload │ ├── grblUpload.ino │ └── license.txt └── grblWrite_BuildInfo │ ├── grblWrite_BuildInfo.ino │ └── license.txt ├── gcode.c ├── gcode.h ├── grbl.h ├── jog.c ├── jog.h ├── limits.c ├── limits.h ├── main.c ├── motion_control.c ├── motion_control.h ├── nuts_bolts.c ├── nuts_bolts.h ├── planner.c ├── planner.h ├── print.c ├── print.h ├── probe.c ├── probe.h ├── protocol.c ├── protocol.h ├── report.c ├── report.h ├── serial.c ├── serial.h ├── settings.c ├── settings.h ├── spindle_control.c ├── spindle_control.h ├── stepper.c ├── stepper.h ├── system.c └── system.h /.gitignore: -------------------------------------------------------------------------------- 1 | *.hex 2 | *.o 3 | *.elf 4 | *.DS_Store 5 | *.d 6 | 7 | README.md 8 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | # Part of Grbl 2 | # 3 | # Copyright (c) 2009-2011 Simen Svale Skogsrud 4 | # Copyright (c) 2012-2016 Sungeun K. Jeon for Gnea Research LLC 5 | # 6 | # Grbl is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # Grbl is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU General Public License 17 | # along with Grbl. If not, see . 18 | 19 | 20 | # This is a prototype Makefile. Modify it according to your needs. 21 | # You should at least check the settings for 22 | # DEVICE ....... The AVR device you compile for 23 | # CLOCK ........ Target AVR clock rate in Hertz 24 | # OBJECTS ...... The object files created from your source files. This list is 25 | # usually the same as the list of source files with suffix ".o". 26 | # PROGRAMMER ... Options to avrdude which define the hardware you use for 27 | # uploading to the AVR and the interface where this hardware 28 | # is connected. 29 | # FUSES ........ Parameters for avrdude to flash the fuses appropriately. 30 | 31 | DEVICE ?= atmega328p 32 | CLOCK = 16000000 33 | PROGRAMMER ?= -c avrisp2 -P usb 34 | SOURCE = main.c motion_control.c gcode.c spindle_control.c coolant_control.c serial.c \ 35 | protocol.c stepper.c eeprom.c settings.c planner.c nuts_bolts.c limits.c jog.c\ 36 | print.c probe.c report.c system.c 37 | BUILDDIR = build 38 | SOURCEDIR = grbl 39 | # FUSES = -U hfuse:w:0xd9:m -U lfuse:w:0x24:m 40 | FUSES = -U hfuse:w:0xd2:m -U lfuse:w:0xff:m 41 | 42 | # Tune the lines below only if you know what you are doing: 43 | 44 | AVRDUDE = avrdude $(PROGRAMMER) -p $(DEVICE) -B 10 -F 45 | 46 | # Compile flags for avr-gcc v4.8.1. Does not produce -flto warnings. 47 | # COMPILE = avr-gcc -Wall -Os -DF_CPU=$(CLOCK) -mmcu=$(DEVICE) -I. -ffunction-sections 48 | 49 | # Compile flags for avr-gcc v4.9.2 compatible with the IDE. Or if you don't care about the warnings. 50 | COMPILE = avr-gcc -Wall -Os -DF_CPU=$(CLOCK) -mmcu=$(DEVICE) -I. -ffunction-sections -flto 51 | 52 | 53 | OBJECTS = $(addprefix $(BUILDDIR)/,$(notdir $(SOURCE:.c=.o))) 54 | 55 | # symbolic targets: 56 | all: grbl.hex 57 | 58 | $(BUILDDIR)/%.o: $(SOURCEDIR)/%.c 59 | $(COMPILE) -MMD -MP -c $< -o $@ 60 | 61 | .S.o: 62 | $(COMPILE) -x assembler-with-cpp -c $< -o $(BUILDDIR)/$@ 63 | # "-x assembler-with-cpp" should not be necessary since this is the default 64 | # file type for the .S (with capital S) extension. However, upper case 65 | # characters are not always preserved on Windows. To ensure WinAVR 66 | # compatibility define the file type manually. 67 | 68 | #.c.s: 69 | $(COMPILE) -S $< -o $(BUILDDIR)/$@ 70 | 71 | flash: all 72 | $(AVRDUDE) -U flash:w:grbl.hex:i 73 | 74 | fuse: 75 | $(AVRDUDE) $(FUSES) 76 | 77 | # Xcode uses the Makefile targets "", "clean" and "install" 78 | install: flash fuse 79 | 80 | # if you use a bootloader, change the command below appropriately: 81 | load: all 82 | bootloadHID grbl.hex 83 | 84 | clean: 85 | rm -f grbl.hex $(BUILDDIR)/*.o $(BUILDDIR)/*.d $(BUILDDIR)/*.elf 86 | 87 | # file targets: 88 | $(BUILDDIR)/main.elf: $(OBJECTS) 89 | $(COMPILE) -o $(BUILDDIR)/main.elf $(OBJECTS) -lm -Wl,--gc-sections 90 | 91 | grbl.hex: $(BUILDDIR)/main.elf 92 | rm -f grbl.hex 93 | avr-objcopy -j .text -j .data -O ihex $(BUILDDIR)/main.elf grbl.hex 94 | avr-size --format=berkeley $(BUILDDIR)/main.elf 95 | # If you have an EEPROM section, you must also create a hex file for the 96 | # EEPROM and add it to the "flash" target. 97 | 98 | # Targets for code debugging and analysis: 99 | disasm: main.elf 100 | avr-objdump -d $(BUILDDIR)/main.elf 101 | 102 | cpp: 103 | $(COMPILE) -E $(SOURCEDIR)/main.c 104 | 105 | # include generated header dependencies 106 | -include $(BUILDDIR)/$(OBJECTS:.o=.d) 107 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | #GRBL 28byj-48 2 | 3 | This is a modified fork from ruizivo/GRBL-28byj-48-Servo. This modification implements all 3-axises XYZ to a 28BYJ-48 stepper motor. 4 | 5 | The motors (28byj-48) are connected to a controller card (Arduino UNO) that uses the chip ULN2003. This board is connected to pins A0, A1, A2, A3 for the Y-Axis(IN4->IN1), 2, 3,4,5 Digital pins to the X-Axis(IN4->IN1), and 8,9,12,13 to the Z-Axis(IN4->IN1). 6 | 7 | This work was derived from: 8 | See https://github.com/ruizivo/GRBL-28byj-48-Servo 9 | 10 | #GRBL 28byj-48 + Servo Motor 11 | 12 | This GRBL uses an ugly hack to control two motors unipolar steps as 28byj-48 and also supports a servo motor on pin 11 13 | 14 | The motors (28byj-48) are connected to a controller card that uses the chip ULN2003. This board is connected to pins A0, A1, A2, A3 for the Y axis and 2,3,4,5 digital pins to the axis X. The servomotor connected to pin 11 h. 15 | 16 | Credits to robottini who did support the servo motor ... link to git https://github.com/robottini/grbl-servo 17 | 18 | I tested the code very well with 328p (Arduino Uno, Duemilanove etv), not with 2560 (Arduino Mega) because I did not do the alterations in the file cpu_map_atmega2560.h 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /build/.gitignore: -------------------------------------------------------------------------------- 1 | # Ignore everything in this directory 2 | * 3 | # Except this file 4 | !.gitignore -------------------------------------------------------------------------------- /doc/csv/alarm_codes_en_US.csv: -------------------------------------------------------------------------------- 1 | "Alarm Code in v1.1+"," Alarm Message in v1.0-"," Alarm Description" 2 | "1","Hard limit","Hard limit has been triggered. Machine position is likely lost due to sudden halt. Re-homing is highly recommended." 3 | "2","Soft limit","Soft limit alarm. G-code motion target exceeds machine travel. Machine position retained. Alarm may be safely unlocked." 4 | "3","Abort during cycle","Reset while in motion. Machine position is likely lost due to sudden halt. Re-homing is highly recommended." 5 | "4","Probe fail","Probe fail. Probe is not in the expected initial state before starting probe cycle when G38.2 and G38.3 is not triggered and G38.4 and G38.5 is triggered." 6 | "5","Probe fail","Probe fail. Probe did not contact the workpiece within the programmed travel for G38.2 and G38.4." 7 | "6","Homing fail","Homing fail. The active homing cycle was reset." 8 | "7","Homing fail","Homing fail. Safety door was opened during homing cycle." 9 | "8","Homing fail","Homing fail. Pull off travel failed to clear limit switch. Try increasing pull-off setting or check wiring." 10 | "9","Homing fail","Homing fail. Could not find limit switch within search distances. Try increasing max travel, decreasing pull-off distance, or check wiring." 11 | -------------------------------------------------------------------------------- /doc/csv/build_option_codes_en_US.csv: -------------------------------------------------------------------------------- 1 | "OPT: Code"," Build-Option Description","State" 2 | "V","Variable spindle","Enabled" 3 | "N","Line numbers","Enabled" 4 | "M","Mist coolant M7","Enabled" 5 | "C","CoreXY","Enabled" 6 | "P","Parking motion","Enabled" 7 | "Z","Homing force origin","Enabled" 8 | "H","Homing single axis commands","Enabled" 9 | "L","Two limit switches on axis","Enabled" 10 | "A","Allow feed rate overrides in probe cycles","Enabled" 11 | "D","Use spindle direction as enable pin","Enabled" 12 | "0","Spindle enable off when speed is zero","Enabled" 13 | "S","Software limit pin debouncing","Enabled" 14 | "R","Parking override control","Enabled" 15 | "*","Restore all EEPROM command","Disabled" 16 | "$","Restore EEPROM `$` settings command","Disabled" 17 | "#","Restore EEPROM parameter data command","Disabled" 18 | "I","Build info write user string command","Disabled" 19 | "E","Force sync upon EEPROM write","Disabled" 20 | "W","Force sync upon work coordinate offset change","Disabled" 21 | "L","Homing initialization auto-lock","Disabled" -------------------------------------------------------------------------------- /doc/csv/error_codes_en_US.csv: -------------------------------------------------------------------------------- 1 | Error Code in v1.1+ ,Error Message in v1.0-, Error Description 2 | 1,Expected command letter,G-code words consist of a letter and a value. Letter was not found. 3 | 2,Bad number format,Missing the expected G-code word value or numeric value format is not valid. 4 | 3,Invalid statement,Grbl '$' system command was not recognized or supported. 5 | 4,Value < 0,Negative value received for an expected positive value. 6 | 5,Setting disabled,Homing cycle failure. Homing is not enabled via settings. 7 | 6,Value < 3 usec,Minimum step pulse time must be greater than 3usec. 8 | 7,EEPROM read fail. Using defaults,An EEPROM read failed. Auto-restoring affected EEPROM to default values. 9 | 8,Not idle,Grbl '$' command cannot be used unless Grbl is IDLE. Ensures smooth operation during a job. 10 | 9,G-code lock,G-code commands are locked out during alarm or jog state. 11 | 10,Homing not enabled,Soft limits cannot be enabled without homing also enabled. 12 | 11,Line overflow,Max characters per line exceeded. Received command line was not executed. 13 | 12,Step rate > 30kHz,Grbl '$' setting value cause the step rate to exceed the maximum supported. 14 | 13,Check Door,Safety door detected as opened and door state initiated. 15 | 14,Line length exceeded,Build info or startup line exceeded EEPROM line length limit. Line not stored. 16 | 15,Travel exceeded,Jog target exceeds machine travel. Jog command has been ignored. 17 | 16,Invalid jog command,Jog command has no '=' or contains prohibited g-code. 18 | 20,Unsupported command,Unsupported or invalid g-code command found in block. 19 | 21,Modal group violation,More than one g-code command from same modal group found in block. 20 | 22,Undefined feed rate,Feed rate has not yet been set or is undefined. 21 | 23,Invalid gcode ID:23,G-code command in block requires an integer value. 22 | 24,Invalid gcode ID:24,More than one g-code command that requires axis words found in block. 23 | 25,Invalid gcode ID:25,Repeated g-code word found in block. 24 | 26,Invalid gcode ID:26,No axis words found in block for g-code command or current modal state which requires them. 25 | 27,Invalid gcode ID:27,Line number value is invalid. 26 | 28,Invalid gcode ID:28,G-code command is missing a required value word. 27 | 29,Invalid gcode ID:29,G59.x work coordinate systems are not supported. 28 | 30,Invalid gcode ID:30,G53 only allowed with G0 and G1 motion modes. 29 | 31,Invalid gcode ID:31,Axis words found in block when no command or current modal state uses them. 30 | 32,Invalid gcode ID:32,G2 and G3 arcs require at least one in-plane axis word. 31 | 33,Invalid gcode ID:33,Motion command target is invalid. 32 | 34,Invalid gcode ID:34,Arc radius value is invalid. 33 | 35,Invalid gcode ID:35,G2 and G3 arcs require at least one in-plane offset word. 34 | 36,Invalid gcode ID:36,Unused value words found in block. 35 | 37,Invalid gcode ID:37,G43.1 dynamic tool length offset is not assigned to configured tool length axis. 36 | 38,Invalid gcode ID:38,Tool number greater than max supported value. -------------------------------------------------------------------------------- /doc/csv/setting_codes_en_US.csv: -------------------------------------------------------------------------------- 1 | "$-Code"," Setting"," Units"," Setting Description" 2 | "0","Step pulse time","microseconds","Sets time length per step. Minimum 3usec." 3 | "1","Step idle delay","milliseconds","Sets a short hold delay when stopping to let dynamics settle before disabling steppers. Value 255 keeps motors enabled with no delay." 4 | "2","Step pulse invert","mask","Inverts the step signal. Set axis bit to invert (00000ZYX)." 5 | "3","Step direction invert","mask","Inverts the direction signal. Set axis bit to invert (00000ZYX)." 6 | "4","Invert step enable pin","boolean","Inverts the stepper driver enable pin signal." 7 | "5","Invert limit pins","boolean","Inverts the all of the limit input pins." 8 | "6","Invert probe pin","boolean","Inverts the probe input pin signal." 9 | "10","Status report options","mask","Alters data included in status reports." 10 | "11","Junction deviation","millimeters","Sets how fast Grbl travels through consecutive motions. Lower value slows it down." 11 | "12","Arc tolerance","millimeters","Sets the G2 and G3 arc tracing accuracy based on radial error. Beware: A very small value may effect performance." 12 | "13","Report in inches","boolean","Enables inch units when returning any position and rate value that is not a settings value." 13 | "20","Soft limits enable","boolean","Enables soft limits checks within machine travel and sets alarm when exceeded. Requires homing." 14 | "21","Hard limits enable","boolean","Enables hard limits. Immediately halts motion and throws an alarm when switch is triggered." 15 | "22","Homing cycle enable","boolean","Enables homing cycle. Requires limit switches on all axes." 16 | "23","Homing direction invert","mask","Homing searches for a switch in the positive direction. Set axis bit (00000ZYX) to search in negative direction." 17 | "24","Homing locate feed rate","mm/min","Feed rate to slowly engage limit switch to determine its location accurately." 18 | "25","Homing search seek rate","mm/min","Seek rate to quickly find the limit switch before the slower locating phase." 19 | "26","Homing switch debounce delay","milliseconds","Sets a short delay between phases of homing cycle to let a switch debounce." 20 | "27","Homing switch pull-off distance","millimeters","Retract distance after triggering switch to disengage it. Homing will fail if switch isn't cleared." 21 | "30","Maximum spindle speed","RPM","Maximum spindle speed. Sets PWM to 100% duty cycle." 22 | "31","Minimum spindle speed","RPM","Minimum spindle speed. Sets PWM to 0.4% or lowest duty cycle." 23 | "32","Laser-mode enable","boolean","Enables laser mode. Consecutive G1/2/3 commands will not halt when spindle speed is changed." 24 | "100","X-axis travel resolution","step/mm","X-axis travel resolution in steps per millimeter." 25 | "101","Y-axis travel resolution","step/mm","Y-axis travel resolution in steps per millimeter." 26 | "102","Z-axis travel resolution","step/mm","Z-axis travel resolution in steps per millimeter." 27 | "110","X-axis maximum rate","mm/min","X-axis maximum rate. Used as G0 rapid rate." 28 | "111","Y-axis maximum rate","mm/min","Y-axis maximum rate. Used as G0 rapid rate." 29 | "112","Z-axis maximum rate","mm/min","Z-axis maximum rate. Used as G0 rapid rate." 30 | "120","X-axis acceleration","mm/sec^2","X-axis acceleration. Used for motion planning to not exceed motor torque and lose steps." 31 | "121","Y-axis acceleration","mm/sec^2","Y-axis acceleration. Used for motion planning to not exceed motor torque and lose steps." 32 | "122","Z-axis acceleration","mm/sec^2","Z-axis acceleration. Used for motion planning to not exceed motor torque and lose steps." 33 | "130","X-axis maximum travel","millimeters","Maximum X-axis travel distance from homing switch. Determines valid machine space for soft-limits and homing search distances." 34 | "131","Y-axis maximum travel","millimeters","Maximum Y-axis travel distance from homing switch. Determines valid machine space for soft-limits and homing search distances." 35 | "132","Z-axis maximum travel","millimeters","Maximum Z-axis travel distance from homing switch. Determines valid machine space for soft-limits and homing search distances." 36 | -------------------------------------------------------------------------------- /doc/log/commit_log_v0.9j.txt: -------------------------------------------------------------------------------- 1 | ---------------- 2 | Date: 2015-08-14 3 | Author: Sonny Jeon 4 | Subject: Individual control pin invert compile-option. 5 | 6 | - Control pins may be individually inverted through a 7 | CONTROL_INVERT_MASK macro. This mask is define in the cpu_map.h file. 8 | 9 | 10 | ---------------- 11 | Date: 2015-07-17 12 | Author: Sonny Jeon 13 | Subject: Version bump to v0.9j 14 | 15 | - Version bump requested by OEMs to easily determine whether the 16 | firmware supports the new EEPROM reset feature. Other than that, no 17 | significant changes. 18 | -------------------------------------------------------------------------------- /doc/log/commit_log_v1.0b.txt: -------------------------------------------------------------------------------- 1 | ---------------- 2 | Date: 2015-09-30 3 | Author: Sonny Jeon 4 | Subject: Bug fixes. 5 | 6 | - G38.x was not printing correctly in the $G g-code state reports. Now 7 | fixed. 8 | 9 | - When investigating the above issue, it was noticed that G38.x 10 | wouldn’t show at all, but instead a G0 would be printed. This was 11 | unlike the v0.9j master build. It turned out volatile variables do not 12 | like to be defined inside a C struct. These are undefined on how to be 13 | handled. Once pulled out, all weird issues went away. 14 | 15 | - Also changed two ‘sizeof()’ statements in the mc_probe() and 16 | probe_state_monitor() functions to be more robust later on. 17 | 18 | - Updated the commit logs to individual files for each minor release. 19 | Forgot to update the generating script to account for this. 20 | 21 | 22 | ---------------- 23 | Date: 2015-09-30 24 | Author: Sonny Jeon 25 | Subject: Minor bug fixes. 26 | 27 | - G38.x was not printing correctly in the $G g-code state reports. Now 28 | fixed. 29 | 30 | - Potential bug regarding volatile variables inside a struct. It has 31 | never been a problem in v0.9, but ran into this during v1.0 32 | development. Just to be safe, the fixes are applied here. 33 | 34 | - Updated pre-built firmwares with these two bug fixes. 35 | 36 | 37 | ---------------- 38 | Date: 2015-09-24 39 | Author: Sonny Jeon 40 | Subject: Updated G28/G30 intermediate motion behavior. 41 | 42 | - G28 and G30’s behavior has been updated from the old NIST g-code 43 | standard to LinuxCNC’s. Previously when an intermediate motion was 44 | programmed, the NIST standard would move all axes to the final G28/30 45 | stored coordinates. LinuxCNC states it only moves the axes specified in 46 | the command. 47 | 48 | For example, suppose G28’s stored position is (x,y,z) = (1,2,3) for 49 | simplicity, and we want to do an automated z-axis tool retraction and 50 | then park at the x,y location. `G28 G91 Z5` will first move the Z axis 51 | 5mm(or inches) up, then move Z to position 3 in machine coordinates. 52 | Next, the command `G28 G91 X0 Y0` would skip the intermediate move 53 | since distance is zero, but then move only the x and y axes to machine 54 | coordinates 1 and 2, respectively. The z-axis wouldn’t move in this 55 | case, since it wasn’t specified. 56 | 57 | This change is intended to make Grbl more LinuxCNC compatible while 58 | making commands, like the shown tool retraction, much easier to 59 | implement. 60 | 61 | 62 | ---------------- 63 | Date: 2015-09-05 64 | Author: Sonny Jeon 65 | Subject: Parking motion bug fix. 66 | 67 | - Parking motion would intermittently complete the queued tool path 68 | upon resuming in certain scenarios. Now fixed. 69 | 70 | 71 | ---------------- 72 | Date: 2015-08-29 73 | Author: Sonny Jeon 74 | Subject: Optional line number reporting bug fix. 75 | 76 | - Fixed a bug where it would not compile when USE_LINE_NUMBERS was 77 | enabled. 78 | 79 | 80 | ---------------- 81 | Date: 2015-08-27 82 | Author: Sonny Jeon 83 | Subject: Update README 84 | 85 | 86 | ---------------- 87 | Date: 2015-08-27 88 | Author: Sonny Jeon 89 | Subject: v1.0 Beta Release. 90 | 91 | - Tons of new stuff in this release, which is fairly stable and well 92 | tested. However, much more is coming soon! 93 | 94 | - Real-time parking motion with safety door. When this compile option 95 | is enabled, an opened safety door will cause Grbl to automatically feed 96 | hold, retract, de-energize the spindle/coolant, and parks near Z max. 97 | After the door is closed and resume is commanded, this reverses and the 98 | program continues as if nothing happened. This is also highly 99 | configurable. See config.h for details. 100 | 101 | - New spindle max and min rpm ‘$’ settings! This has been requested 102 | often. Grbl will output 5V when commanded to turn on the spindle at its 103 | max rpm, and 0.02V with min rpm. The voltage and the rpm range are 104 | linear to each other. This should help users tweak their settings to 105 | get close to true rpm’s. 106 | 107 | - If the new max rpm ‘$’ setting is set = 0 or less than min rpm, the 108 | spindle speed PWM pin will act like a regular on/off spindle enable 109 | pin. On pin D11. 110 | 111 | - BEWARE: Your old EEPROM settings will be wiped! The new spindle rpm 112 | settings require a new settings version, so Grbl will automatically 113 | wipe and restore the EEPROM with the new defaults. 114 | 115 | - Control pin can now be inverted individually with a 116 | CONTROL_INVERT_MASK in the cpu_map header file. Not typical for users 117 | to need this, but handy to have. 118 | 119 | - Fixed bug when Grbl receive too many characters in a line and 120 | overflows. Previously it would respond with an error per overflow 121 | character and another acknowledge upon an EOL character. This broke the 122 | streaming protocol. Now fixed to only respond with an error after an 123 | EOL character. 124 | 125 | - Fixed a bug with the safety door during an ALARM mode. You now can’t 126 | home or unlock the axes until the safety door has been closed. This is 127 | for safety reasons (obviously.) 128 | 129 | - Tweaked some the Mega2560 cpu_map settings . Increased segment buffer 130 | size and fixed the spindle PWM settings to output at a higher PWM 131 | frequency. 132 | 133 | - Generalized the delay function used by G4 delay for use by parking 134 | motion. Allows non-blocking status reports and real-time control during 135 | re-energizing of the spindle and coolant. 136 | 137 | - Added spindle rpm max and min defaults to default.h files. 138 | 139 | - Added a new print float for rpm values. 140 | 141 | -------------------------------------------------------------------------------- /doc/log/commit_log_v1.0c.txt: -------------------------------------------------------------------------------- 1 | ---------------- 2 | Date: 2016-03-19 3 | Author: Sonny Jeon 4 | Subject: No variable spindle and spindle speed fix. 5 | 6 | - Soft limit errors were stuck in a feed hold without notifying the 7 | user why it was in a hold. When resumed, the soft limit error would 8 | kick in. Issue should be fixed to behave as intended to automatically 9 | hold and issue a soft limit alarm once the machine has come to a stop. 10 | 11 | 12 | ---------------- 13 | Date: 2016-03-11 14 | Author: Sonny Jeon 15 | Subject: Soft limit error bug fix. 16 | 17 | - Soft limit errors were stuck in a feed hold without notifying the 18 | user why it was in a hold. When resumed, the soft limit error would 19 | kick in. Issue should be fixed to behave as intended. To automatically 20 | hold and issue a soft limit alarm once the machine has come to a stop. 21 | 22 | 23 | ---------------- 24 | Date: 2016-03-04 25 | Author: Sonny Jeon 26 | Subject: Applied master branch bug fixes. 27 | 28 | - Planner was under-estimating maximum speeds through straight 29 | junctions in certain cases. The calculations have been updated to be 30 | more accurate. 31 | 32 | - Strange sizeof() bug in the most recent releases. Manifested as an 33 | alarm upon a power up even when homing was disabled. Fixed by declaring 34 | sizeof() with struct types, rather than variable names, even though 35 | they were validated to give the same value. 36 | 37 | - Spindle speed zero should disable the spindle. Now fixed. 38 | 39 | - New configuration option for inverting certain limit pins. Handy for 40 | mixed NO and NC switch machines. See config.h for details. 41 | 42 | 43 | ---------------- 44 | Date: 2015-11-09 45 | Author: Sonny Jeon 46 | Subject: Pin state reporting of all pins. Flash optimization. 47 | 48 | - New pin state realtime reporting feature. Instead of `Lim:000` for 49 | limit state reports, the new feature shows `Pin:000|0|0000`, or 50 | something similar. The `|` delimited fields indicate xyz limits, probe, 51 | and control pin states, where 0 is always not triggered, and 1 is 52 | triggered. Invert masks ARE accounted for. 53 | Each field may be enabled or disabled via the `$10` status report 54 | setting. The probe and control pin flags are bits 5 and 6, respectively. 55 | 56 | - Remove the now deprecated `REPORT_CONTROL_PIN_STATE` option in 57 | config.h 58 | 59 | - The old limit pin reports `Lim:000` may be re-enabled by commenting 60 | out `REPORT_ALL_PIN_STATES` in config.h. 61 | 62 | - Incremented the version letter (v1.0c) to indicate the change in 63 | reporting style. 64 | 65 | - Replaced all bit_true_atomic and bit_false_atomic macros with 66 | function calls. This saved a couple hundred bytes of flash. 67 | 68 | -------------------------------------------------------------------------------- /doc/media/COPYING: -------------------------------------------------------------------------------- 1 | 2 | Copyright (c) 2015 Gnea Research LLC. All Rights Reserved. 3 | -------------------------------------------------------------------------------- /doc/media/Grbl Logo 150px.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TGit-Tech/GRBL-28byj-48/bad3e5654ec3ca98cdcff56d65f09ab4e1989e9f/doc/media/Grbl Logo 150px.png -------------------------------------------------------------------------------- /doc/media/Grbl Logo 250px.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TGit-Tech/GRBL-28byj-48/bad3e5654ec3ca98cdcff56d65f09ab4e1989e9f/doc/media/Grbl Logo 250px.png -------------------------------------------------------------------------------- /doc/media/Grbl Logo 320px.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TGit-Tech/GRBL-28byj-48/bad3e5654ec3ca98cdcff56d65f09ab4e1989e9f/doc/media/Grbl Logo 320px.png -------------------------------------------------------------------------------- /doc/media/Grbl Logo 640px.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TGit-Tech/GRBL-28byj-48/bad3e5654ec3ca98cdcff56d65f09ab4e1989e9f/doc/media/Grbl Logo 640px.png -------------------------------------------------------------------------------- /doc/media/Grbl Logo.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TGit-Tech/GRBL-28byj-48/bad3e5654ec3ca98cdcff56d65f09ab4e1989e9f/doc/media/Grbl Logo.pdf -------------------------------------------------------------------------------- /doc/media/Grbl Logo.svg: -------------------------------------------------------------------------------- 1 | 2 | 16 | 18 | 19 | 21 | image/svg+xml 22 | 24 | 25 | 26 | 27 | 28 | 48 | /Users/chamnit/Dropbox/documents/OHS/Logo/Grbl.DXF - scale = 58.043118, origin = (0.000000, 0.000000), auto = True 50 | 52 | 58 | 62 | 63 | 70 | 76 | 82 | 88 | 89 | 91 | 93 | 95 | 96 | 100 | 103 | 109 | 115 | 121 | 127 | 132 | 133 | 134 | 135 | -------------------------------------------------------------------------------- /doc/script/simple_stream.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | """\ 3 | Simple g-code streaming script for grbl 4 | 5 | Provided as an illustration of the basic communication interface 6 | for grbl. When grbl has finished parsing the g-code block, it will 7 | return an 'ok' or 'error' response. When the planner buffer is full, 8 | grbl will not send a response until the planner buffer clears space. 9 | 10 | G02/03 arcs are special exceptions, where they inject short line 11 | segments directly into the planner. So there may not be a response 12 | from grbl for the duration of the arc. 13 | 14 | --------------------- 15 | The MIT License (MIT) 16 | 17 | Copyright (c) 2012 Sungeun K. Jeon 18 | 19 | Permission is hereby granted, free of charge, to any person obtaining a copy 20 | of this software and associated documentation files (the "Software"), to deal 21 | in the Software without restriction, including without limitation the rights 22 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 23 | copies of the Software, and to permit persons to whom the Software is 24 | furnished to do so, subject to the following conditions: 25 | 26 | The above copyright notice and this permission notice shall be included in 27 | all copies or substantial portions of the Software. 28 | 29 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 30 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 31 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 32 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 33 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 34 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 35 | THE SOFTWARE. 36 | --------------------- 37 | """ 38 | 39 | import serial 40 | import time 41 | 42 | # Open grbl serial port 43 | s = serial.Serial('/dev/tty.usbmodem1811',115200) 44 | 45 | # Open g-code file 46 | f = open('grbl.gcode','r'); 47 | 48 | # Wake up grbl 49 | s.write("\r\n\r\n") 50 | time.sleep(2) # Wait for grbl to initialize 51 | s.flushInput() # Flush startup text in serial input 52 | 53 | # Stream g-code to grbl 54 | for line in f: 55 | l = line.strip() # Strip all EOL characters for consistency 56 | print 'Sending: ' + l, 57 | s.write(l + '\n') # Send g-code block to grbl 58 | grbl_out = s.readline() # Wait for grbl response with carriage return 59 | print ' : ' + grbl_out.strip() 60 | 61 | # Wait here until grbl is finished to close serial port and file. 62 | raw_input(" Press to exit and disable grbl.") 63 | 64 | # Close file and serial port 65 | f.close() 66 | s.close() -------------------------------------------------------------------------------- /doc/script/stream.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | """\ 3 | 4 | Stream g-code to grbl controller 5 | 6 | This script differs from the simple_stream.py script by 7 | tracking the number of characters in grbl's serial read 8 | buffer. This allows grbl to fetch the next line directly 9 | from the serial buffer and does not have to wait for a 10 | response from the computer. This effectively adds another 11 | buffer layer to prevent buffer starvation. 12 | 13 | CHANGELOG: 14 | - 20161212: Added push message feedback for simple streaming 15 | - 20140714: Updated baud rate to 115200. Added a settings 16 | write mode via simple streaming method. MIT-licensed. 17 | 18 | TODO: 19 | - Add runtime command capabilities 20 | 21 | --------------------- 22 | The MIT License (MIT) 23 | 24 | Copyright (c) 2012-2016 Sungeun K. Jeon 25 | 26 | Permission is hereby granted, free of charge, to any person obtaining a copy 27 | of this software and associated documentation files (the "Software"), to deal 28 | in the Software without restriction, including without limitation the rights 29 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 30 | copies of the Software, and to permit persons to whom the Software is 31 | furnished to do so, subject to the following conditions: 32 | 33 | The above copyright notice and this permission notice shall be included in 34 | all copies or substantial portions of the Software. 35 | 36 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 37 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 38 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 39 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 40 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 41 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 42 | THE SOFTWARE. 43 | --------------------- 44 | """ 45 | 46 | import serial 47 | import re 48 | import time 49 | import sys 50 | import argparse 51 | # import threading 52 | 53 | RX_BUFFER_SIZE = 128 54 | 55 | # Define command line argument interface 56 | parser = argparse.ArgumentParser(description='Stream g-code file to grbl. (pySerial and argparse libraries required)') 57 | parser.add_argument('gcode_file', type=argparse.FileType('r'), 58 | help='g-code filename to be streamed') 59 | parser.add_argument('device_file', 60 | help='serial device path') 61 | parser.add_argument('-q','--quiet',action='store_true', default=False, 62 | help='suppress output text') 63 | parser.add_argument('-s','--settings',action='store_true', default=False, 64 | help='settings write mode') 65 | args = parser.parse_args() 66 | 67 | # Periodic timer to query for status reports 68 | # TODO: Need to track down why this doesn't restart consistently before a release. 69 | # def periodic(): 70 | # s.write('?') 71 | # t = threading.Timer(0.1, periodic) # In seconds 72 | # t.start() 73 | 74 | # Initialize 75 | s = serial.Serial(args.device_file,115200) 76 | f = args.gcode_file 77 | verbose = True 78 | if args.quiet : verbose = False 79 | settings_mode = False 80 | if args.settings : settings_mode = True 81 | 82 | # Wake up grbl 83 | print "Initializing grbl..." 84 | s.write("\r\n\r\n") 85 | 86 | # Wait for grbl to initialize and flush startup text in serial input 87 | time.sleep(2) 88 | s.flushInput() 89 | 90 | # Stream g-code to grbl 91 | l_count = 0 92 | if settings_mode: 93 | # Send settings file via simple call-response streaming method. Settings must be streamed 94 | # in this manner since the EEPROM accessing cycles shut-off the serial interrupt. 95 | print "SETTINGS MODE: Streaming", args.gcode_file.name, " to ", args.device_file 96 | for line in f: 97 | l_count += 1 # Iterate line counter 98 | # l_block = re.sub('\s|\(.*?\)','',line).upper() # Strip comments/spaces/new line and capitalize 99 | l_block = line.strip() # Strip all EOL characters for consistency 100 | if verbose: print 'SND: ' + str(l_count) + ':' + l_block, 101 | s.write(l_block + '\n') # Send g-code block to grbl 102 | while 1: 103 | grbl_out = s.readline().strip() # Wait for grbl response with carriage return 104 | if grbl_out.find('ok') < 0 and grbl_out.find('error') < 0 : 105 | print "\n Debug: ",grbl_out, 106 | else : 107 | if verbose: print 'REC:',grbl_out 108 | break 109 | else: 110 | # Send g-code program via a more agressive streaming protocol that forces characters into 111 | # Grbl's serial read buffer to ensure Grbl has immediate access to the next g-code command 112 | # rather than wait for the call-response serial protocol to finish. This is done by careful 113 | # counting of the number of characters sent by the streamer to Grbl and tracking Grbl's 114 | # responses, such that we never overflow Grbl's serial read buffer. 115 | g_count = 0 116 | c_line = [] 117 | # periodic() # Start status report periodic timer 118 | for line in f: 119 | l_count += 1 # Iterate line counter 120 | # l_block = re.sub('\s|\(.*?\)','',line).upper() # Strip comments/spaces/new line and capitalize 121 | l_block = line.strip() 122 | c_line.append(len(l_block)+1) # Track number of characters in grbl serial read buffer 123 | grbl_out = '' 124 | while sum(c_line) >= RX_BUFFER_SIZE-1 | s.inWaiting() : 125 | out_temp = s.readline().strip() # Wait for grbl response 126 | if out_temp.find('ok') < 0 and out_temp.find('error') < 0 : 127 | print " Debug: ",out_temp # Debug response 128 | else : 129 | grbl_out += out_temp; 130 | g_count += 1 # Iterate g-code counter 131 | grbl_out += str(g_count); # Add line finished indicator 132 | del c_line[0] # Delete the block character count corresponding to the last 'ok' 133 | if verbose: print "SND: " + str(l_count) + " : " + l_block, 134 | s.write(l_block + '\n') # Send g-code block to grbl 135 | if verbose : print "BUF:",str(sum(c_line)),"REC:",grbl_out 136 | 137 | # Wait for user input after streaming is completed 138 | print "G-code streaming finished!\n" 139 | print "WARNING: Wait until grbl completes buffered g-code blocks before exiting." 140 | raw_input(" Press to exit and disable grbl.") 141 | 142 | # Close file and serial port 143 | f.close() 144 | s.close() 145 | -------------------------------------------------------------------------------- /grbl 0.8 with SpindleControl/coolant_control.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | coolant_control.c - coolant control methods 3 | Part of Grbl 4 | 5 | Copyright (c) 2012 Sungeun K. Jeon 6 | 7 | Grbl is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation, either version 3 of the License, or 10 | (at your option) any later version. 11 | 12 | Grbl is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with Grbl. If not, see . 19 | */ 20 | 21 | #include "coolant_control.h" 22 | #include "settings.h" 23 | #include "config.h" 24 | #include "planner.h" 25 | 26 | #include 27 | 28 | static uint8_t current_coolant_mode; 29 | 30 | void coolant_init() 31 | { 32 | current_coolant_mode = COOLANT_DISABLE; 33 | #if ENABLE_M7 34 | COOLANT_MIST_DDR |= (1 << COOLANT_MIST_BIT); 35 | #endif 36 | COOLANT_FLOOD_DDR |= (1 << COOLANT_FLOOD_BIT); 37 | coolant_stop(); 38 | } 39 | 40 | void coolant_stop() 41 | { 42 | #ifdef ENABLE_M7 43 | COOLANT_MIST_PORT &= ~(1 << COOLANT_MIST_BIT); 44 | #endif 45 | COOLANT_FLOOD_PORT &= ~(1 << COOLANT_FLOOD_BIT); 46 | } 47 | 48 | 49 | void coolant_run(uint8_t mode) 50 | { 51 | if (mode != current_coolant_mode) 52 | { 53 | plan_synchronize(); // Ensure coolant turns on when specified in program. 54 | if (mode == COOLANT_FLOOD_ENABLE) { 55 | COOLANT_FLOOD_PORT |= (1 << COOLANT_FLOOD_BIT); 56 | #ifdef ENABLE_M7 57 | } else if (mode == COOLANT_MIST_ENABLE) { 58 | COOLANT_MIST_PORT |= (1 << COOLANT_MIST_BIT); 59 | #endif 60 | } else { 61 | coolant_stop(); 62 | } 63 | current_coolant_mode = mode; 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /grbl 0.8 with SpindleControl/coolant_control.h: -------------------------------------------------------------------------------- 1 | /* 2 | coolant_control.h - spindle control methods 3 | Part of Grbl 4 | 5 | Copyright (c) 2012 Sungeun K. Jeon 6 | 7 | Grbl is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation, either version 3 of the License, or 10 | (at your option) any later version. 11 | 12 | Grbl is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with Grbl. If not, see . 19 | */ 20 | 21 | #ifndef coolant_control_h 22 | #define coolant_control_h 23 | 24 | #include 25 | 26 | #define COOLANT_MIST_ENABLE 2 27 | #define COOLANT_FLOOD_ENABLE 1 28 | #define COOLANT_DISABLE 0 // Must be zero. 29 | 30 | void coolant_init(); 31 | void coolant_stop(); 32 | void coolant_run(uint8_t mode); 33 | 34 | #endif -------------------------------------------------------------------------------- /grbl 0.8 with SpindleControl/eeprom.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | unsigned char eeprom_get_char( unsigned int addr ) 4 | { 5 | return eeprom_read_byte((unsigned char *) addr); 6 | } 7 | 8 | void eeprom_put_char( unsigned int addr, char new_value ) 9 | { 10 | eeprom_write_byte((unsigned char *) addr, new_value); 11 | } 12 | 13 | void memcpy_to_eeprom_with_checksum(unsigned int destination, char *source, unsigned int size) { 14 | unsigned char checksum = 0; 15 | for(; size > 0; size--) { 16 | checksum = (checksum << 1) || (checksum >> 7); 17 | checksum += *source; 18 | eeprom_put_char(destination++, *(source++)); 19 | } 20 | eeprom_put_char(destination, checksum); 21 | } 22 | 23 | int memcpy_from_eeprom_with_checksum(char *destination, unsigned int source, unsigned int size) { 24 | unsigned char data, checksum = 0; 25 | for(; size > 0; size--) { 26 | data = eeprom_get_char(source++); 27 | checksum = (checksum << 1) || (checksum >> 7); 28 | checksum += data; 29 | *(destination++) = data; 30 | } 31 | return(checksum == eeprom_get_char(source)); 32 | } -------------------------------------------------------------------------------- /grbl 0.8 with SpindleControl/eeprom.h: -------------------------------------------------------------------------------- 1 | #ifndef eeprom_h 2 | #define eeprom_h 3 | 4 | char eeprom_get_char(unsigned int addr); 5 | void eeprom_put_char(unsigned int addr, char new_value); 6 | void memcpy_to_eeprom_with_checksum(unsigned int destination, char *source, unsigned int size); 7 | int memcpy_from_eeprom_with_checksum(char *destination, unsigned int source, unsigned int size); 8 | 9 | #endif 10 | -------------------------------------------------------------------------------- /grbl 0.8 with SpindleControl/examples/GRBLtoArduino/GRBLtoArduino.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Thanks for supporting Open-Hard/Soft-ware and thanks 3 | for all of the contributors to this project. 4 | 5 | For extra info on GRBL please have a look at my blog : 6 | http://blog.protoneer.co.nz/tag/grbl/ 7 | 8 | Grbl is free software: you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License as published by 10 | the Free Software Foundation, either version 3 of the License, or 11 | (at your option) any later version. 12 | 13 | Grbl is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | http://www.gnu.org/licenses/ 18 | */ 19 | 20 | /* 21 | Supported hardware: 22 | Arduino Duemilanove 23 | Arduino Uno 24 | Arduino Mega 2560 (Limited Testing) 25 | 26 | */ 27 | 28 | #include 29 | 30 | void setup(){ 31 | startGrbl(); 32 | } 33 | 34 | void loop(){} 35 | -------------------------------------------------------------------------------- /grbl 0.8 with SpindleControl/gcode.h: -------------------------------------------------------------------------------- 1 | /* 2 | gcode.h - rs274/ngc parser. 3 | Part of Grbl 4 | 5 | Copyright (c) 2009-2011 Simen Svale Skogsrud 6 | Copyright (c) 2011-2012 Sungeun K. Jeon 7 | 8 | Grbl is free software: you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License as published by 10 | the Free Software Foundation, either version 3 of the License, or 11 | (at your option) any later version. 12 | 13 | Grbl is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with Grbl. If not, see . 20 | */ 21 | 22 | #ifndef gcode_h 23 | #define gcode_h 24 | #include 25 | #include "nuts_bolts.h" 26 | 27 | // Define modal group internal numbers for checking multiple command violations and tracking the 28 | // type of command that is called in the block. A modal group is a group of g-code commands that are 29 | // mutually exclusive, or cannot exist on the same line, because they each toggle a state or execute 30 | // a unique motion. These are defined in the NIST RS274-NGC v3 g-code standard, available online, 31 | // and are similar/identical to other g-code interpreters by manufacturers (Haas,Fanuc,Mazak,etc). 32 | #define MODAL_GROUP_NONE 0 33 | #define MODAL_GROUP_0 1 // [G4,G10,G28,G30,G53,G92,G92.1] Non-modal 34 | #define MODAL_GROUP_1 2 // [G0,G1,G2,G3,G80] Motion 35 | #define MODAL_GROUP_2 3 // [G17,G18,G19] Plane selection 36 | #define MODAL_GROUP_3 4 // [G90,G91] Distance mode 37 | #define MODAL_GROUP_4 5 // [M0,M1,M2,M30] Stopping 38 | #define MODAL_GROUP_5 6 // [G93,G94] Feed rate mode 39 | #define MODAL_GROUP_6 7 // [G20,G21] Units 40 | #define MODAL_GROUP_7 8 // [M3,M4,M5] Spindle turning 41 | #define MODAL_GROUP_12 9 // [G54,G55,G56,G57,G58,G59] Coordinate system selection 42 | 43 | // Define command actions for within execution-type modal groups (motion, stopping, non-modal). Used 44 | // internally by the parser to know which command to execute. 45 | #define MOTION_MODE_SEEK 0 // G0 46 | #define MOTION_MODE_LINEAR 1 // G1 47 | #define MOTION_MODE_CW_ARC 2 // G2 48 | #define MOTION_MODE_CCW_ARC 3 // G3 49 | #define MOTION_MODE_CANCEL 4 // G80 50 | 51 | #define PROGRAM_FLOW_RUNNING 0 52 | #define PROGRAM_FLOW_PAUSED 1 // M0, M1 53 | #define PROGRAM_FLOW_COMPLETED 2 // M2, M30 54 | 55 | #define NON_MODAL_NONE 0 56 | #define NON_MODAL_DWELL 1 // G4 57 | #define NON_MODAL_SET_COORDINATE_DATA 2 // G10 58 | #define NON_MODAL_GO_HOME_0 3 // G28 59 | #define NON_MODAL_SET_HOME_0 4 // G28.1 60 | #define NON_MODAL_GO_HOME_1 5 // G30 61 | #define NON_MODAL_SET_HOME_1 6 // G30.1 62 | #define NON_MODAL_SET_COORDINATE_OFFSET 7 // G92 63 | #define NON_MODAL_RESET_COORDINATE_OFFSET 8 //G92.1 64 | 65 | typedef struct { 66 | uint8_t status_code; // Parser status for current block 67 | uint8_t motion_mode; // {G0, G1, G2, G3, G80} 68 | uint8_t inverse_feed_rate_mode; // {G93, G94} 69 | uint8_t inches_mode; // 0 = millimeter mode, 1 = inches mode {G20, G21} 70 | uint8_t absolute_mode; // 0 = relative motion, 1 = absolute motion {G90, G91} 71 | uint8_t program_flow; // {M0, M1, M2, M30} 72 | int8_t spindle_direction; // 1 = CW, -1 = CCW, 0 = Stop {M3, M4, M5} 73 | uint8_t coolant_mode; // 0 = Disable, 1 = Flood Enable {M8, M9} 74 | float feed_rate; // Millimeters/min 75 | // float seek_rate; // Millimeters/min. Will be used in v0.9 when axis independence is installed 76 | float position[3]; // Where the interpreter considers the tool to be at this point in the code 77 | uint8_t tool; 78 | // uint16_t spindle_speed; // RPM/100 79 | uint8_t plane_axis_0, 80 | plane_axis_1, 81 | plane_axis_2; // The axes of the selected plane 82 | uint8_t coord_select; // Active work coordinate system number. Default: 0=G54. 83 | float coord_system[N_AXIS]; // Current work coordinate system (G54+). Stores offset from absolute machine 84 | // position in mm. Loaded from EEPROM when called. 85 | float coord_offset[N_AXIS]; // Retains the G92 coordinate offset (work coordinates) relative to 86 | // machine zero in mm. Non-persistent. Cleared upon reset and boot. 87 | } parser_state_t; 88 | extern parser_state_t gc; 89 | 90 | // Initialize the parser 91 | void gc_init(); 92 | 93 | // Execute one block of rs275/ngc/g-code 94 | uint8_t gc_execute_line(char *line); 95 | 96 | // Set g-code parser position. Input in steps. 97 | void gc_set_current_position(int32_t x, int32_t y, int32_t z); 98 | 99 | #endif 100 | -------------------------------------------------------------------------------- /grbl 0.8 with SpindleControl/grblmain.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | main.c - An embedded CNC Controller with rs274/ngc (g-code) support 3 | Part of Grbl 4 | 5 | Copyright (c) 2009-2011 Simen Svale Skogsrud 6 | Copyright (c) 2011-2012 Sungeun K. Jeon 7 | 8 | Grbl is free software: you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License as published by 10 | the Free Software Foundation, either version 3 of the License, or 11 | (at your option) any later version. 12 | 13 | Grbl is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with Grbl. If not, see . 20 | */ 21 | 22 | /* A big thanks to Alden Hart of Synthetos, supplier of grblshield and TinyG, who has 23 | been integral throughout the development of the higher level details of Grbl, as well 24 | as being a consistent sounding board for the future of accessible and free CNC. */ 25 | 26 | #include 27 | #include 28 | #include "config.h" 29 | #include "planner.h" 30 | #include "nuts_bolts.h" 31 | #include "stepper.h" 32 | #include "spindle_control.h" 33 | #include "coolant_control.h" 34 | #include "motion_control.h" 35 | #include "gcode.h" 36 | #include "protocol.h" 37 | #include "limits.h" 38 | #include "report.h" 39 | #include "settings.h" 40 | #include "serial.h" 41 | 42 | // Declare system global variable structure 43 | system_t sys; 44 | 45 | int startGrbl(void) 46 | { 47 | // Initialize system 48 | serial_init(); // Setup serial baud rate and interrupts 49 | settings_init(); // Load grbl settings from EEPROM 50 | st_init(); // Setup stepper pins and interrupt timers 51 | sei(); // Enable interrupts 52 | 53 | memset(&sys, 0, sizeof(sys)); // Clear all system variables 54 | sys.abort = true; // Set abort to complete initialization 55 | sys.state = STATE_INIT; // Set alarm state to indicate unknown initial position 56 | 57 | for(;;) { 58 | 59 | // Execute system reset upon a system abort, where the main program will return to this loop. 60 | // Once here, it is safe to re-initialize the system. At startup, the system will automatically 61 | // reset to finish the initialization process. 62 | if (sys.abort) { 63 | // Reset system. 64 | serial_reset_read_buffer(); // Clear serial read buffer 65 | plan_init(); // Clear block buffer and planner variables 66 | gc_init(); // Set g-code parser to default state 67 | protocol_init(); // Clear incoming line data and execute startup lines 68 | spindle_init(); 69 | coolant_init(); 70 | limits_init(); 71 | st_reset(); // Clear stepper subsystem variables. 72 | 73 | // Sync cleared gcode and planner positions to current system position, which is only 74 | // cleared upon startup, not a reset/abort. 75 | sys_sync_current_position(); 76 | 77 | // Reset system variables. 78 | sys.abort = false; 79 | sys.execute = 0; 80 | if (bit_istrue(settings.flags,BITFLAG_AUTO_START)) { sys.auto_start = true; } 81 | 82 | // Check for power-up and set system alarm if homing is enabled to force homing cycle 83 | // by setting Grbl's alarm state. Alarm locks out all g-code commands, including the 84 | // startup scripts, but allows access to settings and internal commands. Only a homing 85 | // cycle '$H' or kill alarm locks '$X' will disable the alarm. 86 | // NOTE: The startup script will run after successful completion of the homing cycle, but 87 | // not after disabling the alarm locks. Prevents motion startup blocks from crashing into 88 | // things uncontrollably. Very bad. 89 | #ifdef HOMING_INIT_LOCK 90 | if (sys.state == STATE_INIT && bit_istrue(settings.flags,BITFLAG_HOMING_ENABLE)) { sys.state = STATE_ALARM; } 91 | #endif 92 | 93 | // Check for and report alarm state after a reset, error, or an initial power up. 94 | if (sys.state == STATE_ALARM) { 95 | report_feedback_message(MESSAGE_ALARM_LOCK); 96 | } else { 97 | // All systems go. Set system to ready and execute startup script. 98 | sys.state = STATE_IDLE; 99 | protocol_execute_startup(); 100 | } 101 | } 102 | 103 | protocol_execute_runtime(); 104 | protocol_process(); // ... process the serial protocol 105 | 106 | } 107 | return 0; /* never reached */ 108 | } 109 | -------------------------------------------------------------------------------- /grbl 0.8 with SpindleControl/grblmain.h: -------------------------------------------------------------------------------- 1 | #ifndef grblmain_h 2 | #define grblmain_h 3 | 4 | void startGrbl(); 5 | 6 | #endif -------------------------------------------------------------------------------- /grbl 0.8 with SpindleControl/limits.h: -------------------------------------------------------------------------------- 1 | /* 2 | limits.h - code pertaining to limit-switches and performing the homing cycle 3 | Part of Grbl 4 | 5 | Copyright (c) 2009-2011 Simen Svale Skogsrud 6 | 7 | Grbl is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation, either version 3 of the License, or 10 | (at your option) any later version. 11 | 12 | Grbl is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with Grbl. If not, see . 19 | */ 20 | 21 | #ifndef limits_h 22 | #define limits_h 23 | 24 | // initialize the limits module 25 | void limits_init(); 26 | 27 | // perform the homing cycle 28 | void limits_go_home(); 29 | 30 | #endif -------------------------------------------------------------------------------- /grbl 0.8 with SpindleControl/motion_control.h: -------------------------------------------------------------------------------- 1 | /* 2 | motion_control.h - high level interface for issuing motion commands 3 | Part of Grbl 4 | 5 | Copyright (c) 2009-2011 Simen Svale Skogsrud 6 | Copyright (c) 2011-2012 Sungeun K. Jeon 7 | 8 | Grbl is free software: you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License as published by 10 | the Free Software Foundation, either version 3 of the License, or 11 | (at your option) any later version. 12 | 13 | Grbl is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with Grbl. If not, see . 20 | */ 21 | 22 | #ifndef motion_control_h 23 | #define motion_control_h 24 | 25 | #include 26 | #include "planner.h" 27 | 28 | // Execute linear motion in absolute millimeter coordinates. Feed rate given in millimeters/second 29 | // unless invert_feed_rate is true. Then the feed_rate means that the motion should be completed in 30 | // (1 minute)/feed_rate time. 31 | void mc_line(float x, float y, float z, float feed_rate, uint8_t invert_feed_rate); 32 | 33 | // Execute an arc in offset mode format. position == current xyz, target == target xyz, 34 | // offset == offset from current xyz, axis_XXX defines circle plane in tool space, axis_linear is 35 | // the direction of helical travel, radius == circle radius, isclockwise boolean. Used 36 | // for vector transformation direction. 37 | void mc_arc(float *position, float *target, float *offset, uint8_t axis_0, uint8_t axis_1, 38 | uint8_t axis_linear, float feed_rate, uint8_t invert_feed_rate, float radius, uint8_t isclockwise); 39 | 40 | // Dwell for a specific number of seconds 41 | void mc_dwell(float seconds); 42 | 43 | // Perform homing cycle to locate machine zero. Requires limit switches. 44 | void mc_go_home(); 45 | 46 | // Performs system reset. If in motion state, kills all motion and sets system alarm. 47 | void mc_reset(); 48 | 49 | #endif 50 | -------------------------------------------------------------------------------- /grbl 0.8 with SpindleControl/nuts_bolts.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | nuts_bolts.c - Shared functions 3 | Part of Grbl 4 | 5 | Copyright (c) 2009-2011 Simen Svale Skogsrud 6 | Copyright (c) 2011-2012 Sungeun K. Jeon 7 | 8 | Grbl is free software: you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License as published by 10 | the Free Software Foundation, either version 3 of the License, or 11 | (at your option) any later version. 12 | 13 | Grbl is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with Grbl. If not, see . 20 | */ 21 | 22 | #include 23 | #include "nuts_bolts.h" 24 | #include "gcode.h" 25 | #include "planner.h" 26 | 27 | #define MAX_INT_DIGITS 8 // Maximum number of digits in int32 (and float) 28 | 29 | // Extracts a floating point value from a string. The following code is based loosely on 30 | // the avr-libc strtod() function by Michael Stumpf and Dmitry Xmelkov and many freely 31 | // available conversion method examples, but has been highly optimized for Grbl. For known 32 | // CNC applications, the typical decimal value is expected to be in the range of E0 to E-4. 33 | // Scientific notation is officially not supported by g-code, and the 'E' character may 34 | // be a g-code word on some CNC systems. So, 'E' notation will not be recognized. 35 | // NOTE: Thanks to Radu-Eosif Mihailescu for identifying the issues with using strtod(). 36 | int read_float(char *line, uint8_t *char_counter, float *float_ptr) 37 | { 38 | char *ptr = line + *char_counter; 39 | unsigned char c; 40 | 41 | // Grab first character and increment pointer. No spaces assumed in line. 42 | c = *ptr++; 43 | 44 | // Capture initial positive/minus character 45 | bool isnegative = false; 46 | if (c == '-') { 47 | isnegative = true; 48 | c = *ptr++; 49 | } else if (c == '+') { 50 | c = *ptr++; 51 | } 52 | 53 | // Extract number into fast integer. Track decimal in terms of exponent value. 54 | uint32_t intval = 0; 55 | int8_t exp = 0; 56 | uint8_t ndigit = 0; 57 | bool isdecimal = false; 58 | while(1) { 59 | c -= '0'; 60 | if (c <= 9) { 61 | ndigit++; 62 | if (ndigit <= MAX_INT_DIGITS) { 63 | if (isdecimal) { exp--; } 64 | intval = (((intval << 2) + intval) << 1) + c; // intval*10 + c 65 | } else { 66 | if (!(isdecimal)) { exp++; } // Drop overflow digits 67 | } 68 | } else if (c == (('.'-'0') & 0xff) && !(isdecimal)) { 69 | isdecimal = true; 70 | } else { 71 | break; 72 | } 73 | c = *ptr++; 74 | } 75 | 76 | // Return if no digits have been read. 77 | if (!ndigit) { return(false); }; 78 | 79 | // Convert integer into floating point. 80 | float fval; 81 | fval = (float)intval; 82 | 83 | // Apply decimal. Should perform no more than two floating point multiplications for the 84 | // expected range of E0 to E-4. 85 | if (fval != 0) { 86 | while (exp <= -2) { 87 | fval *= 0.01; 88 | exp += 2; 89 | } 90 | if (exp < 0) { 91 | fval *= 0.1; 92 | } else if (exp > 0) { 93 | do { 94 | fval *= 10.0; 95 | } while (--exp > 0); 96 | } 97 | } 98 | 99 | // Assign floating point value with correct sign. 100 | if (isnegative) { 101 | *float_ptr = -fval; 102 | } else { 103 | *float_ptr = fval; 104 | } 105 | 106 | *char_counter = ptr - line - 1; // Set char_counter to next statement 107 | 108 | return(true); 109 | } 110 | 111 | 112 | // Delays variable defined milliseconds. Compiler compatibility fix for _delay_ms(), 113 | // which only accepts constants in future compiler releases. 114 | void delay_ms(uint16_t ms) 115 | { 116 | while ( ms-- ) { _delay_ms(1); } 117 | } 118 | 119 | 120 | // Delays variable defined microseconds. Compiler compatibility fix for _delay_us(), 121 | // which only accepts constants in future compiler releases. Written to perform more 122 | // efficiently with larger delays, as the counter adds parasitic time in each iteration. 123 | void delay_us(uint32_t us) 124 | { 125 | while (us) { 126 | if (us < 10) { 127 | _delay_us(1); 128 | us--; 129 | } else if (us < 100) { 130 | _delay_us(10); 131 | us -= 10; 132 | } else if (us < 1000) { 133 | _delay_us(100); 134 | us -= 100; 135 | } else { 136 | _delay_ms(1); 137 | us -= 1000; 138 | } 139 | } 140 | } 141 | 142 | // Syncs all internal position vectors to the current system position. 143 | void sys_sync_current_position() 144 | { 145 | plan_set_current_position(sys.position[X_AXIS],sys.position[Y_AXIS],sys.position[Z_AXIS]); 146 | gc_set_current_position(sys.position[X_AXIS],sys.position[Y_AXIS],sys.position[Z_AXIS]); 147 | } 148 | -------------------------------------------------------------------------------- /grbl 0.8 with SpindleControl/nuts_bolts.h: -------------------------------------------------------------------------------- 1 | /* 2 | nuts_bolts.h - Header file for shared definitions, variables, and functions 3 | Part of Grbl 4 | 5 | Copyright (c) 2009-2011 Simen Svale Skogsrud 6 | Copyright (c) 2011-2012 Sungeun K. Jeon 7 | 8 | Grbl is free software: you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License as published by 10 | the Free Software Foundation, either version 3 of the License, or 11 | (at your option) any later version. 12 | 13 | Grbl is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with Grbl. If not, see . 20 | */ 21 | 22 | #ifndef nuts_bolts_h 23 | #define nuts_bolts_h 24 | 25 | #include 26 | #include 27 | #include 28 | #include "config.h" 29 | #include "defaults.h" 30 | 31 | #define false 0 32 | #define true 1 33 | 34 | #define N_AXIS 3 // Number of axes 35 | #define X_AXIS 0 // Axis indexing value 36 | #define Y_AXIS 1 37 | #define Z_AXIS 2 38 | 39 | #define MM_PER_INCH (25.40) 40 | #define INCH_PER_MM (0.0393701) 41 | 42 | // Useful macros 43 | #define clear_vector(a) memset(a, 0, sizeof(a)) 44 | #define clear_vector_float(a) memset(a, 0.0, sizeof(float)*N_AXIS) 45 | #define max(a,b) (((a) > (b)) ? (a) : (b)) 46 | #define min(a,b) (((a) < (b)) ? (a) : (b)) 47 | 48 | // Bit field and masking macros 49 | #define bit(n) (1 << n) 50 | #define bit_true(x,mask) (x |= mask) 51 | #define bit_false(x,mask) (x &= ~mask) 52 | #define bit_toggle(x,mask) (x ^= mask) 53 | #define bit_istrue(x,mask) ((x & mask) != 0) 54 | #define bit_isfalse(x,mask) ((x & mask) == 0) 55 | 56 | // Define system executor bit map. Used internally by runtime protocol as runtime command flags, 57 | // which notifies the main program to execute the specified runtime command asynchronously. 58 | // NOTE: The system executor uses an unsigned 8-bit volatile variable (8 flag limit.) The default 59 | // flags are always false, so the runtime protocol only needs to check for a non-zero value to 60 | // know when there is a runtime command to execute. 61 | #define EXEC_STATUS_REPORT bit(0) // bitmask 00000001 62 | #define EXEC_CYCLE_START bit(1) // bitmask 00000010 63 | #define EXEC_CYCLE_STOP bit(2) // bitmask 00000100 64 | #define EXEC_FEED_HOLD bit(3) // bitmask 00001000 65 | #define EXEC_RESET bit(4) // bitmask 00010000 66 | #define EXEC_ALARM bit(5) // bitmask 00100000 67 | #define EXEC_CRIT_EVENT bit(6) // bitmask 01000000 68 | // #define bit(7) // bitmask 10000000 69 | 70 | // Define system state bit map. The state variable primarily tracks the individual functions 71 | // of Grbl to manage each without overlapping. It is also used as a messaging flag for 72 | // critical events. 73 | #define STATE_IDLE 0 // Must be zero. 74 | #define STATE_INIT 1 // Initial power up state. 75 | #define STATE_QUEUED 2 // Indicates buffered blocks, awaiting cycle start. 76 | #define STATE_CYCLE 3 // Cycle is running 77 | #define STATE_HOLD 4 // Executing feed hold 78 | #define STATE_HOMING 5 // Performing homing cycle 79 | #define STATE_ALARM 6 // In alarm state. Locks out all g-code processes. Allows settings access. 80 | #define STATE_CHECK_MODE 7 // G-code check mode. Locks out planner and motion only. 81 | // #define STATE_JOG 8 // Jogging mode is unique like homing. 82 | 83 | // Define global system variables 84 | typedef struct { 85 | uint8_t abort; // System abort flag. Forces exit back to main loop for reset. 86 | uint8_t state; // Tracks the current state of Grbl. 87 | volatile uint8_t execute; // Global system runtime executor bitflag variable. See EXEC bitmasks. 88 | int32_t position[N_AXIS]; // Real-time machine (aka home) position vector in steps. 89 | // NOTE: This may need to be a volatile variable, if problems arise. 90 | uint8_t auto_start; // Planner auto-start flag. Toggled off during feed hold. Defaulted by settings. 91 | } system_t; 92 | extern system_t sys; 93 | 94 | // Read a floating point value from a string. Line points to the input buffer, char_counter 95 | // is the indexer pointing to the current character of the line, while float_ptr is 96 | // a pointer to the result variable. Returns true when it succeeds 97 | int read_float(char *line, uint8_t *char_counter, float *float_ptr); 98 | 99 | // Delays variable-defined milliseconds. Compiler compatibility fix for _delay_ms(). 100 | void delay_ms(uint16_t ms); 101 | 102 | // Delays variable-defined microseconds. Compiler compatibility fix for _delay_us(). 103 | void delay_us(uint32_t us); 104 | 105 | // Syncs Grbl's gcode and planner position variables with the system position. 106 | void sys_sync_current_position(); 107 | 108 | #endif 109 | -------------------------------------------------------------------------------- /grbl 0.8 with SpindleControl/planner.h: -------------------------------------------------------------------------------- 1 | /* 2 | planner.h - buffers movement commands and manages the acceleration profile plan 3 | Part of Grbl 4 | 5 | Copyright (c) 2009-2011 Simen Svale Skogsrud 6 | Copyright (c) 2011-2012 Sungeun K. Jeon 7 | 8 | Grbl is free software: you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License as published by 10 | the Free Software Foundation, either version 3 of the License, or 11 | (at your option) any later version. 12 | 13 | Grbl is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with Grbl. If not, see . 20 | */ 21 | 22 | #ifndef planner_h 23 | #define planner_h 24 | 25 | // The number of linear motions that can be in the plan at any give time 26 | #ifndef BLOCK_BUFFER_SIZE 27 | #define BLOCK_BUFFER_SIZE 18 28 | #endif 29 | 30 | // This struct is used when buffering the setup for each linear movement "nominal" values are as specified in 31 | // the source g-code and may never actually be reached if acceleration management is active. 32 | typedef struct { 33 | 34 | // Fields used by the bresenham algorithm for tracing the line 35 | uint8_t direction_bits; // The direction bit set for this block (refers to *_DIRECTION_BIT in config.h) 36 | uint32_t steps_x, steps_y, steps_z; // Step count along each axis 37 | int32_t step_event_count; // The number of step events required to complete this block 38 | 39 | // Fields used by the motion planner to manage acceleration 40 | float nominal_speed; // The nominal speed for this block in mm/min 41 | float entry_speed; // Entry speed at previous-current block junction in mm/min 42 | float max_entry_speed; // Maximum allowable junction entry speed in mm/min 43 | float millimeters; // The total travel of this block in mm 44 | uint8_t recalculate_flag; // Planner flag to recalculate trapezoids on entry junction 45 | uint8_t nominal_length_flag; // Planner flag for nominal speed always reached 46 | 47 | // Settings for the trapezoid generator 48 | uint32_t initial_rate; // The step rate at start of block 49 | uint32_t final_rate; // The step rate at end of block 50 | int32_t rate_delta; // The steps/minute to add or subtract when changing speed (must be positive) 51 | uint32_t accelerate_until; // The index of the step event on which to stop acceleration 52 | uint32_t decelerate_after; // The index of the step event on which to start decelerating 53 | uint32_t nominal_rate; // The nominal step rate for this block in step_events/minute 54 | 55 | } block_t; 56 | 57 | // Initialize the motion plan subsystem 58 | void plan_init(); 59 | 60 | // Add a new linear movement to the buffer. x, y and z is the signed, absolute target position in 61 | // millimaters. Feed rate specifies the speed of the motion. If feed rate is inverted, the feed 62 | // rate is taken to mean "frequency" and would complete the operation in 1/feed_rate minutes. 63 | void plan_buffer_line(float x, float y, float z, float feed_rate, uint8_t invert_feed_rate); 64 | 65 | // Called when the current block is no longer needed. Discards the block and makes the memory 66 | // availible for new blocks. 67 | void plan_discard_current_block(); 68 | 69 | // Gets the current block. Returns NULL if buffer empty 70 | block_t *plan_get_current_block(); 71 | 72 | // Reset the planner position vector (in steps) 73 | void plan_set_current_position(int32_t x, int32_t y, int32_t z); 74 | 75 | // Reinitialize plan with a partially completed block 76 | void plan_cycle_reinitialize(int32_t step_events_remaining); 77 | 78 | // Reset buffer 79 | void plan_reset_buffer(); 80 | 81 | // Returns the status of the block ring buffer. True, if buffer is full. 82 | uint8_t plan_check_full_buffer(); 83 | 84 | // Block until all buffered steps are executed 85 | void plan_synchronize(); 86 | 87 | #endif 88 | -------------------------------------------------------------------------------- /grbl 0.8 with SpindleControl/print.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | print.c - Functions for formatting output strings 3 | Part of Grbl 4 | 5 | Copyright (c) 2009-2011 Simen Svale Skogsrud 6 | Copyright (c) 2011-2012 Sungeun K. Jeon 7 | 8 | Grbl is free software: you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License as published by 10 | the Free Software Foundation, either version 3 of the License, or 11 | (at your option) any later version. 12 | 13 | Grbl is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with Grbl. If not, see . 20 | */ 21 | 22 | /* This code was initially inspired by the wiring_serial module by David A. Mellis which 23 | used to be a part of the Arduino project. */ 24 | 25 | 26 | #include 27 | #include "config.h" 28 | #include "serial.h" 29 | #include "settings.h" 30 | 31 | void printString(const char *s) 32 | { 33 | while (*s) 34 | serial_write(*s++); 35 | } 36 | 37 | // Print a string stored in PGM-memory 38 | void printPgmString(const char *s) 39 | { 40 | char c; 41 | while ((c = pgm_read_byte_near(s++))) 42 | serial_write(c); 43 | } 44 | 45 | // void printIntegerInBase(unsigned long n, unsigned long base) 46 | // { 47 | // unsigned char buf[8 * sizeof(long)]; // Assumes 8-bit chars. 48 | // unsigned long i = 0; 49 | // 50 | // if (n == 0) { 51 | // serial_write('0'); 52 | // return; 53 | // } 54 | // 55 | // while (n > 0) { 56 | // buf[i++] = n % base; 57 | // n /= base; 58 | // } 59 | // 60 | // for (; i > 0; i--) 61 | // serial_write(buf[i - 1] < 10 ? 62 | // '0' + buf[i - 1] : 63 | // 'A' + buf[i - 1] - 10); 64 | // } 65 | 66 | void print_uint8_base2(uint8_t n) 67 | { 68 | unsigned char buf[8]; 69 | uint8_t i = 0; 70 | 71 | for (; i < 8; i++) { 72 | buf[i] = n & 1; 73 | n >>= 1; 74 | } 75 | 76 | for (; i > 0; i--) 77 | serial_write('0' + buf[i - 1]); 78 | } 79 | 80 | static void print_uint32_base10(unsigned long n) 81 | { 82 | unsigned char buf[10]; 83 | uint8_t i = 0; 84 | 85 | if (n == 0) { 86 | serial_write('0'); 87 | return; 88 | } 89 | 90 | while (n > 0) { 91 | buf[i++] = n % 10 + '0'; 92 | n /= 10; 93 | } 94 | 95 | for (; i > 0; i--) 96 | serial_write(buf[i-1]); 97 | } 98 | 99 | void printInteger(long n) 100 | { 101 | if (n < 0) { 102 | serial_write('-'); 103 | n = -n; 104 | } 105 | print_uint32_base10(n); 106 | } 107 | 108 | // Convert float to string by immediately converting to a long integer, which contains 109 | // more digits than a float. Number of decimal places, which are tracked by a counter, 110 | // may be set by the user. The integer is then efficiently converted to a string. 111 | // NOTE: AVR '%' and '/' integer operations are very efficient. Bitshifting speed-up 112 | // techniques are actually just slightly slower. Found this out the hard way. 113 | void printFloat(float n) 114 | { 115 | if (n < 0) { 116 | serial_write('-'); 117 | n = -n; 118 | } 119 | 120 | uint8_t decimals = settings.decimal_places; 121 | while (decimals >= 2) { // Quickly convert values expected to be E0 to E-4. 122 | n *= 100; 123 | decimals -= 2; 124 | } 125 | if (decimals) { n *= 10; } 126 | n += 0.5; // Add rounding factor. Ensures carryover through entire value. 127 | 128 | // Generate digits backwards and store in string. 129 | unsigned char buf[10]; 130 | uint8_t i = 0; 131 | uint32_t a = (long)n; 132 | buf[settings.decimal_places] = '.'; // Place decimal point, even if decimal places are zero. 133 | while(a > 0) { 134 | if (i == settings.decimal_places) { i++; } // Skip decimal point location 135 | buf[i++] = (a % 10) + '0'; // Get digit 136 | a /= 10; 137 | } 138 | while (i < settings.decimal_places) { 139 | buf[i++] = '0'; // Fill in zeros to decimal point for (n < 1) 140 | } 141 | if (i == settings.decimal_places) { // Fill in leading zero, if needed. 142 | i++; 143 | buf[i++] = '0'; 144 | } 145 | 146 | // Print the generated string. 147 | for (; i > 0; i--) 148 | serial_write(buf[i-1]); 149 | } 150 | -------------------------------------------------------------------------------- /grbl 0.8 with SpindleControl/print.h: -------------------------------------------------------------------------------- 1 | /* 2 | print.h - Functions for formatting output strings 3 | Part of Grbl 4 | 5 | Copyright (c) 2009-2011 Simen Svale Skogsrud 6 | Copyright (c) 2011-2012 Sungeun K. Jeon 7 | 8 | Grbl is free software: you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License as published by 10 | the Free Software Foundation, either version 3 of the License, or 11 | (at your option) any later version. 12 | 13 | Grbl is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with Grbl. If not, see . 20 | */ 21 | 22 | /* This code was initially inspired by the wiring_serial module by David A. Mellis which 23 | used to be a part of the Arduino project. */ 24 | 25 | #ifndef print_h 26 | #define print_h 27 | 28 | void printString(const char *s); 29 | 30 | void printPgmString(const char *s); 31 | 32 | void printInteger(long n); 33 | 34 | void print_uint8_base2(uint8_t n); 35 | 36 | void printFloat(float n); 37 | 38 | #endif -------------------------------------------------------------------------------- /grbl 0.8 with SpindleControl/protocol.h: -------------------------------------------------------------------------------- 1 | /* 2 | protocol.h - the serial protocol master control unit 3 | Part of Grbl 4 | 5 | Copyright (c) 2009-2011 Simen Svale Skogsrud 6 | Copyright (c) 2011-2012 Sungeun K. Jeon 7 | 8 | Grbl is free software: you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License as published by 10 | the Free Software Foundation, either version 3 of the License, or 11 | (at your option) any later version. 12 | 13 | Grbl is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with Grbl. If not, see . 20 | */ 21 | #ifndef protocol_h 22 | #define protocol_h 23 | 24 | #include 25 | 26 | // Line buffer size from the serial input stream to be executed. 27 | // NOTE: Not a problem except for extreme cases, but the line buffer size can be too small 28 | // and g-code blocks can get truncated. Officially, the g-code standards support up to 256 29 | // characters. In future versions, this will be increased, when we know how much extra 30 | // memory space we can invest into here or we re-write the g-code parser not to have his 31 | // buffer. 32 | #ifndef LINE_BUFFER_SIZE 33 | #define LINE_BUFFER_SIZE 50 34 | #endif 35 | 36 | // Initialize the serial protocol 37 | void protocol_init(); 38 | 39 | // Read command lines from the serial port and execute them as they 40 | // come in. Blocks until the serial buffer is emptied. 41 | void protocol_process(); 42 | 43 | // Executes one line of input according to protocol 44 | uint8_t protocol_execute_line(char *line); 45 | 46 | // Checks and executes a runtime command at various stop points in main program 47 | void protocol_execute_runtime(); 48 | 49 | // Execute the startup script lines stored in EEPROM upon initialization 50 | void protocol_execute_startup(); 51 | 52 | #endif 53 | -------------------------------------------------------------------------------- /grbl 0.8 with SpindleControl/report.h: -------------------------------------------------------------------------------- 1 | /* 2 | report.h - reporting and messaging methods 3 | Part of Grbl 4 | 5 | Copyright (c) 2012 Sungeun K. Jeon 6 | 7 | Grbl is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation, either version 3 of the License, or 10 | (at your option) any later version. 11 | 12 | Grbl is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with Grbl. If not, see . 19 | */ 20 | #ifndef report_h 21 | #define report_h 22 | 23 | 24 | // Define Grbl status codes. 25 | #define STATUS_OK 0 26 | #define STATUS_BAD_NUMBER_FORMAT 1 27 | #define STATUS_EXPECTED_COMMAND_LETTER 2 28 | #define STATUS_UNSUPPORTED_STATEMENT 3 29 | #define STATUS_ARC_RADIUS_ERROR 4 30 | #define STATUS_MODAL_GROUP_VIOLATION 5 31 | #define STATUS_INVALID_STATEMENT 6 32 | #define STATUS_SETTING_DISABLED 7 33 | #define STATUS_SETTING_VALUE_NEG 8 34 | #define STATUS_SETTING_STEP_PULSE_MIN 9 35 | #define STATUS_SETTING_READ_FAIL 10 36 | #define STATUS_IDLE_ERROR 11 37 | #define STATUS_ALARM_LOCK 12 38 | 39 | // Define Grbl alarm codes. Less than zero to distinguish alarm error from status error. 40 | #define ALARM_HARD_LIMIT -1 41 | #define ALARM_ABORT_CYCLE -2 42 | 43 | // Define Grbl feedback message codes. 44 | #define MESSAGE_CRITICAL_EVENT 1 45 | #define MESSAGE_ALARM_LOCK 2 46 | #define MESSAGE_ALARM_UNLOCK 3 47 | #define MESSAGE_ENABLED 4 48 | #define MESSAGE_DISABLED 5 49 | 50 | // Prints system status messages. 51 | void report_status_message(uint8_t status_code); 52 | 53 | // Prints system alarm messages. 54 | void report_alarm_message(int8_t alarm_code); 55 | 56 | // Prints miscellaneous feedback messages. 57 | void report_feedback_message(uint8_t message_code); 58 | 59 | // Prints welcome message 60 | void report_init_message(); 61 | 62 | // Prints Grbl help and current global settings 63 | void report_grbl_help(); 64 | 65 | // Prints Grbl global settings 66 | void report_grbl_settings(); 67 | 68 | // Prints realtime status report 69 | void report_realtime_status(); 70 | 71 | // Prints Grbl persistent coordinate parameters 72 | void report_gcode_parameters(); 73 | 74 | // Prints current g-code parser mode state 75 | void report_gcode_modes(); 76 | 77 | // Prints startup line 78 | void report_startup_line(uint8_t n, char *line); 79 | 80 | #endif 81 | -------------------------------------------------------------------------------- /grbl 0.8 with SpindleControl/serial.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | serial.c - Low level functions for sending and recieving bytes via the serial port 3 | Part of Grbl 4 | 5 | Copyright (c) 2009-2011 Simen Svale Skogsrud 6 | Copyright (c) 2011-2012 Sungeun K. Jeon 7 | 8 | Grbl is free software: you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License as published by 10 | the Free Software Foundation, either version 3 of the License, or 11 | (at your option) any later version. 12 | 13 | Grbl is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with Grbl. If not, see . 20 | */ 21 | 22 | /* This code was initially inspired by the wiring_serial module by David A. Mellis which 23 | used to be a part of the Arduino project. */ 24 | 25 | #include 26 | #include "serial.h" 27 | #include "config.h" 28 | #include "motion_control.h" 29 | #include "protocol.h" 30 | 31 | 32 | uint8_t rx_buffer[RX_BUFFER_SIZE]; 33 | uint8_t rx_buffer_head = 0; 34 | uint8_t rx_buffer_tail = 0; 35 | 36 | uint8_t tx_buffer[TX_BUFFER_SIZE]; 37 | uint8_t tx_buffer_head = 0; 38 | volatile uint8_t tx_buffer_tail = 0; 39 | 40 | #ifdef ENABLE_XONXOFF 41 | volatile uint8_t flow_ctrl = XON_SENT; // Flow control state variable 42 | 43 | // Returns the number of bytes in the RX buffer. This replaces a typical byte counter to prevent 44 | // the interrupt and main programs from writing to the counter at the same time. 45 | static uint8_t get_rx_buffer_count() 46 | { 47 | if (rx_buffer_head == rx_buffer_tail) { return(0); } 48 | if (rx_buffer_head < rx_buffer_tail) { return(rx_buffer_tail-rx_buffer_head); } 49 | return (RX_BUFFER_SIZE - (rx_buffer_head-rx_buffer_tail)); 50 | } 51 | #endif 52 | 53 | 54 | void serial_init() 55 | { 56 | // Set baud rate 57 | #if BAUD_RATE < 57600 58 | uint16_t UBRR0_value = ((F_CPU / (8L * BAUD_RATE)) - 1)/2 ; 59 | UCSR0A &= ~(1 << U2X0); // baud doubler off - Only needed on Uno XXX 60 | #else 61 | uint16_t UBRR0_value = ((F_CPU / (4L * BAUD_RATE)) - 1)/2; 62 | UCSR0A |= (1 << U2X0); // baud doubler on for high baud rates, i.e. 115200 63 | #endif 64 | UBRR0H = UBRR0_value >> 8; 65 | UBRR0L = UBRR0_value; 66 | 67 | // enable rx and tx 68 | UCSR0B |= 1<= RX_BUFFER_FULL) && flow_ctrl == XON_SENT) { 183 | flow_ctrl = SEND_XOFF; 184 | UCSR0B |= (1 << UDRIE0); // Force TX 185 | } 186 | #endif 187 | 188 | } 189 | 190 | } 191 | } 192 | 193 | void serial_reset_read_buffer() 194 | { 195 | rx_buffer_tail = rx_buffer_head; 196 | 197 | #ifdef ENABLE_XONXOFF 198 | flow_ctrl = XON_SENT; 199 | #endif 200 | } -------------------------------------------------------------------------------- /grbl 0.8 with SpindleControl/serial.h: -------------------------------------------------------------------------------- 1 | /* 2 | serial.c - Low level functions for sending and recieving bytes via the serial port 3 | Part of Grbl 4 | 5 | Copyright (c) 2009-2011 Simen Svale Skogsrud 6 | Copyright (c) 2011-2012 Sungeun K. Jeon 7 | 8 | Grbl is free software: you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License as published by 10 | the Free Software Foundation, either version 3 of the License, or 11 | (at your option) any later version. 12 | 13 | Grbl is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with Grbl. If not, see . 20 | */ 21 | 22 | /* This code was initially inspired by the wiring_serial module by David A. Mellis which 23 | used to be a part of the Arduino project. */ 24 | 25 | #ifndef serial_h 26 | #define serial_h 27 | 28 | #include "nuts_bolts.h" 29 | 30 | #ifndef RX_BUFFER_SIZE 31 | #define RX_BUFFER_SIZE 128 32 | #endif 33 | #ifndef TX_BUFFER_SIZE 34 | #define TX_BUFFER_SIZE 64 35 | #endif 36 | 37 | #define SERIAL_NO_DATA 0xff 38 | 39 | #ifdef ENABLE_XONXOFF 40 | #define RX_BUFFER_FULL 96 // XOFF high watermark 41 | #define RX_BUFFER_LOW 64 // XON low watermark 42 | #define SEND_XOFF 1 43 | #define SEND_XON 2 44 | #define XOFF_SENT 3 45 | #define XON_SENT 4 46 | #define XOFF_CHAR 0x13 47 | #define XON_CHAR 0x11 48 | #endif 49 | 50 | void serial_init(); 51 | 52 | void serial_write(uint8_t data); 53 | 54 | uint8_t serial_read(); 55 | 56 | // Reset and empty data in read buffer. Used by e-stop and reset. 57 | void serial_reset_read_buffer(); 58 | 59 | #endif 60 | -------------------------------------------------------------------------------- /grbl 0.8 with SpindleControl/settings.h: -------------------------------------------------------------------------------- 1 | /* 2 | settings.h - eeprom configuration handling 3 | Part of Grbl 4 | 5 | Copyright (c) 2009-2011 Simen Svale Skogsrud 6 | Copyright (c) 2011-2012 Sungeun K. Jeon 7 | 8 | Grbl is free software: you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License as published by 10 | the Free Software Foundation, either version 3 of the License, or 11 | (at your option) any later version. 12 | 13 | Grbl is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with Grbl. If not, see . 20 | */ 21 | 22 | #ifndef settings_h 23 | #define settings_h 24 | 25 | #include 26 | #include "nuts_bolts.h" 27 | 28 | #define GRBL_VERSION "0.8c" 29 | 30 | // Version of the EEPROM data. Will be used to migrate existing data from older versions of Grbl 31 | // when firmware is upgraded. Always stored in byte 0 of eeprom 32 | #define SETTINGS_VERSION 5 33 | 34 | // Define bit flag masks for the boolean settings in settings.flag. 35 | #define BITFLAG_REPORT_INCHES bit(0) 36 | #define BITFLAG_AUTO_START bit(1) 37 | #define BITFLAG_INVERT_ST_ENABLE bit(2) 38 | #define BITFLAG_HARD_LIMIT_ENABLE bit(3) 39 | #define BITFLAG_HOMING_ENABLE bit(4) 40 | 41 | // Define EEPROM memory address location values for Grbl settings and parameters 42 | // NOTE: The Atmega328p has 1KB EEPROM. The upper half is reserved for parameters and 43 | // the startup script. The lower half contains the global settings and space for future 44 | // developments. 45 | #define EEPROM_ADDR_GLOBAL 1 46 | #define EEPROM_ADDR_PARAMETERS 512 47 | #define EEPROM_ADDR_STARTUP_BLOCK 768 48 | 49 | // Define EEPROM address indexing for coordinate parameters 50 | #define N_COORDINATE_SYSTEM 6 // Number of supported work coordinate systems (from index 1) 51 | #define SETTING_INDEX_NCOORD N_COORDINATE_SYSTEM+1 // Total number of system stored (from index 0) 52 | // NOTE: Work coordinate indices are (0=G54, 1=G55, ... , 6=G59) 53 | #define SETTING_INDEX_G28 N_COORDINATE_SYSTEM // Home position 1 54 | #define SETTING_INDEX_G30 N_COORDINATE_SYSTEM+1 // Home position 2 55 | // #define SETTING_INDEX_G92 N_COORDINATE_SYSTEM+2 // Coordinate offset (G92.2,G92.3 not supported) 56 | 57 | // Global persistent settings (Stored from byte EEPROM_ADDR_GLOBAL onwards) 58 | typedef struct { 59 | float steps_per_mm[3]; 60 | uint8_t microsteps; 61 | uint8_t pulse_microseconds; 62 | float default_feed_rate; 63 | float default_seek_rate; 64 | uint8_t invert_mask; 65 | float mm_per_arc_segment; 66 | float acceleration; 67 | float junction_deviation; 68 | uint8_t flags; // Contains default boolean settings 69 | uint8_t homing_dir_mask; 70 | float homing_feed_rate; 71 | float homing_seek_rate; 72 | uint16_t homing_debounce_delay; 73 | float homing_pulloff; 74 | uint8_t stepper_idle_lock_time; // If max value 255, steppers do not disable. 75 | uint8_t decimal_places; 76 | uint8_t n_arc_correction; 77 | // uint8_t status_report_mask; // Mask to indicate desired report data. 78 | } settings_t; 79 | extern settings_t settings; 80 | 81 | // Initialize the configuration subsystem (load settings from EEPROM) 82 | void settings_init(); 83 | 84 | // A helper method to set new settings from command line 85 | uint8_t settings_store_global_setting(int parameter, float value); 86 | 87 | // Stores the protocol line variable as a startup line in EEPROM 88 | void settings_store_startup_line(uint8_t n, char *line); 89 | 90 | // Reads an EEPROM startup line to the protocol line variable 91 | uint8_t settings_read_startup_line(uint8_t n, char *line); 92 | 93 | // Writes selected coordinate data to EEPROM 94 | void settings_write_coord_data(uint8_t coord_select, float *coord_data); 95 | 96 | // Reads selected coordinate data from EEPROM 97 | uint8_t settings_read_coord_data(uint8_t coord_select, float *coord_data); 98 | 99 | #endif 100 | -------------------------------------------------------------------------------- /grbl 0.8 with SpindleControl/spindle_control.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | spindle_control.c - spindle control methods 3 | Part of Grbl 4 | 5 | Copyright (c) 2009-2011 Simen Svale Skogsrud 6 | Copyright (c) 2012 Sungeun K. Jeon 7 | 8 | Grbl is free software: you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License as published by 10 | the Free Software Foundation, either version 3 of the License, or 11 | (at your option) any later version. 12 | 13 | Grbl is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with Grbl. If not, see . 20 | */ 21 | 22 | #include "settings.h" 23 | #include "spindle_control.h" 24 | #include "planner.h" 25 | 26 | static uint8_t current_direction; 27 | 28 | void spindle_init() 29 | { 30 | current_direction = 0; 31 | SPINDLE_ENABLE_DDR |= (1< 0) { 47 | SPINDLE_DIRECTION_PORT &= ~(1<. 20 | */ 21 | 22 | #ifndef spindle_control_h 23 | #define spindle_control_h 24 | 25 | #include 26 | 27 | void spindle_init(); 28 | void spindle_run(int8_t direction); //, uint16_t rpm); 29 | void spindle_stop(); 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /grbl 0.8 with SpindleControl/stepper.h: -------------------------------------------------------------------------------- 1 | /* 2 | stepper.h - stepper motor driver: executes motion plans of planner.c using the stepper motors 3 | Part of Grbl 4 | 5 | Copyright (c) 2009-2011 Simen Svale Skogsrud 6 | Copyright (c) 2011 Sungeun K. Jeon 7 | 8 | Grbl is free software: you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License as published by 10 | the Free Software Foundation, either version 3 of the License, or 11 | (at your option) any later version. 12 | 13 | Grbl is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with Grbl. If not, see . 20 | */ 21 | 22 | #ifndef stepper_h 23 | #define stepper_h 24 | 25 | #include 26 | 27 | // Initialize and setup the stepper motor subsystem 28 | void st_init(); 29 | 30 | // Enable steppers, but cycle does not start unless called by motion control or runtime command. 31 | void st_wake_up(); 32 | 33 | // Immediately disables steppers 34 | void st_go_idle(); 35 | 36 | // Reset the stepper subsystem variables 37 | void st_reset(); 38 | 39 | // Notify the stepper subsystem to start executing the g-code program in buffer. 40 | void st_cycle_start(); 41 | 42 | // Reinitializes the buffer after a feed hold for a resume. 43 | void st_cycle_reinitialize(); 44 | 45 | // Initiates a feed hold of the running program 46 | void st_feed_hold(); 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /grbl.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TGit-Tech/GRBL-28byj-48/bad3e5654ec3ca98cdcff56d65f09ab4e1989e9f/grbl.zip -------------------------------------------------------------------------------- /grbl/coolant_control.c: -------------------------------------------------------------------------------- 1 | /* 2 | coolant_control.c - coolant control methods 3 | Part of Grbl 4 | 5 | Copyright (c) 2012-2016 Sungeun K. Jeon for Gnea Research LLC 6 | 7 | Grbl is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation, either version 3 of the License, or 10 | (at your option) any later version. 11 | 12 | Grbl is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with Grbl. If not, see . 19 | */ 20 | 21 | #include "grbl.h" 22 | 23 | 24 | void coolant_init() 25 | { 26 | COOLANT_FLOOD_DDR |= (1 << COOLANT_FLOOD_BIT); // Configure as output pin 27 | #ifdef ENABLE_M7 28 | COOLANT_MIST_DDR |= (1 << COOLANT_MIST_BIT); 29 | #endif 30 | coolant_stop(); 31 | } 32 | 33 | 34 | // Returns current coolant output state. Overrides may alter it from programmed state. 35 | uint8_t coolant_get_state() 36 | { 37 | uint8_t cl_state = COOLANT_STATE_DISABLE; 38 | #ifdef INVERT_COOLANT_FLOOD_PIN 39 | if (bit_isfalse(COOLANT_FLOOD_PORT,(1 << COOLANT_FLOOD_BIT))) { 40 | #else 41 | if (bit_istrue(COOLANT_FLOOD_PORT,(1 << COOLANT_FLOOD_BIT))) { 42 | #endif 43 | cl_state |= COOLANT_STATE_FLOOD; 44 | } 45 | #ifdef ENABLE_M7 46 | #ifdef INVERT_COOLANT_MIST_PIN 47 | if (bit_isfalse(COOLANT_MIST_PORT,(1 << COOLANT_MIST_BIT))) { 48 | #else 49 | if (bit_istrue(COOLANT_MIST_PORT,(1 << COOLANT_MIST_BIT))) { 50 | #endif 51 | cl_state |= COOLANT_STATE_MIST; 52 | } 53 | #endif 54 | return(cl_state); 55 | } 56 | 57 | 58 | // Directly called by coolant_init(), coolant_set_state(), and mc_reset(), which can be at 59 | // an interrupt-level. No report flag set, but only called by routines that don't need it. 60 | void coolant_stop() 61 | { 62 | #ifdef INVERT_COOLANT_FLOOD_PIN 63 | COOLANT_FLOOD_PORT |= (1 << COOLANT_FLOOD_BIT); 64 | #else 65 | COOLANT_FLOOD_PORT &= ~(1 << COOLANT_FLOOD_BIT); 66 | #endif 67 | #ifdef ENABLE_M7 68 | #ifdef INVERT_COOLANT_MIST_PIN 69 | COOLANT_MIST_PORT |= (1 << COOLANT_MIST_BIT); 70 | #else 71 | COOLANT_MIST_PORT &= ~(1 << COOLANT_MIST_BIT); 72 | #endif 73 | #endif 74 | } 75 | 76 | 77 | // Main program only. Immediately sets flood coolant running state and also mist coolant, 78 | // if enabled. Also sets a flag to report an update to a coolant state. 79 | // Called by coolant toggle override, parking restore, parking retract, sleep mode, g-code 80 | // parser program end, and g-code parser coolant_sync(). 81 | void coolant_set_state(uint8_t mode) 82 | { 83 | if (sys.abort) { return; } // Block during abort. 84 | 85 | if (mode == COOLANT_DISABLE) { 86 | 87 | coolant_stop(); 88 | 89 | } else { 90 | 91 | if (mode & COOLANT_FLOOD_ENABLE) { 92 | #ifdef INVERT_COOLANT_FLOOD_PIN 93 | COOLANT_FLOOD_PORT &= ~(1 << COOLANT_FLOOD_BIT); 94 | #else 95 | COOLANT_FLOOD_PORT |= (1 << COOLANT_FLOOD_BIT); 96 | #endif 97 | } 98 | 99 | #ifdef ENABLE_M7 100 | if (mode & COOLANT_MIST_ENABLE) { 101 | #ifdef INVERT_COOLANT_MIST_PIN 102 | COOLANT_MIST_PORT &= ~(1 << COOLANT_MIST_BIT); 103 | #else 104 | COOLANT_MIST_PORT |= (1 << COOLANT_MIST_BIT); 105 | #endif 106 | } 107 | #endif 108 | 109 | } 110 | sys.report_ovr_counter = 0; // Set to report change immediately 111 | } 112 | 113 | 114 | // G-code parser entry-point for setting coolant state. Forces a planner buffer sync and bails 115 | // if an abort or check-mode is active. 116 | void coolant_sync(uint8_t mode) 117 | { 118 | if (sys.state == STATE_CHECK_MODE) { return; } 119 | protocol_buffer_synchronize(); // Ensure coolant turns on when specified in program. 120 | coolant_set_state(mode); 121 | } 122 | -------------------------------------------------------------------------------- /grbl/coolant_control.h: -------------------------------------------------------------------------------- 1 | /* 2 | coolant_control.h - spindle control methods 3 | Part of Grbl 4 | 5 | Copyright (c) 2012-2016 Sungeun K. Jeon for Gnea Research LLC 6 | 7 | Grbl is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation, either version 3 of the License, or 10 | (at your option) any later version. 11 | 12 | Grbl is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with Grbl. If not, see . 19 | */ 20 | 21 | #ifndef coolant_control_h 22 | #define coolant_control_h 23 | 24 | #define COOLANT_NO_SYNC false 25 | #define COOLANT_FORCE_SYNC true 26 | 27 | #define COOLANT_STATE_DISABLE 0 // Must be zero 28 | #define COOLANT_STATE_FLOOD bit(0) 29 | #define COOLANT_STATE_MIST bit(1) 30 | 31 | 32 | // Initializes coolant control pins. 33 | void coolant_init(); 34 | 35 | // Returns current coolant output state. Overrides may alter it from programmed state. 36 | uint8_t coolant_get_state(); 37 | 38 | // Immediately disables coolant pins. 39 | void coolant_stop(); 40 | 41 | // Sets the coolant pins according to state specified. 42 | void coolant_set_state(uint8_t mode); 43 | 44 | // G-code parser entry-point for setting coolant states. Checks for and executes additional conditions. 45 | void coolant_sync(uint8_t mode); 46 | 47 | #endif 48 | -------------------------------------------------------------------------------- /grbl/cpu_map/cpu_map_atmega2560.h: -------------------------------------------------------------------------------- 1 | /* 2 | cpu_map_atmega2560.h - CPU and pin mapping configuration file 3 | Part of Grbl 4 | 5 | Copyright (c) 2012-2015 Sungeun K. Jeon 6 | 7 | Grbl is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation, either version 3 of the License, or 10 | (at your option) any later version. 11 | 12 | Grbl is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with Grbl. If not, see . 19 | */ 20 | 21 | /* This cpu_map file serves as a central pin mapping settings file for AVR Mega 2560 */ 22 | 23 | 24 | #ifdef GRBL_PLATFORM 25 | #error "cpu_map already defined: GRBL_PLATFORM=" GRBL_PLATFORM 26 | #endif 27 | 28 | 29 | #define GRBL_PLATFORM "Atmega2560" 30 | 31 | // Serial port pins 32 | #define SERIAL_RX USART0_RX_vect 33 | #define SERIAL_UDRE USART0_UDRE_vect 34 | 35 | // Increase Buffers to make use of extra SRAM 36 | //#define RX_BUFFER_SIZE 256 37 | //#define TX_BUFFER_SIZE 128 38 | //#define BLOCK_BUFFER_SIZE 36 39 | //#define LINE_BUFFER_SIZE 100 40 | 41 | // Define step pulse output pins. NOTE: All step bit pins must be on the same port. 42 | #define STEP_DDR DDRA 43 | #define STEP_PORT PORTA 44 | #define STEP_PIN PINA 45 | #define X_STEP_BIT 2 // MEGA2560 Digital Pin 24 46 | #define Y_STEP_BIT 3 // MEGA2560 Digital Pin 25 47 | #define Z_STEP_BIT 4 // MEGA2560 Digital Pin 26 48 | #define STEP_MASK ((1<. 19 | */ 20 | 21 | /* The defaults.h file serves as a central default settings file for different machine 22 | types, from DIY CNC mills to CNC conversions of off-the-shelf machines. The settings 23 | here are supplied by users, so your results may vary. However, this should give you 24 | a good starting point as you get to know your machine and tweak the settings for your 25 | nefarious needs. */ 26 | 27 | #ifndef defaults_h 28 | #define defaults_h 29 | 30 | // Grbl generic default settings. Should work across different machines. 31 | #define DEFAULT_X_STEPS_PER_MM 250.0 32 | #define DEFAULT_Y_STEPS_PER_MM 250.0 33 | #define DEFAULT_Z_STEPS_PER_MM 250.0 34 | #define DEFAULT_X_MAX_RATE 500.0 // mm/min 35 | #define DEFAULT_Y_MAX_RATE 500.0 // mm/min 36 | #define DEFAULT_Z_MAX_RATE 500.0 // mm/min 37 | #define DEFAULT_X_ACCELERATION (10.0*60*60) // 10*60*60 mm/min^2 = 10 mm/sec^2 38 | #define DEFAULT_Y_ACCELERATION (10.0*60*60) // 10*60*60 mm/min^2 = 10 mm/sec^2 39 | #define DEFAULT_Z_ACCELERATION (10.0*60*60) // 10*60*60 mm/min^2 = 10 mm/sec^2 40 | #define DEFAULT_X_MAX_TRAVEL 200.0 // mm 41 | #define DEFAULT_Y_MAX_TRAVEL 200.0 // mm 42 | #define DEFAULT_Z_MAX_TRAVEL 200.0 // mm 43 | #define DEFAULT_STEP_PULSE_MICROSECONDS 10 44 | #define DEFAULT_STEPPING_INVERT_MASK 0 45 | #define DEFAULT_DIRECTION_INVERT_MASK 0 46 | #define DEFAULT_STEPPER_IDLE_LOCK_TIME 25 // msec (0-254, 255 keeps steppers enabled) 47 | #define DEFAULT_STATUS_REPORT_MASK ((BITFLAG_RT_STATUS_MACHINE_POSITION)|(BITFLAG_RT_STATUS_WORK_POSITION)) 48 | #define DEFAULT_JUNCTION_DEVIATION 0.01 // mm 49 | #define DEFAULT_ARC_TOLERANCE 0.002 // mm 50 | #define DEFAULT_REPORT_INCHES 0 // false 51 | #define DEFAULT_INVERT_ST_ENABLE 0 // false 52 | #define DEFAULT_INVERT_LIMIT_PINS 0 // false 53 | #define DEFAULT_SOFT_LIMIT_ENABLE 0 // false 54 | #define DEFAULT_HARD_LIMIT_ENABLE 0 // false 55 | #define DEFAULT_HOMING_ENABLE 0 // false 56 | #define DEFAULT_HOMING_DIR_MASK 0 // move positive dir 57 | #define DEFAULT_HOMING_FEED_RATE 25.0 // mm/min 58 | #define DEFAULT_HOMING_SEEK_RATE 500.0 // mm/min 59 | #define DEFAULT_HOMING_DEBOUNCE_DELAY 250 // msec (0-65k) 60 | #define DEFAULT_HOMING_PULLOFF 1.0 // mm 61 | 62 | #endif 63 | -------------------------------------------------------------------------------- /grbl/defaults/defaults_oxcnc.h: -------------------------------------------------------------------------------- 1 | /* 2 | defaults_oxcnc.h - defaults settings configuration file 3 | Part of Grbl 4 | 5 | Copyright (c) 2012-2015 Sungeun K. Jeon 6 | 7 | Grbl is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation, either version 3 of the License, or 10 | (at your option) any later version. 11 | 12 | Grbl is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with Grbl. If not, see . 19 | */ 20 | 21 | /* The defaults.h file serves as a central default settings file for different machine 22 | types, from DIY CNC mills to CNC conversions of off-the-shelf machines. The settings 23 | here are supplied by users, so your results may vary. However, this should give you 24 | a good starting point as you get to know your machine and tweak the settings for your 25 | nefarious needs. */ 26 | 27 | #ifndef defaults_h 28 | #define defaults_h 29 | 30 | // Grbl settings for OpenBuilds OX CNC Machine 31 | // http://www.openbuilds.com/builds/openbuilds-ox-cnc-machine.341/ 32 | #define DEFAULT_X_STEPS_PER_MM 26.670 33 | #define DEFAULT_Y_STEPS_PER_MM 26.670 34 | #define DEFAULT_Z_STEPS_PER_MM 50 35 | #define DEFAULT_X_MAX_RATE 500.0 // mm/min 36 | #define DEFAULT_Y_MAX_RATE 500.0 // mm/min 37 | #define DEFAULT_Z_MAX_RATE 500.0 // mm/min 38 | #define DEFAULT_X_ACCELERATION (10.0*60*60) // 10*60*60 mm/min^2 = 10 mm/sec^2 39 | #define DEFAULT_Y_ACCELERATION (10.0*60*60) // 10*60*60 mm/min^2 = 10 mm/sec^2 40 | #define DEFAULT_Z_ACCELERATION (10.0*60*60) // 10*60*60 mm/min^2 = 10 mm/sec^2 41 | #define DEFAULT_X_MAX_TRAVEL 500.0 // mm 42 | #define DEFAULT_Y_MAX_TRAVEL 750.0 // mm 43 | #define DEFAULT_Z_MAX_TRAVEL 80.0 // mm 44 | #define DEFAULT_STEP_PULSE_MICROSECONDS 10 45 | #define DEFAULT_STEPPING_INVERT_MASK 0 46 | #define DEFAULT_DIRECTION_INVERT_MASK 0 47 | #define DEFAULT_STEPPER_IDLE_LOCK_TIME 25 // msec (0-254, 255 keeps steppers enabled) 48 | #define DEFAULT_STATUS_REPORT_MASK ((BITFLAG_RT_STATUS_MACHINE_POSITION)|(BITFLAG_RT_STATUS_WORK_POSITION)) 49 | #define DEFAULT_JUNCTION_DEVIATION 0.02 // mm 50 | #define DEFAULT_ARC_TOLERANCE 0.002 // mm 51 | #define DEFAULT_REPORT_INCHES 0 // false 52 | #define DEFAULT_INVERT_ST_ENABLE 0 // false 53 | #define DEFAULT_INVERT_LIMIT_PINS 0 // false 54 | #define DEFAULT_SOFT_LIMIT_ENABLE 0 // false 55 | #define DEFAULT_HARD_LIMIT_ENABLE 0 // false 56 | #define DEFAULT_HOMING_ENABLE 0 // false 57 | #define DEFAULT_HOMING_DIR_MASK 0 // move positive dir 58 | #define DEFAULT_HOMING_FEED_RATE 25.0 // mm/min 59 | #define DEFAULT_HOMING_SEEK_RATE 500.0 // mm/min 60 | #define DEFAULT_HOMING_DEBOUNCE_DELAY 250 // msec (0-65k) 61 | #define DEFAULT_HOMING_PULLOFF 1.0 // mm 62 | 63 | #endif 64 | -------------------------------------------------------------------------------- /grbl/defaults/defaults_shapeoko.h: -------------------------------------------------------------------------------- 1 | /* 2 | defaults_shapeoko.h - defaults settings configuration file 3 | Part of Grbl 4 | 5 | Copyright (c) 2012-2015 Sungeun K. Jeon 6 | 7 | Grbl is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation, either version 3 of the License, or 10 | (at your option) any later version. 11 | 12 | Grbl is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with Grbl. If not, see . 19 | */ 20 | 21 | /* The defaults.h file serves as a central default settings file for different machine 22 | types, from DIY CNC mills to CNC conversions of off-the-shelf machines. The settings 23 | here are supplied by users, so your results may vary. However, this should give you 24 | a good starting point as you get to know your machine and tweak the settings for your 25 | nefarious needs. */ 26 | 27 | #ifndef defaults_h 28 | #define defaults_h 29 | 30 | 31 | // Description: Shapeoko CNC mill with three NEMA 17 stepper motors, driven by Synthetos 32 | // grblShield with a 24V, 4.2A power supply. 33 | #define MICROSTEPS_XY 8 34 | #define STEP_REVS_XY 400 35 | #define MM_PER_REV_XY (0.08*18*MM_PER_INCH) // 0.08 in belt pitch, 18 pulley teeth 36 | #define MICROSTEPS_Z 2 37 | #define STEP_REVS_Z 400 38 | #define MM_PER_REV_Z 1.250 // 1.25 mm/rev leadscrew 39 | #define DEFAULT_X_STEPS_PER_MM (MICROSTEPS_XY*STEP_REVS_XY/MM_PER_REV_XY) 40 | #define DEFAULT_Y_STEPS_PER_MM (MICROSTEPS_XY*STEP_REVS_XY/MM_PER_REV_XY) 41 | #define DEFAULT_Z_STEPS_PER_MM (MICROSTEPS_Z*STEP_REVS_Z/MM_PER_REV_Z) 42 | #define DEFAULT_X_MAX_RATE 1000.0 // mm/min 43 | #define DEFAULT_Y_MAX_RATE 1000.0 // mm/min 44 | #define DEFAULT_Z_MAX_RATE 1000.0 // mm/min 45 | #define DEFAULT_X_ACCELERATION (15.0*60*60) // 15*60*60 mm/min^2 = 15 mm/sec^2 46 | #define DEFAULT_Y_ACCELERATION (15.0*60*60) // 15*60*60 mm/min^2 = 15 mm/sec^2 47 | #define DEFAULT_Z_ACCELERATION (15.0*60*60) // 15*60*60 mm/min^2 = 15 mm/sec^2 48 | #define DEFAULT_X_MAX_TRAVEL 200.0 // mm 49 | #define DEFAULT_Y_MAX_TRAVEL 200.0 // mm 50 | #define DEFAULT_Z_MAX_TRAVEL 200.0 // mm 51 | #define DEFAULT_STEP_PULSE_MICROSECONDS 10 52 | #define DEFAULT_STEPPING_INVERT_MASK 0 53 | #define DEFAULT_DIRECTION_INVERT_MASK ((1<. 19 | */ 20 | 21 | /* The defaults.h file serves as a central default settings file for different machine 22 | types, from DIY CNC mills to CNC conversions of off-the-shelf machines. The settings 23 | here are supplied by users, so your results may vary. However, this should give you 24 | a good starting point as you get to know your machine and tweak the settings for your 25 | nefarious needs. */ 26 | 27 | #ifndef defaults_h 28 | #define defaults_h 29 | 30 | // Description: Shapeoko CNC mill with three NEMA 17 stepper motors, driven by Synthetos 31 | // grblShield at 28V. 32 | #define MICROSTEPS_XY 8 33 | #define STEP_REVS_XY 200 34 | #define MM_PER_REV_XY (2.0*20) // 2mm belt pitch, 20 pulley teeth 35 | #define MICROSTEPS_Z 2 36 | #define STEP_REVS_Z 200 37 | #define MM_PER_REV_Z 1.250 // 1.25 mm/rev leadscrew 38 | #define DEFAULT_X_STEPS_PER_MM (MICROSTEPS_XY*STEP_REVS_XY/MM_PER_REV_XY) 39 | #define DEFAULT_Y_STEPS_PER_MM (MICROSTEPS_XY*STEP_REVS_XY/MM_PER_REV_XY) 40 | #define DEFAULT_Z_STEPS_PER_MM (MICROSTEPS_Z*STEP_REVS_Z/MM_PER_REV_Z) 41 | #define DEFAULT_X_MAX_RATE 5000.0 // mm/min 42 | #define DEFAULT_Y_MAX_RATE 5000.0 // mm/min 43 | #define DEFAULT_Z_MAX_RATE 500.0 // mm/min 44 | #define DEFAULT_X_ACCELERATION (250.0*60*60) // 25*60*60 mm/min^2 = 25 mm/sec^2 45 | #define DEFAULT_Y_ACCELERATION (250.0*60*60) // 25*60*60 mm/min^2 = 25 mm/sec^2 46 | #define DEFAULT_Z_ACCELERATION (50.0*60*60) // 25*60*60 mm/min^2 = 25 mm/sec^2 47 | #define DEFAULT_X_MAX_TRAVEL 290.0 // mm 48 | #define DEFAULT_Y_MAX_TRAVEL 290.0 // mm 49 | #define DEFAULT_Z_MAX_TRAVEL 100.0 // mm 50 | #define DEFAULT_STEP_PULSE_MICROSECONDS 10 51 | #define DEFAULT_STEPPING_INVERT_MASK 0 52 | #define DEFAULT_DIRECTION_INVERT_MASK ((1<. 19 | */ 20 | 21 | /* The defaults.h file serves as a central default settings file for different machine 22 | types, from DIY CNC mills to CNC conversions of off-the-shelf machines. The settings 23 | here are supplied by users, so your results may vary. However, this should give you 24 | a good starting point as you get to know your machine and tweak the settings for your 25 | nefarious needs. */ 26 | 27 | #ifndef defaults_h 28 | #define defaults_h 29 | 30 | // Description: Shapeoko CNC mill with three NEMA 23 stepper motors, driven by CarbideMotion 31 | #define MICROSTEPS_XY 8 32 | #define STEP_REVS_XY 200 33 | #define MM_PER_REV_XY (2.0*20) // 2mm belt pitch, 20 pulley teeth 34 | #define MICROSTEPS_Z 8 35 | #define STEP_REVS_Z 200 36 | #define MM_PER_REV_Z (2.0*20) // 2mm belt pitch, 20 pulley teeth 37 | #define DEFAULT_X_STEPS_PER_MM (MICROSTEPS_XY*STEP_REVS_XY/MM_PER_REV_XY) 38 | #define DEFAULT_Y_STEPS_PER_MM (MICROSTEPS_XY*STEP_REVS_XY/MM_PER_REV_XY) 39 | #define DEFAULT_Z_STEPS_PER_MM (MICROSTEPS_Z*STEP_REVS_Z/MM_PER_REV_Z) 40 | #define DEFAULT_X_MAX_RATE 5000.0 // mm/min 41 | #define DEFAULT_Y_MAX_RATE 5000.0 // mm/min 42 | #define DEFAULT_Z_MAX_RATE 5000.0 // mm/min 43 | #define DEFAULT_X_ACCELERATION (400.0*60*60) // 400*60*60 mm/min^2 = 400 mm/sec^2 44 | #define DEFAULT_Y_ACCELERATION (400.0*60*60) // 400*60*60 mm/min^2 = 400 mm/sec^2 45 | #define DEFAULT_Z_ACCELERATION (400.0*60*60) // 400*60*60 mm/min^2 = 400 mm/sec^2 46 | #define DEFAULT_X_MAX_TRAVEL 425.0 // mm 47 | #define DEFAULT_Y_MAX_TRAVEL 465.0 // mm 48 | #define DEFAULT_Z_MAX_TRAVEL 80.0 // mm 49 | #define DEFAULT_STEP_PULSE_MICROSECONDS 10 50 | #define DEFAULT_STEPPING_INVERT_MASK 0 51 | #define DEFAULT_DIRECTION_INVERT_MASK ((1<. 19 | */ 20 | 21 | /* The defaults.h file serves as a central default settings file for different machine 22 | types, from DIY CNC mills to CNC conversions of off-the-shelf machines. The settings 23 | here are supplied by users, so your results may vary. However, this should give you 24 | a good starting point as you get to know your machine and tweak the settings for your 25 | nefarious needs. */ 26 | 27 | #ifndef defaults_h 28 | #define defaults_h 29 | 30 | // Description: Sherline 5400 mill with three NEMA 23 Keling KL23H256-21-8B 185 oz-in stepper motors, 31 | // driven by three Pololu A4988 stepper drivers with a 30V, 6A power supply at 1.5A per winding. 32 | #define MICROSTEPS 2 33 | #define STEPS_PER_REV 200.0 34 | #define MM_PER_REV (0.050*MM_PER_INCH) // 0.050 inch/rev leadscrew 35 | #define DEFAULT_X_STEPS_PER_MM (STEPS_PER_REV*MICROSTEPS/MM_PER_REV) 36 | #define DEFAULT_Y_STEPS_PER_MM (STEPS_PER_REV*MICROSTEPS/MM_PER_REV) 37 | #define DEFAULT_Z_STEPS_PER_MM (STEPS_PER_REV*MICROSTEPS/MM_PER_REV) 38 | #define DEFAULT_X_MAX_RATE 635.0 // mm/min (25 ipm) 39 | #define DEFAULT_Y_MAX_RATE 635.0 // mm/min 40 | #define DEFAULT_Z_MAX_RATE 635.0 // mm/min 41 | #define DEFAULT_X_ACCELERATION (50.0*60*60) // 50*60*60 mm/min^2 = 50 mm/sec^2 42 | #define DEFAULT_Y_ACCELERATION (50.0*60*60) // 50*60*60 mm/min^2 = 50 mm/sec^2 43 | #define DEFAULT_Z_ACCELERATION (50.0*60*60) // 50*60*60 mm/min^2 = 50 mm/sec^2 44 | #define DEFAULT_X_MAX_TRAVEL 225.0 // mm 45 | #define DEFAULT_Y_MAX_TRAVEL 125.0 // mm 46 | #define DEFAULT_Z_MAX_TRAVEL 170.0 // mm 47 | #define DEFAULT_STEP_PULSE_MICROSECONDS 10 48 | #define DEFAULT_STEPPING_INVERT_MASK 0 49 | #define DEFAULT_DIRECTION_INVERT_MASK ((1<. 19 | */ 20 | 21 | /* The defaults.h file serves as a central default settings file for different machine 22 | types, from DIY CNC mills to CNC conversions of off-the-shelf machines. The settings 23 | here are supplied by users, so your results may vary. However, this should give you 24 | a good starting point as you get to know your machine and tweak the settings for your 25 | nefarious needs. */ 26 | 27 | #ifndef defaults_h 28 | #define defaults_h 29 | 30 | // Settings only for Grbl Simulator (www.github.com/grbl/grbl-sim) 31 | // Grbl generic default settings. Should work across different machines. 32 | #define DEFAULT_X_STEPS_PER_MM 1000.0 33 | #define DEFAULT_Y_STEPS_PER_MM 1000.0 34 | #define DEFAULT_Z_STEPS_PER_MM 1000.0 35 | #define DEFAULT_X_MAX_RATE 1000.0 // mm/min 36 | #define DEFAULT_Y_MAX_RATE 1000.0 // mm/min 37 | #define DEFAULT_Z_MAX_RATE 1000.0 // mm/min 38 | #define DEFAULT_X_ACCELERATION (100.0*60*60) // 10*60*60 mm/min^2 = 10 mm/sec^2 39 | #define DEFAULT_Y_ACCELERATION (100.0*60*60) // 10*60*60 mm/min^2 = 10 mm/sec^2 40 | #define DEFAULT_Z_ACCELERATION (100.0*60*60) // 10*60*60 mm/min^2 = 10 mm/sec^2 41 | #define DEFAULT_X_MAX_TRAVEL 1000.0 // mm 42 | #define DEFAULT_Y_MAX_TRAVEL 1000.0 // mm 43 | #define DEFAULT_Z_MAX_TRAVEL 1000.0 // mm 44 | #define DEFAULT_STEP_PULSE_MICROSECONDS 10 45 | #define DEFAULT_STEPPING_INVERT_MASK 0 46 | #define DEFAULT_DIRECTION_INVERT_MASK 0 47 | #define DEFAULT_STEPPER_IDLE_LOCK_TIME 25 // msec (0-254, 255 keeps steppers enabled) 48 | #define DEFAULT_STATUS_REPORT_MASK ((BITFLAG_RT_STATUS_MACHINE_POSITION)|(BITFLAG_RT_STATUS_WORK_POSITION)) 49 | #define DEFAULT_JUNCTION_DEVIATION 0.01 // mm 50 | #define DEFAULT_ARC_TOLERANCE 0.002 // mm 51 | #define DEFAULT_REPORT_INCHES 0 // false 52 | #define DEFAULT_INVERT_ST_ENABLE 0 // false 53 | #define DEFAULT_INVERT_LIMIT_PINS 0 // false 54 | #define DEFAULT_SOFT_LIMIT_ENABLE 0 // false 55 | #define DEFAULT_HARD_LIMIT_ENABLE 0 // false 56 | #define DEFAULT_HOMING_ENABLE 0 // false 57 | #define DEFAULT_HOMING_DIR_MASK 0 // move positive dir 58 | #define DEFAULT_HOMING_FEED_RATE 25.0 // mm/min 59 | #define DEFAULT_HOMING_SEEK_RATE 500.0 // mm/min 60 | #define DEFAULT_HOMING_DEBOUNCE_DELAY 250 // msec (0-65k) 61 | #define DEFAULT_HOMING_PULLOFF 1.0 // mm 62 | 63 | #endif 64 | -------------------------------------------------------------------------------- /grbl/defaults/defaults_x_carve_1000mm.h: -------------------------------------------------------------------------------- 1 | /* 2 | defaults_x_carve_1000mm.h - defaults settings configuration file 3 | Part of Grbl 4 | 5 | Copyright (c) 2012-2015 Sungeun K. Jeon 6 | 7 | Grbl is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation, either version 3 of the License, or 10 | (at your option) any later version. 11 | 12 | Grbl is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with Grbl. If not, see . 19 | */ 20 | 21 | /* The defaults.h file serves as a central default settings file for different machine 22 | types, from DIY CNC mills to CNC conversions of off-the-shelf machines. The settings 23 | here are supplied by users, so your results may vary. However, this should give you 24 | a good starting point as you get to know your machine and tweak the settings for your 25 | nefarious needs. */ 26 | 27 | #ifndef defaults_h 28 | #define defaults_h 29 | 30 | // Description: X-Carve 3D Carver CNC mill with three 200 step/rev motors driven by Synthetos 31 | // grblShield at 24V. 32 | #define MICROSTEPS_XY 8 33 | #define STEP_REVS_XY 200 34 | #define MM_PER_REV_XY (2.0*20) // 2mm belt pitch, 20 pulley teeth 35 | #define MICROSTEPS_Z 2 36 | #define STEP_REVS_Z 200 37 | #define MM_PER_REV_Z 2.117 // ACME 3/8-12 Leadscrew 38 | #define DEFAULT_X_STEPS_PER_MM (MICROSTEPS_XY*STEP_REVS_XY/MM_PER_REV_XY) 39 | #define DEFAULT_Y_STEPS_PER_MM (MICROSTEPS_XY*STEP_REVS_XY/MM_PER_REV_XY) 40 | #define DEFAULT_Z_STEPS_PER_MM (MICROSTEPS_Z*STEP_REVS_Z/MM_PER_REV_Z) 41 | #define DEFAULT_X_MAX_RATE 8000.0 // mm/min 42 | #define DEFAULT_Y_MAX_RATE 8000.0 // mm/min 43 | #define DEFAULT_Z_MAX_RATE 500.0 // mm/min 44 | #define DEFAULT_X_ACCELERATION (500.0*60*60) // 25*60*60 mm/min^2 = 25 mm/sec^2 45 | #define DEFAULT_Y_ACCELERATION (500.0*60*60) // 25*60*60 mm/min^2 = 25 mm/sec^2 46 | #define DEFAULT_Z_ACCELERATION (50.0*60*60) // 25*60*60 mm/min^2 = 25 mm/sec^2 47 | #define DEFAULT_X_MAX_TRAVEL 740.0 // mm 48 | #define DEFAULT_Y_MAX_TRAVEL 790.0 // mm 49 | #define DEFAULT_Z_MAX_TRAVEL 100.0 // mm 50 | #define DEFAULT_STEP_PULSE_MICROSECONDS 10 51 | #define DEFAULT_STEPPING_INVERT_MASK 0 52 | #define DEFAULT_DIRECTION_INVERT_MASK ((1<. 19 | */ 20 | 21 | /* The defaults.h file serves as a central default settings file for different machine 22 | types, from DIY CNC mills to CNC conversions of off-the-shelf machines. The settings 23 | here are supplied by users, so your results may vary. However, this should give you 24 | a good starting point as you get to know your machine and tweak the settings for your 25 | nefarious needs. */ 26 | 27 | #ifndef defaults_h 28 | #define defaults_h 29 | 30 | // Description: X-Carve 3D Carver CNC mill with three 200 step/rev motors driven by Synthetos 31 | // grblShield at 24V. 32 | #define MICROSTEPS_XY 8 33 | #define STEP_REVS_XY 200 34 | #define MM_PER_REV_XY (2.0*20) // 2mm belt pitch, 20 pulley teeth 35 | #define MICROSTEPS_Z 2 36 | #define STEP_REVS_Z 200 37 | #define MM_PER_REV_Z 2.117 // ACME 3/8-12 Leadscrew 38 | #define DEFAULT_X_STEPS_PER_MM (MICROSTEPS_XY*STEP_REVS_XY/MM_PER_REV_XY) 39 | #define DEFAULT_Y_STEPS_PER_MM (MICROSTEPS_XY*STEP_REVS_XY/MM_PER_REV_XY) 40 | #define DEFAULT_Z_STEPS_PER_MM (MICROSTEPS_Z*STEP_REVS_Z/MM_PER_REV_Z) 41 | #define DEFAULT_X_MAX_RATE 8000.0 // mm/min 42 | #define DEFAULT_Y_MAX_RATE 8000.0 // mm/min 43 | #define DEFAULT_Z_MAX_RATE 500.0 // mm/min 44 | #define DEFAULT_X_ACCELERATION (500.0*60*60) // 25*60*60 mm/min^2 = 25 mm/sec^2 45 | #define DEFAULT_Y_ACCELERATION (500.0*60*60) // 25*60*60 mm/min^2 = 25 mm/sec^2 46 | #define DEFAULT_Z_ACCELERATION (50.0*60*60) // 25*60*60 mm/min^2 = 25 mm/sec^2 47 | #define DEFAULT_X_MAX_TRAVEL 290.0 // mm 48 | #define DEFAULT_Y_MAX_TRAVEL 290.0 // mm 49 | #define DEFAULT_Z_MAX_TRAVEL 100.0 // mm 50 | #define DEFAULT_STEP_PULSE_MICROSECONDS 10 51 | #define DEFAULT_STEPPING_INVERT_MASK 0 52 | #define DEFAULT_DIRECTION_INVERT_MASK ((1<. 19 | */ 20 | 21 | /* The defaults.h file serves as a central default settings file for different machine 22 | types, from DIY CNC mills to CNC conversions of off-the-shelf machines. The settings 23 | here are supplied by users, so your results may vary. However, this should give you 24 | a good starting point as you get to know your machine and tweak the settings for your 25 | nefarious needs. */ 26 | 27 | #ifndef defaults_h 28 | #define defaults_h 29 | 30 | // Description: Zen Toolworks 7x7 mill with three Shinano SST43D2121 65oz-in NEMA 17 stepper motors. 31 | // Leadscrew is different from some ZTW kits, where most are 1.25mm/rev rather than 8.0mm/rev here. 32 | // Driven by 30V, 6A power supply and TI DRV8811 stepper motor drivers. 33 | #define MICROSTEPS 8 34 | #define STEPS_PER_REV 200.0 35 | #define MM_PER_REV 8.0 // 8 mm/rev leadscrew 36 | #define DEFAULT_X_STEPS_PER_MM (STEPS_PER_REV*MICROSTEPS/MM_PER_REV) 37 | #define DEFAULT_Y_STEPS_PER_MM (STEPS_PER_REV*MICROSTEPS/MM_PER_REV) 38 | #define DEFAULT_Z_STEPS_PER_MM (STEPS_PER_REV*MICROSTEPS/MM_PER_REV) 39 | #define DEFAULT_X_MAX_RATE 6000.0 // mm/min 40 | #define DEFAULT_Y_MAX_RATE 6000.0 // mm/min 41 | #define DEFAULT_Z_MAX_RATE 6000.0 // mm/min 42 | #define DEFAULT_X_ACCELERATION (600.0*60*60) // 600*60*60 mm/min^2 = 600 mm/sec^2 43 | #define DEFAULT_Y_ACCELERATION (600.0*60*60) // 600*60*60 mm/min^2 = 600 mm/sec^2 44 | #define DEFAULT_Z_ACCELERATION (600.0*60*60) // 600*60*60 mm/min^2 = 600 mm/sec^2 45 | #define DEFAULT_X_MAX_TRAVEL 190.0 // mm 46 | #define DEFAULT_Y_MAX_TRAVEL 180.0 // mm 47 | #define DEFAULT_Z_MAX_TRAVEL 150.0 // mm 48 | #define DEFAULT_STEP_PULSE_MICROSECONDS 10 49 | #define DEFAULT_STEPPING_INVERT_MASK 0 50 | #define DEFAULT_DIRECTION_INVERT_MASK ((1< 25 | #include 26 | 27 | /* These EEPROM bits have different names on different devices. */ 28 | #ifndef EEPE 29 | #define EEPE EEWE //!< EEPROM program/write enable. 30 | #define EEMPE EEMWE //!< EEPROM master program/write enable. 31 | #endif 32 | 33 | /* These two are unfortunately not defined in the device include files. */ 34 | #define EEPM1 5 //!< EEPROM Programming Mode Bit 1. 35 | #define EEPM0 4 //!< EEPROM Programming Mode Bit 0. 36 | 37 | /* Define to reduce code size. */ 38 | #define EEPROM_IGNORE_SELFPROG //!< Remove SPM flag polling. 39 | 40 | /*! \brief Read byte from EEPROM. 41 | * 42 | * This function reads one byte from a given EEPROM address. 43 | * 44 | * \note The CPU is halted for 4 clock cycles during EEPROM read. 45 | * 46 | * \param addr EEPROM address to read from. 47 | * \return The byte read from the EEPROM address. 48 | */ 49 | unsigned char eeprom_get_char( unsigned int addr ) 50 | { 51 | do {} while( EECR & (1< 0; size--) { 133 | checksum = (checksum << 1) || (checksum >> 7); 134 | checksum += *source; 135 | eeprom_put_char(destination++, *(source++)); 136 | } 137 | eeprom_put_char(destination, checksum); 138 | } 139 | 140 | int memcpy_from_eeprom_with_checksum(char *destination, unsigned int source, unsigned int size) { 141 | unsigned char data, checksum = 0; 142 | for(; size > 0; size--) { 143 | data = eeprom_get_char(source++); 144 | checksum = (checksum << 1) || (checksum >> 7); 145 | checksum += data; 146 | *(destination++) = data; 147 | } 148 | return(checksum == eeprom_get_char(source)); 149 | } 150 | 151 | // end of file 152 | -------------------------------------------------------------------------------- /grbl/eeprom.h: -------------------------------------------------------------------------------- 1 | /* 2 | eeprom.h - EEPROM methods 3 | Part of Grbl 4 | 5 | Copyright (c) 2009-2011 Simen Svale Skogsrud 6 | 7 | Grbl is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation, either version 3 of the License, or 10 | (at your option) any later version. 11 | 12 | Grbl is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with Grbl. If not, see . 19 | */ 20 | 21 | #ifndef eeprom_h 22 | #define eeprom_h 23 | 24 | unsigned char eeprom_get_char(unsigned int addr); 25 | void eeprom_put_char(unsigned int addr, unsigned char new_value); 26 | void memcpy_to_eeprom_with_checksum(unsigned int destination, char *source, unsigned int size); 27 | int memcpy_from_eeprom_with_checksum(char *destination, unsigned int source, unsigned int size); 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /grbl/examples/grblUpload/grblUpload.ino: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | This sketch compiles and uploads Grbl to your 328p-based Arduino! 3 | 4 | To use: 5 | - First make sure you have imported Grbl source code into your Arduino 6 | IDE. There are details on our Github website on how to do this. 7 | 8 | - Select your Arduino Board and Serial Port in the Tools drop-down menu. 9 | NOTE: Grbl only officially supports 328p-based Arduinos, like the Uno. 10 | Using other boards will likely not work! 11 | 12 | - Then just click 'Upload'. That's it! 13 | 14 | For advanced users: 15 | If you'd like to see what else Grbl can do, there are some additional 16 | options for customization and features you can enable or disable. 17 | Navigate your file system to where the Arduino IDE has stored the Grbl 18 | source code files, open the 'config.h' file in your favorite text 19 | editor. Inside are dozens of feature descriptions and #defines. Simply 20 | comment or uncomment the #defines or alter their assigned values, save 21 | your changes, and then click 'Upload' here. 22 | 23 | Copyright (c) 2015 Sungeun K. Jeon 24 | Released under the MIT-license. See license.txt for details. 25 | ***********************************************************************/ 26 | 27 | #include 28 | 29 | // Do not alter this file! 30 | -------------------------------------------------------------------------------- /grbl/examples/grblUpload/license.txt: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Sungeun K. Jeon 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. -------------------------------------------------------------------------------- /grbl/examples/grblWrite_BuildInfo/grblWrite_BuildInfo.ino: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | This sketch writes a `$I` build info string directly into Arduino EEPROM 3 | 4 | To use: 5 | - Just alter the "build_info_line" string to whatever you'd like. Then 6 | compile and upload this sketch to your Arduino. 7 | 8 | - If your Arduino is blinking slowly, your string has already been 9 | written to your EEPROM and been verified by checksums! That's it! 10 | 11 | - If you Arduino LED is blinking fast, something went wrong and the 12 | checksums don't match. You can optionally connect to the Arduino via 13 | the serial monitor, and the sketch will show what its doing. 14 | 15 | NOTE: This sketch is provided as a tool template for OEMs who may need 16 | to restrict users from altering their build info, so they can place 17 | important product information here when enabling the restriction. 18 | 19 | NOTE: When uploading Grbl to the Arduino with this sketch on it, make 20 | sure you see the slow blink before you start the upload process. This 21 | ensures you aren't flashing Grbl when it's in mid-write of the EEPROM. 22 | 23 | Copyright (c) 2016 Sungeun K. Jeon for Gnea Research LLC 24 | Released under the MIT-license. See license.txt for details. 25 | ***********************************************************************/ 26 | 27 | #include 28 | #include 29 | 30 | #define SERIAL_BAUD_RATE 115200 31 | #define LINE_LENGTH 80U // Grbl line length 32 | #define BYTE_LOCATION 942U // Grbl build info EEPROM address. 33 | 34 | 35 | // ----- CHANGE THIS LINE ----- 36 | 37 | char build_info_line[LINE_LENGTH] = "Testing123."; 38 | 39 | // ----------------------------- 40 | 41 | 42 | uint8_t status = false; 43 | int ledPin = 13; // LED connected to digital pin 13 44 | 45 | void setup() { 46 | Serial.begin(SERIAL_BAUD_RATE); 47 | delay(500); 48 | 49 | uint32_t address = BYTE_LOCATION; 50 | uint32_t size = LINE_LENGTH; 51 | char *write_pointer = (char*)build_info_line; 52 | uint8_t write_checksum = 0; 53 | for (; size>0; size--) { 54 | write_checksum = (write_checksum << 1) || (write_checksum >> 7); 55 | write_checksum += *write_pointer; 56 | EEPROM.put(address++, *(write_pointer++)); 57 | } 58 | EEPROM.put(address,write_checksum); 59 | 60 | Serial.print(F("-> Writing line to EEPROM: '")); 61 | Serial.print(build_info_line); 62 | Serial.print(F("'\n\r-> Write checksum: ")); 63 | Serial.println(write_checksum,DEC); 64 | 65 | size = LINE_LENGTH; 66 | address = BYTE_LOCATION; 67 | uint8_t data = 0; 68 | char read_line[LINE_LENGTH]; 69 | char *read_pointer = (char*)read_line; 70 | uint8_t read_checksum = 0; 71 | uint8_t stored_checksum = 0; 72 | for(; size > 0; size--) { 73 | data = EEPROM.read(address++); 74 | read_checksum = (read_checksum << 1) || (read_checksum >> 7); 75 | read_checksum += data; 76 | *(read_pointer++) = data; 77 | } 78 | stored_checksum = EEPROM.read(address); 79 | 80 | Serial.print(F("<- Reading line from EEPROM: '")); 81 | Serial.print(read_line); 82 | Serial.print("'\n\r<- Read checksum: "); 83 | Serial.println(read_checksum,DEC); 84 | 85 | if ((read_checksum == write_checksum) && (read_checksum == stored_checksum)) { 86 | status = true; 87 | Serial.print(F("SUCCESS! All checksums match!\r\n")); 88 | } else { 89 | if (write_checksum != stored_checksum) { 90 | Serial.println(F("ERROR! Write and stored EEPROM checksums don't match!")); 91 | } else { 92 | Serial.println(F("ERROR! Read and stored checksums don't match!")); 93 | } 94 | } 95 | pinMode(ledPin, OUTPUT); // sets the digital pin as output 96 | } 97 | 98 | void loop() { 99 | // Blink to let user know EEPROM write status. 100 | // Slow blink is 'ok'. Fast blink is an 'error'. 101 | digitalWrite(ledPin, HIGH); // sets the LED on 102 | if (status) { delay(1500); } // Slow blink 103 | else { delay(100); } // Rapid blink 104 | digitalWrite(ledPin, LOW); // sets the LED off 105 | if (status) { delay(1500); } 106 | else { delay(100); } 107 | } 108 | 109 | 110 | -------------------------------------------------------------------------------- /grbl/examples/grblWrite_BuildInfo/license.txt: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 Sungeun K. Jeon for Gnea Research LLC 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. -------------------------------------------------------------------------------- /grbl/grbl.h: -------------------------------------------------------------------------------- 1 | /* 2 | grbl.h - main Grbl include file 3 | Part of Grbl 4 | 5 | Copyright (c) 2015-2016 Sungeun K. Jeon for Gnea Research LLC 6 | 7 | Grbl is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation, either version 3 of the License, or 10 | (at your option) any later version. 11 | 12 | Grbl is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with Grbl. If not, see . 19 | */ 20 | 21 | #ifndef grbl_h 22 | #define grbl_h 23 | 24 | // Grbl versioning system 25 | #define GRBL_VERSION "1.1f" 26 | #define GRBL_VERSION_BUILD "20170131" 27 | 28 | // Define standard libraries used by Grbl. 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include 40 | 41 | // Define the Grbl system include files. NOTE: Do not alter organization. 42 | #include "config.h" 43 | #include "nuts_bolts.h" 44 | #include "settings.h" 45 | #include "system.h" 46 | #include "defaults.h" 47 | #include "cpu_map.h" 48 | #include "planner.h" 49 | #include "coolant_control.h" 50 | #include "eeprom.h" 51 | #include "gcode.h" 52 | #include "limits.h" 53 | #include "motion_control.h" 54 | #include "planner.h" 55 | #include "print.h" 56 | #include "probe.h" 57 | #include "protocol.h" 58 | #include "report.h" 59 | #include "serial.h" 60 | #include "spindle_control.h" 61 | #include "stepper.h" 62 | #include "jog.h" 63 | 64 | // --------------------------------------------------------------------------------------- 65 | // COMPILE-TIME ERROR CHECKING OF DEFINE VALUES: 66 | 67 | #ifndef HOMING_CYCLE_0 68 | #error "Required HOMING_CYCLE_0 not defined." 69 | #endif 70 | 71 | #if defined(USE_SPINDLE_DIR_AS_ENABLE_PIN) && !defined(VARIABLE_SPINDLE) 72 | #error "USE_SPINDLE_DIR_AS_ENABLE_PIN may only be used with VARIABLE_SPINDLE enabled" 73 | #endif 74 | 75 | #if defined(USE_SPINDLE_DIR_AS_ENABLE_PIN) && !defined(CPU_MAP_ATMEGA328P) 76 | #error "USE_SPINDLE_DIR_AS_ENABLE_PIN may only be used with a 328p processor" 77 | #endif 78 | 79 | #if !defined(USE_SPINDLE_DIR_AS_ENABLE_PIN) && defined(SPINDLE_ENABLE_OFF_WITH_ZERO_SPEED) 80 | #error "SPINDLE_ENABLE_OFF_WITH_ZERO_SPEED may only be used with USE_SPINDLE_DIR_AS_ENABLE_PIN enabled" 81 | #endif 82 | 83 | #if defined(PARKING_ENABLE) 84 | #if defined(HOMING_FORCE_SET_ORIGIN) 85 | #error "HOMING_FORCE_SET_ORIGIN is not supported with PARKING_ENABLE at this time." 86 | #endif 87 | #endif 88 | 89 | #if defined(ENABLE_PARKING_OVERRIDE_CONTROL) 90 | #if !defined(PARKING_ENABLE) 91 | #error "ENABLE_PARKING_OVERRIDE_CONTROL must be enabled with PARKING_ENABLE." 92 | #endif 93 | #endif 94 | 95 | #if defined(SPINDLE_PWM_MIN_VALUE) 96 | #if !(SPINDLE_PWM_MIN_VALUE > 0) 97 | #error "SPINDLE_PWM_MIN_VALUE must be greater than zero." 98 | #endif 99 | #endif 100 | 101 | #if (REPORT_WCO_REFRESH_BUSY_COUNT < REPORT_WCO_REFRESH_IDLE_COUNT) 102 | #error "WCO busy refresh is less than idle refresh." 103 | #endif 104 | #if (REPORT_OVR_REFRESH_BUSY_COUNT < REPORT_OVR_REFRESH_IDLE_COUNT) 105 | #error "Override busy refresh is less than idle refresh." 106 | #endif 107 | #if (REPORT_WCO_REFRESH_IDLE_COUNT < 2) 108 | #error "WCO refresh must be greater than one." 109 | #endif 110 | #if (REPORT_OVR_REFRESH_IDLE_COUNT < 1) 111 | #error "Override refresh must be greater than zero." 112 | #endif 113 | 114 | // --------------------------------------------------------------------------------------- 115 | 116 | #endif 117 | -------------------------------------------------------------------------------- /grbl/jog.c: -------------------------------------------------------------------------------- 1 | /* 2 | jog.h - Jogging methods 3 | Part of Grbl 4 | 5 | Copyright (c) 2016 Sungeun K. Jeon for Gnea Research LLC 6 | 7 | Grbl is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation, either version 3 of the License, or 10 | (at your option) any later version. 11 | 12 | Grbl is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with Grbl. If not, see . 19 | */ 20 | 21 | #include "grbl.h" 22 | 23 | 24 | // Sets up valid jog motion received from g-code parser, checks for soft-limits, and executes the jog. 25 | uint8_t jog_execute(plan_line_data_t *pl_data, parser_block_t *gc_block) 26 | { 27 | // Initialize planner data struct for jogging motions. 28 | // NOTE: Spindle and coolant are allowed to fully function with overrides during a jog. 29 | pl_data->feed_rate = gc_block->values.f; 30 | pl_data->condition |= PL_COND_FLAG_NO_FEED_OVERRIDE; 31 | #ifdef USE_LINE_NUMBERS 32 | pl_data->line_number = gc_block->values.n; 33 | #endif 34 | 35 | if (bit_istrue(settings.flags,BITFLAG_SOFT_LIMIT_ENABLE)) { 36 | if (system_check_travel_limits(gc_block->values.xyz)) { return(STATUS_TRAVEL_EXCEEDED); } 37 | } 38 | 39 | // Valid jog command. Plan, set state, and execute. 40 | mc_line(gc_block->values.xyz,pl_data); 41 | if (sys.state == STATE_IDLE) { 42 | if (plan_get_current_block() != NULL) { // Check if there is a block to execute. 43 | sys.state = STATE_JOG; 44 | st_prep_buffer(); 45 | st_wake_up(); // NOTE: Manual start. No state machine required. 46 | } 47 | } 48 | 49 | return(STATUS_OK); 50 | } 51 | -------------------------------------------------------------------------------- /grbl/jog.h: -------------------------------------------------------------------------------- 1 | /* 2 | jog.h - Jogging methods 3 | Part of Grbl 4 | 5 | Copyright (c) 2016 Sungeun K. Jeon for Gnea Research LLC 6 | 7 | Grbl is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation, either version 3 of the License, or 10 | (at your option) any later version. 11 | 12 | Grbl is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with Grbl. If not, see . 19 | */ 20 | 21 | #ifndef jog_h 22 | #define jog_h 23 | 24 | #include "gcode.h" 25 | 26 | // System motion line numbers must be zero. 27 | #define JOG_LINE_NUMBER 0 28 | 29 | // Sets up valid jog motion received from g-code parser, checks for soft-limits, and executes the jog. 30 | uint8_t jog_execute(plan_line_data_t *pl_data, parser_block_t *gc_block); 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /grbl/limits.h: -------------------------------------------------------------------------------- 1 | /* 2 | limits.h - code pertaining to limit-switches and performing the homing cycle 3 | Part of Grbl 4 | 5 | Copyright (c) 2012-2016 Sungeun K. Jeon for Gnea Research LLC 6 | Copyright (c) 2009-2011 Simen Svale Skogsrud 7 | 8 | Grbl is free software: you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License as published by 10 | the Free Software Foundation, either version 3 of the License, or 11 | (at your option) any later version. 12 | 13 | Grbl is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with Grbl. If not, see . 20 | */ 21 | 22 | #ifndef limits_h 23 | #define limits_h 24 | 25 | 26 | // Initialize the limits module 27 | void limits_init(); 28 | 29 | // Disables hard limits. 30 | void limits_disable(); 31 | 32 | // Returns limit state as a bit-wise uint8 variable. 33 | uint8_t limits_get_state(); 34 | 35 | // Perform one portion of the homing cycle based on the input settings. 36 | void limits_go_home(uint8_t cycle_mask); 37 | 38 | // Check for soft limit violations 39 | void limits_soft_check(float *target); 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /grbl/main.c: -------------------------------------------------------------------------------- 1 | /* 2 | main.c - An embedded CNC Controller with rs274/ngc (g-code) support 3 | Part of Grbl 4 | 5 | Copyright (c) 2011-2016 Sungeun K. Jeon for Gnea Research LLC 6 | Copyright (c) 2009-2011 Simen Svale Skogsrud 7 | 8 | Grbl is free software: you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License as published by 10 | the Free Software Foundation, either version 3 of the License, or 11 | (at your option) any later version. 12 | 13 | Grbl is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with Grbl. If not, see . 20 | */ 21 | 22 | #include "grbl.h" 23 | 24 | 25 | // Declare system global variable structure 26 | system_t sys; 27 | int32_t sys_position[N_AXIS]; // Real-time machine (aka home) position vector in steps. 28 | int32_t sys_probe_position[N_AXIS]; // Last probe position in machine coordinates and steps. 29 | volatile uint8_t sys_probe_state; // Probing state value. Used to coordinate the probing cycle with stepper ISR. 30 | volatile uint8_t sys_rt_exec_state; // Global realtime executor bitflag variable for state management. See EXEC bitmasks. 31 | volatile uint8_t sys_rt_exec_alarm; // Global realtime executor bitflag variable for setting various alarms. 32 | volatile uint8_t sys_rt_exec_motion_override; // Global realtime executor bitflag variable for motion-based overrides. 33 | volatile uint8_t sys_rt_exec_accessory_override; // Global realtime executor bitflag variable for spindle/coolant overrides. 34 | 35 | 36 | int main(void) 37 | { 38 | // Initialize system upon power-up. 39 | serial_init(); // Setup serial baud rate and interrupts 40 | settings_init(); // Load Grbl settings from EEPROM 41 | stepper_init(); // Configure stepper pins and interrupt timers 42 | system_init(); // Configure pinout pins and pin-change interrupt 43 | 44 | memset(sys_position,0,sizeof(sys_position)); // Clear machine position. 45 | sei(); // Enable interrupts 46 | 47 | // Initialize system state. 48 | #ifdef FORCE_INITIALIZATION_ALARM 49 | // Force Grbl into an ALARM state upon a power-cycle or hard reset. 50 | sys.state = STATE_ALARM; 51 | #else 52 | sys.state = STATE_IDLE; 53 | #endif 54 | 55 | // Check for power-up and set system alarm if homing is enabled to force homing cycle 56 | // by setting Grbl's alarm state. Alarm locks out all g-code commands, including the 57 | // startup scripts, but allows access to settings and internal commands. Only a homing 58 | // cycle '$H' or kill alarm locks '$X' will disable the alarm. 59 | // NOTE: The startup script will run after successful completion of the homing cycle, but 60 | // not after disabling the alarm locks. Prevents motion startup blocks from crashing into 61 | // things uncontrollably. Very bad. 62 | #ifdef HOMING_INIT_LOCK 63 | if (bit_istrue(settings.flags,BITFLAG_HOMING_ENABLE)) { sys.state = STATE_ALARM; } 64 | #endif 65 | 66 | // Grbl initialization loop upon power-up or a system abort. For the latter, all processes 67 | // will return to this loop to be cleanly re-initialized. 68 | for(;;) { 69 | 70 | // Reset system variables. 71 | uint8_t prior_state = sys.state; 72 | memset(&sys, 0, sizeof(system_t)); // Clear system struct variable. 73 | sys.state = prior_state; 74 | sys.f_override = DEFAULT_FEED_OVERRIDE; // Set to 100% 75 | sys.r_override = DEFAULT_RAPID_OVERRIDE; // Set to 100% 76 | sys.spindle_speed_ovr = DEFAULT_SPINDLE_SPEED_OVERRIDE; // Set to 100% 77 | memset(sys_probe_position,0,sizeof(sys_probe_position)); // Clear probe position. 78 | sys_probe_state = 0; 79 | sys_rt_exec_state = 0; 80 | sys_rt_exec_alarm = 0; 81 | sys_rt_exec_motion_override = 0; 82 | sys_rt_exec_accessory_override = 0; 83 | 84 | // Reset Grbl primary systems. 85 | serial_reset_read_buffer(); // Clear serial read buffer 86 | gc_init(); // Set g-code parser to default state 87 | spindle_init(); 88 | coolant_init(); 89 | limits_init(); 90 | probe_init(); 91 | plan_reset(); // Clear block buffer and planner variables 92 | st_reset(); // Clear stepper subsystem variables. 93 | 94 | // Sync cleared gcode and planner positions to current system position. 95 | plan_sync_position(); 96 | gc_sync_position(); 97 | 98 | // Print welcome message. Indicates an initialization has occured at power-up or with a reset. 99 | report_init_message(); 100 | 101 | // Start Grbl main loop. Processes program inputs and executes them. 102 | protocol_main_loop(); 103 | 104 | } 105 | return 0; /* Never reached */ 106 | } 107 | -------------------------------------------------------------------------------- /grbl/motion_control.h: -------------------------------------------------------------------------------- 1 | /* 2 | motion_control.h - high level interface for issuing motion commands 3 | Part of Grbl 4 | 5 | Copyright (c) 2011-2016 Sungeun K. Jeon for Gnea Research LLC 6 | Copyright (c) 2009-2011 Simen Svale Skogsrud 7 | 8 | Grbl is free software: you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License as published by 10 | the Free Software Foundation, either version 3 of the License, or 11 | (at your option) any later version. 12 | 13 | Grbl is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with Grbl. If not, see . 20 | */ 21 | 22 | #ifndef motion_control_h 23 | #define motion_control_h 24 | 25 | 26 | // System motion commands must have a line number of zero. 27 | #define HOMING_CYCLE_LINE_NUMBER 0 28 | #define PARKING_MOTION_LINE_NUMBER 0 29 | 30 | #define HOMING_CYCLE_ALL 0 // Must be zero. 31 | #define HOMING_CYCLE_X bit(X_AXIS) 32 | #define HOMING_CYCLE_Y bit(Y_AXIS) 33 | #define HOMING_CYCLE_Z bit(Z_AXIS) 34 | 35 | 36 | // Execute linear motion in absolute millimeter coordinates. Feed rate given in millimeters/second 37 | // unless invert_feed_rate is true. Then the feed_rate means that the motion should be completed in 38 | // (1 minute)/feed_rate time. 39 | void mc_line(float *target, plan_line_data_t *pl_data); 40 | 41 | // Execute an arc in offset mode format. position == current xyz, target == target xyz, 42 | // offset == offset from current xyz, axis_XXX defines circle plane in tool space, axis_linear is 43 | // the direction of helical travel, radius == circle radius, is_clockwise_arc boolean. Used 44 | // for vector transformation direction. 45 | void mc_arc(float *target, plan_line_data_t *pl_data, float *position, float *offset, float radius, 46 | uint8_t axis_0, uint8_t axis_1, uint8_t axis_linear, uint8_t is_clockwise_arc); 47 | 48 | // Dwell for a specific number of seconds 49 | void mc_dwell(float seconds); 50 | 51 | // Perform homing cycle to locate machine zero. Requires limit switches. 52 | void mc_homing_cycle(uint8_t cycle_mask); 53 | 54 | // Perform tool length probe cycle. Requires probe switch. 55 | uint8_t mc_probe_cycle(float *target, plan_line_data_t *pl_data, uint8_t parser_flags); 56 | 57 | // Handles updating the override control state. 58 | void mc_override_ctrl_update(uint8_t override_state); 59 | 60 | // Plans and executes the single special motion case for parking. Independent of main planner buffer. 61 | void mc_parking_motion(float *parking_target, plan_line_data_t *pl_data); 62 | 63 | // Performs system reset. If in motion state, kills all motion and sets system alarm. 64 | void mc_reset(); 65 | 66 | #endif 67 | -------------------------------------------------------------------------------- /grbl/nuts_bolts.c: -------------------------------------------------------------------------------- 1 | /* 2 | nuts_bolts.c - Shared functions 3 | Part of Grbl 4 | 5 | Copyright (c) 2011-2016 Sungeun K. Jeon for Gnea Research LLC 6 | Copyright (c) 2009-2011 Simen Svale Skogsrud 7 | 8 | Grbl is free software: you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License as published by 10 | the Free Software Foundation, either version 3 of the License, or 11 | (at your option) any later version. 12 | 13 | Grbl is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with Grbl. If not, see . 20 | */ 21 | 22 | #include "grbl.h" 23 | 24 | 25 | #define MAX_INT_DIGITS 8 // Maximum number of digits in int32 (and float) 26 | 27 | 28 | // Extracts a floating point value from a string. The following code is based loosely on 29 | // the avr-libc strtod() function by Michael Stumpf and Dmitry Xmelkov and many freely 30 | // available conversion method examples, but has been highly optimized for Grbl. For known 31 | // CNC applications, the typical decimal value is expected to be in the range of E0 to E-4. 32 | // Scientific notation is officially not supported by g-code, and the 'E' character may 33 | // be a g-code word on some CNC systems. So, 'E' notation will not be recognized. 34 | // NOTE: Thanks to Radu-Eosif Mihailescu for identifying the issues with using strtod(). 35 | uint8_t read_float(char *line, uint8_t *char_counter, float *float_ptr) 36 | { 37 | char *ptr = line + *char_counter; 38 | unsigned char c; 39 | 40 | // Grab first character and increment pointer. No spaces assumed in line. 41 | c = *ptr++; 42 | 43 | // Capture initial positive/minus character 44 | bool isnegative = false; 45 | if (c == '-') { 46 | isnegative = true; 47 | c = *ptr++; 48 | } else if (c == '+') { 49 | c = *ptr++; 50 | } 51 | 52 | // Extract number into fast integer. Track decimal in terms of exponent value. 53 | uint32_t intval = 0; 54 | int8_t exp = 0; 55 | uint8_t ndigit = 0; 56 | bool isdecimal = false; 57 | while(1) { 58 | c -= '0'; 59 | if (c <= 9) { 60 | ndigit++; 61 | if (ndigit <= MAX_INT_DIGITS) { 62 | if (isdecimal) { exp--; } 63 | intval = (((intval << 2) + intval) << 1) + c; // intval*10 + c 64 | } else { 65 | if (!(isdecimal)) { exp++; } // Drop overflow digits 66 | } 67 | } else if (c == (('.'-'0') & 0xff) && !(isdecimal)) { 68 | isdecimal = true; 69 | } else { 70 | break; 71 | } 72 | c = *ptr++; 73 | } 74 | 75 | // Return if no digits have been read. 76 | if (!ndigit) { return(false); }; 77 | 78 | // Convert integer into floating point. 79 | float fval; 80 | fval = (float)intval; 81 | 82 | // Apply decimal. Should perform no more than two floating point multiplications for the 83 | // expected range of E0 to E-4. 84 | if (fval != 0) { 85 | while (exp <= -2) { 86 | fval *= 0.01; 87 | exp += 2; 88 | } 89 | if (exp < 0) { 90 | fval *= 0.1; 91 | } else if (exp > 0) { 92 | do { 93 | fval *= 10.0; 94 | } while (--exp > 0); 95 | } 96 | } 97 | 98 | // Assign floating point value with correct sign. 99 | if (isnegative) { 100 | *float_ptr = -fval; 101 | } else { 102 | *float_ptr = fval; 103 | } 104 | 105 | *char_counter = ptr - line - 1; // Set char_counter to next statement 106 | 107 | return(true); 108 | } 109 | 110 | 111 | // Non-blocking delay function used for general operation and suspend features. 112 | void delay_sec(float seconds, uint8_t mode) 113 | { 114 | uint16_t i = ceil(1000/DWELL_TIME_STEP*seconds); 115 | while (i-- > 0) { 116 | if (sys.abort) { return; } 117 | if (mode == DELAY_MODE_DWELL) { 118 | protocol_execute_realtime(); 119 | } else { // DELAY_MODE_SYS_SUSPEND 120 | // Execute rt_system() only to avoid nesting suspend loops. 121 | protocol_exec_rt_system(); 122 | if (sys.suspend & SUSPEND_RESTART_RETRACT) { return; } // Bail, if safety door reopens. 123 | } 124 | _delay_ms(DWELL_TIME_STEP); // Delay DWELL_TIME_STEP increment 125 | } 126 | } 127 | 128 | 129 | // Delays variable defined milliseconds. Compiler compatibility fix for _delay_ms(), 130 | // which only accepts constants in future compiler releases. 131 | void delay_ms(uint16_t ms) 132 | { 133 | while ( ms-- ) { _delay_ms(1); } 134 | } 135 | 136 | 137 | // Delays variable defined microseconds. Compiler compatibility fix for _delay_us(), 138 | // which only accepts constants in future compiler releases. Written to perform more 139 | // efficiently with larger delays, as the counter adds parasitic time in each iteration. 140 | void delay_us(uint32_t us) 141 | { 142 | while (us) { 143 | if (us < 10) { 144 | _delay_us(1); 145 | us--; 146 | } else if (us < 100) { 147 | _delay_us(10); 148 | us -= 10; 149 | } else if (us < 1000) { 150 | _delay_us(100); 151 | us -= 100; 152 | } else { 153 | _delay_ms(1); 154 | us -= 1000; 155 | } 156 | } 157 | } 158 | 159 | 160 | // Simple hypotenuse computation function. 161 | float hypot_f(float x, float y) { return(sqrt(x*x + y*y)); } 162 | 163 | 164 | float convert_delta_vector_to_unit_vector(float *vector) 165 | { 166 | uint8_t idx; 167 | float magnitude = 0.0; 168 | for (idx=0; idx. 20 | */ 21 | 22 | #ifndef nuts_bolts_h 23 | #define nuts_bolts_h 24 | 25 | #define false 0 26 | #define true 1 27 | 28 | #define SOME_LARGE_VALUE 1.0E+38 29 | 30 | // Axis array index values. Must start with 0 and be continuous. 31 | #define N_AXIS 3 // Number of axes 32 | #define X_AXIS 0 // Axis indexing value. 33 | #define Y_AXIS 1 34 | #define Z_AXIS 2 35 | // #define A_AXIS 3 36 | 37 | // CoreXY motor assignments. DO NOT ALTER. 38 | // NOTE: If the A and B motor axis bindings are changed, this effects the CoreXY equations. 39 | #ifdef COREXY 40 | #define A_MOTOR X_AXIS // Must be X_AXIS 41 | #define B_MOTOR Y_AXIS // Must be Y_AXIS 42 | #endif 43 | 44 | // Conversions 45 | #define MM_PER_INCH (25.40) 46 | #define INCH_PER_MM (0.0393701) 47 | #define TICKS_PER_MICROSECOND (F_CPU/1000000) 48 | 49 | #define DELAY_MODE_DWELL 0 50 | #define DELAY_MODE_SYS_SUSPEND 1 51 | 52 | // Useful macros 53 | #define clear_vector(a) memset(a, 0, sizeof(a)) 54 | #define clear_vector_float(a) memset(a, 0.0, sizeof(float)*N_AXIS) 55 | // #define clear_vector_long(a) memset(a, 0.0, sizeof(long)*N_AXIS) 56 | #define max(a,b) (((a) > (b)) ? (a) : (b)) 57 | #define min(a,b) (((a) < (b)) ? (a) : (b)) 58 | #define isequal_position_vector(a,b) !(memcmp(a, b, sizeof(float)*N_AXIS)) 59 | 60 | // Bit field and masking macros 61 | #define bit(n) (1 << n) 62 | #define bit_true(x,mask) (x) |= (mask) 63 | #define bit_false(x,mask) (x) &= ~(mask) 64 | #define bit_istrue(x,mask) ((x & mask) != 0) 65 | #define bit_isfalse(x,mask) ((x & mask) == 0) 66 | 67 | // Read a floating point value from a string. Line points to the input buffer, char_counter 68 | // is the indexer pointing to the current character of the line, while float_ptr is 69 | // a pointer to the result variable. Returns true when it succeeds 70 | uint8_t read_float(char *line, uint8_t *char_counter, float *float_ptr); 71 | 72 | // Non-blocking delay function used for general operation and suspend features. 73 | void delay_sec(float seconds, uint8_t mode); 74 | 75 | // Delays variable-defined milliseconds. Compiler compatibility fix for _delay_ms(). 76 | void delay_ms(uint16_t ms); 77 | 78 | // Delays variable-defined microseconds. Compiler compatibility fix for _delay_us(). 79 | void delay_us(uint32_t us); 80 | 81 | // Computes hypotenuse, avoiding avr-gcc's bloated version and the extra error checking. 82 | float hypot_f(float x, float y); 83 | 84 | float convert_delta_vector_to_unit_vector(float *vector); 85 | float limit_value_by_axis_maximum(float *max_value, float *unit_vec); 86 | 87 | #endif 88 | -------------------------------------------------------------------------------- /grbl/print.c: -------------------------------------------------------------------------------- 1 | /* 2 | print.c - Functions for formatting output strings 3 | Part of Grbl 4 | 5 | Copyright (c) 2011-2016 Sungeun K. Jeon for Gnea Research LLC 6 | Copyright (c) 2009-2011 Simen Svale Skogsrud 7 | 8 | Grbl is free software: you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License as published by 10 | the Free Software Foundation, either version 3 of the License, or 11 | (at your option) any later version. 12 | 13 | Grbl is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with Grbl. If not, see . 20 | */ 21 | 22 | #include "grbl.h" 23 | 24 | 25 | void printString(const char *s) 26 | { 27 | while (*s) 28 | serial_write(*s++); 29 | } 30 | 31 | 32 | // Print a string stored in PGM-memory 33 | void printPgmString(const char *s) 34 | { 35 | char c; 36 | while ((c = pgm_read_byte_near(s++))) 37 | serial_write(c); 38 | } 39 | 40 | 41 | // void printIntegerInBase(unsigned long n, unsigned long base) 42 | // { 43 | // unsigned char buf[8 * sizeof(long)]; // Assumes 8-bit chars. 44 | // unsigned long i = 0; 45 | // 46 | // if (n == 0) { 47 | // serial_write('0'); 48 | // return; 49 | // } 50 | // 51 | // while (n > 0) { 52 | // buf[i++] = n % base; 53 | // n /= base; 54 | // } 55 | // 56 | // for (; i > 0; i--) 57 | // serial_write(buf[i - 1] < 10 ? 58 | // '0' + buf[i - 1] : 59 | // 'A' + buf[i - 1] - 10); 60 | // } 61 | 62 | 63 | // Prints an uint8 variable in base 10. 64 | void print_uint8_base10(uint8_t n) 65 | { 66 | uint8_t digit_a = 0; 67 | uint8_t digit_b = 0; 68 | if (n >= 100) { // 100-255 69 | digit_a = '0' + n % 10; 70 | n /= 10; 71 | } 72 | if (n >= 10) { // 10-99 73 | digit_b = '0' + n % 10; 74 | n /= 10; 75 | } 76 | serial_write('0' + n); 77 | if (digit_b) { serial_write(digit_b); } 78 | if (digit_a) { serial_write(digit_a); } 79 | } 80 | 81 | 82 | // Prints an uint8 variable in base 2 with desired number of desired digits. 83 | void print_uint8_base2_ndigit(uint8_t n, uint8_t digits) { 84 | unsigned char buf[digits]; 85 | uint8_t i = 0; 86 | 87 | for (; i < digits; i++) { 88 | buf[i] = n % 2 ; 89 | n /= 2; 90 | } 91 | 92 | for (; i > 0; i--) 93 | serial_write('0' + buf[i - 1]); 94 | } 95 | 96 | 97 | void print_uint32_base10(uint32_t n) 98 | { 99 | if (n == 0) { 100 | serial_write('0'); 101 | return; 102 | } 103 | 104 | unsigned char buf[10]; 105 | uint8_t i = 0; 106 | 107 | while (n > 0) { 108 | buf[i++] = n % 10; 109 | n /= 10; 110 | } 111 | 112 | for (; i > 0; i--) 113 | serial_write('0' + buf[i-1]); 114 | } 115 | 116 | 117 | void printInteger(long n) 118 | { 119 | if (n < 0) { 120 | serial_write('-'); 121 | print_uint32_base10(-n); 122 | } else { 123 | print_uint32_base10(n); 124 | } 125 | } 126 | 127 | 128 | // Convert float to string by immediately converting to a long integer, which contains 129 | // more digits than a float. Number of decimal places, which are tracked by a counter, 130 | // may be set by the user. The integer is then efficiently converted to a string. 131 | // NOTE: AVR '%' and '/' integer operations are very efficient. Bitshifting speed-up 132 | // techniques are actually just slightly slower. Found this out the hard way. 133 | void printFloat(float n, uint8_t decimal_places) 134 | { 135 | if (n < 0) { 136 | serial_write('-'); 137 | n = -n; 138 | } 139 | 140 | uint8_t decimals = decimal_places; 141 | while (decimals >= 2) { // Quickly convert values expected to be E0 to E-4. 142 | n *= 100; 143 | decimals -= 2; 144 | } 145 | if (decimals) { n *= 10; } 146 | n += 0.5; // Add rounding factor. Ensures carryover through entire value. 147 | 148 | // Generate digits backwards and store in string. 149 | unsigned char buf[13]; 150 | uint8_t i = 0; 151 | uint32_t a = (long)n; 152 | while(a > 0) { 153 | buf[i++] = (a % 10) + '0'; // Get digit 154 | a /= 10; 155 | } 156 | while (i < decimal_places) { 157 | buf[i++] = '0'; // Fill in zeros to decimal point for (n < 1) 158 | } 159 | if (i == decimal_places) { // Fill in leading zero, if needed. 160 | buf[i++] = '0'; 161 | } 162 | 163 | // Print the generated string. 164 | for (; i > 0; i--) { 165 | if (i == decimal_places) { serial_write('.'); } // Insert decimal point in right place. 166 | serial_write(buf[i-1]); 167 | } 168 | } 169 | 170 | 171 | // Floating value printing handlers for special variables types used in Grbl and are defined 172 | // in the config.h. 173 | // - CoordValue: Handles all position or coordinate values in inches or mm reporting. 174 | // - RateValue: Handles feed rate and current velocity in inches or mm reporting. 175 | void printFloat_CoordValue(float n) { 176 | if (bit_istrue(settings.flags,BITFLAG_REPORT_INCHES)) { 177 | printFloat(n*INCH_PER_MM,N_DECIMAL_COORDVALUE_INCH); 178 | } else { 179 | printFloat(n,N_DECIMAL_COORDVALUE_MM); 180 | } 181 | } 182 | 183 | void printFloat_RateValue(float n) { 184 | if (bit_istrue(settings.flags,BITFLAG_REPORT_INCHES)) { 185 | printFloat(n*INCH_PER_MM,N_DECIMAL_RATEVALUE_INCH); 186 | } else { 187 | printFloat(n,N_DECIMAL_RATEVALUE_MM); 188 | } 189 | } 190 | 191 | // Debug tool to print free memory in bytes at the called point. 192 | // NOTE: Keep commented unless using. Part of this function always gets compiled in. 193 | // void printFreeMemory() 194 | // { 195 | // extern int __heap_start, *__brkval; 196 | // uint16_t free; // Up to 64k values. 197 | // free = (int) &free - (__brkval == 0 ? (int) &__heap_start : (int) __brkval); 198 | // printInteger((int32_t)free); 199 | // printString(" "); 200 | // } 201 | -------------------------------------------------------------------------------- /grbl/print.h: -------------------------------------------------------------------------------- 1 | /* 2 | print.h - Functions for formatting output strings 3 | Part of Grbl 4 | 5 | Copyright (c) 2011-2016 Sungeun K. Jeon for Gnea Research LLC 6 | Copyright (c) 2009-2011 Simen Svale Skogsrud 7 | 8 | Grbl is free software: you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License as published by 10 | the Free Software Foundation, either version 3 of the License, or 11 | (at your option) any later version. 12 | 13 | Grbl is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with Grbl. If not, see . 20 | */ 21 | 22 | #ifndef print_h 23 | #define print_h 24 | 25 | 26 | void printString(const char *s); 27 | 28 | void printPgmString(const char *s); 29 | 30 | void printInteger(long n); 31 | 32 | void print_uint32_base10(uint32_t n); 33 | 34 | // Prints an uint8 variable in base 10. 35 | void print_uint8_base10(uint8_t n); 36 | 37 | // Prints an uint8 variable in base 2 with desired number of desired digits. 38 | void print_uint8_base2_ndigit(uint8_t n, uint8_t digits); 39 | 40 | void printFloat(float n, uint8_t decimal_places); 41 | 42 | // Floating value printing handlers for special variables types used in Grbl. 43 | // - CoordValue: Handles all position or coordinate values in inches or mm reporting. 44 | // - RateValue: Handles feed rate and current velocity in inches or mm reporting. 45 | void printFloat_CoordValue(float n); 46 | void printFloat_RateValue(float n); 47 | 48 | // Debug tool to print free memory in bytes at the called point. Not used otherwise. 49 | void printFreeMemory(); 50 | 51 | #endif 52 | -------------------------------------------------------------------------------- /grbl/probe.c: -------------------------------------------------------------------------------- 1 | /* 2 | probe.c - code pertaining to probing methods 3 | Part of Grbl 4 | 5 | Copyright (c) 2014-2016 Sungeun K. Jeon for Gnea Research LLC 6 | 7 | Grbl is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation, either version 3 of the License, or 10 | (at your option) any later version. 11 | 12 | Grbl is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with Grbl. If not, see . 19 | */ 20 | 21 | #include "grbl.h" 22 | 23 | 24 | // Inverts the probe pin state depending on user settings and probing cycle mode. 25 | uint8_t probe_invert_mask; 26 | 27 | 28 | // Probe pin initialization routine. 29 | void probe_init() 30 | { 31 | PROBE_DDR &= ~(PROBE_MASK); // Configure as input pins 32 | #ifdef DISABLE_PROBE_PIN_PULL_UP 33 | PROBE_PORT &= ~(PROBE_MASK); // Normal low operation. Requires external pull-down. 34 | #else 35 | PROBE_PORT |= PROBE_MASK; // Enable internal pull-up resistors. Normal high operation. 36 | #endif 37 | probe_configure_invert_mask(false); // Initialize invert mask. 38 | } 39 | 40 | 41 | // Called by probe_init() and the mc_probe() routines. Sets up the probe pin invert mask to 42 | // appropriately set the pin logic according to setting for normal-high/normal-low operation 43 | // and the probing cycle modes for toward-workpiece/away-from-workpiece. 44 | void probe_configure_invert_mask(uint8_t is_probe_away) 45 | { 46 | probe_invert_mask = 0; // Initialize as zero. 47 | if (bit_isfalse(settings.flags,BITFLAG_INVERT_PROBE_PIN)) { probe_invert_mask ^= PROBE_MASK; } 48 | if (is_probe_away) { probe_invert_mask ^= PROBE_MASK; } 49 | } 50 | 51 | 52 | // Returns the probe pin state. Triggered = true. Called by gcode parser and probe state monitor. 53 | uint8_t probe_get_state() { return((PROBE_PIN & PROBE_MASK) ^ probe_invert_mask); } 54 | 55 | 56 | // Monitors probe pin state and records the system position when detected. Called by the 57 | // stepper ISR per ISR tick. 58 | // NOTE: This function must be extremely efficient as to not bog down the stepper ISR. 59 | void probe_state_monitor() 60 | { 61 | if (probe_get_state()) { 62 | sys_probe_state = PROBE_OFF; 63 | memcpy(sys_probe_position, sys_position, sizeof(sys_position)); 64 | bit_true(sys_rt_exec_state, EXEC_MOTION_CANCEL); 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /grbl/probe.h: -------------------------------------------------------------------------------- 1 | /* 2 | probe.h - code pertaining to probing methods 3 | Part of Grbl 4 | 5 | Copyright (c) 2014-2016 Sungeun K. Jeon for Gnea Research LLC 6 | 7 | Grbl is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation, either version 3 of the License, or 10 | (at your option) any later version. 11 | 12 | Grbl is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with Grbl. If not, see . 19 | */ 20 | 21 | #ifndef probe_h 22 | #define probe_h 23 | 24 | // Values that define the probing state machine. 25 | #define PROBE_OFF 0 // Probing disabled or not in use. (Must be zero.) 26 | #define PROBE_ACTIVE 1 // Actively watching the input pin. 27 | 28 | // Probe pin initialization routine. 29 | void probe_init(); 30 | 31 | // Called by probe_init() and the mc_probe() routines. Sets up the probe pin invert mask to 32 | // appropriately set the pin logic according to setting for normal-high/normal-low operation 33 | // and the probing cycle modes for toward-workpiece/away-from-workpiece. 34 | void probe_configure_invert_mask(uint8_t is_probe_away); 35 | 36 | // Returns probe pin state. Triggered = true. Called by gcode parser and probe state monitor. 37 | uint8_t probe_get_state(); 38 | 39 | // Monitors probe pin state and records the system position when detected. Called by the 40 | // stepper ISR per ISR tick. 41 | void probe_state_monitor(); 42 | 43 | #endif 44 | -------------------------------------------------------------------------------- /grbl/protocol.h: -------------------------------------------------------------------------------- 1 | /* 2 | protocol.h - controls Grbl execution protocol and procedures 3 | Part of Grbl 4 | 5 | Copyright (c) 2011-2016 Sungeun K. Jeon for Gnea Research LLC 6 | Copyright (c) 2009-2011 Simen Svale Skogsrud 7 | 8 | Grbl is free software: you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License as published by 10 | the Free Software Foundation, either version 3 of the License, or 11 | (at your option) any later version. 12 | 13 | Grbl is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with Grbl. If not, see . 20 | */ 21 | 22 | #ifndef protocol_h 23 | #define protocol_h 24 | 25 | // Line buffer size from the serial input stream to be executed. 26 | // NOTE: Not a problem except for extreme cases, but the line buffer size can be too small 27 | // and g-code blocks can get truncated. Officially, the g-code standards support up to 256 28 | // characters. In future versions, this will be increased, when we know how much extra 29 | // memory space we can invest into here or we re-write the g-code parser not to have this 30 | // buffer. 31 | #ifndef LINE_BUFFER_SIZE 32 | #define LINE_BUFFER_SIZE 80 33 | #endif 34 | 35 | // Starts Grbl main loop. It handles all incoming characters from the serial port and executes 36 | // them as they complete. It is also responsible for finishing the initialization procedures. 37 | void protocol_main_loop(); 38 | 39 | // Checks and executes a realtime command at various stop points in main program 40 | void protocol_execute_realtime(); 41 | void protocol_exec_rt_system(); 42 | 43 | // Executes the auto cycle feature, if enabled. 44 | void protocol_auto_cycle_start(); 45 | 46 | // Block until all buffered steps are executed 47 | void protocol_buffer_synchronize(); 48 | 49 | #endif 50 | -------------------------------------------------------------------------------- /grbl/report.h: -------------------------------------------------------------------------------- 1 | /* 2 | report.h - reporting and messaging methods 3 | Part of Grbl 4 | 5 | Copyright (c) 2012-2016 Sungeun K. Jeon for Gnea Research LLC 6 | 7 | Grbl is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation, either version 3 of the License, or 10 | (at your option) any later version. 11 | 12 | Grbl is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with Grbl. If not, see . 19 | */ 20 | #ifndef report_h 21 | #define report_h 22 | 23 | // Define Grbl status codes. Valid values (0-255) 24 | #define STATUS_OK 0 25 | #define STATUS_EXPECTED_COMMAND_LETTER 1 26 | #define STATUS_BAD_NUMBER_FORMAT 2 27 | #define STATUS_INVALID_STATEMENT 3 28 | #define STATUS_NEGATIVE_VALUE 4 29 | #define STATUS_SETTING_DISABLED 5 30 | #define STATUS_SETTING_STEP_PULSE_MIN 6 31 | #define STATUS_SETTING_READ_FAIL 7 32 | #define STATUS_IDLE_ERROR 8 33 | #define STATUS_SYSTEM_GC_LOCK 9 34 | #define STATUS_SOFT_LIMIT_ERROR 10 35 | #define STATUS_OVERFLOW 11 36 | #define STATUS_MAX_STEP_RATE_EXCEEDED 12 37 | #define STATUS_CHECK_DOOR 13 38 | #define STATUS_LINE_LENGTH_EXCEEDED 14 39 | #define STATUS_TRAVEL_EXCEEDED 15 40 | #define STATUS_INVALID_JOG_COMMAND 16 41 | 42 | #define STATUS_GCODE_UNSUPPORTED_COMMAND 20 43 | #define STATUS_GCODE_MODAL_GROUP_VIOLATION 21 44 | #define STATUS_GCODE_UNDEFINED_FEED_RATE 22 45 | #define STATUS_GCODE_COMMAND_VALUE_NOT_INTEGER 23 46 | #define STATUS_GCODE_AXIS_COMMAND_CONFLICT 24 47 | #define STATUS_GCODE_WORD_REPEATED 25 48 | #define STATUS_GCODE_NO_AXIS_WORDS 26 49 | #define STATUS_GCODE_INVALID_LINE_NUMBER 27 50 | #define STATUS_GCODE_VALUE_WORD_MISSING 28 51 | #define STATUS_GCODE_UNSUPPORTED_COORD_SYS 29 52 | #define STATUS_GCODE_G53_INVALID_MOTION_MODE 30 53 | #define STATUS_GCODE_AXIS_WORDS_EXIST 31 54 | #define STATUS_GCODE_NO_AXIS_WORDS_IN_PLANE 32 55 | #define STATUS_GCODE_INVALID_TARGET 33 56 | #define STATUS_GCODE_ARC_RADIUS_ERROR 34 57 | #define STATUS_GCODE_NO_OFFSETS_IN_PLANE 35 58 | #define STATUS_GCODE_UNUSED_WORDS 36 59 | #define STATUS_GCODE_G43_DYNAMIC_AXIS_ERROR 37 60 | #define STATUS_GCODE_MAX_VALUE_EXCEEDED 38 61 | 62 | // Define Grbl alarm codes. Valid values (1-255). 0 is reserved. 63 | #define ALARM_HARD_LIMIT_ERROR EXEC_ALARM_HARD_LIMIT 64 | #define ALARM_SOFT_LIMIT_ERROR EXEC_ALARM_SOFT_LIMIT 65 | #define ALARM_ABORT_CYCLE EXEC_ALARM_ABORT_CYCLE 66 | #define ALARM_PROBE_FAIL_INITIAL EXEC_ALARM_PROBE_FAIL_INITIAL 67 | #define ALARM_PROBE_FAIL_CONTACT EXEC_ALARM_PROBE_FAIL_CONTACT 68 | #define ALARM_HOMING_FAIL_RESET EXEC_ALARM_HOMING_FAIL_RESET 69 | #define ALARM_HOMING_FAIL_DOOR EXEC_ALARM_HOMING_FAIL_DOOR 70 | #define ALARM_HOMING_FAIL_PULLOFF EXEC_ALARM_HOMING_FAIL_PULLOFF 71 | #define ALARM_HOMING_FAIL_APPROACH EXEC_ALARM_HOMING_FAIL_APPROACH 72 | 73 | // Define Grbl feedback message codes. Valid values (0-255). 74 | #define MESSAGE_CRITICAL_EVENT 1 75 | #define MESSAGE_ALARM_LOCK 2 76 | #define MESSAGE_ALARM_UNLOCK 3 77 | #define MESSAGE_ENABLED 4 78 | #define MESSAGE_DISABLED 5 79 | #define MESSAGE_SAFETY_DOOR_AJAR 6 80 | #define MESSAGE_CHECK_LIMITS 7 81 | #define MESSAGE_PROGRAM_END 8 82 | #define MESSAGE_RESTORE_DEFAULTS 9 83 | #define MESSAGE_SPINDLE_RESTORE 10 84 | #define MESSAGE_SLEEP_MODE 11 85 | 86 | // Prints system status messages. 87 | void report_status_message(uint8_t status_code); 88 | 89 | // Prints system alarm messages. 90 | void report_alarm_message(uint8_t alarm_code); 91 | 92 | // Prints miscellaneous feedback messages. 93 | void report_feedback_message(uint8_t message_code); 94 | 95 | // Prints welcome message 96 | void report_init_message(); 97 | 98 | // Prints Grbl help and current global settings 99 | void report_grbl_help(); 100 | 101 | // Prints Grbl global settings 102 | void report_grbl_settings(); 103 | 104 | // Prints an echo of the pre-parsed line received right before execution. 105 | void report_echo_line_received(char *line); 106 | 107 | // Prints realtime status report 108 | void report_realtime_status(); 109 | 110 | // Prints recorded probe position 111 | void report_probe_parameters(); 112 | 113 | // Prints Grbl NGC parameters (coordinate offsets, probe) 114 | void report_ngc_parameters(); 115 | 116 | // Prints current g-code parser mode state 117 | void report_gcode_modes(); 118 | 119 | // Prints startup line when requested and executed. 120 | void report_startup_line(uint8_t n, char *line); 121 | void report_execute_startup_message(char *line, uint8_t status_code); 122 | 123 | // Prints build info and user info 124 | void report_build_info(char *line); 125 | 126 | #ifdef DEBUG 127 | void report_realtime_debug(); 128 | #endif 129 | 130 | #endif 131 | -------------------------------------------------------------------------------- /grbl/serial.h: -------------------------------------------------------------------------------- 1 | /* 2 | serial.c - Low level functions for sending and recieving bytes via the serial port 3 | Part of Grbl 4 | 5 | Copyright (c) 2011-2016 Sungeun K. Jeon for Gnea Research LLC 6 | Copyright (c) 2009-2011 Simen Svale Skogsrud 7 | 8 | Grbl is free software: you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License as published by 10 | the Free Software Foundation, either version 3 of the License, or 11 | (at your option) any later version. 12 | 13 | Grbl is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with Grbl. If not, see . 20 | */ 21 | 22 | #ifndef serial_h 23 | #define serial_h 24 | 25 | 26 | #ifndef RX_BUFFER_SIZE 27 | #define RX_BUFFER_SIZE 128 28 | #endif 29 | #ifndef TX_BUFFER_SIZE 30 | #ifdef USE_LINE_NUMBERS 31 | #define TX_BUFFER_SIZE 112 32 | #else 33 | #define TX_BUFFER_SIZE 104 34 | #endif 35 | #endif 36 | 37 | #define SERIAL_NO_DATA 0xff 38 | 39 | 40 | void serial_init(); 41 | 42 | // Writes one byte to the TX serial buffer. Called by main program. 43 | void serial_write(uint8_t data); 44 | 45 | // Fetches the first byte in the serial read buffer. Called by main program. 46 | uint8_t serial_read(); 47 | 48 | // Reset and empty data in read buffer. Used by e-stop and reset. 49 | void serial_reset_read_buffer(); 50 | 51 | // Returns the number of bytes available in the RX serial buffer. 52 | uint8_t serial_get_rx_buffer_available(); 53 | 54 | // Returns the number of bytes used in the RX serial buffer. 55 | // NOTE: Deprecated. Not used unless classic status reports are enabled in config.h. 56 | uint8_t serial_get_rx_buffer_count(); 57 | 58 | // Returns the number of bytes used in the TX serial buffer. 59 | // NOTE: Not used except for debugging and ensuring no TX bottlenecks. 60 | uint8_t serial_get_tx_buffer_count(); 61 | 62 | #endif 63 | -------------------------------------------------------------------------------- /grbl/settings.h: -------------------------------------------------------------------------------- 1 | /* 2 | settings.h - eeprom configuration handling 3 | Part of Grbl 4 | 5 | Copyright (c) 2011-2016 Sungeun K. Jeon for Gnea Research LLC 6 | Copyright (c) 2009-2011 Simen Svale Skogsrud 7 | 8 | Grbl is free software: you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License as published by 10 | the Free Software Foundation, either version 3 of the License, or 11 | (at your option) any later version. 12 | 13 | Grbl is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with Grbl. If not, see . 20 | */ 21 | 22 | #ifndef settings_h 23 | #define settings_h 24 | 25 | #include "grbl.h" 26 | 27 | 28 | // Version of the EEPROM data. Will be used to migrate existing data from older versions of Grbl 29 | // when firmware is upgraded. Always stored in byte 0 of eeprom 30 | #define SETTINGS_VERSION 10 // NOTE: Check settings_reset() when moving to next version. 31 | 32 | // Define bit flag masks for the boolean settings in settings.flag. 33 | #define BITFLAG_REPORT_INCHES bit(0) 34 | #define BITFLAG_LASER_MODE bit(1) 35 | #define BITFLAG_INVERT_ST_ENABLE bit(2) 36 | #define BITFLAG_HARD_LIMIT_ENABLE bit(3) 37 | #define BITFLAG_HOMING_ENABLE bit(4) 38 | #define BITFLAG_SOFT_LIMIT_ENABLE bit(5) 39 | #define BITFLAG_INVERT_LIMIT_PINS bit(6) 40 | #define BITFLAG_INVERT_PROBE_PIN bit(7) 41 | 42 | // Define status reporting boolean enable bit flags in settings.status_report_mask 43 | #define BITFLAG_RT_STATUS_POSITION_TYPE bit(0) 44 | #define BITFLAG_RT_STATUS_BUFFER_STATE bit(1) 45 | 46 | // Define settings restore bitflags. 47 | #define SETTINGS_RESTORE_DEFAULTS bit(0) 48 | #define SETTINGS_RESTORE_PARAMETERS bit(1) 49 | #define SETTINGS_RESTORE_STARTUP_LINES bit(2) 50 | #define SETTINGS_RESTORE_BUILD_INFO bit(3) 51 | #ifndef SETTINGS_RESTORE_ALL 52 | #define SETTINGS_RESTORE_ALL 0xFF // All bitflags 53 | #endif 54 | 55 | // Define EEPROM memory address location values for Grbl settings and parameters 56 | // NOTE: The Atmega328p has 1KB EEPROM. The upper half is reserved for parameters and 57 | // the startup script. The lower half contains the global settings and space for future 58 | // developments. 59 | #define EEPROM_ADDR_GLOBAL 1U 60 | #define EEPROM_ADDR_PARAMETERS 512U 61 | #define EEPROM_ADDR_STARTUP_BLOCK 768U 62 | #define EEPROM_ADDR_BUILD_INFO 942U 63 | 64 | // Define EEPROM address indexing for coordinate parameters 65 | #define N_COORDINATE_SYSTEM 6 // Number of supported work coordinate systems (from index 1) 66 | #define SETTING_INDEX_NCOORD N_COORDINATE_SYSTEM+1 // Total number of system stored (from index 0) 67 | // NOTE: Work coordinate indices are (0=G54, 1=G55, ... , 6=G59) 68 | #define SETTING_INDEX_G28 N_COORDINATE_SYSTEM // Home position 1 69 | #define SETTING_INDEX_G30 N_COORDINATE_SYSTEM+1 // Home position 2 70 | // #define SETTING_INDEX_G92 N_COORDINATE_SYSTEM+2 // Coordinate offset (G92.2,G92.3 not supported) 71 | 72 | // Define Grbl axis settings numbering scheme. Starts at START_VAL, every INCREMENT, over N_SETTINGS. 73 | #define AXIS_N_SETTINGS 4 74 | #define AXIS_SETTINGS_START_VAL 100 // NOTE: Reserving settings values >= 100 for axis settings. Up to 255. 75 | #define AXIS_SETTINGS_INCREMENT 10 // Must be greater than the number of axis settings 76 | 77 | // Global persistent settings (Stored from byte EEPROM_ADDR_GLOBAL onwards) 78 | typedef struct { 79 | // Axis settings 80 | float steps_per_mm[N_AXIS]; 81 | float max_rate[N_AXIS]; 82 | float acceleration[N_AXIS]; 83 | float max_travel[N_AXIS]; 84 | 85 | // Remaining Grbl settings 86 | uint8_t pulse_microseconds; 87 | uint8_t step_invert_mask; 88 | uint8_t dir_invert_mask; 89 | uint8_t stepper_idle_lock_time; // If max value 255, steppers do not disable. 90 | uint8_t status_report_mask; // Mask to indicate desired report data. 91 | float junction_deviation; 92 | float arc_tolerance; 93 | 94 | float rpm_max; 95 | float rpm_min; 96 | 97 | uint8_t flags; // Contains default boolean settings 98 | 99 | uint8_t homing_dir_mask; 100 | float homing_feed_rate; 101 | float homing_seek_rate; 102 | uint16_t homing_debounce_delay; 103 | float homing_pulloff; 104 | } settings_t; 105 | extern settings_t settings; 106 | 107 | // Initialize the configuration subsystem (load settings from EEPROM) 108 | void settings_init(); 109 | 110 | // Helper function to clear and restore EEPROM defaults 111 | void settings_restore(uint8_t restore_flag); 112 | 113 | // A helper method to set new settings from command line 114 | uint8_t settings_store_global_setting(uint8_t parameter, float value); 115 | 116 | // Stores the protocol line variable as a startup line in EEPROM 117 | void settings_store_startup_line(uint8_t n, char *line); 118 | 119 | // Reads an EEPROM startup line to the protocol line variable 120 | uint8_t settings_read_startup_line(uint8_t n, char *line); 121 | 122 | // Stores build info user-defined string 123 | void settings_store_build_info(char *line); 124 | 125 | // Reads build info user-defined string 126 | uint8_t settings_read_build_info(char *line); 127 | 128 | // Writes selected coordinate data to EEPROM 129 | void settings_write_coord_data(uint8_t coord_select, float *coord_data); 130 | 131 | // Reads selected coordinate data from EEPROM 132 | uint8_t settings_read_coord_data(uint8_t coord_select, float *coord_data); 133 | 134 | // Returns the step pin mask according to Grbl's internal axis numbering 135 | uint8_t get_step_pin_mask(uint8_t i); 136 | 137 | // Returns the direction pin mask according to Grbl's internal axis numbering 138 | uint8_t get_direction_pin_mask(uint8_t i); 139 | 140 | // Returns the limit pin mask according to Grbl's internal axis numbering 141 | uint8_t get_limit_pin_mask(uint8_t i); 142 | 143 | 144 | #endif 145 | -------------------------------------------------------------------------------- /grbl/spindle_control.h: -------------------------------------------------------------------------------- 1 | /* 2 | spindle_control.h - spindle control methods 3 | Part of Grbl 4 | 5 | Copyright (c) 2012-2016 Sungeun K. Jeon for Gnea Research LLC 6 | Copyright (c) 2009-2011 Simen Svale Skogsrud 7 | 8 | Grbl is free software: you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License as published by 10 | the Free Software Foundation, either version 3 of the License, or 11 | (at your option) any later version. 12 | 13 | Grbl is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with Grbl. If not, see . 20 | */ 21 | 22 | #ifndef spindle_control_h 23 | #define spindle_control_h 24 | 25 | #define SPINDLE_NO_SYNC false 26 | #define SPINDLE_FORCE_SYNC true 27 | 28 | #define SPINDLE_STATE_DISABLE 0 // Must be zero. 29 | #define SPINDLE_STATE_CW bit(0) 30 | #define SPINDLE_STATE_CCW bit(1) 31 | 32 | 33 | // Initializes spindle pins and hardware PWM, if enabled. 34 | void spindle_init(); 35 | 36 | // Returns current spindle output state. Overrides may alter it from programmed states. 37 | uint8_t spindle_get_state(); 38 | 39 | // Called by g-code parser when setting spindle state and requires a buffer sync. 40 | // Immediately sets spindle running state with direction and spindle rpm via PWM, if enabled. 41 | // Called by spindle_sync() after sync and parking motion/spindle stop override during restore. 42 | #ifdef VARIABLE_SPINDLE 43 | 44 | // Called by g-code parser when setting spindle state and requires a buffer sync. 45 | void spindle_sync(uint8_t state, float rpm); 46 | 47 | // Sets spindle running state with direction, enable, and spindle PWM. 48 | void spindle_set_state(uint8_t state, float rpm); 49 | 50 | // Sets spindle PWM quickly for stepper ISR. Also called by spindle_set_state(). 51 | // NOTE: 328p PWM register is 8-bit. 52 | void spindle_set_speed(uint8_t pwm_value); 53 | 54 | // Computes 328p-specific PWM register value for the given RPM for quick updating. 55 | uint8_t spindle_compute_pwm_value(float rpm); 56 | 57 | #else 58 | 59 | // Called by g-code parser when setting spindle state and requires a buffer sync. 60 | #define spindle_sync(state, rpm) _spindle_sync(state) 61 | void _spindle_sync(uint8_t state); 62 | 63 | // Sets spindle running state with direction and enable. 64 | #define spindle_set_state(state, rpm) _spindle_set_state(state) 65 | void _spindle_set_state(uint8_t state); 66 | 67 | #endif 68 | 69 | // Stop and start spindle routines. Called by all spindle routines and stepper ISR. 70 | void spindle_stop(); 71 | 72 | 73 | #endif 74 | -------------------------------------------------------------------------------- /grbl/stepper.h: -------------------------------------------------------------------------------- 1 | /* 2 | stepper.h - stepper motor driver: executes motion plans of planner.c using the stepper motors 3 | Part of Grbl 4 | 5 | Copyright (c) 2011-2016 Sungeun K. Jeon for Gnea Research LLC 6 | Copyright (c) 2009-2011 Simen Svale Skogsrud 7 | 8 | Grbl is free software: you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License as published by 10 | the Free Software Foundation, either version 3 of the License, or 11 | (at your option) any later version. 12 | 13 | Grbl is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with Grbl. If not, see . 20 | */ 21 | 22 | #ifndef stepper_h 23 | #define stepper_h 24 | 25 | #ifndef SEGMENT_BUFFER_SIZE 26 | #define SEGMENT_BUFFER_SIZE 6 27 | #endif 28 | 29 | // Initialize and setup the stepper motor subsystem 30 | void stepper_init(); 31 | 32 | // Enable steppers, but cycle does not start unless called by motion control or realtime command. 33 | void st_wake_up(); 34 | 35 | // Immediately disables steppers 36 | void st_go_idle(); 37 | 38 | // Generate the step and direction port invert masks. 39 | void st_generate_step_dir_invert_masks(); 40 | 41 | // Reset the stepper subsystem variables 42 | void st_reset(); 43 | 44 | // Changes the run state of the step segment buffer to execute the special parking motion. 45 | void st_parking_setup_buffer(); 46 | 47 | // Restores the step segment buffer to the normal run state after a parking motion. 48 | void st_parking_restore_buffer(); 49 | 50 | // Reloads step segment buffer. Called continuously by realtime execution system. 51 | void st_prep_buffer(); 52 | 53 | // Called by planner_recalculate() when the executing block is updated by the new plan. 54 | void st_update_plan_block_parameters(); 55 | 56 | // Called by realtime status reporting if realtime rate reporting is enabled in config.h. 57 | float st_get_realtime_rate(); 58 | 59 | #endif 60 | --------------------------------------------------------------------------------