1
0
mirror of https://github.com/bdring/Grbl_Esp32.git synced 2025-09-08 21:30:54 +02:00

Manual tool change

This commit is contained in:
bdring
2020-11-30 14:34:34 -06:00
parent 5f95a5a763
commit 724c6e36b3
6 changed files with 51 additions and 17 deletions

View File

@@ -212,7 +212,7 @@ void calc_solenoid(float penZ) {
A tool (pen) change is done by bumping the carriage against the right edge 3 times per
position change. Pen 1-4 is valid range.
*/
bool user_tool_change(uint8_t new_tool) {
bool user_tool_change(uint8_t new_tool, bool automatic) {
uint8_t move_count;
char gcode_line[20];
protocol_buffer_synchronize(); // wait for all previous moves to complete

View File

@@ -71,35 +71,41 @@ void user_machine_init() {
pinMode(ETS_DUST_OFF, OUTPUT);
// the tool setter
tool[ETS_INDEX].mpos[X_AXIS] = 108;
tool[ETS_INDEX].mpos[X_AXIS] = 104;
tool[ETS_INDEX].mpos[Y_AXIS] = 292.0;
tool[ETS_INDEX].mpos[Z_AXIS] = -60.0; // Mpos before collet face triggers probe
tool[1].mpos[X_AXIS] = 151.0;
tool[1].mpos[Y_AXIS] = 291.0;
tool[1].mpos[X_AXIS] = 146.0;
tool[1].mpos[Y_AXIS] = 292.0;
tool[1].mpos[Z_AXIS] = -87.0;
tool[2].mpos[X_AXIS] = 186.0;
tool[2].mpos[Y_AXIS] = 291.0;
tool[2].mpos[X_AXIS] = 181.0;
tool[2].mpos[Y_AXIS] = 292.0;
tool[2].mpos[Z_AXIS] = -87.0;
tool[3].mpos[X_AXIS] = 221.0;
tool[3].mpos[X_AXIS] = 216.0;
tool[3].mpos[Y_AXIS] = 292.0;
tool[3].mpos[Z_AXIS] = -87.0;
tool[4].mpos[X_AXIS] = 256.0;
tool[4].mpos[Y_AXIS] = 291.0;
tool[4].mpos[X_AXIS] = 251.0;
tool[4].mpos[Y_AXIS] = 292.0;
tool[4].mpos[Z_AXIS] = -87.0;
top_of_z = limitsMaxPosition(Z_AXIS) - homing_pulloff->get();
}
bool user_tool_change(uint8_t new_tool) {
bool user_tool_change(uint8_t new_tool, bool automatic) {
bool spindle_was_on = false;
bool was_incremental_mode = false; // started in G91 mode
uint64_t spindle_spin_delay; // used to make sure spindle has fully spun down and up.
float saved_mpos[MAX_N_AXIS] = {}; // the position before the tool change
if (!automatic) {
current_tool = new_tool;
grbl_msg_sendf(CLIENT_ALL, MsgLevel::Info, "Manual tool change to:%d", current_tool);
return true;
}
if (new_tool == current_tool) { // if no change, we are done
grbl_msg_sendf(CLIENT_SERIAL, MsgLevel::Info, "ATC existing tool requested:%d", new_tool);
return true;

View File

@@ -123,7 +123,7 @@ void forward_kinematics(float* position) {
user_tool_change() is called when tool change gcode is received,
to perform appropriate actions for your machine.
*/
bool user_tool_change(uint8_t new_tool) {}
bool user_tool_change(uint8_t new_tool, bool automatic) {}
#if defined(MACRO_BUTTON_0_PIN) || defined(MACRO_BUTTON_1_PIN) || defined(MACRO_BUTTON_2_PIN)
/*

View File

@@ -516,6 +516,10 @@ Error gc_execute_line(char* line, uint8_t client) {
mg_word_bit = ModalGroup::MM9;
break;
#endif
case 61: // Set Current Tool
gc_block.modal.tool_change = ToolChange::SetTool;
mg_word_bit = ModalGroup::MM6;
break;
case 62:
gc_block.modal.io_control = IoControl::DigitalOnSync;
mg_word_bit = ModalGroup::MM10;
@@ -626,7 +630,10 @@ Error gc_execute_line(char* line, uint8_t client) {
case 'Q':
axis_word_bit = GCodeWord::Q;
gc_block.values.q = value;
//grbl_msg_sendf(CLIENT_SERIAL, MSG_LEVEL_INFO, "Q %2.2f", value);
if (gc_block.modal.tool_change == ToolChange::SetTool) { // M61
gc_state.tool = int_value;
}
break;
case 'R':
axis_word_bit = GCodeWord::R;
@@ -825,6 +832,19 @@ Error gc_execute_line(char* line, uint8_t client) {
bit_false(value_words, bit(GCodeWord::E));
bit_false(value_words, bit(GCodeWord::Q));
}
if (gc_block.non_modal_command == NonModal::Dwell) {
if (bit_isfalse(value_words, bit(GCodeWord::P))) {
FAIL(Error::GcodeValueWordMissing); // [P word missing]
}
bit_false(value_words, bit(GCodeWord::P));
}
if (gc_block.modal.tool_change == ToolChange::SetTool) {
if (bit_isfalse(value_words, bit(GCodeWord::Q))) {
FAIL(Error::GcodeValueWordMissing); // [P word missing]
}
bit_false(value_words, bit(GCodeWord::Q));
}
// [11. Set active plane ]: N/A
switch (gc_block.modal.plane_select) {
case Plane::XY:
@@ -1252,6 +1272,7 @@ Error gc_execute_line(char* line, uint8_t client) {
(bit(GCodeWord::X) | bit(GCodeWord::Y) | bit(GCodeWord::Z) | bit(GCodeWord::A) | bit(GCodeWord::B) |
bit(GCodeWord::C))); // Remove axis words.
}
if (value_words) {
FAIL(Error::GcodeUnusedWords); // [Unused words]
}
@@ -1350,12 +1371,19 @@ Error gc_execute_line(char* line, uint8_t client) {
} // else { pl_data->spindle_speed = 0.0; } // Initialized as zero already.
// [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 (gc_block.modal.tool_change == ToolChange::Enable) {
if (!user_tool_change(gc_state.tool)) { // (weak) should be user defined
if (!user_tool_change(gc_state.tool, true)) { // (weak) should be user defined
FAIL(Error::ToolChangeError);
}
}
// [61. Manually set current tool ]
if (gc_block.modal.tool_change == ToolChange::SetTool) {
if (!user_tool_change(gc_state.tool, false)) { // (weak) should be user defined
FAIL(Error::ToolChangeError);
}
}
// [7. Spindle control ]:
if (gc_state.modal.spindle != gc_block.modal.spindle) {
// Update spindle control and apply spindle speed when enabling it in this block.
@@ -1602,7 +1630,6 @@ Error gc_execute_line(char* line, uint8_t client) {
}
__attribute__((weak)) bool user_tool_change(uint8_t new_tool) {
return true;
}

View File

@@ -44,7 +44,7 @@ enum class ModalGroup : uint8_t {
MG12 = 9, // [G54,G55,G56,G57,G58,G59] Coordinate system selection
MG13 = 10, // [G61] Control mode
MM4 = 11, // [M0,M1,M2,M30] Stopping
MM6 = 14, // [M6] Tool change
MM6 = 14, // [M6, M61] Tool change, Set Current Tool
MM7 = 12, // [M3,M4,M5] Spindle turning
MM8 = 13, // [M7,M8,M9] Coolant control
MM9 = 14, // [M56] Override control
@@ -185,6 +185,7 @@ enum class ToolLengthOffset : uint8_t {
enum class ToolChange : uint8_t {
Disable = 0,
Enable = 1,
SetTool = 2, // tell Grbl the current tool
};
// Modal Group G12: Active work coordinate system

View File

@@ -114,4 +114,4 @@ void user_defined_macro(uint8_t index);
// Called if USE_M30 is defined
void user_m30();
bool user_tool_change(uint8_t new_tool); // weak
bool user_tool_change(uint8_t new_tool, bool automatic); // weak