Skip to content

Commit

Permalink
WIP - Still borken
Browse files Browse the repository at this point in the history
  • Loading branch information
bdring committed Jan 7, 2025
1 parent c692589 commit ac1fe59
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
13 changes: 10 additions & 3 deletions FluidNC/src/GCode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1605,14 +1605,15 @@ Error gc_execute_line(char* line) {
// NOTE: Pass zero spindle speed for all restricted laser motions.
if (!disableLaser) {
pl_data->spindle_speed = gc_state.spindle_speed; // Record data for planner use.
} // else { pl_data->spindle_speed = 0.0; } // Initialized as zero already.
} // else { pl_data->spindle_speed = 0.0; } // Initialized as zero already.
// [5. Select tool ]: NOT SUPPORTED. Only tracks tool value.
// [M6. Change tool ]:
if (gc_block.modal.tool_change == ToolChange::Enable) {
if (gc_state.selected_tool != gc_state.current_tool) {
bool stopped_spindle = false; // was spindle stopped via the change
bool new_spindle = false; // was the spindle changed
protocol_buffer_synchronize(); // wait for motion in buffer to finish

Spindles::Spindle::switchSpindle(
gc_state.selected_tool, Spindles::SpindleFactory::objects(), spindle, stopped_spindle, new_spindle);
if (stopped_spindle) {
Expand All @@ -1621,13 +1622,19 @@ Error gc_execute_line(char* line) {
if (new_spindle) {
gc_state.spindle_speed = 0.0;
}
log_info("Sel:" << gc_state.selected_tool << " Cur:" << gc_state.current_tool);
spindle->tool_change(gc_state.selected_tool, false, false);
gc_state.current_tool = gc_state.selected_tool;
report_ovr_counter = 0; // Set to report change immediately
if (spindle->_atc_name == "" && spindle->_m6_macro.get().empty()) { // if neither of these exist we need to set the value here
gc_state.current_tool = gc_state.selected_tool;
}
report_ovr_counter = 0; // Set to report change immediately
gc_ovr_changed();
}
}
if (gc_block.modal.set_tool_number == SetToolNumber::Enable) {
if (gc_block.values.q < 0) {
FAIL(Error::NegativeValue); // https://linuxcnc.org/docs/2.8/html/gcode/m-code.html#mcode:m61
}
gc_state.selected_tool = gc_block.values.q;
bool stopped_spindle = false; // was spindle stopped via the change
bool new_spindle = false; // was the spindle changed
Expand Down
19 changes: 12 additions & 7 deletions FluidNC/src/Spindles/Spindle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,13 @@ namespace Spindles {
spindle->stop(); // stop the current spindle
stop_spindle = true; // used to stop the next spindle
}
if (candidate != spindle) {
spindle = candidate;
new_spindle = true;
if (candidate != spindle) { // we are changing spindles
log_info("Sel:" << gc_state.selected_tool << " Cur:" << gc_state.current_tool);
//gc_state.selected_tool = 0; // we are changing the original spindle to tool 0, for use by macro or class
spindle->tool_change(new_tool, false, false); // run the tool change on the exiting spindle
gc_state.selected_tool = new_tool;
spindle = candidate;
new_spindle = true;
log_info("Changed to spindle:" << spindle->name());
}
} else {
Expand Down Expand Up @@ -129,27 +133,28 @@ namespace Spindles {
// pre_select is generally ignored except for machines that need to get a tool ready
// set_tool is just used to tell the atc what is already installed.
bool Spindle::tool_change(uint32_t tool_number, bool pre_select, bool set_tool) {
log_info(_name << " Spindle::tool_change Sel:" << gc_state.selected_tool << " Cur:" << gc_state.current_tool << "pre:" << pre_select << " set:" << set_tool);

if (_atc != NULL) {
log_info(_name << " spindle changed to tool:" << tool_number << " using " << _atc_name);
return _atc->tool_change(tool_number, pre_select, set_tool);
}
if (!_m6_macro.get().empty()) {
log_info(_name << " spindle changed to tool:" << tool_number << " using m6_macro");
log_info("#1 " << _name << " spindle changed to tool:" << tool_number << " using m6_macro" << _m6_macro.get());
if (pre_select) {
return true;
}
_last_tool = tool_number;
if (set_tool) {
return true;
}

//if (tool_number != _last_tool) {
log_info(_name << " spindle run macro: " << _m6_macro.get());
log_info("#2 " << _name << " spindle changed to tool:" << tool_number << " using m6_macro" << _m6_macro.get());
_m6_macro.run(nullptr);
_last_tool = tool_number;
return true;
//}
}

return true;
}

Expand Down

0 comments on commit ac1fe59

Please sign in to comment.