Skip to content

Commit

Permalink
Merge pull request #995 from bdring/ProbeInMm
Browse files Browse the repository at this point in the history
Added G38.6-9 to force probe units in mm
  • Loading branch information
bdring authored Aug 14, 2023
2 parents d63a827 + c077a11 commit 1d4e2a0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
Binary file modified FluidNC/data/index.html.gz
Binary file not shown.
17 changes: 11 additions & 6 deletions FluidNC/src/GCode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ Error gc_execute_line(char* line) {
bool syncLaser = false;
bool disableLaser = false;
bool laserIsMotion = false;
bool nonmodalG38 = false; // Used for G38.6-9

auto n_axis = config->_axes->_numberAxis;
float coord_data[MAX_N_AXIS]; // Used by WCO-related commands
Expand Down Expand Up @@ -320,6 +321,10 @@ Error gc_execute_line(char* line) {
probeExplicit = true;

axis_command = AxisCommand::MotionMode;
if (mantissa >= 60) {
nonmodalG38 = true;
mantissa -= 40;
}
switch (mantissa) {
case 20:
gc_block.modal.motion = Motion::ProbeToward;
Expand Down Expand Up @@ -794,7 +799,7 @@ Error gc_execute_line(char* line) {
if (bitnum_is_false(value_words, GCodeWord::F)) {
FAIL(Error::GcodeUndefinedFeedRate);
}
if (gc_block.modal.units == Units::Inches) {
if (!nonmodalG38 && gc_block.modal.units == Units::Inches) {
gc_block.values.f *= MM_PER_INCH;
}
} else {
Expand Down Expand Up @@ -822,7 +827,7 @@ Error gc_execute_line(char* line) {
// - In units per mm mode: If F word passed, ensure value is in mm/min, otherwise push last state value.
if (gc_state.modal.feed_rate == FeedRate::UnitsPerMin) { // Last state is also G94
if (bitnum_is_true(value_words, GCodeWord::F)) {
if (gc_block.modal.units == Units::Inches) {
if (!nonmodalG38 && gc_block.modal.units == Units::Inches) {
gc_block.values.f *= MM_PER_INCH;
}
} else {
Expand Down Expand Up @@ -895,7 +900,7 @@ Error gc_execute_line(char* line) {

// [12. Set length units ]: N/A
// Pre-convert XYZ coordinate values to millimeters, if applicable.
if (gc_block.modal.units == Units::Inches) {
if (!nonmodalG38 && gc_block.modal.units == Units::Inches) {
for (size_t idx = 0; idx < n_axis; idx++) { // Axes indices are consistent, so loop may be used.
if ((idx < A_AXIS || idx > C_AXIS) && bitnum_is_true(axis_words, idx)) {
gc_block.values.xyz[idx] *= MM_PER_INCH;
Expand Down Expand Up @@ -1034,7 +1039,7 @@ Error gc_execute_line(char* line) {
// NOTE: G53 is never active with G28/30 since they are in the same modal group.
if (gc_block.non_modal_command != NonModal::AbsoluteOverride) {
// Apply coordinate offsets based on distance mode.
if (gc_block.modal.distance == Distance::Absolute) {
if (!nonmodalG38 && gc_block.modal.distance == Distance::Absolute) {
gc_block.values.xyz[idx] += block_coord_system[idx] + gc_state.coord_offset[idx];
if (idx == TOOL_LENGTH_OFFSET_AXIS) {
gc_block.values.xyz[idx] += gc_state.tool_length_offset;
Expand Down Expand Up @@ -1152,7 +1157,7 @@ Error gc_execute_line(char* line) {
FAIL(Error::GcodeInvalidTarget); // [Invalid target]
}
// Convert radius value to proper units.
if (gc_block.modal.units == Units::Inches) {
if (!nonmodalG38 && gc_block.modal.units == Units::Inches) {
gc_block.values.r *= MM_PER_INCH;
}
/* We need to calculate the center of the circle that has the designated radius and passes
Expand Down Expand Up @@ -1246,7 +1251,7 @@ Error gc_execute_line(char* line) {
}
clear_bits(value_words, (bitnum_to_mask(GCodeWord::I) | bitnum_to_mask(GCodeWord::J) | bitnum_to_mask(GCodeWord::K)));
// Convert IJK values to proper units.
if (gc_block.modal.units == Units::Inches) {
if (!nonmodalG38 && gc_block.modal.units == Units::Inches) {
for (size_t idx = 0; idx < n_axis; idx++) { // Axes indices are consistent, so loop may be used to save flash space.
if (ijk_words & bitnum_to_mask(idx)) {
gc_block.values.ijk[idx] *= MM_PER_INCH;
Expand Down

0 comments on commit 1d4e2a0

Please sign in to comment.