Mass reformat
No code changes other than what clang-format mandates. This is breaking
This commit is contained in:
parent
a1c041481c
commit
fe32d197f9
38 changed files with 7094 additions and 6574 deletions
|
|
@ -29,7 +29,6 @@
|
|||
#define config_h
|
||||
#include "grbl.h" // For Arduino IDE compatibility.
|
||||
|
||||
|
||||
// Define CPU pin map and default settings.
|
||||
// NOTE: OEMs can avoid the need to maintain/update the defaults.h and cpu_map.h files and use only
|
||||
// one configuration file by placing their specific defaults and pin map at the bottom of this file.
|
||||
|
|
@ -102,8 +101,8 @@
|
|||
// on separate pin, but homed in one cycle. Also, it should be noted that the function of hard limits
|
||||
// will not be affected by pin sharing.
|
||||
// NOTE: Defaults are set for a traditional 3-axis CNC machine. Z-axis first to clear, followed by X & Y.
|
||||
#define HOMING_CYCLE_0 (1<<Z_AXIS) // REQUIRED: First move Z to clear workspace.
|
||||
#define HOMING_CYCLE_1 ((1<<X_AXIS)|(1<<Y_AXIS)) // OPTIONAL: Then move X,Y at the same time.
|
||||
#define HOMING_CYCLE_0 (1 << Z_AXIS) // REQUIRED: First move Z to clear workspace.
|
||||
#define HOMING_CYCLE_1 ((1 << X_AXIS) | (1 << Y_AXIS)) // OPTIONAL: Then move X,Y at the same time.
|
||||
// #define HOMING_CYCLE_2 // OPTIONAL: Uncomment and add axes mask to enable
|
||||
|
||||
// NOTE: The following are two examples to setup homing for 2-axis machines.
|
||||
|
|
@ -323,9 +322,9 @@
|
|||
// normal-open switch and vice versa.
|
||||
// NOTE: All pins associated with the feature are disabled, i.e. XYZ limit pins, not individual axes.
|
||||
// WARNING: When the pull-ups are disabled, this requires additional wiring with pull-down resistors!
|
||||
//#define DISABLE_LIMIT_PIN_PULL_UP
|
||||
//#define DISABLE_PROBE_PIN_PULL_UP
|
||||
//#define DISABLE_CONTROL_PIN_PULL_UP
|
||||
// #define DISABLE_LIMIT_PIN_PULL_UP
|
||||
// #define DISABLE_PROBE_PIN_PULL_UP
|
||||
// #define DISABLE_CONTROL_PIN_PULL_UP
|
||||
|
||||
// Sets which axis the tool length offset is applied. Assumes the spindle is always parallel with
|
||||
// the selected axis with the tool oriented toward the negative direction. In other words, a positive
|
||||
|
|
@ -509,7 +508,8 @@
|
|||
// written into the Arduino EEPROM via a seperate .INO sketch to contain product data. Altering this
|
||||
// macro to not restore the build info EEPROM will ensure this data is retained after firmware upgrades.
|
||||
// NOTE: Uncomment to override defaults in settings.h
|
||||
// #define SETTINGS_RESTORE_ALL (SETTINGS_RESTORE_DEFAULTS | SETTINGS_RESTORE_PARAMETERS | SETTINGS_RESTORE_STARTUP_LINES | SETTINGS_RESTORE_BUILD_INFO)
|
||||
// #define SETTINGS_RESTORE_ALL (SETTINGS_RESTORE_DEFAULTS | SETTINGS_RESTORE_PARAMETERS |
|
||||
// SETTINGS_RESTORE_STARTUP_LINES | SETTINGS_RESTORE_BUILD_INFO)
|
||||
|
||||
// Enable the '$I=(string)' build info write command. If disabled, any existing build info data must
|
||||
// be placed into EEPROM via external means with a valid checksum value. This macro option is useful
|
||||
|
|
@ -568,7 +568,8 @@
|
|||
#define PARKING_TARGET -5.0 // Parking axis target. In mm, as machine coordinate [-max_travel,0].
|
||||
#define PARKING_RATE 500.0 // Parking fast rate after pull-out in mm/min.
|
||||
#define PARKING_PULLOUT_RATE 100.0 // Pull-out/plunge slow feed rate in mm/min.
|
||||
#define PARKING_PULLOUT_INCREMENT 5.0 // Spindle pull-out and plunge distance in mm. Incremental distance.
|
||||
#define PARKING_PULLOUT_INCREMENT \
|
||||
5.0 // Spindle pull-out and plunge distance in mm. Incremental distance.
|
||||
// Must be positive value or equal to zero.
|
||||
|
||||
// Enables a special set of M-code commands that enables and disables the parking motion.
|
||||
|
|
@ -674,7 +675,6 @@
|
|||
// updating lots of code to ensure everything is running correctly.
|
||||
// #define DUAL_AXIS_CONFIG_CNC_SHIELD_CLONE // Uncomment to select. Comment other configs.
|
||||
|
||||
|
||||
/* ---------------------------------------------------------------------------------------
|
||||
OEM Single File Configuration Option
|
||||
|
||||
|
|
@ -688,5 +688,4 @@
|
|||
|
||||
// Paste default settings definitions here.
|
||||
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -20,107 +20,101 @@
|
|||
|
||||
#include "grbl.h"
|
||||
|
||||
|
||||
void coolant_init()
|
||||
{
|
||||
void coolant_init() {
|
||||
COOLANT_FLOOD_DDR |= (1 << COOLANT_FLOOD_BIT); // Configure as output pin
|
||||
#ifdef ENABLE_M7
|
||||
#ifdef ENABLE_M7
|
||||
COOLANT_MIST_DDR |= (1 << COOLANT_MIST_BIT);
|
||||
#endif
|
||||
#endif
|
||||
coolant_stop();
|
||||
}
|
||||
|
||||
|
||||
// Returns current coolant output state. Overrides may alter it from programmed state.
|
||||
uint8_t coolant_get_state()
|
||||
{
|
||||
uint8_t coolant_get_state() {
|
||||
uint8_t cl_state = COOLANT_STATE_DISABLE;
|
||||
#ifdef INVERT_COOLANT_FLOOD_PIN
|
||||
if (bit_isfalse(COOLANT_FLOOD_PORT,(1 << COOLANT_FLOOD_BIT))) {
|
||||
#else
|
||||
if (bit_istrue(COOLANT_FLOOD_PORT,(1 << COOLANT_FLOOD_BIT))) {
|
||||
#endif
|
||||
#ifdef INVERT_COOLANT_FLOOD_PIN
|
||||
if (bit_isfalse(COOLANT_FLOOD_PORT, (1 << COOLANT_FLOOD_BIT))) {
|
||||
#else
|
||||
if (bit_istrue(COOLANT_FLOOD_PORT, (1 << COOLANT_FLOOD_BIT))) {
|
||||
#endif
|
||||
cl_state |= COOLANT_STATE_FLOOD;
|
||||
}
|
||||
#ifdef ENABLE_M7
|
||||
#ifdef INVERT_COOLANT_MIST_PIN
|
||||
if (bit_isfalse(COOLANT_MIST_PORT,(1 << COOLANT_MIST_BIT))) {
|
||||
#else
|
||||
if (bit_istrue(COOLANT_MIST_PORT,(1 << COOLANT_MIST_BIT))) {
|
||||
#endif
|
||||
#ifdef ENABLE_M7
|
||||
#ifdef INVERT_COOLANT_MIST_PIN
|
||||
if (bit_isfalse(COOLANT_MIST_PORT, (1 << COOLANT_MIST_BIT))) {
|
||||
#else
|
||||
if (bit_istrue(COOLANT_MIST_PORT, (1 << COOLANT_MIST_BIT))) {
|
||||
#endif
|
||||
cl_state |= COOLANT_STATE_MIST;
|
||||
}
|
||||
#endif
|
||||
return(cl_state);
|
||||
#endif
|
||||
return (cl_state);
|
||||
}
|
||||
|
||||
|
||||
// Directly called by coolant_init(), coolant_set_state(), and mc_reset(), which can be at
|
||||
// an interrupt-level. No report flag set, but only called by routines that don't need it.
|
||||
void coolant_stop()
|
||||
{
|
||||
#ifdef INVERT_COOLANT_FLOOD_PIN
|
||||
void coolant_stop() {
|
||||
#ifdef INVERT_COOLANT_FLOOD_PIN
|
||||
COOLANT_FLOOD_PORT |= (1 << COOLANT_FLOOD_BIT);
|
||||
#else
|
||||
#else
|
||||
COOLANT_FLOOD_PORT &= ~(1 << COOLANT_FLOOD_BIT);
|
||||
#endif
|
||||
#ifdef ENABLE_M7
|
||||
#ifdef INVERT_COOLANT_MIST_PIN
|
||||
#endif
|
||||
#ifdef ENABLE_M7
|
||||
#ifdef INVERT_COOLANT_MIST_PIN
|
||||
COOLANT_MIST_PORT |= (1 << COOLANT_MIST_BIT);
|
||||
#else
|
||||
#else
|
||||
COOLANT_MIST_PORT &= ~(1 << COOLANT_MIST_BIT);
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
// Main program only. Immediately sets flood coolant running state and also mist coolant,
|
||||
// if enabled. Also sets a flag to report an update to a coolant state.
|
||||
// Called by coolant toggle override, parking restore, parking retract, sleep mode, g-code
|
||||
// parser program end, and g-code parser coolant_sync().
|
||||
void coolant_set_state(uint8_t mode)
|
||||
{
|
||||
if (sys.abort) { return; } // Block during abort.
|
||||
void coolant_set_state(uint8_t mode) {
|
||||
if (sys.abort) {
|
||||
return;
|
||||
} // Block during abort.
|
||||
|
||||
if (mode & COOLANT_FLOOD_ENABLE) {
|
||||
#ifdef INVERT_COOLANT_FLOOD_PIN
|
||||
#ifdef INVERT_COOLANT_FLOOD_PIN
|
||||
COOLANT_FLOOD_PORT &= ~(1 << COOLANT_FLOOD_BIT);
|
||||
#else
|
||||
#else
|
||||
COOLANT_FLOOD_PORT |= (1 << COOLANT_FLOOD_BIT);
|
||||
#endif
|
||||
#endif
|
||||
} else {
|
||||
#ifdef INVERT_COOLANT_FLOOD_PIN
|
||||
#ifdef INVERT_COOLANT_FLOOD_PIN
|
||||
COOLANT_FLOOD_PORT |= (1 << COOLANT_FLOOD_BIT);
|
||||
#else
|
||||
#else
|
||||
COOLANT_FLOOD_PORT &= ~(1 << COOLANT_FLOOD_BIT);
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef ENABLE_M7
|
||||
#ifdef ENABLE_M7
|
||||
if (mode & COOLANT_MIST_ENABLE) {
|
||||
#ifdef INVERT_COOLANT_MIST_PIN
|
||||
#ifdef INVERT_COOLANT_MIST_PIN
|
||||
COOLANT_MIST_PORT &= ~(1 << COOLANT_MIST_BIT);
|
||||
#else
|
||||
#else
|
||||
COOLANT_MIST_PORT |= (1 << COOLANT_MIST_BIT);
|
||||
#endif
|
||||
#endif
|
||||
} else {
|
||||
#ifdef INVERT_COOLANT_MIST_PIN
|
||||
#ifdef INVERT_COOLANT_MIST_PIN
|
||||
COOLANT_MIST_PORT |= (1 << COOLANT_MIST_BIT);
|
||||
#else
|
||||
#else
|
||||
COOLANT_MIST_PORT &= ~(1 << COOLANT_MIST_BIT);
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
sys.report_ovr_counter = 0; // Set to report change immediately
|
||||
}
|
||||
|
||||
|
||||
// G-code parser entry-point for setting coolant state. Forces a planner buffer sync and bails
|
||||
// if an abort or check-mode is active.
|
||||
void coolant_sync(uint8_t mode)
|
||||
{
|
||||
if (sys.state == STATE_CHECK_MODE) { return; }
|
||||
void coolant_sync(uint8_t mode) {
|
||||
if (sys.state == STATE_CHECK_MODE) {
|
||||
return;
|
||||
}
|
||||
protocol_buffer_synchronize(); // Ensure coolant turns on when specified in program.
|
||||
coolant_set_state(mode);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,7 +28,6 @@
|
|||
#define COOLANT_STATE_FLOOD PL_COND_FLAG_COOLANT_FLOOD
|
||||
#define COOLANT_STATE_MIST PL_COND_FLAG_COOLANT_MIST
|
||||
|
||||
|
||||
// Initializes coolant control pins.
|
||||
void coolant_init();
|
||||
|
||||
|
|
|
|||
387
grbl/cpu_map.h
387
grbl/cpu_map.h
|
|
@ -22,230 +22,231 @@
|
|||
processor types or alternative pin layouts. This version of Grbl officially supports
|
||||
only the Arduino Mega328p. */
|
||||
|
||||
|
||||
#ifndef cpu_map_h
|
||||
#define cpu_map_h
|
||||
|
||||
|
||||
#ifdef CPU_MAP_ATMEGA328P // (Arduino Uno) Officially supported by Grbl.
|
||||
|
||||
// Define serial port pins and interrupt vectors.
|
||||
#define SERIAL_RX USART_RX_vect
|
||||
#define SERIAL_UDRE USART_UDRE_vect
|
||||
// Define serial port pins and interrupt vectors.
|
||||
#define SERIAL_RX USART_RX_vect
|
||||
#define SERIAL_UDRE USART_UDRE_vect
|
||||
|
||||
// Define step pulse output pins. NOTE: All step bit pins must be on the same port.
|
||||
#define STEP_DDR DDRD
|
||||
#define STEP_PORT PORTD
|
||||
#define X_STEP_BIT 2 // Uno Digital Pin 2
|
||||
#define Y_STEP_BIT 3 // Uno Digital Pin 3
|
||||
#define Z_STEP_BIT 4 // Uno Digital Pin 4
|
||||
#define STEP_MASK ((1<<X_STEP_BIT)|(1<<Y_STEP_BIT)|(1<<Z_STEP_BIT)) // All step bits
|
||||
// Define step pulse output pins. NOTE: All step bit pins must be on the same port.
|
||||
#define STEP_DDR DDRD
|
||||
#define STEP_PORT PORTD
|
||||
#define X_STEP_BIT 2 // Uno Digital Pin 2
|
||||
#define Y_STEP_BIT 3 // Uno Digital Pin 3
|
||||
#define Z_STEP_BIT 4 // Uno Digital Pin 4
|
||||
#define STEP_MASK ((1 << X_STEP_BIT) | (1 << Y_STEP_BIT) | (1 << Z_STEP_BIT)) // All step bits
|
||||
|
||||
// Define step direction output pins. NOTE: All direction pins must be on the same port.
|
||||
#define DIRECTION_DDR DDRD
|
||||
#define DIRECTION_PORT PORTD
|
||||
#define X_DIRECTION_BIT 5 // Uno Digital Pin 5
|
||||
#define Y_DIRECTION_BIT 6 // Uno Digital Pin 6
|
||||
#define Z_DIRECTION_BIT 7 // Uno Digital Pin 7
|
||||
#define DIRECTION_MASK ((1<<X_DIRECTION_BIT)|(1<<Y_DIRECTION_BIT)|(1<<Z_DIRECTION_BIT)) // All direction bits
|
||||
// Define step direction output pins. NOTE: All direction pins must be on the same port.
|
||||
#define DIRECTION_DDR DDRD
|
||||
#define DIRECTION_PORT PORTD
|
||||
#define X_DIRECTION_BIT 5 // Uno Digital Pin 5
|
||||
#define Y_DIRECTION_BIT 6 // Uno Digital Pin 6
|
||||
#define Z_DIRECTION_BIT 7 // Uno Digital Pin 7
|
||||
#define DIRECTION_MASK ((1 << X_DIRECTION_BIT) | (1 << Y_DIRECTION_BIT) | (1 << Z_DIRECTION_BIT)) // All direction bits
|
||||
|
||||
// Define stepper driver enable/disable output pin.
|
||||
#define STEPPERS_DISABLE_DDR DDRB
|
||||
#define STEPPERS_DISABLE_PORT PORTB
|
||||
#define STEPPERS_DISABLE_BIT 0 // Uno Digital Pin 8
|
||||
#define STEPPERS_DISABLE_MASK (1<<STEPPERS_DISABLE_BIT)
|
||||
// Define stepper driver enable/disable output pin.
|
||||
#define STEPPERS_DISABLE_DDR DDRB
|
||||
#define STEPPERS_DISABLE_PORT PORTB
|
||||
#define STEPPERS_DISABLE_BIT 0 // Uno Digital Pin 8
|
||||
#define STEPPERS_DISABLE_MASK (1 << STEPPERS_DISABLE_BIT)
|
||||
|
||||
// Define homing/hard limit switch input pins and limit interrupt vectors.
|
||||
// NOTE: All limit bit pins must be on the same port, but not on a port with other input pins (CONTROL).
|
||||
#define LIMIT_DDR DDRB
|
||||
#define LIMIT_PIN PINB
|
||||
#define LIMIT_PORT PORTB
|
||||
#define X_LIMIT_BIT 1 // Uno Digital Pin 9
|
||||
#define Y_LIMIT_BIT 2 // Uno Digital Pin 10
|
||||
#ifdef VARIABLE_SPINDLE // Z Limit pin and spindle enabled swapped to access hardware PWM on Pin 11.
|
||||
#define Z_LIMIT_BIT 4 // Uno Digital Pin 12
|
||||
#else
|
||||
#define Z_LIMIT_BIT 3 // Uno Digital Pin 11
|
||||
#endif
|
||||
#if !defined(ENABLE_DUAL_AXIS)
|
||||
#define LIMIT_MASK ((1<<X_LIMIT_BIT)|(1<<Y_LIMIT_BIT)|(1<<Z_LIMIT_BIT)) // All limit bits
|
||||
#endif
|
||||
#define LIMIT_INT PCIE0 // Pin change interrupt enable pin
|
||||
#define LIMIT_INT_vect PCINT0_vect
|
||||
#define LIMIT_PCMSK PCMSK0 // Pin change interrupt register
|
||||
// Define homing/hard limit switch input pins and limit interrupt vectors.
|
||||
// NOTE: All limit bit pins must be on the same port, but not on a port with other input pins (CONTROL).
|
||||
#define LIMIT_DDR DDRB
|
||||
#define LIMIT_PIN PINB
|
||||
#define LIMIT_PORT PORTB
|
||||
#define X_LIMIT_BIT 1 // Uno Digital Pin 9
|
||||
#define Y_LIMIT_BIT 2 // Uno Digital Pin 10
|
||||
#ifdef VARIABLE_SPINDLE // Z Limit pin and spindle enabled swapped to access hardware PWM on Pin 11.
|
||||
#define Z_LIMIT_BIT 4 // Uno Digital Pin 12
|
||||
#else
|
||||
#define Z_LIMIT_BIT 3 // Uno Digital Pin 11
|
||||
#endif
|
||||
#if !defined(ENABLE_DUAL_AXIS)
|
||||
#define LIMIT_MASK ((1 << X_LIMIT_BIT) | (1 << Y_LIMIT_BIT) | (1 << Z_LIMIT_BIT)) // All limit bits
|
||||
#endif
|
||||
#define LIMIT_INT PCIE0 // Pin change interrupt enable pin
|
||||
#define LIMIT_INT_vect PCINT0_vect
|
||||
#define LIMIT_PCMSK PCMSK0 // Pin change interrupt register
|
||||
|
||||
// Define user-control controls (cycle start, reset, feed hold) input pins.
|
||||
// NOTE: All CONTROLs pins must be on the same port and not on a port with other input pins (limits).
|
||||
#define CONTROL_DDR DDRC
|
||||
#define CONTROL_PIN PINC
|
||||
#define CONTROL_PORT PORTC
|
||||
#define CONTROL_RESET_BIT 0 // Uno Analog Pin 0
|
||||
#define CONTROL_FEED_HOLD_BIT 1 // Uno Analog Pin 1
|
||||
#define CONTROL_CYCLE_START_BIT 2 // Uno Analog Pin 2
|
||||
#define CONTROL_SAFETY_DOOR_BIT 1 // Uno Analog Pin 1 NOTE: Safety door is shared with feed hold. Enabled by config define.
|
||||
#define CONTROL_INT PCIE1 // Pin change interrupt enable pin
|
||||
#define CONTROL_INT_vect PCINT1_vect
|
||||
#define CONTROL_PCMSK PCMSK1 // Pin change interrupt register
|
||||
#define CONTROL_MASK ((1<<CONTROL_RESET_BIT)|(1<<CONTROL_FEED_HOLD_BIT)|(1<<CONTROL_CYCLE_START_BIT)|(1<<CONTROL_SAFETY_DOOR_BIT))
|
||||
#define CONTROL_INVERT_MASK CONTROL_MASK // May be re-defined to only invert certain control pins.
|
||||
// Define user-control controls (cycle start, reset, feed hold) input pins.
|
||||
// NOTE: All CONTROLs pins must be on the same port and not on a port with other input pins (limits).
|
||||
#define CONTROL_DDR DDRC
|
||||
#define CONTROL_PIN PINC
|
||||
#define CONTROL_PORT PORTC
|
||||
#define CONTROL_RESET_BIT 0 // Uno Analog Pin 0
|
||||
#define CONTROL_FEED_HOLD_BIT 1 // Uno Analog Pin 1
|
||||
#define CONTROL_CYCLE_START_BIT 2 // Uno Analog Pin 2
|
||||
#define CONTROL_SAFETY_DOOR_BIT \
|
||||
1 // Uno Analog Pin 1 NOTE: Safety door is shared with feed hold. Enabled by config define.
|
||||
#define CONTROL_INT PCIE1 // Pin change interrupt enable pin
|
||||
#define CONTROL_INT_vect PCINT1_vect
|
||||
#define CONTROL_PCMSK PCMSK1 // Pin change interrupt register
|
||||
#define CONTROL_MASK \
|
||||
((1 << CONTROL_RESET_BIT) | (1 << CONTROL_FEED_HOLD_BIT) | (1 << CONTROL_CYCLE_START_BIT) | \
|
||||
(1 << CONTROL_SAFETY_DOOR_BIT))
|
||||
#define CONTROL_INVERT_MASK CONTROL_MASK // May be re-defined to only invert certain control pins.
|
||||
|
||||
// Define probe switch input pin.
|
||||
#define PROBE_DDR DDRC
|
||||
#define PROBE_PIN PINC
|
||||
#define PROBE_PORT PORTC
|
||||
#define PROBE_BIT 5 // Uno Analog Pin 5
|
||||
#define PROBE_MASK (1<<PROBE_BIT)
|
||||
// Define probe switch input pin.
|
||||
#define PROBE_DDR DDRC
|
||||
#define PROBE_PIN PINC
|
||||
#define PROBE_PORT PORTC
|
||||
#define PROBE_BIT 5 // Uno Analog Pin 5
|
||||
#define PROBE_MASK (1 << PROBE_BIT)
|
||||
|
||||
#if !defined(ENABLE_DUAL_AXIS)
|
||||
#if !defined(ENABLE_DUAL_AXIS)
|
||||
|
||||
// Define flood and mist coolant enable output pins.
|
||||
#define COOLANT_FLOOD_DDR DDRC
|
||||
#define COOLANT_FLOOD_PORT PORTC
|
||||
#define COOLANT_FLOOD_BIT 3 // Uno Analog Pin 3
|
||||
#define COOLANT_MIST_DDR DDRC
|
||||
#define COOLANT_MIST_PORT PORTC
|
||||
#define COOLANT_MIST_BIT 4 // Uno Analog Pin 4
|
||||
// Define flood and mist coolant enable output pins.
|
||||
#define COOLANT_FLOOD_DDR DDRC
|
||||
#define COOLANT_FLOOD_PORT PORTC
|
||||
#define COOLANT_FLOOD_BIT 3 // Uno Analog Pin 3
|
||||
#define COOLANT_MIST_DDR DDRC
|
||||
#define COOLANT_MIST_PORT PORTC
|
||||
#define COOLANT_MIST_BIT 4 // Uno Analog Pin 4
|
||||
|
||||
// Define spindle enable and spindle direction output pins.
|
||||
#define SPINDLE_ENABLE_DDR DDRB
|
||||
#define SPINDLE_ENABLE_PORT PORTB
|
||||
// Z Limit pin and spindle PWM/enable pin swapped to access hardware PWM on Pin 11.
|
||||
#ifdef VARIABLE_SPINDLE
|
||||
#ifdef USE_SPINDLE_DIR_AS_ENABLE_PIN
|
||||
// If enabled, spindle direction pin now used as spindle enable, while PWM remains on D11.
|
||||
#define SPINDLE_ENABLE_BIT 5 // Uno Digital Pin 13 (NOTE: D13 can't be pulled-high input due to LED.)
|
||||
#else
|
||||
#define SPINDLE_ENABLE_BIT 3 // Uno Digital Pin 11
|
||||
#endif
|
||||
#else
|
||||
#define SPINDLE_ENABLE_BIT 4 // Uno Digital Pin 12
|
||||
#endif
|
||||
#ifndef USE_SPINDLE_DIR_AS_ENABLE_PIN
|
||||
#define SPINDLE_DIRECTION_DDR DDRB
|
||||
#define SPINDLE_DIRECTION_PORT PORTB
|
||||
#define SPINDLE_DIRECTION_BIT 5 // Uno Digital Pin 13 (NOTE: D13 can't be pulled-high input due to LED.)
|
||||
#endif
|
||||
// Define spindle enable and spindle direction output pins.
|
||||
#define SPINDLE_ENABLE_DDR DDRB
|
||||
#define SPINDLE_ENABLE_PORT PORTB
|
||||
// Z Limit pin and spindle PWM/enable pin swapped to access hardware PWM on Pin 11.
|
||||
#ifdef VARIABLE_SPINDLE
|
||||
#ifdef USE_SPINDLE_DIR_AS_ENABLE_PIN
|
||||
// If enabled, spindle direction pin now used as spindle enable, while PWM remains on D11.
|
||||
#define SPINDLE_ENABLE_BIT 5 // Uno Digital Pin 13 (NOTE: D13 can't be pulled-high input due to LED.)
|
||||
#else
|
||||
#define SPINDLE_ENABLE_BIT 3 // Uno Digital Pin 11
|
||||
#endif
|
||||
#else
|
||||
#define SPINDLE_ENABLE_BIT 4 // Uno Digital Pin 12
|
||||
#endif
|
||||
#ifndef USE_SPINDLE_DIR_AS_ENABLE_PIN
|
||||
#define SPINDLE_DIRECTION_DDR DDRB
|
||||
#define SPINDLE_DIRECTION_PORT PORTB
|
||||
#define SPINDLE_DIRECTION_BIT 5 // Uno Digital Pin 13 (NOTE: D13 can't be pulled-high input due to LED.)
|
||||
#endif
|
||||
|
||||
// Variable spindle configuration below. Do not change unless you know what you are doing.
|
||||
// NOTE: Only used when variable spindle is enabled.
|
||||
#define SPINDLE_PWM_MAX_VALUE 255 // Don't change. 328p fast PWM mode fixes top value as 255.
|
||||
#ifndef SPINDLE_PWM_MIN_VALUE
|
||||
#define SPINDLE_PWM_MIN_VALUE 1 // Must be greater than zero.
|
||||
#endif
|
||||
#define SPINDLE_PWM_OFF_VALUE 0
|
||||
#define SPINDLE_PWM_RANGE (SPINDLE_PWM_MAX_VALUE-SPINDLE_PWM_MIN_VALUE)
|
||||
#define SPINDLE_TCCRA_REGISTER TCCR2A
|
||||
#define SPINDLE_TCCRB_REGISTER TCCR2B
|
||||
#define SPINDLE_OCR_REGISTER OCR2A
|
||||
#define SPINDLE_COMB_BIT COM2A1
|
||||
// Variable spindle configuration below. Do not change unless you know what you are doing.
|
||||
// NOTE: Only used when variable spindle is enabled.
|
||||
#define SPINDLE_PWM_MAX_VALUE 255 // Don't change. 328p fast PWM mode fixes top value as 255.
|
||||
#ifndef SPINDLE_PWM_MIN_VALUE
|
||||
#define SPINDLE_PWM_MIN_VALUE 1 // Must be greater than zero.
|
||||
#endif
|
||||
#define SPINDLE_PWM_OFF_VALUE 0
|
||||
#define SPINDLE_PWM_RANGE (SPINDLE_PWM_MAX_VALUE - SPINDLE_PWM_MIN_VALUE)
|
||||
#define SPINDLE_TCCRA_REGISTER TCCR2A
|
||||
#define SPINDLE_TCCRB_REGISTER TCCR2B
|
||||
#define SPINDLE_OCR_REGISTER OCR2A
|
||||
#define SPINDLE_COMB_BIT COM2A1
|
||||
|
||||
// Prescaled, 8-bit Fast PWM mode.
|
||||
#define SPINDLE_TCCRA_INIT_MASK ((1<<WGM20) | (1<<WGM21)) // Configures fast PWM mode.
|
||||
// #define SPINDLE_TCCRB_INIT_MASK (1<<CS20) // Disable prescaler -> 62.5kHz
|
||||
// #define SPINDLE_TCCRB_INIT_MASK (1<<CS21) // 1/8 prescaler -> 7.8kHz (Used in v0.9)
|
||||
// #define SPINDLE_TCCRB_INIT_MASK ((1<<CS21) | (1<<CS20)) // 1/32 prescaler -> 1.96kHz
|
||||
#define SPINDLE_TCCRB_INIT_MASK (1<<CS22) // 1/64 prescaler -> 0.98kHz (J-tech laser)
|
||||
// Prescaled, 8-bit Fast PWM mode.
|
||||
#define SPINDLE_TCCRA_INIT_MASK ((1 << WGM20) | (1 << WGM21)) // Configures fast PWM mode.
|
||||
// #define SPINDLE_TCCRB_INIT_MASK (1<<CS20) // Disable prescaler -> 62.5kHz
|
||||
// #define SPINDLE_TCCRB_INIT_MASK (1<<CS21) // 1/8 prescaler -> 7.8kHz (Used in v0.9)
|
||||
// #define SPINDLE_TCCRB_INIT_MASK ((1<<CS21) | (1<<CS20)) // 1/32 prescaler -> 1.96kHz
|
||||
#define SPINDLE_TCCRB_INIT_MASK (1 << CS22) // 1/64 prescaler -> 0.98kHz (J-tech laser)
|
||||
|
||||
// NOTE: On the 328p, these must be the same as the SPINDLE_ENABLE settings.
|
||||
#define SPINDLE_PWM_DDR DDRB
|
||||
#define SPINDLE_PWM_PORT PORTB
|
||||
#define SPINDLE_PWM_BIT 3 // Uno Digital Pin 11
|
||||
// NOTE: On the 328p, these must be the same as the SPINDLE_ENABLE settings.
|
||||
#define SPINDLE_PWM_DDR DDRB
|
||||
#define SPINDLE_PWM_PORT PORTB
|
||||
#define SPINDLE_PWM_BIT 3 // Uno Digital Pin 11
|
||||
|
||||
#else
|
||||
#else
|
||||
|
||||
// Dual axis feature requires an independent step pulse pin to operate. The independent direction pin is not
|
||||
// absolutely necessary but facilitates easy direction inverting with a Grbl $$ setting. These pins replace
|
||||
// the spindle direction and optional coolant mist pins.
|
||||
// Dual axis feature requires an independent step pulse pin to operate. The independent direction pin is not
|
||||
// absolutely necessary but facilitates easy direction inverting with a Grbl $$ setting. These pins replace
|
||||
// the spindle direction and optional coolant mist pins.
|
||||
|
||||
#ifdef DUAL_AXIS_CONFIG_PROTONEER_V3_51
|
||||
// NOTE: Step pulse and direction pins may be on any port and output pin.
|
||||
#define STEP_DDR_DUAL DDRC
|
||||
#define STEP_PORT_DUAL PORTC
|
||||
#define DUAL_STEP_BIT 4 // Uno Analog Pin 4
|
||||
#define STEP_MASK_DUAL ((1<<DUAL_STEP_BIT))
|
||||
#define DIRECTION_DDR_DUAL DDRC
|
||||
#define DIRECTION_PORT_DUAL PORTC
|
||||
#define DUAL_DIRECTION_BIT 3 // Uno Analog Pin 3
|
||||
#define DIRECTION_MASK_DUAL ((1<<DUAL_DIRECTION_BIT))
|
||||
#ifdef DUAL_AXIS_CONFIG_PROTONEER_V3_51
|
||||
// NOTE: Step pulse and direction pins may be on any port and output pin.
|
||||
#define STEP_DDR_DUAL DDRC
|
||||
#define STEP_PORT_DUAL PORTC
|
||||
#define DUAL_STEP_BIT 4 // Uno Analog Pin 4
|
||||
#define STEP_MASK_DUAL ((1 << DUAL_STEP_BIT))
|
||||
#define DIRECTION_DDR_DUAL DDRC
|
||||
#define DIRECTION_PORT_DUAL PORTC
|
||||
#define DUAL_DIRECTION_BIT 3 // Uno Analog Pin 3
|
||||
#define DIRECTION_MASK_DUAL ((1 << DUAL_DIRECTION_BIT))
|
||||
|
||||
// NOTE: Dual axis limit is shared with the z-axis limit pin by default. Pin used must be on the same port
|
||||
// as other limit pins.
|
||||
#define DUAL_LIMIT_BIT Z_LIMIT_BIT
|
||||
#define LIMIT_MASK ((1<<X_LIMIT_BIT)|(1<<Y_LIMIT_BIT)|(1<<Z_LIMIT_BIT)|(1<<DUAL_LIMIT_BIT))
|
||||
// NOTE: Dual axis limit is shared with the z-axis limit pin by default. Pin used must be on the same port
|
||||
// as other limit pins.
|
||||
#define DUAL_LIMIT_BIT Z_LIMIT_BIT
|
||||
#define LIMIT_MASK ((1 << X_LIMIT_BIT) | (1 << Y_LIMIT_BIT) | (1 << Z_LIMIT_BIT) | (1 << DUAL_LIMIT_BIT))
|
||||
|
||||
// Define coolant enable output pins.
|
||||
// NOTE: Coolant flood moved from A3 to A4. Coolant mist not supported with dual axis feature on Arduino Uno.
|
||||
#define COOLANT_FLOOD_DDR DDRB
|
||||
#define COOLANT_FLOOD_PORT PORTB
|
||||
#define COOLANT_FLOOD_BIT 5 // Uno Digital Pin 13
|
||||
// Define coolant enable output pins.
|
||||
// NOTE: Coolant flood moved from A3 to A4. Coolant mist not supported with dual axis feature on Arduino Uno.
|
||||
#define COOLANT_FLOOD_DDR DDRB
|
||||
#define COOLANT_FLOOD_PORT PORTB
|
||||
#define COOLANT_FLOOD_BIT 5 // Uno Digital Pin 13
|
||||
|
||||
// Define spindle enable output pin.
|
||||
// NOTE: Spindle enable moved from D12 to A3 (old coolant flood enable pin). Spindle direction pin is removed.
|
||||
#define SPINDLE_ENABLE_DDR DDRB
|
||||
#define SPINDLE_ENABLE_PORT PORTB
|
||||
#ifdef VARIABLE_SPINDLE
|
||||
// NOTE: USE_SPINDLE_DIR_AS_ENABLE_PIN not supported with dual axis feature.
|
||||
#define SPINDLE_ENABLE_BIT 3 // Uno Digital Pin 11
|
||||
#else
|
||||
#define SPINDLE_ENABLE_BIT 4 // Uno Digital Pin 12
|
||||
#endif
|
||||
// Define spindle enable output pin.
|
||||
// NOTE: Spindle enable moved from D12 to A3 (old coolant flood enable pin). Spindle direction pin is removed.
|
||||
#define SPINDLE_ENABLE_DDR DDRB
|
||||
#define SPINDLE_ENABLE_PORT PORTB
|
||||
#ifdef VARIABLE_SPINDLE
|
||||
// NOTE: USE_SPINDLE_DIR_AS_ENABLE_PIN not supported with dual axis feature.
|
||||
#define SPINDLE_ENABLE_BIT 3 // Uno Digital Pin 11
|
||||
#else
|
||||
#define SPINDLE_ENABLE_BIT 4 // Uno Digital Pin 12
|
||||
#endif
|
||||
|
||||
// Variable spindle configuration below. Do not change unless you know what you are doing.
|
||||
// NOTE: Only used when variable spindle is enabled.
|
||||
#define SPINDLE_PWM_MAX_VALUE 255 // Don't change. 328p fast PWM mode fixes top value as 255.
|
||||
#ifndef SPINDLE_PWM_MIN_VALUE
|
||||
#define SPINDLE_PWM_MIN_VALUE 1 // Must be greater than zero.
|
||||
#endif
|
||||
#define SPINDLE_PWM_OFF_VALUE 0
|
||||
#define SPINDLE_PWM_RANGE (SPINDLE_PWM_MAX_VALUE-SPINDLE_PWM_MIN_VALUE)
|
||||
#define SPINDLE_TCCRA_REGISTER TCCR2A
|
||||
#define SPINDLE_TCCRB_REGISTER TCCR2B
|
||||
#define SPINDLE_OCR_REGISTER OCR2A
|
||||
#define SPINDLE_COMB_BIT COM2A1
|
||||
// Variable spindle configuration below. Do not change unless you know what you are doing.
|
||||
// NOTE: Only used when variable spindle is enabled.
|
||||
#define SPINDLE_PWM_MAX_VALUE 255 // Don't change. 328p fast PWM mode fixes top value as 255.
|
||||
#ifndef SPINDLE_PWM_MIN_VALUE
|
||||
#define SPINDLE_PWM_MIN_VALUE 1 // Must be greater than zero.
|
||||
#endif
|
||||
#define SPINDLE_PWM_OFF_VALUE 0
|
||||
#define SPINDLE_PWM_RANGE (SPINDLE_PWM_MAX_VALUE - SPINDLE_PWM_MIN_VALUE)
|
||||
#define SPINDLE_TCCRA_REGISTER TCCR2A
|
||||
#define SPINDLE_TCCRB_REGISTER TCCR2B
|
||||
#define SPINDLE_OCR_REGISTER OCR2A
|
||||
#define SPINDLE_COMB_BIT COM2A1
|
||||
|
||||
// Prescaled, 8-bit Fast PWM mode.
|
||||
#define SPINDLE_TCCRA_INIT_MASK ((1<<WGM20) | (1<<WGM21)) // Configures fast PWM mode.
|
||||
// #define SPINDLE_TCCRB_INIT_MASK (1<<CS20) // Disable prescaler -> 62.5kHz
|
||||
// #define SPINDLE_TCCRB_INIT_MASK (1<<CS21) // 1/8 prescaler -> 7.8kHz (Used in v0.9)
|
||||
// #define SPINDLE_TCCRB_INIT_MASK ((1<<CS21) | (1<<CS20)) // 1/32 prescaler -> 1.96kHz
|
||||
#define SPINDLE_TCCRB_INIT_MASK (1<<CS22) // 1/64 prescaler -> 0.98kHz (J-tech laser)
|
||||
// Prescaled, 8-bit Fast PWM mode.
|
||||
#define SPINDLE_TCCRA_INIT_MASK ((1 << WGM20) | (1 << WGM21)) // Configures fast PWM mode.
|
||||
// #define SPINDLE_TCCRB_INIT_MASK (1<<CS20) // Disable prescaler -> 62.5kHz
|
||||
// #define SPINDLE_TCCRB_INIT_MASK (1<<CS21) // 1/8 prescaler -> 7.8kHz (Used in v0.9)
|
||||
// #define SPINDLE_TCCRB_INIT_MASK ((1<<CS21) | (1<<CS20)) // 1/32 prescaler -> 1.96kHz
|
||||
#define SPINDLE_TCCRB_INIT_MASK (1 << CS22) // 1/64 prescaler -> 0.98kHz (J-tech laser)
|
||||
|
||||
// NOTE: On the 328p, these must be the same as the SPINDLE_ENABLE settings.
|
||||
#define SPINDLE_PWM_DDR DDRB
|
||||
#define SPINDLE_PWM_PORT PORTB
|
||||
#define SPINDLE_PWM_BIT 3 // Uno Digital Pin 11
|
||||
#endif
|
||||
// NOTE: On the 328p, these must be the same as the SPINDLE_ENABLE settings.
|
||||
#define SPINDLE_PWM_DDR DDRB
|
||||
#define SPINDLE_PWM_PORT PORTB
|
||||
#define SPINDLE_PWM_BIT 3 // Uno Digital Pin 11
|
||||
#endif
|
||||
|
||||
// NOTE: Variable spindle not supported with this shield.
|
||||
#ifdef DUAL_AXIS_CONFIG_CNC_SHIELD_CLONE
|
||||
// NOTE: Step pulse and direction pins may be on any port and output pin.
|
||||
#define STEP_DDR_DUAL DDRB
|
||||
#define STEP_PORT_DUAL PORTB
|
||||
#define DUAL_STEP_BIT 4 // Uno Digital Pin 12
|
||||
#define STEP_MASK_DUAL ((1<<DUAL_STEP_BIT))
|
||||
#define DIRECTION_DDR_DUAL DDRB
|
||||
#define DIRECTION_PORT_DUAL PORTB
|
||||
#define DUAL_DIRECTION_BIT 5 // Uno Digital Pin 13
|
||||
#define DIRECTION_MASK_DUAL ((1<<DUAL_DIRECTION_BIT))
|
||||
// NOTE: Variable spindle not supported with this shield.
|
||||
#ifdef DUAL_AXIS_CONFIG_CNC_SHIELD_CLONE
|
||||
// NOTE: Step pulse and direction pins may be on any port and output pin.
|
||||
#define STEP_DDR_DUAL DDRB
|
||||
#define STEP_PORT_DUAL PORTB
|
||||
#define DUAL_STEP_BIT 4 // Uno Digital Pin 12
|
||||
#define STEP_MASK_DUAL ((1 << DUAL_STEP_BIT))
|
||||
#define DIRECTION_DDR_DUAL DDRB
|
||||
#define DIRECTION_PORT_DUAL PORTB
|
||||
#define DUAL_DIRECTION_BIT 5 // Uno Digital Pin 13
|
||||
#define DIRECTION_MASK_DUAL ((1 << DUAL_DIRECTION_BIT))
|
||||
|
||||
// NOTE: Dual axis limit is shared with the z-axis limit pin by default.
|
||||
#define DUAL_LIMIT_BIT Z_LIMIT_BIT
|
||||
#define LIMIT_MASK ((1<<X_LIMIT_BIT)|(1<<Y_LIMIT_BIT)|(1<<Z_LIMIT_BIT)|(1<<DUAL_LIMIT_BIT))
|
||||
// NOTE: Dual axis limit is shared with the z-axis limit pin by default.
|
||||
#define DUAL_LIMIT_BIT Z_LIMIT_BIT
|
||||
#define LIMIT_MASK ((1 << X_LIMIT_BIT) | (1 << Y_LIMIT_BIT) | (1 << Z_LIMIT_BIT) | (1 << DUAL_LIMIT_BIT))
|
||||
|
||||
// Define coolant enable output pins.
|
||||
// NOTE: Coolant flood moved from A3 to A4. Coolant mist not supported with dual axis feature on Arduino Uno.
|
||||
#define COOLANT_FLOOD_DDR DDRC
|
||||
#define COOLANT_FLOOD_PORT PORTC
|
||||
#define COOLANT_FLOOD_BIT 4 // Uno Analog Pin 4
|
||||
// Define coolant enable output pins.
|
||||
// NOTE: Coolant flood moved from A3 to A4. Coolant mist not supported with dual axis feature on Arduino Uno.
|
||||
#define COOLANT_FLOOD_DDR DDRC
|
||||
#define COOLANT_FLOOD_PORT PORTC
|
||||
#define COOLANT_FLOOD_BIT 4 // Uno Analog Pin 4
|
||||
|
||||
// Define spindle enable output pin.
|
||||
// NOTE: Spindle enable moved from D12 to A3 (old coolant flood enable pin). Spindle direction pin is removed.
|
||||
#define SPINDLE_ENABLE_DDR DDRC
|
||||
#define SPINDLE_ENABLE_PORT PORTC
|
||||
#define SPINDLE_ENABLE_BIT 3 // Uno Analog Pin 3
|
||||
#endif
|
||||
// Define spindle enable output pin.
|
||||
// NOTE: Spindle enable moved from D12 to A3 (old coolant flood enable pin). Spindle direction pin is removed.
|
||||
#define SPINDLE_ENABLE_DDR DDRC
|
||||
#define SPINDLE_ENABLE_PORT PORTC
|
||||
#define SPINDLE_ENABLE_BIT 3 // Uno Analog Pin 3
|
||||
#endif
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
|||
1004
grbl/defaults.h
1004
grbl/defaults.h
File diff suppressed because it is too large
Load diff
102
grbl/eeprom.c
102
grbl/eeprom.c
|
|
@ -1,33 +1,33 @@
|
|||
// This file has been prepared for Doxygen automatic documentation generation.
|
||||
/*! \file ********************************************************************
|
||||
*
|
||||
* Atmel Corporation
|
||||
*
|
||||
* \li File: eeprom.c
|
||||
* \li Compiler: IAR EWAAVR 3.10c
|
||||
* \li Support mail: avr@atmel.com
|
||||
*
|
||||
* \li Supported devices: All devices with split EEPROM erase/write
|
||||
* capabilities can be used.
|
||||
* The example is written for ATmega48.
|
||||
*
|
||||
* \li AppNote: AVR103 - Using the EEPROM Programming Modes.
|
||||
*
|
||||
* \li Description: Example on how to use the split EEPROM erase/write
|
||||
* capabilities in e.g. ATmega48. All EEPROM
|
||||
* programming modes are tested, i.e. Erase+Write,
|
||||
* Erase-only and Write-only.
|
||||
*
|
||||
* $Revision: 1.6 $
|
||||
* $Date: Friday, February 11, 2005 07:16:44 UTC $
|
||||
****************************************************************************/
|
||||
#include <avr/io.h>
|
||||
*
|
||||
* Atmel Corporation
|
||||
*
|
||||
* \li File: eeprom.c
|
||||
* \li Compiler: IAR EWAAVR 3.10c
|
||||
* \li Support mail: avr@atmel.com
|
||||
*
|
||||
* \li Supported devices: All devices with split EEPROM erase/write
|
||||
* capabilities can be used.
|
||||
* The example is written for ATmega48.
|
||||
*
|
||||
* \li AppNote: AVR103 - Using the EEPROM Programming Modes.
|
||||
*
|
||||
* \li Description: Example on how to use the split EEPROM erase/write
|
||||
* capabilities in e.g. ATmega48. All EEPROM
|
||||
* programming modes are tested, i.e. Erase+Write,
|
||||
* Erase-only and Write-only.
|
||||
*
|
||||
* $Revision: 1.6 $
|
||||
* $Date: Friday, February 11, 2005 07:16:44 UTC $
|
||||
****************************************************************************/
|
||||
#include <avr/interrupt.h>
|
||||
#include <avr/io.h>
|
||||
|
||||
/* These EEPROM bits have different names on different devices. */
|
||||
#ifndef EEPE
|
||||
#define EEPE EEWE //!< EEPROM program/write enable.
|
||||
#define EEMPE EEMWE //!< EEPROM master program/write enable.
|
||||
#define EEPE EEWE //!< EEPROM program/write enable.
|
||||
#define EEMPE EEMWE //!< EEPROM master program/write enable.
|
||||
#endif
|
||||
|
||||
/* These two are unfortunately not defined in the device include files. */
|
||||
|
|
@ -46,11 +46,11 @@
|
|||
* \param addr EEPROM address to read from.
|
||||
* \return The byte read from the EEPROM address.
|
||||
*/
|
||||
unsigned char eeprom_get_char( unsigned int addr )
|
||||
{
|
||||
do {} while( EECR & (1<<EEPE) ); // Wait for completion of previous write.
|
||||
unsigned char eeprom_get_char(unsigned int addr) {
|
||||
do {
|
||||
} while (EECR & (1 << EEPE)); // Wait for completion of previous write.
|
||||
EEAR = addr; // Set EEPROM address register.
|
||||
EECR = (1<<EERE); // Start EEPROM read operation.
|
||||
EECR = (1 << EERE); // Start EEPROM read operation.
|
||||
return EEDR; // Return the byte read from EEPROM.
|
||||
}
|
||||
|
||||
|
|
@ -71,53 +71,54 @@ unsigned char eeprom_get_char( unsigned int addr )
|
|||
* \param addr EEPROM address to write to.
|
||||
* \param new_value New EEPROM value.
|
||||
*/
|
||||
void eeprom_put_char( unsigned int addr, unsigned char new_value )
|
||||
{
|
||||
void eeprom_put_char(unsigned int addr, unsigned char new_value) {
|
||||
char old_value; // Old EEPROM value.
|
||||
char diff_mask; // Difference mask, i.e. old value XOR new value.
|
||||
|
||||
cli(); // Ensure atomic operation for the write operation.
|
||||
|
||||
do {} while( EECR & (1<<EEPE) ); // Wait for completion of previous write.
|
||||
#ifndef EEPROM_IGNORE_SELFPROG
|
||||
do {} while( SPMCSR & (1<<SELFPRGEN) ); // Wait for completion of SPM.
|
||||
#endif
|
||||
do {
|
||||
} while (EECR & (1 << EEPE)); // Wait for completion of previous write.
|
||||
#ifndef EEPROM_IGNORE_SELFPROG
|
||||
do {
|
||||
} while (SPMCSR & (1 << SELFPRGEN)); // Wait for completion of SPM.
|
||||
#endif
|
||||
|
||||
EEAR = addr; // Set EEPROM address register.
|
||||
EECR = (1<<EERE); // Start EEPROM read operation.
|
||||
EECR = (1 << EERE); // Start EEPROM read operation.
|
||||
old_value = EEDR; // Get old EEPROM value.
|
||||
diff_mask = old_value ^ new_value; // Get bit differences.
|
||||
|
||||
// Check if any bits are changed to '1' in the new value.
|
||||
if( diff_mask & new_value ) {
|
||||
if (diff_mask & new_value) {
|
||||
// Now we know that _some_ bits need to be erased to '1'.
|
||||
|
||||
// Check if any bits in the new value are '0'.
|
||||
if( new_value != 0xff ) {
|
||||
if (new_value != 0xff) {
|
||||
// Now we know that some bits need to be programmed to '0' also.
|
||||
|
||||
EEDR = new_value; // Set EEPROM data register.
|
||||
EECR = (1<<EEMPE) | // Set Master Write Enable bit...
|
||||
(0<<EEPM1) | (0<<EEPM0); // ...and Erase+Write mode.
|
||||
EECR |= (1<<EEPE); // Start Erase+Write operation.
|
||||
EECR = (1 << EEMPE) | // Set Master Write Enable bit...
|
||||
(0 << EEPM1) | (0 << EEPM0); // ...and Erase+Write mode.
|
||||
EECR |= (1 << EEPE); // Start Erase+Write operation.
|
||||
} else {
|
||||
// Now we know that all bits should be erased.
|
||||
|
||||
EECR = (1<<EEMPE) | // Set Master Write Enable bit...
|
||||
(1<<EEPM0); // ...and Erase-only mode.
|
||||
EECR |= (1<<EEPE); // Start Erase-only operation.
|
||||
EECR = (1 << EEMPE) | // Set Master Write Enable bit...
|
||||
(1 << EEPM0); // ...and Erase-only mode.
|
||||
EECR |= (1 << EEPE); // Start Erase-only operation.
|
||||
}
|
||||
} else {
|
||||
// Now we know that _no_ bits need to be erased to '1'.
|
||||
|
||||
// Check if any bits are changed from '1' in the old value.
|
||||
if( diff_mask ) {
|
||||
if (diff_mask) {
|
||||
// Now we know that _some_ bits need to the programmed to '0'.
|
||||
|
||||
EEDR = new_value; // Set EEPROM data register.
|
||||
EECR = (1<<EEMPE) | // Set Master Write Enable bit...
|
||||
(1<<EEPM1); // ...and Write-only mode.
|
||||
EECR |= (1<<EEPE); // Start Write-only operation.
|
||||
EECR = (1 << EEMPE) | // Set Master Write Enable bit...
|
||||
(1 << EEPM1); // ...and Write-only mode.
|
||||
EECR |= (1 << EEPE); // Start Write-only operation.
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -126,10 +127,9 @@ void eeprom_put_char( unsigned int addr, unsigned char new_value )
|
|||
|
||||
// Extensions added as part of Grbl
|
||||
|
||||
|
||||
void memcpy_to_eeprom_with_checksum(unsigned int destination, char *source, unsigned int size) {
|
||||
unsigned char checksum = 0;
|
||||
for(; size > 0; size--) {
|
||||
for (; size > 0; size--) {
|
||||
checksum = ((checksum << 1) != 0) || (checksum >> 7);
|
||||
checksum += *source;
|
||||
eeprom_put_char(destination++, *(source++));
|
||||
|
|
@ -139,13 +139,13 @@ void memcpy_to_eeprom_with_checksum(unsigned int destination, char *source, unsi
|
|||
|
||||
int memcpy_from_eeprom_with_checksum(char *destination, unsigned int source, unsigned int size) {
|
||||
unsigned char data, checksum = 0;
|
||||
for(; size > 0; size--) {
|
||||
for (; size > 0; size--) {
|
||||
data = eeprom_get_char(source++);
|
||||
checksum = ((checksum << 1) != 0) || (checksum >> 7);
|
||||
checksum += data;
|
||||
*(destination++) = data;
|
||||
}
|
||||
return(checksum == eeprom_get_char(source));
|
||||
return (checksum == eeprom_get_char(source));
|
||||
}
|
||||
|
||||
// end of file
|
||||
|
|
|
|||
733
grbl/gcode.c
733
grbl/gcode.c
File diff suppressed because it is too large
Load diff
20
grbl/gcode.h
20
grbl/gcode.h
|
|
@ -22,7 +22,6 @@
|
|||
#ifndef gcode_h
|
||||
#define gcode_h
|
||||
|
||||
|
||||
// Define modal group internal numbers for checking multiple command violations and tracking the
|
||||
// type of command that is called in the block. A modal group is a group of g-code commands that are
|
||||
// mutually exclusive, or cannot exist on the same line, because they each toggle a state or execute
|
||||
|
|
@ -63,7 +62,7 @@
|
|||
#define NON_MODAL_SET_HOME_1 40 // G30.1 (Do not alter value)
|
||||
#define NON_MODAL_ABSOLUTE_OVERRIDE 53 // G53 (Do not alter value)
|
||||
#define NON_MODAL_SET_COORDINATE_OFFSET 92 // G92 (Do not alter value)
|
||||
#define NON_MODAL_RESET_COORDINATE_OFFSET 102 //G92.1 (Do not alter value)
|
||||
#define NON_MODAL_RESET_COORDINATE_OFFSET 102 // G92.1 (Do not alter value)
|
||||
|
||||
// Modal Group G1: Motion modes
|
||||
#define MOTION_MODE_SEEK 0 // G0 (Default: Must be zero)
|
||||
|
|
@ -125,11 +124,11 @@
|
|||
|
||||
// Modal Group M9: Override control
|
||||
#ifdef DEACTIVATE_PARKING_UPON_INIT
|
||||
#define OVERRIDE_DISABLED 0 // (Default: Must be zero)
|
||||
#define OVERRIDE_PARKING_MOTION 1 // M56
|
||||
#define OVERRIDE_DISABLED 0 // (Default: Must be zero)
|
||||
#define OVERRIDE_PARKING_MOTION 1 // M56
|
||||
#else
|
||||
#define OVERRIDE_PARKING_MOTION 0 // M56 (Default: Must be zero)
|
||||
#define OVERRIDE_DISABLED 1 // Parking disabled.
|
||||
#define OVERRIDE_PARKING_MOTION 0 // M56 (Default: Must be zero)
|
||||
#define OVERRIDE_DISABLED 1 // Parking disabled.
|
||||
#endif
|
||||
|
||||
// Modal Group G12: Active work coordinate system
|
||||
|
|
@ -161,9 +160,9 @@
|
|||
#define GC_PROBE_FAIL_INIT GC_UPDATE_POS_NONE
|
||||
#define GC_PROBE_FAIL_END GC_UPDATE_POS_TARGET
|
||||
#ifdef SET_CHECK_MODE_PROBE_TO_START
|
||||
#define GC_PROBE_CHECK_MODE GC_UPDATE_POS_NONE
|
||||
#define GC_PROBE_CHECK_MODE GC_UPDATE_POS_NONE
|
||||
#else
|
||||
#define GC_PROBE_CHECK_MODE GC_UPDATE_POS_TARGET
|
||||
#define GC_PROBE_CHECK_MODE GC_UPDATE_POS_TARGET
|
||||
#endif
|
||||
|
||||
// Define gcode parser flags for handling special cases.
|
||||
|
|
@ -177,7 +176,6 @@
|
|||
#define GC_PARSER_LASER_DISABLE bit(6)
|
||||
#define GC_PARSER_LASER_ISMOTION bit(7)
|
||||
|
||||
|
||||
// NOTE: When this struct is zeroed, the above defines set the defaults for the system.
|
||||
typedef struct {
|
||||
uint8_t motion; // {G0,G1,G2,G3,G38.2,G80}
|
||||
|
|
@ -209,7 +207,6 @@ typedef struct {
|
|||
float xyz[3]; // X,Y,Z Translational axes
|
||||
} gc_values_t;
|
||||
|
||||
|
||||
typedef struct {
|
||||
gc_modal_t modal;
|
||||
|
||||
|
|
@ -226,8 +223,8 @@ typedef struct {
|
|||
// machine zero in mm. Non-persistent. Cleared upon reset and boot.
|
||||
float tool_length_offset; // Tracks tool length offset value when enabled.
|
||||
} parser_state_t;
|
||||
extern parser_state_t gc_state;
|
||||
|
||||
extern parser_state_t gc_state;
|
||||
|
||||
typedef struct {
|
||||
uint8_t non_modal_command;
|
||||
|
|
@ -235,7 +232,6 @@ typedef struct {
|
|||
gc_values_t values;
|
||||
} parser_block_t;
|
||||
|
||||
|
||||
// Initialize the parser
|
||||
void gc_init();
|
||||
|
||||
|
|
|
|||
101
grbl/grbl.h
101
grbl/grbl.h
|
|
@ -26,113 +26,112 @@
|
|||
#define GRBL_VERSION_BUILD "20190830"
|
||||
|
||||
// Define standard libraries used by Grbl.
|
||||
#include <avr/interrupt.h>
|
||||
#include <avr/io.h>
|
||||
#include <avr/pgmspace.h>
|
||||
#include <avr/interrupt.h>
|
||||
#include <avr/wdt.h>
|
||||
#include <util/delay.h>
|
||||
#include <math.h>
|
||||
#include <inttypes.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <math.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <util/delay.h>
|
||||
|
||||
// Define the Grbl system include files. NOTE: Do not alter organization.
|
||||
#include "config.h"
|
||||
#include "nuts_bolts.h"
|
||||
#include "settings.h"
|
||||
#include "system.h"
|
||||
#include "defaults.h"
|
||||
#include "cpu_map.h"
|
||||
#include "planner.h"
|
||||
#include "coolant_control.h"
|
||||
#include "cpu_map.h"
|
||||
#include "defaults.h"
|
||||
#include "eeprom.h"
|
||||
#include "gcode.h"
|
||||
#include "jog.h"
|
||||
#include "limits.h"
|
||||
#include "motion_control.h"
|
||||
#include "nuts_bolts.h"
|
||||
#include "planner.h"
|
||||
#include "print.h"
|
||||
#include "probe.h"
|
||||
#include "protocol.h"
|
||||
#include "report.h"
|
||||
#include "serial.h"
|
||||
#include "settings.h"
|
||||
#include "spindle_control.h"
|
||||
#include "stepper.h"
|
||||
#include "jog.h"
|
||||
#include "system.h"
|
||||
|
||||
// ---------------------------------------------------------------------------------------
|
||||
// COMPILE-TIME ERROR CHECKING OF DEFINE VALUES:
|
||||
|
||||
#ifndef HOMING_CYCLE_0
|
||||
#error "Required HOMING_CYCLE_0 not defined."
|
||||
#error "Required HOMING_CYCLE_0 not defined."
|
||||
#endif
|
||||
|
||||
#if defined(USE_SPINDLE_DIR_AS_ENABLE_PIN) && !defined(VARIABLE_SPINDLE)
|
||||
#error "USE_SPINDLE_DIR_AS_ENABLE_PIN may only be used with VARIABLE_SPINDLE enabled"
|
||||
#error "USE_SPINDLE_DIR_AS_ENABLE_PIN may only be used with VARIABLE_SPINDLE enabled"
|
||||
#endif
|
||||
|
||||
#if defined(USE_SPINDLE_DIR_AS_ENABLE_PIN) && !defined(CPU_MAP_ATMEGA328P)
|
||||
#error "USE_SPINDLE_DIR_AS_ENABLE_PIN may only be used with a 328p processor"
|
||||
#error "USE_SPINDLE_DIR_AS_ENABLE_PIN may only be used with a 328p processor"
|
||||
#endif
|
||||
|
||||
#if !defined(USE_SPINDLE_DIR_AS_ENABLE_PIN) && defined(SPINDLE_ENABLE_OFF_WITH_ZERO_SPEED)
|
||||
#error "SPINDLE_ENABLE_OFF_WITH_ZERO_SPEED may only be used with USE_SPINDLE_DIR_AS_ENABLE_PIN enabled"
|
||||
#error "SPINDLE_ENABLE_OFF_WITH_ZERO_SPEED may only be used with USE_SPINDLE_DIR_AS_ENABLE_PIN enabled"
|
||||
#endif
|
||||
|
||||
#if defined(PARKING_ENABLE)
|
||||
#if defined(HOMING_FORCE_SET_ORIGIN)
|
||||
#error "HOMING_FORCE_SET_ORIGIN is not supported with PARKING_ENABLE at this time."
|
||||
#endif
|
||||
#if defined(HOMING_FORCE_SET_ORIGIN)
|
||||
#error "HOMING_FORCE_SET_ORIGIN is not supported with PARKING_ENABLE at this time."
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(ENABLE_PARKING_OVERRIDE_CONTROL)
|
||||
#if !defined(PARKING_ENABLE)
|
||||
#error "ENABLE_PARKING_OVERRIDE_CONTROL must be enabled with PARKING_ENABLE."
|
||||
#endif
|
||||
#if !defined(PARKING_ENABLE)
|
||||
#error "ENABLE_PARKING_OVERRIDE_CONTROL must be enabled with PARKING_ENABLE."
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(SPINDLE_PWM_MIN_VALUE)
|
||||
#if !(SPINDLE_PWM_MIN_VALUE > 0)
|
||||
#error "SPINDLE_PWM_MIN_VALUE must be greater than zero."
|
||||
#endif
|
||||
#if !(SPINDLE_PWM_MIN_VALUE > 0)
|
||||
#error "SPINDLE_PWM_MIN_VALUE must be greater than zero."
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if (REPORT_WCO_REFRESH_BUSY_COUNT < REPORT_WCO_REFRESH_IDLE_COUNT)
|
||||
#error "WCO busy refresh is less than idle refresh."
|
||||
#error "WCO busy refresh is less than idle refresh."
|
||||
#endif
|
||||
#if (REPORT_OVR_REFRESH_BUSY_COUNT < REPORT_OVR_REFRESH_IDLE_COUNT)
|
||||
#error "Override busy refresh is less than idle refresh."
|
||||
#error "Override busy refresh is less than idle refresh."
|
||||
#endif
|
||||
#if (REPORT_WCO_REFRESH_IDLE_COUNT < 2)
|
||||
#error "WCO refresh must be greater than one."
|
||||
#error "WCO refresh must be greater than one."
|
||||
#endif
|
||||
#if (REPORT_OVR_REFRESH_IDLE_COUNT < 1)
|
||||
#error "Override refresh must be greater than zero."
|
||||
#error "Override refresh must be greater than zero."
|
||||
#endif
|
||||
|
||||
#if defined(ENABLE_DUAL_AXIS)
|
||||
#if !((DUAL_AXIS_SELECT == X_AXIS) || (DUAL_AXIS_SELECT == Y_AXIS))
|
||||
#error "Dual axis currently supports X or Y axes only."
|
||||
#endif
|
||||
#if defined(DUAL_AXIS_CONFIG_CNC_SHIELD_CLONE) && defined(VARIABLE_SPINDLE)
|
||||
#error "VARIABLE_SPINDLE not supported with DUAL_AXIS_CNC_SHIELD_CLONE."
|
||||
#endif
|
||||
#if defined(DUAL_AXIS_CONFIG_CNC_SHIELD_CLONE) && defined(DUAL_AXIS_CONFIG_PROTONEER_V3_51)
|
||||
#error "More than one dual axis configuration found. Select one."
|
||||
#endif
|
||||
#if !defined(DUAL_AXIS_CONFIG_CNC_SHIELD_CLONE) && !defined(DUAL_AXIS_CONFIG_PROTONEER_V3_51)
|
||||
#error "No supported dual axis configuration found. Select one."
|
||||
#endif
|
||||
#if defined(COREXY)
|
||||
#error "CORE XY not supported with dual axis feature."
|
||||
#endif
|
||||
#if defined(USE_SPINDLE_DIR_AS_ENABLE_PIN)
|
||||
#error "USE_SPINDLE_DIR_AS_ENABLE_PIN not supported with dual axis feature."
|
||||
#endif
|
||||
#if defined(ENABLE_M7)
|
||||
#error "ENABLE_M7 not supported with dual axis feature."
|
||||
#endif
|
||||
#if !((DUAL_AXIS_SELECT == X_AXIS) || (DUAL_AXIS_SELECT == Y_AXIS))
|
||||
#error "Dual axis currently supports X or Y axes only."
|
||||
#endif
|
||||
#if defined(DUAL_AXIS_CONFIG_CNC_SHIELD_CLONE) && defined(VARIABLE_SPINDLE)
|
||||
#error "VARIABLE_SPINDLE not supported with DUAL_AXIS_CNC_SHIELD_CLONE."
|
||||
#endif
|
||||
#if defined(DUAL_AXIS_CONFIG_CNC_SHIELD_CLONE) && defined(DUAL_AXIS_CONFIG_PROTONEER_V3_51)
|
||||
#error "More than one dual axis configuration found. Select one."
|
||||
#endif
|
||||
#if !defined(DUAL_AXIS_CONFIG_CNC_SHIELD_CLONE) && !defined(DUAL_AXIS_CONFIG_PROTONEER_V3_51)
|
||||
#error "No supported dual axis configuration found. Select one."
|
||||
#endif
|
||||
#if defined(COREXY)
|
||||
#error "CORE XY not supported with dual axis feature."
|
||||
#endif
|
||||
#if defined(USE_SPINDLE_DIR_AS_ENABLE_PIN)
|
||||
#error "USE_SPINDLE_DIR_AS_ENABLE_PIN not supported with dual axis feature."
|
||||
#endif
|
||||
#if defined(ENABLE_M7)
|
||||
#error "ENABLE_M7 not supported with dual axis feature."
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// ---------------------------------------------------------------------------------------
|
||||
|
|
|
|||
18
grbl/jog.c
18
grbl/jog.c
|
|
@ -20,24 +20,24 @@
|
|||
|
||||
#include "grbl.h"
|
||||
|
||||
|
||||
// Sets up valid jog motion received from g-code parser, checks for soft-limits, and executes the jog.
|
||||
uint8_t jog_execute(plan_line_data_t *pl_data, parser_block_t *gc_block)
|
||||
{
|
||||
uint8_t jog_execute(plan_line_data_t *pl_data, parser_block_t *gc_block) {
|
||||
// Initialize planner data struct for jogging motions.
|
||||
// NOTE: Spindle and coolant are allowed to fully function with overrides during a jog.
|
||||
pl_data->feed_rate = gc_block->values.f;
|
||||
pl_data->condition |= PL_COND_FLAG_NO_FEED_OVERRIDE;
|
||||
#ifdef USE_LINE_NUMBERS
|
||||
#ifdef USE_LINE_NUMBERS
|
||||
pl_data->line_number = gc_block->values.n;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
if (bit_istrue(settings.flags,BITFLAG_SOFT_LIMIT_ENABLE)) {
|
||||
if (system_check_travel_limits(gc_block->values.xyz)) { return(STATUS_TRAVEL_EXCEEDED); }
|
||||
if (bit_istrue(settings.flags, BITFLAG_SOFT_LIMIT_ENABLE)) {
|
||||
if (system_check_travel_limits(gc_block->values.xyz)) {
|
||||
return (STATUS_TRAVEL_EXCEEDED);
|
||||
}
|
||||
}
|
||||
|
||||
// Valid jog command. Plan, set state, and execute.
|
||||
mc_line(gc_block->values.xyz,pl_data);
|
||||
mc_line(gc_block->values.xyz, pl_data);
|
||||
if (sys.state == STATE_IDLE) {
|
||||
if (plan_get_current_block() != NULL) { // Check if there is a block to execute.
|
||||
sys.state = STATE_JOG;
|
||||
|
|
@ -46,5 +46,5 @@ uint8_t jog_execute(plan_line_data_t *pl_data, parser_block_t *gc_block)
|
|||
}
|
||||
}
|
||||
|
||||
return(STATUS_OK);
|
||||
return (STATUS_OK);
|
||||
}
|
||||
|
|
|
|||
288
grbl/limits.c
288
grbl/limits.c
|
|
@ -21,80 +21,79 @@
|
|||
|
||||
#include "grbl.h"
|
||||
|
||||
|
||||
// Homing axis search distance multiplier. Computed by this value times the cycle travel.
|
||||
#ifndef HOMING_AXIS_SEARCH_SCALAR
|
||||
#define HOMING_AXIS_SEARCH_SCALAR 1.5 // Must be > 1 to ensure limit switch will be engaged.
|
||||
#define HOMING_AXIS_SEARCH_SCALAR 1.5 // Must be > 1 to ensure limit switch will be engaged.
|
||||
#endif
|
||||
#ifndef HOMING_AXIS_LOCATE_SCALAR
|
||||
#define HOMING_AXIS_LOCATE_SCALAR 5.0 // Must be > 1 to ensure limit switch is cleared.
|
||||
#define HOMING_AXIS_LOCATE_SCALAR 5.0 // Must be > 1 to ensure limit switch is cleared.
|
||||
#endif
|
||||
|
||||
#ifdef ENABLE_DUAL_AXIS
|
||||
// Flags for dual axis async limit trigger check.
|
||||
#define DUAL_AXIS_CHECK_DISABLE 0 // Must be zero
|
||||
#define DUAL_AXIS_CHECK_ENABLE bit(0)
|
||||
#define DUAL_AXIS_CHECK_TRIGGER_1 bit(1)
|
||||
#define DUAL_AXIS_CHECK_TRIGGER_2 bit(2)
|
||||
// Flags for dual axis async limit trigger check.
|
||||
#define DUAL_AXIS_CHECK_DISABLE 0 // Must be zero
|
||||
#define DUAL_AXIS_CHECK_ENABLE bit(0)
|
||||
#define DUAL_AXIS_CHECK_TRIGGER_1 bit(1)
|
||||
#define DUAL_AXIS_CHECK_TRIGGER_2 bit(2)
|
||||
#endif
|
||||
|
||||
void limits_init()
|
||||
{
|
||||
void limits_init() {
|
||||
LIMIT_DDR &= ~(LIMIT_MASK); // Set as input pins
|
||||
|
||||
#ifdef DISABLE_LIMIT_PIN_PULL_UP
|
||||
#ifdef DISABLE_LIMIT_PIN_PULL_UP
|
||||
LIMIT_PORT &= ~(LIMIT_MASK); // Normal low operation. Requires external pull-down.
|
||||
#else
|
||||
#else
|
||||
LIMIT_PORT |= (LIMIT_MASK); // Enable internal pull-up resistors. Normal high operation.
|
||||
#endif
|
||||
#endif
|
||||
|
||||
if (bit_istrue(settings.flags,BITFLAG_HARD_LIMIT_ENABLE)) {
|
||||
if (bit_istrue(settings.flags, BITFLAG_HARD_LIMIT_ENABLE)) {
|
||||
LIMIT_PCMSK |= LIMIT_MASK; // Enable specific pins of the Pin Change Interrupt
|
||||
PCICR |= (1 << LIMIT_INT); // Enable Pin Change Interrupt
|
||||
} else {
|
||||
limits_disable();
|
||||
}
|
||||
|
||||
#ifdef ENABLE_SOFTWARE_DEBOUNCE
|
||||
MCUSR &= ~(1<<WDRF);
|
||||
WDTCSR |= (1<<WDCE) | (1<<WDE);
|
||||
WDTCSR = (1<<WDP0); // Set time-out at ~32msec.
|
||||
#endif
|
||||
#ifdef ENABLE_SOFTWARE_DEBOUNCE
|
||||
MCUSR &= ~(1 << WDRF);
|
||||
WDTCSR |= (1 << WDCE) | (1 << WDE);
|
||||
WDTCSR = (1 << WDP0); // Set time-out at ~32msec.
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
// Disables hard limits.
|
||||
void limits_disable()
|
||||
{
|
||||
void limits_disable() {
|
||||
LIMIT_PCMSK &= ~LIMIT_MASK; // Disable specific pins of the Pin Change Interrupt
|
||||
PCICR &= ~(1 << LIMIT_INT); // Disable Pin Change Interrupt
|
||||
}
|
||||
|
||||
|
||||
// Returns limit state as a bit-wise uint8 variable. Each bit indicates an axis limit, where
|
||||
// triggered is 1 and not triggered is 0. Invert mask is applied. Axes are defined by their
|
||||
// number in bit position, i.e. Z_AXIS is (1<<2) or bit 2, and Y_AXIS is (1<<1) or bit 1.
|
||||
uint8_t limits_get_state()
|
||||
{
|
||||
uint8_t limits_get_state() {
|
||||
uint8_t limit_state = 0;
|
||||
uint8_t pin = (LIMIT_PIN & LIMIT_MASK);
|
||||
#ifdef INVERT_LIMIT_PIN_MASK
|
||||
#ifdef INVERT_LIMIT_PIN_MASK
|
||||
pin ^= INVERT_LIMIT_PIN_MASK;
|
||||
#endif
|
||||
if (bit_isfalse(settings.flags,BITFLAG_INVERT_LIMIT_PINS)) { pin ^= LIMIT_MASK; }
|
||||
#endif
|
||||
if (bit_isfalse(settings.flags, BITFLAG_INVERT_LIMIT_PINS)) {
|
||||
pin ^= LIMIT_MASK;
|
||||
}
|
||||
if (pin) {
|
||||
uint8_t idx;
|
||||
for (idx=0; idx<N_AXIS; idx++) {
|
||||
if (pin & get_limit_pin_mask(idx)) { limit_state |= (1 << idx); }
|
||||
for (idx = 0; idx < N_AXIS; idx++) {
|
||||
if (pin & get_limit_pin_mask(idx)) {
|
||||
limit_state |= (1 << idx);
|
||||
}
|
||||
#ifdef ENABLE_DUAL_AXIS
|
||||
if (pin & (1<<DUAL_LIMIT_BIT)) { limit_state |= (1 << N_AXIS); }
|
||||
#endif
|
||||
}
|
||||
return(limit_state);
|
||||
#ifdef ENABLE_DUAL_AXIS
|
||||
if (pin & (1 << DUAL_LIMIT_BIT)) {
|
||||
limit_state |= (1 << N_AXIS);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
return (limit_state);
|
||||
}
|
||||
|
||||
|
||||
// This is the Limit Pin Change Interrupt, which handles the hard limit feature. A bouncing
|
||||
// limit switch can cause a lot of problems, like false readings and multiple interrupt calls.
|
||||
// If a switch is triggered at all, something bad has happened and treat it as such, regardless
|
||||
|
|
@ -107,8 +106,8 @@ uint8_t limits_get_state()
|
|||
// special pinout for an e-stop, but it is generally recommended to just directly connect
|
||||
// your e-stop switch to the Arduino reset pin, since it is the most correct way to do this.
|
||||
#ifndef ENABLE_SOFTWARE_DEBOUNCE
|
||||
ISR(LIMIT_INT_vect) // DEFAULT: Limit pin change interrupt process.
|
||||
{
|
||||
ISR(LIMIT_INT_vect) // DEFAULT: Limit pin change interrupt process.
|
||||
{
|
||||
// Ignore limit switches if already in an alarm state or in-process of executing an alarm.
|
||||
// When in the alarm state, Grbl should have been reset or will force a reset, so any pending
|
||||
// moves in the planner and serial buffers are all cleared and newly sent blocks will be
|
||||
|
|
@ -116,25 +115,30 @@ uint8_t limits_get_state()
|
|||
// limit setting if their limits are constantly triggering after a reset and move their axes.
|
||||
if (sys.state != STATE_ALARM) {
|
||||
if (!(sys_rt_exec_alarm)) {
|
||||
#ifdef HARD_LIMIT_FORCE_STATE_CHECK
|
||||
#ifdef HARD_LIMIT_FORCE_STATE_CHECK
|
||||
// Check limit pin state.
|
||||
if (limits_get_state()) {
|
||||
mc_reset(); // Initiate system kill.
|
||||
system_set_exec_alarm(EXEC_ALARM_HARD_LIMIT); // Indicate hard limit critical event
|
||||
}
|
||||
#else
|
||||
#else
|
||||
mc_reset(); // Initiate system kill.
|
||||
system_set_exec_alarm(EXEC_ALARM_HARD_LIMIT); // Indicate hard limit critical event
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
#else // OPTIONAL: Software debounce limit pin routine.
|
||||
// Upon limit pin change, enable watchdog timer to create a short delay.
|
||||
ISR(LIMIT_INT_vect) { if (!(WDTCSR & (1<<WDIE))) { WDTCSR |= (1<<WDIE); } }
|
||||
ISR(WDT_vect) // Watchdog timer ISR
|
||||
{
|
||||
WDTCSR &= ~(1<<WDIE); // Disable watchdog timer.
|
||||
// Upon limit pin change, enable watchdog timer to create a short delay.
|
||||
ISR(LIMIT_INT_vect) {
|
||||
if (!(WDTCSR & (1 << WDIE))) {
|
||||
WDTCSR |= (1 << WDIE);
|
||||
}
|
||||
}
|
||||
|
||||
ISR(WDT_vect) // Watchdog timer ISR
|
||||
{
|
||||
WDTCSR &= ~(1 << WDIE); // Disable watchdog timer.
|
||||
if (sys.state != STATE_ALARM) { // Ignore if already in alarm state.
|
||||
if (!(sys_rt_exec_alarm)) {
|
||||
// Check limit pin state.
|
||||
|
|
@ -144,7 +148,7 @@ uint8_t limits_get_state()
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
// Homes the specified cycle axes, sets the machine position, and performs a pull-off motion after
|
||||
|
|
@ -154,55 +158,59 @@ uint8_t limits_get_state()
|
|||
// circumvent the processes for executing motions in normal operation.
|
||||
// NOTE: Only the abort realtime command can interrupt this process.
|
||||
// TODO: Move limit pin-specific calls to a general function for portability.
|
||||
void limits_go_home(uint8_t cycle_mask)
|
||||
{
|
||||
if (sys.abort) { return; } // Block if system reset has been issued.
|
||||
void limits_go_home(uint8_t cycle_mask) {
|
||||
if (sys.abort) {
|
||||
return;
|
||||
} // Block if system reset has been issued.
|
||||
|
||||
// Initialize plan data struct for homing motion. Spindle and coolant are disabled.
|
||||
plan_line_data_t plan_data;
|
||||
plan_line_data_t *pl_data = &plan_data;
|
||||
memset(pl_data,0,sizeof(plan_line_data_t));
|
||||
pl_data->condition = (PL_COND_FLAG_SYSTEM_MOTION|PL_COND_FLAG_NO_FEED_OVERRIDE);
|
||||
#ifdef USE_LINE_NUMBERS
|
||||
memset(pl_data, 0, sizeof(plan_line_data_t));
|
||||
pl_data->condition = (PL_COND_FLAG_SYSTEM_MOTION | PL_COND_FLAG_NO_FEED_OVERRIDE);
|
||||
#ifdef USE_LINE_NUMBERS
|
||||
pl_data->line_number = HOMING_CYCLE_LINE_NUMBER;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// Initialize variables used for homing computations.
|
||||
uint8_t n_cycle = (2*N_HOMING_LOCATE_CYCLE+1);
|
||||
uint8_t n_cycle = (2 * N_HOMING_LOCATE_CYCLE + 1);
|
||||
uint8_t step_pin[N_AXIS];
|
||||
#ifdef ENABLE_DUAL_AXIS
|
||||
#ifdef ENABLE_DUAL_AXIS
|
||||
uint8_t step_pin_dual;
|
||||
uint8_t dual_axis_async_check;
|
||||
int32_t dual_trigger_position;
|
||||
#if (DUAL_AXIS_SELECT == X_AXIS)
|
||||
float fail_distance = (-DUAL_AXIS_HOMING_FAIL_AXIS_LENGTH_PERCENT/100.0)*settings.max_travel[Y_AXIS];
|
||||
#else
|
||||
float fail_distance = (-DUAL_AXIS_HOMING_FAIL_AXIS_LENGTH_PERCENT/100.0)*settings.max_travel[X_AXIS];
|
||||
#endif
|
||||
#if (DUAL_AXIS_SELECT == X_AXIS)
|
||||
float fail_distance = (-DUAL_AXIS_HOMING_FAIL_AXIS_LENGTH_PERCENT / 100.0) * settings.max_travel[Y_AXIS];
|
||||
#else
|
||||
float fail_distance = (-DUAL_AXIS_HOMING_FAIL_AXIS_LENGTH_PERCENT / 100.0) * settings.max_travel[X_AXIS];
|
||||
#endif
|
||||
fail_distance = min(fail_distance, DUAL_AXIS_HOMING_FAIL_DISTANCE_MAX);
|
||||
fail_distance = max(fail_distance, DUAL_AXIS_HOMING_FAIL_DISTANCE_MIN);
|
||||
int32_t dual_fail_distance = trunc(fail_distance*settings.steps_per_mm[DUAL_AXIS_SELECT]);
|
||||
// int32_t dual_fail_distance = trunc((DUAL_AXIS_HOMING_TRIGGER_FAIL_DISTANCE)*settings.steps_per_mm[DUAL_AXIS_SELECT]);
|
||||
#endif
|
||||
int32_t dual_fail_distance = trunc(fail_distance * settings.steps_per_mm[DUAL_AXIS_SELECT]);
|
||||
// int32_t dual_fail_distance =
|
||||
// trunc((DUAL_AXIS_HOMING_TRIGGER_FAIL_DISTANCE)*settings.steps_per_mm[DUAL_AXIS_SELECT]);
|
||||
#endif
|
||||
float target[N_AXIS];
|
||||
float max_travel = 0.0;
|
||||
uint8_t idx;
|
||||
for (idx=0; idx<N_AXIS; idx++) {
|
||||
for (idx = 0; idx < N_AXIS; idx++) {
|
||||
// Initialize step pin masks
|
||||
step_pin[idx] = get_step_pin_mask(idx);
|
||||
#ifdef COREXY
|
||||
if ((idx==A_MOTOR)||(idx==B_MOTOR)) { step_pin[idx] = (get_step_pin_mask(X_AXIS)|get_step_pin_mask(Y_AXIS)); }
|
||||
#endif
|
||||
#ifdef COREXY
|
||||
if ((idx == A_MOTOR) || (idx == B_MOTOR)) {
|
||||
step_pin[idx] = (get_step_pin_mask(X_AXIS) | get_step_pin_mask(Y_AXIS));
|
||||
}
|
||||
#endif
|
||||
|
||||
if (bit_istrue(cycle_mask,bit(idx))) {
|
||||
if (bit_istrue(cycle_mask, bit(idx))) {
|
||||
// Set target based on max_travel setting. Ensure homing switches engaged with search scalar.
|
||||
// NOTE: settings.max_travel[] is stored as a negative value.
|
||||
max_travel = max(max_travel,(-HOMING_AXIS_SEARCH_SCALAR)*settings.max_travel[idx]);
|
||||
max_travel = max(max_travel, (-HOMING_AXIS_SEARCH_SCALAR) * settings.max_travel[idx]);
|
||||
}
|
||||
}
|
||||
#ifdef ENABLE_DUAL_AXIS
|
||||
step_pin_dual = (1<<DUAL_STEP_BIT);
|
||||
#endif
|
||||
#ifdef ENABLE_DUAL_AXIS
|
||||
step_pin_dual = (1 << DUAL_STEP_BIT);
|
||||
#endif
|
||||
|
||||
// Set search mode with approach at seek rate to quickly engage the specified cycle_mask limit switches.
|
||||
bool approach = true;
|
||||
|
|
@ -211,21 +219,21 @@ void limits_go_home(uint8_t cycle_mask)
|
|||
uint8_t limit_state, axislock, n_active_axis;
|
||||
do {
|
||||
|
||||
system_convert_array_steps_to_mpos(target,sys_position);
|
||||
system_convert_array_steps_to_mpos(target, sys_position);
|
||||
|
||||
// Initialize and declare variables needed for homing routine.
|
||||
axislock = 0;
|
||||
#ifdef ENABLE_DUAL_AXIS
|
||||
#ifdef ENABLE_DUAL_AXIS
|
||||
sys.homing_axis_lock_dual = 0;
|
||||
dual_trigger_position = 0;
|
||||
dual_axis_async_check = DUAL_AXIS_CHECK_DISABLE;
|
||||
#endif
|
||||
#endif
|
||||
n_active_axis = 0;
|
||||
for (idx=0; idx<N_AXIS; idx++) {
|
||||
for (idx = 0; idx < N_AXIS; idx++) {
|
||||
// Set target location for active axes and setup computation for homing rate.
|
||||
if (bit_istrue(cycle_mask,bit(idx))) {
|
||||
if (bit_istrue(cycle_mask, bit(idx))) {
|
||||
n_active_axis++;
|
||||
#ifdef COREXY
|
||||
#ifdef COREXY
|
||||
if (idx == X_AXIS) {
|
||||
int32_t axis_position = system_convert_corexy_to_y_axis_steps(sys_position);
|
||||
sys_position[A_MOTOR] = axis_position;
|
||||
|
|
@ -236,25 +244,32 @@ void limits_go_home(uint8_t cycle_mask)
|
|||
} else {
|
||||
sys_position[Z_AXIS] = 0;
|
||||
}
|
||||
#else
|
||||
#else
|
||||
sys_position[idx] = 0;
|
||||
#endif
|
||||
#endif
|
||||
// Set target direction based on cycle mask and homing cycle approach state.
|
||||
// NOTE: This happens to compile smaller than any other implementation tried.
|
||||
if (bit_istrue(settings.homing_dir_mask,bit(idx))) {
|
||||
if (approach) { target[idx] = -max_travel; }
|
||||
else { target[idx] = max_travel; }
|
||||
if (bit_istrue(settings.homing_dir_mask, bit(idx))) {
|
||||
if (approach) {
|
||||
target[idx] = -max_travel;
|
||||
} else {
|
||||
if (approach) { target[idx] = max_travel; }
|
||||
else { target[idx] = -max_travel; }
|
||||
target[idx] = max_travel;
|
||||
}
|
||||
} else {
|
||||
if (approach) {
|
||||
target[idx] = max_travel;
|
||||
} else {
|
||||
target[idx] = -max_travel;
|
||||
}
|
||||
}
|
||||
// Apply axislock to the step port pins active in this cycle.
|
||||
axislock |= step_pin[idx];
|
||||
#ifdef ENABLE_DUAL_AXIS
|
||||
if (idx == DUAL_AXIS_SELECT) { sys.homing_axis_lock_dual = step_pin_dual; }
|
||||
#endif
|
||||
#ifdef ENABLE_DUAL_AXIS
|
||||
if (idx == DUAL_AXIS_SELECT) {
|
||||
sys.homing_axis_lock_dual = step_pin_dual;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
}
|
||||
homing_rate *= sqrt(n_active_axis); // [sqrt(N_AXIS)] Adjust so individual axes all move at homing rate.
|
||||
sys.homing_axis_lock = axislock;
|
||||
|
|
@ -270,23 +285,28 @@ void limits_go_home(uint8_t cycle_mask)
|
|||
if (approach) {
|
||||
// Check limit state. Lock out cycle axes when they change.
|
||||
limit_state = limits_get_state();
|
||||
for (idx=0; idx<N_AXIS; idx++) {
|
||||
for (idx = 0; idx < N_AXIS; idx++) {
|
||||
if (axislock & step_pin[idx]) {
|
||||
if (limit_state & (1 << idx)) {
|
||||
#ifdef COREXY
|
||||
if (idx==Z_AXIS) { axislock &= ~(step_pin[Z_AXIS]); }
|
||||
else { axislock &= ~(step_pin[A_MOTOR]|step_pin[B_MOTOR]); }
|
||||
#else
|
||||
#ifdef COREXY
|
||||
if (idx == Z_AXIS) {
|
||||
axislock &= ~(step_pin[Z_AXIS]);
|
||||
} else {
|
||||
axislock &= ~(step_pin[A_MOTOR] | step_pin[B_MOTOR]);
|
||||
}
|
||||
#else
|
||||
axislock &= ~(step_pin[idx]);
|
||||
#ifdef ENABLE_DUAL_AXIS
|
||||
if (idx == DUAL_AXIS_SELECT) { dual_axis_async_check |= DUAL_AXIS_CHECK_TRIGGER_1; }
|
||||
#endif
|
||||
#endif
|
||||
#ifdef ENABLE_DUAL_AXIS
|
||||
if (idx == DUAL_AXIS_SELECT) {
|
||||
dual_axis_async_check |= DUAL_AXIS_CHECK_TRIGGER_1;
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
sys.homing_axis_lock = axislock;
|
||||
#ifdef ENABLE_DUAL_AXIS
|
||||
#ifdef ENABLE_DUAL_AXIS
|
||||
if (sys.homing_axis_lock_dual) { // NOTE: Only true when homing dual axis.
|
||||
if (limit_state & (1 << N_AXIS)) {
|
||||
sys.homing_axis_lock_dual = 0;
|
||||
|
|
@ -294,10 +314,12 @@ void limits_go_home(uint8_t cycle_mask)
|
|||
}
|
||||
}
|
||||
|
||||
// When first dual axis limit triggers, record position and begin checking distance until other limit triggers. Bail upon failure.
|
||||
// When first dual axis limit triggers, record position and begin checking distance until other limit
|
||||
// triggers. Bail upon failure.
|
||||
if (dual_axis_async_check) {
|
||||
if (dual_axis_async_check & DUAL_AXIS_CHECK_ENABLE) {
|
||||
if (( dual_axis_async_check & (DUAL_AXIS_CHECK_TRIGGER_1 | DUAL_AXIS_CHECK_TRIGGER_2)) == (DUAL_AXIS_CHECK_TRIGGER_1 | DUAL_AXIS_CHECK_TRIGGER_2)) {
|
||||
if ((dual_axis_async_check & (DUAL_AXIS_CHECK_TRIGGER_1 | DUAL_AXIS_CHECK_TRIGGER_2)) ==
|
||||
(DUAL_AXIS_CHECK_TRIGGER_1 | DUAL_AXIS_CHECK_TRIGGER_2)) {
|
||||
dual_axis_async_check = DUAL_AXIS_CHECK_DISABLE;
|
||||
} else {
|
||||
if (abs(dual_trigger_position - sys_position[DUAL_AXIS_SELECT]) > dual_fail_distance) {
|
||||
|
|
@ -312,7 +334,7 @@ void limits_go_home(uint8_t cycle_mask)
|
|||
dual_trigger_position = sys_position[DUAL_AXIS_SELECT];
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
st_prep_buffer(); // Check and prep segment buffer. NOTE: Should take no longer than 200us.
|
||||
|
|
@ -321,13 +343,21 @@ void limits_go_home(uint8_t cycle_mask)
|
|||
if (sys_rt_exec_state & (EXEC_SAFETY_DOOR | EXEC_RESET | EXEC_CYCLE_STOP)) {
|
||||
uint8_t rt_exec = sys_rt_exec_state;
|
||||
// Homing failure condition: Reset issued during cycle.
|
||||
if (rt_exec & EXEC_RESET) { system_set_exec_alarm(EXEC_ALARM_HOMING_FAIL_RESET); }
|
||||
if (rt_exec & EXEC_RESET) {
|
||||
system_set_exec_alarm(EXEC_ALARM_HOMING_FAIL_RESET);
|
||||
}
|
||||
// Homing failure condition: Safety door was opened.
|
||||
if (rt_exec & EXEC_SAFETY_DOOR) { system_set_exec_alarm(EXEC_ALARM_HOMING_FAIL_DOOR); }
|
||||
if (rt_exec & EXEC_SAFETY_DOOR) {
|
||||
system_set_exec_alarm(EXEC_ALARM_HOMING_FAIL_DOOR);
|
||||
}
|
||||
// Homing failure condition: Limit switch still engaged after pull-off motion
|
||||
if (!approach && (limits_get_state() & cycle_mask)) { system_set_exec_alarm(EXEC_ALARM_HOMING_FAIL_PULLOFF); }
|
||||
if (!approach && (limits_get_state() & cycle_mask)) {
|
||||
system_set_exec_alarm(EXEC_ALARM_HOMING_FAIL_PULLOFF);
|
||||
}
|
||||
// Homing failure condition: Limit switch not found during approach.
|
||||
if (approach && (rt_exec & EXEC_CYCLE_STOP)) { system_set_exec_alarm(EXEC_ALARM_HOMING_FAIL_APPROACH); }
|
||||
if (approach && (rt_exec & EXEC_CYCLE_STOP)) {
|
||||
system_set_exec_alarm(EXEC_ALARM_HOMING_FAIL_APPROACH);
|
||||
}
|
||||
if (sys_rt_exec_alarm) {
|
||||
mc_reset(); // Stop motors, if they are running.
|
||||
protocol_execute_realtime();
|
||||
|
|
@ -339,11 +369,11 @@ void limits_go_home(uint8_t cycle_mask)
|
|||
}
|
||||
}
|
||||
|
||||
#ifdef ENABLE_DUAL_AXIS
|
||||
#ifdef ENABLE_DUAL_AXIS
|
||||
} while ((STEP_MASK & axislock) || (sys.homing_axis_lock_dual));
|
||||
#else
|
||||
#else
|
||||
} while (STEP_MASK & axislock);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
st_reset(); // Immediately force kill steppers and reset step segment buffer.
|
||||
delay_ms(settings.homing_debounce_delay); // Delay to allow transient dynamics to dissipate.
|
||||
|
|
@ -353,7 +383,7 @@ void limits_go_home(uint8_t cycle_mask)
|
|||
|
||||
// After first cycle, homing enters locating phase. Shorten search to pull-off distance.
|
||||
if (approach) {
|
||||
max_travel = settings.homing_pulloff*HOMING_AXIS_LOCATE_SCALAR;
|
||||
max_travel = settings.homing_pulloff * HOMING_AXIS_LOCATE_SCALAR;
|
||||
homing_rate = settings.homing_feed_rate;
|
||||
} else {
|
||||
max_travel = settings.homing_pulloff;
|
||||
|
|
@ -370,46 +400,44 @@ void limits_go_home(uint8_t cycle_mask)
|
|||
// triggering when hard limits are enabled or when more than one axes shares a limit pin.
|
||||
int32_t set_axis_position;
|
||||
// Set machine positions for homed limit switches. Don't update non-homed axes.
|
||||
for (idx=0; idx<N_AXIS; idx++) {
|
||||
for (idx = 0; idx < N_AXIS; idx++) {
|
||||
// NOTE: settings.max_travel[] is stored as a negative value.
|
||||
if (cycle_mask & bit(idx)) {
|
||||
#ifdef HOMING_FORCE_SET_ORIGIN
|
||||
#ifdef HOMING_FORCE_SET_ORIGIN
|
||||
set_axis_position = 0;
|
||||
#else
|
||||
if ( bit_istrue(settings.homing_dir_mask,bit(idx)) ) {
|
||||
set_axis_position = lround((settings.max_travel[idx]+settings.homing_pulloff)*settings.steps_per_mm[idx]);
|
||||
#else
|
||||
if (bit_istrue(settings.homing_dir_mask, bit(idx))) {
|
||||
set_axis_position =
|
||||
lround((settings.max_travel[idx] + settings.homing_pulloff) * settings.steps_per_mm[idx]);
|
||||
} else {
|
||||
set_axis_position = lround(-settings.homing_pulloff*settings.steps_per_mm[idx]);
|
||||
set_axis_position = lround(-settings.homing_pulloff * settings.steps_per_mm[idx]);
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef COREXY
|
||||
if (idx==X_AXIS) {
|
||||
#ifdef COREXY
|
||||
if (idx == X_AXIS) {
|
||||
int32_t off_axis_position = system_convert_corexy_to_y_axis_steps(sys_position);
|
||||
sys_position[A_MOTOR] = set_axis_position + off_axis_position;
|
||||
sys_position[B_MOTOR] = set_axis_position - off_axis_position;
|
||||
} else if (idx==Y_AXIS) {
|
||||
} else if (idx == Y_AXIS) {
|
||||
int32_t off_axis_position = system_convert_corexy_to_x_axis_steps(sys_position);
|
||||
sys_position[A_MOTOR] = off_axis_position + set_axis_position;
|
||||
sys_position[B_MOTOR] = off_axis_position - set_axis_position;
|
||||
} else {
|
||||
sys_position[idx] = set_axis_position;
|
||||
}
|
||||
#else
|
||||
#else
|
||||
sys_position[idx] = set_axis_position;
|
||||
#endif
|
||||
|
||||
#endif
|
||||
}
|
||||
}
|
||||
sys.step_control = STEP_CONTROL_NORMAL_OP; // Return step control to normal operation.
|
||||
}
|
||||
|
||||
|
||||
// Performs a soft limit check. Called from mc_line() only. Assumes the machine has been homed,
|
||||
// the workspace volume is in all negative space, and the system is in normal operation.
|
||||
// NOTE: Used by jogging to limit travel within soft-limit volume.
|
||||
void limits_soft_check(float *target)
|
||||
{
|
||||
void limits_soft_check(float *target) {
|
||||
if (system_check_travel_limits(target)) {
|
||||
sys.soft_limit = true;
|
||||
// Force feed hold if cycle is active. All buffered blocks are guaranteed to be within
|
||||
|
|
@ -419,8 +447,10 @@ void limits_soft_check(float *target)
|
|||
system_set_exec_state_flag(EXEC_FEED_HOLD);
|
||||
do {
|
||||
protocol_execute_realtime();
|
||||
if (sys.abort) { return; }
|
||||
} while ( sys.state != STATE_IDLE );
|
||||
if (sys.abort) {
|
||||
return;
|
||||
}
|
||||
} while (sys.state != STATE_IDLE);
|
||||
}
|
||||
mc_reset(); // Issue system reset and ensure spindle and coolant are shutdown.
|
||||
system_set_exec_alarm(EXEC_ALARM_SOFT_LIMIT); // Indicate soft limit critical event
|
||||
|
|
|
|||
|
|
@ -22,7 +22,6 @@
|
|||
#ifndef limits_h
|
||||
#define limits_h
|
||||
|
||||
|
||||
// Initialize the limits module
|
||||
void limits_init();
|
||||
|
||||
|
|
|
|||
50
grbl/main.c
50
grbl/main.c
|
|
@ -21,54 +21,55 @@
|
|||
|
||||
#include "grbl.h"
|
||||
|
||||
|
||||
// Declare system global variable structure
|
||||
system_t sys;
|
||||
int32_t sys_position[N_AXIS]; // Real-time machine (aka home) position vector in steps.
|
||||
int32_t sys_probe_position[N_AXIS]; // Last probe position in machine coordinates and steps.
|
||||
volatile uint8_t sys_probe_state; // Probing state value. Used to coordinate the probing cycle with stepper ISR.
|
||||
volatile uint8_t sys_rt_exec_state; // Global realtime executor bitflag variable for state management. See EXEC bitmasks.
|
||||
volatile uint8_t
|
||||
sys_rt_exec_state; // Global realtime executor bitflag variable for state management. See EXEC bitmasks.
|
||||
volatile uint8_t sys_rt_exec_alarm; // Global realtime executor bitflag variable for setting various alarms.
|
||||
volatile uint8_t sys_rt_exec_motion_override; // Global realtime executor bitflag variable for motion-based overrides.
|
||||
volatile uint8_t sys_rt_exec_accessory_override; // Global realtime executor bitflag variable for spindle/coolant overrides.
|
||||
volatile uint8_t
|
||||
sys_rt_exec_accessory_override; // Global realtime executor bitflag variable for spindle/coolant overrides.
|
||||
#ifdef DEBUG
|
||||
volatile uint8_t sys_rt_exec_debug;
|
||||
volatile uint8_t sys_rt_exec_debug;
|
||||
#endif
|
||||
|
||||
|
||||
int main(void)
|
||||
{
|
||||
int main(void) {
|
||||
// Initialize system upon power-up.
|
||||
serial_init(); // Setup serial baud rate and interrupts
|
||||
settings_init(); // Load Grbl settings from EEPROM
|
||||
stepper_init(); // Configure stepper pins and interrupt timers
|
||||
system_init(); // Configure pinout pins and pin-change interrupt
|
||||
|
||||
memset(sys_position,0,sizeof(sys_position)); // Clear machine position.
|
||||
memset(sys_position, 0, sizeof(sys_position)); // Clear machine position.
|
||||
sei(); // Enable interrupts
|
||||
|
||||
// Initialize system state.
|
||||
#ifdef FORCE_INITIALIZATION_ALARM
|
||||
// Initialize system state.
|
||||
#ifdef FORCE_INITIALIZATION_ALARM
|
||||
// Force Grbl into an ALARM state upon a power-cycle or hard reset.
|
||||
sys.state = STATE_ALARM;
|
||||
#else
|
||||
#else
|
||||
sys.state = STATE_IDLE;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// Check for power-up and set system alarm if homing is enabled to force homing cycle
|
||||
// by setting Grbl's alarm state. Alarm locks out all g-code commands, including the
|
||||
// startup scripts, but allows access to settings and internal commands. Only a homing
|
||||
// cycle '$H' or kill alarm locks '$X' will disable the alarm.
|
||||
// NOTE: The startup script will run after successful completion of the homing cycle, but
|
||||
// not after disabling the alarm locks. Prevents motion startup blocks from crashing into
|
||||
// things uncontrollably. Very bad.
|
||||
#ifdef HOMING_INIT_LOCK
|
||||
if (bit_istrue(settings.flags,BITFLAG_HOMING_ENABLE)) { sys.state = STATE_ALARM; }
|
||||
#endif
|
||||
// Check for power-up and set system alarm if homing is enabled to force homing cycle
|
||||
// by setting Grbl's alarm state. Alarm locks out all g-code commands, including the
|
||||
// startup scripts, but allows access to settings and internal commands. Only a homing
|
||||
// cycle '$H' or kill alarm locks '$X' will disable the alarm.
|
||||
// NOTE: The startup script will run after successful completion of the homing cycle, but
|
||||
// not after disabling the alarm locks. Prevents motion startup blocks from crashing into
|
||||
// things uncontrollably. Very bad.
|
||||
#ifdef HOMING_INIT_LOCK
|
||||
if (bit_istrue(settings.flags, BITFLAG_HOMING_ENABLE)) {
|
||||
sys.state = STATE_ALARM;
|
||||
}
|
||||
#endif
|
||||
|
||||
// Grbl initialization loop upon power-up or a system abort. For the latter, all processes
|
||||
// will return to this loop to be cleanly re-initialized.
|
||||
for(;;) {
|
||||
for (;;) {
|
||||
|
||||
// Reset system variables.
|
||||
uint8_t prior_state = sys.state;
|
||||
|
|
@ -77,7 +78,7 @@ int main(void)
|
|||
sys.f_override = DEFAULT_FEED_OVERRIDE; // Set to 100%
|
||||
sys.r_override = DEFAULT_RAPID_OVERRIDE; // Set to 100%
|
||||
sys.spindle_speed_ovr = DEFAULT_SPINDLE_SPEED_OVERRIDE; // Set to 100%
|
||||
memset(sys_probe_position,0,sizeof(sys_probe_position)); // Clear probe position.
|
||||
memset(sys_probe_position, 0, sizeof(sys_probe_position)); // Clear probe position.
|
||||
sys_probe_state = 0;
|
||||
sys_rt_exec_state = 0;
|
||||
sys_rt_exec_alarm = 0;
|
||||
|
|
@ -103,7 +104,6 @@ int main(void)
|
|||
|
||||
// Start Grbl main loop. Processes program inputs and executes them.
|
||||
protocol_main_loop();
|
||||
|
||||
}
|
||||
return 0; /* Never reached */
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,7 +21,6 @@
|
|||
|
||||
#include "grbl.h"
|
||||
|
||||
|
||||
// Execute linear motion in absolute millimeter coordinates. Feed rate given in millimeters/second
|
||||
// unless invert_feed_rate is true. Then the feed_rate means that the motion should be completed in
|
||||
// (1 minute)/feed_rate time.
|
||||
|
|
@ -29,17 +28,20 @@
|
|||
// segments, must pass through this routine before being passed to the planner. The seperation of
|
||||
// mc_line and plan_buffer_line is done primarily to place non-planner-type functions from being
|
||||
// in the planner and to let backlash compensation or canned cycle integration simple and direct.
|
||||
void mc_line(float *target, plan_line_data_t *pl_data)
|
||||
{
|
||||
void mc_line(float *target, plan_line_data_t *pl_data) {
|
||||
// If enabled, check for soft limit violations. Placed here all line motions are picked up
|
||||
// from everywhere in Grbl.
|
||||
if (bit_istrue(settings.flags,BITFLAG_SOFT_LIMIT_ENABLE)) {
|
||||
if (bit_istrue(settings.flags, BITFLAG_SOFT_LIMIT_ENABLE)) {
|
||||
// NOTE: Block jog state. Jogging is a special case and soft limits are handled independently.
|
||||
if (sys.state != STATE_JOG) { limits_soft_check(target); }
|
||||
if (sys.state != STATE_JOG) {
|
||||
limits_soft_check(target);
|
||||
}
|
||||
}
|
||||
|
||||
// If in check gcode mode, prevent motion by blocking planner. Soft limits still work.
|
||||
if (sys.state == STATE_CHECK_MODE) { return; }
|
||||
if (sys.state == STATE_CHECK_MODE) {
|
||||
return;
|
||||
}
|
||||
|
||||
// NOTE: Backlash compensation may be installed here. It will need direction info to track when
|
||||
// to insert a backlash line motion(s) before the intended line motion and will require its own
|
||||
|
|
@ -59,14 +61,20 @@ void mc_line(float *target, plan_line_data_t *pl_data)
|
|||
// Remain in this loop until there is room in the buffer.
|
||||
do {
|
||||
protocol_execute_realtime(); // Check for any run-time commands
|
||||
if (sys.abort) { return; } // Bail, if system abort.
|
||||
if ( plan_check_full_buffer() ) { protocol_auto_cycle_start(); } // Auto-cycle start when buffer is full.
|
||||
else { break; }
|
||||
if (sys.abort) {
|
||||
return;
|
||||
} // Bail, if system abort.
|
||||
if (plan_check_full_buffer()) {
|
||||
protocol_auto_cycle_start();
|
||||
} // Auto-cycle start when buffer is full.
|
||||
else {
|
||||
break;
|
||||
}
|
||||
} while (1);
|
||||
|
||||
// Plan and queue motion into planner buffer
|
||||
if (plan_buffer_line(target, pl_data) == PLAN_EMPTY_BLOCK) {
|
||||
if (bit_istrue(settings.flags,BITFLAG_LASER_MODE)) {
|
||||
if (bit_istrue(settings.flags, BITFLAG_LASER_MODE)) {
|
||||
// Correctly set spindle state, if there is a coincident position passed. Forces a buffer
|
||||
// sync while in M3 laser mode only.
|
||||
if (pl_data->condition & PL_COND_FLAG_SPINDLE_CW) {
|
||||
|
|
@ -76,7 +84,6 @@ void mc_line(float *target, plan_line_data_t *pl_data)
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
// Execute an arc in offset mode format. position == current xyz, target == target xyz,
|
||||
// offset == offset from current xyz, axis_X defines circle plane in tool space, axis_linear is
|
||||
// the direction of helical travel, radius == circle radius, isclockwise boolean. Used
|
||||
|
|
@ -84,9 +91,8 @@ void mc_line(float *target, plan_line_data_t *pl_data)
|
|||
// The arc is approximated by generating a huge number of tiny, linear segments. The chordal tolerance
|
||||
// of each segment is configured in settings.arc_tolerance, which is defined to be the maximum normal
|
||||
// distance from segment to the circle when the end points both lie on the circle.
|
||||
void mc_arc(float *target, plan_line_data_t *pl_data, float *position, float *offset, float radius,
|
||||
uint8_t axis_0, uint8_t axis_1, uint8_t axis_linear, uint8_t is_clockwise_arc)
|
||||
{
|
||||
void mc_arc(float *target, plan_line_data_t *pl_data, float *position, float *offset, float radius, uint8_t axis_0,
|
||||
uint8_t axis_1, uint8_t axis_linear, uint8_t is_clockwise_arc) {
|
||||
float center_axis0 = position[axis_0] + offset[axis_0];
|
||||
float center_axis1 = position[axis_1] + offset[axis_1];
|
||||
float r_axis0 = -offset[axis_0]; // Radius vector from center to current location
|
||||
|
|
@ -95,19 +101,23 @@ void mc_arc(float *target, plan_line_data_t *pl_data, float *position, float *of
|
|||
float rt_axis1 = target[axis_1] - center_axis1;
|
||||
|
||||
// CCW angle between position and target from circle center. Only one atan2() trig computation required.
|
||||
float angular_travel = atan2(r_axis0*rt_axis1-r_axis1*rt_axis0, r_axis0*rt_axis0+r_axis1*rt_axis1);
|
||||
float angular_travel = atan2(r_axis0 * rt_axis1 - r_axis1 * rt_axis0, r_axis0 * rt_axis0 + r_axis1 * rt_axis1);
|
||||
if (is_clockwise_arc) { // Correct atan2 output per direction
|
||||
if (angular_travel >= -ARC_ANGULAR_TRAVEL_EPSILON) { angular_travel -= 2*M_PI; }
|
||||
if (angular_travel >= -ARC_ANGULAR_TRAVEL_EPSILON) {
|
||||
angular_travel -= 2 * M_PI;
|
||||
}
|
||||
} else {
|
||||
if (angular_travel <= ARC_ANGULAR_TRAVEL_EPSILON) { angular_travel += 2*M_PI; }
|
||||
if (angular_travel <= ARC_ANGULAR_TRAVEL_EPSILON) {
|
||||
angular_travel += 2 * M_PI;
|
||||
}
|
||||
}
|
||||
|
||||
// NOTE: Segment end points are on the arc, which can lead to the arc diameter being smaller by up to
|
||||
// (2x) settings.arc_tolerance. For 99% of users, this is just fine. If a different arc segment fit
|
||||
// is desired, i.e. least-squares, midpoint on arc, just change the mm_per_arc_segment calculation.
|
||||
// For the intended uses of Grbl, this value shouldn't exceed 2000 for the strictest of cases.
|
||||
uint16_t segments = floor(fabs(0.5*angular_travel*radius)/
|
||||
sqrt(settings.arc_tolerance*(2*radius - settings.arc_tolerance)) );
|
||||
uint16_t segments = floor(fabs(0.5 * angular_travel * radius) /
|
||||
sqrt(settings.arc_tolerance * (2 * radius - settings.arc_tolerance)));
|
||||
|
||||
if (segments) {
|
||||
// Multiply inverse feed_rate to compensate for the fact that this movement is approximated
|
||||
|
|
@ -115,11 +125,11 @@ void mc_arc(float *target, plan_line_data_t *pl_data, float *position, float *of
|
|||
// all segments.
|
||||
if (pl_data->condition & PL_COND_FLAG_INVERSE_TIME) {
|
||||
pl_data->feed_rate *= segments;
|
||||
bit_false(pl_data->condition,PL_COND_FLAG_INVERSE_TIME); // Force as feed absolute mode over arc segments.
|
||||
bit_false(pl_data->condition, PL_COND_FLAG_INVERSE_TIME); // Force as feed absolute mode over arc segments.
|
||||
}
|
||||
|
||||
float theta_per_segment = angular_travel/segments;
|
||||
float linear_per_segment = (target[axis_linear] - position[axis_linear])/segments;
|
||||
float theta_per_segment = angular_travel / segments;
|
||||
float linear_per_segment = (target[axis_linear] - position[axis_linear]) / segments;
|
||||
|
||||
/* Vector rotation by transformation matrix: r is the original vector, r_T is the rotated vector,
|
||||
and phi is the angle of rotation. Solution approach by Jens Geisler.
|
||||
|
|
@ -147,8 +157,8 @@ void mc_arc(float *target, plan_line_data_t *pl_data, float *position, float *of
|
|||
This is important when there are successive arc motions.
|
||||
*/
|
||||
// Computes: cos_T = 1 - theta_per_segment^2/2, sin_T = theta_per_segment - theta_per_segment^3/6) in ~52usec
|
||||
float cos_T = 2.0 - theta_per_segment*theta_per_segment;
|
||||
float sin_T = theta_per_segment*0.16666667*(cos_T + 4.0);
|
||||
float cos_T = 2.0 - theta_per_segment * theta_per_segment;
|
||||
float sin_T = theta_per_segment * 0.16666667 * (cos_T + 4.0);
|
||||
cos_T *= 0.5;
|
||||
|
||||
float sin_Ti;
|
||||
|
|
@ -157,21 +167,21 @@ void mc_arc(float *target, plan_line_data_t *pl_data, float *position, float *of
|
|||
uint16_t i;
|
||||
uint8_t count = 0;
|
||||
|
||||
for (i = 1; i<segments; i++) { // Increment (segments-1).
|
||||
for (i = 1; i < segments; i++) { // Increment (segments-1).
|
||||
|
||||
if (count < N_ARC_CORRECTION) {
|
||||
// Apply vector rotation matrix. ~40 usec
|
||||
r_axisi = r_axis0*sin_T + r_axis1*cos_T;
|
||||
r_axis0 = r_axis0*cos_T - r_axis1*sin_T;
|
||||
r_axisi = r_axis0 * sin_T + r_axis1 * cos_T;
|
||||
r_axis0 = r_axis0 * cos_T - r_axis1 * sin_T;
|
||||
r_axis1 = r_axisi;
|
||||
count++;
|
||||
} else {
|
||||
// Arc correction to radius vector. Computed only every N_ARC_CORRECTION increments. ~375 usec
|
||||
// Compute exact location by applying transformation matrix from initial radius vector(=-offset).
|
||||
cos_Ti = cos(i*theta_per_segment);
|
||||
sin_Ti = sin(i*theta_per_segment);
|
||||
r_axis0 = -offset[axis_0]*cos_Ti + offset[axis_1]*sin_Ti;
|
||||
r_axis1 = -offset[axis_0]*sin_Ti - offset[axis_1]*cos_Ti;
|
||||
cos_Ti = cos(i * theta_per_segment);
|
||||
sin_Ti = sin(i * theta_per_segment);
|
||||
r_axis0 = -offset[axis_0] * cos_Ti + offset[axis_1] * sin_Ti;
|
||||
r_axis1 = -offset[axis_0] * sin_Ti - offset[axis_1] * cos_Ti;
|
||||
count = 0;
|
||||
}
|
||||
|
||||
|
|
@ -183,61 +193,65 @@ void mc_arc(float *target, plan_line_data_t *pl_data, float *position, float *of
|
|||
mc_line(position, pl_data);
|
||||
|
||||
// Bail mid-circle on system abort. Runtime command check already performed by mc_line.
|
||||
if (sys.abort) { return; }
|
||||
if (sys.abort) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
// Ensure last segment arrives at target location.
|
||||
mc_line(target, pl_data);
|
||||
}
|
||||
|
||||
|
||||
// Execute dwell in seconds.
|
||||
void mc_dwell(float seconds)
|
||||
{
|
||||
if (sys.state == STATE_CHECK_MODE) { return; }
|
||||
void mc_dwell(float seconds) {
|
||||
if (sys.state == STATE_CHECK_MODE) {
|
||||
return;
|
||||
}
|
||||
protocol_buffer_synchronize();
|
||||
delay_sec(seconds, DELAY_MODE_DWELL);
|
||||
}
|
||||
|
||||
|
||||
// Perform homing cycle to locate and set machine zero. Only '$H' executes this command.
|
||||
// NOTE: There should be no motions in the buffer and Grbl must be in an idle state before
|
||||
// executing the homing cycle. This prevents incorrect buffered plans after homing.
|
||||
void mc_homing_cycle(uint8_t cycle_mask)
|
||||
{
|
||||
// Check and abort homing cycle, if hard limits are already enabled. Helps prevent problems
|
||||
// with machines with limits wired on both ends of travel to one limit pin.
|
||||
// TODO: Move the pin-specific LIMIT_PIN call to limits.c as a function.
|
||||
#ifdef LIMITS_TWO_SWITCHES_ON_AXES
|
||||
void mc_homing_cycle(uint8_t cycle_mask) {
|
||||
// Check and abort homing cycle, if hard limits are already enabled. Helps prevent problems
|
||||
// with machines with limits wired on both ends of travel to one limit pin.
|
||||
// TODO: Move the pin-specific LIMIT_PIN call to limits.c as a function.
|
||||
#ifdef LIMITS_TWO_SWITCHES_ON_AXES
|
||||
if (limits_get_state()) {
|
||||
mc_reset(); // Issue system reset and ensure spindle and coolant are shutdown.
|
||||
system_set_exec_alarm(EXEC_ALARM_HARD_LIMIT);
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
limits_disable(); // Disable hard limits pin change register for cycle duration
|
||||
|
||||
// -------------------------------------------------------------------------------------
|
||||
// Perform homing routine. NOTE: Special motion case. Only system reset works.
|
||||
|
||||
#ifdef HOMING_SINGLE_AXIS_COMMANDS
|
||||
if (cycle_mask) { limits_go_home(cycle_mask); } // Perform homing cycle based on mask.
|
||||
#ifdef HOMING_SINGLE_AXIS_COMMANDS
|
||||
if (cycle_mask) {
|
||||
limits_go_home(cycle_mask);
|
||||
} // Perform homing cycle based on mask.
|
||||
else
|
||||
#endif
|
||||
#endif
|
||||
{
|
||||
// Search to engage all axes limit switches at faster homing seek rate.
|
||||
limits_go_home(HOMING_CYCLE_0); // Homing cycle 0
|
||||
#ifdef HOMING_CYCLE_1
|
||||
#ifdef HOMING_CYCLE_1
|
||||
limits_go_home(HOMING_CYCLE_1); // Homing cycle 1
|
||||
#endif
|
||||
#ifdef HOMING_CYCLE_2
|
||||
#endif
|
||||
#ifdef HOMING_CYCLE_2
|
||||
limits_go_home(HOMING_CYCLE_2); // Homing cycle 2
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
protocol_execute_realtime(); // Check for reset and set system abort.
|
||||
if (sys.abort) { return; } // Did not complete. Alarm state set by mc_alarm.
|
||||
if (sys.abort) {
|
||||
return;
|
||||
} // Did not complete. Alarm state set by mc_alarm.
|
||||
|
||||
// Homing cycle complete! Setup system for normal operation.
|
||||
// -------------------------------------------------------------------------------------
|
||||
|
|
@ -250,31 +264,33 @@ void mc_homing_cycle(uint8_t cycle_mask)
|
|||
limits_init();
|
||||
}
|
||||
|
||||
|
||||
// Perform tool length probe cycle. Requires probe switch.
|
||||
// NOTE: Upon probe failure, the program will be stopped and placed into ALARM state.
|
||||
uint8_t mc_probe_cycle(float *target, plan_line_data_t *pl_data, uint8_t parser_flags)
|
||||
{
|
||||
uint8_t mc_probe_cycle(float *target, plan_line_data_t *pl_data, uint8_t parser_flags) {
|
||||
// TODO: Need to update this cycle so it obeys a non-auto cycle start.
|
||||
if (sys.state == STATE_CHECK_MODE) { return(GC_PROBE_CHECK_MODE); }
|
||||
if (sys.state == STATE_CHECK_MODE) {
|
||||
return (GC_PROBE_CHECK_MODE);
|
||||
}
|
||||
|
||||
// Finish all queued commands and empty planner buffer before starting probe cycle.
|
||||
protocol_buffer_synchronize();
|
||||
if (sys.abort) { return(GC_PROBE_ABORT); } // Return if system reset has been issued.
|
||||
if (sys.abort) {
|
||||
return (GC_PROBE_ABORT);
|
||||
} // Return if system reset has been issued.
|
||||
|
||||
// Initialize probing control variables
|
||||
uint8_t is_probe_away = bit_istrue(parser_flags,GC_PARSER_PROBE_IS_AWAY);
|
||||
uint8_t is_no_error = bit_istrue(parser_flags,GC_PARSER_PROBE_IS_NO_ERROR);
|
||||
uint8_t is_probe_away = bit_istrue(parser_flags, GC_PARSER_PROBE_IS_AWAY);
|
||||
uint8_t is_no_error = bit_istrue(parser_flags, GC_PARSER_PROBE_IS_NO_ERROR);
|
||||
sys.probe_succeeded = false; // Re-initialize probe history before beginning cycle.
|
||||
probe_configure_invert_mask(is_probe_away);
|
||||
|
||||
// After syncing, check if probe is already triggered. If so, halt and issue alarm.
|
||||
// NOTE: This probe initialization error applies to all probing cycles.
|
||||
if ( probe_get_state() ) { // Check probe pin state.
|
||||
if (probe_get_state()) { // Check probe pin state.
|
||||
system_set_exec_alarm(EXEC_ALARM_PROBE_FAIL_INITIAL);
|
||||
protocol_execute_realtime();
|
||||
probe_configure_invert_mask(false); // Re-initialize invert mask before returning.
|
||||
return(GC_PROBE_FAIL_INIT); // Nothing else to do but bail.
|
||||
return (GC_PROBE_FAIL_INIT); // Nothing else to do but bail.
|
||||
}
|
||||
|
||||
// Setup and queue probing motion. Auto cycle-start should not start the cycle.
|
||||
|
|
@ -287,15 +303,20 @@ uint8_t mc_probe_cycle(float *target, plan_line_data_t *pl_data, uint8_t parser_
|
|||
system_set_exec_state_flag(EXEC_CYCLE_START);
|
||||
do {
|
||||
protocol_execute_realtime();
|
||||
if (sys.abort) { return(GC_PROBE_ABORT); } // Check for system abort
|
||||
if (sys.abort) {
|
||||
return (GC_PROBE_ABORT);
|
||||
} // Check for system abort
|
||||
} while (sys.state != STATE_IDLE);
|
||||
|
||||
// Probing cycle complete!
|
||||
|
||||
// Set state variables and error out, if the probe failed and cycle with error is enabled.
|
||||
if (sys_probe_state == PROBE_ACTIVE) {
|
||||
if (is_no_error) { memcpy(sys_probe_position, sys_position, sizeof(sys_position)); }
|
||||
else { system_set_exec_alarm(EXEC_ALARM_PROBE_FAIL_CONTACT); }
|
||||
if (is_no_error) {
|
||||
memcpy(sys_probe_position, sys_position, sizeof(sys_position));
|
||||
} else {
|
||||
system_set_exec_alarm(EXEC_ALARM_PROBE_FAIL_CONTACT);
|
||||
}
|
||||
} else {
|
||||
sys.probe_succeeded = true; // Indicate to system the probing cycle completed successfully.
|
||||
}
|
||||
|
|
@ -308,63 +329,67 @@ uint8_t mc_probe_cycle(float *target, plan_line_data_t *pl_data, uint8_t parser_
|
|||
plan_reset(); // Reset planner buffer. Zero planner positions. Ensure probing motion is cleared.
|
||||
plan_sync_position(); // Sync planner position to current machine position.
|
||||
|
||||
#ifdef MESSAGE_PROBE_COORDINATES
|
||||
#ifdef MESSAGE_PROBE_COORDINATES
|
||||
// All done! Output the probe position as message.
|
||||
report_probe_parameters();
|
||||
#endif
|
||||
#endif
|
||||
|
||||
if (sys.probe_succeeded) { return(GC_PROBE_FOUND); } // Successful probe cycle.
|
||||
else { return(GC_PROBE_FAIL_END); } // Failed to trigger probe within travel. With or without error.
|
||||
if (sys.probe_succeeded) {
|
||||
return (GC_PROBE_FOUND);
|
||||
} // Successful probe cycle.
|
||||
else {
|
||||
return (GC_PROBE_FAIL_END);
|
||||
} // Failed to trigger probe within travel. With or without error.
|
||||
}
|
||||
|
||||
|
||||
// Plans and executes the single special motion case for parking. Independent of main planner buffer.
|
||||
// NOTE: Uses the always free planner ring buffer head to store motion parameters for execution.
|
||||
#ifdef PARKING_ENABLE
|
||||
void mc_parking_motion(float *parking_target, plan_line_data_t *pl_data)
|
||||
{
|
||||
if (sys.abort) { return; } // Block during abort.
|
||||
void mc_parking_motion(float *parking_target, plan_line_data_t *pl_data) {
|
||||
if (sys.abort) {
|
||||
return;
|
||||
} // Block during abort.
|
||||
|
||||
uint8_t plan_status = plan_buffer_line(parking_target, pl_data);
|
||||
|
||||
if (plan_status) {
|
||||
bit_true(sys.step_control, STEP_CONTROL_EXECUTE_SYS_MOTION);
|
||||
bit_false(sys.step_control, STEP_CONTROL_END_MOTION); // Allow parking motion to execute, if feed hold is active.
|
||||
bit_false(sys.step_control,
|
||||
STEP_CONTROL_END_MOTION); // Allow parking motion to execute, if feed hold is active.
|
||||
st_parking_setup_buffer(); // Setup step segment buffer for special parking motion case
|
||||
st_prep_buffer();
|
||||
st_wake_up();
|
||||
do {
|
||||
protocol_exec_rt_system();
|
||||
if (sys.abort) { return; }
|
||||
if (sys.abort) {
|
||||
return;
|
||||
}
|
||||
} while (sys.step_control & STEP_CONTROL_EXECUTE_SYS_MOTION);
|
||||
st_parking_restore_buffer(); // Restore step segment buffer to normal run state.
|
||||
} else {
|
||||
bit_false(sys.step_control, STEP_CONTROL_EXECUTE_SYS_MOTION);
|
||||
protocol_exec_rt_system();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef ENABLE_PARKING_OVERRIDE_CONTROL
|
||||
void mc_override_ctrl_update(uint8_t override_state)
|
||||
{
|
||||
void mc_override_ctrl_update(uint8_t override_state) {
|
||||
// Finish all queued commands before altering override control state
|
||||
protocol_buffer_synchronize();
|
||||
if (sys.abort) { return; }
|
||||
sys.override_ctrl = override_state;
|
||||
if (sys.abort) {
|
||||
return;
|
||||
}
|
||||
sys.override_ctrl = override_state;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
// Method to ready the system to reset by setting the realtime reset command and killing any
|
||||
// active processes in the system. This also checks if a system reset is issued while Grbl
|
||||
// is in a motion state. If so, kills the steppers and sets the system alarm to flag position
|
||||
// lost, since there was an abrupt uncontrolled deceleration. Called at an interrupt level by
|
||||
// realtime abort command and hard limits. So, keep to a minimum.
|
||||
void mc_reset()
|
||||
{
|
||||
void mc_reset() {
|
||||
// Only this function can set the system reset. Helps prevent multiple kill calls.
|
||||
if (bit_isfalse(sys_rt_exec_state, EXEC_RESET)) {
|
||||
system_set_exec_state_flag(EXEC_RESET);
|
||||
|
|
@ -380,8 +405,12 @@ void mc_reset()
|
|||
if ((sys.state & (STATE_CYCLE | STATE_HOMING | STATE_JOG)) ||
|
||||
(sys.step_control & (STEP_CONTROL_EXECUTE_HOLD | STEP_CONTROL_EXECUTE_SYS_MOTION))) {
|
||||
if (sys.state == STATE_HOMING) {
|
||||
if (!sys_rt_exec_alarm) {system_set_exec_alarm(EXEC_ALARM_HOMING_FAIL_RESET); }
|
||||
} else { system_set_exec_alarm(EXEC_ALARM_ABORT_CYCLE); }
|
||||
if (!sys_rt_exec_alarm) {
|
||||
system_set_exec_alarm(EXEC_ALARM_HOMING_FAIL_RESET);
|
||||
}
|
||||
} else {
|
||||
system_set_exec_alarm(EXEC_ALARM_ABORT_CYCLE);
|
||||
}
|
||||
st_go_idle(); // Force kill steppers. Position has likely been lost.
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,7 +22,6 @@
|
|||
#ifndef motion_control_h
|
||||
#define motion_control_h
|
||||
|
||||
|
||||
// System motion commands must have a line number of zero.
|
||||
#define HOMING_CYCLE_LINE_NUMBER 0
|
||||
#define PARKING_MOTION_LINE_NUMBER 0
|
||||
|
|
@ -32,7 +31,6 @@
|
|||
#define HOMING_CYCLE_Y bit(Y_AXIS)
|
||||
#define HOMING_CYCLE_Z bit(Z_AXIS)
|
||||
|
||||
|
||||
// Execute linear motion in absolute millimeter coordinates. Feed rate given in millimeters/second
|
||||
// unless invert_feed_rate is true. Then the feed_rate means that the motion should be completed in
|
||||
// (1 minute)/feed_rate time.
|
||||
|
|
@ -42,8 +40,8 @@ void mc_line(float *target, plan_line_data_t *pl_data);
|
|||
// offset == offset from current xyz, axis_XXX defines circle plane in tool space, axis_linear is
|
||||
// the direction of helical travel, radius == circle radius, is_clockwise_arc boolean. Used
|
||||
// for vector transformation direction.
|
||||
void mc_arc(float *target, plan_line_data_t *pl_data, float *position, float *offset, float radius,
|
||||
uint8_t axis_0, uint8_t axis_1, uint8_t axis_linear, uint8_t is_clockwise_arc);
|
||||
void mc_arc(float *target, plan_line_data_t *pl_data, float *position, float *offset, float radius, uint8_t axis_0,
|
||||
uint8_t axis_1, uint8_t axis_linear, uint8_t is_clockwise_arc);
|
||||
|
||||
// Dwell for a specific number of seconds
|
||||
void mc_dwell(float seconds);
|
||||
|
|
|
|||
|
|
@ -21,10 +21,8 @@
|
|||
|
||||
#include "grbl.h"
|
||||
|
||||
|
||||
#define MAX_INT_DIGITS 8 // Maximum number of digits in int32 (and float)
|
||||
|
||||
|
||||
// Extracts a floating point value from a string. The following code is based loosely on
|
||||
// the avr-libc strtod() function by Michael Stumpf and Dmitry Xmelkov and many freely
|
||||
// available conversion method examples, but has been highly optimized for Grbl. For known
|
||||
|
|
@ -32,8 +30,7 @@
|
|||
// Scientific notation is officially not supported by g-code, and the 'E' character may
|
||||
// be a g-code word on some CNC systems. So, 'E' notation will not be recognized.
|
||||
// NOTE: Thanks to Radu-Eosif Mihailescu for identifying the issues with using strtod().
|
||||
uint8_t read_float(char *line, uint8_t *char_counter, float *float_ptr)
|
||||
{
|
||||
uint8_t read_float(char *line, uint8_t *char_counter, float *float_ptr) {
|
||||
char *ptr = line + *char_counter;
|
||||
unsigned char c;
|
||||
|
||||
|
|
@ -54,17 +51,21 @@ uint8_t read_float(char *line, uint8_t *char_counter, float *float_ptr)
|
|||
int8_t exp = 0;
|
||||
uint8_t ndigit = 0;
|
||||
bool isdecimal = false;
|
||||
while(1) {
|
||||
while (1) {
|
||||
c -= '0';
|
||||
if (c <= 9) {
|
||||
ndigit++;
|
||||
if (ndigit <= MAX_INT_DIGITS) {
|
||||
if (isdecimal) { exp--; }
|
||||
if (isdecimal) {
|
||||
exp--;
|
||||
}
|
||||
intval = (((intval << 2) + intval) << 1) + c; // intval*10 + c
|
||||
} else {
|
||||
if (!(isdecimal)) { exp++; } // Drop overflow digits
|
||||
if (!(isdecimal)) {
|
||||
exp++;
|
||||
} // Drop overflow digits
|
||||
}
|
||||
} else if (c == (('.'-'0') & 0xff) && !(isdecimal)) {
|
||||
} else if (c == (('.' - '0') & 0xff) && !(isdecimal)) {
|
||||
isdecimal = true;
|
||||
} else {
|
||||
break;
|
||||
|
|
@ -73,7 +74,9 @@ uint8_t read_float(char *line, uint8_t *char_counter, float *float_ptr)
|
|||
}
|
||||
|
||||
// Return if no digits have been read.
|
||||
if (!ndigit) { return(false); };
|
||||
if (!ndigit) {
|
||||
return (false);
|
||||
};
|
||||
|
||||
// Convert integer into floating point.
|
||||
float fval;
|
||||
|
|
@ -104,41 +107,41 @@ uint8_t read_float(char *line, uint8_t *char_counter, float *float_ptr)
|
|||
|
||||
*char_counter = ptr - line - 1; // Set char_counter to next statement
|
||||
|
||||
return(true);
|
||||
return (true);
|
||||
}
|
||||
|
||||
|
||||
// Non-blocking delay function used for general operation and suspend features.
|
||||
void delay_sec(float seconds, uint8_t mode)
|
||||
{
|
||||
uint16_t i = ceil(1000/DWELL_TIME_STEP*seconds);
|
||||
void delay_sec(float seconds, uint8_t mode) {
|
||||
uint16_t i = ceil(1000 / DWELL_TIME_STEP * seconds);
|
||||
while (i-- > 0) {
|
||||
if (sys.abort) { return; }
|
||||
if (sys.abort) {
|
||||
return;
|
||||
}
|
||||
if (mode == DELAY_MODE_DWELL) {
|
||||
protocol_execute_realtime();
|
||||
} else { // DELAY_MODE_SYS_SUSPEND
|
||||
// Execute rt_system() only to avoid nesting suspend loops.
|
||||
protocol_exec_rt_system();
|
||||
if (sys.suspend & SUSPEND_RESTART_RETRACT) { return; } // Bail, if safety door reopens.
|
||||
if (sys.suspend & SUSPEND_RESTART_RETRACT) {
|
||||
return;
|
||||
} // Bail, if safety door reopens.
|
||||
}
|
||||
_delay_ms(DWELL_TIME_STEP); // Delay DWELL_TIME_STEP increment
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Delays variable defined milliseconds. Compiler compatibility fix for _delay_ms(),
|
||||
// which only accepts constants in future compiler releases.
|
||||
void delay_ms(uint16_t ms)
|
||||
{
|
||||
while ( ms-- ) { _delay_ms(1); }
|
||||
void delay_ms(uint16_t ms) {
|
||||
while (ms--) {
|
||||
_delay_ms(1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Delays variable defined microseconds. Compiler compatibility fix for _delay_us(),
|
||||
// which only accepts constants in future compiler releases. Written to perform more
|
||||
// efficiently with larger delays, as the counter adds parasitic time in each iteration.
|
||||
void delay_us(uint32_t us)
|
||||
{
|
||||
void delay_us(uint32_t us) {
|
||||
while (us) {
|
||||
if (us < 10) {
|
||||
_delay_us(1);
|
||||
|
|
@ -156,35 +159,34 @@ void delay_us(uint32_t us)
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
// Simple hypotenuse computation function.
|
||||
float hypot_f(float x, float y) { return(sqrt(x*x + y*y)); }
|
||||
float hypot_f(float x, float y) {
|
||||
return (sqrt(x * x + y * y));
|
||||
}
|
||||
|
||||
|
||||
float convert_delta_vector_to_unit_vector(float *vector)
|
||||
{
|
||||
float convert_delta_vector_to_unit_vector(float *vector) {
|
||||
uint8_t idx;
|
||||
float magnitude = 0.0;
|
||||
for (idx=0; idx<N_AXIS; idx++) {
|
||||
for (idx = 0; idx < N_AXIS; idx++) {
|
||||
if (vector[idx] != 0.0) {
|
||||
magnitude += vector[idx]*vector[idx];
|
||||
magnitude += vector[idx] * vector[idx];
|
||||
}
|
||||
}
|
||||
magnitude = sqrt(magnitude);
|
||||
float inv_magnitude = 1.0/magnitude;
|
||||
for (idx=0; idx<N_AXIS; idx++) { vector[idx] *= inv_magnitude; }
|
||||
return(magnitude);
|
||||
float inv_magnitude = 1.0 / magnitude;
|
||||
for (idx = 0; idx < N_AXIS; idx++) {
|
||||
vector[idx] *= inv_magnitude;
|
||||
}
|
||||
return (magnitude);
|
||||
}
|
||||
|
||||
|
||||
float limit_value_by_axis_maximum(float *max_value, float *unit_vec)
|
||||
{
|
||||
float limit_value_by_axis_maximum(float *max_value, float *unit_vec) {
|
||||
uint8_t idx;
|
||||
float limit_value = SOME_LARGE_VALUE;
|
||||
for (idx=0; idx<N_AXIS; idx++) {
|
||||
for (idx = 0; idx < N_AXIS; idx++) {
|
||||
if (unit_vec[idx] != 0) { // Avoid divide by zero.
|
||||
limit_value = min(limit_value,fabs(max_value[idx]/unit_vec[idx]));
|
||||
limit_value = min(limit_value, fabs(max_value[idx] / unit_vec[idx]));
|
||||
}
|
||||
}
|
||||
return(limit_value);
|
||||
return (limit_value);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -37,32 +37,32 @@
|
|||
// CoreXY motor assignments. DO NOT ALTER.
|
||||
// NOTE: If the A and B motor axis bindings are changed, this effects the CoreXY equations.
|
||||
#ifdef COREXY
|
||||
#define A_MOTOR X_AXIS // Must be X_AXIS
|
||||
#define B_MOTOR Y_AXIS // Must be Y_AXIS
|
||||
#define A_MOTOR X_AXIS // Must be X_AXIS
|
||||
#define B_MOTOR Y_AXIS // Must be Y_AXIS
|
||||
#endif
|
||||
|
||||
// Conversions
|
||||
#define MM_PER_INCH (25.40)
|
||||
#define INCH_PER_MM (0.0393701)
|
||||
#define TICKS_PER_MICROSECOND (F_CPU/1000000)
|
||||
#define TICKS_PER_MICROSECOND (F_CPU / 1000000)
|
||||
|
||||
#define DELAY_MODE_DWELL 0
|
||||
#define DELAY_MODE_SYS_SUSPEND 1
|
||||
|
||||
// Useful macros
|
||||
#define clear_vector(a) memset(a, 0, sizeof(a))
|
||||
#define clear_vector_float(a) memset(a, 0.0, sizeof(float)*N_AXIS)
|
||||
#define clear_vector_float(a) memset(a, 0.0, sizeof(float) * N_AXIS)
|
||||
// #define clear_vector_long(a) memset(a, 0.0, sizeof(long)*N_AXIS)
|
||||
#define max(a,b) (((a) > (b)) ? (a) : (b))
|
||||
#define min(a,b) (((a) < (b)) ? (a) : (b))
|
||||
#define isequal_position_vector(a,b) !(memcmp(a, b, sizeof(float)*N_AXIS))
|
||||
#define max(a, b) (((a) > (b)) ? (a) : (b))
|
||||
#define min(a, b) (((a) < (b)) ? (a) : (b))
|
||||
#define isequal_position_vector(a, b) !(memcmp(a, b, sizeof(float) * N_AXIS))
|
||||
|
||||
// Bit field and masking macros
|
||||
#define bit(n) (1 << n)
|
||||
#define bit_true(x,mask) (x) |= (mask)
|
||||
#define bit_false(x,mask) (x) &= ~(mask)
|
||||
#define bit_istrue(x,mask) ((x & mask) != 0)
|
||||
#define bit_isfalse(x,mask) ((x & mask) == 0)
|
||||
#define bit_true(x, mask) (x) |= (mask)
|
||||
#define bit_false(x, mask) (x) &= ~(mask)
|
||||
#define bit_istrue(x, mask) ((x & mask) != 0)
|
||||
#define bit_isfalse(x, mask) ((x & mask) == 0)
|
||||
|
||||
// Read a floating point value from a string. Line points to the input buffer, char_counter
|
||||
// is the indexer pointing to the current character of the line, while float_ptr is
|
||||
|
|
|
|||
293
grbl/planner.c
293
grbl/planner.c
|
|
@ -22,7 +22,6 @@
|
|||
|
||||
#include "grbl.h"
|
||||
|
||||
|
||||
static plan_block_t block_buffer[BLOCK_BUFFER_SIZE]; // A ring buffer for motion instructions
|
||||
static uint8_t block_buffer_tail; // Index of the block to process now
|
||||
static uint8_t block_buffer_head; // Index of the next block to be pushed
|
||||
|
|
@ -37,27 +36,27 @@ typedef struct {
|
|||
float previous_unit_vec[N_AXIS]; // Unit vector of previous path line segment
|
||||
float previous_nominal_speed; // Nominal speed of previous path line segment
|
||||
} planner_t;
|
||||
|
||||
static planner_t pl;
|
||||
|
||||
|
||||
// Returns the index of the next block in the ring buffer. Also called by stepper segment buffer.
|
||||
uint8_t plan_next_block_index(uint8_t block_index)
|
||||
{
|
||||
uint8_t plan_next_block_index(uint8_t block_index) {
|
||||
block_index++;
|
||||
if (block_index == BLOCK_BUFFER_SIZE) { block_index = 0; }
|
||||
return(block_index);
|
||||
if (block_index == BLOCK_BUFFER_SIZE) {
|
||||
block_index = 0;
|
||||
}
|
||||
return (block_index);
|
||||
}
|
||||
|
||||
|
||||
// Returns the index of the previous block in the ring buffer
|
||||
static uint8_t plan_prev_block_index(uint8_t block_index)
|
||||
{
|
||||
if (block_index == 0) { block_index = BLOCK_BUFFER_SIZE; }
|
||||
static uint8_t plan_prev_block_index(uint8_t block_index) {
|
||||
if (block_index == 0) {
|
||||
block_index = BLOCK_BUFFER_SIZE;
|
||||
}
|
||||
block_index--;
|
||||
return(block_index);
|
||||
return (block_index);
|
||||
}
|
||||
|
||||
|
||||
/* PLANNER SPEED DEFINITION
|
||||
+--------+ <- current->nominal_speed
|
||||
/ \
|
||||
|
|
@ -123,13 +122,14 @@ static uint8_t plan_prev_block_index(uint8_t block_index)
|
|||
ARM versions should have enough memory and speed for look-ahead blocks numbering up to a hundred or more.
|
||||
|
||||
*/
|
||||
static void planner_recalculate()
|
||||
{
|
||||
static void planner_recalculate() {
|
||||
// Initialize block index to the last block in the planner buffer.
|
||||
uint8_t block_index = plan_prev_block_index(block_buffer_head);
|
||||
|
||||
// Bail. Can't do anything with one only one plan-able block.
|
||||
if (block_index == block_buffer_planned) { return; }
|
||||
if (block_index == block_buffer_planned) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Reverse Pass: Coarsely maximize all possible deceleration curves back-planning from the last
|
||||
// block in buffer. Cease planning when the last optimal planned or tail pointer is reached.
|
||||
|
|
@ -139,12 +139,14 @@ static void planner_recalculate()
|
|||
plan_block_t *current = &block_buffer[block_index];
|
||||
|
||||
// Calculate maximum entry speed for last block in buffer, where the exit speed is always zero.
|
||||
current->entry_speed_sqr = min( current->max_entry_speed_sqr, 2*current->acceleration*current->millimeters);
|
||||
current->entry_speed_sqr = min(current->max_entry_speed_sqr, 2 * current->acceleration * current->millimeters);
|
||||
|
||||
block_index = plan_prev_block_index(block_index);
|
||||
if (block_index == block_buffer_planned) { // Only two plannable blocks in buffer. Reverse pass complete.
|
||||
// Check if the first block is the tail. If so, notify stepper to update its current parameters.
|
||||
if (block_index == block_buffer_tail) { st_update_plan_block_parameters(); }
|
||||
if (block_index == block_buffer_tail) {
|
||||
st_update_plan_block_parameters();
|
||||
}
|
||||
} else { // Three or more plan-able blocks
|
||||
while (block_index != block_buffer_planned) {
|
||||
next = current;
|
||||
|
|
@ -152,11 +154,13 @@ static void planner_recalculate()
|
|||
block_index = plan_prev_block_index(block_index);
|
||||
|
||||
// Check if next block is the tail block(=planned block). If so, update current stepper parameters.
|
||||
if (block_index == block_buffer_tail) { st_update_plan_block_parameters(); }
|
||||
if (block_index == block_buffer_tail) {
|
||||
st_update_plan_block_parameters();
|
||||
}
|
||||
|
||||
// Compute maximum entry speed decelerating over the current block from its exit speed.
|
||||
if (current->entry_speed_sqr != current->max_entry_speed_sqr) {
|
||||
entry_speed_sqr = next->entry_speed_sqr + 2*current->acceleration*current->millimeters;
|
||||
entry_speed_sqr = next->entry_speed_sqr + 2 * current->acceleration * current->millimeters;
|
||||
if (entry_speed_sqr < current->max_entry_speed_sqr) {
|
||||
current->entry_speed_sqr = entry_speed_sqr;
|
||||
} else {
|
||||
|
|
@ -178,7 +182,7 @@ static void planner_recalculate()
|
|||
// pointer forward, since everything before this is all optimal. In other words, nothing
|
||||
// can improve the plan from the buffer tail to the planned pointer by logic.
|
||||
if (current->entry_speed_sqr < next->entry_speed_sqr) {
|
||||
entry_speed_sqr = current->entry_speed_sqr + 2*current->acceleration*current->millimeters;
|
||||
entry_speed_sqr = current->entry_speed_sqr + 2 * current->acceleration * current->millimeters;
|
||||
// If true, current block is full-acceleration and we can move the planned pointer forward.
|
||||
if (entry_speed_sqr < next->entry_speed_sqr) {
|
||||
next->entry_speed_sqr = entry_speed_sqr; // Always <= max_entry_speed_sqr. Backward pass sets this.
|
||||
|
|
@ -190,99 +194,101 @@ static void planner_recalculate()
|
|||
// point in the buffer. When the plan is bracketed by either the beginning of the
|
||||
// buffer and a maximum entry speed or two maximum entry speeds, every block in between
|
||||
// cannot logically be further improved. Hence, we don't have to recompute them anymore.
|
||||
if (next->entry_speed_sqr == next->max_entry_speed_sqr) { block_buffer_planned = block_index; }
|
||||
block_index = plan_next_block_index( block_index );
|
||||
if (next->entry_speed_sqr == next->max_entry_speed_sqr) {
|
||||
block_buffer_planned = block_index;
|
||||
}
|
||||
block_index = plan_next_block_index(block_index);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void plan_reset()
|
||||
{
|
||||
void plan_reset() {
|
||||
memset(&pl, 0, sizeof(planner_t)); // Clear planner struct
|
||||
plan_reset_buffer();
|
||||
}
|
||||
|
||||
|
||||
void plan_reset_buffer()
|
||||
{
|
||||
void plan_reset_buffer() {
|
||||
block_buffer_tail = 0;
|
||||
block_buffer_head = 0; // Empty = tail
|
||||
next_buffer_head = 1; // plan_next_block_index(block_buffer_head)
|
||||
block_buffer_planned = 0; // = block_buffer_tail;
|
||||
}
|
||||
|
||||
|
||||
void plan_discard_current_block()
|
||||
{
|
||||
void plan_discard_current_block() {
|
||||
if (block_buffer_head != block_buffer_tail) { // Discard non-empty buffer.
|
||||
uint8_t block_index = plan_next_block_index( block_buffer_tail );
|
||||
uint8_t block_index = plan_next_block_index(block_buffer_tail);
|
||||
// Push block_buffer_planned pointer, if encountered.
|
||||
if (block_buffer_tail == block_buffer_planned) { block_buffer_planned = block_index; }
|
||||
if (block_buffer_tail == block_buffer_planned) {
|
||||
block_buffer_planned = block_index;
|
||||
}
|
||||
block_buffer_tail = block_index;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Returns address of planner buffer block used by system motions. Called by segment generator.
|
||||
plan_block_t *plan_get_system_motion_block()
|
||||
{
|
||||
return(&block_buffer[block_buffer_head]);
|
||||
plan_block_t *plan_get_system_motion_block() {
|
||||
return (&block_buffer[block_buffer_head]);
|
||||
}
|
||||
|
||||
|
||||
// Returns address of first planner block, if available. Called by various main program functions.
|
||||
plan_block_t *plan_get_current_block()
|
||||
{
|
||||
if (block_buffer_head == block_buffer_tail) { return(NULL); } // Buffer empty
|
||||
return(&block_buffer[block_buffer_tail]);
|
||||
plan_block_t *plan_get_current_block() {
|
||||
if (block_buffer_head == block_buffer_tail) {
|
||||
return (NULL);
|
||||
} // Buffer empty
|
||||
return (&block_buffer[block_buffer_tail]);
|
||||
}
|
||||
|
||||
|
||||
float plan_get_exec_block_exit_speed_sqr()
|
||||
{
|
||||
float plan_get_exec_block_exit_speed_sqr() {
|
||||
uint8_t block_index = plan_next_block_index(block_buffer_tail);
|
||||
if (block_index == block_buffer_head) { return( 0.0 ); }
|
||||
return( block_buffer[block_index].entry_speed_sqr );
|
||||
if (block_index == block_buffer_head) {
|
||||
return (0.0);
|
||||
}
|
||||
return (block_buffer[block_index].entry_speed_sqr);
|
||||
}
|
||||
|
||||
|
||||
// Returns the availability status of the block ring buffer. True, if full.
|
||||
uint8_t plan_check_full_buffer()
|
||||
{
|
||||
if (block_buffer_tail == next_buffer_head) { return(true); }
|
||||
return(false);
|
||||
uint8_t plan_check_full_buffer() {
|
||||
if (block_buffer_tail == next_buffer_head) {
|
||||
return (true);
|
||||
}
|
||||
return (false);
|
||||
}
|
||||
|
||||
|
||||
// Computes and returns block nominal speed based on running condition and override values.
|
||||
// NOTE: All system motion commands, such as homing/parking, are not subject to overrides.
|
||||
float plan_compute_profile_nominal_speed(plan_block_t *block)
|
||||
{
|
||||
float plan_compute_profile_nominal_speed(plan_block_t *block) {
|
||||
float nominal_speed = block->programmed_rate;
|
||||
if (block->condition & PL_COND_FLAG_RAPID_MOTION) { nominal_speed *= (0.01*sys.r_override); }
|
||||
else {
|
||||
if (!(block->condition & PL_COND_FLAG_NO_FEED_OVERRIDE)) { nominal_speed *= (0.01*sys.f_override); }
|
||||
if (nominal_speed > block->rapid_rate) { nominal_speed = block->rapid_rate; }
|
||||
if (block->condition & PL_COND_FLAG_RAPID_MOTION) {
|
||||
nominal_speed *= (0.01 * sys.r_override);
|
||||
} else {
|
||||
if (!(block->condition & PL_COND_FLAG_NO_FEED_OVERRIDE)) {
|
||||
nominal_speed *= (0.01 * sys.f_override);
|
||||
}
|
||||
if (nominal_speed > MINIMUM_FEED_RATE) { return(nominal_speed); }
|
||||
return(MINIMUM_FEED_RATE);
|
||||
if (nominal_speed > block->rapid_rate) {
|
||||
nominal_speed = block->rapid_rate;
|
||||
}
|
||||
}
|
||||
if (nominal_speed > MINIMUM_FEED_RATE) {
|
||||
return (nominal_speed);
|
||||
}
|
||||
return (MINIMUM_FEED_RATE);
|
||||
}
|
||||
|
||||
|
||||
// Computes and updates the max entry speed (sqr) of the block, based on the minimum of the junction's
|
||||
// previous and current nominal speeds and max junction speed.
|
||||
static void plan_compute_profile_parameters(plan_block_t *block, float nominal_speed, float prev_nominal_speed)
|
||||
{
|
||||
static void plan_compute_profile_parameters(plan_block_t *block, float nominal_speed, float prev_nominal_speed) {
|
||||
// Compute the junction maximum entry based on the minimum of the junction speed and neighboring nominal speeds.
|
||||
if (nominal_speed > prev_nominal_speed) { block->max_entry_speed_sqr = prev_nominal_speed*prev_nominal_speed; }
|
||||
else { block->max_entry_speed_sqr = nominal_speed*nominal_speed; }
|
||||
if (block->max_entry_speed_sqr > block->max_junction_speed_sqr) { block->max_entry_speed_sqr = block->max_junction_speed_sqr; }
|
||||
if (nominal_speed > prev_nominal_speed) {
|
||||
block->max_entry_speed_sqr = prev_nominal_speed * prev_nominal_speed;
|
||||
} else {
|
||||
block->max_entry_speed_sqr = nominal_speed * nominal_speed;
|
||||
}
|
||||
if (block->max_entry_speed_sqr > block->max_junction_speed_sqr) {
|
||||
block->max_entry_speed_sqr = block->max_junction_speed_sqr;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Re-calculates buffered motions profile parameters upon a motion-based override change.
|
||||
void plan_update_velocity_profile_parameters()
|
||||
{
|
||||
void plan_update_velocity_profile_parameters() {
|
||||
uint8_t block_index = block_buffer_tail;
|
||||
plan_block_t *block;
|
||||
float nominal_speed;
|
||||
|
|
@ -297,7 +303,6 @@ void plan_update_velocity_profile_parameters()
|
|||
pl.previous_nominal_speed = prev_nominal_speed; // Update prev nominal speed for next incoming block.
|
||||
}
|
||||
|
||||
|
||||
/* Add a new linear movement to the buffer. target[N_AXIS] is the signed, absolute target position
|
||||
in millimeters. Feed rate specifies the speed of the motion. If feed rate is inverted, the feed
|
||||
rate is taken to mean "frequency" and would complete the operation in 1/feed_rate minutes.
|
||||
|
|
@ -312,18 +317,17 @@ void plan_update_velocity_profile_parameters()
|
|||
head. It avoids changing the planner state and preserves the buffer to ensure subsequent gcode
|
||||
motions are still planned correctly, while the stepper module only points to the block buffer head
|
||||
to execute the special system motion. */
|
||||
uint8_t plan_buffer_line(float *target, plan_line_data_t *pl_data)
|
||||
{
|
||||
uint8_t plan_buffer_line(float *target, plan_line_data_t *pl_data) {
|
||||
// Prepare and initialize new block. Copy relevant pl_data for block execution.
|
||||
plan_block_t *block = &block_buffer[block_buffer_head];
|
||||
memset(block,0,sizeof(plan_block_t)); // Zero all block values.
|
||||
memset(block, 0, sizeof(plan_block_t)); // Zero all block values.
|
||||
block->condition = pl_data->condition;
|
||||
#ifdef VARIABLE_SPINDLE
|
||||
#ifdef VARIABLE_SPINDLE
|
||||
block->spindle_speed = pl_data->spindle_speed;
|
||||
#endif
|
||||
#ifdef USE_LINE_NUMBERS
|
||||
#endif
|
||||
#ifdef USE_LINE_NUMBERS
|
||||
block->line_number = pl_data->line_number;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// Compute and store initial move distance data.
|
||||
int32_t target_steps[N_AXIS], position_steps[N_AXIS];
|
||||
|
|
@ -332,53 +336,63 @@ uint8_t plan_buffer_line(float *target, plan_line_data_t *pl_data)
|
|||
|
||||
// Copy position data based on type of motion being planned.
|
||||
if (block->condition & PL_COND_FLAG_SYSTEM_MOTION) {
|
||||
#ifdef COREXY
|
||||
#ifdef COREXY
|
||||
position_steps[X_AXIS] = system_convert_corexy_to_x_axis_steps(sys_position);
|
||||
position_steps[Y_AXIS] = system_convert_corexy_to_y_axis_steps(sys_position);
|
||||
position_steps[Z_AXIS] = sys_position[Z_AXIS];
|
||||
#else
|
||||
#else
|
||||
memcpy(position_steps, sys_position, sizeof(sys_position));
|
||||
#endif
|
||||
} else { memcpy(position_steps, pl.position, sizeof(pl.position)); }
|
||||
#endif
|
||||
} else {
|
||||
memcpy(position_steps, pl.position, sizeof(pl.position));
|
||||
}
|
||||
|
||||
#ifdef COREXY
|
||||
target_steps[A_MOTOR] = lround(target[A_MOTOR]*settings.steps_per_mm[A_MOTOR]);
|
||||
target_steps[B_MOTOR] = lround(target[B_MOTOR]*settings.steps_per_mm[B_MOTOR]);
|
||||
block->steps[A_MOTOR] = labs((target_steps[X_AXIS]-position_steps[X_AXIS]) + (target_steps[Y_AXIS]-position_steps[Y_AXIS]));
|
||||
block->steps[B_MOTOR] = labs((target_steps[X_AXIS]-position_steps[X_AXIS]) - (target_steps[Y_AXIS]-position_steps[Y_AXIS]));
|
||||
#endif
|
||||
#ifdef COREXY
|
||||
target_steps[A_MOTOR] = lround(target[A_MOTOR] * settings.steps_per_mm[A_MOTOR]);
|
||||
target_steps[B_MOTOR] = lround(target[B_MOTOR] * settings.steps_per_mm[B_MOTOR]);
|
||||
block->steps[A_MOTOR] =
|
||||
labs((target_steps[X_AXIS] - position_steps[X_AXIS]) + (target_steps[Y_AXIS] - position_steps[Y_AXIS]));
|
||||
block->steps[B_MOTOR] =
|
||||
labs((target_steps[X_AXIS] - position_steps[X_AXIS]) - (target_steps[Y_AXIS] - position_steps[Y_AXIS]));
|
||||
#endif
|
||||
|
||||
for (idx=0; idx<N_AXIS; idx++) {
|
||||
// Calculate target position in absolute steps, number of steps for each axis, and determine max step events.
|
||||
// Also, compute individual axes distance for move and prep unit vector calculations.
|
||||
// NOTE: Computes true distance from converted step values.
|
||||
#ifdef COREXY
|
||||
if ( !(idx == A_MOTOR) && !(idx == B_MOTOR) ) {
|
||||
target_steps[idx] = lround(target[idx]*settings.steps_per_mm[idx]);
|
||||
block->steps[idx] = labs(target_steps[idx]-position_steps[idx]);
|
||||
for (idx = 0; idx < N_AXIS; idx++) {
|
||||
// Calculate target position in absolute steps, number of steps for each axis, and determine max step events.
|
||||
// Also, compute individual axes distance for move and prep unit vector calculations.
|
||||
// NOTE: Computes true distance from converted step values.
|
||||
#ifdef COREXY
|
||||
if (!(idx == A_MOTOR) && !(idx == B_MOTOR)) {
|
||||
target_steps[idx] = lround(target[idx] * settings.steps_per_mm[idx]);
|
||||
block->steps[idx] = labs(target_steps[idx] - position_steps[idx]);
|
||||
}
|
||||
block->step_event_count = max(block->step_event_count, block->steps[idx]);
|
||||
if (idx == A_MOTOR) {
|
||||
delta_mm = (target_steps[X_AXIS]-position_steps[X_AXIS] + target_steps[Y_AXIS]-position_steps[Y_AXIS])/settings.steps_per_mm[idx];
|
||||
delta_mm = (target_steps[X_AXIS] - position_steps[X_AXIS] + target_steps[Y_AXIS] - position_steps[Y_AXIS]) /
|
||||
settings.steps_per_mm[idx];
|
||||
} else if (idx == B_MOTOR) {
|
||||
delta_mm = (target_steps[X_AXIS]-position_steps[X_AXIS] - target_steps[Y_AXIS]+position_steps[Y_AXIS])/settings.steps_per_mm[idx];
|
||||
delta_mm = (target_steps[X_AXIS] - position_steps[X_AXIS] - target_steps[Y_AXIS] + position_steps[Y_AXIS]) /
|
||||
settings.steps_per_mm[idx];
|
||||
} else {
|
||||
delta_mm = (target_steps[idx] - position_steps[idx])/settings.steps_per_mm[idx];
|
||||
delta_mm = (target_steps[idx] - position_steps[idx]) / settings.steps_per_mm[idx];
|
||||
}
|
||||
#else
|
||||
target_steps[idx] = lround(target[idx]*settings.steps_per_mm[idx]);
|
||||
block->steps[idx] = labs(target_steps[idx]-position_steps[idx]);
|
||||
#else
|
||||
target_steps[idx] = lround(target[idx] * settings.steps_per_mm[idx]);
|
||||
block->steps[idx] = labs(target_steps[idx] - position_steps[idx]);
|
||||
block->step_event_count = max(block->step_event_count, block->steps[idx]);
|
||||
delta_mm = (target_steps[idx] - position_steps[idx])/settings.steps_per_mm[idx];
|
||||
#endif
|
||||
delta_mm = (target_steps[idx] - position_steps[idx]) / settings.steps_per_mm[idx];
|
||||
#endif
|
||||
unit_vec[idx] = delta_mm; // Store unit vector numerator
|
||||
|
||||
// Set direction bits. Bit enabled always means direction is negative.
|
||||
if (delta_mm < 0.0 ) { block->direction_bits |= get_direction_pin_mask(idx); }
|
||||
if (delta_mm < 0.0) {
|
||||
block->direction_bits |= get_direction_pin_mask(idx);
|
||||
}
|
||||
}
|
||||
|
||||
// Bail if this is a zero-length block. Highly unlikely to occur.
|
||||
if (block->step_event_count == 0) { return(PLAN_EMPTY_BLOCK); }
|
||||
if (block->step_event_count == 0) {
|
||||
return (PLAN_EMPTY_BLOCK);
|
||||
}
|
||||
|
||||
// Calculate the unit vector of the line move and the block maximum feed rate and acceleration scaled
|
||||
// down such that no individual axes maximum values are exceeded with respect to the line direction.
|
||||
|
|
@ -389,10 +403,13 @@ uint8_t plan_buffer_line(float *target, plan_line_data_t *pl_data)
|
|||
block->rapid_rate = limit_value_by_axis_maximum(settings.max_rate, unit_vec);
|
||||
|
||||
// Store programmed rate.
|
||||
if (block->condition & PL_COND_FLAG_RAPID_MOTION) { block->programmed_rate = block->rapid_rate; }
|
||||
else {
|
||||
if (block->condition & PL_COND_FLAG_RAPID_MOTION) {
|
||||
block->programmed_rate = block->rapid_rate;
|
||||
} else {
|
||||
block->programmed_rate = pl_data->feed_rate;
|
||||
if (block->condition & PL_COND_FLAG_INVERSE_TIME) { block->programmed_rate *= block->millimeters; }
|
||||
if (block->condition & PL_COND_FLAG_INVERSE_TIME) {
|
||||
block->programmed_rate *= block->millimeters;
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Need to check this method handling zero junction speeds when starting from rest.
|
||||
|
|
@ -428,15 +445,15 @@ uint8_t plan_buffer_line(float *target, plan_line_data_t *pl_data)
|
|||
|
||||
float junction_unit_vec[N_AXIS];
|
||||
float junction_cos_theta = 0.0;
|
||||
for (idx=0; idx<N_AXIS; idx++) {
|
||||
junction_cos_theta -= pl.previous_unit_vec[idx]*unit_vec[idx];
|
||||
junction_unit_vec[idx] = unit_vec[idx]-pl.previous_unit_vec[idx];
|
||||
for (idx = 0; idx < N_AXIS; idx++) {
|
||||
junction_cos_theta -= pl.previous_unit_vec[idx] * unit_vec[idx];
|
||||
junction_unit_vec[idx] = unit_vec[idx] - pl.previous_unit_vec[idx];
|
||||
}
|
||||
|
||||
// NOTE: Computed without any expensive trig, sin() or acos(), by trig half angle identity of cos(theta).
|
||||
if (junction_cos_theta > 0.999999) {
|
||||
// For a 0 degree acute junction, just set minimum junction speed.
|
||||
block->max_junction_speed_sqr = MINIMUM_JUNCTION_SPEED*MINIMUM_JUNCTION_SPEED;
|
||||
block->max_junction_speed_sqr = MINIMUM_JUNCTION_SPEED * MINIMUM_JUNCTION_SPEED;
|
||||
} else {
|
||||
if (junction_cos_theta < -0.999999) {
|
||||
// Junction is a straight line or 180 degrees. Junction speed is infinite.
|
||||
|
|
@ -444,9 +461,11 @@ uint8_t plan_buffer_line(float *target, plan_line_data_t *pl_data)
|
|||
} else {
|
||||
convert_delta_vector_to_unit_vector(junction_unit_vec);
|
||||
float junction_acceleration = limit_value_by_axis_maximum(settings.acceleration, junction_unit_vec);
|
||||
float sin_theta_d2 = sqrt(0.5*(1.0-junction_cos_theta)); // Trig half angle identity. Always positive.
|
||||
block->max_junction_speed_sqr = max( MINIMUM_JUNCTION_SPEED*MINIMUM_JUNCTION_SPEED,
|
||||
(junction_acceleration * settings.junction_deviation * sin_theta_d2)/(1.0-sin_theta_d2) );
|
||||
float sin_theta_d2 =
|
||||
sqrt(0.5 * (1.0 - junction_cos_theta)); // Trig half angle identity. Always positive.
|
||||
block->max_junction_speed_sqr =
|
||||
max(MINIMUM_JUNCTION_SPEED * MINIMUM_JUNCTION_SPEED,
|
||||
(junction_acceleration * settings.junction_deviation * sin_theta_d2) / (1.0 - sin_theta_d2));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -468,53 +487,49 @@ uint8_t plan_buffer_line(float *target, plan_line_data_t *pl_data)
|
|||
// Finish up by recalculating the plan with the new block.
|
||||
planner_recalculate();
|
||||
}
|
||||
return(PLAN_OK);
|
||||
return (PLAN_OK);
|
||||
}
|
||||
|
||||
|
||||
// Reset the planner position vectors. Called by the system abort/initialization routine.
|
||||
void plan_sync_position()
|
||||
{
|
||||
void plan_sync_position() {
|
||||
// TODO: For motor configurations not in the same coordinate frame as the machine position,
|
||||
// this function needs to be updated to accomodate the difference.
|
||||
uint8_t idx;
|
||||
for (idx=0; idx<N_AXIS; idx++) {
|
||||
#ifdef COREXY
|
||||
if (idx==X_AXIS) {
|
||||
for (idx = 0; idx < N_AXIS; idx++) {
|
||||
#ifdef COREXY
|
||||
if (idx == X_AXIS) {
|
||||
pl.position[X_AXIS] = system_convert_corexy_to_x_axis_steps(sys_position);
|
||||
} else if (idx==Y_AXIS) {
|
||||
} else if (idx == Y_AXIS) {
|
||||
pl.position[Y_AXIS] = system_convert_corexy_to_y_axis_steps(sys_position);
|
||||
} else {
|
||||
pl.position[idx] = sys_position[idx];
|
||||
}
|
||||
#else
|
||||
#else
|
||||
pl.position[idx] = sys_position[idx];
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Returns the number of available blocks are in the planner buffer.
|
||||
uint8_t plan_get_block_buffer_available()
|
||||
{
|
||||
if (block_buffer_head >= block_buffer_tail) { return((BLOCK_BUFFER_SIZE-1)-(block_buffer_head-block_buffer_tail)); }
|
||||
return((block_buffer_tail-block_buffer_head-1));
|
||||
uint8_t plan_get_block_buffer_available() {
|
||||
if (block_buffer_head >= block_buffer_tail) {
|
||||
return ((BLOCK_BUFFER_SIZE - 1) - (block_buffer_head - block_buffer_tail));
|
||||
}
|
||||
return ((block_buffer_tail - block_buffer_head - 1));
|
||||
}
|
||||
|
||||
|
||||
// Returns the number of active blocks are in the planner buffer.
|
||||
// NOTE: Deprecated. Not used unless classic status reports are enabled in config.h
|
||||
uint8_t plan_get_block_buffer_count()
|
||||
{
|
||||
if (block_buffer_head >= block_buffer_tail) { return(block_buffer_head-block_buffer_tail); }
|
||||
return(BLOCK_BUFFER_SIZE - (block_buffer_tail-block_buffer_head));
|
||||
uint8_t plan_get_block_buffer_count() {
|
||||
if (block_buffer_head >= block_buffer_tail) {
|
||||
return (block_buffer_head - block_buffer_tail);
|
||||
}
|
||||
return (BLOCK_BUFFER_SIZE - (block_buffer_tail - block_buffer_head));
|
||||
}
|
||||
|
||||
|
||||
// Re-initialize buffer plan with a partially completed block, assumed to exist at the buffer tail.
|
||||
// Called after a steppers have come to a complete stop for a feed hold and the cycle is stopped.
|
||||
void plan_cycle_reinitialize()
|
||||
{
|
||||
void plan_cycle_reinitialize() {
|
||||
// Re-plan from a complete stop. Reset planner entry speeds and buffer planned pointer.
|
||||
st_update_plan_block_parameters();
|
||||
block_buffer_planned = block_buffer_tail;
|
||||
|
|
|
|||
|
|
@ -22,14 +22,13 @@
|
|||
#ifndef planner_h
|
||||
#define planner_h
|
||||
|
||||
|
||||
// The number of linear motions that can be in the plan at any give time
|
||||
#ifndef BLOCK_BUFFER_SIZE
|
||||
#ifdef USE_LINE_NUMBERS
|
||||
#define BLOCK_BUFFER_SIZE 15
|
||||
#else
|
||||
#define BLOCK_BUFFER_SIZE 16
|
||||
#endif
|
||||
#ifdef USE_LINE_NUMBERS
|
||||
#define BLOCK_BUFFER_SIZE 15
|
||||
#else
|
||||
#define BLOCK_BUFFER_SIZE 16
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// Returned status message from planner.
|
||||
|
|
@ -45,10 +44,10 @@
|
|||
#define PL_COND_FLAG_SPINDLE_CCW bit(5)
|
||||
#define PL_COND_FLAG_COOLANT_FLOOD bit(6)
|
||||
#define PL_COND_FLAG_COOLANT_MIST bit(7)
|
||||
#define PL_COND_MOTION_MASK (PL_COND_FLAG_RAPID_MOTION|PL_COND_FLAG_SYSTEM_MOTION|PL_COND_FLAG_NO_FEED_OVERRIDE)
|
||||
#define PL_COND_SPINDLE_MASK (PL_COND_FLAG_SPINDLE_CW|PL_COND_FLAG_SPINDLE_CCW)
|
||||
#define PL_COND_ACCESSORY_MASK (PL_COND_FLAG_SPINDLE_CW|PL_COND_FLAG_SPINDLE_CCW|PL_COND_FLAG_COOLANT_FLOOD|PL_COND_FLAG_COOLANT_MIST)
|
||||
|
||||
#define PL_COND_MOTION_MASK (PL_COND_FLAG_RAPID_MOTION | PL_COND_FLAG_SYSTEM_MOTION | PL_COND_FLAG_NO_FEED_OVERRIDE)
|
||||
#define PL_COND_SPINDLE_MASK (PL_COND_FLAG_SPINDLE_CW | PL_COND_FLAG_SPINDLE_CCW)
|
||||
#define PL_COND_ACCESSORY_MASK \
|
||||
(PL_COND_FLAG_SPINDLE_CW | PL_COND_FLAG_SPINDLE_CCW | PL_COND_FLAG_COOLANT_FLOOD | PL_COND_FLAG_COOLANT_MIST)
|
||||
|
||||
// This struct stores a linear movement of a g-code block motion with its critical "nominal" values
|
||||
// are as specified in the source g-code.
|
||||
|
|
@ -61,9 +60,9 @@ typedef struct {
|
|||
|
||||
// Block condition data to ensure correct execution depending on states and overrides.
|
||||
uint8_t condition; // Block bitflag variable defining block run conditions. Copied from pl_line_data.
|
||||
#ifdef USE_LINE_NUMBERS
|
||||
#ifdef USE_LINE_NUMBERS
|
||||
int32_t line_number; // Block line number for real-time reporting. Copied from pl_line_data.
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// Fields used by the motion planner to manage acceleration. Some of these values may be updated
|
||||
// by the stepper module during execution of special motion cases for replanning purposes.
|
||||
|
|
@ -79,24 +78,22 @@ typedef struct {
|
|||
float rapid_rate; // Axis-limit adjusted maximum rate for this block direction in (mm/min)
|
||||
float programmed_rate; // Programmed rate of this block (mm/min).
|
||||
|
||||
#ifdef VARIABLE_SPINDLE
|
||||
#ifdef VARIABLE_SPINDLE
|
||||
// Stored spindle speed data used by spindle overrides and resuming methods.
|
||||
float spindle_speed; // Block spindle speed. Copied from pl_line_data.
|
||||
#endif
|
||||
#endif
|
||||
} plan_block_t;
|
||||
|
||||
|
||||
// Planner data prototype. Must be used when passing new motions to the planner.
|
||||
typedef struct {
|
||||
float feed_rate; // Desired feed rate for line motion. Value is ignored, if rapid motion.
|
||||
float spindle_speed; // Desired spindle speed through line motion.
|
||||
uint8_t condition; // Bitflag variable to indicate planner conditions. See defines above.
|
||||
#ifdef USE_LINE_NUMBERS
|
||||
#ifdef USE_LINE_NUMBERS
|
||||
int32_t line_number; // Desired line number to report when executing.
|
||||
#endif
|
||||
#endif
|
||||
} plan_line_data_t;
|
||||
|
||||
|
||||
// Initialize and reset the motion plan subsystem
|
||||
void plan_reset(); // Reset all
|
||||
void plan_reset_buffer(); // Reset buffer only.
|
||||
|
|
@ -146,5 +143,4 @@ uint8_t plan_check_full_buffer();
|
|||
|
||||
void plan_get_planner_mpos(float *target);
|
||||
|
||||
|
||||
#endif
|
||||
|
|
|
|||
73
grbl/print.c
73
grbl/print.c
|
|
@ -21,23 +21,16 @@
|
|||
|
||||
#include "grbl.h"
|
||||
|
||||
|
||||
void printString(const char *s)
|
||||
{
|
||||
while (*s)
|
||||
serial_write(*s++);
|
||||
void printString(const char *s) {
|
||||
while (*s) serial_write(*s++);
|
||||
}
|
||||
|
||||
|
||||
// Print a string stored in PGM-memory
|
||||
void printPgmString(const char *s)
|
||||
{
|
||||
void printPgmString(const char *s) {
|
||||
char c;
|
||||
while ((c = pgm_read_byte_near(s++)))
|
||||
serial_write(c);
|
||||
while ((c = pgm_read_byte_near(s++))) serial_write(c);
|
||||
}
|
||||
|
||||
|
||||
// void printIntegerInBase(unsigned long n, unsigned long base)
|
||||
// {
|
||||
// unsigned char buf[8 * sizeof(long)]; // Assumes 8-bit chars.
|
||||
|
|
@ -59,10 +52,8 @@ void printPgmString(const char *s)
|
|||
// 'A' + buf[i - 1] - 10);
|
||||
// }
|
||||
|
||||
|
||||
// Prints an uint8 variable in base 10.
|
||||
void print_uint8_base10(uint8_t n)
|
||||
{
|
||||
void print_uint8_base10(uint8_t n) {
|
||||
uint8_t digit_a = 0;
|
||||
uint8_t digit_b = 0;
|
||||
if (n >= 100) { // 100-255
|
||||
|
|
@ -74,28 +65,28 @@ void print_uint8_base10(uint8_t n)
|
|||
n /= 10;
|
||||
}
|
||||
serial_write('0' + n);
|
||||
if (digit_b) { serial_write(digit_b); }
|
||||
if (digit_a) { serial_write(digit_a); }
|
||||
if (digit_b) {
|
||||
serial_write(digit_b);
|
||||
}
|
||||
if (digit_a) {
|
||||
serial_write(digit_a);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Prints an uint8 variable in base 2 with desired number of desired digits.
|
||||
void print_uint8_base2_ndigit(uint8_t n, uint8_t digits) {
|
||||
unsigned char buf[digits];
|
||||
uint8_t i = 0;
|
||||
|
||||
for (; i < digits; i++) {
|
||||
buf[i] = n % 2 ;
|
||||
buf[i] = n % 2;
|
||||
n /= 2;
|
||||
}
|
||||
|
||||
for (; i > 0; i--)
|
||||
serial_write('0' + buf[i - 1]);
|
||||
for (; i > 0; i--) serial_write('0' + buf[i - 1]);
|
||||
}
|
||||
|
||||
|
||||
void print_uint32_base10(uint32_t n)
|
||||
{
|
||||
void print_uint32_base10(uint32_t n) {
|
||||
if (n == 0) {
|
||||
serial_write('0');
|
||||
return;
|
||||
|
|
@ -109,13 +100,10 @@ void print_uint32_base10(uint32_t n)
|
|||
n /= 10;
|
||||
}
|
||||
|
||||
for (; i > 0; i--)
|
||||
serial_write('0' + buf[i-1]);
|
||||
for (; i > 0; i--) serial_write('0' + buf[i - 1]);
|
||||
}
|
||||
|
||||
|
||||
void printInteger(long n)
|
||||
{
|
||||
void printInteger(long n) {
|
||||
if (n < 0) {
|
||||
serial_write('-');
|
||||
print_uint32_base10(-n);
|
||||
|
|
@ -124,14 +112,12 @@ void printInteger(long n)
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
// Convert float to string by immediately converting to a long integer, which contains
|
||||
// more digits than a float. Number of decimal places, which are tracked by a counter,
|
||||
// may be set by the user. The integer is then efficiently converted to a string.
|
||||
// NOTE: AVR '%' and '/' integer operations are very efficient. Bitshifting speed-up
|
||||
// techniques are actually just slightly slower. Found this out the hard way.
|
||||
void printFloat(float n, uint8_t decimal_places)
|
||||
{
|
||||
void printFloat(float n, uint8_t decimal_places) {
|
||||
if (n < 0) {
|
||||
serial_write('-');
|
||||
n = -n;
|
||||
|
|
@ -142,14 +128,16 @@ void printFloat(float n, uint8_t decimal_places)
|
|||
n *= 100;
|
||||
decimals -= 2;
|
||||
}
|
||||
if (decimals) { n *= 10; }
|
||||
if (decimals) {
|
||||
n *= 10;
|
||||
}
|
||||
n += 0.5; // Add rounding factor. Ensures carryover through entire value.
|
||||
|
||||
// Generate digits backwards and store in string.
|
||||
unsigned char buf[13];
|
||||
uint8_t i = 0;
|
||||
uint32_t a = (long)n;
|
||||
while(a > 0) {
|
||||
while (a > 0) {
|
||||
buf[i++] = (a % 10) + '0'; // Get digit
|
||||
a /= 10;
|
||||
}
|
||||
|
|
@ -162,29 +150,30 @@ void printFloat(float n, uint8_t decimal_places)
|
|||
|
||||
// Print the generated string.
|
||||
for (; i > 0; i--) {
|
||||
if (i == decimal_places) { serial_write('.'); } // Insert decimal point in right place.
|
||||
serial_write(buf[i-1]);
|
||||
if (i == decimal_places) {
|
||||
serial_write('.');
|
||||
} // Insert decimal point in right place.
|
||||
serial_write(buf[i - 1]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Floating value printing handlers for special variables types used in Grbl and are defined
|
||||
// in the config.h.
|
||||
// - CoordValue: Handles all position or coordinate values in inches or mm reporting.
|
||||
// - RateValue: Handles feed rate and current velocity in inches or mm reporting.
|
||||
void printFloat_CoordValue(float n) {
|
||||
if (bit_istrue(settings.flags,BITFLAG_REPORT_INCHES)) {
|
||||
printFloat(n*INCH_PER_MM,N_DECIMAL_COORDVALUE_INCH);
|
||||
if (bit_istrue(settings.flags, BITFLAG_REPORT_INCHES)) {
|
||||
printFloat(n * INCH_PER_MM, N_DECIMAL_COORDVALUE_INCH);
|
||||
} else {
|
||||
printFloat(n,N_DECIMAL_COORDVALUE_MM);
|
||||
printFloat(n, N_DECIMAL_COORDVALUE_MM);
|
||||
}
|
||||
}
|
||||
|
||||
void printFloat_RateValue(float n) {
|
||||
if (bit_istrue(settings.flags,BITFLAG_REPORT_INCHES)) {
|
||||
printFloat(n*INCH_PER_MM,N_DECIMAL_RATEVALUE_INCH);
|
||||
if (bit_istrue(settings.flags, BITFLAG_REPORT_INCHES)) {
|
||||
printFloat(n * INCH_PER_MM, N_DECIMAL_RATEVALUE_INCH);
|
||||
} else {
|
||||
printFloat(n,N_DECIMAL_RATEVALUE_MM);
|
||||
printFloat(n, N_DECIMAL_RATEVALUE_MM);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -22,7 +22,6 @@
|
|||
#ifndef print_h
|
||||
#define print_h
|
||||
|
||||
|
||||
void printString(const char *s);
|
||||
|
||||
void printPgmString(const char *s);
|
||||
|
|
|
|||
32
grbl/probe.c
32
grbl/probe.c
|
|
@ -20,44 +20,42 @@
|
|||
|
||||
#include "grbl.h"
|
||||
|
||||
|
||||
// Inverts the probe pin state depending on user settings and probing cycle mode.
|
||||
uint8_t probe_invert_mask;
|
||||
|
||||
|
||||
// Probe pin initialization routine.
|
||||
void probe_init()
|
||||
{
|
||||
void probe_init() {
|
||||
PROBE_DDR &= ~(PROBE_MASK); // Configure as input pins
|
||||
#ifdef DISABLE_PROBE_PIN_PULL_UP
|
||||
#ifdef DISABLE_PROBE_PIN_PULL_UP
|
||||
PROBE_PORT &= ~(PROBE_MASK); // Normal low operation. Requires external pull-down.
|
||||
#else
|
||||
#else
|
||||
PROBE_PORT |= PROBE_MASK; // Enable internal pull-up resistors. Normal high operation.
|
||||
#endif
|
||||
#endif
|
||||
probe_configure_invert_mask(false); // Initialize invert mask.
|
||||
}
|
||||
|
||||
|
||||
// Called by probe_init() and the mc_probe() routines. Sets up the probe pin invert mask to
|
||||
// appropriately set the pin logic according to setting for normal-high/normal-low operation
|
||||
// and the probing cycle modes for toward-workpiece/away-from-workpiece.
|
||||
void probe_configure_invert_mask(uint8_t is_probe_away)
|
||||
{
|
||||
void probe_configure_invert_mask(uint8_t is_probe_away) {
|
||||
probe_invert_mask = 0; // Initialize as zero.
|
||||
if (bit_isfalse(settings.flags,BITFLAG_INVERT_PROBE_PIN)) { probe_invert_mask ^= PROBE_MASK; }
|
||||
if (is_probe_away) { probe_invert_mask ^= PROBE_MASK; }
|
||||
if (bit_isfalse(settings.flags, BITFLAG_INVERT_PROBE_PIN)) {
|
||||
probe_invert_mask ^= PROBE_MASK;
|
||||
}
|
||||
if (is_probe_away) {
|
||||
probe_invert_mask ^= PROBE_MASK;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Returns the probe pin state. Triggered = true. Called by gcode parser and probe state monitor.
|
||||
uint8_t probe_get_state() { return((PROBE_PIN & PROBE_MASK) ^ probe_invert_mask); }
|
||||
|
||||
uint8_t probe_get_state() {
|
||||
return ((PROBE_PIN & PROBE_MASK) ^ probe_invert_mask);
|
||||
}
|
||||
|
||||
// Monitors probe pin state and records the system position when detected. Called by the
|
||||
// stepper ISR per ISR tick.
|
||||
// NOTE: This function must be extremely efficient as to not bog down the stepper ISR.
|
||||
void probe_state_monitor()
|
||||
{
|
||||
void probe_state_monitor() {
|
||||
if (probe_get_state()) {
|
||||
sys_probe_state = PROBE_OFF;
|
||||
memcpy(sys_probe_position, sys_position, sizeof(sys_position));
|
||||
|
|
|
|||
430
grbl/protocol.c
430
grbl/protocol.c
|
|
@ -26,26 +26,23 @@
|
|||
#define LINE_FLAG_COMMENT_PARENTHESES bit(1)
|
||||
#define LINE_FLAG_COMMENT_SEMICOLON bit(2)
|
||||
|
||||
|
||||
static char line[LINE_BUFFER_SIZE]; // Line to be executed. Zero-terminated.
|
||||
|
||||
static void protocol_exec_rt_suspend();
|
||||
|
||||
|
||||
/*
|
||||
GRBL PRIMARY LOOP:
|
||||
*/
|
||||
void protocol_main_loop()
|
||||
{
|
||||
// Perform some machine checks to make sure everything is good to go.
|
||||
#ifdef CHECK_LIMITS_AT_INIT
|
||||
void protocol_main_loop() {
|
||||
// Perform some machine checks to make sure everything is good to go.
|
||||
#ifdef CHECK_LIMITS_AT_INIT
|
||||
if (bit_istrue(settings.flags, BITFLAG_HARD_LIMIT_ENABLE)) {
|
||||
if (limits_get_state()) {
|
||||
sys.state = STATE_ALARM; // Ensure alarm state is active.
|
||||
report_feedback_message(MESSAGE_CHECK_LIMITS);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
// Check for and report alarm state after a reset, error, or an initial power up.
|
||||
// NOTE: Sleep mode disables the stepper drivers and position can't be guaranteed.
|
||||
// Re-initialize the sleep state as an ALARM mode to ensure user homes or acknowledges.
|
||||
|
|
@ -75,16 +72,18 @@ void protocol_main_loop()
|
|||
|
||||
// Process one line of incoming serial data, as the data becomes available. Performs an
|
||||
// initial filtering by removing spaces and comments and capitalizing all letters.
|
||||
while((c = serial_read()) != SERIAL_NO_DATA) {
|
||||
while ((c = serial_read()) != SERIAL_NO_DATA) {
|
||||
if ((c == '\n') || (c == '\r')) { // End of line reached
|
||||
|
||||
protocol_execute_realtime(); // Runtime command check point.
|
||||
if (sys.abort) { return; } // Bail to calling function upon system abort
|
||||
if (sys.abort) {
|
||||
return;
|
||||
} // Bail to calling function upon system abort
|
||||
|
||||
line[char_counter] = 0; // Set string termination character.
|
||||
#ifdef REPORT_ECHO_LINE_RECEIVED
|
||||
#ifdef REPORT_ECHO_LINE_RECEIVED
|
||||
report_echo_line_received(line);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// Direct and execute one line of formatted input, and report status of execution.
|
||||
if (line_flags & LINE_FLAG_OVERFLOW) {
|
||||
|
|
@ -114,7 +113,9 @@ void protocol_main_loop()
|
|||
// Throw away all (except EOL) comment characters and overflow characters.
|
||||
if (c == ')') {
|
||||
// End of '()' comment. Resume line allowed.
|
||||
if (line_flags & LINE_FLAG_COMMENT_PARENTHESES) { line_flags &= ~(LINE_FLAG_COMMENT_PARENTHESES); }
|
||||
if (line_flags & LINE_FLAG_COMMENT_PARENTHESES) {
|
||||
line_flags &= ~(LINE_FLAG_COMMENT_PARENTHESES);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (c <= ' ') {
|
||||
|
|
@ -138,16 +139,15 @@ void protocol_main_loop()
|
|||
// where, during a program, the system auto-cycle start will continue to execute
|
||||
// everything until the next '%' sign. This will help fix resuming issues with certain
|
||||
// functions that empty the planner buffer to execute its task on-time.
|
||||
} else if (char_counter >= (LINE_BUFFER_SIZE-1)) {
|
||||
} else if (char_counter >= (LINE_BUFFER_SIZE - 1)) {
|
||||
// Detect line buffer overflow and set flag.
|
||||
line_flags |= LINE_FLAG_OVERFLOW;
|
||||
} else if (c >= 'a' && c <= 'z') { // Upcase lowercase
|
||||
line[char_counter++] = c-'a'+'A';
|
||||
line[char_counter++] = c - 'a' + 'A';
|
||||
} else {
|
||||
line[char_counter++] = c;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -157,40 +157,39 @@ void protocol_main_loop()
|
|||
protocol_auto_cycle_start();
|
||||
|
||||
protocol_execute_realtime(); // Runtime command check point.
|
||||
if (sys.abort) { return; } // Bail to main() program loop to reset system.
|
||||
if (sys.abort) {
|
||||
return;
|
||||
} // Bail to main() program loop to reset system.
|
||||
}
|
||||
|
||||
return; /* Never reached */
|
||||
}
|
||||
|
||||
|
||||
// Block until all buffered steps are executed or in a cycle state. Works with feed hold
|
||||
// during a synchronize call, if it should happen. Also, waits for clean cycle end.
|
||||
void protocol_buffer_synchronize()
|
||||
{
|
||||
void protocol_buffer_synchronize() {
|
||||
// If system is queued, ensure cycle resumes if the auto start flag is present.
|
||||
protocol_auto_cycle_start();
|
||||
do {
|
||||
protocol_execute_realtime(); // Check and execute run-time commands
|
||||
if (sys.abort) { return; } // Check for system abort
|
||||
if (sys.abort) {
|
||||
return;
|
||||
} // Check for system abort
|
||||
} while (plan_get_current_block() || (sys.state == STATE_CYCLE));
|
||||
}
|
||||
|
||||
|
||||
// Auto-cycle start triggers when there is a motion ready to execute and if the main program is not
|
||||
// actively parsing commands.
|
||||
// NOTE: This function is called from the main loop, buffer sync, and mc_line() only and executes
|
||||
// when one of these conditions exist respectively: There are no more blocks sent (i.e. streaming
|
||||
// is finished, single commands), a command that needs to wait for the motions in the buffer to
|
||||
// execute calls a buffer sync, or the planner buffer is full and ready to go.
|
||||
void protocol_auto_cycle_start()
|
||||
{
|
||||
void protocol_auto_cycle_start() {
|
||||
if (plan_get_current_block() != NULL) { // Check if there are any blocks in the buffer.
|
||||
system_set_exec_state_flag(EXEC_CYCLE_START); // If so, execute them!
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// This function is the general interface to Grbl's real-time command execution system. It is called
|
||||
// from various check points in the main program, primarily where there may be a while loop waiting
|
||||
// for a buffer to clear space or any point where the execution time from the last check point may
|
||||
|
|
@ -202,18 +201,17 @@ void protocol_auto_cycle_start()
|
|||
// the same task, such as the planner recalculating the buffer upon a feedhold or overrides.
|
||||
// NOTE: The sys_rt_exec_state variable flags are set by any process, step or serial interrupts, pinouts,
|
||||
// limit switches, or the main program.
|
||||
void protocol_execute_realtime()
|
||||
{
|
||||
void protocol_execute_realtime() {
|
||||
protocol_exec_rt_system();
|
||||
if (sys.suspend) { protocol_exec_rt_suspend(); }
|
||||
if (sys.suspend) {
|
||||
protocol_exec_rt_suspend();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Executes run-time commands, when required. This function primarily operates as Grbl's state
|
||||
// machine and controls the various real-time features Grbl has to offer.
|
||||
// NOTE: Do not alter this unless you know exactly what you are doing!
|
||||
void protocol_exec_rt_system()
|
||||
{
|
||||
void protocol_exec_rt_system() {
|
||||
uint8_t rt_exec; // Temp variable to avoid calling volatile multiple times.
|
||||
rt_exec = sys_rt_exec_alarm; // Copy volatile sys_rt_exec_alarm.
|
||||
if (rt_exec) { // Enter only if any bit flag is true
|
||||
|
|
@ -232,7 +230,7 @@ void protocol_exec_rt_system()
|
|||
// the user and a GUI time to do what is needed before resetting, like killing the
|
||||
// incoming stream. The same could be said about soft limits. While the position is not
|
||||
// lost, continued streaming could cause a serious crash if by chance it gets executed.
|
||||
} while (bit_isfalse(sys_rt_exec_state,EXEC_RESET));
|
||||
} while (bit_isfalse(sys_rt_exec_state, EXEC_RESET));
|
||||
}
|
||||
system_clear_exec_alarm(); // Clear alarm
|
||||
}
|
||||
|
|
@ -265,26 +263,34 @@ void protocol_exec_rt_system()
|
|||
st_update_plan_block_parameters(); // Notify stepper module to recompute for hold deceleration.
|
||||
sys.step_control = STEP_CONTROL_EXECUTE_HOLD; // Initiate suspend state with active flag.
|
||||
if (sys.state == STATE_JOG) { // Jog cancelled upon any hold event, except for sleeping.
|
||||
if (!(rt_exec & EXEC_SLEEP)) { sys.suspend |= SUSPEND_JOG_CANCEL; }
|
||||
if (!(rt_exec & EXEC_SLEEP)) {
|
||||
sys.suspend |= SUSPEND_JOG_CANCEL;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// If IDLE, Grbl is not in motion. Simply indicate suspend state and hold is complete.
|
||||
if (sys.state == STATE_IDLE) { sys.suspend = SUSPEND_HOLD_COMPLETE; }
|
||||
if (sys.state == STATE_IDLE) {
|
||||
sys.suspend = SUSPEND_HOLD_COMPLETE;
|
||||
}
|
||||
|
||||
// Execute and flag a motion cancel with deceleration and return to idle. Used primarily by probing cycle
|
||||
// to halt and cancel the remainder of the motion.
|
||||
// Execute and flag a motion cancel with deceleration and return to idle. Used primarily by probing
|
||||
// cycle to halt and cancel the remainder of the motion.
|
||||
if (rt_exec & EXEC_MOTION_CANCEL) {
|
||||
// MOTION_CANCEL only occurs during a CYCLE, but a HOLD and SAFETY_DOOR may been initiated beforehand
|
||||
// to hold the CYCLE. Motion cancel is valid for a single planner block motion only, while jog cancel
|
||||
// will handle and clear multiple planner block motions.
|
||||
if (!(sys.state & STATE_JOG)) { sys.suspend |= SUSPEND_MOTION_CANCEL; } // NOTE: State is STATE_CYCLE.
|
||||
// MOTION_CANCEL only occurs during a CYCLE, but a HOLD and SAFETY_DOOR may been initiated
|
||||
// beforehand to hold the CYCLE. Motion cancel is valid for a single planner block motion only,
|
||||
// while jog cancel will handle and clear multiple planner block motions.
|
||||
if (!(sys.state & STATE_JOG)) {
|
||||
sys.suspend |= SUSPEND_MOTION_CANCEL;
|
||||
} // NOTE: State is STATE_CYCLE.
|
||||
}
|
||||
|
||||
// Execute a feed hold with deceleration, if required. Then, suspend system.
|
||||
if (rt_exec & EXEC_FEED_HOLD) {
|
||||
// Block SAFETY_DOOR, JOG, and SLEEP states from changing to HOLD state.
|
||||
if (!(sys.state & (STATE_SAFETY_DOOR | STATE_JOG | STATE_SLEEP))) { sys.state = STATE_HOLD; }
|
||||
if (!(sys.state & (STATE_SAFETY_DOOR | STATE_JOG | STATE_SLEEP))) {
|
||||
sys.state = STATE_HOLD;
|
||||
}
|
||||
}
|
||||
|
||||
// Execute a safety door stop with a feed hold and disable spindle/coolant.
|
||||
|
|
@ -298,29 +304,34 @@ void protocol_exec_rt_system()
|
|||
// already retracting, parked or in sleep state.
|
||||
if (sys.state == STATE_SAFETY_DOOR) {
|
||||
if (sys.suspend & SUSPEND_INITIATE_RESTORE) { // Actively restoring
|
||||
#ifdef PARKING_ENABLE
|
||||
#ifdef PARKING_ENABLE
|
||||
// Set hold and reset appropriate control flags to restart parking sequence.
|
||||
if (sys.step_control & STEP_CONTROL_EXECUTE_SYS_MOTION) {
|
||||
st_update_plan_block_parameters(); // Notify stepper module to recompute for hold deceleration.
|
||||
st_update_plan_block_parameters(); // Notify stepper module to recompute for hold
|
||||
// deceleration.
|
||||
sys.step_control = (STEP_CONTROL_EXECUTE_HOLD | STEP_CONTROL_EXECUTE_SYS_MOTION);
|
||||
sys.suspend &= ~(SUSPEND_HOLD_COMPLETE);
|
||||
} // else NO_MOTION is active.
|
||||
#endif
|
||||
sys.suspend &= ~(SUSPEND_RETRACT_COMPLETE | SUSPEND_INITIATE_RESTORE | SUSPEND_RESTORE_COMPLETE);
|
||||
#endif
|
||||
sys.suspend &=
|
||||
~(SUSPEND_RETRACT_COMPLETE | SUSPEND_INITIATE_RESTORE | SUSPEND_RESTORE_COMPLETE);
|
||||
sys.suspend |= SUSPEND_RESTART_RETRACT;
|
||||
}
|
||||
}
|
||||
if (sys.state != STATE_SLEEP) { sys.state = STATE_SAFETY_DOOR; }
|
||||
if (sys.state != STATE_SLEEP) {
|
||||
sys.state = STATE_SAFETY_DOOR;
|
||||
}
|
||||
// NOTE: This flag doesn't change when the door closes, unlike sys.state. Ensures any parking motions
|
||||
// are executed if the door switch closes and the state returns to HOLD.
|
||||
}
|
||||
// NOTE: This flag doesn't change when the door closes, unlike sys.state. Ensures any parking
|
||||
// motions are executed if the door switch closes and the state returns to HOLD.
|
||||
sys.suspend |= SUSPEND_SAFETY_DOOR_AJAR;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (rt_exec & EXEC_SLEEP) {
|
||||
if (sys.state == STATE_ALARM) { sys.suspend |= (SUSPEND_RETRACT_COMPLETE|SUSPEND_HOLD_COMPLETE); }
|
||||
if (sys.state == STATE_ALARM) {
|
||||
sys.suspend |= (SUSPEND_RETRACT_COMPLETE | SUSPEND_HOLD_COMPLETE);
|
||||
}
|
||||
sys.state = STATE_SLEEP;
|
||||
}
|
||||
|
||||
|
|
@ -337,22 +348,24 @@ void protocol_exec_rt_system()
|
|||
if (sys.suspend & SUSPEND_RESTORE_COMPLETE) {
|
||||
sys.state = STATE_IDLE; // Set to IDLE to immediately resume the cycle.
|
||||
} else if (sys.suspend & SUSPEND_RETRACT_COMPLETE) {
|
||||
// Flag to re-energize powered components and restore original position, if disabled by SAFETY_DOOR.
|
||||
// NOTE: For a safety door to resume, the switch must be closed, as indicated by HOLD state, and
|
||||
// the retraction execution is complete, which implies the initial feed hold is not active. To
|
||||
// restore normal operation, the restore procedures must be initiated by the following flag. Once,
|
||||
// they are complete, it will call CYCLE_START automatically to resume and exit the suspend.
|
||||
// Flag to re-energize powered components and restore original position, if disabled by
|
||||
// SAFETY_DOOR. NOTE: For a safety door to resume, the switch must be closed, as indicated by
|
||||
// HOLD state, and the retraction execution is complete, which implies the initial feed hold is
|
||||
// not active. To restore normal operation, the restore procedures must be initiated by the
|
||||
// following flag. Once, they are complete, it will call CYCLE_START automatically to resume and
|
||||
// exit the suspend.
|
||||
sys.suspend |= SUSPEND_INITIATE_RESTORE;
|
||||
}
|
||||
}
|
||||
// Cycle start only when IDLE or when a hold is complete and ready to resume.
|
||||
if ((sys.state == STATE_IDLE) || ((sys.state & STATE_HOLD) && (sys.suspend & SUSPEND_HOLD_COMPLETE))) {
|
||||
if (sys.state == STATE_HOLD && sys.spindle_stop_ovr) {
|
||||
sys.spindle_stop_ovr |= SPINDLE_STOP_OVR_RESTORE_CYCLE; // Set to restore in suspend routine and cycle start after.
|
||||
sys.spindle_stop_ovr |=
|
||||
SPINDLE_STOP_OVR_RESTORE_CYCLE; // Set to restore in suspend routine and cycle start after.
|
||||
} else {
|
||||
// Start cycle only if queued motions exist in planner buffer and the motion is not canceled.
|
||||
sys.step_control = STEP_CONTROL_NORMAL_OP; // Restore step control to normal operation
|
||||
if (plan_get_current_block() && bit_isfalse(sys.suspend,SUSPEND_MOTION_CANCEL)) {
|
||||
if (plan_get_current_block() && bit_isfalse(sys.suspend, SUSPEND_MOTION_CANCEL)) {
|
||||
sys.suspend = SUSPEND_DISABLE; // Break suspend state.
|
||||
sys.state = STATE_CYCLE;
|
||||
st_prep_buffer(); // Initialize step segment buffer before beginning cycle.
|
||||
|
|
@ -373,12 +386,15 @@ void protocol_exec_rt_system()
|
|||
// NOTE: Bresenham algorithm variables are still maintained through both the planner and stepper
|
||||
// cycle reinitializations. The stepper path should continue exactly as if nothing has happened.
|
||||
// NOTE: EXEC_CYCLE_STOP is set by the stepper subsystem when a cycle or feed hold completes.
|
||||
if ((sys.state & (STATE_HOLD|STATE_SAFETY_DOOR|STATE_SLEEP)) && !(sys.soft_limit) && !(sys.suspend & SUSPEND_JOG_CANCEL)) {
|
||||
if ((sys.state & (STATE_HOLD | STATE_SAFETY_DOOR | STATE_SLEEP)) && !(sys.soft_limit) &&
|
||||
!(sys.suspend & SUSPEND_JOG_CANCEL)) {
|
||||
// Hold complete. Set to indicate ready to resume. Remain in HOLD or DOOR states until user
|
||||
// has issued a resume command or reset.
|
||||
plan_cycle_reinitialize();
|
||||
if (sys.step_control & STEP_CONTROL_EXECUTE_HOLD) { sys.suspend |= SUSPEND_HOLD_COMPLETE; }
|
||||
bit_false(sys.step_control,(STEP_CONTROL_EXECUTE_HOLD | STEP_CONTROL_EXECUTE_SYS_MOTION));
|
||||
if (sys.step_control & STEP_CONTROL_EXECUTE_HOLD) {
|
||||
sys.suspend |= SUSPEND_HOLD_COMPLETE;
|
||||
}
|
||||
bit_false(sys.step_control, (STEP_CONTROL_EXECUTE_HOLD | STEP_CONTROL_EXECUTE_SYS_MOTION));
|
||||
} else {
|
||||
// Motion complete. Includes CYCLE/JOG/HOMING states and jog cancel/motion cancel/soft limit events.
|
||||
// NOTE: Motion and jog cancel both immediately return to idle after the hold completes.
|
||||
|
|
@ -408,18 +424,34 @@ void protocol_exec_rt_system()
|
|||
system_clear_exec_motion_overrides(); // Clear all motion override flags.
|
||||
|
||||
uint8_t new_f_override = sys.f_override;
|
||||
if (rt_exec & EXEC_FEED_OVR_RESET) { new_f_override = DEFAULT_FEED_OVERRIDE; }
|
||||
if (rt_exec & EXEC_FEED_OVR_COARSE_PLUS) { new_f_override += FEED_OVERRIDE_COARSE_INCREMENT; }
|
||||
if (rt_exec & EXEC_FEED_OVR_COARSE_MINUS) { new_f_override -= FEED_OVERRIDE_COARSE_INCREMENT; }
|
||||
if (rt_exec & EXEC_FEED_OVR_FINE_PLUS) { new_f_override += FEED_OVERRIDE_FINE_INCREMENT; }
|
||||
if (rt_exec & EXEC_FEED_OVR_FINE_MINUS) { new_f_override -= FEED_OVERRIDE_FINE_INCREMENT; }
|
||||
new_f_override = min(new_f_override,MAX_FEED_RATE_OVERRIDE);
|
||||
new_f_override = max(new_f_override,MIN_FEED_RATE_OVERRIDE);
|
||||
if (rt_exec & EXEC_FEED_OVR_RESET) {
|
||||
new_f_override = DEFAULT_FEED_OVERRIDE;
|
||||
}
|
||||
if (rt_exec & EXEC_FEED_OVR_COARSE_PLUS) {
|
||||
new_f_override += FEED_OVERRIDE_COARSE_INCREMENT;
|
||||
}
|
||||
if (rt_exec & EXEC_FEED_OVR_COARSE_MINUS) {
|
||||
new_f_override -= FEED_OVERRIDE_COARSE_INCREMENT;
|
||||
}
|
||||
if (rt_exec & EXEC_FEED_OVR_FINE_PLUS) {
|
||||
new_f_override += FEED_OVERRIDE_FINE_INCREMENT;
|
||||
}
|
||||
if (rt_exec & EXEC_FEED_OVR_FINE_MINUS) {
|
||||
new_f_override -= FEED_OVERRIDE_FINE_INCREMENT;
|
||||
}
|
||||
new_f_override = min(new_f_override, MAX_FEED_RATE_OVERRIDE);
|
||||
new_f_override = max(new_f_override, MIN_FEED_RATE_OVERRIDE);
|
||||
|
||||
uint8_t new_r_override = sys.r_override;
|
||||
if (rt_exec & EXEC_RAPID_OVR_RESET) { new_r_override = DEFAULT_RAPID_OVERRIDE; }
|
||||
if (rt_exec & EXEC_RAPID_OVR_MEDIUM) { new_r_override = RAPID_OVERRIDE_MEDIUM; }
|
||||
if (rt_exec & EXEC_RAPID_OVR_LOW) { new_r_override = RAPID_OVERRIDE_LOW; }
|
||||
if (rt_exec & EXEC_RAPID_OVR_RESET) {
|
||||
new_r_override = DEFAULT_RAPID_OVERRIDE;
|
||||
}
|
||||
if (rt_exec & EXEC_RAPID_OVR_MEDIUM) {
|
||||
new_r_override = RAPID_OVERRIDE_MEDIUM;
|
||||
}
|
||||
if (rt_exec & EXEC_RAPID_OVR_LOW) {
|
||||
new_r_override = RAPID_OVERRIDE_LOW;
|
||||
}
|
||||
|
||||
if ((new_f_override != sys.f_override) || (new_r_override != sys.r_override)) {
|
||||
sys.f_override = new_f_override;
|
||||
|
|
@ -436,19 +468,32 @@ void protocol_exec_rt_system()
|
|||
|
||||
// NOTE: Unlike motion overrides, spindle overrides do not require a planner reinitialization.
|
||||
uint8_t last_s_override = sys.spindle_speed_ovr;
|
||||
if (rt_exec & EXEC_SPINDLE_OVR_RESET) { last_s_override = DEFAULT_SPINDLE_SPEED_OVERRIDE; }
|
||||
if (rt_exec & EXEC_SPINDLE_OVR_COARSE_PLUS) { last_s_override += SPINDLE_OVERRIDE_COARSE_INCREMENT; }
|
||||
if (rt_exec & EXEC_SPINDLE_OVR_COARSE_MINUS) { last_s_override -= SPINDLE_OVERRIDE_COARSE_INCREMENT; }
|
||||
if (rt_exec & EXEC_SPINDLE_OVR_FINE_PLUS) { last_s_override += SPINDLE_OVERRIDE_FINE_INCREMENT; }
|
||||
if (rt_exec & EXEC_SPINDLE_OVR_FINE_MINUS) { last_s_override -= SPINDLE_OVERRIDE_FINE_INCREMENT; }
|
||||
last_s_override = min(last_s_override,MAX_SPINDLE_SPEED_OVERRIDE);
|
||||
last_s_override = max(last_s_override,MIN_SPINDLE_SPEED_OVERRIDE);
|
||||
if (rt_exec & EXEC_SPINDLE_OVR_RESET) {
|
||||
last_s_override = DEFAULT_SPINDLE_SPEED_OVERRIDE;
|
||||
}
|
||||
if (rt_exec & EXEC_SPINDLE_OVR_COARSE_PLUS) {
|
||||
last_s_override += SPINDLE_OVERRIDE_COARSE_INCREMENT;
|
||||
}
|
||||
if (rt_exec & EXEC_SPINDLE_OVR_COARSE_MINUS) {
|
||||
last_s_override -= SPINDLE_OVERRIDE_COARSE_INCREMENT;
|
||||
}
|
||||
if (rt_exec & EXEC_SPINDLE_OVR_FINE_PLUS) {
|
||||
last_s_override += SPINDLE_OVERRIDE_FINE_INCREMENT;
|
||||
}
|
||||
if (rt_exec & EXEC_SPINDLE_OVR_FINE_MINUS) {
|
||||
last_s_override -= SPINDLE_OVERRIDE_FINE_INCREMENT;
|
||||
}
|
||||
last_s_override = min(last_s_override, MAX_SPINDLE_SPEED_OVERRIDE);
|
||||
last_s_override = max(last_s_override, MIN_SPINDLE_SPEED_OVERRIDE);
|
||||
|
||||
if (last_s_override != sys.spindle_speed_ovr) {
|
||||
sys.spindle_speed_ovr = last_s_override;
|
||||
// NOTE: Spindle speed overrides during HOLD state are taken care of by suspend function.
|
||||
if (sys.state == STATE_IDLE) { spindle_set_state(gc_state.modal.spindle, gc_state.spindle_speed); }
|
||||
else { bit_true(sys.step_control, STEP_CONTROL_UPDATE_SPINDLE_PWM); }
|
||||
if (sys.state == STATE_IDLE) {
|
||||
spindle_set_state(gc_state.modal.spindle, gc_state.spindle_speed);
|
||||
} else {
|
||||
bit_true(sys.step_control, STEP_CONTROL_UPDATE_SPINDLE_PWM);
|
||||
}
|
||||
sys.report_ovr_counter = 0; // Set to report change immediately
|
||||
}
|
||||
|
||||
|
|
@ -456,8 +501,11 @@ void protocol_exec_rt_system()
|
|||
// Spindle stop override allowed only while in HOLD state.
|
||||
// NOTE: Report counters are set in spindle_set_state() when spindle stop is executed.
|
||||
if (sys.state == STATE_HOLD) {
|
||||
if (!(sys.spindle_stop_ovr)) { sys.spindle_stop_ovr = SPINDLE_STOP_OVR_INITIATE; }
|
||||
else if (sys.spindle_stop_ovr & SPINDLE_STOP_OVR_ENABLED) { sys.spindle_stop_ovr |= SPINDLE_STOP_OVR_RESTORE; }
|
||||
if (!(sys.spindle_stop_ovr)) {
|
||||
sys.spindle_stop_ovr = SPINDLE_STOP_OVR_INITIATE;
|
||||
} else if (sys.spindle_stop_ovr & SPINDLE_STOP_OVR_ENABLED) {
|
||||
sys.spindle_stop_ovr |= SPINDLE_STOP_OVR_RESTORE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -467,64 +515,70 @@ void protocol_exec_rt_system()
|
|||
if (rt_exec & (EXEC_COOLANT_FLOOD_OVR_TOGGLE | EXEC_COOLANT_MIST_OVR_TOGGLE)) {
|
||||
if ((sys.state == STATE_IDLE) || (sys.state & (STATE_CYCLE | STATE_HOLD | STATE_JOG))) {
|
||||
uint8_t coolant_state = gc_state.modal.coolant;
|
||||
#ifdef ENABLE_M7
|
||||
#ifdef ENABLE_M7
|
||||
if (rt_exec & EXEC_COOLANT_MIST_OVR_TOGGLE) {
|
||||
if (coolant_state & COOLANT_MIST_ENABLE) { bit_false(coolant_state,COOLANT_MIST_ENABLE); }
|
||||
else { coolant_state |= COOLANT_MIST_ENABLE; }
|
||||
if (coolant_state & COOLANT_MIST_ENABLE) {
|
||||
bit_false(coolant_state, COOLANT_MIST_ENABLE);
|
||||
} else {
|
||||
coolant_state |= COOLANT_MIST_ENABLE;
|
||||
}
|
||||
}
|
||||
if (rt_exec & EXEC_COOLANT_FLOOD_OVR_TOGGLE) {
|
||||
if (coolant_state & COOLANT_FLOOD_ENABLE) { bit_false(coolant_state,COOLANT_FLOOD_ENABLE); }
|
||||
else { coolant_state |= COOLANT_FLOOD_ENABLE; }
|
||||
if (coolant_state & COOLANT_FLOOD_ENABLE) {
|
||||
bit_false(coolant_state, COOLANT_FLOOD_ENABLE);
|
||||
} else {
|
||||
coolant_state |= COOLANT_FLOOD_ENABLE;
|
||||
}
|
||||
#else
|
||||
if (coolant_state & COOLANT_FLOOD_ENABLE) { bit_false(coolant_state,COOLANT_FLOOD_ENABLE); }
|
||||
else { coolant_state |= COOLANT_FLOOD_ENABLE; }
|
||||
#endif
|
||||
}
|
||||
#else
|
||||
if (coolant_state & COOLANT_FLOOD_ENABLE) {
|
||||
bit_false(coolant_state, COOLANT_FLOOD_ENABLE);
|
||||
} else {
|
||||
coolant_state |= COOLANT_FLOOD_ENABLE;
|
||||
}
|
||||
#endif
|
||||
coolant_set_state(coolant_state); // Report counter set in coolant_set_state().
|
||||
gc_state.modal.coolant = coolant_state;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
#ifdef DEBUG
|
||||
if (sys_rt_exec_debug) {
|
||||
report_realtime_debug();
|
||||
sys_rt_exec_debug = 0;
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// Reload step segment buffer
|
||||
if (sys.state & (STATE_CYCLE | STATE_HOLD | STATE_SAFETY_DOOR | STATE_HOMING | STATE_SLEEP| STATE_JOG)) {
|
||||
if (sys.state & (STATE_CYCLE | STATE_HOLD | STATE_SAFETY_DOOR | STATE_HOMING | STATE_SLEEP | STATE_JOG)) {
|
||||
st_prep_buffer();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
// Handles Grbl system suspend procedures, such as feed hold, safety door, and parking motion.
|
||||
// The system will enter this loop, create local variables for suspend tasks, and return to
|
||||
// whatever function that invoked the suspend, such that Grbl resumes normal operation.
|
||||
// This function is written in a way to promote custom parking motions. Simply use this as a
|
||||
// template
|
||||
static void protocol_exec_rt_suspend()
|
||||
{
|
||||
#ifdef PARKING_ENABLE
|
||||
static void protocol_exec_rt_suspend() {
|
||||
#ifdef PARKING_ENABLE
|
||||
// Declare and initialize parking local variables
|
||||
float restore_target[N_AXIS];
|
||||
float parking_target[N_AXIS];
|
||||
float retract_waypoint = PARKING_PULLOUT_INCREMENT;
|
||||
plan_line_data_t plan_data;
|
||||
plan_line_data_t *pl_data = &plan_data;
|
||||
memset(pl_data,0,sizeof(plan_line_data_t));
|
||||
pl_data->condition = (PL_COND_FLAG_SYSTEM_MOTION|PL_COND_FLAG_NO_FEED_OVERRIDE);
|
||||
#ifdef USE_LINE_NUMBERS
|
||||
memset(pl_data, 0, sizeof(plan_line_data_t));
|
||||
pl_data->condition = (PL_COND_FLAG_SYSTEM_MOTION | PL_COND_FLAG_NO_FEED_OVERRIDE);
|
||||
#ifdef USE_LINE_NUMBERS
|
||||
pl_data->line_number = PARKING_MOTION_LINE_NUMBER;
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
plan_block_t *block = plan_get_current_block();
|
||||
uint8_t restore_condition;
|
||||
#ifdef VARIABLE_SPINDLE
|
||||
#ifdef VARIABLE_SPINDLE
|
||||
float restore_spindle_speed;
|
||||
if (block == NULL) {
|
||||
restore_condition = (gc_state.modal.spindle | gc_state.modal.coolant);
|
||||
|
|
@ -533,19 +587,24 @@ static void protocol_exec_rt_suspend()
|
|||
restore_condition = (block->condition & PL_COND_SPINDLE_MASK) | coolant_get_state();
|
||||
restore_spindle_speed = block->spindle_speed;
|
||||
}
|
||||
#ifdef DISABLE_LASER_DURING_HOLD
|
||||
if (bit_istrue(settings.flags,BITFLAG_LASER_MODE)) {
|
||||
#ifdef DISABLE_LASER_DURING_HOLD
|
||||
if (bit_istrue(settings.flags, BITFLAG_LASER_MODE)) {
|
||||
system_set_exec_accessory_override_flag(EXEC_SPINDLE_OVR_STOP);
|
||||
}
|
||||
#endif
|
||||
#else
|
||||
if (block == NULL) { restore_condition = (gc_state.modal.spindle | gc_state.modal.coolant); }
|
||||
else { restore_condition = (block->condition & PL_COND_SPINDLE_MASK) | coolant_get_state(); }
|
||||
#endif
|
||||
#endif
|
||||
#else
|
||||
if (block == NULL) {
|
||||
restore_condition = (gc_state.modal.spindle | gc_state.modal.coolant);
|
||||
} else {
|
||||
restore_condition = (block->condition & PL_COND_SPINDLE_MASK) | coolant_get_state();
|
||||
}
|
||||
#endif
|
||||
|
||||
while (sys.suspend) {
|
||||
|
||||
if (sys.abort) { return; }
|
||||
if (sys.abort) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Block until initial hold is complete and the machine has stopped motion.
|
||||
if (sys.suspend & SUSPEND_HOLD_COMPLETE) {
|
||||
|
|
@ -555,53 +614,54 @@ static void protocol_exec_rt_suspend()
|
|||
if (sys.state & (STATE_SAFETY_DOOR | STATE_SLEEP)) {
|
||||
|
||||
// Handles retraction motions and de-energizing.
|
||||
if (bit_isfalse(sys.suspend,SUSPEND_RETRACT_COMPLETE)) {
|
||||
if (bit_isfalse(sys.suspend, SUSPEND_RETRACT_COMPLETE)) {
|
||||
|
||||
// Ensure any prior spindle stop override is disabled at start of safety door routine.
|
||||
sys.spindle_stop_ovr = SPINDLE_STOP_OVR_DISABLED;
|
||||
|
||||
#ifndef PARKING_ENABLE
|
||||
#ifndef PARKING_ENABLE
|
||||
|
||||
spindle_set_state(SPINDLE_DISABLE,0.0); // De-energize
|
||||
spindle_set_state(SPINDLE_DISABLE, 0.0); // De-energize
|
||||
coolant_set_state(COOLANT_DISABLE); // De-energize
|
||||
|
||||
#else
|
||||
#else
|
||||
|
||||
// Get current position and store restore location and spindle retract waypoint.
|
||||
system_convert_array_steps_to_mpos(parking_target,sys_position);
|
||||
if (bit_isfalse(sys.suspend,SUSPEND_RESTART_RETRACT)) {
|
||||
memcpy(restore_target,parking_target,sizeof(parking_target));
|
||||
system_convert_array_steps_to_mpos(parking_target, sys_position);
|
||||
if (bit_isfalse(sys.suspend, SUSPEND_RESTART_RETRACT)) {
|
||||
memcpy(restore_target, parking_target, sizeof(parking_target));
|
||||
retract_waypoint += restore_target[PARKING_AXIS];
|
||||
retract_waypoint = min(retract_waypoint,PARKING_TARGET);
|
||||
retract_waypoint = min(retract_waypoint, PARKING_TARGET);
|
||||
}
|
||||
|
||||
// Execute slow pull-out parking retract motion. Parking requires homing enabled, the
|
||||
// current location not exceeding the parking target location, and laser mode disabled.
|
||||
// NOTE: State is will remain DOOR, until the de-energizing and retract is complete.
|
||||
#ifdef ENABLE_PARKING_OVERRIDE_CONTROL
|
||||
if ((bit_istrue(settings.flags,BITFLAG_HOMING_ENABLE)) &&
|
||||
// Execute slow pull-out parking retract motion. Parking requires homing enabled, the
|
||||
// current location not exceeding the parking target location, and laser mode disabled.
|
||||
// NOTE: State is will remain DOOR, until the de-energizing and retract is complete.
|
||||
#ifdef ENABLE_PARKING_OVERRIDE_CONTROL
|
||||
if ((bit_istrue(settings.flags, BITFLAG_HOMING_ENABLE)) &&
|
||||
(parking_target[PARKING_AXIS] < PARKING_TARGET) &&
|
||||
bit_isfalse(settings.flags,BITFLAG_LASER_MODE) &&
|
||||
bit_isfalse(settings.flags, BITFLAG_LASER_MODE) &&
|
||||
(sys.override_ctrl == OVERRIDE_PARKING_MOTION)) {
|
||||
#else
|
||||
if ((bit_istrue(settings.flags,BITFLAG_HOMING_ENABLE)) &&
|
||||
#else
|
||||
if ((bit_istrue(settings.flags, BITFLAG_HOMING_ENABLE)) &&
|
||||
(parking_target[PARKING_AXIS] < PARKING_TARGET) &&
|
||||
bit_isfalse(settings.flags,BITFLAG_LASER_MODE)) {
|
||||
#endif
|
||||
bit_isfalse(settings.flags, BITFLAG_LASER_MODE)) {
|
||||
#endif
|
||||
// Retract spindle by pullout distance. Ensure retraction motion moves away from
|
||||
// the workpiece and waypoint motion doesn't exceed the parking target location.
|
||||
if (parking_target[PARKING_AXIS] < retract_waypoint) {
|
||||
parking_target[PARKING_AXIS] = retract_waypoint;
|
||||
pl_data->feed_rate = PARKING_PULLOUT_RATE;
|
||||
pl_data->condition |= (restore_condition & PL_COND_ACCESSORY_MASK); // Retain accessory state
|
||||
pl_data->condition |=
|
||||
(restore_condition & PL_COND_ACCESSORY_MASK); // Retain accessory state
|
||||
pl_data->spindle_speed = restore_spindle_speed;
|
||||
mc_parking_motion(parking_target, pl_data);
|
||||
}
|
||||
|
||||
// NOTE: Clear accessory state after retract and after an aborted restore motion.
|
||||
pl_data->condition = (PL_COND_FLAG_SYSTEM_MOTION|PL_COND_FLAG_NO_FEED_OVERRIDE);
|
||||
pl_data->condition = (PL_COND_FLAG_SYSTEM_MOTION | PL_COND_FLAG_NO_FEED_OVERRIDE);
|
||||
pl_data->spindle_speed = 0.0;
|
||||
spindle_set_state(SPINDLE_DISABLE,0.0); // De-energize
|
||||
spindle_set_state(SPINDLE_DISABLE, 0.0); // De-energize
|
||||
coolant_set_state(COOLANT_DISABLE); // De-energize
|
||||
|
||||
// Execute fast parking retract motion to parking target location.
|
||||
|
|
@ -615,48 +675,51 @@ static void protocol_exec_rt_suspend()
|
|||
|
||||
// Parking motion not possible. Just disable the spindle and coolant.
|
||||
// NOTE: Laser mode does not start a parking motion to ensure the laser stops immediately.
|
||||
spindle_set_state(SPINDLE_DISABLE,0.0); // De-energize
|
||||
spindle_set_state(SPINDLE_DISABLE, 0.0); // De-energize
|
||||
coolant_set_state(COOLANT_DISABLE); // De-energize
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
sys.suspend &= ~(SUSPEND_RESTART_RETRACT);
|
||||
sys.suspend |= SUSPEND_RETRACT_COMPLETE;
|
||||
|
||||
} else {
|
||||
|
||||
|
||||
if (sys.state == STATE_SLEEP) {
|
||||
report_feedback_message(MESSAGE_SLEEP_MODE);
|
||||
// Spindle and coolant should already be stopped, but do it again just to be sure.
|
||||
spindle_set_state(SPINDLE_DISABLE,0.0); // De-energize
|
||||
spindle_set_state(SPINDLE_DISABLE, 0.0); // De-energize
|
||||
coolant_set_state(COOLANT_DISABLE); // De-energize
|
||||
st_go_idle(); // Disable steppers
|
||||
while (!(sys.abort)) { protocol_exec_rt_system(); } // Do nothing until reset.
|
||||
while (!(sys.abort)) {
|
||||
protocol_exec_rt_system();
|
||||
} // Do nothing until reset.
|
||||
return; // Abort received. Return to re-initialize.
|
||||
}
|
||||
|
||||
// Allows resuming from parking/safety door. Actively checks if safety door is closed and ready to resume.
|
||||
// Allows resuming from parking/safety door. Actively checks if safety door is closed and ready to
|
||||
// resume.
|
||||
if (sys.state == STATE_SAFETY_DOOR) {
|
||||
if (!(system_check_safety_door_ajar())) {
|
||||
sys.suspend &= ~(SUSPEND_SAFETY_DOOR_AJAR); // Reset door ajar flag to denote ready to resume.
|
||||
sys.suspend &=
|
||||
~(SUSPEND_SAFETY_DOOR_AJAR); // Reset door ajar flag to denote ready to resume.
|
||||
}
|
||||
}
|
||||
|
||||
// Handles parking restore and safety door resume.
|
||||
if (sys.suspend & SUSPEND_INITIATE_RESTORE) {
|
||||
|
||||
#ifdef PARKING_ENABLE
|
||||
// Execute fast restore motion to the pull-out position. Parking requires homing enabled.
|
||||
// NOTE: State is will remain DOOR, until the de-energizing and retract is complete.
|
||||
#ifdef ENABLE_PARKING_OVERRIDE_CONTROL
|
||||
if (((settings.flags & (BITFLAG_HOMING_ENABLE|BITFLAG_LASER_MODE)) == BITFLAG_HOMING_ENABLE) &&
|
||||
#ifdef PARKING_ENABLE
|
||||
// Execute fast restore motion to the pull-out position. Parking requires homing enabled.
|
||||
// NOTE: State is will remain DOOR, until the de-energizing and retract is complete.
|
||||
#ifdef ENABLE_PARKING_OVERRIDE_CONTROL
|
||||
if (((settings.flags & (BITFLAG_HOMING_ENABLE | BITFLAG_LASER_MODE)) ==
|
||||
BITFLAG_HOMING_ENABLE) &&
|
||||
(sys.override_ctrl == OVERRIDE_PARKING_MOTION)) {
|
||||
#else
|
||||
if ((settings.flags & (BITFLAG_HOMING_ENABLE|BITFLAG_LASER_MODE)) == BITFLAG_HOMING_ENABLE) {
|
||||
#endif
|
||||
#else
|
||||
if ((settings.flags & (BITFLAG_HOMING_ENABLE | BITFLAG_LASER_MODE)) == BITFLAG_HOMING_ENABLE) {
|
||||
#endif
|
||||
// Check to ensure the motion doesn't move below pull-out position.
|
||||
if (parking_target[PARKING_AXIS] <= PARKING_TARGET) {
|
||||
parking_target[PARKING_AXIS] = retract_waypoint;
|
||||
|
|
@ -664,60 +727,65 @@ static void protocol_exec_rt_suspend()
|
|||
mc_parking_motion(parking_target, pl_data);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// Delayed Tasks: Restart spindle and coolant, delay to power-up, then resume cycle.
|
||||
if (gc_state.modal.spindle != SPINDLE_DISABLE) {
|
||||
// Block if safety door re-opened during prior restore actions.
|
||||
if (bit_isfalse(sys.suspend,SUSPEND_RESTART_RETRACT)) {
|
||||
if (bit_istrue(settings.flags,BITFLAG_LASER_MODE)) {
|
||||
// When in laser mode, ignore spindle spin-up delay. Set to turn on laser when cycle starts.
|
||||
if (bit_isfalse(sys.suspend, SUSPEND_RESTART_RETRACT)) {
|
||||
if (bit_istrue(settings.flags, BITFLAG_LASER_MODE)) {
|
||||
// When in laser mode, ignore spindle spin-up delay. Set to turn on laser when cycle
|
||||
// starts.
|
||||
bit_true(sys.step_control, STEP_CONTROL_UPDATE_SPINDLE_PWM);
|
||||
} else {
|
||||
spindle_set_state((restore_condition & (PL_COND_FLAG_SPINDLE_CW | PL_COND_FLAG_SPINDLE_CCW)), restore_spindle_speed);
|
||||
spindle_set_state(
|
||||
(restore_condition & (PL_COND_FLAG_SPINDLE_CW | PL_COND_FLAG_SPINDLE_CCW)),
|
||||
restore_spindle_speed);
|
||||
delay_sec(SAFETY_DOOR_SPINDLE_DELAY, DELAY_MODE_SYS_SUSPEND);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (gc_state.modal.coolant != COOLANT_DISABLE) {
|
||||
// Block if safety door re-opened during prior restore actions.
|
||||
if (bit_isfalse(sys.suspend,SUSPEND_RESTART_RETRACT)) {
|
||||
// NOTE: Laser mode will honor this delay. An exhaust system is often controlled by this pin.
|
||||
coolant_set_state((restore_condition & (PL_COND_FLAG_COOLANT_FLOOD | PL_COND_FLAG_COOLANT_MIST)));
|
||||
if (bit_isfalse(sys.suspend, SUSPEND_RESTART_RETRACT)) {
|
||||
// NOTE: Laser mode will honor this delay. An exhaust system is often controlled by this
|
||||
// pin.
|
||||
coolant_set_state(
|
||||
(restore_condition & (PL_COND_FLAG_COOLANT_FLOOD | PL_COND_FLAG_COOLANT_MIST)));
|
||||
delay_sec(SAFETY_DOOR_COOLANT_DELAY, DELAY_MODE_SYS_SUSPEND);
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef PARKING_ENABLE
|
||||
// Execute slow plunge motion from pull-out position to resume position.
|
||||
#ifdef ENABLE_PARKING_OVERRIDE_CONTROL
|
||||
if (((settings.flags & (BITFLAG_HOMING_ENABLE|BITFLAG_LASER_MODE)) == BITFLAG_HOMING_ENABLE) &&
|
||||
#ifdef PARKING_ENABLE
|
||||
// Execute slow plunge motion from pull-out position to resume position.
|
||||
#ifdef ENABLE_PARKING_OVERRIDE_CONTROL
|
||||
if (((settings.flags & (BITFLAG_HOMING_ENABLE | BITFLAG_LASER_MODE)) ==
|
||||
BITFLAG_HOMING_ENABLE) &&
|
||||
(sys.override_ctrl == OVERRIDE_PARKING_MOTION)) {
|
||||
#else
|
||||
if ((settings.flags & (BITFLAG_HOMING_ENABLE|BITFLAG_LASER_MODE)) == BITFLAG_HOMING_ENABLE) {
|
||||
#endif
|
||||
#else
|
||||
if ((settings.flags & (BITFLAG_HOMING_ENABLE | BITFLAG_LASER_MODE)) == BITFLAG_HOMING_ENABLE) {
|
||||
#endif
|
||||
// Block if safety door re-opened during prior restore actions.
|
||||
if (bit_isfalse(sys.suspend,SUSPEND_RESTART_RETRACT)) {
|
||||
if (bit_isfalse(sys.suspend, SUSPEND_RESTART_RETRACT)) {
|
||||
// Regardless if the retract parking motion was a valid/safe motion or not, the
|
||||
// restore parking motion should logically be valid, either by returning to the
|
||||
// original position through valid machine space or by not moving at all.
|
||||
pl_data->feed_rate = PARKING_PULLOUT_RATE;
|
||||
pl_data->condition |= (restore_condition & PL_COND_ACCESSORY_MASK); // Restore accessory state
|
||||
pl_data->condition |=
|
||||
(restore_condition & PL_COND_ACCESSORY_MASK); // Restore accessory state
|
||||
pl_data->spindle_speed = restore_spindle_speed;
|
||||
mc_parking_motion(restore_target, pl_data);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
if (bit_isfalse(sys.suspend,SUSPEND_RESTART_RETRACT)) {
|
||||
if (bit_isfalse(sys.suspend, SUSPEND_RESTART_RETRACT)) {
|
||||
sys.suspend |= SUSPEND_RESTORE_COMPLETE;
|
||||
system_set_exec_state_flag(EXEC_CYCLE_START); // Set to resume program.
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
} else {
|
||||
|
||||
// Feed hold manager. Controls spindle stop override states.
|
||||
|
|
@ -726,8 +794,9 @@ static void protocol_exec_rt_suspend()
|
|||
// Handles beginning of spindle stop
|
||||
if (sys.spindle_stop_ovr & SPINDLE_STOP_OVR_INITIATE) {
|
||||
if (gc_state.modal.spindle != SPINDLE_DISABLE) {
|
||||
spindle_set_state(SPINDLE_DISABLE,0.0); // De-energize
|
||||
sys.spindle_stop_ovr = SPINDLE_STOP_OVR_ENABLED; // Set stop override state to enabled, if de-energized.
|
||||
spindle_set_state(SPINDLE_DISABLE, 0.0); // De-energize
|
||||
sys.spindle_stop_ovr =
|
||||
SPINDLE_STOP_OVR_ENABLED; // Set stop override state to enabled, if de-energized.
|
||||
} else {
|
||||
sys.spindle_stop_ovr = SPINDLE_STOP_OVR_DISABLED; // Clear stop override state
|
||||
}
|
||||
|
|
@ -735,11 +804,14 @@ static void protocol_exec_rt_suspend()
|
|||
} else if (sys.spindle_stop_ovr & (SPINDLE_STOP_OVR_RESTORE | SPINDLE_STOP_OVR_RESTORE_CYCLE)) {
|
||||
if (gc_state.modal.spindle != SPINDLE_DISABLE) {
|
||||
report_feedback_message(MESSAGE_SPINDLE_RESTORE);
|
||||
if (bit_istrue(settings.flags,BITFLAG_LASER_MODE)) {
|
||||
// When in laser mode, ignore spindle spin-up delay. Set to turn on laser when cycle starts.
|
||||
if (bit_istrue(settings.flags, BITFLAG_LASER_MODE)) {
|
||||
// When in laser mode, ignore spindle spin-up delay. Set to turn on laser when cycle
|
||||
// starts.
|
||||
bit_true(sys.step_control, STEP_CONTROL_UPDATE_SPINDLE_PWM);
|
||||
} else {
|
||||
spindle_set_state((restore_condition & (PL_COND_FLAG_SPINDLE_CW | PL_COND_FLAG_SPINDLE_CCW)), restore_spindle_speed);
|
||||
spindle_set_state(
|
||||
(restore_condition & (PL_COND_FLAG_SPINDLE_CW | PL_COND_FLAG_SPINDLE_CCW)),
|
||||
restore_spindle_speed);
|
||||
}
|
||||
}
|
||||
if (sys.spindle_stop_ovr & SPINDLE_STOP_OVR_RESTORE_CYCLE) {
|
||||
|
|
@ -748,18 +820,18 @@ static void protocol_exec_rt_suspend()
|
|||
sys.spindle_stop_ovr = SPINDLE_STOP_OVR_DISABLED; // Clear stop override state
|
||||
}
|
||||
} else {
|
||||
// Handles spindle state during hold. NOTE: Spindle speed overrides may be altered during hold state.
|
||||
// NOTE: STEP_CONTROL_UPDATE_SPINDLE_PWM is automatically reset upon resume in step generator.
|
||||
// Handles spindle state during hold. NOTE: Spindle speed overrides may be altered during hold
|
||||
// state. NOTE: STEP_CONTROL_UPDATE_SPINDLE_PWM is automatically reset upon resume in step
|
||||
// generator.
|
||||
if (bit_istrue(sys.step_control, STEP_CONTROL_UPDATE_SPINDLE_PWM)) {
|
||||
spindle_set_state((restore_condition & (PL_COND_FLAG_SPINDLE_CW | PL_COND_FLAG_SPINDLE_CCW)), restore_spindle_speed);
|
||||
spindle_set_state((restore_condition & (PL_COND_FLAG_SPINDLE_CW | PL_COND_FLAG_SPINDLE_CCW)),
|
||||
restore_spindle_speed);
|
||||
bit_false(sys.step_control, STEP_CONTROL_UPDATE_SPINDLE_PWM);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
protocol_exec_rt_system();
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@
|
|||
// memory space we can invest into here or we re-write the g-code parser not to have this
|
||||
// buffer.
|
||||
#ifndef LINE_BUFFER_SIZE
|
||||
#define LINE_BUFFER_SIZE 80
|
||||
#define LINE_BUFFER_SIZE 80
|
||||
#endif
|
||||
|
||||
// Starts Grbl main loop. It handles all incoming characters from the serial port and executes
|
||||
|
|
|
|||
575
grbl/report.c
575
grbl/report.c
|
|
@ -28,19 +28,38 @@
|
|||
|
||||
#include "grbl.h"
|
||||
|
||||
|
||||
// Internal report utilities to reduce flash with repetitive tasks turned into functions.
|
||||
void report_util_setting_prefix(uint8_t n) { serial_write('$'); print_uint8_base10(n); serial_write('='); }
|
||||
static void report_util_line_feed() { printPgmString(PSTR("\r\n")); }
|
||||
static void report_util_feedback_line_feed() { serial_write(']'); report_util_line_feed(); }
|
||||
static void report_util_gcode_modes_G() { printPgmString(PSTR(" G")); }
|
||||
static void report_util_gcode_modes_M() { printPgmString(PSTR(" M")); }
|
||||
void report_util_setting_prefix(uint8_t n) {
|
||||
serial_write('$');
|
||||
print_uint8_base10(n);
|
||||
serial_write('=');
|
||||
}
|
||||
|
||||
static void report_util_line_feed() {
|
||||
printPgmString(PSTR("\r\n"));
|
||||
}
|
||||
|
||||
static void report_util_feedback_line_feed() {
|
||||
serial_write(']');
|
||||
report_util_line_feed();
|
||||
}
|
||||
|
||||
static void report_util_gcode_modes_G() {
|
||||
printPgmString(PSTR(" G"));
|
||||
}
|
||||
|
||||
static void report_util_gcode_modes_M() {
|
||||
printPgmString(PSTR(" M"));
|
||||
}
|
||||
|
||||
// static void report_util_comment_line_feed() { serial_write(')'); report_util_line_feed(); }
|
||||
static void report_util_axis_values(float *axis_value) {
|
||||
uint8_t idx;
|
||||
for (idx=0; idx<N_AXIS; idx++) {
|
||||
for (idx = 0; idx < N_AXIS; idx++) {
|
||||
printFloat_CoordValue(axis_value[idx]);
|
||||
if (idx < (N_AXIS-1)) { serial_write(','); }
|
||||
if (idx < (N_AXIS - 1)) {
|
||||
serial_write(',');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -96,24 +115,24 @@ static void report_util_uint8_setting(uint8_t n, int val) {
|
|||
print_uint8_base10(val);
|
||||
report_util_line_feed(); // report_util_setting_string(n);
|
||||
}
|
||||
|
||||
static void report_util_float_setting(uint8_t n, float val, uint8_t n_decimal) {
|
||||
report_util_setting_prefix(n);
|
||||
printFloat(val,n_decimal);
|
||||
printFloat(val, n_decimal);
|
||||
report_util_line_feed(); // report_util_setting_string(n);
|
||||
}
|
||||
|
||||
|
||||
// Handles the primary confirmation protocol response for streaming interfaces and human-feedback.
|
||||
// For every incoming line, this method responds with an 'ok' for a successful command or an
|
||||
// 'error:' to indicate some error event with the line or some critical system error during
|
||||
// operation. Errors events can originate from the g-code parser, settings module, or asynchronously
|
||||
// from a critical error, such as a triggered hard limit. Interface should always monitor for these
|
||||
// responses.
|
||||
void report_status_message(uint8_t status_code)
|
||||
{
|
||||
switch(status_code) {
|
||||
void report_status_message(uint8_t status_code) {
|
||||
switch (status_code) {
|
||||
case STATUS_OK: // STATUS_OK
|
||||
printPgmString(PSTR("ok\r\n")); break;
|
||||
printPgmString(PSTR("ok\r\n"));
|
||||
break;
|
||||
default:
|
||||
printPgmString(PSTR("error:"));
|
||||
print_uint8_base10(status_code);
|
||||
|
|
@ -122,8 +141,7 @@ void report_status_message(uint8_t status_code)
|
|||
}
|
||||
|
||||
// Prints alarm messages.
|
||||
void report_alarm_message(uint8_t alarm_code)
|
||||
{
|
||||
void report_alarm_message(uint8_t alarm_code) {
|
||||
printPgmString(PSTR("ALARM:"));
|
||||
print_uint8_base10(alarm_code);
|
||||
report_util_line_feed();
|
||||
|
|
@ -135,40 +153,26 @@ void report_alarm_message(uint8_t alarm_code)
|
|||
// messages such as setup warnings, switch toggling, and how to exit alarms.
|
||||
// NOTE: For interfaces, messages are always placed within brackets. And if silent mode
|
||||
// is installed, the message number codes are less than zero.
|
||||
void report_feedback_message(uint8_t message_code)
|
||||
{
|
||||
void report_feedback_message(uint8_t message_code) {
|
||||
printPgmString(PSTR("[MSG:"));
|
||||
switch(message_code) {
|
||||
case MESSAGE_CRITICAL_EVENT:
|
||||
printPgmString(PSTR("Reset to continue")); break;
|
||||
case MESSAGE_ALARM_LOCK:
|
||||
printPgmString(PSTR("'$H'|'$X' to unlock")); break;
|
||||
case MESSAGE_ALARM_UNLOCK:
|
||||
printPgmString(PSTR("Caution: Unlocked")); break;
|
||||
case MESSAGE_ENABLED:
|
||||
printPgmString(PSTR("Enabled")); break;
|
||||
case MESSAGE_DISABLED:
|
||||
printPgmString(PSTR("Disabled")); break;
|
||||
case MESSAGE_SAFETY_DOOR_AJAR:
|
||||
printPgmString(PSTR("Check Door")); break;
|
||||
case MESSAGE_CHECK_LIMITS:
|
||||
printPgmString(PSTR("Check Limits")); break;
|
||||
case MESSAGE_PROGRAM_END:
|
||||
printPgmString(PSTR("Pgm End")); break;
|
||||
case MESSAGE_RESTORE_DEFAULTS:
|
||||
printPgmString(PSTR("Restoring defaults")); break;
|
||||
case MESSAGE_SPINDLE_RESTORE:
|
||||
printPgmString(PSTR("Restoring spindle")); break;
|
||||
case MESSAGE_SLEEP_MODE:
|
||||
printPgmString(PSTR("Sleeping")); break;
|
||||
switch (message_code) {
|
||||
case MESSAGE_CRITICAL_EVENT: printPgmString(PSTR("Reset to continue")); break;
|
||||
case MESSAGE_ALARM_LOCK: printPgmString(PSTR("'$H'|'$X' to unlock")); break;
|
||||
case MESSAGE_ALARM_UNLOCK: printPgmString(PSTR("Caution: Unlocked")); break;
|
||||
case MESSAGE_ENABLED: printPgmString(PSTR("Enabled")); break;
|
||||
case MESSAGE_DISABLED: printPgmString(PSTR("Disabled")); break;
|
||||
case MESSAGE_SAFETY_DOOR_AJAR: printPgmString(PSTR("Check Door")); break;
|
||||
case MESSAGE_CHECK_LIMITS: printPgmString(PSTR("Check Limits")); break;
|
||||
case MESSAGE_PROGRAM_END: printPgmString(PSTR("Pgm End")); break;
|
||||
case MESSAGE_RESTORE_DEFAULTS: printPgmString(PSTR("Restoring defaults")); break;
|
||||
case MESSAGE_SPINDLE_RESTORE: printPgmString(PSTR("Restoring spindle")); break;
|
||||
case MESSAGE_SLEEP_MODE: printPgmString(PSTR("Sleeping")); break;
|
||||
}
|
||||
report_util_feedback_line_feed();
|
||||
}
|
||||
|
||||
|
||||
// Welcome message
|
||||
void report_init_message()
|
||||
{
|
||||
void report_init_message() {
|
||||
printPgmString(PSTR("\r\nGrbl " GRBL_VERSION " ['$' for help]\r\n"));
|
||||
}
|
||||
|
||||
|
|
@ -177,77 +181,74 @@ void report_grbl_help() {
|
|||
printPgmString(PSTR("[HLP:$$ $# $G $I $N $x=val $Nx=line $J=line $SLP $C $X $H ~ ! ? ctrl-x]\r\n"));
|
||||
}
|
||||
|
||||
|
||||
// Grbl global settings print out.
|
||||
// NOTE: The numbering scheme here must correlate to storing in settings.c
|
||||
void report_grbl_settings() {
|
||||
// Print Grbl settings.
|
||||
report_util_uint8_setting(0,settings.pulse_microseconds);
|
||||
report_util_uint8_setting(1,settings.stepper_idle_lock_time);
|
||||
report_util_uint8_setting(2,settings.step_invert_mask);
|
||||
report_util_uint8_setting(3,settings.dir_invert_mask);
|
||||
report_util_uint8_setting(4,bit_istrue(settings.flags,BITFLAG_INVERT_ST_ENABLE));
|
||||
report_util_uint8_setting(5,bit_istrue(settings.flags,BITFLAG_INVERT_LIMIT_PINS));
|
||||
report_util_uint8_setting(6,bit_istrue(settings.flags,BITFLAG_INVERT_PROBE_PIN));
|
||||
report_util_uint8_setting(10,settings.status_report_mask);
|
||||
report_util_float_setting(11,settings.junction_deviation,N_DECIMAL_SETTINGVALUE);
|
||||
report_util_float_setting(12,settings.arc_tolerance,N_DECIMAL_SETTINGVALUE);
|
||||
report_util_uint8_setting(13,bit_istrue(settings.flags,BITFLAG_REPORT_INCHES));
|
||||
report_util_uint8_setting(20,bit_istrue(settings.flags,BITFLAG_SOFT_LIMIT_ENABLE));
|
||||
report_util_uint8_setting(21,bit_istrue(settings.flags,BITFLAG_HARD_LIMIT_ENABLE));
|
||||
report_util_uint8_setting(22,bit_istrue(settings.flags,BITFLAG_HOMING_ENABLE));
|
||||
report_util_uint8_setting(23,settings.homing_dir_mask);
|
||||
report_util_float_setting(24,settings.homing_feed_rate,N_DECIMAL_SETTINGVALUE);
|
||||
report_util_float_setting(25,settings.homing_seek_rate,N_DECIMAL_SETTINGVALUE);
|
||||
report_util_uint8_setting(26,settings.homing_debounce_delay);
|
||||
report_util_float_setting(27,settings.homing_pulloff,N_DECIMAL_SETTINGVALUE);
|
||||
report_util_float_setting(30,settings.rpm_max,N_DECIMAL_RPMVALUE);
|
||||
report_util_float_setting(31,settings.rpm_min,N_DECIMAL_RPMVALUE);
|
||||
#ifdef VARIABLE_SPINDLE
|
||||
report_util_uint8_setting(32,bit_istrue(settings.flags,BITFLAG_LASER_MODE));
|
||||
#else
|
||||
report_util_uint8_setting(32,0);
|
||||
#endif
|
||||
report_util_uint8_setting(0, settings.pulse_microseconds);
|
||||
report_util_uint8_setting(1, settings.stepper_idle_lock_time);
|
||||
report_util_uint8_setting(2, settings.step_invert_mask);
|
||||
report_util_uint8_setting(3, settings.dir_invert_mask);
|
||||
report_util_uint8_setting(4, bit_istrue(settings.flags, BITFLAG_INVERT_ST_ENABLE));
|
||||
report_util_uint8_setting(5, bit_istrue(settings.flags, BITFLAG_INVERT_LIMIT_PINS));
|
||||
report_util_uint8_setting(6, bit_istrue(settings.flags, BITFLAG_INVERT_PROBE_PIN));
|
||||
report_util_uint8_setting(10, settings.status_report_mask);
|
||||
report_util_float_setting(11, settings.junction_deviation, N_DECIMAL_SETTINGVALUE);
|
||||
report_util_float_setting(12, settings.arc_tolerance, N_DECIMAL_SETTINGVALUE);
|
||||
report_util_uint8_setting(13, bit_istrue(settings.flags, BITFLAG_REPORT_INCHES));
|
||||
report_util_uint8_setting(20, bit_istrue(settings.flags, BITFLAG_SOFT_LIMIT_ENABLE));
|
||||
report_util_uint8_setting(21, bit_istrue(settings.flags, BITFLAG_HARD_LIMIT_ENABLE));
|
||||
report_util_uint8_setting(22, bit_istrue(settings.flags, BITFLAG_HOMING_ENABLE));
|
||||
report_util_uint8_setting(23, settings.homing_dir_mask);
|
||||
report_util_float_setting(24, settings.homing_feed_rate, N_DECIMAL_SETTINGVALUE);
|
||||
report_util_float_setting(25, settings.homing_seek_rate, N_DECIMAL_SETTINGVALUE);
|
||||
report_util_uint8_setting(26, settings.homing_debounce_delay);
|
||||
report_util_float_setting(27, settings.homing_pulloff, N_DECIMAL_SETTINGVALUE);
|
||||
report_util_float_setting(30, settings.rpm_max, N_DECIMAL_RPMVALUE);
|
||||
report_util_float_setting(31, settings.rpm_min, N_DECIMAL_RPMVALUE);
|
||||
#ifdef VARIABLE_SPINDLE
|
||||
report_util_uint8_setting(32, bit_istrue(settings.flags, BITFLAG_LASER_MODE));
|
||||
#else
|
||||
report_util_uint8_setting(32, 0);
|
||||
#endif
|
||||
// Print axis settings
|
||||
uint8_t idx, set_idx;
|
||||
uint8_t val = AXIS_SETTINGS_START_VAL;
|
||||
for (set_idx=0; set_idx<AXIS_N_SETTINGS; set_idx++) {
|
||||
for (idx=0; idx<N_AXIS; idx++) {
|
||||
for (set_idx = 0; set_idx < AXIS_N_SETTINGS; set_idx++) {
|
||||
for (idx = 0; idx < N_AXIS; idx++) {
|
||||
switch (set_idx) {
|
||||
case 0: report_util_float_setting(val+idx,settings.steps_per_mm[idx],N_DECIMAL_SETTINGVALUE); break;
|
||||
case 1: report_util_float_setting(val+idx,settings.max_rate[idx],N_DECIMAL_SETTINGVALUE); break;
|
||||
case 2: report_util_float_setting(val+idx,settings.acceleration[idx]/(60*60),N_DECIMAL_SETTINGVALUE); break;
|
||||
case 3: report_util_float_setting(val+idx,-settings.max_travel[idx],N_DECIMAL_SETTINGVALUE); break;
|
||||
case 0: report_util_float_setting(val + idx, settings.steps_per_mm[idx], N_DECIMAL_SETTINGVALUE); break;
|
||||
case 1: report_util_float_setting(val + idx, settings.max_rate[idx], N_DECIMAL_SETTINGVALUE); break;
|
||||
case 2:
|
||||
report_util_float_setting(val + idx, settings.acceleration[idx] / (60 * 60), N_DECIMAL_SETTINGVALUE);
|
||||
break;
|
||||
case 3: report_util_float_setting(val + idx, -settings.max_travel[idx], N_DECIMAL_SETTINGVALUE); break;
|
||||
}
|
||||
}
|
||||
val += AXIS_SETTINGS_INCREMENT;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Prints current probe parameters. Upon a probe command, these parameters are updated upon a
|
||||
// successful probe or upon a failed probe with the G38.3 without errors command (if supported).
|
||||
// These values are retained until Grbl is power-cycled, whereby they will be re-zeroed.
|
||||
void report_probe_parameters()
|
||||
{
|
||||
void report_probe_parameters() {
|
||||
// Report in terms of machine position.
|
||||
printPgmString(PSTR("[PRB:"));
|
||||
float print_position[N_AXIS];
|
||||
system_convert_array_steps_to_mpos(print_position,sys_probe_position);
|
||||
system_convert_array_steps_to_mpos(print_position, sys_probe_position);
|
||||
report_util_axis_values(print_position);
|
||||
serial_write(':');
|
||||
print_uint8_base10(sys.probe_succeeded);
|
||||
report_util_feedback_line_feed();
|
||||
}
|
||||
|
||||
|
||||
// Prints Grbl NGC parameters (coordinate offsets, probing)
|
||||
void report_ngc_parameters()
|
||||
{
|
||||
void report_ngc_parameters() {
|
||||
float coord_data[N_AXIS];
|
||||
uint8_t coord_select;
|
||||
for (coord_select = 0; coord_select <= SETTING_INDEX_NCOORD; coord_select++) {
|
||||
if (!(settings_read_coord_data(coord_select,coord_data))) {
|
||||
if (!(settings_read_coord_data(coord_select, coord_data))) {
|
||||
report_status_message(STATUS_SETTING_READ_FAIL);
|
||||
return;
|
||||
}
|
||||
|
|
@ -255,7 +256,7 @@ void report_ngc_parameters()
|
|||
switch (coord_select) {
|
||||
case 6: printPgmString(PSTR("28")); break;
|
||||
case 7: printPgmString(PSTR("30")); break;
|
||||
default: print_uint8_base10(coord_select+54); break; // G54-G59
|
||||
default: print_uint8_base10(coord_select + 54); break; // G54-G59
|
||||
}
|
||||
serial_write(':');
|
||||
report_util_axis_values(coord_data);
|
||||
|
|
@ -270,69 +271,77 @@ void report_ngc_parameters()
|
|||
report_probe_parameters(); // Print probe parameters. Not persistent in memory.
|
||||
}
|
||||
|
||||
|
||||
// Print current gcode parser mode state
|
||||
void report_gcode_modes()
|
||||
{
|
||||
void report_gcode_modes() {
|
||||
printPgmString(PSTR("[GC:G"));
|
||||
if (gc_state.modal.motion >= MOTION_MODE_PROBE_TOWARD) {
|
||||
printPgmString(PSTR("38."));
|
||||
print_uint8_base10(gc_state.modal.motion - (MOTION_MODE_PROBE_TOWARD-2));
|
||||
print_uint8_base10(gc_state.modal.motion - (MOTION_MODE_PROBE_TOWARD - 2));
|
||||
} else {
|
||||
print_uint8_base10(gc_state.modal.motion);
|
||||
}
|
||||
|
||||
report_util_gcode_modes_G();
|
||||
print_uint8_base10(gc_state.modal.coord_select+54);
|
||||
print_uint8_base10(gc_state.modal.coord_select + 54);
|
||||
|
||||
report_util_gcode_modes_G();
|
||||
print_uint8_base10(gc_state.modal.plane_select+17);
|
||||
print_uint8_base10(gc_state.modal.plane_select + 17);
|
||||
|
||||
report_util_gcode_modes_G();
|
||||
print_uint8_base10(21-gc_state.modal.units);
|
||||
print_uint8_base10(21 - gc_state.modal.units);
|
||||
|
||||
report_util_gcode_modes_G();
|
||||
print_uint8_base10(gc_state.modal.distance+90);
|
||||
print_uint8_base10(gc_state.modal.distance + 90);
|
||||
|
||||
report_util_gcode_modes_G();
|
||||
print_uint8_base10(94-gc_state.modal.feed_rate);
|
||||
print_uint8_base10(94 - gc_state.modal.feed_rate);
|
||||
|
||||
if (gc_state.modal.program_flow) {
|
||||
report_util_gcode_modes_M();
|
||||
switch (gc_state.modal.program_flow) {
|
||||
case PROGRAM_FLOW_PAUSED : serial_write('0'); break;
|
||||
case PROGRAM_FLOW_PAUSED: serial_write('0'); break;
|
||||
// case PROGRAM_FLOW_OPTIONAL_STOP : serial_write('1'); break; // M1 is ignored and not supported.
|
||||
case PROGRAM_FLOW_COMPLETED_M2 :
|
||||
case PROGRAM_FLOW_COMPLETED_M30 :
|
||||
print_uint8_base10(gc_state.modal.program_flow);
|
||||
break;
|
||||
case PROGRAM_FLOW_COMPLETED_M2:
|
||||
case PROGRAM_FLOW_COMPLETED_M30: print_uint8_base10(gc_state.modal.program_flow); break;
|
||||
}
|
||||
}
|
||||
|
||||
report_util_gcode_modes_M();
|
||||
switch (gc_state.modal.spindle) {
|
||||
case SPINDLE_ENABLE_CW : serial_write('3'); break;
|
||||
case SPINDLE_ENABLE_CCW : serial_write('4'); break;
|
||||
case SPINDLE_DISABLE : serial_write('5'); break;
|
||||
case SPINDLE_ENABLE_CW: serial_write('3'); break;
|
||||
case SPINDLE_ENABLE_CCW: serial_write('4'); break;
|
||||
case SPINDLE_DISABLE: serial_write('5'); break;
|
||||
}
|
||||
|
||||
#ifdef ENABLE_M7
|
||||
#ifdef ENABLE_M7
|
||||
if (gc_state.modal.coolant) { // Note: Multiple coolant states may be active at the same time.
|
||||
if (gc_state.modal.coolant & PL_COND_FLAG_COOLANT_MIST) { report_util_gcode_modes_M(); serial_write('7'); }
|
||||
if (gc_state.modal.coolant & PL_COND_FLAG_COOLANT_FLOOD) { report_util_gcode_modes_M(); serial_write('8'); }
|
||||
} else { report_util_gcode_modes_M(); serial_write('9'); }
|
||||
#else
|
||||
if (gc_state.modal.coolant & PL_COND_FLAG_COOLANT_MIST) {
|
||||
report_util_gcode_modes_M();
|
||||
if (gc_state.modal.coolant) { serial_write('8'); }
|
||||
else { serial_write('9'); }
|
||||
#endif
|
||||
serial_write('7');
|
||||
}
|
||||
if (gc_state.modal.coolant & PL_COND_FLAG_COOLANT_FLOOD) {
|
||||
report_util_gcode_modes_M();
|
||||
serial_write('8');
|
||||
}
|
||||
} else {
|
||||
report_util_gcode_modes_M();
|
||||
serial_write('9');
|
||||
}
|
||||
#else
|
||||
report_util_gcode_modes_M();
|
||||
if (gc_state.modal.coolant) {
|
||||
serial_write('8');
|
||||
} else {
|
||||
serial_write('9');
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef ENABLE_PARKING_OVERRIDE_CONTROL
|
||||
#ifdef ENABLE_PARKING_OVERRIDE_CONTROL
|
||||
if (sys.override_ctrl == OVERRIDE_PARKING_MOTION) {
|
||||
report_util_gcode_modes_M();
|
||||
print_uint8_base10(56);
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
printPgmString(PSTR(" T"));
|
||||
print_uint8_base10(gc_state.tool);
|
||||
|
|
@ -340,17 +349,16 @@ void report_gcode_modes()
|
|||
printPgmString(PSTR(" F"));
|
||||
printFloat_RateValue(gc_state.feed_rate);
|
||||
|
||||
#ifdef VARIABLE_SPINDLE
|
||||
#ifdef VARIABLE_SPINDLE
|
||||
printPgmString(PSTR(" S"));
|
||||
printFloat(gc_state.spindle_speed,N_DECIMAL_RPMVALUE);
|
||||
#endif
|
||||
printFloat(gc_state.spindle_speed, N_DECIMAL_RPMVALUE);
|
||||
#endif
|
||||
|
||||
report_util_feedback_line_feed();
|
||||
}
|
||||
|
||||
// Prints specified startup line
|
||||
void report_startup_line(uint8_t n, char *line)
|
||||
{
|
||||
void report_startup_line(uint8_t n, char *line) {
|
||||
printPgmString(PSTR("$N"));
|
||||
print_uint8_base10(n);
|
||||
serial_write('=');
|
||||
|
|
@ -358,8 +366,7 @@ void report_startup_line(uint8_t n, char *line)
|
|||
report_util_line_feed();
|
||||
}
|
||||
|
||||
void report_execute_startup_message(char *line, uint8_t status_code)
|
||||
{
|
||||
void report_execute_startup_message(char *line, uint8_t status_code) {
|
||||
serial_write('>');
|
||||
printString(line);
|
||||
serial_write(':');
|
||||
|
|
@ -367,109 +374,105 @@ void report_execute_startup_message(char *line, uint8_t status_code)
|
|||
}
|
||||
|
||||
// Prints build info line
|
||||
void report_build_info(char *line)
|
||||
{
|
||||
void report_build_info(char *line) {
|
||||
printPgmString(PSTR("[VER:" GRBL_VERSION "." GRBL_VERSION_BUILD ":"));
|
||||
printString(line);
|
||||
report_util_feedback_line_feed();
|
||||
printPgmString(PSTR("[OPT:")); // Generate compile-time build option list
|
||||
#ifdef VARIABLE_SPINDLE
|
||||
#ifdef VARIABLE_SPINDLE
|
||||
serial_write('V');
|
||||
#endif
|
||||
#ifdef USE_LINE_NUMBERS
|
||||
#endif
|
||||
#ifdef USE_LINE_NUMBERS
|
||||
serial_write('N');
|
||||
#endif
|
||||
#ifdef ENABLE_M7
|
||||
#endif
|
||||
#ifdef ENABLE_M7
|
||||
serial_write('M');
|
||||
#endif
|
||||
#ifdef COREXY
|
||||
#endif
|
||||
#ifdef COREXY
|
||||
serial_write('C');
|
||||
#endif
|
||||
#ifdef PARKING_ENABLE
|
||||
#endif
|
||||
#ifdef PARKING_ENABLE
|
||||
serial_write('P');
|
||||
#endif
|
||||
#ifdef HOMING_FORCE_SET_ORIGIN
|
||||
#endif
|
||||
#ifdef HOMING_FORCE_SET_ORIGIN
|
||||
serial_write('Z');
|
||||
#endif
|
||||
#ifdef HOMING_SINGLE_AXIS_COMMANDS
|
||||
#endif
|
||||
#ifdef HOMING_SINGLE_AXIS_COMMANDS
|
||||
serial_write('H');
|
||||
#endif
|
||||
#ifdef LIMITS_TWO_SWITCHES_ON_AXES
|
||||
#endif
|
||||
#ifdef LIMITS_TWO_SWITCHES_ON_AXES
|
||||
serial_write('T');
|
||||
#endif
|
||||
#ifdef ALLOW_FEED_OVERRIDE_DURING_PROBE_CYCLES
|
||||
#endif
|
||||
#ifdef ALLOW_FEED_OVERRIDE_DURING_PROBE_CYCLES
|
||||
serial_write('A');
|
||||
#endif
|
||||
#ifdef USE_SPINDLE_DIR_AS_ENABLE_PIN
|
||||
#endif
|
||||
#ifdef USE_SPINDLE_DIR_AS_ENABLE_PIN
|
||||
serial_write('D');
|
||||
#endif
|
||||
#ifdef SPINDLE_ENABLE_OFF_WITH_ZERO_SPEED
|
||||
#endif
|
||||
#ifdef SPINDLE_ENABLE_OFF_WITH_ZERO_SPEED
|
||||
serial_write('0');
|
||||
#endif
|
||||
#ifdef ENABLE_SOFTWARE_DEBOUNCE
|
||||
#endif
|
||||
#ifdef ENABLE_SOFTWARE_DEBOUNCE
|
||||
serial_write('S');
|
||||
#endif
|
||||
#ifdef ENABLE_PARKING_OVERRIDE_CONTROL
|
||||
#endif
|
||||
#ifdef ENABLE_PARKING_OVERRIDE_CONTROL
|
||||
serial_write('R');
|
||||
#endif
|
||||
#ifndef HOMING_INIT_LOCK
|
||||
#endif
|
||||
#ifndef HOMING_INIT_LOCK
|
||||
serial_write('L');
|
||||
#endif
|
||||
#ifdef ENABLE_SAFETY_DOOR_INPUT_PIN
|
||||
#endif
|
||||
#ifdef ENABLE_SAFETY_DOOR_INPUT_PIN
|
||||
serial_write('+');
|
||||
#endif
|
||||
#ifndef ENABLE_RESTORE_EEPROM_WIPE_ALL // NOTE: Shown when disabled.
|
||||
#endif
|
||||
#ifndef ENABLE_RESTORE_EEPROM_WIPE_ALL // NOTE: Shown when disabled.
|
||||
serial_write('*');
|
||||
#endif
|
||||
#ifndef ENABLE_RESTORE_EEPROM_DEFAULT_SETTINGS // NOTE: Shown when disabled.
|
||||
#endif
|
||||
#ifndef ENABLE_RESTORE_EEPROM_DEFAULT_SETTINGS // NOTE: Shown when disabled.
|
||||
serial_write('$');
|
||||
#endif
|
||||
#ifndef ENABLE_RESTORE_EEPROM_CLEAR_PARAMETERS // NOTE: Shown when disabled.
|
||||
#endif
|
||||
#ifndef ENABLE_RESTORE_EEPROM_CLEAR_PARAMETERS // NOTE: Shown when disabled.
|
||||
serial_write('#');
|
||||
#endif
|
||||
#ifndef ENABLE_BUILD_INFO_WRITE_COMMAND // NOTE: Shown when disabled.
|
||||
#endif
|
||||
#ifndef ENABLE_BUILD_INFO_WRITE_COMMAND // NOTE: Shown when disabled.
|
||||
serial_write('I');
|
||||
#endif
|
||||
#ifndef FORCE_BUFFER_SYNC_DURING_EEPROM_WRITE // NOTE: Shown when disabled.
|
||||
#endif
|
||||
#ifndef FORCE_BUFFER_SYNC_DURING_EEPROM_WRITE // NOTE: Shown when disabled.
|
||||
serial_write('E');
|
||||
#endif
|
||||
#ifndef FORCE_BUFFER_SYNC_DURING_WCO_CHANGE // NOTE: Shown when disabled.
|
||||
#endif
|
||||
#ifndef FORCE_BUFFER_SYNC_DURING_WCO_CHANGE // NOTE: Shown when disabled.
|
||||
serial_write('W');
|
||||
#endif
|
||||
#ifdef ENABLE_DUAL_AXIS
|
||||
#endif
|
||||
#ifdef ENABLE_DUAL_AXIS
|
||||
serial_write('2');
|
||||
#endif
|
||||
#endif
|
||||
// NOTE: Compiled values, like override increments/max/min values, may be added at some point later.
|
||||
serial_write(',');
|
||||
print_uint8_base10(BLOCK_BUFFER_SIZE-1);
|
||||
print_uint8_base10(BLOCK_BUFFER_SIZE - 1);
|
||||
serial_write(',');
|
||||
print_uint8_base10(RX_BUFFER_SIZE);
|
||||
|
||||
report_util_feedback_line_feed();
|
||||
}
|
||||
|
||||
|
||||
// Prints the character string line Grbl has received from the user, which has been pre-parsed,
|
||||
// and has been sent into protocol_execute_line() routine to be executed by Grbl.
|
||||
void report_echo_line_received(char *line)
|
||||
{
|
||||
printPgmString(PSTR("[echo: ")); printString(line);
|
||||
void report_echo_line_received(char *line) {
|
||||
printPgmString(PSTR("[echo: "));
|
||||
printString(line);
|
||||
report_util_feedback_line_feed();
|
||||
}
|
||||
|
||||
|
||||
// Prints real-time data. This function grabs a real-time snapshot of the stepper subprogram
|
||||
// and the actual location of the CNC machine. Users may change the following function to their
|
||||
// specific needs, but the desired real-time data report must be as short as possible. This is
|
||||
// requires as it minimizes the computational overhead and allows grbl to keep running smoothly,
|
||||
// especially during g-code programs with fast, short line segments and high frequency reports (5-20Hz).
|
||||
void report_realtime_status()
|
||||
{
|
||||
// Prints real-time data. This function grabs a real-time snapshot of the stepper subprogram
|
||||
// and the actual location of the CNC machine. Users may change the following function to their
|
||||
// specific needs, but the desired real-time data report must be as short as possible. This is
|
||||
// requires as it minimizes the computational overhead and allows grbl to keep running smoothly,
|
||||
// especially during g-code programs with fast, short line segments and high frequency reports (5-20Hz).
|
||||
void report_realtime_status() {
|
||||
uint8_t idx;
|
||||
int32_t current_position[N_AXIS]; // Copy current state of the system position variable
|
||||
memcpy(current_position,sys_position,sizeof(sys_position));
|
||||
memcpy(current_position, sys_position, sizeof(sys_position));
|
||||
float print_position[N_AXIS];
|
||||
system_convert_array_steps_to_mpos(print_position,current_position);
|
||||
system_convert_array_steps_to_mpos(print_position, current_position);
|
||||
|
||||
// Report current machine state and sub-states
|
||||
serial_write('<');
|
||||
|
|
@ -479,8 +482,12 @@ void report_realtime_status()
|
|||
case STATE_HOLD:
|
||||
if (!(sys.suspend & SUSPEND_JOG_CANCEL)) {
|
||||
printPgmString(PSTR("Hold:"));
|
||||
if (sys.suspend & SUSPEND_HOLD_COMPLETE) { serial_write('0'); } // Ready to resume
|
||||
else { serial_write('1'); } // Actively holding
|
||||
if (sys.suspend & SUSPEND_HOLD_COMPLETE) {
|
||||
serial_write('0');
|
||||
} // Ready to resume
|
||||
else {
|
||||
serial_write('1');
|
||||
} // Actively holding
|
||||
break;
|
||||
} // Continues to print jog state during jog cancel.
|
||||
case STATE_JOG: printPgmString(PSTR("Jog")); break;
|
||||
|
|
@ -507,40 +514,41 @@ void report_realtime_status()
|
|||
}
|
||||
|
||||
float wco[N_AXIS];
|
||||
if (bit_isfalse(settings.status_report_mask,BITFLAG_RT_STATUS_POSITION_TYPE) ||
|
||||
(sys.report_wco_counter == 0) ) {
|
||||
for (idx=0; idx< N_AXIS; idx++) {
|
||||
if (bit_isfalse(settings.status_report_mask, BITFLAG_RT_STATUS_POSITION_TYPE) || (sys.report_wco_counter == 0)) {
|
||||
for (idx = 0; idx < N_AXIS; idx++) {
|
||||
// Apply work coordinate offsets and tool length offset to current position.
|
||||
wco[idx] = gc_state.coord_system[idx]+gc_state.coord_offset[idx];
|
||||
if (idx == TOOL_LENGTH_OFFSET_AXIS) { wco[idx] += gc_state.tool_length_offset; }
|
||||
if (bit_isfalse(settings.status_report_mask,BITFLAG_RT_STATUS_POSITION_TYPE)) {
|
||||
wco[idx] = gc_state.coord_system[idx] + gc_state.coord_offset[idx];
|
||||
if (idx == TOOL_LENGTH_OFFSET_AXIS) {
|
||||
wco[idx] += gc_state.tool_length_offset;
|
||||
}
|
||||
if (bit_isfalse(settings.status_report_mask, BITFLAG_RT_STATUS_POSITION_TYPE)) {
|
||||
print_position[idx] -= wco[idx];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Report machine position
|
||||
if (bit_istrue(settings.status_report_mask,BITFLAG_RT_STATUS_POSITION_TYPE)) {
|
||||
if (bit_istrue(settings.status_report_mask, BITFLAG_RT_STATUS_POSITION_TYPE)) {
|
||||
printPgmString(PSTR("|MPos:"));
|
||||
} else {
|
||||
printPgmString(PSTR("|WPos:"));
|
||||
}
|
||||
report_util_axis_values(print_position);
|
||||
|
||||
// Returns planner and serial read buffer states.
|
||||
#ifdef REPORT_FIELD_BUFFER_STATE
|
||||
if (bit_istrue(settings.status_report_mask,BITFLAG_RT_STATUS_BUFFER_STATE)) {
|
||||
// Returns planner and serial read buffer states.
|
||||
#ifdef REPORT_FIELD_BUFFER_STATE
|
||||
if (bit_istrue(settings.status_report_mask, BITFLAG_RT_STATUS_BUFFER_STATE)) {
|
||||
printPgmString(PSTR("|Bf:"));
|
||||
print_uint8_base10(plan_get_block_buffer_available());
|
||||
serial_write(',');
|
||||
print_uint8_base10(serial_get_rx_buffer_available());
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef USE_LINE_NUMBERS
|
||||
#ifdef REPORT_FIELD_LINE_NUMBERS
|
||||
#ifdef USE_LINE_NUMBERS
|
||||
#ifdef REPORT_FIELD_LINE_NUMBERS
|
||||
// Report current line number
|
||||
plan_block_t * cur_block = plan_get_current_block();
|
||||
plan_block_t *cur_block = plan_get_current_block();
|
||||
if (cur_block != NULL) {
|
||||
uint32_t ln = cur_block->line_number;
|
||||
if (ln > 0) {
|
||||
|
|
@ -548,75 +556,109 @@ void report_realtime_status()
|
|||
printInteger(ln);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// Report realtime feed speed
|
||||
#ifdef REPORT_FIELD_CURRENT_FEED_SPEED
|
||||
#ifdef VARIABLE_SPINDLE
|
||||
// Report realtime feed speed
|
||||
#ifdef REPORT_FIELD_CURRENT_FEED_SPEED
|
||||
#ifdef VARIABLE_SPINDLE
|
||||
printPgmString(PSTR("|FS:"));
|
||||
printFloat_RateValue(st_get_realtime_rate());
|
||||
serial_write(',');
|
||||
printFloat(sys.spindle_speed,N_DECIMAL_RPMVALUE);
|
||||
#else
|
||||
printFloat(sys.spindle_speed, N_DECIMAL_RPMVALUE);
|
||||
#else
|
||||
printPgmString(PSTR("|F:"));
|
||||
printFloat_RateValue(st_get_realtime_rate());
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef REPORT_FIELD_PIN_STATE
|
||||
#ifdef REPORT_FIELD_PIN_STATE
|
||||
uint8_t lim_pin_state = limits_get_state();
|
||||
uint8_t ctrl_pin_state = system_control_get_state();
|
||||
uint8_t prb_pin_state = probe_get_state();
|
||||
if (lim_pin_state | ctrl_pin_state | prb_pin_state) {
|
||||
printPgmString(PSTR("|Pn:"));
|
||||
if (prb_pin_state) { serial_write('P'); }
|
||||
if (prb_pin_state) {
|
||||
serial_write('P');
|
||||
}
|
||||
if (lim_pin_state) {
|
||||
#ifdef ENABLE_DUAL_AXIS
|
||||
#if (DUAL_AXIS_SELECT == X_AXIS)
|
||||
if (bit_istrue(lim_pin_state,(bit(X_AXIS)|bit(N_AXIS)))) { serial_write('X'); }
|
||||
if (bit_istrue(lim_pin_state,bit(Y_AXIS))) { serial_write('Y'); }
|
||||
#endif
|
||||
#if (DUAL_AXIS_SELECT == Y_AXIS)
|
||||
if (bit_istrue(lim_pin_state,bit(X_AXIS))) { serial_write('X'); }
|
||||
if (bit_istrue(lim_pin_state,(bit(Y_AXIS)|bit(N_AXIS)))) { serial_write('Y'); }
|
||||
#endif
|
||||
if (bit_istrue(lim_pin_state,bit(Z_AXIS))) { serial_write('Z'); }
|
||||
#else
|
||||
if (bit_istrue(lim_pin_state,bit(X_AXIS))) { serial_write('X'); }
|
||||
if (bit_istrue(lim_pin_state,bit(Y_AXIS))) { serial_write('Y'); }
|
||||
if (bit_istrue(lim_pin_state,bit(Z_AXIS))) { serial_write('Z'); }
|
||||
#endif
|
||||
#ifdef ENABLE_DUAL_AXIS
|
||||
#if (DUAL_AXIS_SELECT == X_AXIS)
|
||||
if (bit_istrue(lim_pin_state, (bit(X_AXIS) | bit(N_AXIS)))) {
|
||||
serial_write('X');
|
||||
}
|
||||
if (bit_istrue(lim_pin_state, bit(Y_AXIS))) {
|
||||
serial_write('Y');
|
||||
}
|
||||
#endif
|
||||
#if (DUAL_AXIS_SELECT == Y_AXIS)
|
||||
if (bit_istrue(lim_pin_state, bit(X_AXIS))) {
|
||||
serial_write('X');
|
||||
}
|
||||
if (bit_istrue(lim_pin_state, (bit(Y_AXIS) | bit(N_AXIS)))) {
|
||||
serial_write('Y');
|
||||
}
|
||||
#endif
|
||||
if (bit_istrue(lim_pin_state, bit(Z_AXIS))) {
|
||||
serial_write('Z');
|
||||
}
|
||||
#else
|
||||
if (bit_istrue(lim_pin_state, bit(X_AXIS))) {
|
||||
serial_write('X');
|
||||
}
|
||||
if (bit_istrue(lim_pin_state, bit(Y_AXIS))) {
|
||||
serial_write('Y');
|
||||
}
|
||||
if (bit_istrue(lim_pin_state, bit(Z_AXIS))) {
|
||||
serial_write('Z');
|
||||
}
|
||||
#endif
|
||||
}
|
||||
if (ctrl_pin_state) {
|
||||
#ifdef ENABLE_SAFETY_DOOR_INPUT_PIN
|
||||
if (bit_istrue(ctrl_pin_state,CONTROL_PIN_INDEX_SAFETY_DOOR)) { serial_write('D'); }
|
||||
#endif
|
||||
if (bit_istrue(ctrl_pin_state,CONTROL_PIN_INDEX_RESET)) { serial_write('R'); }
|
||||
if (bit_istrue(ctrl_pin_state,CONTROL_PIN_INDEX_FEED_HOLD)) { serial_write('H'); }
|
||||
if (bit_istrue(ctrl_pin_state,CONTROL_PIN_INDEX_CYCLE_START)) { serial_write('S'); }
|
||||
#ifdef ENABLE_SAFETY_DOOR_INPUT_PIN
|
||||
if (bit_istrue(ctrl_pin_state, CONTROL_PIN_INDEX_SAFETY_DOOR)) {
|
||||
serial_write('D');
|
||||
}
|
||||
#endif
|
||||
if (bit_istrue(ctrl_pin_state, CONTROL_PIN_INDEX_RESET)) {
|
||||
serial_write('R');
|
||||
}
|
||||
if (bit_istrue(ctrl_pin_state, CONTROL_PIN_INDEX_FEED_HOLD)) {
|
||||
serial_write('H');
|
||||
}
|
||||
if (bit_istrue(ctrl_pin_state, CONTROL_PIN_INDEX_CYCLE_START)) {
|
||||
serial_write('S');
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef REPORT_FIELD_WORK_COORD_OFFSET
|
||||
if (sys.report_wco_counter > 0) { sys.report_wco_counter--; }
|
||||
else {
|
||||
#ifdef REPORT_FIELD_WORK_COORD_OFFSET
|
||||
if (sys.report_wco_counter > 0) {
|
||||
sys.report_wco_counter--;
|
||||
} else {
|
||||
if (sys.state & (STATE_HOMING | STATE_CYCLE | STATE_HOLD | STATE_JOG | STATE_SAFETY_DOOR)) {
|
||||
sys.report_wco_counter = (REPORT_WCO_REFRESH_BUSY_COUNT-1); // Reset counter for slow refresh
|
||||
} else { sys.report_wco_counter = (REPORT_WCO_REFRESH_IDLE_COUNT-1); }
|
||||
if (sys.report_ovr_counter == 0) { sys.report_ovr_counter = 1; } // Set override on next report.
|
||||
sys.report_wco_counter = (REPORT_WCO_REFRESH_BUSY_COUNT - 1); // Reset counter for slow refresh
|
||||
} else {
|
||||
sys.report_wco_counter = (REPORT_WCO_REFRESH_IDLE_COUNT - 1);
|
||||
}
|
||||
if (sys.report_ovr_counter == 0) {
|
||||
sys.report_ovr_counter = 1;
|
||||
} // Set override on next report.
|
||||
printPgmString(PSTR("|WCO:"));
|
||||
report_util_axis_values(wco);
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef REPORT_FIELD_OVERRIDES
|
||||
if (sys.report_ovr_counter > 0) { sys.report_ovr_counter--; }
|
||||
else {
|
||||
#ifdef REPORT_FIELD_OVERRIDES
|
||||
if (sys.report_ovr_counter > 0) {
|
||||
sys.report_ovr_counter--;
|
||||
} else {
|
||||
if (sys.state & (STATE_HOMING | STATE_CYCLE | STATE_HOLD | STATE_JOG | STATE_SAFETY_DOOR)) {
|
||||
sys.report_ovr_counter = (REPORT_OVR_REFRESH_BUSY_COUNT-1); // Reset counter for slow refresh
|
||||
} else { sys.report_ovr_counter = (REPORT_OVR_REFRESH_IDLE_COUNT-1); }
|
||||
sys.report_ovr_counter = (REPORT_OVR_REFRESH_BUSY_COUNT - 1); // Reset counter for slow refresh
|
||||
} else {
|
||||
sys.report_ovr_counter = (REPORT_OVR_REFRESH_IDLE_COUNT - 1);
|
||||
}
|
||||
printPgmString(PSTR("|Ov:"));
|
||||
print_uint8_base10(sys.f_override);
|
||||
serial_write(',');
|
||||
|
|
@ -629,34 +671,43 @@ void report_realtime_status()
|
|||
if (sp_state || cl_state) {
|
||||
printPgmString(PSTR("|A:"));
|
||||
if (sp_state) { // != SPINDLE_STATE_DISABLE
|
||||
#ifdef VARIABLE_SPINDLE
|
||||
#ifdef USE_SPINDLE_DIR_AS_ENABLE_PIN
|
||||
#ifdef VARIABLE_SPINDLE
|
||||
#ifdef USE_SPINDLE_DIR_AS_ENABLE_PIN
|
||||
serial_write('S'); // CW
|
||||
#else
|
||||
if (sp_state == SPINDLE_STATE_CW) { serial_write('S'); } // CW
|
||||
else { serial_write('C'); } // CCW
|
||||
#endif
|
||||
#else
|
||||
if (sp_state & SPINDLE_STATE_CW) { serial_write('S'); } // CW
|
||||
else { serial_write('C'); } // CCW
|
||||
#endif
|
||||
#else
|
||||
if (sp_state == SPINDLE_STATE_CW) {
|
||||
serial_write('S');
|
||||
} // CW
|
||||
else {
|
||||
serial_write('C');
|
||||
} // CCW
|
||||
#endif
|
||||
#else
|
||||
if (sp_state & SPINDLE_STATE_CW) {
|
||||
serial_write('S');
|
||||
} // CW
|
||||
else {
|
||||
serial_write('C');
|
||||
} // CCW
|
||||
#endif
|
||||
}
|
||||
if (cl_state & COOLANT_STATE_FLOOD) { serial_write('F'); }
|
||||
#ifdef ENABLE_M7
|
||||
if (cl_state & COOLANT_STATE_MIST) { serial_write('M'); }
|
||||
#endif
|
||||
if (cl_state & COOLANT_STATE_FLOOD) {
|
||||
serial_write('F');
|
||||
}
|
||||
#ifdef ENABLE_M7
|
||||
if (cl_state & COOLANT_STATE_MIST) {
|
||||
serial_write('M');
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
serial_write('>');
|
||||
report_util_line_feed();
|
||||
}
|
||||
|
||||
|
||||
#ifdef DEBUG
|
||||
void report_realtime_debug()
|
||||
{
|
||||
|
||||
}
|
||||
void report_realtime_debug() {
|
||||
}
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -125,7 +125,7 @@ void report_execute_startup_message(char *line, uint8_t status_code);
|
|||
void report_build_info(char *line);
|
||||
|
||||
#ifdef DEBUG
|
||||
void report_realtime_debug();
|
||||
void report_realtime_debug();
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
|
|
|||
132
grbl/serial.c
132
grbl/serial.c
|
|
@ -21,8 +21,8 @@
|
|||
|
||||
#include "grbl.h"
|
||||
|
||||
#define RX_RING_BUFFER (RX_BUFFER_SIZE+1)
|
||||
#define TX_RING_BUFFER (TX_BUFFER_SIZE+1)
|
||||
#define RX_RING_BUFFER (RX_BUFFER_SIZE + 1)
|
||||
#define TX_RING_BUFFER (TX_BUFFER_SIZE + 1)
|
||||
|
||||
uint8_t serial_rx_buffer[RX_RING_BUFFER];
|
||||
uint8_t serial_rx_buffer_head = 0;
|
||||
|
|
@ -32,66 +32,67 @@ uint8_t serial_tx_buffer[TX_RING_BUFFER];
|
|||
uint8_t serial_tx_buffer_head = 0;
|
||||
volatile uint8_t serial_tx_buffer_tail = 0;
|
||||
|
||||
|
||||
// Returns the number of bytes available in the RX serial buffer.
|
||||
uint8_t serial_get_rx_buffer_available()
|
||||
{
|
||||
uint8_t serial_get_rx_buffer_available() {
|
||||
uint8_t rtail = serial_rx_buffer_tail; // Copy to limit multiple calls to volatile
|
||||
if (serial_rx_buffer_head >= rtail) { return(RX_BUFFER_SIZE - (serial_rx_buffer_head-rtail)); }
|
||||
return((rtail-serial_rx_buffer_head-1));
|
||||
if (serial_rx_buffer_head >= rtail) {
|
||||
return (RX_BUFFER_SIZE - (serial_rx_buffer_head - rtail));
|
||||
}
|
||||
return ((rtail - serial_rx_buffer_head - 1));
|
||||
}
|
||||
|
||||
|
||||
// Returns the number of bytes used in the RX serial buffer.
|
||||
// NOTE: Deprecated. Not used unless classic status reports are enabled in config.h.
|
||||
uint8_t serial_get_rx_buffer_count()
|
||||
{
|
||||
uint8_t serial_get_rx_buffer_count() {
|
||||
uint8_t rtail = serial_rx_buffer_tail; // Copy to limit multiple calls to volatile
|
||||
if (serial_rx_buffer_head >= rtail) { return(serial_rx_buffer_head-rtail); }
|
||||
return (RX_BUFFER_SIZE - (rtail-serial_rx_buffer_head));
|
||||
if (serial_rx_buffer_head >= rtail) {
|
||||
return (serial_rx_buffer_head - rtail);
|
||||
}
|
||||
return (RX_BUFFER_SIZE - (rtail - serial_rx_buffer_head));
|
||||
}
|
||||
|
||||
|
||||
// Returns the number of bytes used in the TX serial buffer.
|
||||
// NOTE: Not used except for debugging and ensuring no TX bottlenecks.
|
||||
uint8_t serial_get_tx_buffer_count()
|
||||
{
|
||||
uint8_t serial_get_tx_buffer_count() {
|
||||
uint8_t ttail = serial_tx_buffer_tail; // Copy to limit multiple calls to volatile
|
||||
if (serial_tx_buffer_head >= ttail) { return(serial_tx_buffer_head-ttail); }
|
||||
return (TX_RING_BUFFER - (ttail-serial_tx_buffer_head));
|
||||
if (serial_tx_buffer_head >= ttail) {
|
||||
return (serial_tx_buffer_head - ttail);
|
||||
}
|
||||
return (TX_RING_BUFFER - (ttail - serial_tx_buffer_head));
|
||||
}
|
||||
|
||||
|
||||
void serial_init()
|
||||
{
|
||||
// Set baud rate
|
||||
#if BAUD_RATE < 57600
|
||||
uint16_t UBRR0_value = ((F_CPU / (8L * BAUD_RATE)) - 1)/2 ;
|
||||
void serial_init() {
|
||||
// Set baud rate
|
||||
#if BAUD_RATE < 57600
|
||||
uint16_t UBRR0_value = ((F_CPU / (8L * BAUD_RATE)) - 1) / 2;
|
||||
UCSR0A &= ~(1 << U2X0); // baud doubler off - Only needed on Uno XXX
|
||||
#else
|
||||
uint16_t UBRR0_value = ((F_CPU / (4L * BAUD_RATE)) - 1)/2;
|
||||
#else
|
||||
uint16_t UBRR0_value = ((F_CPU / (4L * BAUD_RATE)) - 1) / 2;
|
||||
UCSR0A |= (1 << U2X0); // baud doubler on for high baud rates, i.e. 115200
|
||||
#endif
|
||||
#endif
|
||||
UBRR0H = UBRR0_value >> 8;
|
||||
UBRR0L = UBRR0_value;
|
||||
|
||||
// enable rx, tx, and interrupt on complete reception of a byte
|
||||
UCSR0B |= (1<<RXEN0 | 1<<TXEN0 | 1<<RXCIE0);
|
||||
UCSR0B |= (1 << RXEN0 | 1 << TXEN0 | 1 << RXCIE0);
|
||||
|
||||
// defaults to 8-bit, no parity, 1 stop bit
|
||||
}
|
||||
|
||||
|
||||
// Writes one byte to the TX serial buffer. Called by main program.
|
||||
void serial_write(uint8_t data) {
|
||||
// Calculate next head
|
||||
uint8_t next_head = serial_tx_buffer_head + 1;
|
||||
if (next_head == TX_RING_BUFFER) { next_head = 0; }
|
||||
if (next_head == TX_RING_BUFFER) {
|
||||
next_head = 0;
|
||||
}
|
||||
|
||||
// Wait until there is space in the buffer
|
||||
while (next_head == serial_tx_buffer_tail) {
|
||||
// TODO: Restructure st_prep_buffer() calls to be executed here during a long print.
|
||||
if (sys_rt_exec_state & EXEC_RESET) { return; } // Only check for abort to avoid an endless loop.
|
||||
if (sys_rt_exec_state & EXEC_RESET) {
|
||||
return;
|
||||
} // Only check for abort to avoid an endless loop.
|
||||
}
|
||||
|
||||
// Store data and advance head
|
||||
|
|
@ -102,10 +103,8 @@ void serial_write(uint8_t data) {
|
|||
UCSR0B |= (1 << UDRIE0);
|
||||
}
|
||||
|
||||
|
||||
// Data Register Empty Interrupt handler
|
||||
ISR(SERIAL_UDRE)
|
||||
{
|
||||
ISR(SERIAL_UDRE) {
|
||||
uint8_t tail = serial_tx_buffer_tail; // Temporary serial_tx_buffer_tail (to optimize for volatile)
|
||||
|
||||
// Send a byte from the buffer
|
||||
|
|
@ -113,18 +112,20 @@ ISR(SERIAL_UDRE)
|
|||
|
||||
// Update tail position
|
||||
tail++;
|
||||
if (tail == TX_RING_BUFFER) { tail = 0; }
|
||||
if (tail == TX_RING_BUFFER) {
|
||||
tail = 0;
|
||||
}
|
||||
|
||||
serial_tx_buffer_tail = tail;
|
||||
|
||||
// Turn off Data Register Empty Interrupt to stop tx-streaming if this concludes the transfer
|
||||
if (tail == serial_tx_buffer_head) { UCSR0B &= ~(1 << UDRIE0); }
|
||||
if (tail == serial_tx_buffer_head) {
|
||||
UCSR0B &= ~(1 << UDRIE0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Fetches the first byte in the serial read buffer. Called by main program.
|
||||
uint8_t serial_read()
|
||||
{
|
||||
uint8_t serial_read() {
|
||||
uint8_t tail = serial_rx_buffer_tail; // Temporary serial_rx_buffer_tail (to optimize for volatile)
|
||||
if (serial_rx_buffer_head == tail) {
|
||||
return SERIAL_NO_DATA;
|
||||
|
|
@ -132,16 +133,16 @@ uint8_t serial_read()
|
|||
uint8_t data = serial_rx_buffer[tail];
|
||||
|
||||
tail++;
|
||||
if (tail == RX_RING_BUFFER) { tail = 0; }
|
||||
if (tail == RX_RING_BUFFER) {
|
||||
tail = 0;
|
||||
}
|
||||
serial_rx_buffer_tail = tail;
|
||||
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
ISR(SERIAL_RX)
|
||||
{
|
||||
ISR(SERIAL_RX) {
|
||||
uint8_t data = UDR0;
|
||||
uint8_t next_head;
|
||||
|
||||
|
|
@ -152,18 +153,23 @@ ISR(SERIAL_RX)
|
|||
case CMD_STATUS_REPORT: system_set_exec_state_flag(EXEC_STATUS_REPORT); break; // Set as true
|
||||
case CMD_CYCLE_START: system_set_exec_state_flag(EXEC_CYCLE_START); break; // Set as true
|
||||
case CMD_FEED_HOLD: system_set_exec_state_flag(EXEC_FEED_HOLD); break; // Set as true
|
||||
default :
|
||||
default:
|
||||
if (data > 0x7F) { // Real-time control characters are extended ACSII only.
|
||||
switch(data) {
|
||||
switch (data) {
|
||||
case CMD_SAFETY_DOOR: system_set_exec_state_flag(EXEC_SAFETY_DOOR); break; // Set as true
|
||||
case CMD_JOG_CANCEL:
|
||||
if (sys.state & STATE_JOG) { // Block all other states from invoking motion cancel.
|
||||
system_set_exec_state_flag(EXEC_MOTION_CANCEL);
|
||||
}
|
||||
break;
|
||||
#ifdef DEBUG
|
||||
case CMD_DEBUG_REPORT: {uint8_t sreg = SREG; cli(); bit_true(sys_rt_exec_debug,EXEC_DEBUG_REPORT); SREG = sreg;} break;
|
||||
#endif
|
||||
#ifdef DEBUG
|
||||
case CMD_DEBUG_REPORT: {
|
||||
uint8_t sreg = SREG;
|
||||
cli();
|
||||
bit_true(sys_rt_exec_debug, EXEC_DEBUG_REPORT);
|
||||
SREG = sreg;
|
||||
} break;
|
||||
#endif
|
||||
case CMD_FEED_OVR_RESET: system_set_exec_motion_override_flag(EXEC_FEED_OVR_RESET); break;
|
||||
case CMD_FEED_OVR_COARSE_PLUS: system_set_exec_motion_override_flag(EXEC_FEED_OVR_COARSE_PLUS); break;
|
||||
case CMD_FEED_OVR_COARSE_MINUS: system_set_exec_motion_override_flag(EXEC_FEED_OVR_COARSE_MINUS); break;
|
||||
|
|
@ -173,20 +179,32 @@ ISR(SERIAL_RX)
|
|||
case CMD_RAPID_OVR_MEDIUM: system_set_exec_motion_override_flag(EXEC_RAPID_OVR_MEDIUM); break;
|
||||
case CMD_RAPID_OVR_LOW: system_set_exec_motion_override_flag(EXEC_RAPID_OVR_LOW); break;
|
||||
case CMD_SPINDLE_OVR_RESET: system_set_exec_accessory_override_flag(EXEC_SPINDLE_OVR_RESET); break;
|
||||
case CMD_SPINDLE_OVR_COARSE_PLUS: system_set_exec_accessory_override_flag(EXEC_SPINDLE_OVR_COARSE_PLUS); break;
|
||||
case CMD_SPINDLE_OVR_COARSE_MINUS: system_set_exec_accessory_override_flag(EXEC_SPINDLE_OVR_COARSE_MINUS); break;
|
||||
case CMD_SPINDLE_OVR_COARSE_PLUS:
|
||||
system_set_exec_accessory_override_flag(EXEC_SPINDLE_OVR_COARSE_PLUS);
|
||||
break;
|
||||
case CMD_SPINDLE_OVR_COARSE_MINUS:
|
||||
system_set_exec_accessory_override_flag(EXEC_SPINDLE_OVR_COARSE_MINUS);
|
||||
break;
|
||||
case CMD_SPINDLE_OVR_FINE_PLUS: system_set_exec_accessory_override_flag(EXEC_SPINDLE_OVR_FINE_PLUS); break;
|
||||
case CMD_SPINDLE_OVR_FINE_MINUS: system_set_exec_accessory_override_flag(EXEC_SPINDLE_OVR_FINE_MINUS); break;
|
||||
case CMD_SPINDLE_OVR_FINE_MINUS:
|
||||
system_set_exec_accessory_override_flag(EXEC_SPINDLE_OVR_FINE_MINUS);
|
||||
break;
|
||||
case CMD_SPINDLE_OVR_STOP: system_set_exec_accessory_override_flag(EXEC_SPINDLE_OVR_STOP); break;
|
||||
case CMD_COOLANT_FLOOD_OVR_TOGGLE: system_set_exec_accessory_override_flag(EXEC_COOLANT_FLOOD_OVR_TOGGLE); break;
|
||||
#ifdef ENABLE_M7
|
||||
case CMD_COOLANT_MIST_OVR_TOGGLE: system_set_exec_accessory_override_flag(EXEC_COOLANT_MIST_OVR_TOGGLE); break;
|
||||
#endif
|
||||
case CMD_COOLANT_FLOOD_OVR_TOGGLE:
|
||||
system_set_exec_accessory_override_flag(EXEC_COOLANT_FLOOD_OVR_TOGGLE);
|
||||
break;
|
||||
#ifdef ENABLE_M7
|
||||
case CMD_COOLANT_MIST_OVR_TOGGLE:
|
||||
system_set_exec_accessory_override_flag(EXEC_COOLANT_MIST_OVR_TOGGLE);
|
||||
break;
|
||||
#endif
|
||||
}
|
||||
// Throw away any unfound extended-ASCII character by not passing it to the serial buffer.
|
||||
} else { // Write character to buffer
|
||||
next_head = serial_rx_buffer_head + 1;
|
||||
if (next_head == RX_RING_BUFFER) { next_head = 0; }
|
||||
if (next_head == RX_RING_BUFFER) {
|
||||
next_head = 0;
|
||||
}
|
||||
|
||||
// Write data to buffer unless it is full.
|
||||
if (next_head != serial_rx_buffer_tail) {
|
||||
|
|
@ -197,8 +215,6 @@ ISR(SERIAL_RX)
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
void serial_reset_read_buffer()
|
||||
{
|
||||
void serial_reset_read_buffer() {
|
||||
serial_rx_buffer_tail = serial_rx_buffer_head;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,21 +22,19 @@
|
|||
#ifndef serial_h
|
||||
#define serial_h
|
||||
|
||||
|
||||
#ifndef RX_BUFFER_SIZE
|
||||
#define RX_BUFFER_SIZE 128
|
||||
#define RX_BUFFER_SIZE 128
|
||||
#endif
|
||||
#ifndef TX_BUFFER_SIZE
|
||||
#ifdef USE_LINE_NUMBERS
|
||||
#define TX_BUFFER_SIZE 112
|
||||
#else
|
||||
#define TX_BUFFER_SIZE 104
|
||||
#endif
|
||||
#ifdef USE_LINE_NUMBERS
|
||||
#define TX_BUFFER_SIZE 112
|
||||
#else
|
||||
#define TX_BUFFER_SIZE 104
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#define SERIAL_NO_DATA 0xff
|
||||
|
||||
|
||||
void serial_init();
|
||||
|
||||
// Writes one byte to the TX serial buffer. Called by main program.
|
||||
|
|
|
|||
279
grbl/settings.c
279
grbl/settings.c
|
|
@ -23,7 +23,7 @@
|
|||
|
||||
settings_t settings;
|
||||
|
||||
const __flash settings_t defaults = {\
|
||||
const __flash settings_t defaults = {
|
||||
.pulse_microseconds = DEFAULT_STEP_PULSE_MICROSECONDS,
|
||||
.stepper_idle_lock_time = DEFAULT_STEPPER_IDLE_LOCK_TIME,
|
||||
.step_invert_mask = DEFAULT_STEPPING_INVERT_MASK,
|
||||
|
|
@ -38,14 +38,10 @@ const __flash settings_t defaults = {\
|
|||
.homing_seek_rate = DEFAULT_HOMING_SEEK_RATE,
|
||||
.homing_debounce_delay = DEFAULT_HOMING_DEBOUNCE_DELAY,
|
||||
.homing_pulloff = DEFAULT_HOMING_PULLOFF,
|
||||
.flags = (DEFAULT_REPORT_INCHES << BIT_REPORT_INCHES) | \
|
||||
(DEFAULT_LASER_MODE << BIT_LASER_MODE) | \
|
||||
(DEFAULT_INVERT_ST_ENABLE << BIT_INVERT_ST_ENABLE) | \
|
||||
(DEFAULT_HARD_LIMIT_ENABLE << BIT_HARD_LIMIT_ENABLE) | \
|
||||
(DEFAULT_HOMING_ENABLE << BIT_HOMING_ENABLE) | \
|
||||
(DEFAULT_SOFT_LIMIT_ENABLE << BIT_SOFT_LIMIT_ENABLE) | \
|
||||
(DEFAULT_INVERT_LIMIT_PINS << BIT_INVERT_LIMIT_PINS) | \
|
||||
(DEFAULT_INVERT_PROBE_PIN << BIT_INVERT_PROBE_PIN),
|
||||
.flags = (DEFAULT_REPORT_INCHES << BIT_REPORT_INCHES) | (DEFAULT_LASER_MODE << BIT_LASER_MODE) |
|
||||
(DEFAULT_INVERT_ST_ENABLE << BIT_INVERT_ST_ENABLE) | (DEFAULT_HARD_LIMIT_ENABLE << BIT_HARD_LIMIT_ENABLE) |
|
||||
(DEFAULT_HOMING_ENABLE << BIT_HOMING_ENABLE) | (DEFAULT_SOFT_LIMIT_ENABLE << BIT_SOFT_LIMIT_ENABLE) |
|
||||
(DEFAULT_INVERT_LIMIT_PINS << BIT_INVERT_LIMIT_PINS) | (DEFAULT_INVERT_PROBE_PIN << BIT_INVERT_PROBE_PIN),
|
||||
.steps_per_mm[X_AXIS] = DEFAULT_X_STEPS_PER_MM,
|
||||
.steps_per_mm[Y_AXIS] = DEFAULT_Y_STEPS_PER_MM,
|
||||
.steps_per_mm[Z_AXIS] = DEFAULT_Z_STEPS_PER_MM,
|
||||
|
|
@ -59,47 +55,38 @@ const __flash settings_t defaults = {\
|
|||
.max_travel[Y_AXIS] = (-DEFAULT_Y_MAX_TRAVEL),
|
||||
.max_travel[Z_AXIS] = (-DEFAULT_Z_MAX_TRAVEL)};
|
||||
|
||||
|
||||
// Method to store startup lines into EEPROM
|
||||
void settings_store_startup_line(uint8_t n, char *line)
|
||||
{
|
||||
#ifdef FORCE_BUFFER_SYNC_DURING_EEPROM_WRITE
|
||||
void settings_store_startup_line(uint8_t n, char *line) {
|
||||
#ifdef FORCE_BUFFER_SYNC_DURING_EEPROM_WRITE
|
||||
protocol_buffer_synchronize(); // A startup line may contain a motion and be executing.
|
||||
#endif
|
||||
uint32_t addr = n*(LINE_BUFFER_SIZE+1)+EEPROM_ADDR_STARTUP_BLOCK;
|
||||
memcpy_to_eeprom_with_checksum(addr,(char*)line, LINE_BUFFER_SIZE);
|
||||
#endif
|
||||
uint32_t addr = n * (LINE_BUFFER_SIZE + 1) + EEPROM_ADDR_STARTUP_BLOCK;
|
||||
memcpy_to_eeprom_with_checksum(addr, (char *)line, LINE_BUFFER_SIZE);
|
||||
}
|
||||
|
||||
|
||||
// Method to store build info into EEPROM
|
||||
// NOTE: This function can only be called in IDLE state.
|
||||
void settings_store_build_info(char *line)
|
||||
{
|
||||
void settings_store_build_info(char *line) {
|
||||
// Build info can only be stored when state is IDLE.
|
||||
memcpy_to_eeprom_with_checksum(EEPROM_ADDR_BUILD_INFO,(char*)line, LINE_BUFFER_SIZE);
|
||||
memcpy_to_eeprom_with_checksum(EEPROM_ADDR_BUILD_INFO, (char *)line, LINE_BUFFER_SIZE);
|
||||
}
|
||||
|
||||
|
||||
// Method to store coord data parameters into EEPROM
|
||||
void settings_write_coord_data(uint8_t coord_select, float *coord_data)
|
||||
{
|
||||
#ifdef FORCE_BUFFER_SYNC_DURING_EEPROM_WRITE
|
||||
void settings_write_coord_data(uint8_t coord_select, float *coord_data) {
|
||||
#ifdef FORCE_BUFFER_SYNC_DURING_EEPROM_WRITE
|
||||
protocol_buffer_synchronize();
|
||||
#endif
|
||||
uint32_t addr = coord_select*(sizeof(float)*N_AXIS+1) + EEPROM_ADDR_PARAMETERS;
|
||||
memcpy_to_eeprom_with_checksum(addr,(char*)coord_data, sizeof(float)*N_AXIS);
|
||||
#endif
|
||||
uint32_t addr = coord_select * (sizeof(float) * N_AXIS + 1) + EEPROM_ADDR_PARAMETERS;
|
||||
memcpy_to_eeprom_with_checksum(addr, (char *)coord_data, sizeof(float) * N_AXIS);
|
||||
}
|
||||
|
||||
|
||||
// Method to store Grbl global settings struct and version number into EEPROM
|
||||
// NOTE: This function can only be called in IDLE state.
|
||||
void write_global_settings()
|
||||
{
|
||||
void write_global_settings() {
|
||||
eeprom_put_char(0, SETTINGS_VERSION);
|
||||
memcpy_to_eeprom_with_checksum(EEPROM_ADDR_GLOBAL, (char*)&settings, sizeof(settings_t));
|
||||
memcpy_to_eeprom_with_checksum(EEPROM_ADDR_GLOBAL, (char *)&settings, sizeof(settings_t));
|
||||
}
|
||||
|
||||
|
||||
// Method to restore EEPROM-saved Grbl global settings back to defaults.
|
||||
void settings_restore(uint8_t restore_flag) {
|
||||
if (restore_flag & SETTINGS_RESTORE_DEFAULTS) {
|
||||
|
|
@ -111,87 +98,83 @@ void settings_restore(uint8_t restore_flag) {
|
|||
uint8_t idx;
|
||||
float coord_data[N_AXIS];
|
||||
memset(&coord_data, 0, sizeof(coord_data));
|
||||
for (idx=0; idx <= SETTING_INDEX_NCOORD; idx++) { settings_write_coord_data(idx, coord_data); }
|
||||
for (idx = 0; idx <= SETTING_INDEX_NCOORD; idx++) {
|
||||
settings_write_coord_data(idx, coord_data);
|
||||
}
|
||||
}
|
||||
|
||||
if (restore_flag & SETTINGS_RESTORE_STARTUP_LINES) {
|
||||
#if N_STARTUP_LINE > 0
|
||||
#if N_STARTUP_LINE > 0
|
||||
eeprom_put_char(EEPROM_ADDR_STARTUP_BLOCK, 0);
|
||||
eeprom_put_char(EEPROM_ADDR_STARTUP_BLOCK+1, 0); // Checksum
|
||||
#endif
|
||||
#if N_STARTUP_LINE > 1
|
||||
eeprom_put_char(EEPROM_ADDR_STARTUP_BLOCK+(LINE_BUFFER_SIZE+1), 0);
|
||||
eeprom_put_char(EEPROM_ADDR_STARTUP_BLOCK+(LINE_BUFFER_SIZE+2), 0); // Checksum
|
||||
#endif
|
||||
eeprom_put_char(EEPROM_ADDR_STARTUP_BLOCK + 1, 0); // Checksum
|
||||
#endif
|
||||
#if N_STARTUP_LINE > 1
|
||||
eeprom_put_char(EEPROM_ADDR_STARTUP_BLOCK + (LINE_BUFFER_SIZE + 1), 0);
|
||||
eeprom_put_char(EEPROM_ADDR_STARTUP_BLOCK + (LINE_BUFFER_SIZE + 2), 0); // Checksum
|
||||
#endif
|
||||
}
|
||||
|
||||
if (restore_flag & SETTINGS_RESTORE_BUILD_INFO) {
|
||||
eeprom_put_char(EEPROM_ADDR_BUILD_INFO , 0);
|
||||
eeprom_put_char(EEPROM_ADDR_BUILD_INFO+1 , 0); // Checksum
|
||||
eeprom_put_char(EEPROM_ADDR_BUILD_INFO, 0);
|
||||
eeprom_put_char(EEPROM_ADDR_BUILD_INFO + 1, 0); // Checksum
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Reads startup line from EEPROM. Updated pointed line string data.
|
||||
uint8_t settings_read_startup_line(uint8_t n, char *line)
|
||||
{
|
||||
uint32_t addr = n*(LINE_BUFFER_SIZE+1)+EEPROM_ADDR_STARTUP_BLOCK;
|
||||
if (!(memcpy_from_eeprom_with_checksum((char*)line, addr, LINE_BUFFER_SIZE))) {
|
||||
uint8_t settings_read_startup_line(uint8_t n, char *line) {
|
||||
uint32_t addr = n * (LINE_BUFFER_SIZE + 1) + EEPROM_ADDR_STARTUP_BLOCK;
|
||||
if (!(memcpy_from_eeprom_with_checksum((char *)line, addr, LINE_BUFFER_SIZE))) {
|
||||
// Reset line with default value
|
||||
line[0] = 0; // Empty line
|
||||
settings_store_startup_line(n, line);
|
||||
return(false);
|
||||
return (false);
|
||||
}
|
||||
return(true);
|
||||
return (true);
|
||||
}
|
||||
|
||||
|
||||
// Reads startup line from EEPROM. Updated pointed line string data.
|
||||
uint8_t settings_read_build_info(char *line)
|
||||
{
|
||||
if (!(memcpy_from_eeprom_with_checksum((char*)line, EEPROM_ADDR_BUILD_INFO, LINE_BUFFER_SIZE))) {
|
||||
uint8_t settings_read_build_info(char *line) {
|
||||
if (!(memcpy_from_eeprom_with_checksum((char *)line, EEPROM_ADDR_BUILD_INFO, LINE_BUFFER_SIZE))) {
|
||||
// Reset line with default value
|
||||
line[0] = 0; // Empty line
|
||||
settings_store_build_info(line);
|
||||
return(false);
|
||||
return (false);
|
||||
}
|
||||
return(true);
|
||||
return (true);
|
||||
}
|
||||
|
||||
|
||||
// Read selected coordinate data from EEPROM. Updates pointed coord_data value.
|
||||
uint8_t settings_read_coord_data(uint8_t coord_select, float *coord_data)
|
||||
{
|
||||
uint32_t addr = coord_select*(sizeof(float)*N_AXIS+1) + EEPROM_ADDR_PARAMETERS;
|
||||
if (!(memcpy_from_eeprom_with_checksum((char*)coord_data, addr, sizeof(float)*N_AXIS))) {
|
||||
uint8_t settings_read_coord_data(uint8_t coord_select, float *coord_data) {
|
||||
uint32_t addr = coord_select * (sizeof(float) * N_AXIS + 1) + EEPROM_ADDR_PARAMETERS;
|
||||
if (!(memcpy_from_eeprom_with_checksum((char *)coord_data, addr, sizeof(float) * N_AXIS))) {
|
||||
// Reset with default zero vector
|
||||
clear_vector_float(coord_data);
|
||||
settings_write_coord_data(coord_select,coord_data);
|
||||
return(false);
|
||||
settings_write_coord_data(coord_select, coord_data);
|
||||
return (false);
|
||||
}
|
||||
return(true);
|
||||
return (true);
|
||||
}
|
||||
|
||||
|
||||
// Reads Grbl global settings struct from EEPROM.
|
||||
uint8_t read_global_settings() {
|
||||
// Check version-byte of eeprom
|
||||
uint8_t version = eeprom_get_char(0);
|
||||
if (version == SETTINGS_VERSION) {
|
||||
// Read settings-record and check checksum
|
||||
if (!(memcpy_from_eeprom_with_checksum((char*)&settings, EEPROM_ADDR_GLOBAL, sizeof(settings_t)))) {
|
||||
return(false);
|
||||
if (!(memcpy_from_eeprom_with_checksum((char *)&settings, EEPROM_ADDR_GLOBAL, sizeof(settings_t)))) {
|
||||
return (false);
|
||||
}
|
||||
} else {
|
||||
return(false);
|
||||
return (false);
|
||||
}
|
||||
return(true);
|
||||
return (true);
|
||||
}
|
||||
|
||||
|
||||
// A helper method to set settings from command line
|
||||
uint8_t settings_store_global_setting(uint8_t parameter, float value) {
|
||||
if (value < 0.0) { return(STATUS_NEGATIVE_VALUE); }
|
||||
if (value < 0.0) {
|
||||
return (STATUS_NEGATIVE_VALUE);
|
||||
}
|
||||
if (parameter >= AXIS_SETTINGS_START_VAL) {
|
||||
// Store axis configuration. Axis numbering sequence set by AXIS_SETTING defines.
|
||||
// NOTE: Ensure the setting index corresponds to the report.c settings printout.
|
||||
|
|
@ -202,35 +185,46 @@ uint8_t settings_store_global_setting(uint8_t parameter, float value) {
|
|||
// Valid axis setting found.
|
||||
switch (set_idx) {
|
||||
case 0:
|
||||
#ifdef MAX_STEP_RATE_HZ
|
||||
if (value*settings.max_rate[parameter] > (MAX_STEP_RATE_HZ*60.0)) { return(STATUS_MAX_STEP_RATE_EXCEEDED); }
|
||||
#endif
|
||||
#ifdef MAX_STEP_RATE_HZ
|
||||
if (value * settings.max_rate[parameter] > (MAX_STEP_RATE_HZ * 60.0)) {
|
||||
return (STATUS_MAX_STEP_RATE_EXCEEDED);
|
||||
}
|
||||
#endif
|
||||
settings.steps_per_mm[parameter] = value;
|
||||
break;
|
||||
case 1:
|
||||
#ifdef MAX_STEP_RATE_HZ
|
||||
if (value*settings.steps_per_mm[parameter] > (MAX_STEP_RATE_HZ*60.0)) { return(STATUS_MAX_STEP_RATE_EXCEEDED); }
|
||||
#endif
|
||||
#ifdef MAX_STEP_RATE_HZ
|
||||
if (value * settings.steps_per_mm[parameter] > (MAX_STEP_RATE_HZ * 60.0)) {
|
||||
return (STATUS_MAX_STEP_RATE_EXCEEDED);
|
||||
}
|
||||
#endif
|
||||
settings.max_rate[parameter] = value;
|
||||
break;
|
||||
case 2: settings.acceleration[parameter] = value*60*60; break; // Convert to mm/min^2 for grbl internal use.
|
||||
case 2:
|
||||
settings.acceleration[parameter] = value * 60 * 60;
|
||||
break; // Convert to mm/min^2 for grbl internal use.
|
||||
case 3: settings.max_travel[parameter] = -value; break; // Store as negative for grbl internal use.
|
||||
}
|
||||
break; // Exit while-loop after setting has been configured and proceed to the EEPROM write call.
|
||||
} else {
|
||||
set_idx++;
|
||||
// If axis index greater than N_AXIS or setting index greater than number of axis settings, error out.
|
||||
if ((parameter < AXIS_SETTINGS_INCREMENT) || (set_idx == AXIS_N_SETTINGS)) { return(STATUS_INVALID_STATEMENT); }
|
||||
if ((parameter < AXIS_SETTINGS_INCREMENT) || (set_idx == AXIS_N_SETTINGS)) {
|
||||
return (STATUS_INVALID_STATEMENT);
|
||||
}
|
||||
parameter -= AXIS_SETTINGS_INCREMENT;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Store non-axis Grbl settings
|
||||
uint8_t int_value = trunc(value);
|
||||
switch(parameter) {
|
||||
switch (parameter) {
|
||||
case 0:
|
||||
if (int_value < 3) { return(STATUS_SETTING_STEP_PULSE_MIN); }
|
||||
settings.pulse_microseconds = int_value; break;
|
||||
if (int_value < 3) {
|
||||
return (STATUS_SETTING_STEP_PULSE_MIN);
|
||||
}
|
||||
settings.pulse_microseconds = int_value;
|
||||
break;
|
||||
case 1: settings.stepper_idle_lock_time = int_value; break;
|
||||
case 2:
|
||||
settings.step_invert_mask = int_value;
|
||||
|
|
@ -241,40 +235,60 @@ uint8_t settings_store_global_setting(uint8_t parameter, float value) {
|
|||
st_generate_step_dir_invert_masks(); // Regenerate step and direction port invert masks.
|
||||
break;
|
||||
case 4: // Reset to ensure change. Immediate re-init may cause problems.
|
||||
if (int_value) { settings.flags |= BITFLAG_INVERT_ST_ENABLE; }
|
||||
else { settings.flags &= ~BITFLAG_INVERT_ST_ENABLE; }
|
||||
if (int_value) {
|
||||
settings.flags |= BITFLAG_INVERT_ST_ENABLE;
|
||||
} else {
|
||||
settings.flags &= ~BITFLAG_INVERT_ST_ENABLE;
|
||||
}
|
||||
break;
|
||||
case 5: // Reset to ensure change. Immediate re-init may cause problems.
|
||||
if (int_value) { settings.flags |= BITFLAG_INVERT_LIMIT_PINS; }
|
||||
else { settings.flags &= ~BITFLAG_INVERT_LIMIT_PINS; }
|
||||
if (int_value) {
|
||||
settings.flags |= BITFLAG_INVERT_LIMIT_PINS;
|
||||
} else {
|
||||
settings.flags &= ~BITFLAG_INVERT_LIMIT_PINS;
|
||||
}
|
||||
break;
|
||||
case 6: // Reset to ensure change. Immediate re-init may cause problems.
|
||||
if (int_value) { settings.flags |= BITFLAG_INVERT_PROBE_PIN; }
|
||||
else { settings.flags &= ~BITFLAG_INVERT_PROBE_PIN; }
|
||||
if (int_value) {
|
||||
settings.flags |= BITFLAG_INVERT_PROBE_PIN;
|
||||
} else {
|
||||
settings.flags &= ~BITFLAG_INVERT_PROBE_PIN;
|
||||
}
|
||||
probe_configure_invert_mask(false);
|
||||
break;
|
||||
case 10: settings.status_report_mask = int_value; break;
|
||||
case 11: settings.junction_deviation = value; break;
|
||||
case 12: settings.arc_tolerance = value; break;
|
||||
case 13:
|
||||
if (int_value) { settings.flags |= BITFLAG_REPORT_INCHES; }
|
||||
else { settings.flags &= ~BITFLAG_REPORT_INCHES; }
|
||||
if (int_value) {
|
||||
settings.flags |= BITFLAG_REPORT_INCHES;
|
||||
} else {
|
||||
settings.flags &= ~BITFLAG_REPORT_INCHES;
|
||||
}
|
||||
system_flag_wco_change(); // Make sure WCO is immediately updated.
|
||||
break;
|
||||
case 20:
|
||||
if (int_value) {
|
||||
if (bit_isfalse(settings.flags, BITFLAG_HOMING_ENABLE)) { return(STATUS_SOFT_LIMIT_ERROR); }
|
||||
if (bit_isfalse(settings.flags, BITFLAG_HOMING_ENABLE)) {
|
||||
return (STATUS_SOFT_LIMIT_ERROR);
|
||||
}
|
||||
settings.flags |= BITFLAG_SOFT_LIMIT_ENABLE;
|
||||
} else { settings.flags &= ~BITFLAG_SOFT_LIMIT_ENABLE; }
|
||||
} else {
|
||||
settings.flags &= ~BITFLAG_SOFT_LIMIT_ENABLE;
|
||||
}
|
||||
break;
|
||||
case 21:
|
||||
if (int_value) { settings.flags |= BITFLAG_HARD_LIMIT_ENABLE; }
|
||||
else { settings.flags &= ~BITFLAG_HARD_LIMIT_ENABLE; }
|
||||
if (int_value) {
|
||||
settings.flags |= BITFLAG_HARD_LIMIT_ENABLE;
|
||||
} else {
|
||||
settings.flags &= ~BITFLAG_HARD_LIMIT_ENABLE;
|
||||
}
|
||||
limits_init(); // Re-init to immediately change. NOTE: Nice to have but could be problematic later.
|
||||
break;
|
||||
case 22:
|
||||
if (int_value) { settings.flags |= BITFLAG_HOMING_ENABLE; }
|
||||
else {
|
||||
if (int_value) {
|
||||
settings.flags |= BITFLAG_HOMING_ENABLE;
|
||||
} else {
|
||||
settings.flags &= ~BITFLAG_HOMING_ENABLE;
|
||||
settings.flags &= ~BITFLAG_SOFT_LIMIT_ENABLE; // Force disable soft-limits.
|
||||
}
|
||||
|
|
@ -284,57 +298,70 @@ uint8_t settings_store_global_setting(uint8_t parameter, float value) {
|
|||
case 25: settings.homing_seek_rate = value; break;
|
||||
case 26: settings.homing_debounce_delay = int_value; break;
|
||||
case 27: settings.homing_pulloff = value; break;
|
||||
case 30: settings.rpm_max = value; spindle_init(); break; // Re-initialize spindle rpm calibration
|
||||
case 31: settings.rpm_min = value; spindle_init(); break; // Re-initialize spindle rpm calibration
|
||||
case 30:
|
||||
settings.rpm_max = value;
|
||||
spindle_init();
|
||||
break; // Re-initialize spindle rpm calibration
|
||||
case 31:
|
||||
settings.rpm_min = value;
|
||||
spindle_init();
|
||||
break; // Re-initialize spindle rpm calibration
|
||||
case 32:
|
||||
#ifdef VARIABLE_SPINDLE
|
||||
if (int_value) { settings.flags |= BITFLAG_LASER_MODE; }
|
||||
else { settings.flags &= ~BITFLAG_LASER_MODE; }
|
||||
#else
|
||||
return(STATUS_SETTING_DISABLED_LASER);
|
||||
#endif
|
||||
#ifdef VARIABLE_SPINDLE
|
||||
if (int_value) {
|
||||
settings.flags |= BITFLAG_LASER_MODE;
|
||||
} else {
|
||||
settings.flags &= ~BITFLAG_LASER_MODE;
|
||||
}
|
||||
#else
|
||||
return (STATUS_SETTING_DISABLED_LASER);
|
||||
#endif
|
||||
break;
|
||||
default:
|
||||
return(STATUS_INVALID_STATEMENT);
|
||||
default: return (STATUS_INVALID_STATEMENT);
|
||||
}
|
||||
}
|
||||
write_global_settings();
|
||||
return(STATUS_OK);
|
||||
return (STATUS_OK);
|
||||
}
|
||||
|
||||
|
||||
// Initialize the config subsystem
|
||||
void settings_init() {
|
||||
if(!read_global_settings()) {
|
||||
if (!read_global_settings()) {
|
||||
report_status_message(STATUS_SETTING_READ_FAIL);
|
||||
settings_restore(SETTINGS_RESTORE_ALL); // Force restore all EEPROM data.
|
||||
report_grbl_settings();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Returns step pin mask according to Grbl internal axis indexing.
|
||||
uint8_t get_step_pin_mask(uint8_t axis_idx)
|
||||
{
|
||||
if ( axis_idx == X_AXIS ) { return((1<<X_STEP_BIT)); }
|
||||
if ( axis_idx == Y_AXIS ) { return((1<<Y_STEP_BIT)); }
|
||||
return((1<<Z_STEP_BIT));
|
||||
uint8_t get_step_pin_mask(uint8_t axis_idx) {
|
||||
if (axis_idx == X_AXIS) {
|
||||
return ((1 << X_STEP_BIT));
|
||||
}
|
||||
if (axis_idx == Y_AXIS) {
|
||||
return ((1 << Y_STEP_BIT));
|
||||
}
|
||||
return ((1 << Z_STEP_BIT));
|
||||
}
|
||||
|
||||
|
||||
// Returns direction pin mask according to Grbl internal axis indexing.
|
||||
uint8_t get_direction_pin_mask(uint8_t axis_idx)
|
||||
{
|
||||
if ( axis_idx == X_AXIS ) { return((1<<X_DIRECTION_BIT)); }
|
||||
if ( axis_idx == Y_AXIS ) { return((1<<Y_DIRECTION_BIT)); }
|
||||
return((1<<Z_DIRECTION_BIT));
|
||||
uint8_t get_direction_pin_mask(uint8_t axis_idx) {
|
||||
if (axis_idx == X_AXIS) {
|
||||
return ((1 << X_DIRECTION_BIT));
|
||||
}
|
||||
if (axis_idx == Y_AXIS) {
|
||||
return ((1 << Y_DIRECTION_BIT));
|
||||
}
|
||||
return ((1 << Z_DIRECTION_BIT));
|
||||
}
|
||||
|
||||
|
||||
// Returns limit pin mask according to Grbl internal axis indexing.
|
||||
uint8_t get_limit_pin_mask(uint8_t axis_idx)
|
||||
{
|
||||
if ( axis_idx == X_AXIS ) { return((1<<X_LIMIT_BIT)); }
|
||||
if ( axis_idx == Y_AXIS ) { return((1<<Y_LIMIT_BIT)); }
|
||||
return((1<<Z_LIMIT_BIT));
|
||||
uint8_t get_limit_pin_mask(uint8_t axis_idx) {
|
||||
if (axis_idx == X_AXIS) {
|
||||
return ((1 << X_LIMIT_BIT));
|
||||
}
|
||||
if (axis_idx == Y_AXIS) {
|
||||
return ((1 << Y_LIMIT_BIT));
|
||||
}
|
||||
return ((1 << Z_LIMIT_BIT));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,7 +24,6 @@
|
|||
|
||||
#include "grbl.h"
|
||||
|
||||
|
||||
// Version of the EEPROM data. Will be used to migrate existing data from older versions of Grbl
|
||||
// when firmware is upgraded. Always stored in byte 0 of eeprom
|
||||
#define SETTINGS_VERSION 10 // NOTE: Check settings_reset() when moving to next version.
|
||||
|
|
@ -58,7 +57,7 @@
|
|||
#define SETTINGS_RESTORE_STARTUP_LINES bit(2)
|
||||
#define SETTINGS_RESTORE_BUILD_INFO bit(3)
|
||||
#ifndef SETTINGS_RESTORE_ALL
|
||||
#define SETTINGS_RESTORE_ALL 0xFF // All bitflags
|
||||
#define SETTINGS_RESTORE_ALL 0xFF // All bitflags
|
||||
#endif
|
||||
|
||||
// Define EEPROM memory address location values for Grbl settings and parameters
|
||||
|
|
@ -72,10 +71,10 @@
|
|||
|
||||
// Define EEPROM address indexing for coordinate parameters
|
||||
#define N_COORDINATE_SYSTEM 6 // Number of supported work coordinate systems (from index 1)
|
||||
#define SETTING_INDEX_NCOORD N_COORDINATE_SYSTEM+1 // Total number of system stored (from index 0)
|
||||
#define SETTING_INDEX_NCOORD N_COORDINATE_SYSTEM + 1 // Total number of system stored (from index 0)
|
||||
// NOTE: Work coordinate indices are (0=G54, 1=G55, ... , 6=G59)
|
||||
#define SETTING_INDEX_G28 N_COORDINATE_SYSTEM // Home position 1
|
||||
#define SETTING_INDEX_G30 N_COORDINATE_SYSTEM+1 // Home position 2
|
||||
#define SETTING_INDEX_G30 N_COORDINATE_SYSTEM + 1 // Home position 2
|
||||
// #define SETTING_INDEX_G92 N_COORDINATE_SYSTEM+2 // Coordinate offset (G92.2,G92.3 not supported)
|
||||
|
||||
// Define Grbl axis settings numbering scheme. Starts at START_VAL, every INCREMENT, over N_SETTINGS.
|
||||
|
|
@ -111,6 +110,7 @@ typedef struct {
|
|||
uint16_t homing_debounce_delay;
|
||||
float homing_pulloff;
|
||||
} settings_t;
|
||||
|
||||
extern settings_t settings;
|
||||
|
||||
// Initialize the configuration subsystem (load settings from EEPROM)
|
||||
|
|
@ -149,5 +149,4 @@ uint8_t get_direction_pin_mask(uint8_t i);
|
|||
// Returns the limit pin mask according to Grbl's internal axis numbering
|
||||
uint8_t get_limit_pin_mask(uint8_t i);
|
||||
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -21,135 +21,135 @@
|
|||
|
||||
#include "grbl.h"
|
||||
|
||||
|
||||
#ifdef VARIABLE_SPINDLE
|
||||
static float pwm_gradient; // Precalulated value to speed up rpm to PWM conversions.
|
||||
static float pwm_gradient; // Precalulated value to speed up rpm to PWM conversions.
|
||||
#endif
|
||||
|
||||
|
||||
void spindle_init()
|
||||
{
|
||||
#ifdef VARIABLE_SPINDLE
|
||||
void spindle_init() {
|
||||
#ifdef VARIABLE_SPINDLE
|
||||
// Configure variable spindle PWM and enable pin, if requried. On the Uno, PWM and enable are
|
||||
// combined unless configured otherwise.
|
||||
SPINDLE_PWM_DDR |= (1<<SPINDLE_PWM_BIT); // Configure as PWM output pin.
|
||||
SPINDLE_PWM_DDR |= (1 << SPINDLE_PWM_BIT); // Configure as PWM output pin.
|
||||
SPINDLE_TCCRA_REGISTER = SPINDLE_TCCRA_INIT_MASK; // Configure PWM output compare timer
|
||||
SPINDLE_TCCRB_REGISTER = SPINDLE_TCCRB_INIT_MASK;
|
||||
#ifdef USE_SPINDLE_DIR_AS_ENABLE_PIN
|
||||
SPINDLE_ENABLE_DDR |= (1<<SPINDLE_ENABLE_BIT); // Configure as output pin.
|
||||
#else
|
||||
#ifndef ENABLE_DUAL_AXIS
|
||||
SPINDLE_DIRECTION_DDR |= (1<<SPINDLE_DIRECTION_BIT); // Configure as output pin.
|
||||
#endif
|
||||
#endif
|
||||
pwm_gradient = SPINDLE_PWM_RANGE/(settings.rpm_max-settings.rpm_min);
|
||||
#else
|
||||
SPINDLE_ENABLE_DDR |= (1<<SPINDLE_ENABLE_BIT); // Configure as output pin.
|
||||
#ifndef ENABLE_DUAL_AXIS
|
||||
SPINDLE_DIRECTION_DDR |= (1<<SPINDLE_DIRECTION_BIT); // Configure as output pin.
|
||||
#endif
|
||||
#endif
|
||||
#ifdef USE_SPINDLE_DIR_AS_ENABLE_PIN
|
||||
SPINDLE_ENABLE_DDR |= (1 << SPINDLE_ENABLE_BIT); // Configure as output pin.
|
||||
#else
|
||||
#ifndef ENABLE_DUAL_AXIS
|
||||
SPINDLE_DIRECTION_DDR |= (1 << SPINDLE_DIRECTION_BIT); // Configure as output pin.
|
||||
#endif
|
||||
#endif
|
||||
pwm_gradient = SPINDLE_PWM_RANGE / (settings.rpm_max - settings.rpm_min);
|
||||
#else
|
||||
SPINDLE_ENABLE_DDR |= (1 << SPINDLE_ENABLE_BIT); // Configure as output pin.
|
||||
#ifndef ENABLE_DUAL_AXIS
|
||||
SPINDLE_DIRECTION_DDR |= (1 << SPINDLE_DIRECTION_BIT); // Configure as output pin.
|
||||
#endif
|
||||
#endif
|
||||
|
||||
spindle_stop();
|
||||
}
|
||||
|
||||
|
||||
uint8_t spindle_get_state()
|
||||
{
|
||||
#ifdef VARIABLE_SPINDLE
|
||||
#ifdef USE_SPINDLE_DIR_AS_ENABLE_PIN
|
||||
// No spindle direction output pin.
|
||||
#ifdef INVERT_SPINDLE_ENABLE_PIN
|
||||
if (bit_isfalse(SPINDLE_ENABLE_PORT,(1<<SPINDLE_ENABLE_BIT))) { return(SPINDLE_STATE_CW); }
|
||||
#else
|
||||
if (bit_istrue(SPINDLE_ENABLE_PORT,(1<<SPINDLE_ENABLE_BIT))) { return(SPINDLE_STATE_CW); }
|
||||
#endif
|
||||
#else
|
||||
if (SPINDLE_TCCRA_REGISTER & (1<<SPINDLE_COMB_BIT)) { // Check if PWM is enabled.
|
||||
#ifdef ENABLE_DUAL_AXIS
|
||||
return(SPINDLE_STATE_CW);
|
||||
#else
|
||||
if (SPINDLE_DIRECTION_PORT & (1<<SPINDLE_DIRECTION_BIT)) { return(SPINDLE_STATE_CCW); }
|
||||
else { return(SPINDLE_STATE_CW); }
|
||||
#endif
|
||||
uint8_t spindle_get_state() {
|
||||
#ifdef VARIABLE_SPINDLE
|
||||
#ifdef USE_SPINDLE_DIR_AS_ENABLE_PIN
|
||||
// No spindle direction output pin.
|
||||
#ifdef INVERT_SPINDLE_ENABLE_PIN
|
||||
if (bit_isfalse(SPINDLE_ENABLE_PORT, (1 << SPINDLE_ENABLE_BIT))) {
|
||||
return (SPINDLE_STATE_CW);
|
||||
}
|
||||
#endif
|
||||
#else
|
||||
#ifdef INVERT_SPINDLE_ENABLE_PIN
|
||||
if (bit_isfalse(SPINDLE_ENABLE_PORT,(1<<SPINDLE_ENABLE_BIT))) {
|
||||
#else
|
||||
if (bit_istrue(SPINDLE_ENABLE_PORT,(1<<SPINDLE_ENABLE_BIT))) {
|
||||
#endif
|
||||
#ifdef ENABLE_DUAL_AXIS
|
||||
return(SPINDLE_STATE_CW);
|
||||
#else
|
||||
if (SPINDLE_DIRECTION_PORT & (1<<SPINDLE_DIRECTION_BIT)) { return(SPINDLE_STATE_CCW); }
|
||||
else { return(SPINDLE_STATE_CW); }
|
||||
#endif
|
||||
#else
|
||||
if (bit_istrue(SPINDLE_ENABLE_PORT, (1 << SPINDLE_ENABLE_BIT))) {
|
||||
return (SPINDLE_STATE_CW);
|
||||
}
|
||||
#endif
|
||||
return(SPINDLE_STATE_DISABLE);
|
||||
#endif
|
||||
#else
|
||||
if (SPINDLE_TCCRA_REGISTER & (1 << SPINDLE_COMB_BIT)) { // Check if PWM is enabled.
|
||||
#ifdef ENABLE_DUAL_AXIS
|
||||
return (SPINDLE_STATE_CW);
|
||||
#else
|
||||
if (SPINDLE_DIRECTION_PORT & (1 << SPINDLE_DIRECTION_BIT)) {
|
||||
return (SPINDLE_STATE_CCW);
|
||||
} else {
|
||||
return (SPINDLE_STATE_CW);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
#else
|
||||
#ifdef INVERT_SPINDLE_ENABLE_PIN
|
||||
if (bit_isfalse(SPINDLE_ENABLE_PORT, (1 << SPINDLE_ENABLE_BIT))) {
|
||||
#else
|
||||
if (bit_istrue(SPINDLE_ENABLE_PORT, (1 << SPINDLE_ENABLE_BIT))) {
|
||||
#endif
|
||||
#ifdef ENABLE_DUAL_AXIS
|
||||
return (SPINDLE_STATE_CW);
|
||||
#else
|
||||
if (SPINDLE_DIRECTION_PORT & (1 << SPINDLE_DIRECTION_BIT)) {
|
||||
return (SPINDLE_STATE_CCW);
|
||||
} else {
|
||||
return (SPINDLE_STATE_CW);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
return (SPINDLE_STATE_DISABLE);
|
||||
}
|
||||
|
||||
|
||||
// Disables the spindle and sets PWM output to zero when PWM variable spindle speed is enabled.
|
||||
// Called by various main program and ISR routines. Keep routine small, fast, and efficient.
|
||||
// Called by spindle_init(), spindle_set_speed(), spindle_set_state(), and mc_reset().
|
||||
void spindle_stop()
|
||||
{
|
||||
#ifdef VARIABLE_SPINDLE
|
||||
SPINDLE_TCCRA_REGISTER &= ~(1<<SPINDLE_COMB_BIT); // Disable PWM. Output voltage is zero.
|
||||
#ifdef USE_SPINDLE_DIR_AS_ENABLE_PIN
|
||||
#ifdef INVERT_SPINDLE_ENABLE_PIN
|
||||
SPINDLE_ENABLE_PORT |= (1<<SPINDLE_ENABLE_BIT); // Set pin to high
|
||||
#else
|
||||
SPINDLE_ENABLE_PORT &= ~(1<<SPINDLE_ENABLE_BIT); // Set pin to low
|
||||
#endif
|
||||
#endif
|
||||
#else
|
||||
#ifdef INVERT_SPINDLE_ENABLE_PIN
|
||||
SPINDLE_ENABLE_PORT |= (1<<SPINDLE_ENABLE_BIT); // Set pin to high
|
||||
#else
|
||||
SPINDLE_ENABLE_PORT &= ~(1<<SPINDLE_ENABLE_BIT); // Set pin to low
|
||||
#endif
|
||||
#endif
|
||||
void spindle_stop() {
|
||||
#ifdef VARIABLE_SPINDLE
|
||||
SPINDLE_TCCRA_REGISTER &= ~(1 << SPINDLE_COMB_BIT); // Disable PWM. Output voltage is zero.
|
||||
#ifdef USE_SPINDLE_DIR_AS_ENABLE_PIN
|
||||
#ifdef INVERT_SPINDLE_ENABLE_PIN
|
||||
SPINDLE_ENABLE_PORT |= (1 << SPINDLE_ENABLE_BIT); // Set pin to high
|
||||
#else
|
||||
SPINDLE_ENABLE_PORT &= ~(1 << SPINDLE_ENABLE_BIT); // Set pin to low
|
||||
#endif
|
||||
#endif
|
||||
#else
|
||||
#ifdef INVERT_SPINDLE_ENABLE_PIN
|
||||
SPINDLE_ENABLE_PORT |= (1 << SPINDLE_ENABLE_BIT); // Set pin to high
|
||||
#else
|
||||
SPINDLE_ENABLE_PORT &= ~(1 << SPINDLE_ENABLE_BIT); // Set pin to low
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
#ifdef VARIABLE_SPINDLE
|
||||
// Sets spindle speed PWM output and enable pin, if configured. Called by spindle_set_state()
|
||||
// and stepper ISR. Keep routine small and efficient.
|
||||
void spindle_set_speed(uint8_t pwm_value)
|
||||
{
|
||||
// Sets spindle speed PWM output and enable pin, if configured. Called by spindle_set_state()
|
||||
// and stepper ISR. Keep routine small and efficient.
|
||||
void spindle_set_speed(uint8_t pwm_value) {
|
||||
SPINDLE_OCR_REGISTER = pwm_value; // Set PWM output level.
|
||||
#ifdef SPINDLE_ENABLE_OFF_WITH_ZERO_SPEED
|
||||
#ifdef SPINDLE_ENABLE_OFF_WITH_ZERO_SPEED
|
||||
if (pwm_value == SPINDLE_PWM_OFF_VALUE) {
|
||||
spindle_stop();
|
||||
} else {
|
||||
SPINDLE_TCCRA_REGISTER |= (1<<SPINDLE_COMB_BIT); // Ensure PWM output is enabled.
|
||||
#ifdef INVERT_SPINDLE_ENABLE_PIN
|
||||
SPINDLE_ENABLE_PORT &= ~(1<<SPINDLE_ENABLE_BIT);
|
||||
#else
|
||||
SPINDLE_ENABLE_PORT |= (1<<SPINDLE_ENABLE_BIT);
|
||||
#endif
|
||||
SPINDLE_TCCRA_REGISTER |= (1 << SPINDLE_COMB_BIT); // Ensure PWM output is enabled.
|
||||
#ifdef INVERT_SPINDLE_ENABLE_PIN
|
||||
SPINDLE_ENABLE_PORT &= ~(1 << SPINDLE_ENABLE_BIT);
|
||||
#else
|
||||
SPINDLE_ENABLE_PORT |= (1 << SPINDLE_ENABLE_BIT);
|
||||
#endif
|
||||
}
|
||||
#else
|
||||
#else
|
||||
if (pwm_value == SPINDLE_PWM_OFF_VALUE) {
|
||||
SPINDLE_TCCRA_REGISTER &= ~(1<<SPINDLE_COMB_BIT); // Disable PWM. Output voltage is zero.
|
||||
SPINDLE_TCCRA_REGISTER &= ~(1 << SPINDLE_COMB_BIT); // Disable PWM. Output voltage is zero.
|
||||
} else {
|
||||
SPINDLE_TCCRA_REGISTER |= (1<<SPINDLE_COMB_BIT); // Ensure PWM output is enabled.
|
||||
}
|
||||
#endif
|
||||
SPINDLE_TCCRA_REGISTER |= (1 << SPINDLE_COMB_BIT); // Ensure PWM output is enabled.
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef ENABLE_PIECEWISE_LINEAR_SPINDLE
|
||||
|
||||
#ifdef ENABLE_PIECEWISE_LINEAR_SPINDLE
|
||||
|
||||
// Called by spindle_set_state() and step segment generator. Keep routine small and efficient.
|
||||
uint8_t spindle_compute_pwm_value(float rpm) // 328p PWM register is 8-bit.
|
||||
{
|
||||
// Called by spindle_set_state() and step segment generator. Keep routine small and efficient.
|
||||
uint8_t spindle_compute_pwm_value(float rpm) // 328p PWM register is 8-bit.
|
||||
{
|
||||
uint8_t pwm_value;
|
||||
rpm *= (0.010*sys.spindle_speed_ovr); // Scale by spindle speed override value.
|
||||
rpm *= (0.010 * sys.spindle_speed_ovr); // Scale by spindle speed override value.
|
||||
// Calculate PWM register value based on rpm max/min settings and programmed rpm.
|
||||
if ((settings.rpm_min >= settings.rpm_max) || (rpm >= RPM_MAX)) {
|
||||
rpm = RPM_MAX;
|
||||
|
|
@ -162,37 +162,37 @@ void spindle_stop()
|
|||
pwm_value = SPINDLE_PWM_MIN_VALUE;
|
||||
}
|
||||
} else {
|
||||
// Compute intermediate PWM value with linear spindle speed model via piecewise linear fit model.
|
||||
#if (N_PIECES > 3)
|
||||
// Compute intermediate PWM value with linear spindle speed model via piecewise linear fit model.
|
||||
#if (N_PIECES > 3)
|
||||
if (rpm > RPM_POINT34) {
|
||||
pwm_value = floor(RPM_LINE_A4*rpm - RPM_LINE_B4);
|
||||
pwm_value = floor(RPM_LINE_A4 * rpm - RPM_LINE_B4);
|
||||
} else
|
||||
#endif
|
||||
#if (N_PIECES > 2)
|
||||
#endif
|
||||
#if (N_PIECES > 2)
|
||||
if (rpm > RPM_POINT23) {
|
||||
pwm_value = floor(RPM_LINE_A3*rpm - RPM_LINE_B3);
|
||||
pwm_value = floor(RPM_LINE_A3 * rpm - RPM_LINE_B3);
|
||||
} else
|
||||
#endif
|
||||
#if (N_PIECES > 1)
|
||||
#endif
|
||||
#if (N_PIECES > 1)
|
||||
if (rpm > RPM_POINT12) {
|
||||
pwm_value = floor(RPM_LINE_A2*rpm - RPM_LINE_B2);
|
||||
pwm_value = floor(RPM_LINE_A2 * rpm - RPM_LINE_B2);
|
||||
} else
|
||||
#endif
|
||||
#endif
|
||||
{
|
||||
pwm_value = floor(RPM_LINE_A1*rpm - RPM_LINE_B1);
|
||||
pwm_value = floor(RPM_LINE_A1 * rpm - RPM_LINE_B1);
|
||||
}
|
||||
}
|
||||
sys.spindle_speed = rpm;
|
||||
return(pwm_value);
|
||||
}
|
||||
return (pwm_value);
|
||||
}
|
||||
|
||||
#else
|
||||
#else
|
||||
|
||||
// Called by spindle_set_state() and step segment generator. Keep routine small and efficient.
|
||||
uint8_t spindle_compute_pwm_value(float rpm) // 328p PWM register is 8-bit.
|
||||
{
|
||||
// Called by spindle_set_state() and step segment generator. Keep routine small and efficient.
|
||||
uint8_t spindle_compute_pwm_value(float rpm) // 328p PWM register is 8-bit.
|
||||
{
|
||||
uint8_t pwm_value;
|
||||
rpm *= (0.010*sys.spindle_speed_ovr); // Scale by spindle speed override value.
|
||||
rpm *= (0.010 * sys.spindle_speed_ovr); // Scale by spindle speed override value.
|
||||
// Calculate PWM register value based on rpm max/min settings and programmed rpm.
|
||||
if ((settings.rpm_min >= settings.rpm_max) || (rpm >= settings.rpm_max)) {
|
||||
// No PWM range possible. Set simple on/off spindle control pin state.
|
||||
|
|
@ -210,81 +210,84 @@ void spindle_stop()
|
|||
// Compute intermediate PWM value with linear spindle speed model.
|
||||
// NOTE: A nonlinear model could be installed here, if required, but keep it VERY light-weight.
|
||||
sys.spindle_speed = rpm;
|
||||
pwm_value = floor((rpm-settings.rpm_min)*pwm_gradient) + SPINDLE_PWM_MIN_VALUE;
|
||||
}
|
||||
return(pwm_value);
|
||||
pwm_value = floor((rpm - settings.rpm_min) * pwm_gradient) + SPINDLE_PWM_MIN_VALUE;
|
||||
}
|
||||
return (pwm_value);
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
// Immediately sets spindle running state with direction and spindle rpm via PWM, if enabled.
|
||||
// Called by g-code parser spindle_sync(), parking retract and restore, g-code program end,
|
||||
// sleep, and spindle stop override.
|
||||
#ifdef VARIABLE_SPINDLE
|
||||
void spindle_set_state(uint8_t state, float rpm)
|
||||
void spindle_set_state(uint8_t state, float rpm)
|
||||
#else
|
||||
void _spindle_set_state(uint8_t state)
|
||||
void _spindle_set_state(uint8_t state)
|
||||
#endif
|
||||
{
|
||||
if (sys.abort) { return; } // Block during abort.
|
||||
if (sys.abort) {
|
||||
return;
|
||||
} // Block during abort.
|
||||
|
||||
if (state == SPINDLE_DISABLE) { // Halt or set spindle direction and rpm.
|
||||
|
||||
#ifdef VARIABLE_SPINDLE
|
||||
#ifdef VARIABLE_SPINDLE
|
||||
sys.spindle_speed = 0.0;
|
||||
#endif
|
||||
#endif
|
||||
spindle_stop();
|
||||
|
||||
} else {
|
||||
|
||||
#if !defined(USE_SPINDLE_DIR_AS_ENABLE_PIN) && !defined(ENABLE_DUAL_AXIS)
|
||||
#if !defined(USE_SPINDLE_DIR_AS_ENABLE_PIN) && !defined(ENABLE_DUAL_AXIS)
|
||||
if (state == SPINDLE_ENABLE_CW) {
|
||||
SPINDLE_DIRECTION_PORT &= ~(1<<SPINDLE_DIRECTION_BIT);
|
||||
SPINDLE_DIRECTION_PORT &= ~(1 << SPINDLE_DIRECTION_BIT);
|
||||
} else {
|
||||
SPINDLE_DIRECTION_PORT |= (1<<SPINDLE_DIRECTION_BIT);
|
||||
SPINDLE_DIRECTION_PORT |= (1 << SPINDLE_DIRECTION_BIT);
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef VARIABLE_SPINDLE
|
||||
#ifdef VARIABLE_SPINDLE
|
||||
// NOTE: Assumes all calls to this function is when Grbl is not moving or must remain off.
|
||||
if (settings.flags & BITFLAG_LASER_MODE) {
|
||||
if (state == SPINDLE_ENABLE_CCW) { rpm = 0.0; } // TODO: May need to be rpm_min*(100/MAX_SPINDLE_SPEED_OVERRIDE);
|
||||
if (state == SPINDLE_ENABLE_CCW) {
|
||||
rpm = 0.0;
|
||||
} // TODO: May need to be rpm_min*(100/MAX_SPINDLE_SPEED_OVERRIDE);
|
||||
}
|
||||
spindle_set_speed(spindle_compute_pwm_value(rpm));
|
||||
#endif
|
||||
#if (defined(USE_SPINDLE_DIR_AS_ENABLE_PIN) && \
|
||||
!defined(SPINDLE_ENABLE_OFF_WITH_ZERO_SPEED)) || !defined(VARIABLE_SPINDLE)
|
||||
// NOTE: Without variable spindle, the enable bit should just turn on or off, regardless
|
||||
// if the spindle speed value is zero, as its ignored anyhow.
|
||||
#ifdef INVERT_SPINDLE_ENABLE_PIN
|
||||
SPINDLE_ENABLE_PORT &= ~(1<<SPINDLE_ENABLE_BIT);
|
||||
#else
|
||||
SPINDLE_ENABLE_PORT |= (1<<SPINDLE_ENABLE_BIT);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#endif
|
||||
#if (defined(USE_SPINDLE_DIR_AS_ENABLE_PIN) && !defined(SPINDLE_ENABLE_OFF_WITH_ZERO_SPEED)) || \
|
||||
!defined(VARIABLE_SPINDLE)
|
||||
// NOTE: Without variable spindle, the enable bit should just turn on or off, regardless
|
||||
// if the spindle speed value is zero, as its ignored anyhow.
|
||||
#ifdef INVERT_SPINDLE_ENABLE_PIN
|
||||
SPINDLE_ENABLE_PORT &= ~(1 << SPINDLE_ENABLE_BIT);
|
||||
#else
|
||||
SPINDLE_ENABLE_PORT |= (1 << SPINDLE_ENABLE_BIT);
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
sys.report_ovr_counter = 0; // Set to report change immediately
|
||||
}
|
||||
|
||||
|
||||
// G-code parser entry-point for setting spindle state. Forces a planner buffer sync and bails
|
||||
// if an abort or check-mode is active.
|
||||
#ifdef VARIABLE_SPINDLE
|
||||
void spindle_sync(uint8_t state, float rpm)
|
||||
{
|
||||
if (sys.state == STATE_CHECK_MODE) { return; }
|
||||
protocol_buffer_synchronize(); // Empty planner buffer to ensure spindle is set when programmed.
|
||||
spindle_set_state(state,rpm);
|
||||
void spindle_sync(uint8_t state, float rpm) {
|
||||
if (sys.state == STATE_CHECK_MODE) {
|
||||
return;
|
||||
}
|
||||
protocol_buffer_synchronize(); // Empty planner buffer to ensure spindle is set when programmed.
|
||||
spindle_set_state(state, rpm);
|
||||
}
|
||||
#else
|
||||
void _spindle_sync(uint8_t state)
|
||||
{
|
||||
if (sys.state == STATE_CHECK_MODE) { return; }
|
||||
void _spindle_sync(uint8_t state) {
|
||||
if (sys.state == STATE_CHECK_MODE) {
|
||||
return;
|
||||
}
|
||||
protocol_buffer_synchronize(); // Empty planner buffer to ensure spindle is set when programmed.
|
||||
_spindle_set_state(state);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -29,7 +29,6 @@
|
|||
#define SPINDLE_STATE_CW bit(0)
|
||||
#define SPINDLE_STATE_CCW bit(1)
|
||||
|
||||
|
||||
// Initializes spindle pins and hardware PWM, if enabled.
|
||||
void spindle_init();
|
||||
|
||||
|
|
@ -41,33 +40,32 @@ uint8_t spindle_get_state();
|
|||
// Called by spindle_sync() after sync and parking motion/spindle stop override during restore.
|
||||
#ifdef VARIABLE_SPINDLE
|
||||
|
||||
// Called by g-code parser when setting spindle state and requires a buffer sync.
|
||||
void spindle_sync(uint8_t state, float rpm);
|
||||
// Called by g-code parser when setting spindle state and requires a buffer sync.
|
||||
void spindle_sync(uint8_t state, float rpm);
|
||||
|
||||
// Sets spindle running state with direction, enable, and spindle PWM.
|
||||
void spindle_set_state(uint8_t state, float rpm);
|
||||
// Sets spindle running state with direction, enable, and spindle PWM.
|
||||
void spindle_set_state(uint8_t state, float rpm);
|
||||
|
||||
// Sets spindle PWM quickly for stepper ISR. Also called by spindle_set_state().
|
||||
// NOTE: 328p PWM register is 8-bit.
|
||||
void spindle_set_speed(uint8_t pwm_value);
|
||||
// Sets spindle PWM quickly for stepper ISR. Also called by spindle_set_state().
|
||||
// NOTE: 328p PWM register is 8-bit.
|
||||
void spindle_set_speed(uint8_t pwm_value);
|
||||
|
||||
// Computes 328p-specific PWM register value for the given RPM for quick updating.
|
||||
uint8_t spindle_compute_pwm_value(float rpm);
|
||||
// Computes 328p-specific PWM register value for the given RPM for quick updating.
|
||||
uint8_t spindle_compute_pwm_value(float rpm);
|
||||
|
||||
#else
|
||||
|
||||
// Called by g-code parser when setting spindle state and requires a buffer sync.
|
||||
#define spindle_sync(state, rpm) _spindle_sync(state)
|
||||
void _spindle_sync(uint8_t state);
|
||||
// Called by g-code parser when setting spindle state and requires a buffer sync.
|
||||
#define spindle_sync(state, rpm) _spindle_sync(state)
|
||||
void _spindle_sync(uint8_t state);
|
||||
|
||||
// Sets spindle running state with direction and enable.
|
||||
#define spindle_set_state(state, rpm) _spindle_set_state(state)
|
||||
void _spindle_set_state(uint8_t state);
|
||||
// Sets spindle running state with direction and enable.
|
||||
#define spindle_set_state(state, rpm) _spindle_set_state(state)
|
||||
void _spindle_set_state(uint8_t state);
|
||||
|
||||
#endif
|
||||
|
||||
// Stop and start spindle routines. Called by all spindle routines and stepper ISR.
|
||||
void spindle_stop();
|
||||
|
||||
|
||||
#endif
|
||||
|
|
|
|||
636
grbl/stepper.c
636
grbl/stepper.c
File diff suppressed because it is too large
Load diff
|
|
@ -23,7 +23,7 @@
|
|||
#define stepper_h
|
||||
|
||||
#ifndef SEGMENT_BUFFER_SIZE
|
||||
#define SEGMENT_BUFFER_SIZE 6
|
||||
#define SEGMENT_BUFFER_SIZE 6
|
||||
#endif
|
||||
|
||||
// Initialize and setup the stepper motor subsystem
|
||||
|
|
|
|||
363
grbl/system.c
363
grbl/system.c
|
|
@ -20,98 +20,95 @@
|
|||
|
||||
#include "grbl.h"
|
||||
|
||||
|
||||
void system_init()
|
||||
{
|
||||
void system_init() {
|
||||
CONTROL_DDR &= ~(CONTROL_MASK); // Configure as input pins
|
||||
#ifdef DISABLE_CONTROL_PIN_PULL_UP
|
||||
#ifdef DISABLE_CONTROL_PIN_PULL_UP
|
||||
CONTROL_PORT &= ~(CONTROL_MASK); // Normal low operation. Requires external pull-down.
|
||||
#else
|
||||
#else
|
||||
CONTROL_PORT |= CONTROL_MASK; // Enable internal pull-up resistors. Normal high operation.
|
||||
#endif
|
||||
#endif
|
||||
CONTROL_PCMSK |= CONTROL_MASK; // Enable specific pins of the Pin Change Interrupt
|
||||
PCICR |= (1 << CONTROL_INT); // Enable Pin Change Interrupt
|
||||
}
|
||||
|
||||
|
||||
// Returns control pin state as a uint8 bitfield. Each bit indicates the input pin state, where
|
||||
// triggered is 1 and not triggered is 0. Invert mask is applied. Bitfield organization is
|
||||
// defined by the CONTROL_PIN_INDEX in the header file.
|
||||
uint8_t system_control_get_state()
|
||||
{
|
||||
uint8_t system_control_get_state() {
|
||||
uint8_t control_state = 0;
|
||||
uint8_t pin = (CONTROL_PIN & CONTROL_MASK) ^ CONTROL_MASK;
|
||||
#ifdef INVERT_CONTROL_PIN_MASK
|
||||
#ifdef INVERT_CONTROL_PIN_MASK
|
||||
pin ^= INVERT_CONTROL_PIN_MASK;
|
||||
#endif
|
||||
#endif
|
||||
if (pin) {
|
||||
#ifdef ENABLE_SAFETY_DOOR_INPUT_PIN
|
||||
if (bit_istrue(pin,(1<<CONTROL_SAFETY_DOOR_BIT))) { control_state |= CONTROL_PIN_INDEX_SAFETY_DOOR; }
|
||||
#else
|
||||
if (bit_istrue(pin,(1<<CONTROL_FEED_HOLD_BIT))) { control_state |= CONTROL_PIN_INDEX_FEED_HOLD; }
|
||||
#endif
|
||||
if (bit_istrue(pin,(1<<CONTROL_RESET_BIT))) { control_state |= CONTROL_PIN_INDEX_RESET; }
|
||||
if (bit_istrue(pin,(1<<CONTROL_CYCLE_START_BIT))) { control_state |= CONTROL_PIN_INDEX_CYCLE_START; }
|
||||
#ifdef ENABLE_SAFETY_DOOR_INPUT_PIN
|
||||
if (bit_istrue(pin, (1 << CONTROL_SAFETY_DOOR_BIT))) {
|
||||
control_state |= CONTROL_PIN_INDEX_SAFETY_DOOR;
|
||||
}
|
||||
return(control_state);
|
||||
#else
|
||||
if (bit_istrue(pin, (1 << CONTROL_FEED_HOLD_BIT))) {
|
||||
control_state |= CONTROL_PIN_INDEX_FEED_HOLD;
|
||||
}
|
||||
#endif
|
||||
if (bit_istrue(pin, (1 << CONTROL_RESET_BIT))) {
|
||||
control_state |= CONTROL_PIN_INDEX_RESET;
|
||||
}
|
||||
if (bit_istrue(pin, (1 << CONTROL_CYCLE_START_BIT))) {
|
||||
control_state |= CONTROL_PIN_INDEX_CYCLE_START;
|
||||
}
|
||||
}
|
||||
return (control_state);
|
||||
}
|
||||
|
||||
|
||||
// Pin change interrupt for pin-out commands, i.e. cycle start, feed hold, and reset. Sets
|
||||
// only the realtime command execute variable to have the main program execute these when
|
||||
// its ready. This works exactly like the character-based realtime commands when picked off
|
||||
// directly from the incoming serial data stream.
|
||||
ISR(CONTROL_INT_vect)
|
||||
{
|
||||
ISR(CONTROL_INT_vect) {
|
||||
uint8_t pin = system_control_get_state();
|
||||
if (pin) {
|
||||
if (bit_istrue(pin,CONTROL_PIN_INDEX_RESET)) {
|
||||
if (bit_istrue(pin, CONTROL_PIN_INDEX_RESET)) {
|
||||
mc_reset();
|
||||
}
|
||||
if (bit_istrue(pin,CONTROL_PIN_INDEX_CYCLE_START)) {
|
||||
if (bit_istrue(pin, CONTROL_PIN_INDEX_CYCLE_START)) {
|
||||
bit_true(sys_rt_exec_state, EXEC_CYCLE_START);
|
||||
}
|
||||
#ifndef ENABLE_SAFETY_DOOR_INPUT_PIN
|
||||
if (bit_istrue(pin,CONTROL_PIN_INDEX_FEED_HOLD)) {
|
||||
#ifndef ENABLE_SAFETY_DOOR_INPUT_PIN
|
||||
if (bit_istrue(pin, CONTROL_PIN_INDEX_FEED_HOLD)) {
|
||||
bit_true(sys_rt_exec_state, EXEC_FEED_HOLD);
|
||||
#else
|
||||
if (bit_istrue(pin,CONTROL_PIN_INDEX_SAFETY_DOOR)) {
|
||||
#else
|
||||
if (bit_istrue(pin, CONTROL_PIN_INDEX_SAFETY_DOOR)) {
|
||||
bit_true(sys_rt_exec_state, EXEC_SAFETY_DOOR);
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Returns if safety door is ajar(T) or closed(F), based on pin state.
|
||||
uint8_t system_check_safety_door_ajar()
|
||||
{
|
||||
#ifdef ENABLE_SAFETY_DOOR_INPUT_PIN
|
||||
return(system_control_get_state() & CONTROL_PIN_INDEX_SAFETY_DOOR);
|
||||
#else
|
||||
return(false); // Input pin not enabled, so just return that it's closed.
|
||||
#endif
|
||||
uint8_t system_check_safety_door_ajar() {
|
||||
#ifdef ENABLE_SAFETY_DOOR_INPUT_PIN
|
||||
return (system_control_get_state() & CONTROL_PIN_INDEX_SAFETY_DOOR);
|
||||
#else
|
||||
return (false); // Input pin not enabled, so just return that it's closed.
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
// Executes user startup script, if stored.
|
||||
void system_execute_startup(char *line)
|
||||
{
|
||||
void system_execute_startup(char *line) {
|
||||
uint8_t n;
|
||||
for (n=0; n < N_STARTUP_LINE; n++) {
|
||||
for (n = 0; n < N_STARTUP_LINE; n++) {
|
||||
if (!(settings_read_startup_line(n, line))) {
|
||||
line[0] = 0;
|
||||
report_execute_startup_message(line,STATUS_SETTING_READ_FAIL);
|
||||
report_execute_startup_message(line, STATUS_SETTING_READ_FAIL);
|
||||
} else {
|
||||
if (line[0] != 0) {
|
||||
uint8_t status_code = gc_execute_line(line);
|
||||
report_execute_startup_message(line,status_code);
|
||||
report_execute_startup_message(line, status_code);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Directs and executes one line of formatted input from protocol_process. While mostly
|
||||
// incoming streaming g-code blocks, this also executes Grbl internal commands, such as
|
||||
// settings, initiating the homing cycle, and toggling switch states. This differs from
|
||||
|
|
@ -120,47 +117,63 @@ void system_execute_startup(char *line)
|
|||
// the lines that are processed afterward, not necessarily real-time during a cycle,
|
||||
// since there are motions already stored in the buffer. However, this 'lag' should not
|
||||
// be an issue, since these commands are not typically used during a cycle.
|
||||
uint8_t system_execute_line(char *line)
|
||||
{
|
||||
uint8_t system_execute_line(char *line) {
|
||||
uint8_t char_counter = 1;
|
||||
uint8_t helper_var = 0; // Helper variable
|
||||
float parameter, value;
|
||||
switch( line[char_counter] ) {
|
||||
case 0 : report_grbl_help(); break;
|
||||
case 'J' : // Jogging
|
||||
switch (line[char_counter]) {
|
||||
case 0: report_grbl_help(); break;
|
||||
case 'J': // Jogging
|
||||
// Execute only if in IDLE or JOG states.
|
||||
if (sys.state != STATE_IDLE && sys.state != STATE_JOG) { return(STATUS_IDLE_ERROR); }
|
||||
if(line[2] != '=') { return(STATUS_INVALID_STATEMENT); }
|
||||
return(gc_execute_line(line)); // NOTE: $J= is ignored inside g-code parser and used to detect jog motions.
|
||||
if (sys.state != STATE_IDLE && sys.state != STATE_JOG) {
|
||||
return (STATUS_IDLE_ERROR);
|
||||
}
|
||||
if (line[2] != '=') {
|
||||
return (STATUS_INVALID_STATEMENT);
|
||||
}
|
||||
return (gc_execute_line(line)); // NOTE: $J= is ignored inside g-code parser and used to detect jog motions.
|
||||
break;
|
||||
case '$': case 'G': case 'C': case 'X':
|
||||
if ( line[2] != 0 ) { return(STATUS_INVALID_STATEMENT); }
|
||||
switch( line[1] ) {
|
||||
case '$' : // Prints Grbl settings
|
||||
if ( sys.state & (STATE_CYCLE | STATE_HOLD) ) { return(STATUS_IDLE_ERROR); } // Block during cycle. Takes too long to print.
|
||||
else { report_grbl_settings(); }
|
||||
case '$':
|
||||
case 'G':
|
||||
case 'C':
|
||||
case 'X':
|
||||
if (line[2] != 0) {
|
||||
return (STATUS_INVALID_STATEMENT);
|
||||
}
|
||||
switch (line[1]) {
|
||||
case '$': // Prints Grbl settings
|
||||
if (sys.state & (STATE_CYCLE | STATE_HOLD)) {
|
||||
return (STATUS_IDLE_ERROR);
|
||||
} // Block during cycle. Takes too long to print.
|
||||
else {
|
||||
report_grbl_settings();
|
||||
}
|
||||
break;
|
||||
case 'G' : // Prints gcode parser state
|
||||
case 'G': // Prints gcode parser state
|
||||
// TODO: Move this to realtime commands for GUIs to request this data during suspend-state.
|
||||
report_gcode_modes();
|
||||
break;
|
||||
case 'C' : // Set check g-code mode [IDLE/CHECK]
|
||||
case 'C': // Set check g-code mode [IDLE/CHECK]
|
||||
// Perform reset when toggling off. Check g-code mode should only work if Grbl
|
||||
// is idle and ready, regardless of alarm locks. This is mainly to keep things
|
||||
// simple and consistent.
|
||||
if ( sys.state == STATE_CHECK_MODE ) {
|
||||
if (sys.state == STATE_CHECK_MODE) {
|
||||
mc_reset();
|
||||
report_feedback_message(MESSAGE_DISABLED);
|
||||
} else {
|
||||
if (sys.state) { return(STATUS_IDLE_ERROR); } // Requires no alarm mode.
|
||||
if (sys.state) {
|
||||
return (STATUS_IDLE_ERROR);
|
||||
} // Requires no alarm mode.
|
||||
sys.state = STATE_CHECK_MODE;
|
||||
report_feedback_message(MESSAGE_ENABLED);
|
||||
}
|
||||
break;
|
||||
case 'X' : // Disable alarm lock [ALARM]
|
||||
case 'X': // Disable alarm lock [ALARM]
|
||||
if (sys.state == STATE_ALARM) {
|
||||
// Block if safety door is ajar.
|
||||
if (system_check_safety_door_ajar()) { return(STATUS_CHECK_DOOR); }
|
||||
if (system_check_safety_door_ajar()) {
|
||||
return (STATUS_CHECK_DOOR);
|
||||
}
|
||||
report_feedback_message(MESSAGE_ALARM_UNLOCK);
|
||||
sys.state = STATE_IDLE;
|
||||
// Don't run startup script. Prevents stored moves in startup from causing accidents.
|
||||
|
|
@ -168,189 +181,213 @@ uint8_t system_execute_line(char *line)
|
|||
break;
|
||||
}
|
||||
break;
|
||||
default :
|
||||
default:
|
||||
// Block any system command that requires the state as IDLE/ALARM. (i.e. EEPROM, homing)
|
||||
if ( !(sys.state == STATE_IDLE || sys.state == STATE_ALARM) ) { return(STATUS_IDLE_ERROR); }
|
||||
switch( line[1] ) {
|
||||
case '#' : // Print Grbl NGC parameters
|
||||
if ( line[2] != 0 ) { return(STATUS_INVALID_STATEMENT); }
|
||||
else { report_ngc_parameters(); }
|
||||
if (!(sys.state == STATE_IDLE || sys.state == STATE_ALARM)) {
|
||||
return (STATUS_IDLE_ERROR);
|
||||
}
|
||||
switch (line[1]) {
|
||||
case '#': // Print Grbl NGC parameters
|
||||
if (line[2] != 0) {
|
||||
return (STATUS_INVALID_STATEMENT);
|
||||
} else {
|
||||
report_ngc_parameters();
|
||||
}
|
||||
break;
|
||||
case 'H' : // Perform homing cycle [IDLE/ALARM]
|
||||
if (bit_isfalse(settings.flags,BITFLAG_HOMING_ENABLE)) {return(STATUS_SETTING_DISABLED); }
|
||||
if (system_check_safety_door_ajar()) { return(STATUS_CHECK_DOOR); } // Block if safety door is ajar.
|
||||
case 'H': // Perform homing cycle [IDLE/ALARM]
|
||||
if (bit_isfalse(settings.flags, BITFLAG_HOMING_ENABLE)) {
|
||||
return (STATUS_SETTING_DISABLED);
|
||||
}
|
||||
if (system_check_safety_door_ajar()) {
|
||||
return (STATUS_CHECK_DOOR);
|
||||
} // Block if safety door is ajar.
|
||||
sys.state = STATE_HOMING; // Set system state variable
|
||||
if (line[2] == 0) {
|
||||
mc_homing_cycle(HOMING_CYCLE_ALL);
|
||||
#ifdef HOMING_SINGLE_AXIS_COMMANDS
|
||||
#ifdef HOMING_SINGLE_AXIS_COMMANDS
|
||||
} else if (line[3] == 0) {
|
||||
switch (line[2]) {
|
||||
case 'X': mc_homing_cycle(HOMING_CYCLE_X); break;
|
||||
case 'Y': mc_homing_cycle(HOMING_CYCLE_Y); break;
|
||||
case 'Z': mc_homing_cycle(HOMING_CYCLE_Z); break;
|
||||
default: return(STATUS_INVALID_STATEMENT);
|
||||
default: return (STATUS_INVALID_STATEMENT);
|
||||
}
|
||||
#endif
|
||||
} else {
|
||||
return (STATUS_INVALID_STATEMENT);
|
||||
}
|
||||
#endif
|
||||
} else { return(STATUS_INVALID_STATEMENT); }
|
||||
if (!sys.abort) { // Execute startup scripts after successful homing.
|
||||
sys.state = STATE_IDLE; // Set to IDLE when complete.
|
||||
st_go_idle(); // Set steppers to the settings idle state before returning.
|
||||
if (line[2] == 0) { system_execute_startup(line); }
|
||||
if (line[2] == 0) {
|
||||
system_execute_startup(line);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 'S' : // Puts Grbl to sleep [IDLE/ALARM]
|
||||
if ((line[2] != 'L') || (line[3] != 'P') || (line[4] != 0)) { return(STATUS_INVALID_STATEMENT); }
|
||||
case 'S': // Puts Grbl to sleep [IDLE/ALARM]
|
||||
if ((line[2] != 'L') || (line[3] != 'P') || (line[4] != 0)) {
|
||||
return (STATUS_INVALID_STATEMENT);
|
||||
}
|
||||
system_set_exec_state_flag(EXEC_SLEEP); // Set to execute sleep mode immediately
|
||||
break;
|
||||
case 'I' : // Print or store build info. [IDLE/ALARM]
|
||||
if ( line[++char_counter] == 0 ) {
|
||||
case 'I': // Print or store build info. [IDLE/ALARM]
|
||||
if (line[++char_counter] == 0) {
|
||||
settings_read_build_info(line);
|
||||
report_build_info(line);
|
||||
#ifdef ENABLE_BUILD_INFO_WRITE_COMMAND
|
||||
#ifdef ENABLE_BUILD_INFO_WRITE_COMMAND
|
||||
} else { // Store startup line [IDLE/ALARM]
|
||||
if(line[char_counter++] != '=') { return(STATUS_INVALID_STATEMENT); }
|
||||
if (line[char_counter++] != '=') {
|
||||
return (STATUS_INVALID_STATEMENT);
|
||||
}
|
||||
helper_var = char_counter; // Set helper variable as counter to start of user info line.
|
||||
do {
|
||||
line[char_counter-helper_var] = line[char_counter];
|
||||
line[char_counter - helper_var] = line[char_counter];
|
||||
} while (line[char_counter++] != 0);
|
||||
settings_store_build_info(line);
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
break;
|
||||
case 'R' : // Restore defaults [IDLE/ALARM]
|
||||
if ((line[2] != 'S') || (line[3] != 'T') || (line[4] != '=') || (line[6] != 0)) { return(STATUS_INVALID_STATEMENT); }
|
||||
case 'R': // Restore defaults [IDLE/ALARM]
|
||||
if ((line[2] != 'S') || (line[3] != 'T') || (line[4] != '=') || (line[6] != 0)) {
|
||||
return (STATUS_INVALID_STATEMENT);
|
||||
}
|
||||
switch (line[5]) {
|
||||
#ifdef ENABLE_RESTORE_EEPROM_DEFAULT_SETTINGS
|
||||
#ifdef ENABLE_RESTORE_EEPROM_DEFAULT_SETTINGS
|
||||
case '$': settings_restore(SETTINGS_RESTORE_DEFAULTS); break;
|
||||
#endif
|
||||
#ifdef ENABLE_RESTORE_EEPROM_CLEAR_PARAMETERS
|
||||
#endif
|
||||
#ifdef ENABLE_RESTORE_EEPROM_CLEAR_PARAMETERS
|
||||
case '#': settings_restore(SETTINGS_RESTORE_PARAMETERS); break;
|
||||
#endif
|
||||
#ifdef ENABLE_RESTORE_EEPROM_WIPE_ALL
|
||||
#endif
|
||||
#ifdef ENABLE_RESTORE_EEPROM_WIPE_ALL
|
||||
case '*': settings_restore(SETTINGS_RESTORE_ALL); break;
|
||||
#endif
|
||||
default: return(STATUS_INVALID_STATEMENT);
|
||||
#endif
|
||||
default: return (STATUS_INVALID_STATEMENT);
|
||||
}
|
||||
report_feedback_message(MESSAGE_RESTORE_DEFAULTS);
|
||||
mc_reset(); // Force reset to ensure settings are initialized correctly.
|
||||
break;
|
||||
case 'N' : // Startup lines. [IDLE/ALARM]
|
||||
if ( line[++char_counter] == 0 ) { // Print startup lines
|
||||
for (helper_var=0; helper_var < N_STARTUP_LINE; helper_var++) {
|
||||
case 'N': // Startup lines. [IDLE/ALARM]
|
||||
if (line[++char_counter] == 0) { // Print startup lines
|
||||
for (helper_var = 0; helper_var < N_STARTUP_LINE; helper_var++) {
|
||||
if (!(settings_read_startup_line(helper_var, line))) {
|
||||
report_status_message(STATUS_SETTING_READ_FAIL);
|
||||
} else {
|
||||
report_startup_line(helper_var,line);
|
||||
report_startup_line(helper_var, line);
|
||||
}
|
||||
}
|
||||
break;
|
||||
} else { // Store startup line [IDLE Only] Prevents motion during ALARM.
|
||||
if (sys.state != STATE_IDLE) { return(STATUS_IDLE_ERROR); } // Store only when idle.
|
||||
if (sys.state != STATE_IDLE) {
|
||||
return (STATUS_IDLE_ERROR);
|
||||
} // Store only when idle.
|
||||
helper_var = true; // Set helper_var to flag storing method.
|
||||
// No break. Continues into default: to read remaining command characters.
|
||||
}
|
||||
default : // Storing setting methods [IDLE/ALARM]
|
||||
if(!read_float(line, &char_counter, ¶meter)) { return(STATUS_BAD_NUMBER_FORMAT); }
|
||||
if(line[char_counter++] != '=') { return(STATUS_INVALID_STATEMENT); }
|
||||
default: // Storing setting methods [IDLE/ALARM]
|
||||
if (!read_float(line, &char_counter, ¶meter)) {
|
||||
return (STATUS_BAD_NUMBER_FORMAT);
|
||||
}
|
||||
if (line[char_counter++] != '=') {
|
||||
return (STATUS_INVALID_STATEMENT);
|
||||
}
|
||||
if (helper_var) { // Store startup line
|
||||
// Prepare sending gcode block to gcode parser by shifting all characters
|
||||
helper_var = char_counter; // Set helper variable as counter to start of gcode block
|
||||
do {
|
||||
line[char_counter-helper_var] = line[char_counter];
|
||||
line[char_counter - helper_var] = line[char_counter];
|
||||
} while (line[char_counter++] != 0);
|
||||
// Execute gcode block to ensure block is valid.
|
||||
helper_var = gc_execute_line(line); // Set helper_var to returned status code.
|
||||
if (helper_var) { return(helper_var); }
|
||||
else {
|
||||
if (helper_var) {
|
||||
return (helper_var);
|
||||
} else {
|
||||
helper_var = trunc(parameter); // Set helper_var to int value of parameter
|
||||
settings_store_startup_line(helper_var,line);
|
||||
settings_store_startup_line(helper_var, line);
|
||||
}
|
||||
} else { // Store global setting.
|
||||
if(!read_float(line, &char_counter, &value)) { return(STATUS_BAD_NUMBER_FORMAT); }
|
||||
if((line[char_counter] != 0) || (parameter > 255)) { return(STATUS_INVALID_STATEMENT); }
|
||||
return(settings_store_global_setting((uint8_t)parameter, value));
|
||||
if (!read_float(line, &char_counter, &value)) {
|
||||
return (STATUS_BAD_NUMBER_FORMAT);
|
||||
}
|
||||
if ((line[char_counter] != 0) || (parameter > 255)) {
|
||||
return (STATUS_INVALID_STATEMENT);
|
||||
}
|
||||
return (settings_store_global_setting((uint8_t)parameter, value));
|
||||
}
|
||||
}
|
||||
}
|
||||
return(STATUS_OK); // If '$' command makes it to here, then everything's ok.
|
||||
return (STATUS_OK); // If '$' command makes it to here, then everything's ok.
|
||||
}
|
||||
|
||||
|
||||
|
||||
void system_flag_wco_change()
|
||||
{
|
||||
#ifdef FORCE_BUFFER_SYNC_DURING_WCO_CHANGE
|
||||
void system_flag_wco_change() {
|
||||
#ifdef FORCE_BUFFER_SYNC_DURING_WCO_CHANGE
|
||||
protocol_buffer_synchronize();
|
||||
#endif
|
||||
#endif
|
||||
sys.report_wco_counter = 0;
|
||||
}
|
||||
|
||||
|
||||
// Returns machine position of axis 'idx'. Must be sent a 'step' array.
|
||||
// NOTE: If motor steps and machine position are not in the same coordinate frame, this function
|
||||
// serves as a central place to compute the transformation.
|
||||
float system_convert_axis_steps_to_mpos(int32_t *steps, uint8_t idx)
|
||||
{
|
||||
float system_convert_axis_steps_to_mpos(int32_t *steps, uint8_t idx) {
|
||||
float pos;
|
||||
#ifdef COREXY
|
||||
if (idx==X_AXIS) {
|
||||
#ifdef COREXY
|
||||
if (idx == X_AXIS) {
|
||||
pos = (float)system_convert_corexy_to_x_axis_steps(steps) / settings.steps_per_mm[idx];
|
||||
} else if (idx==Y_AXIS) {
|
||||
} else if (idx == Y_AXIS) {
|
||||
pos = (float)system_convert_corexy_to_y_axis_steps(steps) / settings.steps_per_mm[idx];
|
||||
} else {
|
||||
pos = steps[idx]/settings.steps_per_mm[idx];
|
||||
pos = steps[idx] / settings.steps_per_mm[idx];
|
||||
}
|
||||
#else
|
||||
pos = steps[idx]/settings.steps_per_mm[idx];
|
||||
#endif
|
||||
return(pos);
|
||||
#else
|
||||
pos = steps[idx] / settings.steps_per_mm[idx];
|
||||
#endif
|
||||
return (pos);
|
||||
}
|
||||
|
||||
|
||||
void system_convert_array_steps_to_mpos(float *position, int32_t *steps)
|
||||
{
|
||||
void system_convert_array_steps_to_mpos(float *position, int32_t *steps) {
|
||||
uint8_t idx;
|
||||
for (idx=0; idx<N_AXIS; idx++) {
|
||||
for (idx = 0; idx < N_AXIS; idx++) {
|
||||
position[idx] = system_convert_axis_steps_to_mpos(steps, idx);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// CoreXY calculation only. Returns x or y-axis "steps" based on CoreXY motor steps.
|
||||
#ifdef COREXY
|
||||
int32_t system_convert_corexy_to_x_axis_steps(int32_t *steps)
|
||||
{
|
||||
return( (steps[A_MOTOR] + steps[B_MOTOR])/2 );
|
||||
}
|
||||
int32_t system_convert_corexy_to_y_axis_steps(int32_t *steps)
|
||||
{
|
||||
return( (steps[A_MOTOR] - steps[B_MOTOR])/2 );
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
// Checks and reports if target array exceeds machine travel limits.
|
||||
uint8_t system_check_travel_limits(float *target)
|
||||
{
|
||||
uint8_t idx;
|
||||
for (idx=0; idx<N_AXIS; idx++) {
|
||||
#ifdef HOMING_FORCE_SET_ORIGIN
|
||||
// When homing forced set origin is enabled, soft limits checks need to account for directionality.
|
||||
// NOTE: max_travel is stored as negative
|
||||
if (bit_istrue(settings.homing_dir_mask,bit(idx))) {
|
||||
if (target[idx] < 0 || target[idx] > -settings.max_travel[idx]) { return(true); }
|
||||
} else {
|
||||
if (target[idx] > 0 || target[idx] < settings.max_travel[idx]) { return(true); }
|
||||
}
|
||||
#else
|
||||
// NOTE: max_travel is stored as negative
|
||||
if (target[idx] > 0 || target[idx] < settings.max_travel[idx]) { return(true); }
|
||||
#endif
|
||||
}
|
||||
return(false);
|
||||
int32_t system_convert_corexy_to_x_axis_steps(int32_t *steps) {
|
||||
return ((steps[A_MOTOR] + steps[B_MOTOR]) / 2);
|
||||
}
|
||||
|
||||
int32_t system_convert_corexy_to_y_axis_steps(int32_t *steps) {
|
||||
return ((steps[A_MOTOR] - steps[B_MOTOR]) / 2);
|
||||
}
|
||||
#endif
|
||||
|
||||
// Checks and reports if target array exceeds machine travel limits.
|
||||
uint8_t system_check_travel_limits(float *target) {
|
||||
uint8_t idx;
|
||||
for (idx = 0; idx < N_AXIS; idx++) {
|
||||
#ifdef HOMING_FORCE_SET_ORIGIN
|
||||
// When homing forced set origin is enabled, soft limits checks need to account for directionality.
|
||||
// NOTE: max_travel is stored as negative
|
||||
if (bit_istrue(settings.homing_dir_mask, bit(idx))) {
|
||||
if (target[idx] < 0 || target[idx] > -settings.max_travel[idx]) {
|
||||
return (true);
|
||||
}
|
||||
} else {
|
||||
if (target[idx] > 0 || target[idx] < settings.max_travel[idx]) {
|
||||
return (true);
|
||||
}
|
||||
}
|
||||
#else
|
||||
// NOTE: max_travel is stored as negative
|
||||
if (target[idx] > 0 || target[idx] < settings.max_travel[idx]) {
|
||||
return (true);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
return (false);
|
||||
}
|
||||
|
||||
// Special handlers for setting and clearing Grbl's real-time execution flags.
|
||||
void system_set_exec_state_flag(uint8_t mask) {
|
||||
|
|
|
|||
|
|
@ -103,16 +103,16 @@
|
|||
|
||||
// Define control pin index for Grbl internal use. Pin maps may change, but these values don't.
|
||||
#ifdef ENABLE_SAFETY_DOOR_INPUT_PIN
|
||||
#define N_CONTROL_PIN 4
|
||||
#define CONTROL_PIN_INDEX_SAFETY_DOOR bit(0)
|
||||
#define CONTROL_PIN_INDEX_RESET bit(1)
|
||||
#define CONTROL_PIN_INDEX_FEED_HOLD bit(2)
|
||||
#define CONTROL_PIN_INDEX_CYCLE_START bit(3)
|
||||
#define N_CONTROL_PIN 4
|
||||
#define CONTROL_PIN_INDEX_SAFETY_DOOR bit(0)
|
||||
#define CONTROL_PIN_INDEX_RESET bit(1)
|
||||
#define CONTROL_PIN_INDEX_FEED_HOLD bit(2)
|
||||
#define CONTROL_PIN_INDEX_CYCLE_START bit(3)
|
||||
#else
|
||||
#define N_CONTROL_PIN 3
|
||||
#define CONTROL_PIN_INDEX_RESET bit(0)
|
||||
#define CONTROL_PIN_INDEX_FEED_HOLD bit(1)
|
||||
#define CONTROL_PIN_INDEX_CYCLE_START bit(2)
|
||||
#define N_CONTROL_PIN 3
|
||||
#define CONTROL_PIN_INDEX_RESET bit(0)
|
||||
#define CONTROL_PIN_INDEX_FEED_HOLD bit(1)
|
||||
#define CONTROL_PIN_INDEX_CYCLE_START bit(2)
|
||||
#endif
|
||||
|
||||
// Define spindle stop override control states.
|
||||
|
|
@ -122,7 +122,6 @@
|
|||
#define SPINDLE_STOP_OVR_RESTORE bit(2)
|
||||
#define SPINDLE_STOP_OVR_RESTORE_CYCLE bit(3)
|
||||
|
||||
|
||||
// Define global system variables
|
||||
typedef struct {
|
||||
uint8_t state; // Tracks the current system state of Grbl.
|
||||
|
|
@ -132,22 +131,23 @@ typedef struct {
|
|||
uint8_t step_control; // Governs the step segment generator depending on system state.
|
||||
uint8_t probe_succeeded; // Tracks if last probing cycle was successful.
|
||||
uint8_t homing_axis_lock; // Locks axes when limits engage. Used as an axis motion mask in the stepper ISR.
|
||||
#ifdef ENABLE_DUAL_AXIS
|
||||
#ifdef ENABLE_DUAL_AXIS
|
||||
uint8_t homing_axis_lock_dual;
|
||||
#endif
|
||||
#endif
|
||||
uint8_t f_override; // Feed rate override value in percent
|
||||
uint8_t r_override; // Rapids override value in percent
|
||||
uint8_t spindle_speed_ovr; // Spindle speed value in percent
|
||||
uint8_t spindle_stop_ovr; // Tracks spindle stop override states
|
||||
uint8_t report_ovr_counter; // Tracks when to add override data to status reports.
|
||||
uint8_t report_wco_counter; // Tracks when to add work coordinate offset data to status reports.
|
||||
#ifdef ENABLE_PARKING_OVERRIDE_CONTROL
|
||||
#ifdef ENABLE_PARKING_OVERRIDE_CONTROL
|
||||
uint8_t override_ctrl; // Tracks override control states.
|
||||
#endif
|
||||
#ifdef VARIABLE_SPINDLE
|
||||
#endif
|
||||
#ifdef VARIABLE_SPINDLE
|
||||
float spindle_speed;
|
||||
#endif
|
||||
#endif
|
||||
} system_t;
|
||||
|
||||
extern system_t sys;
|
||||
|
||||
// NOTE: These position variables may need to be declared as volatiles, if problems arise.
|
||||
|
|
@ -155,14 +155,17 @@ extern int32_t sys_position[N_AXIS]; // Real-time machine (aka home) positi
|
|||
extern int32_t sys_probe_position[N_AXIS]; // Last probe position in machine coordinates and steps.
|
||||
|
||||
extern volatile uint8_t sys_probe_state; // Probing state value. Used to coordinate the probing cycle with stepper ISR.
|
||||
extern volatile uint8_t sys_rt_exec_state; // Global realtime executor bitflag variable for state management. See EXEC bitmasks.
|
||||
extern volatile uint8_t
|
||||
sys_rt_exec_state; // Global realtime executor bitflag variable for state management. See EXEC bitmasks.
|
||||
extern volatile uint8_t sys_rt_exec_alarm; // Global realtime executor bitflag variable for setting various alarms.
|
||||
extern volatile uint8_t sys_rt_exec_motion_override; // Global realtime executor bitflag variable for motion-based overrides.
|
||||
extern volatile uint8_t sys_rt_exec_accessory_override; // Global realtime executor bitflag variable for spindle/coolant overrides.
|
||||
extern volatile uint8_t
|
||||
sys_rt_exec_motion_override; // Global realtime executor bitflag variable for motion-based overrides.
|
||||
extern volatile uint8_t
|
||||
sys_rt_exec_accessory_override; // Global realtime executor bitflag variable for spindle/coolant overrides.
|
||||
|
||||
#ifdef DEBUG
|
||||
#define EXEC_DEBUG_REPORT bit(0)
|
||||
extern volatile uint8_t sys_rt_exec_debug;
|
||||
#define EXEC_DEBUG_REPORT bit(0)
|
||||
extern volatile uint8_t sys_rt_exec_debug;
|
||||
#endif
|
||||
|
||||
// Initialize the serial protocol
|
||||
|
|
@ -180,7 +183,6 @@ uint8_t system_execute_line(char *line);
|
|||
// Execute the startup script lines stored in EEPROM upon initialization
|
||||
void system_execute_startup(char *line);
|
||||
|
||||
|
||||
void system_flag_wco_change();
|
||||
|
||||
// Returns machine position of axis 'idx'. Must be sent a 'step' array.
|
||||
|
|
@ -191,8 +193,8 @@ void system_convert_array_steps_to_mpos(float *position, int32_t *steps);
|
|||
|
||||
// CoreXY calculation only. Returns x or y-axis "steps" based on CoreXY motor steps.
|
||||
#ifdef COREXY
|
||||
int32_t system_convert_corexy_to_x_axis_steps(int32_t *steps);
|
||||
int32_t system_convert_corexy_to_y_axis_steps(int32_t *steps);
|
||||
int32_t system_convert_corexy_to_x_axis_steps(int32_t *steps);
|
||||
int32_t system_convert_corexy_to_y_axis_steps(int32_t *steps);
|
||||
#endif
|
||||
|
||||
// Checks and reports if target array exceeds machine travel limits.
|
||||
|
|
@ -208,5 +210,4 @@ void system_set_exec_accessory_override_flag(uint8_t mask);
|
|||
void system_clear_exec_motion_overrides();
|
||||
void system_clear_exec_accessory_overrides();
|
||||
|
||||
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue