├── .gitignore ├── .vscode ├── c_cpp_properties.json ├── extensions.json └── launch.json ├── COPYING ├── 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 ├── media │ ├── COPYING │ ├── Grbl Logo 150px.png │ ├── Grbl Logo 250px.png │ ├── Grbl Logo 320px.png │ ├── Grbl Logo 640px.png │ ├── Grbl Logo.pdf │ └── Grbl Logo.svg └── script │ ├── simple_stream.py │ └── stream.py ├── grbl ├── config.h ├── coolant_control.c ├── coolant_control.h ├── cpu_map.h ├── cpu_map │ ├── cpu_map_atmega2560.h │ ├── cpu_map_atmega2560_ramps14.h │ └── cpu_map_atmega328p.h ├── defaults.h ├── defaults │ ├── defaults_cyclone2_1.h │ ├── defaults_generic.h │ ├── defaults_oxcnc.h │ ├── defaults_pulpitrockcnc.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 ├── fastio.h ├── 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 ├── ramps.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 └── platformio.ini /.gitignore: -------------------------------------------------------------------------------- 1 | *.hex 2 | *.zip 3 | *.o 4 | *.elf 5 | *.DS_Store 6 | *.d 7 | build/* 8 | src/* 9 | .pio/* 10 | 11 | README.md 12 | -------------------------------------------------------------------------------- /.vscode/c_cpp_properties.json: -------------------------------------------------------------------------------- 1 | { 2 | "configurations": [ 3 | { 4 | "name": "!!! WARNING !!! AUTO-GENERATED FILE, PLEASE DO NOT MODIFY IT AND USE https://docs.platformio.org/page/projectconf/section_env_build.html#build-flags" 5 | }, 6 | { 7 | "name": "Win32", 8 | "includePath": [ 9 | "c:/Users/perner/My Projects/grblForRAMPS/grbl", 10 | "C:/Users/perner/.platformio/packages/framework-arduino-avr/cores/arduino", 11 | "C:/Users/perner/.platformio/packages/framework-arduino-avr/variants/mega", 12 | "C:/Users/perner/.platformio/packages/framework-arduino-avr/libraries/EEPROM/src", 13 | "C:/Users/perner/.platformio/packages/framework-arduino-avr/libraries/HID/src", 14 | "C:/Users/perner/.platformio/packages/framework-arduino-avr/libraries/SPI/src", 15 | "C:/Users/perner/.platformio/packages/framework-arduino-avr/libraries/SoftwareSerial/src", 16 | "C:/Users/perner/.platformio/packages/framework-arduino-avr/libraries/Wire/src", 17 | "C:/Users/perner/.platformio/packages/tool-unity", 18 | "" 19 | ], 20 | "browse": { 21 | "limitSymbolsToIncludedHeaders": true, 22 | "path": [ 23 | "c:/Users/perner/My Projects/grblForRAMPS/grbl", 24 | "C:/Users/perner/.platformio/packages/framework-arduino-avr/cores/arduino", 25 | "C:/Users/perner/.platformio/packages/framework-arduino-avr/variants/mega", 26 | "C:/Users/perner/.platformio/packages/framework-arduino-avr/libraries/EEPROM/src", 27 | "C:/Users/perner/.platformio/packages/framework-arduino-avr/libraries/HID/src", 28 | "C:/Users/perner/.platformio/packages/framework-arduino-avr/libraries/SPI/src", 29 | "C:/Users/perner/.platformio/packages/framework-arduino-avr/libraries/SoftwareSerial/src", 30 | "C:/Users/perner/.platformio/packages/framework-arduino-avr/libraries/Wire/src", 31 | "C:/Users/perner/.platformio/packages/tool-unity", 32 | "" 33 | ] 34 | }, 35 | "defines": [ 36 | "PLATFORMIO=40304", 37 | "ARDUINO_AVR_MEGA2560", 38 | "F_CPU=16000000L", 39 | "ARDUINO_ARCH_AVR", 40 | "ARDUINO=10808", 41 | "__AVR_ATmega2560__", 42 | "" 43 | ], 44 | "intelliSenseMode": "clang-x64", 45 | "cStandard": "c11", 46 | "cppStandard": "c++11", 47 | "compilerPath": "C:/Users/perner/.platformio/packages/toolchain-atmelavr/bin/avr-gcc.exe", 48 | "compilerArgs": [ 49 | "-mmcu=atmega2560", 50 | "" 51 | ] 52 | } 53 | ], 54 | "version": 4 55 | } 56 | -------------------------------------------------------------------------------- /.vscode/extensions.json: -------------------------------------------------------------------------------- 1 | { 2 | // See http://go.microsoft.com/fwlink/?LinkId=827846 3 | // for the documentation about the extensions.json format 4 | "recommendations": [ 5 | "platformio.platformio-ide" 6 | ] 7 | } 8 | -------------------------------------------------------------------------------- /.vscode/launch.json: -------------------------------------------------------------------------------- 1 | // AUTOMATICALLY GENERATED FILE. PLEASE DO NOT MODIFY IT MANUALLY 2 | 3 | // PIO Unified Debugger 4 | // 5 | // Documentation: https://docs.platformio.org/page/plus/debugging.html 6 | // Configuration: https://docs.platformio.org/page/projectconf/section_env_debug.html 7 | 8 | { 9 | "version": "0.2.0", 10 | "configurations": [ 11 | { 12 | "type": "platformio-debug", 13 | "request": "launch", 14 | "name": "PIO Debug", 15 | "executable": "c:/Users/perner/My Projects/grblForRAMPS/build/build/megaatmega2560/firmware.elf", 16 | "toolchainBinDir": "C:/Users/perner/.platformio/packages/toolchain-atmelavr/bin", 17 | "preLaunchTask": { 18 | "type": "PlatformIO", 19 | "task": "Pre-Debug" 20 | }, 21 | "internalConsoleOptions": "openOnSessionStart" 22 | }, 23 | { 24 | "type": "platformio-debug", 25 | "request": "launch", 26 | "name": "PIO Debug (skip Pre-Debug)", 27 | "executable": "c:/Users/perner/My Projects/grblForRAMPS/build/build/megaatmega2560/firmware.elf", 28 | "toolchainBinDir": "C:/Users/perner/.platformio/packages/toolchain-atmelavr/bin", 29 | "internalConsoleOptions": "openOnSessionStart" 30 | } 31 | ] 32 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## GRBL 0.9j for Arduino Mega 2560 and RAMPS 1.4 2 | 3 | This port was initally developed by ArSi arsi@arsi.sk but has been enhanced to also support Arduino Mega 2560 + RAMPS 1.4 Board (including limit switches, homing and probing support). 4 | It's based on Grbl v0.9j Atmega328p 16mhz 115200baud with generic defaults (2016-03-17). 5 | 6 | For my home made CNC machine I have connected the limit switches as per the RAMPS 1.4 standard connection and not the grbl standard: 7 | I.e. 8 | ![grbl for ramps limit and probe connection](https://user-images.githubusercontent.com/942356/51804562-c217f480-2262-11e9-9f21-33e7b92b00d6.png) 9 | 10 | This is the key configuration parameters for making both limit switching and probing working on my RAMPS 1.4 CNC machine: 11 | [grbl RAMPS 1.4 config parameters](/grbl/defaults/defaults_pulpitrockcnc.h) 12 | ``` 13 | #define DEFAULT_INVERT_ST_ENABLE 0 // false 14 | #define DEFAULT_INVERT_LIMIT_PINS 0 // false 15 | // Uses software limits in the firmware to keep the printer from going too far in the opposite direction and hardware endstops for min 16 | #define DEFAULT_SOFT_LIMIT_ENABLE 1 // true 17 | #define DEFAULT_HARD_LIMIT_ENABLE 1 // true 18 | #define DEFAULT_HOMING_ENABLE 1 // true 19 | #define DEFAULT_HOMING_DIR_MASK ((1< 2 | 16 | 18 | 19 | 21 | image/svg+xml 22 | 24 | 25 | 26 | 27 | 28 | 48 | /Users/chamnit/Dropbox/documents/OHS/Logo/Grbl.DXF - scale = 58.043118, origin = (0.000000, 0.000000), auto = True 50 | 52 | 58 | 62 | 63 | 70 | 76 | 82 | 88 | 89 | 91 | 93 | 95 | 96 | 100 | 103 | 109 | 115 | 121 | 127 | 132 | 133 | 134 | 135 | -------------------------------------------------------------------------------- /doc/script/simple_stream.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | """\ 3 | Simple g-code streaming script for grbl 4 | 5 | Provided as an illustration of the basic communication interface 6 | for grbl. When grbl has finished parsing the g-code block, it will 7 | return an 'ok' or 'error' response. When the planner buffer is full, 8 | grbl will not send a response until the planner buffer clears space. 9 | 10 | G02/03 arcs are special exceptions, where they inject short line 11 | segments directly into the planner. So there may not be a response 12 | from grbl for the duration of the arc. 13 | 14 | --------------------- 15 | The MIT License (MIT) 16 | 17 | Copyright (c) 2012 Sungeun K. Jeon 18 | 19 | Permission is hereby granted, free of charge, to any person obtaining a copy 20 | of this software and associated documentation files (the "Software"), to deal 21 | in the Software without restriction, including without limitation the rights 22 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 23 | copies of the Software, and to permit persons to whom the Software is 24 | furnished to do so, subject to the following conditions: 25 | 26 | The above copyright notice and this permission notice shall be included in 27 | all copies or substantial portions of the Software. 28 | 29 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 30 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 31 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 32 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 33 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 34 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 35 | THE SOFTWARE. 36 | --------------------- 37 | """ 38 | 39 | import serial 40 | import time 41 | 42 | # Open grbl serial port 43 | s = serial.Serial('/dev/tty.usbmodem1811',115200) 44 | 45 | # Open g-code file 46 | f = open('grbl.gcode','r'); 47 | 48 | # Wake up grbl 49 | s.write("\r\n\r\n") 50 | time.sleep(2) # Wait for grbl to initialize 51 | s.flushInput() # Flush startup text in serial input 52 | 53 | # Stream g-code to grbl 54 | for line in f: 55 | l = line.strip() # Strip all EOL characters for consistency 56 | print 'Sending: ' + l, 57 | s.write(l + '\n') # Send g-code block to grbl 58 | grbl_out = s.readline() # Wait for grbl response with carriage return 59 | print ' : ' + grbl_out.strip() 60 | 61 | # Wait here until grbl is finished to close serial port and file. 62 | raw_input(" Press to exit and disable grbl.") 63 | 64 | # Close file and serial port 65 | f.close() 66 | s.close() -------------------------------------------------------------------------------- /doc/script/stream.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | """\ 3 | 4 | Stream g-code to grbl controller 5 | 6 | This script differs from the simple_stream.py script by 7 | tracking the number of characters in grbl's serial read 8 | buffer. This allows grbl to fetch the next line directly 9 | from the serial buffer and does not have to wait for a 10 | response from the computer. This effectively adds another 11 | buffer layer to prevent buffer starvation. 12 | 13 | CHANGELOG: 14 | - 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_ATMEGA2560_RAMPS_1_4 // (Arduino Mega 2560)+Ramps1.4 Working Arsi 41 | #include "cpu_map/cpu_map_atmega2560_ramps14.h" 42 | #endif 43 | 44 | /* 45 | #ifdef CPU_MAP_CUSTOM_PROC 46 | // For a custom pin map or different processor, copy and edit one of the available cpu 47 | // map files and modify it to your needs. Make sure the defined name is also changed in 48 | // the config.h file. 49 | #endif 50 | */ 51 | 52 | #endif 53 | -------------------------------------------------------------------------------- /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 | /* This cpu_map file serves as a central pin mapping settings file for AVR Mega 2560 + RAMPS 1.4 22 | PIN Mapping can be found here: https://www.arduino.cc/en/Hacking/PinMapping2560 23 | */ 24 | 25 | 26 | #ifdef GRBL_PLATFORM 27 | #error "cpu_map already defined: GRBL_PLATFORM=" GRBL_PLATFORM 28 | #endif 29 | 30 | 31 | #define GRBL_PLATFORM "Atmega2560_Ramps14" 32 | 33 | // Serial port pins 34 | #define SERIAL_RX USART0_RX_vect 35 | #define SERIAL_UDRE USART0_UDRE_vect 36 | 37 | // Increase Buffers to make use of extra SRAM 38 | //#define RX_BUFFER_SIZE 256 39 | //#define TX_BUFFER_SIZE 128 40 | //#define BLOCK_BUFFER_SIZE 36 41 | //#define LINE_BUFFER_SIZE 100 42 | 43 | // Define step pulse output pins. 44 | // NOTE: Originally grbl require that all step bit pins must be on the same port. 45 | // HOWEVER: X and Y is on same port while Z is on another, therefore a special method from ramps.h is needed 46 | #define X_STEP_BIT 0 // Position within the STEP MASK 47 | #define Y_STEP_BIT 1 // Position within the STEP MASK 48 | #define Z_STEP_BIT 2 // Position within the STEP MASK 49 | #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 | /* 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_GENERIC 34 | // Grbl generic default settings. Should work across different machines. 35 | #include "defaults/defaults_generic.h" 36 | #endif 37 | 38 | #ifdef DEFAULTS_SHERLINE_5400 39 | // Description: Sherline 5400 mill with three NEMA 23 Keling KL23H256-21-8B 185 oz-in stepper motors, 40 | // driven by three Pololu A4988 stepper drivers with a 30V, 6A power supply at 1.5A per winding. 41 | #include "defaults/defaults_sherline.h" 42 | #endif 43 | 44 | #ifdef DEFAULTS_SHAPEOKO 45 | // Description: Shapeoko CNC mill with three NEMA 17 stepper motors, driven by Synthetos 46 | // grblShield with a 24V, 4.2A power supply. 47 | #include "defaults/defaults_shapeoko.h" 48 | #endif 49 | 50 | #ifdef DEFAULTS_SHAPEOKO_2 51 | // Description: Shapeoko CNC mill with three NEMA 17 stepper motors, driven by Synthetos 52 | // grblShield at 28V. 53 | #include "defaults/defaults_shapeoko2.h" 54 | #endif 55 | 56 | #ifdef DEFAULTS_SHAPEOKO_3 57 | // Description: Shapeoko CNC mill with three NEMA 23 stepper motors, driven by CarbideMotion 58 | #include "defaults/defaults_shapeoko3.h" 59 | #endif 60 | 61 | #ifdef DEFAULTS_X_CARVE_500MM 62 | // Description: X-Carve 3D Carver CNC mill with three 200 step/rev motors driven by Synthetos 63 | // grblShield at 24V. 64 | #include "defaults/defaults_x_carve_500mm.h" 65 | #endif 66 | 67 | #ifdef DEFAULTS_X_CARVE_1000MM 68 | // Description: X-Carve 3D Carver CNC mill with three 200 step/rev motors driven by Synthetos 69 | // grblShield at 24V. 70 | #include "defaults/defaults_x_carve_1000mm.h" 71 | #endif 72 | 73 | #ifdef DEFAULTS_ZEN_TOOLWORKS_7x7 74 | // Description: Zen Toolworks 7x7 mill with three Shinano SST43D2121 65oz-in NEMA 17 stepper motors. 75 | // Leadscrew is different from some ZTW kits, where most are 1.25mm/rev rather than 8.0mm/rev here. 76 | // Driven by 30V, 6A power supply and TI DRV8811 stepper motor drivers. 77 | #include "defaults/defaults_zen_toolworks_7x7.h" 78 | #endif 79 | 80 | #ifdef DEFAULTS_OXCNC 81 | // Grbl settings for OpenBuilds OX CNC Machine 82 | // http://www.openbuilds.com/builds/openbuilds-ox-cnc-machine.341/ 83 | #include "defaults/defaults_oxcnc.h" 84 | #endif 85 | 86 | #ifdef DEFAULTS_SIMULATOR 87 | // Settings only for Grbl Simulator (www.github.com/grbl/grbl-sim) 88 | #include "defaults/defaults_simulator.h" 89 | #endif 90 | 91 | #ifdef DEFAULTS_CYCLONE_2_1 92 | // Description: GRBL settings for Cyclone PCB Factory v2.1 93 | // http://reprap.org/wiki/Cyclone_PCB_Factory 94 | #include "defaults/defaults_cyclone2_1.h" 95 | #endif 96 | 97 | #ifdef DEFAULTS_PULPITROCKCNC 98 | // Grbl settings for the RAMPS 1.4 based PulpitRockCNC machine v1.0. 99 | #include "defaults/defaults_pulpitrockcnc.h" 100 | #endif 101 | 102 | #endif 103 | -------------------------------------------------------------------------------- /grbl/defaults/defaults_cyclone2_1.h: -------------------------------------------------------------------------------- 1 | /* 2 | defaults_cyclone2_1.h - GRBL settings for Cyclone PCB Factory v2.1 3 | http://reprap.org/wiki/Cyclone_PCB_Factory 4 | Part of Grbl 5 | 6 | Copyright (c) 2012-2015 Sungeun K. Jeon 7 | 8 | Grbl is free software: you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License as published by 10 | the Free Software Foundation, either version 3 of the License, or 11 | (at your option) any later version. 12 | 13 | Grbl is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with Grbl. If not, see . 20 | */ 21 | 22 | /* The defaults.h file serves as a central default settings file for different machine 23 | types, from DIY CNC mills to CNC conversions of off-the-shelf machines. The settings 24 | here are supplied by users, so your results may vary. However, this should give you 25 | a good starting point as you get to know your machine and tweak the settings for your 26 | nefarious needs. */ 27 | 28 | #ifndef defaults_h 29 | #define defaults_h 30 | 31 | // Description: GRBL settings for Cyclone PCB Factory v2.1 32 | // http://reprap.org/wiki/Cyclone_PCB_Factory 33 | #define MICROSTEPS 16 // 16 --> all three jumpers installed 34 | #define STEPS_PER_REV 200.0 35 | #define MM_PER_REV 1.25 // 1.25 mm/rev leadscrew 36 | #define Cyclone_XY_Gear_Ratio 21.0/21.0 // Number of gear teeth (motor/rod) 37 | #define Cyclone_Z_Gear_Ratio 8.0/15.0 // Number of gear teeth (motor/rod) 38 | #define DEFAULT_X_STEPS_PER_MM (STEPS_PER_REV*MICROSTEPS/(Cyclone_XY_Gear_Ratio*MM_PER_REV)) 39 | #define DEFAULT_Y_STEPS_PER_MM (STEPS_PER_REV*MICROSTEPS/(Cyclone_XY_Gear_Ratio*MM_PER_REV)) 40 | #define DEFAULT_Z_STEPS_PER_MM (STEPS_PER_REV*MICROSTEPS/(Cyclone_Z_Gear_Ratio*MM_PER_REV)) 41 | #define DEFAULT_X_MAX_RATE 5*60.0 // mm/min 42 | #define DEFAULT_Y_MAX_RATE 5*60.0 // mm/min 43 | #define DEFAULT_Z_MAX_RATE 2.5*60.0 // mm/min 44 | #define DEFAULT_X_ACCELERATION (16.0*60*60) // 50*60*60 mm/min^2 = 50 mm/sec^2 45 | #define DEFAULT_Y_ACCELERATION (16.0*60*60) // 50*60*60 mm/min^2 = 50 mm/sec^2 46 | #define DEFAULT_Z_ACCELERATION (16.0*60*60) // 50*60*60 mm/min^2 = 50 mm/sec^2 47 | #define DEFAULT_X_MAX_TRAVEL 168.0 // mm 48 | #define DEFAULT_Y_MAX_TRAVEL 101.0 // mm 49 | #define DEFAULT_Z_MAX_TRAVEL 50.0 // mm 50 | #define DEFAULT_STEP_PULSE_MICROSECONDS 10 51 | #define DEFAULT_STEPPING_INVERT_MASK 0 52 | #define DEFAULT_DIRECTION_INVERT_MASK ((0<. 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_pulpitrockcnc.h: -------------------------------------------------------------------------------- 1 | /* 2 | defaults_pulpitrockcnc.h - Grbl settings for the PulpitRockCNC machine based RAMPS1.4 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 the PulpitRockCNC 31 | #define MICROSTEPS 16 // 16 --> all three jumpers installed 32 | #define STEPS_PER_REV 200.0 33 | #define MM_PER_REV 1.25 // 1.25 mm/rev leadscrew 34 | #define DEFAULT_X_STEPS_PER_MM (STEPS_PER_REV*MICROSTEPS/MM_PER_REV) 35 | #define DEFAULT_Y_STEPS_PER_MM (STEPS_PER_REV*MICROSTEPS/MM_PER_REV) 36 | #define DEFAULT_Z_STEPS_PER_MM (STEPS_PER_REV*MICROSTEPS/MM_PER_REV) 37 | #define DEFAULT_X_MAX_RATE 7*60.0 // mm/min, cyclone:5, 7 is max for Pulpit Rock CNC 38 | #define DEFAULT_Y_MAX_RATE 7*60.0 // mm/min, cyclone:5, 7 is max for Pulpit Rock CNC 39 | #define DEFAULT_Z_MAX_RATE 7*60.0 // mm/min, cyclone:2.5, 7 is max for Pulpit Rock CNC 40 | #define DEFAULT_X_ACCELERATION (16.0*60*60) // 50*60*60 mm/min^2 = 50 mm/sec^2 41 | #define DEFAULT_Y_ACCELERATION (16.0*60*60) // 50*60*60 mm/min^2 = 50 mm/sec^2 42 | #define DEFAULT_Z_ACCELERATION (16.0*60*60) // 50*60*60 mm/min^2 = 50 mm/sec^2 43 | // The Pulpit Rock CNC has the following dimensions: 44 | // X Min = 0 45 | // X Max = 365 46 | // Y Min = 0 47 | // Y Max = 234 48 | // Z Min = 0 49 | // Z Max = 123 50 | #define DEFAULT_X_MAX_TRAVEL 360.0 // mm 360.0 51 | #define DEFAULT_Y_MAX_TRAVEL 230.0 // mm 230.0 52 | #define DEFAULT_Z_MAX_TRAVEL 134.0 // mm (from 0 to -135) 134.0 53 | #define DEFAULT_STEP_PULSE_MICROSECONDS 10 54 | #define DEFAULT_STEPPING_INVERT_MASK 0 55 | #define DEFAULT_DIRECTION_INVERT_MASK ((0<. 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" 26 | #define GRBL_VERSION_BUILD "20160317" 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 | // Called when the limit interrupt method(s) are triggered 42 | void limits_interrupt_triggered(); 43 | 44 | // Called when the limit interrupt method(s) are triggered, using a delay. 45 | void limits_interrupt_triggered_delayed(); 46 | 47 | // Indicate hard limit critical event 48 | void hard_limit_critical_event(); 49 | 50 | #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 | // Check for power-up and set system alarm if homing is enabled to force homing cycle 42 | // by setting Grbl's alarm state. Alarm locks out all g-code commands, including the 43 | // startup scripts, but allows access to settings and internal commands. Only a homing 44 | // cycle '$H' or kill alarm locks '$X' will disable the alarm. 45 | // NOTE: The startup script will run after successful completion of the homing cycle, but 46 | // not after disabling the alarm locks. Prevents motion startup blocks from crashing into 47 | // things uncontrollably. Very bad. 48 | #ifdef HOMING_INIT_LOCK 49 | if (bit_istrue(settings.flags,BITFLAG_HOMING_ENABLE)) { sys.state = STATE_ALARM; } 50 | #endif 51 | 52 | // Force Grbl into an ALARM state upon a power-cycle or hard reset. 53 | #ifdef FORCE_INITIALIZATION_ALARM 54 | sys.state = STATE_ALARM; 55 | #endif 56 | 57 | // Grbl initialization loop upon power-up or a system abort. For the latter, all processes 58 | // will return to this loop to be cleanly re-initialized. 59 | for(;;) { 60 | 61 | // TODO: Separate configure task that require interrupts to be disabled, especially upon 62 | // a system abort and ensuring any active interrupts are cleanly reset. 63 | 64 | // Reset Grbl primary systems. 65 | serial_reset_read_buffer(); // Clear serial read buffer 66 | gc_init(); // Set g-code parser to default state 67 | spindle_init(); 68 | coolant_init(); 69 | limits_init(); 70 | probe_init(); 71 | plan_reset(); // Clear block buffer and planner variables 72 | st_reset(); // Clear stepper subsystem variables. 73 | 74 | // Sync cleared gcode and planner positions to current system position. 75 | plan_sync_position(); 76 | gc_sync_position(); 77 | 78 | // Reset system variables. 79 | sys.abort = false; 80 | sys_rt_exec_state = 0; 81 | sys_rt_exec_alarm = 0; 82 | sys.suspend = false; 83 | sys.soft_limit = false; 84 | 85 | // Start Grbl main loop. Processes program inputs and executes them. 86 | protocol_main_loop(); 87 | 88 | } 89 | return 0; /* Never reached */ 90 | } 91 | -------------------------------------------------------------------------------- /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 | // Conversions 43 | #define MM_PER_INCH (25.40) 44 | #define INCH_PER_MM (0.0393701) 45 | #define TICKS_PER_MICROSECOND (F_CPU/1000000) 46 | 47 | // Useful macros 48 | #define clear_vector(a) memset(a, 0, sizeof(a)) 49 | #define clear_vector_float(a) memset(a, 0.0, sizeof(float)*N_AXIS) 50 | // #define clear_vector_long(a) memset(a, 0.0, sizeof(long)*N_AXIS) 51 | #define max(a,b) (((a) > (b)) ? (a) : (b)) 52 | #define min(a,b) (((a) < (b)) ? (a) : (b)) 53 | 54 | // Bit field and masking macros 55 | #define bit(n) (1 << n) 56 | #define bit_true_atomic(x,mask) {uint8_t sreg = SREG; cli(); (x) |= (mask); SREG = sreg; } 57 | #define bit_false_atomic(x,mask) {uint8_t sreg = SREG; cli(); (x) &= ~(mask); SREG = sreg; } 58 | #define bit_toggle_atomic(x,mask) {uint8_t sreg = SREG; cli(); (x) ^= (mask); SREG = sreg; } 59 | #define bit_true(x,mask) (x) |= (mask) 60 | #define bit_false(x,mask) (x) &= ~(mask) 61 | #define bit_istrue(x,mask) ((x & mask) != 0) 62 | #define bit_isfalse(x,mask) ((x & mask) == 0) 63 | 64 | // Read a floating point value from a string. Line points to the input buffer, char_counter 65 | // is the indexer pointing to the current character of the line, while float_ptr is 66 | // a pointer to the result variable. Returns true when it succeeds 67 | uint8_t read_float(char *line, uint8_t *char_counter, float *float_ptr); 68 | 69 | // Delays variable-defined milliseconds. Compiler compatibility fix for _delay_ms(). 70 | void delay_ms(uint16_t ms); 71 | 72 | // Delays variable-defined microseconds. Compiler compatibility fix for _delay_us(). 73 | void delay_us(uint32_t us); 74 | 75 | // Computes hypotenuse, avoiding avr-gcc's bloated version and the extra error checking. 76 | float hypot_f(float x, float y); 77 | 78 | #endif 79 | -------------------------------------------------------------------------------- /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/ramps.h: -------------------------------------------------------------------------------- 1 | /* 2 | * File: ramps.h 3 | * Author: arsi 4 | * Enchanced by: Per Ivar Nerseth perivar@nerseth.com 5 | * 6 | * Created on September 1, 2014, 4:44 PM - arsi 7 | * Cleanup and enhanced to support both soft and hard limits, March 2016 - perivar 8 | */ 9 | #ifndef RAMPS_H 10 | #define RAMPS_H 11 | 12 | // Used to debug the limit switches 13 | //#define RAMPS_DEBUG_LIMIT_SWITCHES 14 | 15 | #ifdef __cplusplus 16 | extern "C" { 17 | #endif 18 | 19 | #include 20 | #include "cpu_map.h" 21 | #include 22 | #include "fastio.h" 23 | 24 | #define CHECK(var,pos) ((var) & (1<<(pos))) 25 | 26 | /** 27 | * Initialize the steppers (Step, Dir and Enable Pins) 28 | */ 29 | inline void rampsInitSteppers() { 30 | 31 | // Initialize Step Pins 32 | #if defined(X_STEP_PIN) && X_STEP_PIN > -1 33 | SET_OUTPUT(X_STEP_PIN); 34 | #endif 35 | #if defined(Y_STEP_PIN) && Y_STEP_PIN > -1 36 | SET_OUTPUT(Y_STEP_PIN); 37 | #endif 38 | #if defined(Z_STEP_PIN) && Z_STEP_PIN > -1 39 | SET_OUTPUT(Z_STEP_PIN); 40 | #endif 41 | 42 | // Initialize Dir Pins 43 | #if defined(X_DIR_PIN) && X_DIR_PIN > -1 44 | SET_OUTPUT(X_DIR_PIN); 45 | #endif 46 | #if defined(Y_DIR_PIN) && Y_DIR_PIN > -1 47 | SET_OUTPUT(Y_DIR_PIN); 48 | #endif 49 | #if defined(Z_DIR_PIN) && Z_DIR_PIN > -1 50 | SET_OUTPUT(Z_DIR_PIN); 51 | #endif 52 | 53 | // Initialize Enable Pins 54 | #if defined(X_ENABLE_PIN) && X_ENABLE_PIN > -1 55 | SET_OUTPUT(X_ENABLE_PIN); 56 | #endif 57 | #if defined(Y_ENABLE_PIN) && Y_ENABLE_PIN > -1 58 | SET_OUTPUT(Y_ENABLE_PIN); 59 | #endif 60 | #if defined(Z_ENABLE_PIN) && Z_ENABLE_PIN > -1 61 | SET_OUTPUT(Z_ENABLE_PIN); 62 | #endif 63 | } 64 | 65 | /** 66 | * Set the Enable Pin signal (either to high or low) 67 | * @param value 68 | */ 69 | inline void rampsWriteDisable(uint8_t value) { 70 | if (CHECK(value, STEPPERS_DISABLE_BIT)) { 71 | WRITE(X_ENABLE_PIN, HIGH); 72 | WRITE(Y_ENABLE_PIN, HIGH); 73 | WRITE(Z_ENABLE_PIN, HIGH); 74 | } else { 75 | WRITE(X_ENABLE_PIN, LOW); 76 | WRITE(Y_ENABLE_PIN, LOW); 77 | WRITE(Z_ENABLE_PIN, LOW); 78 | } 79 | } 80 | 81 | /** 82 | * Write stepper pulse (Step Pins) 83 | * @param value 84 | */ 85 | inline void rampsWriteSteps(uint8_t value) { 86 | if (CHECK(value, X_STEP_BIT)) { 87 | WRITE(X_STEP_PIN, HIGH); 88 | } else { 89 | WRITE(X_STEP_PIN, LOW); 90 | } 91 | if (CHECK(value, Y_STEP_BIT)) { 92 | WRITE(Y_STEP_PIN, HIGH); 93 | } else { 94 | WRITE(Y_STEP_PIN, LOW); 95 | } 96 | if (CHECK(value, Z_STEP_BIT)) { 97 | WRITE(Z_STEP_PIN, HIGH); 98 | } else { 99 | WRITE(Z_STEP_PIN, LOW); 100 | } 101 | } 102 | 103 | /** 104 | * Write stepper direction (Direction Pins) 105 | * @param value 106 | */ 107 | inline void rampsWriteDirections(uint8_t value) { 108 | if (CHECK(value, X_DIRECTION_BIT)) { 109 | WRITE(X_DIR_PIN, HIGH); 110 | } else { 111 | WRITE(X_DIR_PIN, LOW); 112 | } 113 | if (CHECK(value, Y_DIRECTION_BIT)) { 114 | WRITE(Y_DIR_PIN, HIGH); 115 | } else { 116 | WRITE(Y_DIR_PIN, LOW); 117 | } 118 | if (CHECK(value, Z_DIRECTION_BIT)) { 119 | WRITE(Z_DIR_PIN, LOW); 120 | } else { 121 | WRITE(Z_DIR_PIN, HIGH); 122 | } 123 | } 124 | 125 | /** 126 | * Enable interrupts for the limit switches 127 | */ 128 | inline void rampsLimitsEnableInterrups() { 129 | 130 | // First enable the External Interrupts 131 | // When changing the ISCn bit, an interrupt can occur. Therefore, it is recommended to: 132 | // 1. First disable INTn by clearing its Interrupt Enable bit in the EIMSK Register. 133 | // 2. Then, the ISCn bit can be changed. 134 | // 3. Finally, the INTn interrupt flag should be cleared by writing a logical one to its Interrupt Flag bit (INTFn) in the EIFR Register 135 | // 4. Before the interrupt is re-enabled. 136 | 137 | // X_MIN_PIN uses External Interrupt 138 | #if defined(X_MIN_PIN) && X_MIN_PIN > -1 139 | EIMSK &= ~(1 << X_MIN_INT); // Disable external interrupt INT5 to ensure no interrupts are generated 140 | X_MIN_ICR &= ~(1 << X_MIN_ISCX1); // Set INT5 to trigger on ANY logic change (bit 1 = 0) 141 | X_MIN_ICR |= (1 << X_MIN_ISCX0); // Set INT5 to trigger on ANY logic change (bit 0 = 1) 142 | EIFR = (1 << X_MIN_FR); // Clear flag for INT5 (by writing a logical one) to clear any pending interrupts 143 | EIMSK |= (1 << X_MIN_INT); // Enable external interrupt INT5 144 | #endif 145 | 146 | // Z_MAX_PIN uses External Interrupt 147 | #if defined(Z_MAX_PIN) && Z_MAX_PIN > -1 148 | EIMSK &= ~(1 << Z_MAX_INT); // Disable external interrupt INT2 to ensure no interrupts are generated 149 | Z_MAX_ICR &= ~(1 << Z_MAX_ISCX1); // Set INT2 to trigger on ANY logic change (bit 1 = 0) 150 | Z_MAX_ICR |= (1 << Z_MAX_ISCX0); // Set INT2 to trigger on ANY logic change (bit 0 = 1) 151 | EIFR = (1 << Z_MAX_FR); // Clear flag for INT2 (by writing a logical one) to clear any pending interrupts 152 | EIMSK |= (1 << Z_MAX_INT); // Enable external interrupt INT2 153 | #endif 154 | 155 | // And then enable the Pin Change Interrupt 156 | // Y_MIN_PIN uses Pin Change Interrupt 157 | #if defined(Y_MIN_PIN) && Y_MIN_PIN > -1 158 | Y_MIN_PCMSK |= (1 << Y_MIN_PCI); // Set PCINT10 to trigger an interrupt on state change 159 | PCIFR = (1 << Y_MIN_FR); // Clear flag (by writing a logical one) to clear any pending interrupts 160 | PCICR |= (1 << Y_MIN_INT); // Set PCIE1 to enable PCMSK1 scan, i.e. enable interrupts for PCINT15:8 161 | #endif 162 | } 163 | 164 | /** 165 | * Disable interrupts for the limit switches 166 | */ 167 | inline void rampsLimitsDisableInterrups() { 168 | 169 | #if defined(X_MIN_PIN) && X_MIN_PIN > -1 170 | EIMSK &= ~(1 << X_MIN_INT); // Disable external interrupt INT5 to ensure no interrupts are generated 171 | EIFR = (1 << X_MIN_FR); // Clear flag for INT5 (by writing a logical one) to clear any pending interrupts 172 | #endif 173 | 174 | #if defined(Z_MAX_PIN) && Z_MAX_PIN > -1 175 | EIMSK &= ~(1 << Z_MAX_INT); // Disable external interrupt INT2 to ensure no interrupts are generated 176 | EIFR = (1 << Z_MAX_FR); // Clear flag for INT2 (by writing a logical one) to clear any pending interrupts 177 | #endif 178 | 179 | #if defined(Y_MIN_PIN) && Y_MIN_PIN > -1 180 | Y_MIN_PCMSK &= ~(1 << Y_MIN_PCI); // Disable PCINT10 Interrupt 181 | PCIFR = (1 << Y_MIN_FR); // Clear flag (by writing a logical one) to clear any pending interrupts 182 | #endif 183 | } 184 | 185 | /** 186 | * Enable the limit switches 187 | * @param value whether hard limits should be enabled 188 | */ 189 | inline void rampsInitLimits(bool hardLimitEnable) { 190 | 191 | #if defined(X_MIN_PIN) && X_MIN_PIN > -1 192 | SET_INPUT(X_MIN_PIN); 193 | #ifdef DISABLE_LIMIT_PIN_PULL_UP 194 | WRITE(X_MIN_PIN, LOW); // Normal low operation. Requires external pull-down. 195 | #else 196 | WRITE(X_MIN_PIN, HIGH); // Enable internal pull-up resistors. Normal high operation. 197 | #endif 198 | #endif 199 | #if defined(Y_MIN_PIN) && Y_MIN_PIN > -1 200 | SET_INPUT(Y_MIN_PIN); 201 | #ifdef DISABLE_LIMIT_PIN_PULL_UP 202 | WRITE(Y_MIN_PIN, LOW); // Normal low operation. Requires external pull-down. 203 | #else 204 | WRITE(Y_MIN_PIN, HIGH); // Enable internal pull-up resistors. Normal high operation. 205 | #endif 206 | #endif 207 | #if defined(Z_MAX_PIN) && Z_MAX_PIN > -1 208 | SET_INPUT(Z_MAX_PIN); 209 | #ifdef DISABLE_LIMIT_PIN_PULL_UP 210 | WRITE(Z_MAX_PIN, LOW); // Normal low operation. Requires external pull-down. 211 | #else 212 | WRITE(Z_MAX_PIN, HIGH); // Enable internal pull-up resistors. Normal high operation. 213 | #endif 214 | #endif 215 | 216 | if (hardLimitEnable) { 217 | // enable interrupts for the limit switches 218 | rampsLimitsEnableInterrups(); 219 | } else { 220 | // disable interrupts for the limit switches 221 | rampsLimitsDisableInterrups(); 222 | } 223 | } 224 | 225 | /** 226 | * Return the limit status following the LIMIT_MASK. 227 | * e.g. X_AXIS is (1<<2) or bit 2, Y_AXIS is (1<<1) or bit 1 and Z_AXIS is (1<<0) or bit 0 228 | * @return the status on the limit switches as a uint8_t 229 | */ 230 | inline uint8_t rampsCheckLimits() { 231 | // TODO: wrap witin a "#if defined(___MIN_PIN) && ___MIN_PIN > -1)" clause 232 | return ((READ(X_MIN_PIN)<. 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 | 74 | settings.flags = 0; 75 | if (DEFAULT_REPORT_INCHES) { settings.flags |= BITFLAG_REPORT_INCHES; } 76 | if (DEFAULT_INVERT_ST_ENABLE) { settings.flags |= BITFLAG_INVERT_ST_ENABLE; } 77 | if (DEFAULT_INVERT_LIMIT_PINS) { settings.flags |= BITFLAG_INVERT_LIMIT_PINS; } 78 | if (DEFAULT_SOFT_LIMIT_ENABLE) { settings.flags |= BITFLAG_SOFT_LIMIT_ENABLE; } 79 | if (DEFAULT_HARD_LIMIT_ENABLE) { settings.flags |= BITFLAG_HARD_LIMIT_ENABLE; } 80 | if (DEFAULT_HOMING_ENABLE) { settings.flags |= BITFLAG_HOMING_ENABLE; } 81 | 82 | settings.steps_per_mm[X_AXIS] = DEFAULT_X_STEPS_PER_MM; 83 | settings.steps_per_mm[Y_AXIS] = DEFAULT_Y_STEPS_PER_MM; 84 | settings.steps_per_mm[Z_AXIS] = DEFAULT_Z_STEPS_PER_MM; 85 | settings.max_rate[X_AXIS] = DEFAULT_X_MAX_RATE; 86 | settings.max_rate[Y_AXIS] = DEFAULT_Y_MAX_RATE; 87 | settings.max_rate[Z_AXIS] = DEFAULT_Z_MAX_RATE; 88 | settings.acceleration[X_AXIS] = DEFAULT_X_ACCELERATION; 89 | settings.acceleration[Y_AXIS] = DEFAULT_Y_ACCELERATION; 90 | settings.acceleration[Z_AXIS] = DEFAULT_Z_ACCELERATION; 91 | settings.max_travel[X_AXIS] = (-DEFAULT_X_MAX_TRAVEL); 92 | settings.max_travel[Y_AXIS] = (-DEFAULT_Y_MAX_TRAVEL); 93 | settings.max_travel[Z_AXIS] = (-DEFAULT_Z_MAX_TRAVEL); 94 | 95 | write_global_settings(); 96 | } 97 | 98 | if (restore_flag & SETTINGS_RESTORE_PARAMETERS) { 99 | uint8_t idx; 100 | float coord_data[N_AXIS]; 101 | memset(&coord_data, 0, sizeof(coord_data)); 102 | for (idx=0; idx <= SETTING_INDEX_NCOORD; idx++) { settings_write_coord_data(idx, coord_data); } 103 | } 104 | 105 | if (restore_flag & SETTINGS_RESTORE_STARTUP_LINES) { 106 | #if N_STARTUP_LINE > 0 107 | eeprom_put_char(EEPROM_ADDR_STARTUP_BLOCK, 0); 108 | #endif 109 | #if N_STARTUP_LINE > 1 110 | eeprom_put_char(EEPROM_ADDR_STARTUP_BLOCK+(LINE_BUFFER_SIZE+1), 0); 111 | #endif 112 | } 113 | 114 | if (restore_flag & SETTINGS_RESTORE_BUILD_INFO) { eeprom_put_char(EEPROM_ADDR_BUILD_INFO , 0); } 115 | } 116 | 117 | 118 | // Reads startup line from EEPROM. Updated pointed line string data. 119 | uint8_t settings_read_startup_line(uint8_t n, char *line) 120 | { 121 | uint32_t addr = n*(LINE_BUFFER_SIZE+1)+EEPROM_ADDR_STARTUP_BLOCK; 122 | if (!(memcpy_from_eeprom_with_checksum((char*)line, addr, LINE_BUFFER_SIZE))) { 123 | // Reset line with default value 124 | line[0] = 0; // Empty line 125 | settings_store_startup_line(n, line); 126 | return(false); 127 | } 128 | return(true); 129 | } 130 | 131 | 132 | // Reads startup line from EEPROM. Updated pointed line string data. 133 | uint8_t settings_read_build_info(char *line) 134 | { 135 | if (!(memcpy_from_eeprom_with_checksum((char*)line, EEPROM_ADDR_BUILD_INFO, LINE_BUFFER_SIZE))) { 136 | // Reset line with default value 137 | line[0] = 0; // Empty line 138 | settings_store_build_info(line); 139 | return(false); 140 | } 141 | return(true); 142 | } 143 | 144 | 145 | // Read selected coordinate data from EEPROM. Updates pointed coord_data value. 146 | uint8_t settings_read_coord_data(uint8_t coord_select, float *coord_data) 147 | { 148 | uint32_t addr = coord_select*(sizeof(float)*N_AXIS+1) + EEPROM_ADDR_PARAMETERS; 149 | if (!(memcpy_from_eeprom_with_checksum((char*)coord_data, addr, sizeof(float)*N_AXIS))) { 150 | // Reset with default zero vector 151 | clear_vector_float(coord_data); 152 | settings_write_coord_data(coord_select,coord_data); 153 | return(false); 154 | } 155 | return(true); 156 | } 157 | 158 | 159 | // Reads Grbl global settings struct from EEPROM. 160 | uint8_t read_global_settings() { 161 | // Check version-byte of eeprom 162 | uint8_t version = eeprom_get_char(0); 163 | if (version == SETTINGS_VERSION) { 164 | // Read settings-record and check checksum 165 | if (!(memcpy_from_eeprom_with_checksum((char*)&settings, EEPROM_ADDR_GLOBAL, sizeof(settings_t)))) { 166 | return(false); 167 | } 168 | } else { 169 | return(false); 170 | } 171 | return(true); 172 | } 173 | 174 | 175 | // A helper method to set settings from command line 176 | uint8_t settings_store_global_setting(uint8_t parameter, float value) { 177 | if (value < 0.0) { return(STATUS_NEGATIVE_VALUE); } 178 | if (parameter >= AXIS_SETTINGS_START_VAL) { 179 | // Store axis configuration. Axis numbering sequence set by AXIS_SETTING defines. 180 | // NOTE: Ensure the setting index corresponds to the report.c settings printout. 181 | parameter -= AXIS_SETTINGS_START_VAL; 182 | uint8_t set_idx = 0; 183 | while (set_idx < AXIS_N_SETTINGS) { 184 | if (parameter < N_AXIS) { 185 | // Valid axis setting found. 186 | switch (set_idx) { 187 | case 0: 188 | #ifdef MAX_STEP_RATE_HZ 189 | if (value*settings.max_rate[parameter] > (MAX_STEP_RATE_HZ*60.0)) { return(STATUS_MAX_STEP_RATE_EXCEEDED); } 190 | #endif 191 | settings.steps_per_mm[parameter] = value; 192 | break; 193 | case 1: 194 | #ifdef MAX_STEP_RATE_HZ 195 | if (value*settings.steps_per_mm[parameter] > (MAX_STEP_RATE_HZ*60.0)) { return(STATUS_MAX_STEP_RATE_EXCEEDED); } 196 | #endif 197 | settings.max_rate[parameter] = value; 198 | break; 199 | case 2: settings.acceleration[parameter] = value*60*60; break; // Convert to mm/min^2 for grbl internal use. 200 | case 3: settings.max_travel[parameter] = -value; break; // Store as negative for grbl internal use. 201 | } 202 | break; // Exit while-loop after setting has been configured and proceed to the EEPROM write call. 203 | } else { 204 | set_idx++; 205 | // If axis index greater than N_AXIS or setting index greater than number of axis settings, error out. 206 | if ((parameter < AXIS_SETTINGS_INCREMENT) || (set_idx == AXIS_N_SETTINGS)) { return(STATUS_INVALID_STATEMENT); } 207 | parameter -= AXIS_SETTINGS_INCREMENT; 208 | } 209 | } 210 | } else { 211 | // Store non-axis Grbl settings 212 | uint8_t int_value = trunc(value); 213 | switch(parameter) { 214 | case 0: 215 | if (int_value < 3) { return(STATUS_SETTING_STEP_PULSE_MIN); } 216 | settings.pulse_microseconds = int_value; break; 217 | case 1: settings.stepper_idle_lock_time = int_value; break; 218 | case 2: 219 | settings.step_invert_mask = int_value; 220 | st_generate_step_dir_invert_masks(); // Regenerate step and direction port invert masks. 221 | break; 222 | case 3: 223 | settings.dir_invert_mask = int_value; 224 | st_generate_step_dir_invert_masks(); // Regenerate step and direction port invert masks. 225 | break; 226 | case 4: // Reset to ensure change. Immediate re-init may cause problems. 227 | if (int_value) { settings.flags |= BITFLAG_INVERT_ST_ENABLE; } 228 | else { settings.flags &= ~BITFLAG_INVERT_ST_ENABLE; } 229 | break; 230 | case 5: // Reset to ensure change. Immediate re-init may cause problems. 231 | if (int_value) { settings.flags |= BITFLAG_INVERT_LIMIT_PINS; } 232 | else { settings.flags &= ~BITFLAG_INVERT_LIMIT_PINS; } 233 | break; 234 | case 6: // Reset to ensure change. Immediate re-init may cause problems. 235 | if (int_value) { settings.flags |= BITFLAG_INVERT_PROBE_PIN; } 236 | else { settings.flags &= ~BITFLAG_INVERT_PROBE_PIN; } 237 | break; 238 | case 10: settings.status_report_mask = int_value; break; 239 | case 11: settings.junction_deviation = value; break; 240 | case 12: settings.arc_tolerance = value; break; 241 | case 13: 242 | if (int_value) { settings.flags |= BITFLAG_REPORT_INCHES; } 243 | else { settings.flags &= ~BITFLAG_REPORT_INCHES; } 244 | break; 245 | case 20: 246 | if (int_value) { 247 | if (bit_isfalse(settings.flags, BITFLAG_HOMING_ENABLE)) { return(STATUS_SOFT_LIMIT_ERROR); } 248 | settings.flags |= BITFLAG_SOFT_LIMIT_ENABLE; 249 | } else { settings.flags &= ~BITFLAG_SOFT_LIMIT_ENABLE; } 250 | break; 251 | case 21: 252 | if (int_value) { settings.flags |= BITFLAG_HARD_LIMIT_ENABLE; } 253 | else { settings.flags &= ~BITFLAG_HARD_LIMIT_ENABLE; } 254 | limits_init(); // Re-init to immediately change. NOTE: Nice to have but could be problematic later. 255 | break; 256 | case 22: 257 | if (int_value) { settings.flags |= BITFLAG_HOMING_ENABLE; } 258 | else { 259 | settings.flags &= ~BITFLAG_HOMING_ENABLE; 260 | settings.flags &= ~BITFLAG_SOFT_LIMIT_ENABLE; // Force disable soft-limits. 261 | } 262 | break; 263 | case 23: settings.homing_dir_mask = int_value; break; 264 | case 24: settings.homing_feed_rate = value; break; 265 | case 25: settings.homing_seek_rate = value; break; 266 | case 26: settings.homing_debounce_delay = int_value; break; 267 | case 27: settings.homing_pulloff = value; break; 268 | default: 269 | return(STATUS_INVALID_STATEMENT); 270 | } 271 | } 272 | write_global_settings(); 273 | return(STATUS_OK); 274 | } 275 | 276 | 277 | // Initialize the config subsystem 278 | void settings_init() { 279 | if(!read_global_settings()) { 280 | report_status_message(STATUS_SETTING_READ_FAIL); 281 | settings_restore(SETTINGS_RESTORE_ALL); // Force restore all EEPROM data. 282 | report_grbl_settings(); 283 | } 284 | 285 | // NOTE: Checking paramater data, startup lines, and build info string should be done here, 286 | // but it seems fairly redundant. Each of these can be manually checked and reset or restored. 287 | // Check all parameter data into a dummy variable. If error, reset to zero, otherwise do nothing. 288 | // float coord_data[N_AXIS]; 289 | // uint8_t i; 290 | // for (i=0; i<=SETTING_INDEX_NCOORD; i++) { 291 | // if (!settings_read_coord_data(i, coord_data)) { 292 | // report_status_message(STATUS_SETTING_READ_FAIL); 293 | // } 294 | // } 295 | // NOTE: Startup lines are checked and executed by protocol_main_loop at the end of initialization. 296 | } 297 | 298 | 299 | // Returns step pin mask according to Grbl internal axis indexing. 300 | uint8_t get_step_pin_mask(uint8_t axis_idx) 301 | { 302 | 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 | } settings_t; 103 | extern settings_t settings; 104 | 105 | // Initialize the configuration subsystem (load settings from EEPROM) 106 | void settings_init(); 107 | 108 | // Helper function to clear and restore EEPROM defaults 109 | void settings_restore(uint8_t restore_flag); 110 | 111 | // A helper method to set new settings from command line 112 | uint8_t settings_store_global_setting(uint8_t parameter, float value); 113 | 114 | // Stores the protocol line variable as a startup line in EEPROM 115 | void settings_store_startup_line(uint8_t n, char *line); 116 | 117 | // Reads an EEPROM startup line to the protocol line variable 118 | uint8_t settings_read_startup_line(uint8_t n, char *line); 119 | 120 | // Stores build info user-defined string 121 | void settings_store_build_info(char *line); 122 | 123 | // Reads build info user-defined string 124 | uint8_t settings_read_build_info(char *line); 125 | 126 | // Writes selected coordinate data to EEPROM 127 | void settings_write_coord_data(uint8_t coord_select, float *coord_data); 128 | 129 | // Reads selected coordinate data from EEPROM 130 | uint8_t settings_read_coord_data(uint8_t coord_select, float *coord_data); 131 | 132 | // Returns the step pin mask according to Grbl's internal axis numbering 133 | uint8_t get_step_pin_mask(uint8_t i); 134 | 135 | // Returns the direction pin mask according to Grbl's internal axis numbering 136 | uint8_t get_direction_pin_mask(uint8_t i); 137 | 138 | // Returns the limit pin mask according to Grbl's internal axis numbering 139 | uint8_t get_limit_pin_mask(uint8_t i); 140 | 141 | 142 | #endif 143 | -------------------------------------------------------------------------------- /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 | #include "grbl.h" 23 | 24 | 25 | void spindle_init() 26 | { 27 | // Configure variable spindle PWM and enable pin, if requried. On the Uno, PWM and enable are 28 | // combined unless configured otherwise. 29 | #ifdef VARIABLE_SPINDLE 30 | SPINDLE_PWM_DDR |= (1< SPINDLE_RPM_RANGE ) { rpm = SPINDLE_RPM_RANGE; } // Prevent integer overflow 105 | } 106 | current_pwm = floor( rpm*(PWM_MAX_VALUE/SPINDLE_RPM_RANGE) + 0.5); 107 | #ifdef MINIMUM_SPINDLE_PWM 108 | if (current_pwm < MINIMUM_SPINDLE_PWM) { current_pwm = MINIMUM_SPINDLE_PWM; } 109 | #endif 110 | OCR_REGISTER = current_pwm; // Set PWM pin output 111 | 112 | // On the Uno, spindle enable and PWM are shared, unless otherwise specified. 113 | #if defined(CPU_MAP_ATMEGA2560) || defined(USE_SPINDLE_DIR_AS_ENABLE_PIN) 114 | #ifdef INVERT_SPINDLE_ENABLE_PIN 115 | SPINDLE_ENABLE_PORT &= ~(1<. 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.c: -------------------------------------------------------------------------------- 1 | /* 2 | system.c - Handles 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 | #include "grbl.h" 22 | 23 | 24 | void system_init() 25 | { 26 | CONTROL_DDR &= ~(CONTROL_MASK); // Configure as input pins 27 | #ifdef DISABLE_CONTROL_PIN_PULL_UP 28 | CONTROL_PORT &= ~(CONTROL_MASK); // Normal low operation. Requires external pull-down. 29 | #else 30 | CONTROL_PORT |= CONTROL_MASK; // Enable internal pull-up resistors. Normal high operation. 31 | #endif 32 | CONTROL_PCMSK |= CONTROL_MASK; // Enable specific pins of the Pin Change Interrupt 33 | PCICR |= (1 << CONTROL_INT); // Enable Pin Change Interrupt 34 | } 35 | 36 | 37 | // Pin change interrupt for pin-out commands, i.e. cycle start, feed hold, and reset. Sets 38 | // only the realtime command execute variable to have the main program execute these when 39 | // its ready. This works exactly like the character-based realtime commands when picked off 40 | // directly from the incoming serial data stream. 41 | ISR(CONTROL_INT_vect) 42 | { 43 | uint8_t pin = (CONTROL_PIN & CONTROL_MASK); 44 | #ifndef INVERT_ALL_CONTROL_PINS 45 | pin ^= CONTROL_INVERT_MASK; 46 | #endif 47 | // Enter only if any CONTROL pin is detected as active. 48 | if (pin) { 49 | if (bit_istrue(pin,bit(RESET_BIT))) { 50 | mc_reset(); 51 | } else if (bit_istrue(pin,bit(CYCLE_START_BIT))) { 52 | bit_true(sys_rt_exec_state, EXEC_CYCLE_START); 53 | #ifndef ENABLE_SAFETY_DOOR_INPUT_PIN 54 | } else if (bit_istrue(pin,bit(FEED_HOLD_BIT))) { 55 | bit_true(sys_rt_exec_state, EXEC_FEED_HOLD); 56 | #else 57 | } else if (bit_istrue(pin,bit(SAFETY_DOOR_BIT))) { 58 | bit_true(sys_rt_exec_state, EXEC_SAFETY_DOOR); 59 | #endif 60 | } 61 | } 62 | } 63 | 64 | 65 | // Returns if safety door is ajar(T) or closed(F), based on pin state. 66 | uint8_t system_check_safety_door_ajar() 67 | { 68 | #ifdef ENABLE_SAFETY_DOOR_INPUT_PIN 69 | #ifdef INVERT_CONTROL_PIN 70 | return(bit_istrue(CONTROL_PIN,bit(SAFETY_DOOR_BIT))); 71 | #else 72 | return(bit_isfalse(CONTROL_PIN,bit(SAFETY_DOOR_BIT))); 73 | #endif 74 | #else 75 | return(false); // Input pin not enabled, so just return that it's closed. 76 | #endif 77 | } 78 | 79 | 80 | // Executes user startup script, if stored. 81 | void system_execute_startup(char *line) 82 | { 83 | uint8_t n; 84 | for (n=0; n < N_STARTUP_LINE; n++) { 85 | if (!(settings_read_startup_line(n, line))) { 86 | report_status_message(STATUS_SETTING_READ_FAIL); 87 | } else { 88 | if (line[0] != 0) { 89 | printString(line); // Echo startup line to indicate execution. 90 | report_status_message(gc_execute_line(line)); 91 | } 92 | } 93 | } 94 | } 95 | 96 | 97 | // Directs and executes one line of formatted input from protocol_process. While mostly 98 | // incoming streaming g-code blocks, this also executes Grbl internal commands, such as 99 | // settings, initiating the homing cycle, and toggling switch states. This differs from 100 | // the realtime command module by being susceptible to when Grbl is ready to execute the 101 | // next line during a cycle, so for switches like block delete, the switch only effects 102 | // the lines that are processed afterward, not necessarily real-time during a cycle, 103 | // since there are motions already stored in the buffer. However, this 'lag' should not 104 | // be an issue, since these commands are not typically used during a cycle. 105 | uint8_t system_execute_line(char *line) 106 | { 107 | uint8_t char_counter = 1; 108 | uint8_t helper_var = 0; // Helper variable 109 | float parameter, value; 110 | switch( line[char_counter] ) { 111 | case 0 : report_grbl_help(); break; 112 | case '$': case 'G': case 'C': case 'X': 113 | if ( line[(char_counter+1)] != 0 ) { return(STATUS_INVALID_STATEMENT); } 114 | switch( line[char_counter] ) { 115 | case '$' : // Prints Grbl settings 116 | if ( sys.state & (STATE_CYCLE | STATE_HOLD) ) { return(STATUS_IDLE_ERROR); } // Block during cycle. Takes too long to print. 117 | else { report_grbl_settings(); } 118 | break; 119 | case 'G' : // Prints gcode parser state 120 | // TODO: Move this to realtime commands for GUIs to request this data during suspend-state. 121 | report_gcode_modes(); 122 | break; 123 | case 'C' : // Set check g-code mode [IDLE/CHECK] 124 | // Perform reset when toggling off. Check g-code mode should only work if Grbl 125 | // is idle and ready, regardless of alarm locks. This is mainly to keep things 126 | // simple and consistent. 127 | if ( sys.state == STATE_CHECK_MODE ) { 128 | mc_reset(); 129 | report_feedback_message(MESSAGE_DISABLED); 130 | } else { 131 | if (sys.state) { return(STATUS_IDLE_ERROR); } // Requires no alarm mode. 132 | sys.state = STATE_CHECK_MODE; 133 | report_feedback_message(MESSAGE_ENABLED); 134 | } 135 | break; 136 | case 'X' : // Disable alarm lock [ALARM] 137 | if (sys.state == STATE_ALARM) { 138 | report_feedback_message(MESSAGE_ALARM_UNLOCK); 139 | sys.state = STATE_IDLE; 140 | // Don't run startup script. Prevents stored moves in startup from causing accidents. 141 | if (system_check_safety_door_ajar()) { // Check safety door switch before returning. 142 | bit_true(sys_rt_exec_state, EXEC_SAFETY_DOOR); 143 | protocol_execute_realtime(); // Enter safety door mode. 144 | } 145 | } // Otherwise, no effect. 146 | break; 147 | // case 'J' : break; // Jogging methods 148 | // TODO: Here jogging can be placed for execution as a seperate subprogram. It does not need to be 149 | // susceptible to other realtime commands except for e-stop. The jogging function is intended to 150 | // be a basic toggle on/off with controlled acceleration and deceleration to prevent skipped 151 | // steps. The user would supply the desired feedrate, axis to move, and direction. Toggle on would 152 | // start motion and toggle off would initiate a deceleration to stop. One could 'feather' the 153 | // motion by repeatedly toggling to slow the motion to the desired location. Location data would 154 | // need to be updated real-time and supplied to the user through status queries. 155 | // More controlled exact motions can be taken care of by inputting G0 or G1 commands, which are 156 | // handled by the planner. It would be possible for the jog subprogram to insert blocks into the 157 | // block buffer without having the planner plan them. It would need to manage de/ac-celerations 158 | // on its own carefully. This approach could be effective and possibly size/memory efficient. 159 | // } 160 | // break; 161 | } 162 | break; 163 | default : 164 | // Block any system command that requires the state as IDLE/ALARM. (i.e. EEPROM, homing) 165 | if ( !(sys.state == STATE_IDLE || sys.state == STATE_ALARM) ) { return(STATUS_IDLE_ERROR); } 166 | switch( line[char_counter] ) { 167 | case '#' : // Print Grbl NGC parameters 168 | if ( line[++char_counter] != 0 ) { return(STATUS_INVALID_STATEMENT); } 169 | else { report_ngc_parameters(); } 170 | break; 171 | case 'H' : // Perform homing cycle [IDLE/ALARM] 172 | if (bit_istrue(settings.flags,BITFLAG_HOMING_ENABLE)) { 173 | sys.state = STATE_HOMING; // Set system state variable 174 | // Only perform homing if Grbl is idle or lost. 175 | 176 | // TODO: Likely not required. 177 | if (system_check_safety_door_ajar()) { // Check safety door switch before homing. 178 | bit_true(sys_rt_exec_state, EXEC_SAFETY_DOOR); 179 | protocol_execute_realtime(); // Enter safety door mode. 180 | } 181 | 182 | 183 | mc_homing_cycle(); 184 | if (!sys.abort) { // Execute startup scripts after successful homing. 185 | sys.state = STATE_IDLE; // Set to IDLE when complete. 186 | st_go_idle(); // Set steppers to the settings idle state before returning. 187 | system_execute_startup(line); 188 | } 189 | } else { return(STATUS_SETTING_DISABLED); } 190 | break; 191 | case 'I' : // Print or store build info. [IDLE/ALARM] 192 | if ( line[++char_counter] == 0 ) { 193 | settings_read_build_info(line); 194 | report_build_info(line); 195 | } else { // Store startup line [IDLE/ALARM] 196 | if(line[char_counter++] != '=') { return(STATUS_INVALID_STATEMENT); } 197 | helper_var = char_counter; // Set helper variable as counter to start of user info line. 198 | do { 199 | line[char_counter-helper_var] = line[char_counter]; 200 | } while (line[char_counter++] != 0); 201 | settings_store_build_info(line); 202 | } 203 | break; 204 | case 'R' : // Restore defaults [IDLE/ALARM] 205 | if (line[++char_counter] != 'S') { return(STATUS_INVALID_STATEMENT); } 206 | if (line[++char_counter] != 'T') { return(STATUS_INVALID_STATEMENT); } 207 | if (line[++char_counter] != '=') { return(STATUS_INVALID_STATEMENT); } 208 | if (line[char_counter+2] != 0) { return(STATUS_INVALID_STATEMENT); } 209 | switch (line[++char_counter]) { 210 | case '$': settings_restore(SETTINGS_RESTORE_DEFAULTS); break; 211 | case '#': settings_restore(SETTINGS_RESTORE_PARAMETERS); break; 212 | case '*': settings_restore(SETTINGS_RESTORE_ALL); break; 213 | default: return(STATUS_INVALID_STATEMENT); 214 | } 215 | report_feedback_message(MESSAGE_RESTORE_DEFAULTS); 216 | mc_reset(); // Force reset to ensure settings are initialized correctly. 217 | break; 218 | case 'N' : // Startup lines. [IDLE/ALARM] 219 | if ( line[++char_counter] == 0 ) { // Print startup lines 220 | for (helper_var=0; helper_var < N_STARTUP_LINE; helper_var++) { 221 | if (!(settings_read_startup_line(helper_var, line))) { 222 | report_status_message(STATUS_SETTING_READ_FAIL); 223 | } else { 224 | report_startup_line(helper_var,line); 225 | } 226 | } 227 | break; 228 | } else { // Store startup line [IDLE Only] Prevents motion during ALARM. 229 | if (sys.state != STATE_IDLE) { return(STATUS_IDLE_ERROR); } // Store only when idle. 230 | helper_var = true; // Set helper_var to flag storing method. 231 | // No break. Continues into default: to read remaining command characters. 232 | } 233 | default : // Storing setting methods [IDLE/ALARM] 234 | if(!read_float(line, &char_counter, ¶meter)) { return(STATUS_BAD_NUMBER_FORMAT); } 235 | if(line[char_counter++] != '=') { return(STATUS_INVALID_STATEMENT); } 236 | if (helper_var) { // Store startup line 237 | // Prepare sending gcode block to gcode parser by shifting all characters 238 | helper_var = char_counter; // Set helper variable as counter to start of gcode block 239 | do { 240 | line[char_counter-helper_var] = line[char_counter]; 241 | } while (line[char_counter++] != 0); 242 | // Execute gcode block to ensure block is valid. 243 | helper_var = gc_execute_line(line); // Set helper_var to returned status code. 244 | if (helper_var) { return(helper_var); } 245 | else { 246 | helper_var = trunc(parameter); // Set helper_var to int value of parameter 247 | settings_store_startup_line(helper_var,line); 248 | } 249 | } else { // Store global setting. 250 | if(!read_float(line, &char_counter, &value)) { return(STATUS_BAD_NUMBER_FORMAT); } 251 | if((line[char_counter] != 0) || (parameter > 255)) { return(STATUS_INVALID_STATEMENT); } 252 | return(settings_store_global_setting((uint8_t)parameter, value)); 253 | } 254 | } 255 | } 256 | return(STATUS_OK); // If '$' command makes it to here, then everything's ok. 257 | } 258 | 259 | 260 | // Returns machine position of axis 'idx'. Must be sent a 'step' array. 261 | // NOTE: If motor steps and machine position are not in the same coordinate frame, this function 262 | // serves as a central place to compute the transformation. 263 | float system_convert_axis_steps_to_mpos(int32_t *steps, uint8_t idx) 264 | { 265 | float pos; 266 | #ifdef COREXY 267 | if (idx==A_MOTOR) { 268 | pos = 0.5*((steps[A_MOTOR] + steps[B_MOTOR])/settings.steps_per_mm[idx]); 269 | } else if (idx==B_MOTOR) { 270 | pos = 0.5*((steps[A_MOTOR] - steps[B_MOTOR])/settings.steps_per_mm[idx]); 271 | } else { 272 | pos = steps[idx]/settings.steps_per_mm[idx]; 273 | } 274 | #else 275 | pos = steps[idx]/settings.steps_per_mm[idx]; 276 | #endif 277 | return(pos); 278 | } 279 | 280 | 281 | void system_convert_array_steps_to_mpos(float *position, int32_t *steps) 282 | { 283 | uint8_t idx; 284 | for (idx=0; idx. 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 | #endif 110 | -------------------------------------------------------------------------------- /platformio.ini: -------------------------------------------------------------------------------- 1 | ; PlatformIO Project Configuration File 2 | ; 3 | ; Build options: build flags, source filter 4 | ; Upload options: custom upload port, speed and extra flags 5 | ; Library options: dependencies, extra library storages 6 | ; Advanced options: extra scripting 7 | ; 8 | ; Please visit documentation for the other options and examples 9 | ; https://docs.platformio.org/page/projectconf.html 10 | 11 | [platformio] 12 | workspace_dir=build 13 | src_dir=grbl 14 | include_dir=grbl 15 | 16 | [env:megaatmega2560] 17 | platform = atmelavr 18 | board = megaatmega2560 19 | framework = arduino 20 | monitor_speed = 115200 21 | --------------------------------------------------------------------------------