X-Git-Url: https://git.hcoop.net/clinton/Smoothieware.git/blobdiff_plain/28177f2773214f68df770c8cfa118ddac1d975bc..f95320b7155f6fe614f7579727b840ffb01248e6:/src/modules/tools/zprobe/ZProbe.cpp diff --git a/src/modules/tools/zprobe/ZProbe.cpp b/src/modules/tools/zprobe/ZProbe.cpp index b91d4129..98240b89 100644 --- a/src/modules/tools/zprobe/ZProbe.cpp +++ b/src/modules/tools/zprobe/ZProbe.cpp @@ -325,8 +325,8 @@ void ZProbe::on_gcode_received(void *argument) } else if(gcode->has_g && gcode->g == 38 ) { // G38.2 Straight Probe with error, G38.3 straight probe without error // linuxcnc/grbl style probe http://www.linuxcnc.org/docs/2.5/html/gcode/gcode.html#sec:G38-probe - if(gcode->subcode != 2 && gcode->subcode != 3) { - gcode->stream->printf("error:Only G38.2 and G38.3 are supported\n"); + if(gcode->subcode < 2 || gcode->subcode > 5) { + gcode->stream->printf("error:Only G38.2, G38.3, G38.4, and G38.5 are supported\n"); return; } @@ -336,28 +336,47 @@ void ZProbe::on_gcode_received(void *argument) return; } - if(this->pin.get()) { - gcode->stream->printf("error:ZProbe triggered before move, aborting command.\n"); - return; + if(gcode->subcode == 4 || gcode->subcode == 5) { + if(!this->pin.get()) { + gcode->stream->printf("error:ZProbe triggered before move, aborting command.\n"); + return; + } + } else { + if(this->pin.get()) { + gcode->stream->printf("error:ZProbe triggered before move, aborting command.\n"); + return; + } } // first wait for all moves to finish THEKERNEL->conveyor->wait_for_idle(); + float x= NAN, y=NAN, z=NAN; if(gcode->has_letter('X')) { - // probe in the X axis - probe_XYZ(gcode, X_AXIS); + x= gcode->get_value('X'); + } - }else if(gcode->has_letter('Y')) { - // probe in the Y axis - probe_XYZ(gcode, Y_AXIS); + if(gcode->has_letter('Y')) { + y= gcode->get_value('Y'); + } - }else if(gcode->has_letter('Z')) { - // probe in the Z axis - probe_XYZ(gcode, Z_AXIS); + if(gcode->has_letter('Z')) { + z= gcode->get_value('Z'); + } - }else{ + if(isnan(x) && isnan(y) && isnan(z)) { gcode->stream->printf("error:at least one of X Y or Z must be specified\n"); + return; + } + + if(gcode->subcode == 4 || gcode->subcode == 5) { + pin.set_inverting(pin.is_inverting() != 1); + } + + probe_XYZ(gcode, x, y, z); + + if(gcode->subcode == 4 || gcode->subcode == 5) { + pin.set_inverting(pin.is_inverting() != 1); } return; @@ -403,7 +422,7 @@ void ZProbe::on_gcode_received(void *argument) } // special way to probe in the X or Y or Z direction using planned moves, should work with any kinematics -void ZProbe::probe_XYZ(Gcode *gcode, int axis) +void ZProbe::probe_XYZ(Gcode *gcode, float x, float y, float z) { // enable the probe checking in the timer probing= true; @@ -414,11 +433,7 @@ void ZProbe::probe_XYZ(Gcode *gcode, int axis) float rate = (gcode->has_letter('F')) ? gcode->get_value('F')/60 : this->slow_feedrate; // do a regular move which will stop as soon as the probe is triggered, or the distance is reached - switch(axis) { - case X_AXIS: coordinated_move(gcode->get_value('X'), 0, 0, rate, true); break; - case Y_AXIS: coordinated_move(0, gcode->get_value('Y'), 0, rate, true); break; - case Z_AXIS: coordinated_move(0, 0, gcode->get_value('Z'), rate, true); break; - } + coordinated_move(x, y, z, rate, true); // coordinated_move returns when the move is finished @@ -438,8 +453,8 @@ void ZProbe::probe_XYZ(Gcode *gcode, int axis) gcode->stream->printf("[PRB:%1.3f,%1.3f,%1.3f:%d]\n", THEKERNEL->robot->from_millimeters(pos[X_AXIS]), THEKERNEL->robot->from_millimeters(pos[Y_AXIS]), THEKERNEL->robot->from_millimeters(pos[Z_AXIS]), probeok); THEROBOT->set_last_probe_position(std::make_tuple(pos[X_AXIS], pos[Y_AXIS], pos[Z_AXIS], probeok)); - if(probeok == 0 && gcode->subcode == 2) { - // issue error if probe was not triggered and subcode == 2 + if(probeok == 0 && (gcode->subcode == 2 || gcode->subcode == 4)) { + // issue error if probe was not triggered and subcode is 2 or 4 gcode->stream->printf("ALARM: Probe fail\n"); THEKERNEL->call_event(ON_HALT, nullptr); }