├── .gitignore
├── COPYING
├── Makefile
├── README.md
├── build
└── .gitignore
├── doc
├── 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
└── script
│ ├── simple_stream.py
│ └── stream.py
├── grbl
├── config.h
├── coolant_control.c
├── coolant_control.h
├── cpu_map.h
├── cpu_map
│ ├── cpu_map_atmega2560.h
│ ├── cpu_map_atmega328p.h
│ └── cpu_map_polargraph.h
├── defaults.h
├── defaults
│ ├── defaults_generic.h
│ ├── defaults_oxcnc.h
│ ├── defaults_polar.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
├── gcode.c
├── gcode.h
├── grbl.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
├── images
├── arduino
│ ├── arduinougs.png
│ └── arduinougs2.png
├── cncshield
│ ├── A4988-Stepper-Motor-Driver-Pinout.png
│ ├── Arduino-Nano-pinout-768x768.jpg
│ ├── board1.jpg
│ ├── boardbox.jpg
│ ├── cncshield.jpg
│ ├── cncshieldboard.png
│ ├── cncshieldfixwiring.png
│ ├── cncshieldsoldered.png
│ ├── parameters.png
│ ├── pinconnections.png
│ └── usefulgcodes.png
├── frame
│ ├── board.jpg
│ ├── gondola.jpg
│ ├── motormounted.jpg
│ ├── mount1.png
│ └── mount2.png
├── inkscapegcode
│ ├── inkscapesave.png
│ ├── inkscapesaveproperties1.png
│ ├── inkscapesaveproperties2.png
│ └── inkscapesaveproperties3.png
├── ugs.png
└── universalgcodesender
│ ├── connect.png
│ ├── ugsjog.png
│ ├── ugsmacros.png
│ ├── ugsmain.png
│ └── ugsparameters.png
└── sample_print_gcodes
├── beer_complex.gcode
├── beer_complex.svg
├── hamburger_complex.gcode
├── hamburger_complex.svg
├── hamburger_simple.gcode
└── hamburger_simple.svg
/.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-2015 Sungeun K. Jeon
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 \
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 | COMPILE = avr-gcc -Wall -Os -DF_CPU=$(CLOCK) -mmcu=$(DEVICE) -I. -ffunction-sections -fdata-sections
46 |
47 | OBJECTS = $(addprefix $(BUILDDIR)/,$(notdir $(SOURCE:.c=.o)))
48 |
49 | # symbolic targets:
50 | all: grbl.hex
51 |
52 | $(BUILDDIR)/%.o: $(SOURCEDIR)/%.c
53 | $(COMPILE) -MMD -MP -c $< -o $@
54 |
55 | .S.o:
56 | $(COMPILE) -x assembler-with-cpp -c $< -o $(BUILDDIR)/$@
57 | # "-x assembler-with-cpp" should not be necessary since this is the default
58 | # file type for the .S (with capital S) extension. However, upper case
59 | # characters are not always preserved on Windows. To ensure WinAVR
60 | # compatibility define the file type manually.
61 |
62 | #.c.s:
63 | $(COMPILE) -S $< -o $(BUILDDIR)/$@
64 |
65 | flash: all
66 | $(AVRDUDE) -U flash:w:grbl.hex:i
67 |
68 | fuse:
69 | $(AVRDUDE) $(FUSES)
70 |
71 | # Xcode uses the Makefile targets "", "clean" and "install"
72 | install: flash fuse
73 |
74 | # if you use a bootloader, change the command below appropriately:
75 | load: all
76 | bootloadHID grbl.hex
77 |
78 | clean:
79 | rm -f grbl.hex $(BUILDDIR)/*.o $(BUILDDIR)/*.d $(BUILDDIR)/*.elf
80 |
81 | # file targets:
82 | $(BUILDDIR)/main.elf: $(OBJECTS)
83 | $(COMPILE) -o $(BUILDDIR)/main.elf $(OBJECTS) -lm -Wl,--gc-sections
84 |
85 | grbl.hex: $(BUILDDIR)/main.elf
86 | rm -f grbl.hex
87 | avr-objcopy -j .text -j .data -O ihex $(BUILDDIR)/main.elf grbl.hex
88 | avr-size --format=berkeley $(BUILDDIR)/main.elf
89 | # If you have an EEPROM section, you must also create a hex file for the
90 | # EEPROM and add it to the "flash" target.
91 |
92 | # Targets for code debugging and analysis:
93 | disasm: main.elf
94 | avr-objdump -d $(BUILDDIR)/main.elf
95 |
96 | cpp:
97 | $(COMPILE) -E $(SOURCEDIR)/main.c
98 |
99 | # include generated header dependencies
100 | -include $(BUILDDIR)/$(OBJECTS:.o=.d)
101 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # GRBL - fork for Polargraph (wall draw bot)
2 |
3 |
4 | This code is a fork of GRBL, adding code to support wall draw bots based on some of ilaro's code changes.
5 | * Original GRBL: https://github.com/gnea/grbl
6 | * Ilaro's polar modifications used for some code: https://github.com/ilaro-org/grbl-polar
7 |
8 | Major changes to original GRBL
9 | * Coordinate system - drive motors with polargraph setup
10 | * Servo motor support (for pen)
11 | * No homing support
12 |
13 | You will need
14 | * A 3D printer (or someone who can print out a few parts)
15 | * Some soldering skills to fix the CNC board
16 | * Wires, screws
17 |
18 | # Hardware
19 |
20 | ## Mechanics
21 |
22 | ### Motor mounts
23 |
24 | * Motor mounts with motor and 20T gear
25 | * 3D model: [Polargraph / Vertical Plotter Spring Tensioned Motor Mount](https://www.thingiverse.com/thing:3440067)
26 | * Motor: NEMA17 1.8 degree motor, example eBay: "Nema 17 Stepper Motor 44Ncm 1.7A 38mm 12V 4-wire w/ 1m Cable for CNC 3D Printer"
27 |
28 |
29 |
30 |
31 | ### Gondola
32 |
33 | * Gondola with servo motor and pen
34 | * [Kritzlerbot Polargraph (printable)](https://www.thingiverse.com/thing:16692)
35 | * SG90 servo, example item: "Mini SG90 Micro Servo Motor 9G RC Robot Arm Helicopter Airplane Remote Control"
36 | * Servo extension cables
37 |
38 | * Belt (GT2)
39 | * Example eBay item: "GT2 6mm Timing Belt and 20 Teeth 5mm Bore Pulleys Prusa Reprap 3D printer part"
40 |
41 |
42 |
43 | ### Frame Assembled
44 |
45 |
46 |
47 | ## Electronics
48 |
49 | Components:
50 | * Arduino Nano (mini USB connector)
51 | * 12V Power supply unit (barrel), 2A minimum
52 | * CNC Shield V4
53 | * Beware of the bugs and quirks of the board
54 | * 2 x Stepper motor driver modules A4988
55 |
56 | ### CNC Shield
57 |
58 | The CNC Shield v4 board is a quick and cheap way to create a controller for the polargraph. However the documentation is buggy (lists the wrong pin connections) and the microstepping jumpers near modules are useless, they have to be removed and the MS1/2/3/ pins of modules have to be manually soldered.
59 | You can read more details below if you're curious:
60 | https://www.instructables.com/How-to-Use-the-CNC-V4-Board-despite-Its-quirks/
61 |
62 | We only need to populate the X and Y stepper axis modules on the board.
63 |
64 |
65 |
66 | Pinout:
67 | | Arduino Pin | Atmega port | Connected to |
68 | | ----- | ----- | ----- |
69 | | 2 | PD2 | Stepper X Direction
70 | | 3 | PD3 | Stepper Y Direction
71 | | 4 | PD4 | Stepper Z Direction (unused)
72 | | 5 | PD5 | Stepper X Step
73 | | 6 | PD6 | Stepper Y Step
74 | | 7 | PD7 | Stepper Z Step (unused)
75 | | 8 | PB0 | Stepper enable (all three modules)
76 | | 11| PB3 | Servo PWM signal
77 |
78 | Atmega ports are only for reference if you want to match it up with cpu_map_polargraph.h
79 |
80 |
81 |
82 | You might need to adjust the A4988 servo driver board motor current with the small potentiometer, there are [instructions on how to do this](https://www.the-diy-life.com/how-to-correctly-set-the-motor-current-limit-on-an-a4988-stepper-motor-driver/).
83 |
84 | ## Firmware
85 |
86 | GRBL firmware loading onto Arduino Nano
87 |
88 | 1. Copy the GRBL library:
89 | * From the source tree\grbl
90 | * To the arduino library folder, on windows this is User home\Documents\Arduino\libraries\grbl
91 | * You should see files in that folder like config.h, cpu_map.h, etc.
92 | 2. Restart Arduino IDE
93 | 3. Open File -> Examples -> grbl -> grplUpload
94 | * This will load the grbl upload sketch
95 | 4. Make sure the board is configured, Tools -> Board
96 | * Board: Arduino Nano
97 | * Processor: Atmega328P - if you have a clone you might need (Old Bootloader)
98 | * Port: COM6 - or whatever your port is
99 | 5. Press upload, this will compile the source code and upload it to the Arduino Nano.
100 | 
101 | 6. You are done. You can optionally open the Arduino Serial Console (icon/menu), make sure speed is set to 115200 and you should see the boot up text: "Grbl" appearing.
102 |
103 | # Software (PC)
104 |
105 | ## Universal G-Code Sender
106 |
107 | Download UGS from: https://winder.github.io/ugs_website/
108 |
109 | Then start bin\ugsplatform64.exe (on Windows)
110 |
111 | 
112 |
113 | Sample g-code files can be found in the source tree for testing:
114 |
115 | * sample_print_gcodes/hamburger_complex.gcode - [Complex hamburger gcode file](sample_print_gcodes/hamburger_complex.gcode)
116 | * sample_print_gcodes/hamburger_simple.gcode - [Simple hamburger gcode file](sample_print_gcodes/hamburger_simple.gcode)
117 |
118 | ### Quickstarter for UGS:
119 |
120 | 1. Select the COM port, baud on top and press the Connect icon (to the left)
121 | 
122 | 2. This will connect and show you the GRBL version and current parameters.
123 | 
124 | * Check parameters, especially \$28, \$29 (width of your board in millimeters, vertical home distance).
125 | * Check the steps/millimeters settings (\$100,\$101)
126 | * If (some of the) motors are going the wrong way when you move around (Y+/Y-) then you can either turn the cable connected to the CNC board or use \$3 to invert directions
127 | 3. Make sure the Gondola is in the middle top position (home position), adjust belts manually. On my printer this is X=370 (mm), Y=60 (mm), but this varies. X is always half of the width distance (\$28), Y is \$29
128 | 4. Try to move the gondola around using the Jog controls. Set Step size XY to 10 millimeters.
129 | 
130 | * When you press Y+ the gondola should move down
131 | * If the gondola moves up, both motors need direction reversing
132 | * If the gondola moves left or right, one motor direction needs reversing
133 | * When you press X- the gondola should move left and right for X+
134 | 5. Move the gondola somewhat down and optionally a bit left, then issue the "set home here" command in the Console window prompt
135 | `G92 X0 Y0`
136 | 6. Load the sample gcode with the file open icon (top left in UGS)
137 | * Once this is done, you will see the gcode appear (top middle in UGS) and the image preview (top right)
138 | 7. Press "Play" icon on the top toolbar to start sending of the loaded gcode image. This will start the printing.
139 | 8. Once it is finished, you can issue the "reset gcode offset to original" command in the console:
140 | `G92.1`
141 | 9. Now you can move around more and print more, but remember to always send the home (G92 X0 Y0) and then reset it (G92.1) when finished.
142 |
143 |
144 | ## Configuration of GRBL parameters
145 |
146 | Connect to the cnc module from Universal G-Code Sender with the appropriate port (eg. COM6). In the console window on the bottom:
147 |
148 | * Enter $$ to list all parameters stored in EEPROM
149 | * Change the following parameters - if needed
150 |
151 | Parameter summary
152 | | Param | Value | Description |
153 | | --- | --- | --- |
154 | | $100 | 80 | steps/mm (X), for 20 tooth gear and 16 microsteps with GT2 betlt it's 80
155 | | $101 | 80 | steps/mm (X), for 20 tooth gear and 16 microsteps with GT2
156 | | $3 | 0 | Invert motors mask. If stepper X is going in wrong direction, set value=1, if stepper Y then set value=2, if both set value=3. Or you could just turn the board connector around
157 | | $28 | 740 | Distance (horizontal) between two motors (gears) in millimeters
158 | | $29 | 60 | Distance (vertical) when gondola is homed from the top (millimeters)
159 |
160 | Useful g-codes
161 |
162 | | G-Code | Description |
163 | | --------- | --- |
164 | | M03 S310 | Pen up, move servo to 310 degrees (you might have different value for degrees) |
165 | | M03 S100 | Pen down (100 degrees) |
166 | | G92 X0 Y0 | Set an offset in all coordinate systems, sets the current position to be (0,0) |
167 | | G92.1 | Reset the offset to the original system |
168 |
169 | ## Inkscape
170 |
171 | Inkscape export to g-code:
172 |
173 | * Documentation on how to [use Inkscape to Generate Gcode](https://wiki.opensourceecology.org/wiki/Using_Inkscape_to_Generate_Gcode)
174 | * Install GcodePlot plugin
175 | * File > Save As, 3-axis gcode plotter...
176 | * Change any properies as needed. Make sure to set the Cutting settings -> Lift and Down commands to the pen up/pen down gcode values
177 | * You will need to edit the saved .gcode file manually to remove all lines before the first "M03 S310" because the previous lines would do positioning and homing, we don't need that. Alternatively you can find the plugin python source code and comment out these lines so save doesn't generate them.
178 |
179 |
180 |
181 |
182 |
183 |
184 |
185 |
--------------------------------------------------------------------------------
/build/.gitignore:
--------------------------------------------------------------------------------
1 | # Ignore everything in this directory
2 | *
3 | # Except this file
4 | !.gitignore
--------------------------------------------------------------------------------
/doc/log/commit_log_v0.9j.txt:
--------------------------------------------------------------------------------
1 | ----------------
2 | Date: 2016-07-26
3 | Author: chamnit
4 | Subject: Fixed homing on CoreXY machines only.
5 |
6 | - The homing routine for CoreXY/H-Bot CNC machines has been fixed.
7 |
8 | - Version date bumped, but this update does NOT effect any normal
9 | users. Only CoreXY users.
10 |
11 |
12 | ----------------
13 | Date: 2016-07-26
14 | Author: chamnit
15 | Subject: Merge branch 'master-corexy'
16 |
17 |
18 | ----------------
19 | Date: 2016-07-25
20 | Author: chamnit
21 | Subject: CoreXY homing bug fix attempt 2.
22 |
23 |
24 | ----------------
25 | Date: 2016-07-25
26 | Author: chamnit
27 | Subject: CoreXY homing fix attempt.
28 |
29 |
30 | ----------------
31 | Date: 2016-03-17
32 | Author: Sonny Jeon
33 | Subject: No variable spindle and spindle speed fix.
34 |
35 | - When VARIABLE_SPINDLE output is disabled in config.h, the last commit
36 | would keep the spindle enable pin disabled when spindle speed is not
37 | defined (S0). This is now ignored and will enable with S0, as spindle
38 | speed is ignored in this mode.
39 |
40 |
41 | ----------------
42 | Date: 2016-03-16
43 | Author: Sonny Jeon
44 | Subject: Soft limit handling bug fix
45 |
46 | - Soft limit errors were stuck in a feed hold without notifying the
47 | user why it was in a hold. When resumed, the soft limit error would
48 | kick in. Issue should be fixed to behave as intended to automatically
49 | hold and issue a soft limit alarm once the machine has come to a stop.
50 |
51 |
52 | ----------------
53 | Date: 2016-03-03
54 | Author: Sonny Jeon
55 | Subject: Bug fixes and more limit configurability
56 |
57 | - Strange sizeof() bug in the most recent releases. Manifested as an
58 | alarm upon a power up even when homing was disabled. Fixed by declaring
59 | sizeof() with struct types, rather than variable names, even though
60 | they were validated to give the same value.
61 |
62 | - Spindle speed zero should disable the spindle. Now fixed.
63 |
64 | - New configuration option for inverting certain limit pins. Handy for
65 | mixed NO and NC switch machines. See config.h for details.
66 |
67 | - Incremented version and pre-build firmware link.
68 |
69 |
70 | ----------------
71 | Date: 2015-12-18
72 | Author: Sonny Jeon
73 | Subject: Minor bug fixes.
74 |
75 | - Planner was under-estimating maximum speeds through straight
76 | junctions in certain cases. The calculations have been updated to be
77 | more accurate.
78 |
79 | - Type declaration fix in probe.c.
80 |
81 | - Commit log for v0.9j generated separately from v0.9i’s.
82 |
83 | - Incremented version and updated pre-built firmware link.
84 |
85 |
86 | ----------------
87 | Date: 2015-09-30
88 | Author: Sonny Jeon
89 | Subject: Minor bug fixes.
90 |
91 | - G38.x was not printing correctly in the $G g-code state reports. Now
92 | fixed.
93 |
94 | - Potential bug regarding volatile variables inside a struct. It has
95 | never been a problem in v0.9, but ran into this during v1.0
96 | development. Just to be safe, the fixes are applied here.
97 |
98 | - Updated pre-built firmwares with these two bug fixes.
99 |
100 |
101 | ----------------
102 | Date: 2015-08-16
103 | Author: Sonny Jeon
104 | Subject: Update README.md
105 |
106 | ----------------
107 | Date: 2015-08-14
108 | Author: Sonny Jeon
109 | Subject: Individual control pin invert compile-option.
110 |
111 | - Control pins may be individually inverted through a
112 | CONTROL_INVERT_MASK macro. This mask is define in the cpu_map.h file.
113 |
114 |
115 | ----------------
116 | Date: 2015-07-17
117 | Author: Sonny Jeon
118 | Subject: Version bump to v0.9j
119 |
120 | - Version bump requested by OEMs to easily determine whether the
121 | firmware supports the new EEPROM reset feature. Other than that, no
122 | significant changes.
123 |
124 |
--------------------------------------------------------------------------------
/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 | - 20140714: Updated baud rate to 115200. Added a settings
15 | write mode via simple streaming method. MIT-licensed.
16 |
17 | TODO:
18 | - Add runtime command capabilities
19 |
20 | ---------------------
21 | The MIT License (MIT)
22 |
23 | Copyright (c) 2012-2014 Sungeun K. Jeon
24 |
25 | Permission is hereby granted, free of charge, to any person obtaining a copy
26 | of this software and associated documentation files (the "Software"), to deal
27 | in the Software without restriction, including without limitation the rights
28 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
29 | copies of the Software, and to permit persons to whom the Software is
30 | furnished to do so, subject to the following conditions:
31 |
32 | The above copyright notice and this permission notice shall be included in
33 | all copies or substantial portions of the Software.
34 |
35 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
36 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
37 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
38 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
39 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
40 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
41 | THE SOFTWARE.
42 | ---------------------
43 | """
44 |
45 | import serial
46 | import re
47 | import time
48 | import sys
49 | import argparse
50 | # import threading
51 |
52 | RX_BUFFER_SIZE = 128
53 |
54 | # Define command line argument interface
55 | parser = argparse.ArgumentParser(description='Stream g-code file to grbl. (pySerial and argparse libraries required)')
56 | parser.add_argument('gcode_file', type=argparse.FileType('r'),
57 | help='g-code filename to be streamed')
58 | parser.add_argument('device_file',
59 | help='serial device path')
60 | parser.add_argument('-q','--quiet',action='store_true', default=False,
61 | help='suppress output text')
62 | parser.add_argument('-s','--settings',action='store_true', default=False,
63 | help='settings write mode')
64 | args = parser.parse_args()
65 |
66 | # Periodic timer to query for status reports
67 | # TODO: Need to track down why this doesn't restart consistently before a release.
68 | # def periodic():
69 | # s.write('?')
70 | # t = threading.Timer(0.1, periodic) # In seconds
71 | # t.start()
72 |
73 | # Initialize
74 | s = serial.Serial(args.device_file,115200)
75 | f = args.gcode_file
76 | verbose = True
77 | if args.quiet : verbose = False
78 | settings_mode = False
79 | if args.settings : settings_mode = True
80 |
81 | # Wake up grbl
82 | print "Initializing grbl..."
83 | s.write("\r\n\r\n")
84 |
85 | # Wait for grbl to initialize and flush startup text in serial input
86 | time.sleep(2)
87 | s.flushInput()
88 |
89 | # Stream g-code to grbl
90 | l_count = 0
91 | if settings_mode:
92 | # Send settings file via simple call-response streaming method. Settings must be streamed
93 | # in this manner since the EEPROM accessing cycles shut-off the serial interrupt.
94 | print "SETTINGS MODE: Streaming", args.gcode_file.name, " to ", args.device_file
95 | for line in f:
96 | l_count += 1 # Iterate line counter
97 | # l_block = re.sub('\s|\(.*?\)','',line).upper() # Strip comments/spaces/new line and capitalize
98 | l_block = line.strip() # Strip all EOL characters for consistency
99 | if verbose: print 'SND: ' + str(l_count) + ':' + l_block,
100 | s.write(l_block + '\n') # Send g-code block to grbl
101 | grbl_out = s.readline().strip() # Wait for grbl response with carriage return
102 | if verbose: print 'REC:',grbl_out
103 | else:
104 | # Send g-code program via a more agressive streaming protocol that forces characters into
105 | # Grbl's serial read buffer to ensure Grbl has immediate access to the next g-code command
106 | # rather than wait for the call-response serial protocol to finish. This is done by careful
107 | # counting of the number of characters sent by the streamer to Grbl and tracking Grbl's
108 | # responses, such that we never overflow Grbl's serial read buffer.
109 | g_count = 0
110 | c_line = []
111 | # periodic() # Start status report periodic timer
112 | for line in f:
113 | l_count += 1 # Iterate line counter
114 | # l_block = re.sub('\s|\(.*?\)','',line).upper() # Strip comments/spaces/new line and capitalize
115 | l_block = line.strip()
116 | c_line.append(len(l_block)+1) # Track number of characters in grbl serial read buffer
117 | grbl_out = ''
118 | while sum(c_line) >= RX_BUFFER_SIZE-1 | s.inWaiting() :
119 | out_temp = s.readline().strip() # Wait for grbl response
120 | if out_temp.find('ok') < 0 and out_temp.find('error') < 0 :
121 | print " Debug: ",out_temp # Debug response
122 | else :
123 | grbl_out += out_temp;
124 | g_count += 1 # Iterate g-code counter
125 | grbl_out += str(g_count); # Add line finished indicator
126 | del c_line[0] # Delete the block character count corresponding to the last 'ok'
127 | if verbose: print "SND: " + str(l_count) + " : " + l_block,
128 | s.write(l_block + '\n') # Send g-code block to grbl
129 | if verbose : print "BUF:",str(sum(c_line)),"REC:",grbl_out
130 |
131 | # Wait for user input after streaming is completed
132 | print "G-code streaming finished!\n"
133 | print "WARNING: Wait until grbl completes buffered g-code blocks before exiting."
134 | raw_input(" Press to exit and disable grbl.")
135 |
136 | # Close file and serial port
137 | f.close()
138 | s.close()
--------------------------------------------------------------------------------
/grbl/coolant_control.c:
--------------------------------------------------------------------------------
1 | /*
2 | coolant_control.c - coolant control methods
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 | #include "grbl.h"
22 |
23 |
24 | void coolant_init()
25 | {
26 | COOLANT_FLOOD_DDR |= (1 << COOLANT_FLOOD_BIT);
27 | #ifdef ENABLE_M7
28 | COOLANT_MIST_DDR |= (1 << COOLANT_MIST_BIT);
29 | #endif
30 | coolant_stop();
31 | }
32 |
33 |
34 | void coolant_stop()
35 | {
36 | COOLANT_FLOOD_PORT &= ~(1 << COOLANT_FLOOD_BIT);
37 | #ifdef ENABLE_M7
38 | COOLANT_MIST_PORT &= ~(1 << COOLANT_MIST_BIT);
39 | #endif
40 | }
41 |
42 |
43 | void coolant_set_state(uint8_t mode)
44 | {
45 | if (mode == COOLANT_FLOOD_ENABLE) {
46 | COOLANT_FLOOD_PORT |= (1 << COOLANT_FLOOD_BIT);
47 |
48 | #ifdef ENABLE_M7
49 | } else if (mode == COOLANT_MIST_ENABLE) {
50 | COOLANT_MIST_PORT |= (1 << COOLANT_MIST_BIT);
51 | #endif
52 |
53 | } else {
54 | coolant_stop();
55 | }
56 | }
57 |
58 |
59 | void coolant_run(uint8_t mode)
60 | {
61 | if (sys.state == STATE_CHECK_MODE) { return; }
62 | protocol_buffer_synchronize(); // Ensure coolant turns on when specified in program.
63 | coolant_set_state(mode);
64 | }
65 |
--------------------------------------------------------------------------------
/grbl/coolant_control.h:
--------------------------------------------------------------------------------
1 | /*
2 | coolant_control.h - spindle control methods
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 | #ifndef coolant_control_h
22 | #define coolant_control_h
23 |
24 |
25 | void coolant_init();
26 | void coolant_stop();
27 | void coolant_set_state(uint8_t mode);
28 | void coolant_run(uint8_t mode);
29 |
30 | #endif
--------------------------------------------------------------------------------
/grbl/cpu_map.h:
--------------------------------------------------------------------------------
1 | /*
2 | cpu_map.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 | /* The cpu_map.h files serve as a central pin mapping selection file for different processor
22 | types, i.e. AVR 328p or AVR Mega 2560. Each processor has its own pin mapping file.
23 | (i.e. cpu_map_atmega328p.h) Grbl officially supports the Arduino Uno, but the
24 | other supplied pin mappings are supplied by users, so your results may vary. */
25 |
26 | // NOTE: With new processors, only add the define name and filename to use.
27 |
28 | #ifndef cpu_map_h
29 | #define cpu_map_h
30 |
31 |
32 | #ifdef CPU_MAP_ATMEGA328P // (Arduino Uno) Officially supported by Grbl.
33 | #include "cpu_map/cpu_map_atmega328p.h"
34 | #endif
35 |
36 | #ifdef CPU_MAP_ATMEGA2560 // (Arduino Mega 2560) Working @EliteEng
37 | #include "cpu_map/cpu_map_atmega2560.h"
38 | #endif
39 |
40 | #ifdef CPU_MAP_POLARGRAPH // Polargraph CNC Shield V4
41 | #include "cpu_map/cpu_map_polargraph.h"
42 | #endif
43 |
44 |
45 | /*
46 | #ifdef CPU_MAP_CUSTOM_PROC
47 | // For a custom pin map or different processor, copy and edit one of the available cpu
48 | // map files and modify it to your needs. Make sure the defined name is also changed in
49 | // the config.h file.
50 | #endif
51 | */
52 |
53 | #endif
54 |
--------------------------------------------------------------------------------
/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 | /* Grbl officially supports the Arduino Uno, but the other supplied pin mappings are
22 | supplied by users, so your results may vary. This cpu_map file serves as a central
23 | pin mapping settings file for AVR 328p used on the Arduino Uno. */
24 |
25 | #ifdef GRBL_PLATFORM
26 | #error "cpu_map already defined: GRBL_PLATFORM=" GRBL_PLATFORM
27 | #endif
28 |
29 |
30 | #define GRBL_PLATFORM "Atmega328p"
31 |
32 | // Define serial port pins and interrupt vectors.
33 | #define SERIAL_RX USART_RX_vect
34 | #define SERIAL_UDRE USART_UDRE_vect
35 |
36 | // Define step pulse output pins. NOTE: All step bit pins must be on the same port.
37 | #define STEP_DDR DDRD
38 | #define STEP_PORT PORTD
39 | #define X_STEP_BIT 2 // Uno Digital Pin 2
40 | #define Y_STEP_BIT 3 // Uno Digital Pin 3
41 | #define Z_STEP_BIT 4 // Uno Digital Pin 4
42 | #define STEP_MASK ((1<.
19 | */
20 |
21 | /* Grbl officially supports the Arduino Uno, but the other supplied pin mappings are
22 | supplied by users, so your results may vary. This cpu_map file serves as a central
23 | pin mapping settings file for AVR 328p used on the Arduino Uno. */
24 |
25 | #ifdef GRBL_PLATFORM
26 | #error "cpu_map already defined: GRBL_PLATFORM=" GRBL_PLATFORM
27 | #endif
28 |
29 |
30 | #define GRBL_PLATFORM "Atmega328p"
31 |
32 | // Define serial port pins and interrupt vectors.
33 | #define SERIAL_RX USART_RX_vect
34 | #define SERIAL_UDRE USART_UDRE_vect
35 |
36 | // Define step pulse output pins. NOTE: All step bit pins must be on the same port.
37 | #define STEP_DDR DDRD
38 | #define STEP_PORT PORTD
39 | #define X_STEP_BIT 5 // Uno Digital Pin 2
40 | #define Y_STEP_BIT 6 // Uno Digital Pin 3
41 | #define Z_STEP_BIT 7 // Uno Digital Pin 4
42 | #define STEP_MASK ((1<.
19 | */
20 |
21 | /* The defaults.h file serves as a central default settings selector for different machine
22 | types, from DIY CNC mills to CNC conversions of off-the-shelf machines. The settings
23 | files listed here are supplied by users, so your results may vary. However, this should
24 | give you a good starting point as you get to know your machine and tweak the settings for
25 | your nefarious needs.
26 | Ensure one and only one of these DEFAULTS_XXX values is defined in config.h */
27 |
28 | #ifndef defaults_h
29 |
30 | // Only define the DEFAULT_XXX with where to find the corresponding default_XXX.h file.
31 | // Don't #define defaults_h here, let the selected file do it. Prevents including more than one.
32 |
33 | #ifdef DEFAULTS_POLAR
34 | // Grbl generic default settings. Should work across different machines.
35 | #include "defaults/defaults_polar.h"
36 | #endif
37 |
38 | #ifdef DEFAULTS_GENERIC
39 | // Grbl generic default settings. Should work across different machines.
40 | #include "defaults/defaults_generic.h"
41 | #endif
42 |
43 | #ifdef DEFAULTS_SHERLINE_5400
44 | // Description: Sherline 5400 mill with three NEMA 23 Keling KL23H256-21-8B 185 oz-in stepper motors,
45 | // driven by three Pololu A4988 stepper drivers with a 30V, 6A power supply at 1.5A per winding.
46 | #include "defaults/defaults_sherline.h"
47 | #endif
48 |
49 | #ifdef DEFAULTS_SHAPEOKO
50 | // Description: Shapeoko CNC mill with three NEMA 17 stepper motors, driven by Synthetos
51 | // grblShield with a 24V, 4.2A power supply.
52 | #include "defaults/defaults_shapeoko.h"
53 | #endif
54 |
55 | #ifdef DEFAULTS_SHAPEOKO_2
56 | // Description: Shapeoko CNC mill with three NEMA 17 stepper motors, driven by Synthetos
57 | // grblShield at 28V.
58 | #include "defaults/defaults_shapeoko2.h"
59 | #endif
60 |
61 | #ifdef DEFAULTS_SHAPEOKO_3
62 | // Description: Shapeoko CNC mill with three NEMA 23 stepper motors, driven by CarbideMotion
63 | #include "defaults/defaults_shapeoko3.h"
64 | #endif
65 |
66 | #ifdef DEFAULTS_X_CARVE_500MM
67 | // Description: X-Carve 3D Carver CNC mill with three 200 step/rev motors driven by Synthetos
68 | // grblShield at 24V.
69 | #include "defaults/defaults_x_carve_500mm.h"
70 | #endif
71 |
72 | #ifdef DEFAULTS_X_CARVE_1000MM
73 | // Description: X-Carve 3D Carver CNC mill with three 200 step/rev motors driven by Synthetos
74 | // grblShield at 24V.
75 | #include "defaults/defaults_x_carve_1000mm.h"
76 | #endif
77 |
78 | #ifdef DEFAULTS_ZEN_TOOLWORKS_7x7
79 | // Description: Zen Toolworks 7x7 mill with three Shinano SST43D2121 65oz-in NEMA 17 stepper motors.
80 | // Leadscrew is different from some ZTW kits, where most are 1.25mm/rev rather than 8.0mm/rev here.
81 | // Driven by 30V, 6A power supply and TI DRV8811 stepper motor drivers.
82 | #include "defaults/defaults_zen_toolworks_7x7.h"
83 | #endif
84 |
85 | #ifdef DEFAULTS_OXCNC
86 | // Grbl settings for OpenBuilds OX CNC Machine
87 | // http://www.openbuilds.com/builds/openbuilds-ox-cnc-machine.341/
88 | #include "defaults/defaults_oxcnc.h"
89 | #endif
90 |
91 | #ifdef DEFAULTS_SIMULATOR
92 | // Settings only for Grbl Simulator (www.github.com/grbl/grbl-sim)
93 | #include "defaults/defaults_simulator.h"
94 | #endif
95 |
96 | #endif
97 |
--------------------------------------------------------------------------------
/grbl/defaults/defaults_generic.h:
--------------------------------------------------------------------------------
1 | /*
2 | defaults_generic.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 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_polar.h:
--------------------------------------------------------------------------------
1 | /*
2 | defaults_polar.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 generic default settings. Should work across different machines.
31 | // Steps/mm calculator: https://zalophusdokdo.github.io/StepperMotorsCalculator/en/index.html
32 | #define DEFAULT_X_STEPS_PER_MM 80 // 20 tooth, GT2, 16 microstepping -> 80 steps/mm
33 | #define DEFAULT_Y_STEPS_PER_MM 80
34 | #define DEFAULT_Z_STEPS_PER_MM 250.0
35 | #define DEFAULT_X_MAX_RATE 5000.0 // mm/min
36 | #define DEFAULT_Y_MAX_RATE 5000.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 2000.0 // mm
42 | #define DEFAULT_Y_MAX_TRAVEL 2000.0 // mm
43 | #define DEFAULT_Z_MAX_TRAVEL 200.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 0 // 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 5000.0 // mm/min
60 | #define DEFAULT_HOMING_DEBOUNCE_DELAY 250 // msec (0-65k)
61 | #define DEFAULT_HOMING_PULLOFF 1.0 // mm
62 | #define DEFAULT_X_OFFSET 300.0 // mm
63 | #define DEFAULT_Y_OFFSET 0.0 // mm
64 | #define DEFAULT_Z_OFFSET 200.0 // mm
65 | #define DEFAULT_DISTANCE 740.0 // mm - horizontal distance between Polargraph motor gear centers
66 | #define DEFAULT_HOMING_VERTICAL_DISTANCE 60 // mm - vertical distance of manually homed gondola in the middle
67 |
68 | #endif
--------------------------------------------------------------------------------
/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/gcode.h:
--------------------------------------------------------------------------------
1 | /*
2 | gcode.h - rs274/ngc parser.
3 | Part of Grbl
4 |
5 | Copyright (c) 2011-2015 Sungeun K. Jeon
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 gcode_h
23 | #define gcode_h
24 |
25 |
26 | // Define modal group internal numbers for checking multiple command violations and tracking the
27 | // type of command that is called in the block. A modal group is a group of g-code commands that are
28 | // mutually exclusive, or cannot exist on the same line, because they each toggle a state or execute
29 | // a unique motion. These are defined in the NIST RS274-NGC v3 g-code standard, available online,
30 | // and are similar/identical to other g-code interpreters by manufacturers (Haas,Fanuc,Mazak,etc).
31 | // NOTE: Modal group define values must be sequential and starting from zero.
32 | #define MODAL_GROUP_G0 0 // [G4,G10,G28,G28.1,G30,G30.1,G53,G92,G92.1] Non-modal
33 | #define MODAL_GROUP_G1 1 // [G0,G1,G2,G3,G38.2,G38.3,G38.4,G38.5,G80] Motion
34 | #define MODAL_GROUP_G2 2 // [G17,G18,G19] Plane selection
35 | #define MODAL_GROUP_G3 3 // [G90,G91] Distance mode
36 | #define MODAL_GROUP_G4 4 // [G91.1] Arc IJK distance mode
37 | #define MODAL_GROUP_G5 5 // [G93,G94] Feed rate mode
38 | #define MODAL_GROUP_G6 6 // [G20,G21] Units
39 | #define MODAL_GROUP_G7 7 // [G40] Cutter radius compensation mode. G41/42 NOT SUPPORTED.
40 | #define MODAL_GROUP_G8 8 // [G43.1,G49] Tool length offset
41 | #define MODAL_GROUP_G12 9 // [G54,G55,G56,G57,G58,G59] Coordinate system selection
42 | #define MODAL_GROUP_G13 10 // [G61] Control mode
43 |
44 | #define MODAL_GROUP_M4 11 // [M0,M1,M2,M30] Stopping
45 | #define MODAL_GROUP_M7 12 // [M3,M4,M5] Spindle turning
46 | #define MODAL_GROUP_M8 13 // [M7,M8,M9] Coolant control
47 |
48 | // #define OTHER_INPUT_F 14
49 | // #define OTHER_INPUT_S 15
50 | // #define OTHER_INPUT_T 16
51 |
52 | // Define command actions for within execution-type modal groups (motion, stopping, non-modal). Used
53 | // internally by the parser to know which command to execute.
54 |
55 | // Modal Group G0: Non-modal actions
56 | #define NON_MODAL_NO_ACTION 0 // (Default: Must be zero)
57 | #define NON_MODAL_DWELL 1 // G4
58 | #define NON_MODAL_SET_COORDINATE_DATA 2 // G10
59 | #define NON_MODAL_GO_HOME_0 3 // G28
60 | #define NON_MODAL_SET_HOME_0 4 // G28.1
61 | #define NON_MODAL_GO_HOME_1 5 // G30
62 | #define NON_MODAL_SET_HOME_1 6 // G30.1
63 | #define NON_MODAL_ABSOLUTE_OVERRIDE 7 // G53
64 | #define NON_MODAL_SET_COORDINATE_OFFSET 8 // G92
65 | #define NON_MODAL_RESET_COORDINATE_OFFSET 9 //G92.1
66 |
67 | // Modal Group G1: Motion modes
68 | #define MOTION_MODE_SEEK 0 // G0 (Default: Must be zero)
69 | #define MOTION_MODE_LINEAR 1 // G1
70 | #define MOTION_MODE_CW_ARC 2 // G2
71 | #define MOTION_MODE_CCW_ARC 3 // G3
72 | #define MOTION_MODE_PROBE_TOWARD 4 // G38.2 NOTE: G38.2, G38.3, G38.4, G38.5 must be sequential. See report_gcode_modes().
73 | #define MOTION_MODE_PROBE_TOWARD_NO_ERROR 5 // G38.3
74 | #define MOTION_MODE_PROBE_AWAY 6 // G38.4
75 | #define MOTION_MODE_PROBE_AWAY_NO_ERROR 7 // G38.5
76 | #define MOTION_MODE_NONE 8 // G80
77 |
78 | // Modal Group G2: Plane select
79 | #define PLANE_SELECT_XY 0 // G17 (Default: Must be zero)
80 | #define PLANE_SELECT_ZX 1 // G18
81 | #define PLANE_SELECT_YZ 2 // G19
82 |
83 | // Modal Group G3: Distance mode
84 | #define DISTANCE_MODE_ABSOLUTE 0 // G90 (Default: Must be zero)
85 | #define DISTANCE_MODE_INCREMENTAL 1 // G91
86 |
87 | // Modal Group G4: Arc IJK distance mode
88 | #define DISTANCE_ARC_MODE_INCREMENTAL 0 // G91.1 (Default: Must be zero)
89 |
90 | // Modal Group M4: Program flow
91 | #define PROGRAM_FLOW_RUNNING 0 // (Default: Must be zero)
92 | #define PROGRAM_FLOW_PAUSED 1 // M0, M1
93 | #define PROGRAM_FLOW_COMPLETED 2 // M2, M30
94 |
95 | // Modal Group G5: Feed rate mode
96 | #define FEED_RATE_MODE_UNITS_PER_MIN 0 // G94 (Default: Must be zero)
97 | #define FEED_RATE_MODE_INVERSE_TIME 1 // G93
98 |
99 | // Modal Group G6: Units mode
100 | #define UNITS_MODE_MM 0 // G21 (Default: Must be zero)
101 | #define UNITS_MODE_INCHES 1 // G20
102 |
103 | // Modal Group G7: Cutter radius compensation mode
104 | #define CUTTER_COMP_DISABLE 0 // G40 (Default: Must be zero)
105 |
106 | // Modal Group G13: Control mode
107 | #define CONTROL_MODE_EXACT_PATH 0 // G61 (Default: Must be zero)
108 |
109 | // Modal Group M7: Spindle control
110 | #define SPINDLE_DISABLE 0 // M5 (Default: Must be zero)
111 | #define SPINDLE_ENABLE_CW 1 // M3
112 | #define SPINDLE_ENABLE_CCW 2 // M4
113 |
114 | // Modal Group M8: Coolant control
115 | #define COOLANT_DISABLE 0 // M9 (Default: Must be zero)
116 | #define COOLANT_MIST_ENABLE 1 // M7
117 | #define COOLANT_FLOOD_ENABLE 2 // M8
118 |
119 | // Modal Group G8: Tool length offset
120 | #define TOOL_LENGTH_OFFSET_CANCEL 0 // G49 (Default: Must be zero)
121 | #define TOOL_LENGTH_OFFSET_ENABLE_DYNAMIC 1 // G43.1
122 |
123 | // Modal Group G12: Active work coordinate system
124 | // N/A: Stores coordinate system value (54-59) to change to.
125 |
126 |
127 | // Define parameter word mapping.
128 | #define WORD_F 0
129 | #define WORD_I 1
130 | #define WORD_J 2
131 | #define WORD_K 3
132 | #define WORD_L 4
133 | #define WORD_N 5
134 | #define WORD_P 6
135 | #define WORD_R 7
136 | #define WORD_S 8
137 | #define WORD_T 9
138 | #define WORD_X 10
139 | #define WORD_Y 11
140 | #define WORD_Z 12
141 |
142 |
143 | // NOTE: When this struct is zeroed, the above defines set the defaults for the system.
144 | typedef struct {
145 | uint8_t motion; // {G0,G1,G2,G3,G38.2,G80}
146 | uint8_t feed_rate; // {G93,G94}
147 | uint8_t units; // {G20,G21}
148 | uint8_t distance; // {G90,G91}
149 | // uint8_t distance_arc; // {G91.1} NOTE: Don't track. Only default supported.
150 | uint8_t plane_select; // {G17,G18,G19}
151 | // uint8_t cutter_comp; // {G40} NOTE: Don't track. Only default supported.
152 | uint8_t tool_length; // {G43.1,G49}
153 | uint8_t coord_select; // {G54,G55,G56,G57,G58,G59}
154 | // uint8_t control; // {G61} NOTE: Don't track. Only default supported.
155 | uint8_t program_flow; // {M0,M1,M2,M30}
156 | uint8_t coolant; // {M7,M8,M9}
157 | uint8_t spindle; // {M3,M4,M5}
158 | } gc_modal_t;
159 |
160 | typedef struct {
161 | float f; // Feed
162 | float ijk[3]; // I,J,K Axis arc offsets
163 | uint8_t l; // G10 or canned cycles parameters
164 | int32_t n; // Line number
165 | float p; // G10 or dwell parameters
166 | // float q; // G82 peck drilling
167 | float r; // Arc radius
168 | float s; // Spindle speed
169 | uint8_t t; // Tool selection
170 | float xyz[3]; // X,Y,Z Translational axes
171 | } gc_values_t;
172 |
173 |
174 | typedef struct {
175 | gc_modal_t modal;
176 |
177 | float spindle_speed; // RPM
178 | float feed_rate; // Millimeters/min
179 | uint8_t tool; // Tracks tool number. NOT USED.
180 | int32_t line_number; // Last line number sent
181 |
182 | float position[N_AXIS]; // Where the interpreter considers the tool to be at this point in the code
183 |
184 | float coord_system[N_AXIS]; // Current work coordinate system (G54+). Stores offset from absolute machine
185 | // position in mm. Loaded from EEPROM when called.
186 | float coord_offset[N_AXIS]; // Retains the G92 coordinate offset (work coordinates) relative to
187 | // machine zero in mm. Non-persistent. Cleared upon reset and boot.
188 | float tool_length_offset; // Tracks tool length offset value when enabled.
189 | } parser_state_t;
190 | extern parser_state_t gc_state;
191 |
192 | typedef struct {
193 | // uint16_t command_words; // NOTE: If this bitflag variable fills, G and M words can be separated.
194 | // uint16_t value_words;
195 |
196 | uint8_t non_modal_command;
197 | gc_modal_t modal;
198 | gc_values_t values;
199 |
200 | } parser_block_t;
201 | extern parser_block_t gc_block;
202 |
203 | // Initialize the parser
204 | void gc_init();
205 |
206 | // Execute one block of rs275/ngc/g-code
207 | uint8_t gc_execute_line(char *line);
208 |
209 | // Set g-code parser position. Input in steps.
210 | void gc_sync_position();
211 |
212 | #endif
213 |
--------------------------------------------------------------------------------
/grbl/grbl.h:
--------------------------------------------------------------------------------
1 | /*
2 | grbl.h - main Grbl include file
3 | Part of Grbl
4 |
5 | Copyright (c) 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 | #ifndef grbl_h
22 | #define grbl_h
23 |
24 | // Grbl versioning system
25 | #define GRBL_VERSION "0.9j-polar"
26 | #define GRBL_VERSION_BUILD "20221230"
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 "coolant_control.h"
49 | #include "eeprom.h"
50 | #include "gcode.h"
51 | #include "limits.h"
52 | #include "motion_control.h"
53 | #include "planner.h"
54 | #include "print.h"
55 | #include "probe.h"
56 | #include "protocol.h"
57 | #include "report.h"
58 | #include "serial.h"
59 | #include "spindle_control.h"
60 | #include "stepper.h"
61 |
62 | #endif
63 |
--------------------------------------------------------------------------------
/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-2015 Sungeun K. Jeon
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
--------------------------------------------------------------------------------
/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-2015 Sungeun K. Jeon
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 |
28 |
29 | int main(void)
30 | {
31 | // Initialize system upon power-up.
32 | serial_init(); // Setup serial baud rate and interrupts
33 | settings_init(); // Load Grbl settings from EEPROM
34 | stepper_init(); // Configure stepper pins and interrupt timers
35 | system_init(); // Configure pinout pins and pin-change interrupt
36 |
37 | memset(&sys, 0, sizeof(system_t)); // Clear all system variables
38 | sys.abort = true; // Set abort to complete initialization
39 | sei(); // Enable interrupts
40 |
41 | #ifdef POLARGRAPH_ASSUME_MANUALLY_HOMED
42 | // Assume gondola is manually homed
43 | sys.position[X_AXIS] = settings.distance * settings.steps_per_mm[X_AXIS] / 2;
44 | sys.position[Y_AXIS] = settings.homing_vertical_distance * settings.steps_per_mm[Y_AXIS];
45 | plan_sync_position();
46 | #endif
47 |
48 | // Check for power-up and set system alarm if homing is enabled to force homing cycle
49 | // by setting Grbl's alarm state. Alarm locks out all g-code commands, including the
50 | // startup scripts, but allows access to settings and internal commands. Only a homing
51 | // cycle '$H' or kill alarm locks '$X' will disable the alarm.
52 | // NOTE: The startup script will run after successful completion of the homing cycle, but
53 | // not after disabling the alarm locks. Prevents motion startup blocks from crashing into
54 | // things uncontrollably. Very bad.
55 | #ifdef HOMING_INIT_LOCK
56 | if (bit_istrue(settings.flags,BITFLAG_HOMING_ENABLE)) { sys.state = STATE_ALARM; }
57 | #endif
58 |
59 | // Force Grbl into an ALARM state upon a power-cycle or hard reset.
60 | #ifdef FORCE_INITIALIZATION_ALARM
61 | sys.state = STATE_ALARM;
62 | #endif
63 |
64 | // Grbl initialization loop upon power-up or a system abort. For the latter, all processes
65 | // will return to this loop to be cleanly re-initialized.
66 | for(;;) {
67 |
68 | // TODO: Separate configure task that require interrupts to be disabled, especially upon
69 | // a system abort and ensuring any active interrupts are cleanly reset.
70 |
71 | // Reset Grbl primary systems.
72 | serial_reset_read_buffer(); // Clear serial read buffer
73 | gc_init(); // Set g-code parser to default state
74 | spindle_init();
75 | coolant_init();
76 | limits_init();
77 | probe_init();
78 | plan_reset(); // Clear block buffer and planner variables
79 | st_reset(); // Clear stepper subsystem variables.
80 |
81 | // Sync cleared gcode and planner positions to current system position.
82 | plan_sync_position();
83 | gc_sync_position();
84 |
85 | // Reset system variables.
86 | sys.abort = false;
87 | sys_rt_exec_state = 0;
88 | sys_rt_exec_alarm = 0;
89 | sys.suspend = false;
90 | sys.soft_limit = false;
91 |
92 | // Start Grbl main loop. Processes program inputs and executes them.
93 | protocol_main_loop();
94 |
95 | }
96 | return 0; /* Never reached */
97 | }
98 |
--------------------------------------------------------------------------------
/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-2015 Sungeun K. Jeon
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 | #define HOMING_CYCLE_LINE_NUMBER -1
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 | #ifdef USE_LINE_NUMBERS
32 | void mc_line(float *target, float feed_rate, uint8_t invert_feed_rate, int32_t line_number);
33 | #else
34 | void mc_line(float *target, float feed_rate, uint8_t invert_feed_rate);
35 | #endif
36 |
37 | // Execute an arc in offset mode format. position == current xyz, target == target xyz,
38 | // offset == offset from current xyz, axis_XXX defines circle plane in tool space, axis_linear is
39 | // the direction of helical travel, radius == circle radius, is_clockwise_arc boolean. Used
40 | // for vector transformation direction.
41 | #ifdef USE_LINE_NUMBERS
42 | void mc_arc(float *position, float *target, float *offset, float radius, float feed_rate,
43 | uint8_t invert_feed_rate, uint8_t axis_0, uint8_t axis_1, uint8_t axis_linear, uint8_t is_clockwise_arc, int32_t line_number);
44 | #else
45 | void mc_arc(float *position, float *target, float *offset, float radius, float feed_rate,
46 | uint8_t invert_feed_rate, uint8_t axis_0, uint8_t axis_1, uint8_t axis_linear, uint8_t is_clockwise_arc);
47 | #endif
48 |
49 | // Dwell for a specific number of seconds
50 | void mc_dwell(float seconds);
51 |
52 | // Perform homing cycle to locate machine zero. Requires limit switches.
53 | void mc_homing_cycle();
54 |
55 | // Perform tool length probe cycle. Requires probe switch.
56 | #ifdef USE_LINE_NUMBERS
57 | void mc_probe_cycle(float *target, float feed_rate, uint8_t invert_feed_rate, uint8_t is_probe_away,
58 | uint8_t is_no_error, int32_t line_number);
59 | #else
60 | void mc_probe_cycle(float *target, float feed_rate, uint8_t invert_feed_rate, uint8_t is_probe_away,
61 | uint8_t is_no_error);
62 | #endif
63 |
64 | // Performs system reset. If in motion state, kills all motion and sets system alarm.
65 | void mc_reset();
66 |
67 | #endif
68 |
--------------------------------------------------------------------------------
/grbl/nuts_bolts.c:
--------------------------------------------------------------------------------
1 | /*
2 | nuts_bolts.c - Shared functions
3 | Part of Grbl
4 |
5 | Copyright (c) 2011-2015 Sungeun K. Jeon
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 | // Delays variable defined milliseconds. Compiler compatibility fix for _delay_ms(),
112 | // which only accepts constants in future compiler releases.
113 | void delay_ms(uint16_t ms)
114 | {
115 | while ( ms-- ) { _delay_ms(1); }
116 | }
117 |
118 |
119 | // Delays variable defined microseconds. Compiler compatibility fix for _delay_us(),
120 | // which only accepts constants in future compiler releases. Written to perform more
121 | // efficiently with larger delays, as the counter adds parasitic time in each iteration.
122 | void delay_us(uint32_t us)
123 | {
124 | while (us) {
125 | if (us < 10) {
126 | _delay_us(1);
127 | us--;
128 | } else if (us < 100) {
129 | _delay_us(10);
130 | us -= 10;
131 | } else if (us < 1000) {
132 | _delay_us(100);
133 | us -= 100;
134 | } else {
135 | _delay_ms(1);
136 | us -= 1000;
137 | }
138 | }
139 | }
140 |
141 |
142 | // Simple hypotenuse computation function.
143 | float hypot_f(float x, float y) { return(sqrt(x*x + y*y)); }
144 |
--------------------------------------------------------------------------------
/grbl/nuts_bolts.h:
--------------------------------------------------------------------------------
1 | /*
2 | nuts_bolts.h - Header file for shared definitions, variables, and functions
3 | Part of Grbl
4 |
5 | Copyright (c) 2011-2015 Sungeun K. Jeon
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 nuts_bolts_h
23 | #define nuts_bolts_h
24 |
25 | #define false 0
26 | #define true 1
27 |
28 | // Axis array index values. Must start with 0 and be continuous.
29 | #define N_AXIS 3 // Number of axes
30 | #define X_AXIS 0 // Axis indexing value.
31 | #define Y_AXIS 1
32 | #define Z_AXIS 2
33 | // #define A_AXIS 3
34 |
35 | // CoreXY motor assignments. DO NOT ALTER.
36 | // NOTE: If the A and B motor axis bindings are changed, this effects the CoreXY equations.
37 | #ifdef COREXY
38 | #define A_MOTOR X_AXIS // Must be X_AXIS
39 | #define B_MOTOR Y_AXIS // Must be Y_AXIS
40 | #endif
41 |
42 | #ifdef POLARGRAPH
43 | #define A_MOTOR X_AXIS // Must be X_AXIS
44 | #define B_MOTOR Y_AXIS // Must be Y_AXIS
45 | #endif
46 |
47 | // Conversions
48 | #define MM_PER_INCH (25.40)
49 | #define INCH_PER_MM (0.0393701)
50 | #define TICKS_PER_MICROSECOND (F_CPU/1000000)
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 |
59 | // Bit field and masking macros
60 | #define bit(n) (1 << n)
61 | #define bit_true_atomic(x,mask) {uint8_t sreg = SREG; cli(); (x) |= (mask); SREG = sreg; }
62 | #define bit_false_atomic(x,mask) {uint8_t sreg = SREG; cli(); (x) &= ~(mask); SREG = sreg; }
63 | #define bit_toggle_atomic(x,mask) {uint8_t sreg = SREG; cli(); (x) ^= (mask); SREG = sreg; }
64 | #define bit_true(x,mask) (x) |= (mask)
65 | #define bit_false(x,mask) (x) &= ~(mask)
66 | #define bit_istrue(x,mask) ((x & mask) != 0)
67 | #define bit_isfalse(x,mask) ((x & mask) == 0)
68 |
69 | // Read a floating point value from a string. Line points to the input buffer, char_counter
70 | // is the indexer pointing to the current character of the line, while float_ptr is
71 | // a pointer to the result variable. Returns true when it succeeds
72 | uint8_t read_float(char *line, uint8_t *char_counter, float *float_ptr);
73 |
74 | // Delays variable-defined milliseconds. Compiler compatibility fix for _delay_ms().
75 | void delay_ms(uint16_t ms);
76 |
77 | // Delays variable-defined microseconds. Compiler compatibility fix for _delay_us().
78 | void delay_us(uint32_t us);
79 |
80 | // Computes hypotenuse, avoiding avr-gcc's bloated version and the extra error checking.
81 | float hypot_f(float x, float y);
82 |
83 | #endif
84 |
--------------------------------------------------------------------------------
/grbl/planner.h:
--------------------------------------------------------------------------------
1 | /*
2 | planner.h - buffers movement commands and manages the acceleration profile plan
3 | Part of Grbl
4 |
5 | Copyright (c) 2011-2015 Sungeun K. Jeon
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 planner_h
23 | #define planner_h
24 |
25 |
26 | // The number of linear motions that can be in the plan at any give time
27 | #ifndef BLOCK_BUFFER_SIZE
28 | #ifdef USE_LINE_NUMBERS
29 | #define BLOCK_BUFFER_SIZE 16
30 | #else
31 | #define BLOCK_BUFFER_SIZE 18
32 | #endif
33 | #endif
34 |
35 | // This struct stores a linear movement of a g-code block motion with its critical "nominal" values
36 | // are as specified in the source g-code.
37 | typedef struct {
38 | // Fields used by the bresenham algorithm for tracing the line
39 | // NOTE: Used by stepper algorithm to execute the block correctly. Do not alter these values.
40 | uint8_t direction_bits; // The direction bit set for this block (refers to *_DIRECTION_BIT in config.h)
41 | uint32_t steps[N_AXIS]; // Step count along each axis
42 | uint32_t step_event_count; // The maximum step axis count and number of steps required to complete this block.
43 |
44 | // Fields used by the motion planner to manage acceleration
45 | float entry_speed_sqr; // The current planned entry speed at block junction in (mm/min)^2
46 | float max_entry_speed_sqr; // Maximum allowable entry speed based on the minimum of junction limit and
47 | // neighboring nominal speeds with overrides in (mm/min)^2
48 | float max_junction_speed_sqr; // Junction entry speed limit based on direction vectors in (mm/min)^2
49 | float nominal_speed_sqr; // Axis-limit adjusted nominal speed for this block in (mm/min)^2
50 | float acceleration; // Axis-limit adjusted line acceleration in (mm/min^2)
51 | float millimeters; // The remaining distance for this block to be executed in (mm)
52 | // uint8_t max_override; // Maximum override value based on axis speed limits
53 |
54 | #ifdef USE_LINE_NUMBERS
55 | int32_t line_number;
56 | #endif
57 | } plan_block_t;
58 |
59 |
60 | // Initialize and reset the motion plan subsystem
61 | void plan_reset();
62 |
63 | // Add a new linear movement to the buffer. target[N_AXIS] is the signed, absolute target position
64 | // in millimeters. Feed rate specifies the speed of the motion. If feed rate is inverted, the feed
65 | // rate is taken to mean "frequency" and would complete the operation in 1/feed_rate minutes.
66 | #ifdef USE_LINE_NUMBERS
67 | void plan_buffer_line(float *target, float feed_rate, uint8_t invert_feed_rate, int32_t line_number);
68 | #else
69 | void plan_buffer_line(float *target, float feed_rate, uint8_t invert_feed_rate);
70 | #endif
71 |
72 | // Called when the current block is no longer needed. Discards the block and makes the memory
73 | // availible for new blocks.
74 | void plan_discard_current_block();
75 |
76 | // Gets the current block. Returns NULL if buffer empty
77 | plan_block_t *plan_get_current_block();
78 |
79 | // Called periodically by step segment buffer. Mostly used internally by planner.
80 | uint8_t plan_next_block_index(uint8_t block_index);
81 |
82 | // Called by step segment buffer when computing executing block velocity profile.
83 | float plan_get_exec_block_exit_speed();
84 |
85 | // Reset the planner position vector (in steps)
86 | void plan_sync_position();
87 |
88 | // Reinitialize plan with a partially completed block
89 | void plan_cycle_reinitialize();
90 |
91 | // Returns the number of active blocks are in the planner buffer.
92 | uint8_t plan_get_block_buffer_count();
93 |
94 | // Returns the status of the block ring buffer. True, if buffer is full.
95 | uint8_t plan_check_full_buffer();
96 |
97 | #endif
98 |
--------------------------------------------------------------------------------
/grbl/print.c:
--------------------------------------------------------------------------------
1 | /*
2 | print.c - Functions for formatting output strings
3 | Part of Grbl
4 |
5 | Copyright (c) 2011-2015 Sungeun K. Jeon
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 with base and number of desired digits.
64 | void print_unsigned_int8(uint8_t n, uint8_t base, uint8_t digits)
65 | {
66 | unsigned char buf[digits];
67 | uint8_t i = 0;
68 |
69 | for (; i < digits; i++) {
70 | buf[i] = n % base ;
71 | n /= base;
72 | }
73 |
74 | for (; i > 0; i--)
75 | serial_write('0' + buf[i - 1]);
76 | }
77 |
78 |
79 | // Prints an uint8 variable in base 2.
80 | void print_uint8_base2(uint8_t n) {
81 | print_unsigned_int8(n,2,8);
82 | }
83 |
84 |
85 | // Prints an uint8 variable in base 10.
86 | void print_uint8_base10(uint8_t n)
87 | {
88 | uint8_t digits;
89 | if (n < 10) { digits = 1; }
90 | else if (n < 100) { digits = 2; }
91 | else { digits = 3; }
92 | print_unsigned_int8(n,10,digits);
93 | }
94 |
95 |
96 | void print_uint32_base10(uint32_t n)
97 | {
98 | if (n == 0) {
99 | serial_write('0');
100 | return;
101 | }
102 |
103 | unsigned char buf[10];
104 | uint8_t i = 0;
105 |
106 | while (n > 0) {
107 | buf[i++] = n % 10;
108 | n /= 10;
109 | }
110 |
111 | for (; i > 0; i--)
112 | serial_write('0' + buf[i-1]);
113 | }
114 |
115 |
116 | void printInteger(long n)
117 | {
118 | if (n < 0) {
119 | serial_write('-');
120 | print_uint32_base10(-n);
121 | } else {
122 | print_uint32_base10(n);
123 | }
124 | }
125 |
126 |
127 | // Convert float to string by immediately converting to a long integer, which contains
128 | // more digits than a float. Number of decimal places, which are tracked by a counter,
129 | // may be set by the user. The integer is then efficiently converted to a string.
130 | // NOTE: AVR '%' and '/' integer operations are very efficient. Bitshifting speed-up
131 | // techniques are actually just slightly slower. Found this out the hard way.
132 | void printFloat(float n, uint8_t decimal_places)
133 | {
134 | if (n < 0) {
135 | serial_write('-');
136 | n = -n;
137 | }
138 |
139 | uint8_t decimals = decimal_places;
140 | while (decimals >= 2) { // Quickly convert values expected to be E0 to E-4.
141 | n *= 100;
142 | decimals -= 2;
143 | }
144 | if (decimals) { n *= 10; }
145 | n += 0.5; // Add rounding factor. Ensures carryover through entire value.
146 |
147 | // Generate digits backwards and store in string.
148 | unsigned char buf[10];
149 | uint8_t i = 0;
150 | uint32_t a = (long)n;
151 | buf[decimal_places] = '.'; // Place decimal point, even if decimal places are zero.
152 | while(a > 0) {
153 | if (i == decimal_places) { i++; } // Skip decimal point location
154 | buf[i++] = (a % 10) + '0'; // Get digit
155 | a /= 10;
156 | }
157 | while (i < decimal_places) {
158 | buf[i++] = '0'; // Fill in zeros to decimal point for (n < 1)
159 | }
160 | if (i == decimal_places) { // Fill in leading zero, if needed.
161 | i++;
162 | buf[i++] = '0';
163 | }
164 |
165 | // Print the generated string.
166 | for (; i > 0; i--)
167 | serial_write(buf[i-1]);
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 | // - SettingValue: Handles all floating point settings values (always in mm.)
176 | void printFloat_CoordValue(float n) {
177 | if (bit_istrue(settings.flags,BITFLAG_REPORT_INCHES)) {
178 | printFloat(n*INCH_PER_MM,N_DECIMAL_COORDVALUE_INCH);
179 | } else {
180 | printFloat(n,N_DECIMAL_COORDVALUE_MM);
181 | }
182 | }
183 |
184 | void printFloat_RateValue(float n) {
185 | if (bit_istrue(settings.flags,BITFLAG_REPORT_INCHES)) {
186 | printFloat(n*INCH_PER_MM,N_DECIMAL_RATEVALUE_INCH);
187 | } else {
188 | printFloat(n,N_DECIMAL_RATEVALUE_MM);
189 | }
190 | }
191 |
192 | void printFloat_SettingValue(float n) { printFloat(n,N_DECIMAL_SETTINGVALUE); }
193 |
194 |
195 | // Debug tool to print free memory in bytes at the called point.
196 | // NOTE: Keep commented unless using. Part of this function always gets compiled in.
197 | // void printFreeMemory()
198 | // {
199 | // extern int __heap_start, *__brkval;
200 | // uint16_t free; // Up to 64k values.
201 | // free = (int) &free - (__brkval == 0 ? (int) &__heap_start : (int) __brkval);
202 | // printInteger((int32_t)free);
203 | // printString(" ");
204 | // }
205 |
--------------------------------------------------------------------------------
/grbl/print.h:
--------------------------------------------------------------------------------
1 | /*
2 | print.h - Functions for formatting output strings
3 | Part of Grbl
4 |
5 | Copyright (c) 2011-2015 Sungeun K. Jeon
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 uint8 variable with base and number of desired digits.
35 | void print_unsigned_int8(uint8_t n, uint8_t base, uint8_t digits);
36 |
37 | // Prints an uint8 variable in base 2.
38 | void print_uint8_base2(uint8_t n);
39 |
40 | // Prints an uint8 variable in base 10.
41 | void print_uint8_base10(uint8_t n);
42 |
43 | void printFloat(float n, uint8_t decimal_places);
44 |
45 | // Floating value printing handlers for special variables types used in Grbl.
46 | // - CoordValue: Handles all position or coordinate values in inches or mm reporting.
47 | // - RateValue: Handles feed rate and current velocity in inches or mm reporting.
48 | // - SettingValue: Handles all floating point settings values (always in mm.)
49 | void printFloat_CoordValue(float n);
50 |
51 | void printFloat_RateValue(float n);
52 |
53 | void printFloat_SettingValue(float n);
54 |
55 | // Debug tool to print free memory in bytes at the called point. Not used otherwise.
56 | void printFreeMemory();
57 |
58 | #endif
--------------------------------------------------------------------------------
/grbl/probe.c:
--------------------------------------------------------------------------------
1 | /*
2 | probe.c - code pertaining to probing methods
3 | Part of Grbl
4 |
5 | Copyright (c) 2014-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 | #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. Not required. Updated when in-use.
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 (sys_probe_state == PROBE_ACTIVE) {
62 | if (probe_get_state()) {
63 | sys_probe_state = PROBE_OFF;
64 | memcpy(sys.probe_position, sys.position, sizeof(sys.position));
65 | bit_true(sys_rt_exec_state, EXEC_MOTION_CANCEL);
66 | }
67 | }
68 | }
69 |
--------------------------------------------------------------------------------
/grbl/probe.h:
--------------------------------------------------------------------------------
1 | /*
2 | probe.h - code pertaining to probing methods
3 | Part of Grbl
4 |
5 | Copyright (c) 2014-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 | #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-2015 Sungeun K. Jeon
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 |
42 | // Notify the stepper subsystem to start executing the g-code program in buffer.
43 | // void protocol_cycle_start();
44 |
45 | // Reinitializes the buffer after a feed hold for a resume.
46 | // void protocol_cycle_reinitialize();
47 |
48 | // Initiates a feed hold of the running program
49 | // void protocol_feed_hold();
50 |
51 | // Executes the auto cycle feature, if enabled.
52 | void protocol_auto_cycle_start();
53 |
54 | // Block until all buffered steps are executed
55 | void protocol_buffer_synchronize();
56 |
57 | #endif
58 |
--------------------------------------------------------------------------------
/grbl/report.h:
--------------------------------------------------------------------------------
1 | /*
2 | report.h - reporting and messaging methods
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 | #ifndef report_h
21 | #define report_h
22 |
23 | // Define Grbl status codes.
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_ALARM_LOCK 9
34 | #define STATUS_SOFT_LIMIT_ERROR 10
35 | #define STATUS_OVERFLOW 11
36 | #define STATUS_MAX_STEP_RATE_EXCEEDED 12
37 |
38 | #define STATUS_GCODE_UNSUPPORTED_COMMAND 20
39 | #define STATUS_GCODE_MODAL_GROUP_VIOLATION 21
40 | #define STATUS_GCODE_UNDEFINED_FEED_RATE 22
41 | #define STATUS_GCODE_COMMAND_VALUE_NOT_INTEGER 23
42 | #define STATUS_GCODE_AXIS_COMMAND_CONFLICT 24
43 | #define STATUS_GCODE_WORD_REPEATED 25
44 | #define STATUS_GCODE_NO_AXIS_WORDS 26
45 | #define STATUS_GCODE_INVALID_LINE_NUMBER 27
46 | #define STATUS_GCODE_VALUE_WORD_MISSING 28
47 | #define STATUS_GCODE_UNSUPPORTED_COORD_SYS 29
48 | #define STATUS_GCODE_G53_INVALID_MOTION_MODE 30
49 | #define STATUS_GCODE_AXIS_WORDS_EXIST 31
50 | #define STATUS_GCODE_NO_AXIS_WORDS_IN_PLANE 32
51 | #define STATUS_GCODE_INVALID_TARGET 33
52 | #define STATUS_GCODE_ARC_RADIUS_ERROR 34
53 | #define STATUS_GCODE_NO_OFFSETS_IN_PLANE 35
54 | #define STATUS_GCODE_UNUSED_WORDS 36
55 | #define STATUS_GCODE_G43_DYNAMIC_AXIS_ERROR 37
56 |
57 | // Define Grbl alarm codes.
58 | #define ALARM_HARD_LIMIT_ERROR 1
59 | #define ALARM_SOFT_LIMIT_ERROR 2
60 | #define ALARM_ABORT_CYCLE 3
61 | #define ALARM_PROBE_FAIL 4
62 | #define ALARM_HOMING_FAIL 5
63 |
64 | // Define Grbl feedback message codes.
65 | #define MESSAGE_CRITICAL_EVENT 1
66 | #define MESSAGE_ALARM_LOCK 2
67 | #define MESSAGE_ALARM_UNLOCK 3
68 | #define MESSAGE_ENABLED 4
69 | #define MESSAGE_DISABLED 5
70 | #define MESSAGE_SAFETY_DOOR_AJAR 6
71 | #define MESSAGE_PROGRAM_END 7
72 | #define MESSAGE_RESTORE_DEFAULTS 8
73 |
74 | // Prints system status messages.
75 | void report_status_message(uint8_t status_code);
76 |
77 | // Prints system alarm messages.
78 | void report_alarm_message(int8_t alarm_code);
79 |
80 | // Prints miscellaneous feedback messages.
81 | void report_feedback_message(uint8_t message_code);
82 |
83 | // Prints welcome message
84 | void report_init_message();
85 |
86 | // Prints Grbl help and current global settings
87 | void report_grbl_help();
88 |
89 | // Prints Grbl global settings
90 | void report_grbl_settings();
91 |
92 | // Prints an echo of the pre-parsed line received right before execution.
93 | void report_echo_line_received(char *line);
94 |
95 | // Prints realtime status report
96 | void report_realtime_status();
97 |
98 | // Prints recorded probe position
99 | void report_probe_parameters();
100 |
101 | // Prints Grbl NGC parameters (coordinate offsets, probe)
102 | void report_ngc_parameters();
103 |
104 | // Prints current g-code parser mode state
105 | void report_gcode_modes();
106 |
107 | // Prints startup line
108 | void report_startup_line(uint8_t n, char *line);
109 |
110 | // Prints build info and user info
111 | void report_build_info(char *line);
112 |
113 | #endif
114 |
--------------------------------------------------------------------------------
/grbl/serial.c:
--------------------------------------------------------------------------------
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-2015 Sungeun K. Jeon
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 | uint8_t serial_rx_buffer[RX_BUFFER_SIZE];
26 | uint8_t serial_rx_buffer_head = 0;
27 | volatile uint8_t serial_rx_buffer_tail = 0;
28 |
29 | uint8_t serial_tx_buffer[TX_BUFFER_SIZE];
30 | uint8_t serial_tx_buffer_head = 0;
31 | volatile uint8_t serial_tx_buffer_tail = 0;
32 |
33 |
34 | #ifdef ENABLE_XONXOFF
35 | volatile uint8_t flow_ctrl = XON_SENT; // Flow control state variable
36 | #endif
37 |
38 |
39 | // Returns the number of bytes used in the RX serial buffer.
40 | uint8_t serial_get_rx_buffer_count()
41 | {
42 | uint8_t rtail = serial_rx_buffer_tail; // Copy to limit multiple calls to volatile
43 | if (serial_rx_buffer_head >= rtail) { return(serial_rx_buffer_head-rtail); }
44 | return (RX_BUFFER_SIZE - (rtail-serial_rx_buffer_head));
45 | }
46 |
47 |
48 | // Returns the number of bytes used in the TX serial buffer.
49 | // NOTE: Not used except for debugging and ensuring no TX bottlenecks.
50 | uint8_t serial_get_tx_buffer_count()
51 | {
52 | uint8_t ttail = serial_tx_buffer_tail; // Copy to limit multiple calls to volatile
53 | if (serial_tx_buffer_head >= ttail) { return(serial_tx_buffer_head-ttail); }
54 | return (TX_BUFFER_SIZE - (ttail-serial_tx_buffer_head));
55 | }
56 |
57 |
58 | void serial_init()
59 | {
60 | // Set baud rate
61 | #if BAUD_RATE < 57600
62 | uint16_t UBRR0_value = ((F_CPU / (8L * BAUD_RATE)) - 1)/2 ;
63 | UCSR0A &= ~(1 << U2X0); // baud doubler off - Only needed on Uno XXX
64 | #else
65 | uint16_t UBRR0_value = ((F_CPU / (4L * BAUD_RATE)) - 1)/2;
66 | UCSR0A |= (1 << U2X0); // baud doubler on for high baud rates, i.e. 115200
67 | #endif
68 | UBRR0H = UBRR0_value >> 8;
69 | UBRR0L = UBRR0_value;
70 |
71 | // enable rx and tx
72 | 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 | //TODO: else alarm on overflow?
190 | }
191 | }
192 |
193 |
194 | void serial_reset_read_buffer()
195 | {
196 | serial_rx_buffer_tail = serial_rx_buffer_head;
197 |
198 | #ifdef ENABLE_XONXOFF
199 | flow_ctrl = XON_SENT;
200 | #endif
201 | }
202 |
--------------------------------------------------------------------------------
/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-2015 Sungeun K. Jeon
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 | #define TX_BUFFER_SIZE 64
31 | #endif
32 |
33 | #define SERIAL_NO_DATA 0xff
34 |
35 | #ifdef ENABLE_XONXOFF
36 | #define RX_BUFFER_FULL 96 // XOFF high watermark
37 | #define RX_BUFFER_LOW 64 // XON low watermark
38 | #define SEND_XOFF 1
39 | #define SEND_XON 2
40 | #define XOFF_SENT 3
41 | #define XON_SENT 4
42 | #define XOFF_CHAR 0x13
43 | #define XON_CHAR 0x11
44 | #endif
45 |
46 | void serial_init();
47 |
48 | // Writes one byte to the TX serial buffer. Called by main program.
49 | void serial_write(uint8_t data);
50 |
51 | // Fetches the first byte in the serial read buffer. Called by main program.
52 | uint8_t serial_read();
53 |
54 | // Reset and empty data in read buffer. Used by e-stop and reset.
55 | void serial_reset_read_buffer();
56 |
57 | // Returns the number of bytes used in the RX serial buffer.
58 | uint8_t serial_get_rx_buffer_count();
59 |
60 | // Returns the number of bytes used in the TX serial buffer.
61 | // NOTE: Not used except for debugging and ensuring no TX bottlenecks.
62 | uint8_t serial_get_tx_buffer_count();
63 |
64 | #endif
65 |
--------------------------------------------------------------------------------
/grbl/settings.c:
--------------------------------------------------------------------------------
1 | /*
2 | settings.c - eeprom configuration handling
3 | Part of Grbl
4 |
5 | Copyright (c) 2011-2015 Sungeun K. Jeon
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 | settings_t settings;
25 |
26 |
27 | // Method to store startup lines into EEPROM
28 | void settings_store_startup_line(uint8_t n, char *line)
29 | {
30 | uint32_t addr = n*(LINE_BUFFER_SIZE+1)+EEPROM_ADDR_STARTUP_BLOCK;
31 | memcpy_to_eeprom_with_checksum(addr,(char*)line, LINE_BUFFER_SIZE);
32 | }
33 |
34 |
35 | // Method to store build info into EEPROM
36 | void settings_store_build_info(char *line)
37 | {
38 | memcpy_to_eeprom_with_checksum(EEPROM_ADDR_BUILD_INFO,(char*)line, LINE_BUFFER_SIZE);
39 | }
40 |
41 |
42 | // Method to store coord data parameters into EEPROM
43 | void settings_write_coord_data(uint8_t coord_select, float *coord_data)
44 | {
45 | uint32_t addr = coord_select*(sizeof(float)*N_AXIS+1) + EEPROM_ADDR_PARAMETERS;
46 | memcpy_to_eeprom_with_checksum(addr,(char*)coord_data, sizeof(float)*N_AXIS);
47 | }
48 |
49 |
50 | // Method to store Grbl global settings struct and version number into EEPROM
51 | void write_global_settings()
52 | {
53 | eeprom_put_char(0, SETTINGS_VERSION);
54 | memcpy_to_eeprom_with_checksum(EEPROM_ADDR_GLOBAL, (char*)&settings, sizeof(settings_t));
55 | }
56 |
57 |
58 | // Method to restore EEPROM-saved Grbl global settings back to defaults.
59 | void settings_restore(uint8_t restore_flag) {
60 | if (restore_flag & SETTINGS_RESTORE_DEFAULTS) {
61 | settings.pulse_microseconds = DEFAULT_STEP_PULSE_MICROSECONDS;
62 | settings.stepper_idle_lock_time = DEFAULT_STEPPER_IDLE_LOCK_TIME;
63 | settings.step_invert_mask = DEFAULT_STEPPING_INVERT_MASK;
64 | settings.dir_invert_mask = DEFAULT_DIRECTION_INVERT_MASK;
65 | settings.status_report_mask = DEFAULT_STATUS_REPORT_MASK;
66 | settings.junction_deviation = DEFAULT_JUNCTION_DEVIATION;
67 | settings.arc_tolerance = DEFAULT_ARC_TOLERANCE;
68 | settings.homing_dir_mask = DEFAULT_HOMING_DIR_MASK;
69 | settings.homing_feed_rate = DEFAULT_HOMING_FEED_RATE;
70 | settings.homing_seek_rate = DEFAULT_HOMING_SEEK_RATE;
71 | settings.homing_debounce_delay = DEFAULT_HOMING_DEBOUNCE_DELAY;
72 | settings.homing_pulloff = DEFAULT_HOMING_PULLOFF;
73 | #ifdef POLARGRAPH
74 | settings.distance = DEFAULT_DISTANCE;
75 | settings.homing_vertical_distance = DEFAULT_HOMING_VERTICAL_DISTANCE;
76 | #endif
77 |
78 | settings.flags = 0;
79 | if (DEFAULT_REPORT_INCHES) { settings.flags |= BITFLAG_REPORT_INCHES; }
80 | if (DEFAULT_INVERT_ST_ENABLE) { settings.flags |= BITFLAG_INVERT_ST_ENABLE; }
81 | if (DEFAULT_INVERT_LIMIT_PINS) { settings.flags |= BITFLAG_INVERT_LIMIT_PINS; }
82 | if (DEFAULT_SOFT_LIMIT_ENABLE) { settings.flags |= BITFLAG_SOFT_LIMIT_ENABLE; }
83 | if (DEFAULT_HARD_LIMIT_ENABLE) { settings.flags |= BITFLAG_HARD_LIMIT_ENABLE; }
84 | if (DEFAULT_HOMING_ENABLE) { settings.flags |= BITFLAG_HOMING_ENABLE; }
85 |
86 | settings.steps_per_mm[X_AXIS] = DEFAULT_X_STEPS_PER_MM;
87 | settings.steps_per_mm[Y_AXIS] = DEFAULT_Y_STEPS_PER_MM;
88 | settings.steps_per_mm[Z_AXIS] = DEFAULT_Z_STEPS_PER_MM;
89 | settings.max_rate[X_AXIS] = DEFAULT_X_MAX_RATE;
90 | settings.max_rate[Y_AXIS] = DEFAULT_Y_MAX_RATE;
91 | settings.max_rate[Z_AXIS] = DEFAULT_Z_MAX_RATE;
92 | settings.acceleration[X_AXIS] = DEFAULT_X_ACCELERATION;
93 | settings.acceleration[Y_AXIS] = DEFAULT_Y_ACCELERATION;
94 | settings.acceleration[Z_AXIS] = DEFAULT_Z_ACCELERATION;
95 | settings.max_travel[X_AXIS] = (-DEFAULT_X_MAX_TRAVEL);
96 | settings.max_travel[Y_AXIS] = (-DEFAULT_Y_MAX_TRAVEL);
97 | settings.max_travel[Z_AXIS] = (-DEFAULT_Z_MAX_TRAVEL);
98 |
99 | write_global_settings();
100 | }
101 |
102 | if (restore_flag & SETTINGS_RESTORE_PARAMETERS) {
103 | uint8_t idx;
104 | float coord_data[N_AXIS];
105 | memset(&coord_data, 0, sizeof(coord_data));
106 | for (idx=0; idx <= SETTING_INDEX_NCOORD; idx++) { settings_write_coord_data(idx, coord_data); }
107 | }
108 |
109 | if (restore_flag & SETTINGS_RESTORE_STARTUP_LINES) {
110 | #if N_STARTUP_LINE > 0
111 | eeprom_put_char(EEPROM_ADDR_STARTUP_BLOCK, 0);
112 | #endif
113 | #if N_STARTUP_LINE > 1
114 | eeprom_put_char(EEPROM_ADDR_STARTUP_BLOCK+(LINE_BUFFER_SIZE+1), 0);
115 | #endif
116 | }
117 |
118 | if (restore_flag & SETTINGS_RESTORE_BUILD_INFO) { eeprom_put_char(EEPROM_ADDR_BUILD_INFO , 0); }
119 | }
120 |
121 |
122 | // Reads startup line from EEPROM. Updated pointed line string data.
123 | uint8_t settings_read_startup_line(uint8_t n, char *line)
124 | {
125 | uint32_t addr = n*(LINE_BUFFER_SIZE+1)+EEPROM_ADDR_STARTUP_BLOCK;
126 | if (!(memcpy_from_eeprom_with_checksum((char*)line, addr, LINE_BUFFER_SIZE))) {
127 | // Reset line with default value
128 | line[0] = 0; // Empty line
129 | settings_store_startup_line(n, line);
130 | return(false);
131 | }
132 | return(true);
133 | }
134 |
135 |
136 | // Reads startup line from EEPROM. Updated pointed line string data.
137 | uint8_t settings_read_build_info(char *line)
138 | {
139 | if (!(memcpy_from_eeprom_with_checksum((char*)line, EEPROM_ADDR_BUILD_INFO, LINE_BUFFER_SIZE))) {
140 | // Reset line with default value
141 | line[0] = 0; // Empty line
142 | settings_store_build_info(line);
143 | return(false);
144 | }
145 | return(true);
146 | }
147 |
148 |
149 | // Read selected coordinate data from EEPROM. Updates pointed coord_data value.
150 | uint8_t settings_read_coord_data(uint8_t coord_select, float *coord_data)
151 | {
152 | uint32_t addr = coord_select*(sizeof(float)*N_AXIS+1) + EEPROM_ADDR_PARAMETERS;
153 | if (!(memcpy_from_eeprom_with_checksum((char*)coord_data, addr, sizeof(float)*N_AXIS))) {
154 | // Reset with default zero vector
155 | clear_vector_float(coord_data);
156 | settings_write_coord_data(coord_select,coord_data);
157 | return(false);
158 | }
159 | return(true);
160 | }
161 |
162 |
163 | // Reads Grbl global settings struct from EEPROM.
164 | uint8_t read_global_settings() {
165 | // Check version-byte of eeprom
166 | uint8_t version = eeprom_get_char(0);
167 | if (version == SETTINGS_VERSION) {
168 | // Read settings-record and check checksum
169 | if (!(memcpy_from_eeprom_with_checksum((char*)&settings, EEPROM_ADDR_GLOBAL, sizeof(settings_t)))) {
170 | return(false);
171 | }
172 | } else {
173 | return(false);
174 | }
175 | return(true);
176 | }
177 |
178 |
179 | // A helper method to set settings from command line
180 | uint8_t settings_store_global_setting(uint8_t parameter, float value) {
181 | if (value < 0.0) { return(STATUS_NEGATIVE_VALUE); }
182 | if (parameter >= AXIS_SETTINGS_START_VAL) {
183 | // Store axis configuration. Axis numbering sequence set by AXIS_SETTING defines.
184 | // NOTE: Ensure the setting index corresponds to the report.c settings printout.
185 | parameter -= AXIS_SETTINGS_START_VAL;
186 | uint8_t set_idx = 0;
187 | while (set_idx < AXIS_N_SETTINGS) {
188 | if (parameter < N_AXIS) {
189 | // Valid axis setting found.
190 | switch (set_idx) {
191 | case 0:
192 | #ifdef MAX_STEP_RATE_HZ
193 | if (value*settings.max_rate[parameter] > (MAX_STEP_RATE_HZ*60.0)) { return(STATUS_MAX_STEP_RATE_EXCEEDED); }
194 | #endif
195 | settings.steps_per_mm[parameter] = value;
196 | break;
197 | case 1:
198 | #ifdef MAX_STEP_RATE_HZ
199 | if (value*settings.steps_per_mm[parameter] > (MAX_STEP_RATE_HZ*60.0)) { return(STATUS_MAX_STEP_RATE_EXCEEDED); }
200 | #endif
201 | settings.max_rate[parameter] = value;
202 | break;
203 | case 2: settings.acceleration[parameter] = value*60*60; break; // Convert to mm/min^2 for grbl internal use.
204 | case 3: settings.max_travel[parameter] = -value; break; // Store as negative for grbl internal use.
205 | }
206 | break; // Exit while-loop after setting has been configured and proceed to the EEPROM write call.
207 | } else {
208 | set_idx++;
209 | // If axis index greater than N_AXIS or setting index greater than number of axis settings, error out.
210 | if ((parameter < AXIS_SETTINGS_INCREMENT) || (set_idx == AXIS_N_SETTINGS)) { return(STATUS_INVALID_STATEMENT); }
211 | parameter -= AXIS_SETTINGS_INCREMENT;
212 | }
213 | }
214 | } else {
215 | // Store non-axis Grbl settings
216 | uint8_t int_value = trunc(value);
217 | switch(parameter) {
218 | case 0:
219 | if (int_value < 3) { return(STATUS_SETTING_STEP_PULSE_MIN); }
220 | settings.pulse_microseconds = int_value; break;
221 | case 1: settings.stepper_idle_lock_time = int_value; break;
222 | case 2:
223 | settings.step_invert_mask = int_value;
224 | st_generate_step_dir_invert_masks(); // Regenerate step and direction port invert masks.
225 | break;
226 | case 3:
227 | settings.dir_invert_mask = int_value;
228 | st_generate_step_dir_invert_masks(); // Regenerate step and direction port invert masks.
229 | break;
230 | case 4: // Reset to ensure change. Immediate re-init may cause problems.
231 | if (int_value) { settings.flags |= BITFLAG_INVERT_ST_ENABLE; }
232 | else { settings.flags &= ~BITFLAG_INVERT_ST_ENABLE; }
233 | break;
234 | case 5: // Reset to ensure change. Immediate re-init may cause problems.
235 | if (int_value) { settings.flags |= BITFLAG_INVERT_LIMIT_PINS; }
236 | else { settings.flags &= ~BITFLAG_INVERT_LIMIT_PINS; }
237 | break;
238 | case 6: // Reset to ensure change. Immediate re-init may cause problems.
239 | if (int_value) { settings.flags |= BITFLAG_INVERT_PROBE_PIN; }
240 | else { settings.flags &= ~BITFLAG_INVERT_PROBE_PIN; }
241 | break;
242 | case 10: settings.status_report_mask = int_value; break;
243 | case 11: settings.junction_deviation = value; break;
244 | case 12: settings.arc_tolerance = value; break;
245 | case 13:
246 | if (int_value) { settings.flags |= BITFLAG_REPORT_INCHES; }
247 | else { settings.flags &= ~BITFLAG_REPORT_INCHES; }
248 | break;
249 | case 20:
250 | if (int_value) {
251 | if (bit_isfalse(settings.flags, BITFLAG_HOMING_ENABLE)) { return(STATUS_SOFT_LIMIT_ERROR); }
252 | settings.flags |= BITFLAG_SOFT_LIMIT_ENABLE;
253 | } else { settings.flags &= ~BITFLAG_SOFT_LIMIT_ENABLE; }
254 | break;
255 | case 21:
256 | if (int_value) { settings.flags |= BITFLAG_HARD_LIMIT_ENABLE; }
257 | else { settings.flags &= ~BITFLAG_HARD_LIMIT_ENABLE; }
258 | limits_init(); // Re-init to immediately change. NOTE: Nice to have but could be problematic later.
259 | break;
260 | case 22:
261 | if (int_value) { settings.flags |= BITFLAG_HOMING_ENABLE; }
262 | else {
263 | settings.flags &= ~BITFLAG_HOMING_ENABLE;
264 | settings.flags &= ~BITFLAG_SOFT_LIMIT_ENABLE; // Force disable soft-limits.
265 | }
266 | break;
267 | case 23: settings.homing_dir_mask = int_value; break;
268 | case 24: settings.homing_feed_rate = value; break;
269 | case 25: settings.homing_seek_rate = value; break;
270 | case 26: settings.homing_debounce_delay = int_value; break;
271 | case 27: settings.homing_pulloff = value; break;
272 | #ifdef POLARGRAPH
273 | case 28: settings.distance = value; break;
274 | case 29: settings.homing_vertical_distance = value; break;
275 | #endif
276 | default:
277 | return(STATUS_INVALID_STATEMENT);
278 | }
279 | }
280 | write_global_settings();
281 | return(STATUS_OK);
282 | }
283 |
284 |
285 | // Initialize the config subsystem
286 | void settings_init() {
287 | if(!read_global_settings()) {
288 | report_status_message(STATUS_SETTING_READ_FAIL);
289 | settings_restore(SETTINGS_RESTORE_ALL); // Force restore all EEPROM data.
290 | report_grbl_settings();
291 | }
292 |
293 | // NOTE: Checking paramater data, startup lines, and build info string should be done here,
294 | // but it seems fairly redundant. Each of these can be manually checked and reset or restored.
295 | // Check all parameter data into a dummy variable. If error, reset to zero, otherwise do nothing.
296 | // float coord_data[N_AXIS];
297 | // uint8_t i;
298 | // for (i=0; i<=SETTING_INDEX_NCOORD; i++) {
299 | // if (!settings_read_coord_data(i, coord_data)) {
300 | // report_status_message(STATUS_SETTING_READ_FAIL);
301 | // }
302 | // }
303 | // NOTE: Startup lines are checked and executed by protocol_main_loop at the end of initialization.
304 | }
305 |
306 |
307 | // Returns step pin mask according to Grbl internal axis indexing.
308 | uint8_t get_step_pin_mask(uint8_t axis_idx)
309 | {
310 | if ( axis_idx == X_AXIS ) { return((1<.
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 9 // 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_AUTO_START bit(1) // Obsolete. Don't alter to keep back compatibility.
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_MACHINE_POSITION bit(0)
44 | #define BITFLAG_RT_STATUS_WORK_POSITION bit(1)
45 | #define BITFLAG_RT_STATUS_PLANNER_BUFFER bit(2)
46 | #define BITFLAG_RT_STATUS_SERIAL_RX bit(3)
47 | #define BITFLAG_RT_STATUS_LIMIT_PINS bit(4)
48 |
49 | // Define settings restore bitflags.
50 | #define SETTINGS_RESTORE_ALL 0xFF // All bitflags
51 | #define SETTINGS_RESTORE_DEFAULTS bit(0)
52 | #define SETTINGS_RESTORE_PARAMETERS bit(1)
53 | #define SETTINGS_RESTORE_STARTUP_LINES bit(2)
54 | #define SETTINGS_RESTORE_BUILD_INFO bit(3)
55 |
56 | // Define EEPROM memory address location values for Grbl settings and parameters
57 | // NOTE: The Atmega328p has 1KB EEPROM. The upper half is reserved for parameters and
58 | // the startup script. The lower half contains the global settings and space for future
59 | // developments.
60 | #define EEPROM_ADDR_GLOBAL 1U
61 | #define EEPROM_ADDR_PARAMETERS 512U
62 | #define EEPROM_ADDR_STARTUP_BLOCK 768U
63 | #define EEPROM_ADDR_BUILD_INFO 942U
64 |
65 | // Define EEPROM address indexing for coordinate parameters
66 | #define N_COORDINATE_SYSTEM 6 // Number of supported work coordinate systems (from index 1)
67 | #define SETTING_INDEX_NCOORD N_COORDINATE_SYSTEM+1 // Total number of system stored (from index 0)
68 | // NOTE: Work coordinate indices are (0=G54, 1=G55, ... , 6=G59)
69 | #define SETTING_INDEX_G28 N_COORDINATE_SYSTEM // Home position 1
70 | #define SETTING_INDEX_G30 N_COORDINATE_SYSTEM+1 // Home position 2
71 | // #define SETTING_INDEX_G92 N_COORDINATE_SYSTEM+2 // Coordinate offset (G92.2,G92.3 not supported)
72 |
73 | // Define Grbl axis settings numbering scheme. Starts at START_VAL, every INCREMENT, over N_SETTINGS.
74 | #define AXIS_N_SETTINGS 4
75 | #define AXIS_SETTINGS_START_VAL 100 // NOTE: Reserving settings values >= 100 for axis settings. Up to 255.
76 | #define AXIS_SETTINGS_INCREMENT 10 // Must be greater than the number of axis settings
77 |
78 | // Global persistent settings (Stored from byte EEPROM_ADDR_GLOBAL onwards)
79 | typedef struct {
80 | // Axis settings
81 | float steps_per_mm[N_AXIS];
82 | float max_rate[N_AXIS];
83 | float acceleration[N_AXIS];
84 | float max_travel[N_AXIS];
85 |
86 | // Remaining Grbl settings
87 | uint8_t pulse_microseconds;
88 | uint8_t step_invert_mask;
89 | uint8_t dir_invert_mask;
90 | uint8_t stepper_idle_lock_time; // If max value 255, steppers do not disable.
91 | uint8_t status_report_mask; // Mask to indicate desired report data.
92 | float junction_deviation;
93 | float arc_tolerance;
94 |
95 | uint8_t flags; // Contains default boolean settings
96 |
97 | uint8_t homing_dir_mask;
98 | float homing_feed_rate;
99 | float homing_seek_rate;
100 | uint16_t homing_debounce_delay;
101 | float homing_pulloff;
102 | #ifdef POLARGRAPH
103 | float distance; //Distance between motors
104 | float homing_vertical_distance; //Distance vertical from top when gondola is homed manually
105 | #endif
106 | } settings_t;
107 | extern settings_t settings;
108 |
109 | // Initialize the configuration subsystem (load settings from EEPROM)
110 | void settings_init();
111 |
112 | // Helper function to clear and restore EEPROM defaults
113 | void settings_restore(uint8_t restore_flag);
114 |
115 | // A helper method to set new settings from command line
116 | uint8_t settings_store_global_setting(uint8_t parameter, float value);
117 |
118 | // Stores the protocol line variable as a startup line in EEPROM
119 | void settings_store_startup_line(uint8_t n, char *line);
120 |
121 | // Reads an EEPROM startup line to the protocol line variable
122 | uint8_t settings_read_startup_line(uint8_t n, char *line);
123 |
124 | // Stores build info user-defined string
125 | void settings_store_build_info(char *line);
126 |
127 | // Reads build info user-defined string
128 | uint8_t settings_read_build_info(char *line);
129 |
130 | // Writes selected coordinate data to EEPROM
131 | void settings_write_coord_data(uint8_t coord_select, float *coord_data);
132 |
133 | // Reads selected coordinate data from EEPROM
134 | uint8_t settings_read_coord_data(uint8_t coord_select, float *coord_data);
135 |
136 | // Returns the step pin mask according to Grbl's internal axis numbering
137 | uint8_t get_step_pin_mask(uint8_t i);
138 |
139 | // Returns the direction pin mask according to Grbl's internal axis numbering
140 | uint8_t get_direction_pin_mask(uint8_t i);
141 |
142 | // Returns the limit pin mask according to Grbl's internal axis numbering
143 | uint8_t get_limit_pin_mask(uint8_t i);
144 |
145 |
146 | #endif
147 |
--------------------------------------------------------------------------------
/grbl/spindle_control.c:
--------------------------------------------------------------------------------
1 | /*
2 | spindle_control.c - spindle control methods
3 | Part of Grbl
4 |
5 | Copyright (c) 2012-2015 Sungeun K. Jeon
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 | /* RC-Servo PWM modification: switch between 0.6ms and 2.5ms pulse-width at 61Hz
23 | Prescaler 1024 = 15625Hz / 256Steps = 61Hz 64µs/step -> Values 15 / 32 for 1ms / 2ms
24 | Reload value = 0x07
25 | Replace this file in C:\Program Files (x86)\Arduino\libraries\GRBL
26 | */
27 |
28 | #include "grbl.h"
29 |
30 | #define RC_SERVO_SHORT 9//15 // Timer ticks for 0.6ms pulse duration (9 for 0.6ms)
31 | #define RC_SERVO_LONG 39//32 // Timer ticks for 2.5 ms pulse duration (39 for 2.5ms)
32 | //#define RC_SERVO_INVERT 1 // Uncomment to invert servo direction
33 |
34 | void spindle_init()
35 | {
36 | // Configure variable spindle PWM and enable pin, if requried. On the Uno, PWM and enable are
37 | // combined unless configured otherwise.
38 | #ifdef VARIABLE_SPINDLE
39 | SPINDLE_PWM_DDR |= (1< SPINDLE_RPM_RANGE ) { rpm = SPINDLE_RPM_RANGE; } // Prevent integer overflow
127 | }
128 | current_pwm = floor( rpm*(PWM_MAX_VALUE/SPINDLE_RPM_RANGE) + 0.5);
129 | #ifdef MINIMUM_SPINDLE_PWM
130 | if (current_pwm < MINIMUM_SPINDLE_PWM) { current_pwm = MINIMUM_SPINDLE_PWM; }
131 | #endif
132 | OCR_REGISTER = current_pwm; // Set PWM pin output
133 |
134 | // On the Uno, spindle enable and PWM are shared, unless otherwise specified.
135 | #if defined(CPU_MAP_ATMEGA2560) || defined(USE_SPINDLE_DIR_AS_ENABLE_PIN)
136 | #ifdef INVERT_SPINDLE_ENABLE_PIN
137 | SPINDLE_ENABLE_PORT &= ~(1< SPINDLE_RPM_RANGE ) { rpm = SPINDLE_RPM_RANGE; } // Prevent integer overflow
202 | }
203 |
204 | #ifdef RC_SERVO_INVERT
205 | current_pwm = floor( RC_SERVO_LONG - rpm*(RC_SERVO_RANGE/SPINDLE_RPM_RANGE));
206 | OCR_REGISTER = current_pwm;
207 | #else
208 | current_pwm = floor( rpm*(RC_SERVO_RANGE/SPINDLE_RPM_RANGE) + RC_SERVO_SHORT);
209 | OCR_REGISTER = current_pwm;
210 | #endif
211 | #ifdef MINIMUM_SPINDLE_PWM
212 | if (current_pwm < MINIMUM_SPINDLE_PWM) { current_pwm = MINIMUM_SPINDLE_PWM; }
213 | OCR_REGISTER = current_pwm;
214 | #endif
215 | #endif
216 | }
217 | }
218 | #else
219 | void spindle_run(uint8_t state, float rpm)
220 | {
221 | if (sys.state == STATE_CHECK_MODE) { return; }
222 | protocol_buffer_synchronize(); // Empty planner buffer to ensure spindle is set when programmed.
223 | spindle_set_state(state, rpm);
224 | }
225 | #endif
--------------------------------------------------------------------------------
/grbl/spindle_control.h:
--------------------------------------------------------------------------------
1 | /*
2 | spindle_control.h - spindle control methods
3 | Part of Grbl
4 |
5 | Copyright (c) 2012-2015 Sungeun K. Jeon
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 |
26 | // Initializes spindle pins and hardware PWM, if enabled.
27 | void spindle_init();
28 |
29 | // Sets spindle direction and spindle rpm via PWM, if enabled.
30 | void spindle_run(uint8_t direction, float rpm);
31 |
32 | void spindle_set_state(uint8_t state, float rpm);
33 |
34 | // Kills spindle.
35 | void spindle_stop();
36 |
37 | #endif
38 |
--------------------------------------------------------------------------------
/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-2015 Sungeun K. Jeon
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 | // Reloads step segment buffer. Called continuously by realtime execution system.
45 | void st_prep_buffer();
46 |
47 | // Called by planner_recalculate() when the executing block is updated by the new plan.
48 | void st_update_plan_block_parameters();
49 |
50 | // Called by realtime status reporting if realtime rate reporting is enabled in config.h.
51 | #ifdef REPORT_REALTIME_RATE
52 | float st_get_realtime_rate();
53 | #endif
54 |
55 | #endif
56 |
--------------------------------------------------------------------------------
/grbl/system.h:
--------------------------------------------------------------------------------
1 | /*
2 | system.h - Header for system level commands and real-time processes
3 | Part of Grbl
4 |
5 | Copyright (c) 2014-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 | #ifndef system_h
22 | #define system_h
23 |
24 | #include "grbl.h"
25 |
26 | // Define system executor bit map. Used internally by realtime protocol as realtime command flags,
27 | // which notifies the main program to execute the specified realtime command asynchronously.
28 | // NOTE: The system executor uses an unsigned 8-bit volatile variable (8 flag limit.) The default
29 | // flags are always false, so the realtime protocol only needs to check for a non-zero value to
30 | // know when there is a realtime command to execute.
31 | #define EXEC_STATUS_REPORT bit(0) // bitmask 00000001
32 | #define EXEC_CYCLE_START bit(1) // bitmask 00000010
33 | #define EXEC_CYCLE_STOP bit(2) // bitmask 00000100
34 | #define EXEC_FEED_HOLD bit(3) // bitmask 00001000
35 | #define EXEC_RESET bit(4) // bitmask 00010000
36 | #define EXEC_SAFETY_DOOR bit(5) // bitmask 00100000
37 | #define EXEC_MOTION_CANCEL bit(6) // bitmask 01000000
38 |
39 | // Alarm executor bit map.
40 | // NOTE: EXEC_CRITICAL_EVENT is an optional flag that must be set with an alarm flag. When enabled,
41 | // this halts Grbl into an infinite loop until the user aknowledges the problem and issues a soft-
42 | // reset command. For example, a hard limit event needs this type of halt and aknowledgement.
43 | #define EXEC_CRITICAL_EVENT bit(0) // bitmask 00000001 (SPECIAL FLAG. See NOTE:)
44 | #define EXEC_ALARM_HARD_LIMIT bit(1) // bitmask 00000010
45 | #define EXEC_ALARM_SOFT_LIMIT bit(2) // bitmask 00000100
46 | #define EXEC_ALARM_ABORT_CYCLE bit(3) // bitmask 00001000
47 | #define EXEC_ALARM_PROBE_FAIL bit(4) // bitmask 00010000
48 | #define EXEC_ALARM_HOMING_FAIL bit(5) // bitmask 00100000
49 |
50 | // Define system state bit map. The state variable primarily tracks the individual functions
51 | // of Grbl to manage each without overlapping. It is also used as a messaging flag for
52 | // critical events.
53 | #define STATE_IDLE 0 // Must be zero. No flags.
54 | #define STATE_ALARM bit(0) // In alarm state. Locks out all g-code processes. Allows settings access.
55 | #define STATE_CHECK_MODE bit(1) // G-code check mode. Locks out planner and motion only.
56 | #define STATE_HOMING bit(2) // Performing homing cycle
57 | #define STATE_CYCLE bit(3) // Cycle is running or motions are being executed.
58 | #define STATE_HOLD bit(4) // Active feed hold
59 | #define STATE_SAFETY_DOOR bit(5) // Safety door is ajar. Feed holds and de-energizes system.
60 | #define STATE_MOTION_CANCEL bit(6) // Motion cancel by feed hold and return to idle.
61 |
62 | // Define system suspend states.
63 | #define SUSPEND_DISABLE 0 // Must be zero.
64 | #define SUSPEND_ENABLE_HOLD bit(0) // Enabled. Indicates the cycle is active and currently undergoing a hold.
65 | #define SUSPEND_ENABLE_READY bit(1) // Ready to resume with a cycle start command.
66 | #define SUSPEND_ENERGIZE bit(2) // Re-energizes output before resume.
67 | #define SUSPEND_MOTION_CANCEL bit(3) // Cancels resume motion. Used by probing routine.
68 |
69 |
70 | // Define global system variables
71 | typedef struct {
72 | uint8_t abort; // System abort flag. Forces exit back to main loop for reset.
73 | uint8_t state; // Tracks the current state of Grbl.
74 | uint8_t suspend; // System suspend bitflag variable that manages holds, cancels, and safety door.
75 | uint8_t soft_limit; // Tracks soft limit errors for the state machine. (boolean)
76 |
77 | int32_t position[N_AXIS]; // Real-time machine (aka home) position vector in steps.
78 | // NOTE: This may need to be a volatile variable, if problems arise.
79 |
80 | int32_t probe_position[N_AXIS]; // Last probe position in machine coordinates and steps.
81 | uint8_t probe_succeeded; // Tracks if last probing cycle was successful.
82 | uint8_t homing_axis_lock; // Locks axes when limits engage. Used as an axis motion mask in the stepper ISR.
83 | } system_t;
84 | extern system_t sys;
85 |
86 | volatile uint8_t sys_probe_state; // Probing state value. Used to coordinate the probing cycle with stepper ISR.
87 | volatile uint8_t sys_rt_exec_state; // Global realtime executor bitflag variable for state management. See EXEC bitmasks.
88 | volatile uint8_t sys_rt_exec_alarm; // Global realtime executor bitflag variable for setting various alarms.
89 |
90 |
91 | // Initialize the serial protocol
92 | void system_init();
93 |
94 | // Returns if safety door is open or closed, based on pin state.
95 | uint8_t system_check_safety_door_ajar();
96 |
97 | // Executes an internal system command, defined as a string starting with a '$'
98 | uint8_t system_execute_line(char *line);
99 |
100 | // Execute the startup script lines stored in EEPROM upon initialization
101 | void system_execute_startup(char *line);
102 |
103 | // Returns machine position of axis 'idx'. Must be sent a 'step' array.
104 | float system_convert_axis_steps_to_mpos(int32_t *steps, uint8_t idx);
105 |
106 | // Updates a machine 'position' array based on the 'step' array sent.
107 | void system_convert_array_steps_to_mpos(float *position, int32_t *steps);
108 |
109 | // CoreXY calculation only. Returns x or y-axis "steps" based on CoreXY motor steps.
110 | #ifdef COREXY
111 | int32_t system_convert_corexy_to_x_axis_steps(int32_t *steps);
112 | int32_t system_convert_corexy_to_y_axis_steps(int32_t *steps);
113 | #endif
114 |
115 | #endif
116 |
--------------------------------------------------------------------------------
/images/arduino/arduinougs.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/john4242/grbl-polargraph/94dc599dc19d7b80149ed0138324dceb121be5f4/images/arduino/arduinougs.png
--------------------------------------------------------------------------------
/images/arduino/arduinougs2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/john4242/grbl-polargraph/94dc599dc19d7b80149ed0138324dceb121be5f4/images/arduino/arduinougs2.png
--------------------------------------------------------------------------------
/images/cncshield/A4988-Stepper-Motor-Driver-Pinout.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/john4242/grbl-polargraph/94dc599dc19d7b80149ed0138324dceb121be5f4/images/cncshield/A4988-Stepper-Motor-Driver-Pinout.png
--------------------------------------------------------------------------------
/images/cncshield/Arduino-Nano-pinout-768x768.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/john4242/grbl-polargraph/94dc599dc19d7b80149ed0138324dceb121be5f4/images/cncshield/Arduino-Nano-pinout-768x768.jpg
--------------------------------------------------------------------------------
/images/cncshield/board1.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/john4242/grbl-polargraph/94dc599dc19d7b80149ed0138324dceb121be5f4/images/cncshield/board1.jpg
--------------------------------------------------------------------------------
/images/cncshield/boardbox.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/john4242/grbl-polargraph/94dc599dc19d7b80149ed0138324dceb121be5f4/images/cncshield/boardbox.jpg
--------------------------------------------------------------------------------
/images/cncshield/cncshield.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/john4242/grbl-polargraph/94dc599dc19d7b80149ed0138324dceb121be5f4/images/cncshield/cncshield.jpg
--------------------------------------------------------------------------------
/images/cncshield/cncshieldboard.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/john4242/grbl-polargraph/94dc599dc19d7b80149ed0138324dceb121be5f4/images/cncshield/cncshieldboard.png
--------------------------------------------------------------------------------
/images/cncshield/cncshieldfixwiring.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/john4242/grbl-polargraph/94dc599dc19d7b80149ed0138324dceb121be5f4/images/cncshield/cncshieldfixwiring.png
--------------------------------------------------------------------------------
/images/cncshield/cncshieldsoldered.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/john4242/grbl-polargraph/94dc599dc19d7b80149ed0138324dceb121be5f4/images/cncshield/cncshieldsoldered.png
--------------------------------------------------------------------------------
/images/cncshield/parameters.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/john4242/grbl-polargraph/94dc599dc19d7b80149ed0138324dceb121be5f4/images/cncshield/parameters.png
--------------------------------------------------------------------------------
/images/cncshield/pinconnections.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/john4242/grbl-polargraph/94dc599dc19d7b80149ed0138324dceb121be5f4/images/cncshield/pinconnections.png
--------------------------------------------------------------------------------
/images/cncshield/usefulgcodes.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/john4242/grbl-polargraph/94dc599dc19d7b80149ed0138324dceb121be5f4/images/cncshield/usefulgcodes.png
--------------------------------------------------------------------------------
/images/frame/board.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/john4242/grbl-polargraph/94dc599dc19d7b80149ed0138324dceb121be5f4/images/frame/board.jpg
--------------------------------------------------------------------------------
/images/frame/gondola.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/john4242/grbl-polargraph/94dc599dc19d7b80149ed0138324dceb121be5f4/images/frame/gondola.jpg
--------------------------------------------------------------------------------
/images/frame/motormounted.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/john4242/grbl-polargraph/94dc599dc19d7b80149ed0138324dceb121be5f4/images/frame/motormounted.jpg
--------------------------------------------------------------------------------
/images/frame/mount1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/john4242/grbl-polargraph/94dc599dc19d7b80149ed0138324dceb121be5f4/images/frame/mount1.png
--------------------------------------------------------------------------------
/images/frame/mount2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/john4242/grbl-polargraph/94dc599dc19d7b80149ed0138324dceb121be5f4/images/frame/mount2.png
--------------------------------------------------------------------------------
/images/inkscapegcode/inkscapesave.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/john4242/grbl-polargraph/94dc599dc19d7b80149ed0138324dceb121be5f4/images/inkscapegcode/inkscapesave.png
--------------------------------------------------------------------------------
/images/inkscapegcode/inkscapesaveproperties1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/john4242/grbl-polargraph/94dc599dc19d7b80149ed0138324dceb121be5f4/images/inkscapegcode/inkscapesaveproperties1.png
--------------------------------------------------------------------------------
/images/inkscapegcode/inkscapesaveproperties2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/john4242/grbl-polargraph/94dc599dc19d7b80149ed0138324dceb121be5f4/images/inkscapegcode/inkscapesaveproperties2.png
--------------------------------------------------------------------------------
/images/inkscapegcode/inkscapesaveproperties3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/john4242/grbl-polargraph/94dc599dc19d7b80149ed0138324dceb121be5f4/images/inkscapegcode/inkscapesaveproperties3.png
--------------------------------------------------------------------------------
/images/ugs.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/john4242/grbl-polargraph/94dc599dc19d7b80149ed0138324dceb121be5f4/images/ugs.png
--------------------------------------------------------------------------------
/images/universalgcodesender/connect.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/john4242/grbl-polargraph/94dc599dc19d7b80149ed0138324dceb121be5f4/images/universalgcodesender/connect.png
--------------------------------------------------------------------------------
/images/universalgcodesender/ugsjog.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/john4242/grbl-polargraph/94dc599dc19d7b80149ed0138324dceb121be5f4/images/universalgcodesender/ugsjog.png
--------------------------------------------------------------------------------
/images/universalgcodesender/ugsmacros.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/john4242/grbl-polargraph/94dc599dc19d7b80149ed0138324dceb121be5f4/images/universalgcodesender/ugsmacros.png
--------------------------------------------------------------------------------
/images/universalgcodesender/ugsmain.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/john4242/grbl-polargraph/94dc599dc19d7b80149ed0138324dceb121be5f4/images/universalgcodesender/ugsmain.png
--------------------------------------------------------------------------------
/images/universalgcodesender/ugsparameters.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/john4242/grbl-polargraph/94dc599dc19d7b80149ed0138324dceb121be5f4/images/universalgcodesender/ugsparameters.png
--------------------------------------------------------------------------------
/sample_print_gcodes/hamburger_complex.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
95 |
--------------------------------------------------------------------------------
/sample_print_gcodes/hamburger_simple.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
63 |
--------------------------------------------------------------------------------