kopia lustrzana https://github.com/Schildkroet/GRBL-Advanced
Added tool change
rodzic
650c500338
commit
ee0615a39e
|
|
@ -164,6 +164,10 @@
|
|||
<Option compilerVar="CC" />
|
||||
</Unit>
|
||||
<Unit filename="grbl\System.h" />
|
||||
<Unit filename="grbl\ToolChange.c">
|
||||
<Option compilerVar="CC" />
|
||||
</Unit>
|
||||
<Unit filename="grbl\ToolChange.h" />
|
||||
<Unit filename="grbl\util.c">
|
||||
<Option compilerVar="CC" />
|
||||
</Unit>
|
||||
|
|
@ -220,6 +224,7 @@
|
|||
<Unit filename="main.c">
|
||||
<Option compilerVar="CC" />
|
||||
</Unit>
|
||||
<Unit filename="README.md" />
|
||||
<Unit filename="SPL\inc\misc.h" />
|
||||
<Unit filename="SPL\inc\stm32f4xx_adc.h" />
|
||||
<Unit filename="SPL\inc\stm32f4xx_can.h" />
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@
|
|||
<Cursor1 position="1639" topLine="32" />
|
||||
</Cursor>
|
||||
</File>
|
||||
<File name="grbl\Config.h" open="1" top="0" tabpos="3" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<File name="grbl\Config.h" open="1" top="0" tabpos="8" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<Cursor>
|
||||
<Cursor1 position="39003" topLine="548" />
|
||||
</Cursor>
|
||||
|
|
@ -36,7 +36,7 @@
|
|||
<Cursor1 position="873" topLine="13" />
|
||||
</Cursor>
|
||||
</File>
|
||||
<File name="grbl\defaults.h" open="1" top="0" tabpos="4" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<File name="grbl\defaults.h" open="1" top="0" tabpos="9" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<Cursor>
|
||||
<Cursor1 position="2407" topLine="23" />
|
||||
</Cursor>
|
||||
|
|
@ -116,12 +116,12 @@
|
|||
<Cursor1 position="842" topLine="3" />
|
||||
</Cursor>
|
||||
</File>
|
||||
<File name="grbl\Report.c" open="1" top="0" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<File name="grbl\Report.c" open="1" top="0" tabpos="6" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<Cursor>
|
||||
<Cursor1 position="7135" topLine="235" />
|
||||
</Cursor>
|
||||
</File>
|
||||
<File name="grbl\Report.h" open="1" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<File name="grbl\Report.h" open="1" top="0" tabpos="7" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<Cursor>
|
||||
<Cursor1 position="1483" topLine="9" />
|
||||
</Cursor>
|
||||
|
|
@ -156,9 +156,19 @@
|
|||
<Cursor1 position="875" topLine="0" />
|
||||
</Cursor>
|
||||
</File>
|
||||
<File name="grbl\System.c" open="0" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<File name="grbl\System.c" open="1" top="0" tabpos="5" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<Cursor>
|
||||
<Cursor1 position="12252" topLine="135" />
|
||||
<Cursor1 position="7435" topLine="208" />
|
||||
</Cursor>
|
||||
</File>
|
||||
<File name="grbl\System.h" open="1" top="0" tabpos="4" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<Cursor>
|
||||
<Cursor1 position="4260" topLine="53" />
|
||||
</Cursor>
|
||||
</File>
|
||||
<File name="grbl\ToolChange.c" open="1" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<Cursor>
|
||||
<Cursor1 position="2162" topLine="66" />
|
||||
</Cursor>
|
||||
</File>
|
||||
<File name="grbl\util.c" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
|
|
@ -166,9 +176,9 @@
|
|||
<Cursor1 position="31" topLine="0" />
|
||||
</Cursor>
|
||||
</File>
|
||||
<File name="grbl\util.h" open="0" top="0" tabpos="7" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<File name="grbl\util.h" open="1" top="0" tabpos="3" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<Cursor>
|
||||
<Cursor1 position="2820" topLine="54" />
|
||||
<Cursor1 position="1079" topLine="16" />
|
||||
</Cursor>
|
||||
</File>
|
||||
<File name="HAL\EXTI\EXTI.c" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
|
|
@ -191,9 +201,9 @@
|
|||
<Cursor1 position="1007" topLine="21" />
|
||||
</Cursor>
|
||||
</File>
|
||||
<File name="HAL\GPIO\GPIO.c" open="0" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<File name="HAL\GPIO\GPIO.c" open="1" top="1" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<Cursor>
|
||||
<Cursor1 position="1238" topLine="93" />
|
||||
<Cursor1 position="3818" topLine="0" />
|
||||
</Cursor>
|
||||
</File>
|
||||
<File name="HAL\GPIO\GPIO.h" open="0" top="0" tabpos="4" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
|
|
@ -286,9 +296,9 @@
|
|||
<Cursor1 position="781" topLine="12" />
|
||||
</Cursor>
|
||||
</File>
|
||||
<File name="main.c" open="1" top="1" tabpos="5" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<File name="main.c" open="1" top="0" tabpos="10" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<Cursor>
|
||||
<Cursor1 position="982" topLine="0" />
|
||||
<Cursor1 position="2887" topLine="53" />
|
||||
</Cursor>
|
||||
</File>
|
||||
<File name="SPL\inc\stm32f4xx_cryp.h" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
|
|
|
|||
|
|
@ -176,7 +176,7 @@ void SysTick_Handler(void)
|
|||
* Therefore we just poll them in this 1ms task, which is hopefully fast
|
||||
* enough for critical events. Debouncing pins is also implemented here.
|
||||
*/
|
||||
uint8_t limits = Limits_GetState() & Limits_GetState();
|
||||
uint8_t limits = Limits_GetState();
|
||||
if(limits) {
|
||||
// X-Y-Z Limit
|
||||
if((DebounceCounterLimits == 0) && settings.system_flags & BITFLAG_ENABLE_LIMITS) {
|
||||
|
|
|
|||
22
Makefile
22
Makefile
|
|
@ -9,10 +9,14 @@
|
|||
#---------------------------------------------------------------------------------
|
||||
.SUFFIXES:
|
||||
#---------------------------------------------------------------------------------
|
||||
CC = arm-none-eabi-gcc
|
||||
CXX = arm-none-eabi-g++
|
||||
OBJ = arm-none-eabi-objcopy
|
||||
SIZE = arm-none-eabi-size
|
||||
# Location of gcc-arm-none-eabi toolchain
|
||||
GCC_BASE = /opt/gcc-arm-none-eabi-8-2018-q4-major/bin
|
||||
|
||||
CC = ${GCC_BASE}/arm-none-eabi-gcc
|
||||
CXX = ${GCC_BASE}/arm-none-eabi-g++
|
||||
OBJCPY = ${GCC_BASE}/arm-none-eabi-objcopy
|
||||
SIZE = ${GCC_BASE}/arm-none-eabi-size
|
||||
OBJDUMP = ${GCC_BASE}/arm-none-eabi-objdump
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# TARGET is the name of the output
|
||||
|
|
@ -30,10 +34,10 @@ INCLUDES := $(SOURCES) SPL/inc
|
|||
# options for code generation
|
||||
#---------------------------------------------------------------------------------
|
||||
FLAGS := -mfloat-abi=hard -mcpu=cortex-m4 -gdwarf-2 -mfpu=fpv4-sp-d16 -mthumb
|
||||
CFLAGS := -O2 -g1 -std=c99 -Wall -Wextra $(INCLUDE) -fno-common -fsingle-precision-constant -fdata-sections -ffunction-sections -fomit-frame-pointer -mlittle-endian -DUSE_STDPERIPH_DRIVER -DSTM32F411xE -DSTM32F411RE -D__FPU_USED -DARM_MATH_CM4
|
||||
CFLAGS := -O2 -g1 -std=c11 -Wall -Wextra $(INCLUDE) -fno-common -fsingle-precision-constant -fdata-sections -ffunction-sections -fomit-frame-pointer -mlittle-endian -DUSE_STDPERIPH_DRIVER -DSTM32F411xE -DSTM32F411RE -D__FPU_USED -DARM_MATH_CM4 -Wimplicit-fallthrough=0
|
||||
CXXFLAGS := $(CFLAGS)
|
||||
|
||||
LDFLAGS := -lm -flto -Wl,--gc-sections -T../stm32f411re_flash.ld -Wl,-M=$(OUTPUT).map --specs=nosys.specs -nostartfiles
|
||||
LDFLAGS := -lm -flto -Wl,--gc-sections -T../stm32f411re_flash.ld -Wl,-M=$(OUTPUT).map --specs=nosys.specs -nostartfiles --specs=nano.specs
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# any extra libraries we wish to link with the project
|
||||
|
|
@ -123,14 +127,14 @@ $(OUTPUT).elf: $(OFILES)
|
|||
|
||||
$(OUTPUT).bin: $(OUTPUT).elf
|
||||
@echo Creating bin...
|
||||
@$(OBJ) -O binary $< $@
|
||||
@$(OBJCPY) -O binary $< $@
|
||||
|
||||
$(OUTPUT).hex: $(OUTPUT).elf
|
||||
@echo Creating hex...
|
||||
@$(OBJ) -O ihex $< $@
|
||||
@$(OBJCPY) -O ihex $< $@
|
||||
|
||||
$(OUTPUT).lst: $(OUTPUT).elf
|
||||
@arm-none-eabi-objdump -d $< > $@
|
||||
@$(OBJDUMP) -d $< > $@
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# This rule links in binary data with the .c extension
|
||||
|
|
|
|||
12
README.md
12
README.md
|
|
@ -26,6 +26,18 @@ Added Canned Drill Cycles G81-G83 as experimental features. They are roughly tes
|
|||
#### Hard Reset
|
||||
0x19 (CTRL-Y): Perform a hard reset.
|
||||
|
||||
#### I2C EEPROM
|
||||
Added support for external EEPROM. Uncomment 'USE_EXT_EEPROM' in Config.h.
|
||||
|
||||
#### Tool change
|
||||
* $14=(tool change mode): 0 = Ignore M6; 1 = Manual Tool Change; 2 = Manual Tool Change + TLS
|
||||
* $P: Save TLS position
|
||||
|
||||
Uses Dynamic TLO when $14=2
|
||||
|
||||
#### Attention
|
||||
By default, settings are stored in internal flash memory in last sector. First startup takes about 5-10sec to write all settings.
|
||||
|
||||
***
|
||||
|
||||
### Build Environment:
|
||||
|
|
|
|||
26
grbl/GCode.c
26
grbl/GCode.c
|
|
@ -30,6 +30,7 @@
|
|||
#include "MotionControl.h"
|
||||
#include "Protocol.h"
|
||||
#include "util.h"
|
||||
#include "ToolChange.h"
|
||||
#include "GCode.h"
|
||||
|
||||
#include <math.h>
|
||||
|
|
@ -135,6 +136,7 @@ uint8_t GC_ExecuteLine(char *line)
|
|||
uint8_t int_value = 0;
|
||||
uint16_t mantissa = 0;
|
||||
float old_xyz[N_AXIS] = {0.0};
|
||||
uint8_t change_tool = 0;
|
||||
|
||||
memcpy(old_xyz, gc_state.position, N_AXIS*sizeof(float));
|
||||
|
||||
|
|
@ -404,6 +406,10 @@ uint8_t GC_ExecuteLine(char *line)
|
|||
}
|
||||
break;
|
||||
|
||||
case 6: // Tool change
|
||||
change_tool = 1;
|
||||
break;
|
||||
|
||||
#ifdef ENABLE_M7
|
||||
case 7: case 8: case 9:
|
||||
#else
|
||||
|
|
@ -1418,7 +1424,18 @@ uint8_t GC_ExecuteLine(char *line)
|
|||
// [5. Select tool ]: NOT SUPPORTED. Only tracks tool value.
|
||||
gc_state.tool = gc_block.values.t;
|
||||
|
||||
// [6. Change tool ]: NOT SUPPORTED
|
||||
// [6. Change tool ]:
|
||||
if(change_tool && (settings.tool_change > 0))
|
||||
{
|
||||
if(sys.is_homed)
|
||||
{
|
||||
TC_ChangeCurrentTool();
|
||||
}
|
||||
else
|
||||
{
|
||||
return STATUS_MACHINE_NOT_HOMED;
|
||||
}
|
||||
}
|
||||
|
||||
// [7. Spindle control ]:
|
||||
if(gc_state.modal.spindle != gc_block.modal.spindle)
|
||||
|
|
@ -1585,11 +1602,18 @@ uint8_t GC_ExecuteLine(char *line)
|
|||
delta_y = gc_block.values.xyz[Y_AXIS] - old_xyz[Y_AXIS];
|
||||
}
|
||||
|
||||
if(clear_z < gc_block.values.xyz[Z_AXIS])
|
||||
{
|
||||
// Error
|
||||
return STATUS_GCODE_INVALID_TARGET;
|
||||
}
|
||||
|
||||
//-- [G81] --
|
||||
|
||||
// 0. Check if old_z < clear_z
|
||||
if(old_xyz[Z_AXIS] < clear_z)
|
||||
{
|
||||
// Move old_z to clear_z
|
||||
memcpy(xyz, old_xyz, N_AXIS*sizeof(float));
|
||||
xyz[Z_AXIS] = clear_z;
|
||||
|
||||
|
|
|
|||
|
|
@ -252,7 +252,7 @@ void Limits_GoHome(uint8_t cycle_mask)
|
|||
|
||||
// Exit routines: No time to run protocol_execute_realtime() in this loop.
|
||||
if(sys_rt_exec_state & (EXEC_SAFETY_DOOR | EXEC_RESET | EXEC_CYCLE_STOP)) {
|
||||
uint8_t rt_exec = sys_rt_exec_state;
|
||||
uint16_t rt_exec = sys_rt_exec_state;
|
||||
|
||||
// Homing failure condition: Reset issued during cycle.
|
||||
if(rt_exec & EXEC_RESET) {
|
||||
|
|
|
|||
|
|
@ -129,7 +129,7 @@ void Protocol_MainLoop(void)
|
|||
// Grbl '$' system command
|
||||
Report_StatusMessage(System_ExecuteLine(line));
|
||||
}
|
||||
else if(sys.state & (STATE_ALARM | STATE_JOG)) {
|
||||
else if(sys.state & (STATE_ALARM | STATE_JOG | STATE_TOOL_CHANGE)) {
|
||||
// Everything else is gcode. Block if in alarm or jog mode.
|
||||
Report_StatusMessage(STATUS_SYSTEM_GC_LOCK);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -231,6 +231,7 @@ void Report_GrblSettings(void) {
|
|||
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_IS_TRUE(settings.flags, BITFLAG_REPORT_INCHES));
|
||||
report_util_uint8_setting(14, settings.tool_change);
|
||||
report_util_uint8_setting(20, BIT_IS_TRUE(settings.flags, BITFLAG_SOFT_LIMIT_ENABLE));
|
||||
report_util_uint8_setting(21, BIT_IS_TRUE(settings.flags, BITFLAG_HARD_LIMIT_ENABLE));
|
||||
report_util_uint8_setting(22, BIT_IS_TRUE(settings.flags, BITFLAG_HOMING_ENABLE));
|
||||
|
|
@ -303,6 +304,29 @@ void Report_ProbeParams(void)
|
|||
}
|
||||
|
||||
|
||||
void Report_TLSParams(void)
|
||||
{
|
||||
float print_position[N_AXIS];
|
||||
uint8_t idx = 0;
|
||||
|
||||
// Report in terms of machine position.
|
||||
Printf("[TLS:");
|
||||
System_ConvertArraySteps2Mpos(print_position, settings.tls_position);
|
||||
|
||||
for(idx = 0; idx < 3; idx++) {
|
||||
PrintFloat_CoordValue(print_position[idx]);
|
||||
|
||||
if(idx < (3-1)) {
|
||||
Putc(',');
|
||||
}
|
||||
}
|
||||
|
||||
Putc(':');
|
||||
Printf("%d", settings.tls_valid);
|
||||
report_util_feedback_line_feed();
|
||||
}
|
||||
|
||||
|
||||
// Prints Grbl NGC parameters (coordinate offsets, probing)
|
||||
void Report_NgcParams(void)
|
||||
{
|
||||
|
|
@ -344,7 +368,8 @@ void Report_NgcParams(void)
|
|||
Printf("[TLO:"); // Print tool length offset value
|
||||
PrintFloat_CoordValue(gc_state.tool_length_offset);
|
||||
report_util_feedback_line_feed();
|
||||
Report_ProbeParams(); // Print probe parameters. Not persistent in memory.
|
||||
Report_ProbeParams(); // Print probe parameters. Not persistent in memory.
|
||||
Report_TLSParams(); // Print tls position. Persistent in memory.
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -628,6 +653,14 @@ void Report_RealtimeStatus(void)
|
|||
Printf("Sleep");
|
||||
break;
|
||||
|
||||
case STATE_FEED_DWELL:
|
||||
Printf("Dwell");
|
||||
break;
|
||||
|
||||
case STATE_TOOL_CHANGE:
|
||||
Printf("Tool");
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -43,6 +43,7 @@
|
|||
#define STATUS_TRAVEL_EXCEEDED 15
|
||||
#define STATUS_INVALID_JOG_COMMAND 16
|
||||
#define STATUS_SETTING_DISABLED_LASER 17
|
||||
#define STATUS_MACHINE_NOT_HOMED 18
|
||||
|
||||
#define STATUS_GCODE_UNSUPPORTED_COMMAND 20
|
||||
#define STATUS_GCODE_MODAL_GROUP_VIOLATION 21
|
||||
|
|
@ -116,6 +117,9 @@ void Report_RealtimeStatus(void);
|
|||
// Prints recorded probe position
|
||||
void Report_ProbeParams(void);
|
||||
|
||||
// Prints tls position
|
||||
void Report_TLSParams(void);
|
||||
|
||||
// Prints Grbl NGC parameters (coordinate offsets, probe)
|
||||
void Report_NgcParams(void);
|
||||
|
||||
|
|
|
|||
|
|
@ -133,6 +133,12 @@ void Settings_Restore(uint8_t restore_flag) {
|
|||
settings.backlash[Y_AXIS] = DEFAULT_Y_BACKLASH;
|
||||
settings.backlash[Z_AXIS] = DEFAULT_Z_BACKLASH;
|
||||
|
||||
settings.tool_change = DEFAULT_TOOL_CHANGE_MODE;
|
||||
settings.tls_valid = 0;
|
||||
settings.tls_position[X_AXIS] = 0;
|
||||
settings.tls_position[Y_AXIS] = 0;
|
||||
settings.tls_position[Z_AXIS] = 0;
|
||||
|
||||
WriteGlobalSettings();
|
||||
}
|
||||
|
||||
|
|
@ -326,6 +332,8 @@ uint8_t Settings_StoreGlobalSetting(uint8_t parameter, float value) {
|
|||
System_FlagWcoChange(); // Make sure WCO is immediately updated.
|
||||
break;
|
||||
|
||||
case 14: settings.tool_change = int_value; break; // Check for range?
|
||||
|
||||
case 20:
|
||||
if (int_value) {
|
||||
if (BIT_IS_FALSE(settings.flags, BITFLAG_HOMING_ENABLE)) { return(STATUS_SOFT_LIMIT_ERROR); }
|
||||
|
|
@ -370,6 +378,15 @@ uint8_t Settings_StoreGlobalSetting(uint8_t parameter, float value) {
|
|||
}
|
||||
|
||||
|
||||
void Settings_StoreTlsPosition(void)
|
||||
{
|
||||
memcpy(settings.tls_position, sys_position, sizeof(float)*N_AXIS);
|
||||
settings.tls_valid = 1;
|
||||
|
||||
WriteGlobalSettings();
|
||||
}
|
||||
|
||||
|
||||
// Initialize the config subsystem
|
||||
void Settings_Init(void)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@
|
|||
|
||||
// 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 3 // NOTE: Check settings_reset() when moving to next version.
|
||||
#define SETTINGS_VERSION 4 // NOTE: Check settings_reset() when moving to next version.
|
||||
|
||||
|
||||
// Define bit flag masks for the boolean settings in settings.system_flags
|
||||
|
|
@ -87,7 +87,8 @@
|
|||
#endif
|
||||
|
||||
|
||||
// Global persistent settings (Stored from byte EEPROM_ADDR_GLOBAL onwards)
|
||||
#pragma pack(push, 1) // exact fit - no padding
|
||||
// Global persistent settings (Stored from byte EEPROM_ADDR_GLOBAL onwards); 111 Bytes
|
||||
typedef struct {
|
||||
// Axis settings
|
||||
float steps_per_mm[N_AXIS];
|
||||
|
|
@ -97,6 +98,13 @@ typedef struct {
|
|||
|
||||
float backlash[N_AXIS];
|
||||
|
||||
// Tool change mode
|
||||
uint8_t tool_change;
|
||||
|
||||
// Position of tool length sensor (only XYZ axis)
|
||||
int32_t tls_position[N_AXIS];
|
||||
uint8_t tls_valid;
|
||||
|
||||
// Remaining Grbl settings
|
||||
// TODO: document system_flags
|
||||
uint8_t system_flags;
|
||||
|
|
@ -118,6 +126,7 @@ typedef struct {
|
|||
uint16_t homing_debounce_delay;
|
||||
float homing_pulloff;
|
||||
} Settings_t;
|
||||
#pragma pack(pop)
|
||||
|
||||
|
||||
extern Settings_t settings;
|
||||
|
|
@ -132,6 +141,9 @@ void Settings_Restore(uint8_t restore_flag);
|
|||
// A helper method to set new settings from command line
|
||||
uint8_t Settings_StoreGlobalSetting(uint8_t parameter, float value);
|
||||
|
||||
// Save current position to tls position
|
||||
void Settings_StoreTlsPosition(void);
|
||||
|
||||
// Stores the protocol line variable as a startup line in EEPROM
|
||||
void Settings_StoreStartupLine(uint8_t n, char *line);
|
||||
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@
|
|||
#include "Settings.h"
|
||||
#include "Stepper.h"
|
||||
#include "System.h"
|
||||
#include "ToolChange.h"
|
||||
#include "System32.h"
|
||||
|
||||
|
||||
|
|
@ -234,6 +235,30 @@ uint8_t System_ExecuteLine(char *line)
|
|||
}
|
||||
break;
|
||||
|
||||
case 'T':
|
||||
// Tool change finished. Continue execution
|
||||
System_ClearExecStateFlag(EXEC_TOOL_CHANGE);
|
||||
sys.state = STATE_IDLE;
|
||||
|
||||
// Check if machine is homed and tls enabled
|
||||
if(sys.is_homed && (settings.tool_change == 2))
|
||||
{
|
||||
TC_ProbeTLS();
|
||||
}
|
||||
break;
|
||||
|
||||
case 'P':
|
||||
if(sys.is_homed)
|
||||
{
|
||||
Settings_StoreTlsPosition();
|
||||
}
|
||||
else
|
||||
{
|
||||
return STATUS_MACHINE_NOT_HOMED;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
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) ) {
|
||||
|
|
@ -517,7 +542,7 @@ uint8_t System_CheckTravelLimits(float *target)
|
|||
|
||||
|
||||
// Special handlers for setting and clearing Grbl's real-time execution flags.
|
||||
void System_SetExecStateFlag(uint8_t mask)
|
||||
void System_SetExecStateFlag(uint16_t mask)
|
||||
{
|
||||
uint32_t primask = __get_PRIMASK();
|
||||
__disable_irq();
|
||||
|
|
@ -528,7 +553,7 @@ void System_SetExecStateFlag(uint8_t mask)
|
|||
}
|
||||
|
||||
|
||||
void System_ClearExecStateFlag(uint8_t mask)
|
||||
void System_ClearExecStateFlag(uint16_t mask)
|
||||
{
|
||||
uint32_t primask = __get_PRIMASK();
|
||||
__disable_irq();
|
||||
|
|
|
|||
|
|
@ -39,6 +39,9 @@
|
|||
#define EXEC_MOTION_CANCEL BIT(6)
|
||||
#define EXEC_SLEEP BIT(7)
|
||||
|
||||
#define EXEC_FEED_DWELL BIT(8)
|
||||
#define EXEC_TOOL_CHANGE BIT(9)
|
||||
|
||||
// Alarm executor codes. Valid values (1-255). Zero is reserved.
|
||||
#define EXEC_ALARM_HARD_LIMIT 1
|
||||
#define EXEC_ALARM_SOFT_LIMIT 2
|
||||
|
|
@ -84,6 +87,9 @@
|
|||
#define STATE_SAFETY_DOOR BIT(6) // Safety door is ajar. Feed holds and de-energizes system.
|
||||
#define STATE_SLEEP BIT(7) // Sleep state.
|
||||
|
||||
#define STATE_FEED_DWELL BIT(8) // Dwell
|
||||
#define STATE_TOOL_CHANGE BIT(9) // Tool change in progress
|
||||
|
||||
// Define system suspend flags. Used in various ways to manage suspend states and procedures.
|
||||
#define SUSPEND_DISABLE 0 // Must be zero.
|
||||
#define SUSPEND_HOLD_COMPLETE BIT(0) // Indicates initial feed hold is complete.
|
||||
|
|
@ -120,7 +126,7 @@
|
|||
|
||||
// Define global system variables
|
||||
typedef struct {
|
||||
uint8_t state; // Tracks the current system state of Grbl.
|
||||
uint16_t state; // Tracks the current system state of Grbl.
|
||||
uint8_t abort; // System abort flag. Forces exit back to main loop for reset.
|
||||
uint8_t suspend; // System suspend bitflag variable that manages holds, cancels, and safety door.
|
||||
uint8_t soft_limit; // Tracks soft limit errors for the state machine. (boolean)
|
||||
|
|
@ -137,6 +143,7 @@ typedef struct {
|
|||
uint8_t override_ctrl; // Tracks override control states.
|
||||
#endif
|
||||
float spindle_speed;
|
||||
uint8_t is_homed;
|
||||
} System_t;
|
||||
|
||||
extern System_t sys;
|
||||
|
|
@ -146,7 +153,7 @@ 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 uint16_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.
|
||||
|
|
@ -189,8 +196,8 @@ int32_t system_convert_corexy_to_y_axis_steps(int32_t *steps);
|
|||
uint8_t System_CheckTravelLimits(float *target);
|
||||
|
||||
// Special handlers for setting and clearing Grbl's real-time execution flags.
|
||||
void System_SetExecStateFlag(uint8_t mask);
|
||||
void System_ClearExecStateFlag(uint8_t mask);
|
||||
void System_SetExecStateFlag(uint16_t mask);
|
||||
void System_ClearExecStateFlag(uint16_t mask);
|
||||
void System_SetExecAlarm(uint8_t code);
|
||||
void System_ClearExecAlarm(void);
|
||||
void System_SetExecMotionOverrideFlag(uint8_t mask);
|
||||
|
|
|
|||
|
|
@ -0,0 +1,183 @@
|
|||
/*
|
||||
ToolChange.c - Changing tool
|
||||
Part of Grbl-Advanced
|
||||
|
||||
Copyright (c) 2018-2019 Patrick F.
|
||||
|
||||
Grbl-Advanced is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Grbl-Advanced is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with Grbl-Advanced. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include <string.h>
|
||||
#include "ToolChange.h"
|
||||
#include "GCode.h"
|
||||
#include "MotionControl.h"
|
||||
#include "Protocol.h"
|
||||
#include "System.h"
|
||||
#include "System32.h"
|
||||
#include "SpindleControl.h"
|
||||
#include "Settings.h"
|
||||
#include "defaults.h"
|
||||
|
||||
|
||||
static uint8_t isFirstTC = 1;
|
||||
static int32_t toolOffset = 0;
|
||||
static int32_t toolReferenz = 0;
|
||||
|
||||
|
||||
void TC_Init(void)
|
||||
{
|
||||
isFirstTC = 1;
|
||||
toolOffset = 0;
|
||||
toolReferenz = 0;
|
||||
|
||||
gc_state.modal.tool_length = TOOL_LENGTH_OFFSET_CANCEL;
|
||||
gc_state.tool_length_offset = 0.0;
|
||||
}
|
||||
|
||||
|
||||
void TC_ChangeCurrentTool(void)
|
||||
{
|
||||
Planner_LineData_t pl_data = {0};
|
||||
float position[N_AXIS] = {0.0};
|
||||
|
||||
|
||||
if(sys.state == STATE_CHECK_MODE)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Wait until queue is processed
|
||||
Protocol_BufferSynchronize();
|
||||
|
||||
// Don't move XY. Go to Z 0
|
||||
System_ConvertArraySteps2Mpos(position, sys_position);
|
||||
position[Z_AXIS] = 0.0;
|
||||
|
||||
//System_SetExecStateFlag(EXEC_TOOL_CHANGE);
|
||||
|
||||
pl_data.feed_rate = 0.0;
|
||||
pl_data.condition |= PL_COND_FLAG_RAPID_MOTION; // Set rapid motion condition flag.
|
||||
pl_data.backlash_motion = 0;
|
||||
pl_data.spindle_speed = 0;
|
||||
pl_data.line_number = gc_state.line_number;
|
||||
|
||||
MC_Line(position, &pl_data);
|
||||
Delay_ms(5);
|
||||
|
||||
Spindle_Stop();
|
||||
|
||||
// Wait until queue is processed
|
||||
Protocol_BufferSynchronize();
|
||||
|
||||
// Wait until move is finished
|
||||
while(sys.state != STATE_IDLE);
|
||||
|
||||
sys.state = STATE_TOOL_CHANGE;
|
||||
|
||||
GC_SyncPosition();
|
||||
}
|
||||
|
||||
|
||||
void TC_ProbeTLS(void)
|
||||
{
|
||||
Planner_LineData_t pl_data = {0};
|
||||
float position[N_AXIS] = {0.0};
|
||||
uint8_t flags = 0;
|
||||
|
||||
|
||||
if(sys.state == STATE_CHECK_MODE || settings.tls_valid == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Move to XY position of TLS
|
||||
System_ConvertArraySteps2Mpos(position, settings.tls_position);
|
||||
position[Z_AXIS] = 0.0;
|
||||
|
||||
// Set-up planer
|
||||
pl_data.feed_rate = 0.0;
|
||||
pl_data.condition |= PL_COND_FLAG_RAPID_MOTION; // Set rapid motion condition flag.
|
||||
pl_data.backlash_motion = 0;
|
||||
pl_data.spindle_speed = 0;
|
||||
pl_data.line_number = gc_state.line_number;
|
||||
|
||||
// Move to X/Y position of TLS
|
||||
MC_Line(position, &pl_data);
|
||||
|
||||
// Move down with offset (for tool)
|
||||
position[Z_AXIS] = (settings.tls_position[Z_AXIS] / settings.steps_per_mm[Z_AXIS]) + 90.0;
|
||||
MC_Line(position, &pl_data);
|
||||
|
||||
// Wait until queue is processed
|
||||
Protocol_BufferSynchronize();
|
||||
|
||||
// Set up fast probing
|
||||
pl_data.feed_rate = 180.0;
|
||||
pl_data.condition = 0; // Set rapid motion condition flag.
|
||||
|
||||
// Probe TLS fast
|
||||
position[Z_AXIS] -= 200.0;
|
||||
uint8_t ret = MC_ProbeCycle(position, &pl_data, flags);
|
||||
if(ret != GC_PROBE_FOUND)
|
||||
{
|
||||
// Error
|
||||
return;
|
||||
}
|
||||
|
||||
// Get current position
|
||||
System_ConvertArraySteps2Mpos(position, sys_position);
|
||||
position[Z_AXIS] += 2.0;
|
||||
|
||||
// Move up a little bit for slow probing
|
||||
pl_data.feed_rate = 200.0;
|
||||
MC_Line(position, &pl_data);
|
||||
|
||||
// Probe TLS slow
|
||||
pl_data.feed_rate = 12.0;
|
||||
position[Z_AXIS] -= 200;
|
||||
ret = MC_ProbeCycle(position, &pl_data, flags);
|
||||
if(ret != GC_PROBE_FOUND)
|
||||
{
|
||||
// Error
|
||||
return;
|
||||
}
|
||||
|
||||
if(isFirstTC)
|
||||
{
|
||||
// Save first tool as reference
|
||||
isFirstTC = 0;
|
||||
toolReferenz = sys_probe_position[Z_AXIS];
|
||||
}
|
||||
else
|
||||
{
|
||||
// Calculate tool offset
|
||||
toolOffset = sys_probe_position[Z_AXIS] - toolReferenz;
|
||||
|
||||
// Apply offset as dynamic tool length offset
|
||||
gc_state.modal.tool_length = TOOL_LENGTH_OFFSET_ENABLE_DYNAMIC;
|
||||
gc_state.tool_length_offset = toolOffset / settings.steps_per_mm[Z_AXIS];
|
||||
}
|
||||
|
||||
Delay_ms(5);
|
||||
|
||||
// Move Z up
|
||||
position[Z_AXIS] = 0.0;
|
||||
pl_data.condition |= PL_COND_FLAG_RAPID_MOTION; // Set rapid motion condition flag.
|
||||
|
||||
MC_Line(position, &pl_data);
|
||||
|
||||
// Wait until queue is processed
|
||||
Protocol_BufferSynchronize();
|
||||
|
||||
GC_SyncPosition();
|
||||
}
|
||||
|
|
@ -0,0 +1,33 @@
|
|||
/*
|
||||
ToolChange.h - Changing tool
|
||||
Part of Grbl-Advanced
|
||||
|
||||
Copyright (c) 2018-2019 Patrick F.
|
||||
|
||||
Grbl-Advanced is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Grbl-Advanced is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with Grbl-Advanced. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef TOOLCHANGE_H_INCLUDED
|
||||
#define TOOLCHANGE_H_INCLUDED
|
||||
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
|
||||
void TC_Init(void);
|
||||
void TC_ChangeCurrentTool(void);
|
||||
void TC_ProbeTLS(void);
|
||||
|
||||
|
||||
#endif /* TOOLCHANGE_H_INCLUDED */
|
||||
|
|
@ -70,7 +70,7 @@
|
|||
#define DEFAULT_HOMING_DEBOUNCE_DELAY 250 // msec (0-65k)
|
||||
#define DEFAULT_HOMING_PULLOFF 1.0 // mm
|
||||
#define DEFAULT_TOOL_CHANGE_MODE 0 // 0 = Ignore M6; 1 = Manual tool change; 2 = Manual tool change + TLS
|
||||
#define DEFAULT_TOOL_SENSOR_OFFSET 130.0 // mm
|
||||
#define DEFAULT_TOOL_SENSOR_OFFSET 100.0 // mm
|
||||
#endif
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@
|
|||
#include "Stepper.h"
|
||||
#include "System.h"
|
||||
#include "util.h"
|
||||
#include "ToolChange.h"
|
||||
|
||||
|
||||
#endif // GRBL_ADVANCE_H_INCLUDED
|
||||
|
|
|
|||
5
main.c
5
main.c
|
|
@ -33,7 +33,7 @@ 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 uint16_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.
|
||||
|
|
@ -68,7 +68,7 @@ int main(void)
|
|||
while(1)
|
||||
{
|
||||
// Reset system variables.
|
||||
uint8_t prior_state = sys.state;
|
||||
uint16_t prior_state = sys.state;
|
||||
|
||||
System_Clear();
|
||||
sys.state = prior_state;
|
||||
|
|
@ -85,6 +85,7 @@ int main(void)
|
|||
GC_Init();
|
||||
Planner_Init();
|
||||
MC_Init();
|
||||
TC_Init();
|
||||
|
||||
Coolant_Init();
|
||||
Limits_Init();
|
||||
|
|
|
|||
Ładowanie…
Reference in New Issue