1
0
mirror of https://github.com/bdring/Grbl_Esp32.git synced 2025-09-03 03:13:25 +02:00
This commit is contained in:
bdring
2020-11-19 13:45:54 -06:00
parent 4acc0d8963
commit 985c4f60dc

View File

@@ -57,7 +57,7 @@ int zeroed_tool_index = 1; // Which tool was zero'd on the work piece
uint8_t current_tool = 0;
void go_above_tool(uint8_t tool_num);
void return_tool(uint8_t tool_num);
bool return_tool(uint8_t tool_num);
bool atc_ETS();
bool set_ATC_open(bool open);
void gc_exec_linef(bool sync_after, const char* format, ...);
@@ -121,25 +121,34 @@ bool user_tool_change(uint8_t new_tool) {
if (gc_state.modal.spindle != SpindleState::Disable) {
spindle_was_on = true;
gc_exec_linef(false, "M5");
}
// spindle could have been turned off in gcode before M6
spindle_spin_delay = esp_timer_get_time() + (spindle_delay_spindown->get() * 1000.0); // When will spindle spindown be done.
spindle_spin_delay = esp_timer_get_time() + (spindle_delay_spindown->get() * 1000.0); // When will spindle spindown be done.
return_tool(current_tool); // does nothing if we have no tool
// optimize this
uint64_t current_time = esp_timer_get_time();
if (current_time < spindle_spin_delay) {
vTaskDelay(spindle_spin_delay - current_time);
}
}
// ============= Start of tool change ====================
if (!return_tool(current_tool)) { // does nothing if we have no tool
gc_exec_linef(true, "G53 G0 X%0.3f Y%0.3f Z%0.3f", tool[new_tool].mpos[X_AXIS], tool[new_tool].mpos[Y_AXIS], top_of_z);
}
current_tool = 0;
if (new_tool == 0) { // if changing to tool 0...we are done.
grbl_msg_sendf(CLIENT_SERIAL, MsgLevel::Info, "ATC Changed to tool 0");
gc_exec_linef(true, "G53 G0 Z%0.3f", top_of_z);
gc_exec_linef(true, "G53 G0 Y%0.3f", tool[0].mpos[Y_AXIS] - RACK_SAFE_DIST);
current_tool = new_tool;
return true;
}
go_above_tool(new_tool);
gc_exec_linef(true, "G53 G0 X%0.3f Y%0.3f", tool[new_tool].mpos[X_AXIS],
tool[new_tool].mpos[Y_AXIS]); // Go over new tool
uint64_t current_time = esp_timer_get_time();
if (current_time < spindle_spin_delay) {
vTaskDelay(spindle_spin_delay - current_time);
}
//go_above_tool(new_tool);
set_ATC_open(true); // open ATC
gc_exec_linef(true, "G53G0Z%0.3f", tool[new_tool].mpos[Z_AXIS]); // drop down to tool
@@ -149,12 +158,6 @@ bool user_tool_change(uint8_t new_tool) {
current_tool = new_tool;
// if current tool = 1 it is safe to go straight the the ETS
if (current_tool != 1) {
// move in front of tool
//gc_exec_linef(false, "G53G0X%0.3fY%0.3f", tool[new_tool].mpos[X_AXIS], tool[new_tool].mpos[Y_AXIS] - RACK_SAFE_DIST);
}
if (!atc_ETS()) { // check the length of the tool
return false;
}
@@ -168,9 +171,12 @@ bool user_tool_change(uint8_t new_tool) {
// return to saved mpos in XY
gc_exec_linef(false, "G53G0X%0.3fY%0.3fZ%0.3f", saved_mpos[X_AXIS], saved_mpos[Y_AXIS], top_of_z);
// return to saved mpos in Z
gc_exec_linef(false, "G53G0X%0.3fY%0.3fZ%0.3f", saved_mpos[X_AXIS], saved_mpos[Y_AXIS], saved_mpos[Z_AXIS] + gc_state.tool_length_offset);
// return to saved mpos in Z if it is not outside of work area.
float adjusted_z = saved_mpos[Z_AXIS] + gc_state.tool_length_offset;
if (adjusted_z < limitsMaxPosition(Z_AXIS)) {
gc_exec_linef(
false, "G53G0X%0.3fY%0.3fZ%0.3f", saved_mpos[X_AXIS], saved_mpos[Y_AXIS], saved_mpos[Z_AXIS] + gc_state.tool_length_offset);
}
// was was_incremental on? If so, return to that state
if (was_incremental) {
gc_exec_linef(false, "G91");
@@ -225,18 +231,18 @@ void go_above_tool(uint8_t tool_num) {
gc_exec_linef(true, "G53G0X%0.3fY%0.3f", tool[tool_num].mpos[X_AXIS], tool[tool_num].mpos[Y_AXIS]); // Move over tool
}
void return_tool(uint8_t tool_num) {
if (tool_num == 0)
return;
bool return_tool(uint8_t tool_num) {
if (tool_num == 0) {
return false;
}
go_above_tool(tool_num);
gc_exec_linef(true, "G53G0Z%0.3f", tool[tool_num].mpos[Z_AXIS]); // drop down to tool
set_ATC_open(true); // open ATC
//gc_exec_linef(false, "G4P0.5"); // wait
gc_exec_linef(true, "G53G0Z%0.3f", top_of_z); // Go to top of Z travel
set_ATC_open(false); // close ATC
set_ATC_open(true);
gc_exec_linef(true, "G53G0Z%0.3f", ATC_EMPTY_SAFE_HEIGHT); // Go just above tools
set_ATC_open(false); // close ATC
//gc_exec_linef(true, "G53G0X%0.3fY%0.3f", tool[tool_num].mpos[X_AXIS], tool[tool_num].mpos[Y_AXIS] - RACK_SAFE_DIST); // move forward
return true;
}
bool atc_ETS() {
@@ -250,7 +256,7 @@ bool atc_ETS() {
gc_exec_linef(false, "G91");
// Arc out of current tool
gc_exec_linef(false, "G2 X-%0.3f Y-%0.3f I-%0.3f F4000", RACK_SAFE_DIST, RACK_SAFE_DIST, RACK_SAFE_DIST);
// Move it to arc start
gc_exec_linef(
false, "G53G0X%0.3fY%0.3f", tool[ETS_INDEX].mpos[X_AXIS] + RACK_SAFE_DIST, tool[ETS_INDEX].mpos[Y_AXIS] - RACK_SAFE_DIST);
@@ -259,7 +265,7 @@ bool atc_ETS() {
gc_exec_linef(false, "G2 X-%0.3f Y%0.3f J%0.3f F4000", RACK_SAFE_DIST, RACK_SAFE_DIST, RACK_SAFE_DIST);
gc_exec_linef(false, "G90");
// Move over tool
gc_exec_linef(true, "G53G0X%0.3fY%0.3f", tool[ETS_INDEX].mpos[X_AXIS], tool[ETS_INDEX].mpos[Y_AXIS]);
gc_exec_linef(true, "G53G0X%0.3fY%0.3f", tool[ETS_INDEX].mpos[X_AXIS], tool[ETS_INDEX].mpos[Y_AXIS]);
}
float wco = gc_state.coord_system[Z_AXIS] + gc_state.coord_offset[Z_AXIS] + gc_state.tool_length_offset;
@@ -352,7 +358,7 @@ void gc_exec_linef(bool sync_after, const char* format, ...) {
len = vsnprintf(temp, len + 1, format, arg);
gc_execute_line(temp, CLIENT_INPUT);
grbl_sendf(CLIENT_SERIAL, "[ATC GCode:%s]\r\n", temp);
//grbl_sendf(CLIENT_SERIAL, "[ATC GCode:%s]\r\n", temp);
va_end(arg);
if (temp != loc_buf) {
delete[] temp;