Skip to content

Commit

Permalink
first cut of adding _selected_tool
Browse files Browse the repository at this point in the history
  • Loading branch information
bdring committed Nov 14, 2024
1 parent 870d88f commit 00f365c
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 10 deletions.
19 changes: 12 additions & 7 deletions FluidNC/src/GCode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ void gc_init() {
// Load default G54 coordinate system.
gc_state.modal = modal_defaults;
gc_state.modal.override = config->_start->_deactivateParking ? Override::Disabled : Override::ParkingMotion;
gc_state.current_tool = -1;
coords[gc_state.modal.coord_select]->get(gc_state.coord_system);
flowcontrol_init();
}
Expand Down Expand Up @@ -1611,25 +1612,28 @@ Error gc_execute_line(char* line) {
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);
Spindles::Spindle::switchSpindle(
gc_state.selected_tool, Spindles::SpindleFactory::objects(), spindle, stopped_spindle, new_spindle);
if (stopped_spindle) {
gc_block.modal.spindle = SpindleState::Disable;
}
if (new_spindle) {
gc_state.spindle_speed = 0.0;
}
spindle->tool_change(gc_state.selected_tool, false, false);
gc_state.tool = gc_state.selected_tool;
report_ovr_counter = 0; // Set to report change immediately
gc_state.tool = gc_state.selected_tool;
gc_state.current_tool = gc_state.tool;
report_ovr_counter = 0; // Set to report change immediately
gc_ovr_changed();
}
}
if (gc_block.modal.set_tool_number == SetToolNumber::Enable) {
gc_state.selected_tool = gc_block.values.q;
gc_state.tool = gc_state.selected_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

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) {
gc_block.modal.spindle = SpindleState::Disable;
Expand All @@ -1638,7 +1642,8 @@ Error gc_execute_line(char* line) {
gc_state.spindle_speed = 0.0;
}
spindle->tool_change(gc_state.selected_tool, false, true);
report_ovr_counter = 0; // Set to report change immediately
gc_state.current_tool = gc_block.values.q;
report_ovr_counter = 0; // Set to report change immediately
gc_ovr_changed();
}
// [7. Spindle control ]:
Expand Down
1 change: 1 addition & 0 deletions FluidNC/src/GCode.h
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@ struct parser_state_t {
float feed_rate; // Millimeters/min
uint32_t tool; // Tracks tool number
uint32_t selected_tool; // tool from T value
int32_t current_tool; // the tool in use. default is -1
int32_t line_number; // Last line number sent

float position[MAX_N_AXIS]; // Where the interpreter considers the tool to be at this point in the code
Expand Down
10 changes: 8 additions & 2 deletions FluidNC/src/Parameters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -291,10 +291,16 @@ bool get_system_param(const std::string& name, float& result) {
result = gc_state.spindle_speed;
return true;
}
if (sysn == "_current_tool" || sysn == "_selected_tool") {
result = gc_state.tool;
if (sysn == "_selected_tool") {
result = gc_state.selected_tool;
return true;
}

if (sysn == "_current_tool") {
result = gc_state.current_tool;
return true;
}

if (sysn == "_vmajor") {
std::string version(grbl_version);
auto major = version.substr(0, version.find('.'));
Expand Down
2 changes: 1 addition & 1 deletion FluidNC/src/Report.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ void report_gcode_modes(Channel& channel) {
msg << " M56";
}

msg << " T" << gc_state.tool;
msg << " T" << gc_state.selected_tool;
int digits = config->_reportInches ? 1 : 0;
msg << " F" << std::fixed << std::setprecision(digits) << gc_state.feed_rate;
msg << " S" << uint32_t(gc_state.spindle_speed);
Expand Down
28 changes: 28 additions & 0 deletions fixture_tests/fixtures/tool_param_test.nc
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
$G
(print, $G)
(print, Current tool=%d#<_current_tool>)
(print, Selected tool=%d#<_selected_tool>)
T1
(print, T1)
$G
(print, $G)
(print, Current tool=%d#<_current_tool>)
(print, Selected tool=%d#<_selected_tool>)
M6
(print, M6)
$G
(print, $G)
(print, Current tool=%d#<_current_tool>)
(print, Selected tool=%d#<_selected_tool>)
M6T2
(print, M6T2)
$G
(print, $G)
(print, Current tool=%d#<_current_tool>)
(print, Selected tool=%d#<_selected_tool>)
M61Q3
(print, M61Q3)
$G
(print, $G)
(print, Current tool=%d#<_current_tool>)
(print, Selected tool=%d#<_selected_tool>)

0 comments on commit 00f365c

Please sign in to comment.