Initialize invert_probe
[clinton/Smoothieware.git] / src / modules / tools / zprobe / ZProbe.cpp
CommitLineData
88443c6b
JM
1/*
2 This file is part of Smoothie (http://smoothieware.org/). The motion control part is heavily based on Grbl (https://github.com/simen/grbl).
3 Smoothie is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
4 Smoothie is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
5 You should have received a copy of the GNU General Public License along with Smoothie. If not, see <http://www.gnu.org/licenses/>.
6*/
7
8#include "ZProbe.h"
9
10#include "Kernel.h"
11#include "BaseSolution.h"
12#include "Config.h"
13#include "Robot.h"
14#include "StepperMotor.h"
15#include "StreamOutputPool.h"
16#include "Gcode.h"
17#include "Conveyor.h"
88443c6b
JM
18#include "checksumm.h"
19#include "ConfigValue.h"
20#include "SlowTicker.h"
21#include "Planner.h"
037c350d 22#include "SerialMessage.h"
9f6f04a5
JM
23#include "PublicDataRequest.h"
24#include "EndstopsPublicAccess.h"
25#include "PublicData.h"
ce9d2bda 26#include "LevelingStrategy.h"
a157d099 27#include "StepTicker.h"
37102904 28#include "utils.h"
a5542cae
JM
29
30// strategies we know about
f6efadb0 31#include "DeltaCalibrationStrategy.h"
a5542cae 32#include "ThreePointStrategy.h"
59d4d4ea 33#include "DeltaGridStrategy.h"
6c972e51 34#include "CartGridStrategy.h"
88443c6b 35
88443c6b
JM
36#define enable_checksum CHECKSUM("enable")
37#define probe_pin_checksum CHECKSUM("probe_pin")
7778d1ce 38#define debounce_ms_checksum CHECKSUM("debounce_ms")
681a62d7
JM
39#define slow_feedrate_checksum CHECKSUM("slow_feedrate")
40#define fast_feedrate_checksum CHECKSUM("fast_feedrate")
b469231e 41#define return_feedrate_checksum CHECKSUM("return_feedrate")
681a62d7 42#define probe_height_checksum CHECKSUM("probe_height")
f3b66360 43#define gamma_max_checksum CHECKSUM("gamma_max")
2f46bd5c 44#define max_z_checksum CHECKSUM("max_z")
93f20a8c 45#define reverse_z_direction_checksum CHECKSUM("reverse_z")
6c37f7b4 46#define dwell_before_probing_checksum CHECKSUM("dwell_before_probing")
88443c6b 47
681a62d7 48// from endstop section
b7cd847e 49#define delta_homing_checksum CHECKSUM("delta_homing")
d8198a57 50#define rdelta_homing_checksum CHECKSUM("rdelta_homing")
88443c6b
JM
51
52#define X_AXIS 0
53#define Y_AXIS 1
54#define Z_AXIS 2
55
c8bac202 56#define STEPPER THEROBOT->actuators
dd0a7cfa 57#define STEPS_PER_MM(a) (STEPPER[a]->get_steps_per_mm())
56ce2b5a
JM
58#define Z_STEPS_PER_MM STEPS_PER_MM(Z_AXIS)
59
88443c6b
JM
60void ZProbe::on_module_loaded()
61{
62 // if the module is disabled -> do nothing
56ce2b5a 63 if(!THEKERNEL->config->value( zprobe_checksum, enable_checksum )->by_default(false)->as_bool()) {
88443c6b
JM
64 // as this module is not needed free up the resource
65 delete this;
66 return;
67 }
88443c6b
JM
68
69 // load settings
de5787e0 70 this->config_load();
88443c6b 71 // register event-handlers
88443c6b 72 register_for_event(ON_GCODE_RECEIVED);
88443c6b 73
fc6c9aac 74 // we read the probe in this timer
778093ce 75 probing= false;
357bfb57 76 invert_probe= false;
778093ce 77 THEKERNEL->slow_ticker->attach(1000, this, &ZProbe::read_probe);
88443c6b
JM
78}
79
de5787e0 80void ZProbe::config_load()
88443c6b 81{
681a62d7 82 this->pin.from_string( THEKERNEL->config->value(zprobe_checksum, probe_pin_checksum)->by_default("nc" )->as_string())->as_input();
7778d1ce 83 this->debounce_ms = THEKERNEL->config->value(zprobe_checksum, debounce_ms_checksum)->by_default(0 )->as_number();
681a62d7 84
ce9d2bda 85 // get strategies to load
f6efadb0
JM
86 vector<uint16_t> modules;
87 THEKERNEL->config->get_module_list( &modules, leveling_strategy_checksum);
88 for( auto cs : modules ){
89 if( THEKERNEL->config->value(leveling_strategy_checksum, cs, enable_checksum )->as_bool() ){
90 bool found= false;
9ad47eab
JM
91 LevelingStrategy *ls= nullptr;
92
f6efadb0
JM
93 // check with each known strategy and load it if it matches
94 switch(cs) {
95 case delta_calibration_strategy_checksum:
9ad47eab 96 ls= new DeltaCalibrationStrategy(this);
f6efadb0
JM
97 found= true;
98 break;
a5542cae
JM
99
100 case three_point_leveling_strategy_checksum:
101 // NOTE this strategy is mutually exclusive with the delta calibration strategy
9ad47eab 102 ls= new ThreePointStrategy(this);
a5542cae
JM
103 found= true;
104 break;
105
59d4d4ea 106 case delta_grid_leveling_strategy_checksum:
9ad47eab 107 ls= new DeltaGridStrategy(this);
59d4d4ea
JM
108 found= true;
109 break;
6c972e51
JL
110
111 case cart_grid_leveling_strategy_checksum:
112 ls= new CartGridStrategy(this);
113 found= true;
114 break;
f6efadb0 115 }
9ad47eab
JM
116 if(found) {
117 if(ls->handleConfig()) {
118 this->strategies.push_back(ls);
119 }else{
120 delete ls;
121 }
122 }
f6efadb0
JM
123 }
124 }
ce9d2bda 125
57e927fa 126 // need to know if we need to use delta kinematics for homing
ce9d2bda 127 this->is_delta = THEKERNEL->config->value(delta_homing_checksum)->by_default(false)->as_bool();
d8198a57 128 this->is_rdelta = THEKERNEL->config->value(rdelta_homing_checksum)->by_default(false)->as_bool();
ce9d2bda 129
f6efadb0 130 // default for backwards compatibility add DeltaCalibrationStrategy if a delta
81c3ecbf 131 // may be deprecated
f6efadb0 132 if(this->strategies.empty()) {
57e927fa
JM
133 if(this->is_delta) {
134 this->strategies.push_back(new DeltaCalibrationStrategy(this));
135 this->strategies.back()->handleConfig();
136 }
037c350d 137 }
681a62d7 138
f3b66360 139 this->probe_height = THEKERNEL->config->value(zprobe_checksum, probe_height_checksum)->by_default(5.0F)->as_number();
681a62d7
JM
140 this->slow_feedrate = THEKERNEL->config->value(zprobe_checksum, slow_feedrate_checksum)->by_default(5)->as_number(); // feedrate in mm/sec
141 this->fast_feedrate = THEKERNEL->config->value(zprobe_checksum, fast_feedrate_checksum)->by_default(100)->as_number(); // feedrate in mm/sec
b469231e 142 this->return_feedrate = THEKERNEL->config->value(zprobe_checksum, return_feedrate_checksum)->by_default(0)->as_number(); // feedrate in mm/sec
bac3c948 143 this->reverse_z = THEKERNEL->config->value(zprobe_checksum, reverse_z_direction_checksum)->by_default(false)->as_bool(); // Z probe moves in reverse direction
2f46bd5c
JM
144 this->max_z = THEKERNEL->config->value(zprobe_checksum, max_z_checksum)->by_default(NAN)->as_number(); // maximum zprobe distance
145 if(isnan(this->max_z)){
146 this->max_z = THEKERNEL->config->value(gamma_max_checksum)->by_default(200)->as_number(); // maximum zprobe distance
147 }
6c37f7b4 148 this->dwell_before_probing = THEKERNEL->config->value(zprobe_checksum, dwell_before_probing_checksum)->by_default(0)->as_number(); // dwell time in seconds before probing
2f46bd5c 149
88443c6b
JM
150}
151
6d142b73 152uint32_t ZProbe::read_probe(uint32_t dummy)
88443c6b 153{
6d142b73 154 if(!probing || probe_detected) return 0;
88443c6b 155
8fe38353
JM
156 // we check all axis as it maybe a G38.2 X10 for instance, not just a probe in Z
157 if(STEPPER[X_AXIS]->is_moving() || STEPPER[Y_AXIS]->is_moving() || STEPPER[Z_AXIS]->is_moving()) {
6d142b73 158 // if it is moving then we check the probe, and debounce it
61bf59e7 159 if(this->pin.get() != invert_probe) {
7778d1ce 160 if(debounce < debounce_ms) {
88443c6b
JM
161 debounce++;
162 } else {
6d142b73
JM
163 // we signal the motors to stop, which will preempt any moves on that axis
164 // we do all motors as it may be a delta
165 for(auto &a : THEROBOT->actuators) a->stop_moving();
166 probe_detected= true;
167 debounce= 0;
88443c6b 168 }
6d142b73 169
88443c6b 170 } else {
6d142b73
JM
171 // The endstop was not hit yet
172 debounce= 0;
88443c6b
JM
173 }
174 }
6d142b73
JM
175
176 return 0;
88443c6b 177}
88443c6b 178
6d142b73 179// single probe in Z with custom feedrate
771fb7b2 180// returns boolean value indicating if probe was triggered
6d142b73 181bool ZProbe::run_probe(float& mm, float feedrate, float max_dist, bool reverse)
88443c6b 182{
89ef36ce 183 if(dwell_before_probing > .0001F) safe_delay_ms(dwell_before_probing*1000);
184
965cc29a
JM
185 if(this->pin.get()) {
186 // probe already triggered so abort
187 return false;
188 }
189
36a21d48 190 float maxz= max_dist < 0 ? this->max_z*2 : max_dist;
88443c6b 191
6d142b73
JM
192 probing= true;
193 probe_detected= false;
194 debounce= 0;
195
196 // save current actuator position so we can report how far we moved
eb0d75d3 197 float z_start_pos= THEROBOT->actuators[Z_AXIS]->get_current_position();
6d142b73 198
88443c6b 199 // move Z down
8fd0f38d 200 bool dir= (!reverse_z != reverse); // xor
6d142b73 201 float delta[3]= {0,0,0};
7778d1ce 202 delta[Z_AXIS]= dir ? -maxz : maxz;
121094a5 203 THEROBOT->delta_move(delta, feedrate, 3);
b7cd847e 204
6d142b73 205 // wait until finished
04782655 206 THECONVEYOR->wait_for_idle();
7d6fe308 207
6d142b73 208 // now see how far we moved, get delta in z we moved
29e809e0 209 // NOTE this works for deltas as well as all three actuators move the same amount in Z
eb0d75d3 210 mm= z_start_pos - THEROBOT->actuators[2]->get_current_position();
6d142b73
JM
211
212 // set the last probe position to the actuator units moved during this home
eb0d75d3 213 THEROBOT->set_last_probe_position(std::make_tuple(0, 0, mm, probe_detected?1:0));
6d142b73 214
7778d1ce
JM
215 probing= false;
216
217 if(probe_detected) {
218 // if the probe stopped the move we need to correct the last_milestone as it did not reach where it thought
219 THEROBOT->reset_position_from_current_actuator_position();
220 }
6d142b73
JM
221
222 return probe_detected;
88443c6b
JM
223}
224
71f0df19
JM
225// do probe then return to start position
226bool ZProbe::run_probe_return(float& mm, float feedrate, float max_dist, bool reverse)
681a62d7 227{
eb0d75d3 228 float save_z_pos= THEROBOT->get_axis_position(Z_AXIS);
71f0df19
JM
229
230 bool ok= run_probe(mm, feedrate, max_dist, reverse);
231
681a62d7 232 // move probe back to where it was
b469231e
RM
233 float fr;
234 if(this->return_feedrate != 0) { // use return_feedrate if set
235 fr = this->return_feedrate;
236 } else {
237 fr = this->slow_feedrate*2; // nominally twice slow feedrate
238 if(fr > this->fast_feedrate) fr = this->fast_feedrate; // unless that is greater than fast feedrate
239 }
240
c42bad8f 241 // absolute move back to saved starting position
eb0d75d3 242 coordinated_move(NAN, NAN, save_z_pos, fr, false);
681a62d7 243
71f0df19 244 return ok;
681a62d7
JM
245}
246
6d142b73 247bool ZProbe::doProbeAt(float &mm, float x, float y)
97832d6d 248{
97832d6d
JM
249 // move to xy
250 coordinated_move(x, y, NAN, getFastFeedrate());
71f0df19 251 return run_probe_return(mm, slow_feedrate);
97832d6d 252}
fc7b9a7b 253
88443c6b
JM
254void ZProbe::on_gcode_received(void *argument)
255{
256 Gcode *gcode = static_cast<Gcode *>(argument);
88443c6b 257
57e927fa 258 if( gcode->has_g && gcode->g >= 29 && gcode->g <= 32) {
995b0110
JR
259
260 invert_probe = false;
25dc6344 261 // make sure the probe is defined and not already triggered before moving motors
36a21d48 262 if(!this->pin.connected()) {
7b18a698 263 gcode->stream->printf("ZProbe pin not configured.\n");
25dc6344
JM
264 return;
265 }
965cc29a 266
25dc6344
JM
267 if(this->pin.get()) {
268 gcode->stream->printf("ZProbe triggered before move, aborting command.\n");
269 return;
270 }
271
681a62d7 272 if( gcode->g == 30 ) { // simple Z probe
8fe38353 273 // first wait for all moves to finish
04782655 274 THEKERNEL->conveyor->wait_for_idle();
88443c6b 275
71f0df19 276 bool set_z= (gcode->has_letter('Z') && !is_rdelta);
771fb7b2 277 bool probe_result;
93f20a8c
JM
278 bool reverse= (gcode->has_letter('R') && gcode->get_value('R') != 0); // specify to probe in reverse direction
279 float rate= gcode->has_letter('F') ? gcode->get_value('F') / 60 : this->slow_feedrate;
7778d1ce 280 float mm;
71f0df19
JM
281
282 // if not setting Z then return probe to where it started, otherwise leave it where it is
283 probe_result = (set_z ? run_probe(mm, rate, -1, reverse) : run_probe_return(mm, rate, -1, reverse));
771fb7b2
RM
284
285 if(probe_result) {
71f0df19 286 // the result is in actuator coordinates moved
28177f27 287 gcode->stream->printf("Z:%1.4f\n", THEKERNEL->robot->from_millimeters(mm));
078f76e0 288
71f0df19 289 if(set_z) {
fd2341bc
JM
290 // set current Z to the specified value, shortcut for G92 Znnn
291 char buf[32];
292 int n = snprintf(buf, sizeof(buf), "G92 Z%f", gcode->get_value('Z'));
293 string g(buf, n);
294 Gcode gc(g, &(StreamOutput::NullStream));
295 THEKERNEL->call_event(ON_GCODE_RECEIVED, &gc);
bd96f4d7 296 }
078f76e0 297
681a62d7 298 } else {
bd96f4d7 299 gcode->stream->printf("ZProbe not triggered\n");
88443c6b 300 }
fc7b9a7b 301
ce9d2bda 302 } else {
aaf0c0ee 303 if(!gcode->has_letter('P')) {
fc92f0ac
JM
304 // find the first strategy to handle the gcode
305 for(auto s : strategies){
306 if(s->handleGcode(gcode)) {
307 return;
308 }
309 }
310 gcode->stream->printf("No strategy found to handle G%d\n", gcode->g);
311
312 }else{
aaf0c0ee
JM
313 // P paramater selects which strategy to send the code to
314 // they are loaded in the order they are defined in config, 0 being the first, 1 being the second and so on.
315 uint16_t i= gcode->get_value('P');
316 if(i < strategies.size()) {
fc92f0ac 317 if(!strategies[i]->handleGcode(gcode)){
aaf0c0ee 318 gcode->stream->printf("strategy #%d did not handle G%d\n", i, gcode->g);
fc92f0ac 319 }
ce9d2bda 320 return;
fc92f0ac
JM
321
322 }else{
aaf0c0ee 323 gcode->stream->printf("strategy #%d is not loaded\n", i);
037c350d 324 }
fc7b9a7b 325 }
88443c6b
JM
326 }
327
6c0193b3 328 } else if(gcode->has_g && gcode->g == 38 ) { // G38.2 Straight Probe with error, G38.3 straight probe without error
36a21d48 329 // linuxcnc/grbl style probe http://www.linuxcnc.org/docs/2.5/html/gcode/gcode.html#sec:G38-probe
dca67b99 330 if(gcode->subcode < 2 || gcode->subcode > 5) {
61bf59e7 331 gcode->stream->printf("error:Only G38.2 to G38.5 are supported\n");
36a21d48
JM
332 return;
333 }
334
335 // make sure the probe is defined and not already triggered before moving motors
336 if(!this->pin.connected()) {
e714bd32 337 gcode->stream->printf("error:ZProbe not connected.\n");
36a21d48
JM
338 return;
339 }
17f26e01 340
02fdb253 341 if(this->pin.get() ^ (gcode->subcode >= 4)) {
61bf59e7
JR
342 gcode->stream->printf("error:ZProbe triggered before move, aborting command.\n");
343 return;
36a21d48
JM
344 }
345
8fe38353 346 // first wait for all moves to finish
04782655 347 THEKERNEL->conveyor->wait_for_idle();
36a21d48 348
78cfd180 349 float x= NAN, y=NAN, z=NAN;
36a21d48 350 if(gcode->has_letter('X')) {
78cfd180
JM
351 x= gcode->get_value('X');
352 }
36a21d48 353
78cfd180
JM
354 if(gcode->has_letter('Y')) {
355 y= gcode->get_value('Y');
356 }
36a21d48 357
78cfd180
JM
358 if(gcode->has_letter('Z')) {
359 z= gcode->get_value('Z');
360 }
36a21d48 361
78cfd180 362 if(isnan(x) && isnan(y) && isnan(z)) {
e714bd32 363 gcode->stream->printf("error:at least one of X Y or Z must be specified\n");
78cfd180 364 return;
36a21d48 365 }
7484e84a 366
dca67b99 367 if(gcode->subcode == 4 || gcode->subcode == 5) {
61bf59e7 368 invert_probe = true;
8c2f95f9
JR
369 } else {
370 invert_probe = false;
dca67b99 371 }
8d13395c 372
78cfd180
JM
373 probe_XYZ(gcode, x, y, z);
374
6415c244
JR
375 invert_probe = false;
376
36a21d48
JM
377 return;
378
88443c6b
JM
379 } else if(gcode->has_m) {
380 // M code processing here
3434eac0
RM
381 int c;
382 switch (gcode->m) {
383 case 119:
384 c = this->pin.get();
385 gcode->stream->printf(" Probe: %d", c);
386 gcode->add_nl = true;
387 break;
388
389 case 670:
390 if (gcode->has_letter('S')) this->slow_feedrate = gcode->get_value('S');
391 if (gcode->has_letter('K')) this->fast_feedrate = gcode->get_value('K');
392 if (gcode->has_letter('R')) this->return_feedrate = gcode->get_value('R');
393 if (gcode->has_letter('Z')) this->max_z = gcode->get_value('Z');
394 if (gcode->has_letter('H')) this->probe_height = gcode->get_value('H');
39f1d9bd
JM
395 if (gcode->has_letter('I')) { // NOTE this is temporary and toggles the invertion status of the pin
396 invert_override= (gcode->get_value('I') != 0);
397 pin.set_inverting(pin.is_inverting() != invert_override); // XOR so inverted pin is not inverted and vice versa
398 }
6c37f7b4 399 if (gcode->has_letter('D')) this->dwell_before_probing = gcode->get_value('D');
3434eac0
RM
400 break;
401
402 case 500: // save settings
403 case 503: // print settings
6c37f7b4 404 gcode->stream->printf(";Probe feedrates Slow/fast(K)/Return (mm/sec) max_z (mm) height (mm) dwell (s):\nM670 S%1.2f K%1.2f R%1.2f Z%1.2f H%1.2f D%1.2f\n",
405 this->slow_feedrate, this->fast_feedrate, this->return_feedrate, this->max_z, this->probe_height, this->dwell_before_probing);
fc92f0ac 406
3434eac0
RM
407 // fall through is intended so leveling strategies can handle m-codes too
408
409 default:
410 for(auto s : strategies){
411 if(s->handleGcode(gcode)) {
412 return;
413 }
ce9d2bda 414 }
bd96f4d7 415 }
88443c6b
JM
416 }
417}
418
778093ce 419// special way to probe in the X or Y or Z direction using planned moves, should work with any kinematics
78cfd180 420void ZProbe::probe_XYZ(Gcode *gcode, float x, float y, float z)
37102904 421{
778093ce
JM
422 // enable the probe checking in the timer
423 probing= true;
424 probe_detected= false;
c8bac202 425 THEROBOT->disable_segmentation= true; // we must disable segmentation as this won't work with it enabled (beware on deltas probing in X or Y)
37102904 426
73cad2e1
JM
427 // get probe feedrate in mm/min and convert to mm/sec if specified
428 float rate = (gcode->has_letter('F')) ? gcode->get_value('F')/60 : this->slow_feedrate;
37102904 429
778093ce 430 // do a regular move which will stop as soon as the probe is triggered, or the distance is reached
78cfd180 431 coordinated_move(x, y, z, rate, true);
37102904 432
778093ce
JM
433 // coordinated_move returns when the move is finished
434
435 // disable probe checking
436 probing= false;
c8bac202 437 THEROBOT->disable_segmentation= false;
37102904 438
8fe38353
JM
439 // if the probe stopped the move we need to correct the last_milestone as it did not reach where it thought
440 // this also sets last_milestone to the machine coordinates it stopped at
441 THEROBOT->reset_position_from_current_actuator_position();
37102904 442 float pos[3];
8fe38353 443 THEROBOT->get_axis_position(pos, 3);
37102904 444
778093ce 445 uint8_t probeok= this->probe_detected ? 1 : 0;
b76a9926 446
17f26e01 447 // print results using the GRBL format
28177f27 448 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);
c8bac202 449 THEROBOT->set_last_probe_position(std::make_tuple(pos[X_AXIS], pos[Y_AXIS], pos[Z_AXIS], probeok));
b76a9926 450
dca67b99
JR
451 if(probeok == 0 && (gcode->subcode == 2 || gcode->subcode == 4)) {
452 // issue error if probe was not triggered and subcode is 2 or 4
39c0196b 453 gcode->stream->printf("ALARM: Probe fail\n");
93f20a8c 454 THEKERNEL->call_event(ON_HALT, nullptr);
778093ce 455 }
37102904
JM
456}
457
681a62d7
JM
458// issue a coordinated move directly to robot, and return when done
459// Only move the coordinates that are passed in as not nan
6d142b73 460// NOTE must use G53 to force move in machine coordinates and ignore any WCS offsets
037c350d 461void ZProbe::coordinated_move(float x, float y, float z, float feedrate, bool relative)
681a62d7 462{
3aa7e94e
JM
463 #define CMDLEN 128
464 char *cmd= new char[CMDLEN]; // use heap here to reduce stack usage
037c350d
JM
465
466 if(relative) strcpy(cmd, "G91 G0 ");
e0be983d 467 else strcpy(cmd, "G53 G0 "); // G53 forces movement in machine coordinate system
037c350d 468
681a62d7 469 if(!isnan(x)) {
eb0d75d3 470 size_t n= strlen(cmd);
3aa7e94e 471 snprintf(&cmd[n], CMDLEN-n, " X%1.3f", x);
681a62d7
JM
472 }
473 if(!isnan(y)) {
eb0d75d3 474 size_t n= strlen(cmd);
3aa7e94e 475 snprintf(&cmd[n], CMDLEN-n, " Y%1.3f", y);
681a62d7
JM
476 }
477 if(!isnan(z)) {
eb0d75d3 478 size_t n= strlen(cmd);
3aa7e94e 479 snprintf(&cmd[n], CMDLEN-n, " Z%1.3f", z);
eb0d75d3
JM
480 }
481
482 {
483 size_t n= strlen(cmd);
484 // use specified feedrate (mm/sec)
3aa7e94e 485 snprintf(&cmd[n], CMDLEN-n, " F%1.1f", feedrate * 60); // feed rate is converted to mm/min
681a62d7
JM
486 }
487
037c350d
JM
488 if(relative) strcat(cmd, " G90");
489
b9281d2b 490 //THEKERNEL->streams->printf("DEBUG: move: %s: %u\n", cmd, strlen(cmd));
681a62d7 491
037c350d 492 // send as a command line as may have multiple G codes in it
049c9aae 493 THEROBOT->push_state();
037c350d
JM
494 struct SerialMessage message;
495 message.message = cmd;
bb9951c2
JM
496 delete [] cmd;
497
037c350d
JM
498 message.stream = &(StreamOutput::NullStream);
499 THEKERNEL->call_event(ON_CONSOLE_LINE_RECEIVED, &message );
04782655 500 THEKERNEL->conveyor->wait_for_idle();
049c9aae 501 THEROBOT->pop_state();
bb9951c2 502
681a62d7
JM
503}
504
505// issue home command
506void ZProbe::home()
507{
9a6cabd8 508 Gcode gc(THEKERNEL->is_grbl_mode() ? "G28.2" : "G28", &(StreamOutput::NullStream));
681a62d7
JM
509 THEKERNEL->call_event(ON_GCODE_RECEIVED, &gc);
510}