2009-01-25 00:48:56 +01:00
|
|
|
/*
|
|
|
|
main.c - An embedded CNC Controller with rs274/ngc (g-code) support
|
|
|
|
Part of Grbl
|
|
|
|
|
2011-01-14 16:45:18 +01:00
|
|
|
Copyright (c) 2009-2011 Simen Svale Skogsrud
|
2012-01-29 04:41:08 +01:00
|
|
|
Copyright (c) 2011-2012 Sungeun K. Jeon
|
2012-01-06 18:10:41 +01:00
|
|
|
|
2009-01-25 00:48:56 +01:00
|
|
|
Grbl is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
Grbl is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with Grbl. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
Hard limits, homing direction, pull-off limits after homing, status reports in mm or inches, system alarm, and more.
- Thank you statement added for Alden Hart of Synthetos.
- Hard limits option added, which also works with homing by pulling off
the switches to help prevent unintended triggering. Hard limits use a
interrupt to sense a falling edge pin change and immediately go into
alarm mode, which stops everything and forces the user to issue a reset
(Ctrl-x) or reboot.
- Auto cycle start now a configuration option.
- Alarm mode: A new method to kill all Grbl processes in the event of
something catastrophic or potentially catastropic. Just works with hard
limits for now, but will be expanded to include g-code errors (most
likely) and other events.
- Updated status reports to be configurable in inches or mm mode. Much
more to do here, but this is the first step.
- New settings: auto cycle start, hard limit enable, homing direction
mask (which works the same as the stepper mask), homing pulloff
distance (or distance traveled from homed machine zero to prevent
accidental limit trip).
- Minor memory liberation and calculation speed ups.
2012-10-17 05:29:45 +02:00
|
|
|
/* A big thanks to Alden Hart of Synthetos, supplier of grblshield and TinyG, who has
|
|
|
|
been integral throughout the development of the higher level details of Grbl, as well
|
|
|
|
as being a consistent sounding board for the future of accessible and free CNC. */
|
|
|
|
|
2011-05-31 13:08:42 +02:00
|
|
|
#include <avr/interrupt.h>
|
2011-12-09 02:47:48 +01:00
|
|
|
#include <avr/pgmspace.h>
|
2011-06-03 15:28:14 +02:00
|
|
|
#include "config.h"
|
2011-02-11 00:34:53 +01:00
|
|
|
#include "planner.h"
|
2011-12-09 02:47:48 +01:00
|
|
|
#include "nuts_bolts.h"
|
2009-01-28 23:48:21 +01:00
|
|
|
#include "stepper.h"
|
|
|
|
#include "spindle_control.h"
|
2012-09-21 19:14:13 +02:00
|
|
|
#include "coolant_control.h"
|
2009-01-25 00:48:56 +01:00
|
|
|
#include "motion_control.h"
|
|
|
|
#include "gcode.h"
|
2011-02-18 22:11:53 +01:00
|
|
|
#include "protocol.h"
|
2011-02-20 00:29:56 +01:00
|
|
|
#include "limits.h"
|
2012-11-01 16:37:27 +01:00
|
|
|
#include "report.h"
|
2011-02-05 00:45:41 +01:00
|
|
|
#include "settings.h"
|
2011-05-31 22:45:38 +02:00
|
|
|
#include "serial.h"
|
2009-02-03 09:56:45 +01:00
|
|
|
|
2012-01-06 18:10:41 +01:00
|
|
|
// Declare system global variable structure
|
|
|
|
system_t sys;
|
2011-12-09 02:47:48 +01:00
|
|
|
|
2009-01-25 00:48:56 +01:00
|
|
|
int main(void)
|
|
|
|
{
|
2011-12-09 02:47:48 +01:00
|
|
|
// Initialize system
|
|
|
|
serial_init(BAUD_RATE); // Setup serial baud rate and interrupts
|
|
|
|
st_init(); // Setup stepper pins and interrupt timers
|
2012-01-16 02:25:12 +01:00
|
|
|
sei(); // Enable interrupts
|
2012-01-06 18:10:41 +01:00
|
|
|
|
2012-01-10 16:34:48 +01:00
|
|
|
memset(&sys, 0, sizeof(sys)); // Clear all system variables
|
2012-01-06 18:10:41 +01:00
|
|
|
sys.abort = true; // Set abort to complete initialization
|
Hard limits, homing direction, pull-off limits after homing, status reports in mm or inches, system alarm, and more.
- Thank you statement added for Alden Hart of Synthetos.
- Hard limits option added, which also works with homing by pulling off
the switches to help prevent unintended triggering. Hard limits use a
interrupt to sense a falling edge pin change and immediately go into
alarm mode, which stops everything and forces the user to issue a reset
(Ctrl-x) or reboot.
- Auto cycle start now a configuration option.
- Alarm mode: A new method to kill all Grbl processes in the event of
something catastrophic or potentially catastropic. Just works with hard
limits for now, but will be expanded to include g-code errors (most
likely) and other events.
- Updated status reports to be configurable in inches or mm mode. Much
more to do here, but this is the first step.
- New settings: auto cycle start, hard limit enable, homing direction
mask (which works the same as the stepper mask), homing pulloff
distance (or distance traveled from homed machine zero to prevent
accidental limit trip).
- Minor memory liberation and calculation speed ups.
2012-10-17 05:29:45 +02:00
|
|
|
|
|
|
|
// TODO: When Grbl system status is installed, need to set position lost state upon startup.
|
|
|
|
|
2012-01-29 04:41:08 +01:00
|
|
|
for(;;) {
|
2011-12-09 02:47:48 +01:00
|
|
|
|
2012-01-06 18:10:41 +01:00
|
|
|
// Execute system reset upon a system abort, where the main program will return to this loop.
|
|
|
|
// Once here, it is safe to re-initialize the system. At startup, the system will automatically
|
|
|
|
// reset to finish the initialization process.
|
|
|
|
if (sys.abort) {
|
2012-01-10 16:34:48 +01:00
|
|
|
|
2012-02-11 19:59:35 +01:00
|
|
|
// Retain last known machine position and work coordinate offset(s). If the system abort
|
|
|
|
// occurred while in motion, machine position is not guaranteed, since a hard stop can cause
|
|
|
|
// the steppers to lose steps. Always perform a feedhold before an abort, if maintaining
|
|
|
|
// accurate machine position is required.
|
2012-01-29 04:41:08 +01:00
|
|
|
// TODO: Report last position and coordinate offset to users to help relocate origins. Future
|
|
|
|
// releases will auto-reset the machine position back to [0,0,0] if an abort is used while
|
|
|
|
// grbl is moving the machine.
|
2012-02-11 19:59:35 +01:00
|
|
|
int32_t last_position[3];
|
2012-01-10 16:34:48 +01:00
|
|
|
memcpy(last_position, sys.position, sizeof(sys.position)); // last_position[] = sys.position[]
|
2012-11-01 16:37:27 +01:00
|
|
|
// TODO: Last coordinate system method.
|
|
|
|
|
2011-12-09 02:47:48 +01:00
|
|
|
// Reset system.
|
2012-01-29 04:41:08 +01:00
|
|
|
memset(&sys, 0, sizeof(sys)); // Clear all system variables
|
2011-12-09 02:47:48 +01:00
|
|
|
serial_reset_read_buffer(); // Clear serial read buffer
|
|
|
|
settings_init(); // Load grbl settings from EEPROM
|
|
|
|
protocol_init(); // Clear incoming line data
|
|
|
|
plan_init(); // Clear block buffer and planner variables
|
|
|
|
gc_init(); // Set g-code parser to default state
|
2012-03-10 20:34:09 +01:00
|
|
|
spindle_init();
|
2012-09-21 19:14:13 +02:00
|
|
|
coolant_init();
|
2011-12-09 02:47:48 +01:00
|
|
|
limits_init();
|
2012-01-06 18:10:41 +01:00
|
|
|
st_reset(); // Clear stepper subsystem variables.
|
|
|
|
|
2012-02-11 19:59:35 +01:00
|
|
|
// Reload last known machine position and work systems. G92 coordinate offsets are reset.
|
2012-01-29 04:41:08 +01:00
|
|
|
memcpy(sys.position, last_position, sizeof(last_position)); // sys.position[] = last_position[]
|
|
|
|
gc_set_current_position(last_position[X_AXIS],last_position[Y_AXIS],last_position[Z_AXIS]);
|
|
|
|
plan_set_current_position(last_position[X_AXIS],last_position[Y_AXIS],last_position[Z_AXIS]);
|
|
|
|
|
2012-01-06 18:10:41 +01:00
|
|
|
// Set system runtime defaults
|
|
|
|
// TODO: Eventual move to EEPROM from config.h when all of the new settings are worked out.
|
|
|
|
// Mainly to avoid having to maintain several different versions.
|
Hard limits, homing direction, pull-off limits after homing, status reports in mm or inches, system alarm, and more.
- Thank you statement added for Alden Hart of Synthetos.
- Hard limits option added, which also works with homing by pulling off
the switches to help prevent unintended triggering. Hard limits use a
interrupt to sense a falling edge pin change and immediately go into
alarm mode, which stops everything and forces the user to issue a reset
(Ctrl-x) or reboot.
- Auto cycle start now a configuration option.
- Alarm mode: A new method to kill all Grbl processes in the event of
something catastrophic or potentially catastropic. Just works with hard
limits for now, but will be expanded to include g-code errors (most
likely) and other events.
- Updated status reports to be configurable in inches or mm mode. Much
more to do here, but this is the first step.
- New settings: auto cycle start, hard limit enable, homing direction
mask (which works the same as the stepper mask), homing pulloff
distance (or distance traveled from homed machine zero to prevent
accidental limit trip).
- Minor memory liberation and calculation speed ups.
2012-10-17 05:29:45 +02:00
|
|
|
if (bit_istrue(settings.flags,BITFLAG_AUTO_START)) {
|
2012-01-06 18:10:41 +01:00
|
|
|
sys.auto_start = true;
|
Hard limits, homing direction, pull-off limits after homing, status reports in mm or inches, system alarm, and more.
- Thank you statement added for Alden Hart of Synthetos.
- Hard limits option added, which also works with homing by pulling off
the switches to help prevent unintended triggering. Hard limits use a
interrupt to sense a falling edge pin change and immediately go into
alarm mode, which stops everything and forces the user to issue a reset
(Ctrl-x) or reboot.
- Auto cycle start now a configuration option.
- Alarm mode: A new method to kill all Grbl processes in the event of
something catastrophic or potentially catastropic. Just works with hard
limits for now, but will be expanded to include g-code errors (most
likely) and other events.
- Updated status reports to be configurable in inches or mm mode. Much
more to do here, but this is the first step.
- New settings: auto cycle start, hard limit enable, homing direction
mask (which works the same as the stepper mask), homing pulloff
distance (or distance traveled from homed machine zero to prevent
accidental limit trip).
- Minor memory liberation and calculation speed ups.
2012-10-17 05:29:45 +02:00
|
|
|
}
|
2012-02-11 19:59:35 +01:00
|
|
|
// TODO: Install G20/G21 unit default into settings and load appropriate settings.
|
2012-11-01 16:37:27 +01:00
|
|
|
|
|
|
|
report_init_message();
|
2011-12-09 02:47:48 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
protocol_execute_runtime();
|
2011-02-18 22:19:01 +01:00
|
|
|
protocol_process(); // ... process the serial protocol
|
2011-12-09 02:47:48 +01:00
|
|
|
|
2009-01-25 00:48:56 +01:00
|
|
|
}
|
|
|
|
return 0; /* never reached */
|
|
|
|
}
|