1
0
mirror of https://github.com/bdring/Grbl_Esp32.git synced 2025-09-09 22:01:14 +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; uint8_t current_tool = 0;
void go_above_tool(uint8_t tool_num); 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 atc_ETS();
bool set_ATC_open(bool open); bool set_ATC_open(bool open);
void gc_exec_linef(bool sync_after, const char* format, ...); 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) { if (gc_state.modal.spindle != SpindleState::Disable) {
spindle_was_on = true; spindle_was_on = true;
gc_exec_linef(false, "M5"); 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
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");
current_tool = new_tool;
return true;
}
go_above_tool(new_tool);
uint64_t current_time = esp_timer_get_time(); uint64_t current_time = esp_timer_get_time();
if (current_time < spindle_spin_delay) { if (current_time < spindle_spin_delay) {
vTaskDelay(spindle_spin_delay - current_time); 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;
}
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
//go_above_tool(new_tool);
set_ATC_open(true); // open ATC set_ATC_open(true); // open ATC
gc_exec_linef(true, "G53G0Z%0.3f", tool[new_tool].mpos[Z_AXIS]); // drop down to tool 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; 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 if (!atc_ETS()) { // check the length of the tool
return false; return false;
} }
@@ -168,9 +171,12 @@ bool user_tool_change(uint8_t new_tool) {
// return to saved mpos in XY // 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); 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 // return to saved mpos in Z if it is not outside of work area.
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); 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 // was was_incremental on? If so, return to that state
if (was_incremental) { if (was_incremental) {
gc_exec_linef(false, "G91"); 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 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) { bool return_tool(uint8_t tool_num) {
if (tool_num == 0) if (tool_num == 0) {
return; return false;
}
go_above_tool(tool_num); go_above_tool(tool_num);
gc_exec_linef(true, "G53G0Z%0.3f", tool[tool_num].mpos[Z_AXIS]); // drop down to tool gc_exec_linef(true, "G53G0Z%0.3f", tool[tool_num].mpos[Z_AXIS]); // drop down to tool
set_ATC_open(true); // open ATC set_ATC_open(true);
//gc_exec_linef(false, "G4P0.5"); // wait gc_exec_linef(true, "G53G0Z%0.3f", ATC_EMPTY_SAFE_HEIGHT); // Go just above tools
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(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() { bool atc_ETS() {
@@ -352,7 +358,7 @@ void gc_exec_linef(bool sync_after, const char* format, ...) {
len = vsnprintf(temp, len + 1, format, arg); len = vsnprintf(temp, len + 1, format, arg);
gc_execute_line(temp, CLIENT_INPUT); 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); va_end(arg);
if (temp != loc_buf) { if (temp != loc_buf) {
delete[] temp; delete[] temp;