whitespace changes...
[clinton/Smoothieware.git] / src / modules / tools / endstops / Endstops.cpp
CommitLineData
df27a6a3 1/*
201bcb94
AW
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.
df27a6a3 5 You should have received a copy of the GNU General Public License along with Smoothie. If not, see <http://www.gnu.org/licenses/>.
201bcb94
AW
6*/
7
8#include "libs/Module.h"
9#include "libs/Kernel.h"
10#include "modules/communication/utils/Gcode.h"
3fceb8eb 11#include "modules/robot/Conveyor.h"
807b9b57 12#include "modules/robot/ActuatorCoordinates.h"
201bcb94
AW
13#include "Endstops.h"
14#include "libs/nuts_bolts.h"
750277f8 15#include "libs/Pin.h"
670fa10b 16#include "libs/StepperMotor.h"
201bcb94 17#include "wait_api.h" // mbed.h lib
61134a65
JM
18#include "Robot.h"
19#include "Stepper.h"
20#include "Config.h"
21#include "SlowTicker.h"
22#include "Planner.h"
7af0714f
JM
23#include "checksumm.h"
24#include "utils.h"
8d54c34c 25#include "ConfigValue.h"
fc7b9a7b 26#include "libs/StreamOutput.h"
9f6f04a5
JM
27#include "PublicDataRequest.h"
28#include "EndstopsPublicAccess.h"
3c947f85 29#include "StreamOutputPool.h"
a157d099 30#include "StepTicker.h"
7552475b 31#include "BaseSolution.h"
201bcb94 32
80605954
JM
33#include <ctype.h>
34
33e4cc02
JM
35#define ALPHA_AXIS 0
36#define BETA_AXIS 1
37#define GAMMA_AXIS 2
9a993543
JM
38#define X_AXIS 0
39#define Y_AXIS 1
40#define Z_AXIS 2
33e4cc02 41
33e4cc02
JM
42#define endstops_module_enable_checksum CHECKSUM("endstops_enable")
43#define corexy_homing_checksum CHECKSUM("corexy_homing")
44#define delta_homing_checksum CHECKSUM("delta_homing")
3e1f5b74 45#define scara_homing_checksum CHECKSUM("scara_homing")
33e4cc02
JM
46
47#define alpha_min_endstop_checksum CHECKSUM("alpha_min_endstop")
48#define beta_min_endstop_checksum CHECKSUM("beta_min_endstop")
49#define gamma_min_endstop_checksum CHECKSUM("gamma_min_endstop")
50
51#define alpha_max_endstop_checksum CHECKSUM("alpha_max_endstop")
52#define beta_max_endstop_checksum CHECKSUM("beta_max_endstop")
53#define gamma_max_endstop_checksum CHECKSUM("gamma_max_endstop")
54
55#define alpha_trim_checksum CHECKSUM("alpha_trim")
56#define beta_trim_checksum CHECKSUM("beta_trim")
57#define gamma_trim_checksum CHECKSUM("gamma_trim")
58
59// these values are in steps and should be deprecated
60#define alpha_fast_homing_rate_checksum CHECKSUM("alpha_fast_homing_rate")
61#define beta_fast_homing_rate_checksum CHECKSUM("beta_fast_homing_rate")
62#define gamma_fast_homing_rate_checksum CHECKSUM("gamma_fast_homing_rate")
63
64#define alpha_slow_homing_rate_checksum CHECKSUM("alpha_slow_homing_rate")
65#define beta_slow_homing_rate_checksum CHECKSUM("beta_slow_homing_rate")
66#define gamma_slow_homing_rate_checksum CHECKSUM("gamma_slow_homing_rate")
67
68#define alpha_homing_retract_checksum CHECKSUM("alpha_homing_retract")
69#define beta_homing_retract_checksum CHECKSUM("beta_homing_retract")
70#define gamma_homing_retract_checksum CHECKSUM("gamma_homing_retract")
33e4cc02
JM
71
72// same as above but in user friendly mm/s and mm
73#define alpha_fast_homing_rate_mm_checksum CHECKSUM("alpha_fast_homing_rate_mm_s")
74#define beta_fast_homing_rate_mm_checksum CHECKSUM("beta_fast_homing_rate_mm_s")
75#define gamma_fast_homing_rate_mm_checksum CHECKSUM("gamma_fast_homing_rate_mm_s")
76
77#define alpha_slow_homing_rate_mm_checksum CHECKSUM("alpha_slow_homing_rate_mm_s")
78#define beta_slow_homing_rate_mm_checksum CHECKSUM("beta_slow_homing_rate_mm_s")
79#define gamma_slow_homing_rate_mm_checksum CHECKSUM("gamma_slow_homing_rate_mm_s")
80
81#define alpha_homing_retract_mm_checksum CHECKSUM("alpha_homing_retract_mm")
82#define beta_homing_retract_mm_checksum CHECKSUM("beta_homing_retract_mm")
83#define gamma_homing_retract_mm_checksum CHECKSUM("gamma_homing_retract_mm")
84
85#define endstop_debounce_count_checksum CHECKSUM("endstop_debounce_count")
86
87#define alpha_homing_direction_checksum CHECKSUM("alpha_homing_direction")
88#define beta_homing_direction_checksum CHECKSUM("beta_homing_direction")
89#define gamma_homing_direction_checksum CHECKSUM("gamma_homing_direction")
90#define home_to_max_checksum CHECKSUM("home_to_max")
91#define home_to_min_checksum CHECKSUM("home_to_min")
92#define alpha_min_checksum CHECKSUM("alpha_min")
93#define beta_min_checksum CHECKSUM("beta_min")
94#define gamma_min_checksum CHECKSUM("gamma_min")
95
96#define alpha_max_checksum CHECKSUM("alpha_max")
97#define beta_max_checksum CHECKSUM("beta_max")
98#define gamma_max_checksum CHECKSUM("gamma_max")
99
3c947f85
JM
100#define alpha_limit_enable_checksum CHECKSUM("alpha_limit_enable")
101#define beta_limit_enable_checksum CHECKSUM("beta_limit_enable")
102#define gamma_limit_enable_checksum CHECKSUM("gamma_limit_enable")
103
80605954 104#define homing_order_checksum CHECKSUM("homing_order")
2ddf75fd 105#define move_to_origin_checksum CHECKSUM("move_to_origin_after_home")
80605954 106
dd0a7cfa
JM
107#define STEPPER THEKERNEL->robot->actuators
108#define STEPS_PER_MM(a) (STEPPER[a]->get_steps_per_mm())
56ce2b5a 109
2b3cedc7 110
3c947f85
JM
111// Homing States
112enum{
2ddf75fd
JM
113 MOVING_TO_ENDSTOP_FAST, // homing move
114 MOVING_BACK, // homing move
115 MOVING_TO_ENDSTOP_SLOW, // homing move
fafb45df 116 NOT_HOMING,
3c947f85 117 BACK_OFF_HOME,
2ddf75fd 118 MOVE_TO_ORIGIN,
3c947f85
JM
119 LIMIT_TRIGGERED
120};
121
33e4cc02
JM
122Endstops::Endstops()
123{
201bcb94 124 this->status = NOT_HOMING;
33e4cc02 125 home_offset[0] = home_offset[1] = home_offset[2] = 0.0F;
201bcb94
AW
126}
127
33e4cc02
JM
128void Endstops::on_module_loaded()
129{
7dee696d 130 // Do not do anything if not enabled
314ab8f7 131 if ( THEKERNEL->config->value( endstops_module_enable_checksum )->by_default(true)->as_bool() == false ) {
4e722c00 132 delete this;
33e4cc02
JM
133 return;
134 }
7d62445b 135
9f6f04a5
JM
136 register_for_event(ON_GCODE_RECEIVED);
137 register_for_event(ON_GET_PUBLIC_DATA);
7d6fe308 138 register_for_event(ON_SET_PUBLIC_DATA);
201bcb94 139
a157d099 140 THEKERNEL->step_ticker->register_acceleration_tick_handler([this](){acceleration_tick(); });
201bcb94 141
750277f8
AW
142 // Settings
143 this->on_config_reload(this);
201bcb94
AW
144}
145
750277f8 146// Get config
33e4cc02
JM
147void Endstops::on_config_reload(void *argument)
148{
56ce2b5a
JM
149 this->pins[0].from_string( THEKERNEL->config->value(alpha_min_endstop_checksum )->by_default("nc" )->as_string())->as_input();
150 this->pins[1].from_string( THEKERNEL->config->value(beta_min_endstop_checksum )->by_default("nc" )->as_string())->as_input();
151 this->pins[2].from_string( THEKERNEL->config->value(gamma_min_endstop_checksum )->by_default("nc" )->as_string())->as_input();
152 this->pins[3].from_string( THEKERNEL->config->value(alpha_max_endstop_checksum )->by_default("nc" )->as_string())->as_input();
153 this->pins[4].from_string( THEKERNEL->config->value(beta_max_endstop_checksum )->by_default("nc" )->as_string())->as_input();
154 this->pins[5].from_string( THEKERNEL->config->value(gamma_max_endstop_checksum )->by_default("nc" )->as_string())->as_input();
155
156 // These are the old ones in steps still here for backwards compatibility
157 this->fast_rates[0] = THEKERNEL->config->value(alpha_fast_homing_rate_checksum )->by_default(4000 )->as_number() / STEPS_PER_MM(0);
158 this->fast_rates[1] = THEKERNEL->config->value(beta_fast_homing_rate_checksum )->by_default(4000 )->as_number() / STEPS_PER_MM(1);
159 this->fast_rates[2] = THEKERNEL->config->value(gamma_fast_homing_rate_checksum )->by_default(6400 )->as_number() / STEPS_PER_MM(2);
160 this->slow_rates[0] = THEKERNEL->config->value(alpha_slow_homing_rate_checksum )->by_default(2000 )->as_number() / STEPS_PER_MM(0);
161 this->slow_rates[1] = THEKERNEL->config->value(beta_slow_homing_rate_checksum )->by_default(2000 )->as_number() / STEPS_PER_MM(1);
162 this->slow_rates[2] = THEKERNEL->config->value(gamma_slow_homing_rate_checksum )->by_default(3200 )->as_number() / STEPS_PER_MM(2);
163 this->retract_mm[0] = THEKERNEL->config->value(alpha_homing_retract_checksum )->by_default(400 )->as_number() / STEPS_PER_MM(0);
164 this->retract_mm[1] = THEKERNEL->config->value(beta_homing_retract_checksum )->by_default(400 )->as_number() / STEPS_PER_MM(1);
165 this->retract_mm[2] = THEKERNEL->config->value(gamma_homing_retract_checksum )->by_default(1600 )->as_number() / STEPS_PER_MM(2);
5de98d7c
JM
166
167 // newer mm based config values override the old ones, convert to steps/mm and steps, defaults to what was set in the older config settings above
56ce2b5a
JM
168 this->fast_rates[0] = THEKERNEL->config->value(alpha_fast_homing_rate_mm_checksum )->by_default(this->fast_rates[0])->as_number();
169 this->fast_rates[1] = THEKERNEL->config->value(beta_fast_homing_rate_mm_checksum )->by_default(this->fast_rates[1])->as_number();
170 this->fast_rates[2] = THEKERNEL->config->value(gamma_fast_homing_rate_mm_checksum )->by_default(this->fast_rates[2])->as_number();
171 this->slow_rates[0] = THEKERNEL->config->value(alpha_slow_homing_rate_mm_checksum )->by_default(this->slow_rates[0])->as_number();
172 this->slow_rates[1] = THEKERNEL->config->value(beta_slow_homing_rate_mm_checksum )->by_default(this->slow_rates[1])->as_number();
173 this->slow_rates[2] = THEKERNEL->config->value(gamma_slow_homing_rate_mm_checksum )->by_default(this->slow_rates[2])->as_number();
174 this->retract_mm[0] = THEKERNEL->config->value(alpha_homing_retract_mm_checksum )->by_default(this->retract_mm[0])->as_number();
175 this->retract_mm[1] = THEKERNEL->config->value(beta_homing_retract_mm_checksum )->by_default(this->retract_mm[1])->as_number();
176 this->retract_mm[2] = THEKERNEL->config->value(gamma_homing_retract_mm_checksum )->by_default(this->retract_mm[2])->as_number();
5de98d7c 177
06c48ee8 178 this->debounce_count = THEKERNEL->config->value(endstop_debounce_count_checksum )->by_default(100)->as_number();
5de98d7c 179
409ff5b3 180 // get homing direction and convert to boolean where true is home to min, and false is home to max
314ab8f7 181 int home_dir = get_checksum(THEKERNEL->config->value(alpha_homing_direction_checksum)->by_default("home_to_min")->as_string());
eb09fdbf 182 this->home_direction[0] = home_dir != home_to_max_checksum;
47bbe224 183
314ab8f7 184 home_dir = get_checksum(THEKERNEL->config->value(beta_homing_direction_checksum)->by_default("home_to_min")->as_string());
eb09fdbf 185 this->home_direction[1] = home_dir != home_to_max_checksum;
47bbe224 186
314ab8f7 187 home_dir = get_checksum(THEKERNEL->config->value(gamma_homing_direction_checksum)->by_default("home_to_min")->as_string());
eb09fdbf 188 this->home_direction[2] = home_dir != home_to_max_checksum;
47bbe224 189
314ab8f7 190 this->homing_position[0] = this->home_direction[0] ? THEKERNEL->config->value(alpha_min_checksum)->by_default(0)->as_number() : THEKERNEL->config->value(alpha_max_checksum)->by_default(200)->as_number();
f3b66360
JM
191 this->homing_position[1] = this->home_direction[1] ? THEKERNEL->config->value(beta_min_checksum )->by_default(0)->as_number() : THEKERNEL->config->value(beta_max_checksum )->by_default(200)->as_number();
192 this->homing_position[2] = this->home_direction[2] ? THEKERNEL->config->value(gamma_min_checksum)->by_default(0)->as_number() : THEKERNEL->config->value(gamma_max_checksum)->by_default(200)->as_number();
f29b0272 193
314ab8f7
MM
194 this->is_corexy = THEKERNEL->config->value(corexy_homing_checksum)->by_default(false)->as_bool();
195 this->is_delta = THEKERNEL->config->value(delta_homing_checksum)->by_default(false)->as_bool();
504f0e3e
JM
196 this->is_scara = THEKERNEL->config->value(scara_homing_checksum)->by_default(false)->as_bool();
197
80605954
JM
198 // see if an order has been specified, must be three characters, XYZ or YXZ etc
199 string order= THEKERNEL->config->value(homing_order_checksum)->by_default("")->as_string();
200 this->homing_order= 0;
201 if(order.size() == 3 && !this->is_delta) {
202 int shift= 0;
203 for(auto c : order) {
204 uint8_t i= toupper(c) - 'X';
205 if(i > 2) { // bad value
206 this->homing_order= 0;
207 break;
208 }
209 homing_order |= (i << shift);
210 shift += 2;
211 }
212 }
213
192bca32
JM
214 // endstop trim used by deltas to do soft adjusting
215 // on a delta homing to max, a negative trim value will move the carriage down, and a positive will move it up
216 this->trim_mm[0] = THEKERNEL->config->value(alpha_trim_checksum )->by_default(0 )->as_number();
217 this->trim_mm[1] = THEKERNEL->config->value(beta_trim_checksum )->by_default(0 )->as_number();
218 this->trim_mm[2] = THEKERNEL->config->value(gamma_trim_checksum )->by_default(0 )->as_number();
3c947f85
JM
219
220 // limits enabled
221 this->limit_enable[X_AXIS]= THEKERNEL->config->value(alpha_limit_enable_checksum)->by_default(false)->as_bool();
222 this->limit_enable[Y_AXIS]= THEKERNEL->config->value(beta_limit_enable_checksum)->by_default(false)->as_bool();
223 this->limit_enable[Z_AXIS]= THEKERNEL->config->value(gamma_limit_enable_checksum)->by_default(false)->as_bool();
224
2ddf75fd 225 this->move_to_origin_after_home= THEKERNEL->config->value(move_to_origin_checksum)->by_default(false)->as_bool();
2b3cedc7 226
3c947f85
JM
227 if(this->limit_enable[X_AXIS] || this->limit_enable[Y_AXIS] || this->limit_enable[Z_AXIS]){
228 register_for_event(ON_IDLE);
7f3e6350
JM
229 if(this->is_delta) {
230 // we must enable all the limits not just one
231 this->limit_enable[X_AXIS]= true;
232 this->limit_enable[Y_AXIS]= true;
233 this->limit_enable[Z_AXIS]= true;
234 }
3c947f85 235 }
44127aca
JM
236
237 // NOTE this may also be true of scara. TBD
238 if(this->is_delta) {
239 // some things must be the same or they will die, so force it here to avoid config errors
240 this->fast_rates[1]= this->fast_rates[2]= this->fast_rates[0];
241 this->slow_rates[1]= this->slow_rates[2]= this->slow_rates[0];
242 this->retract_mm[1]= this->retract_mm[2]= this->retract_mm[0];
243 this->home_direction[1]= this->home_direction[2]= this->home_direction[0];
244 this->homing_position[0]= this->homing_position[1]= 0;
44127aca 245 }
3c947f85
JM
246}
247
28166daf
JM
248bool Endstops::debounced_get(int pin)
249{
250 uint8_t debounce= 0;
251 while(this->pins[pin].get()) {
252 if ( ++debounce >= this->debounce_count ) {
253 // pin triggered
254 return true;
255 }
256 }
257 return false;
258}
259
4d149ebb 260static const char *endstop_names[]= {"min_x", "min_y", "min_z", "max_x", "max_y", "max_z"};
3c947f85
JM
261
262void Endstops::on_idle(void *argument)
263{
c3d7feb6
JM
264 if(this->status == LIMIT_TRIGGERED) {
265 // if we were in limit triggered see if it has been cleared
266 for( int c = X_AXIS; c <= Z_AXIS; c++ ) {
267 if(this->limit_enable[c]) {
268 std::array<int, 2> minmax{{0, 3}};
269 // check min and max endstops
270 for (int i : minmax) {
271 int n= c+i;
272 if(this->pins[n].get()) {
273 // still triggered, so exit
ee1c3181 274 bounce_cnt= 0;
c3d7feb6
JM
275 return;
276 }
277 }
278 }
279 }
ee1c3181
JM
280 if(++bounce_cnt > 10) { // can use less as it calls on_idle in between
281 // clear the state
282 this->status= NOT_HOMING;
283 }
4befe777 284 return;
c3d7feb6
JM
285
286 }else if(this->status != NOT_HOMING) {
287 // don't check while homing
288 return;
289 }
3c947f85
JM
290
291 for( int c = X_AXIS; c <= Z_AXIS; c++ ) {
292 if(this->limit_enable[c] && STEPPER[c]->is_moving()) {
293 std::array<int, 2> minmax{{0, 3}};
294 // check min and max endstops
295 for (int i : minmax) {
296 int n= c+i;
28166daf
JM
297 if(debounced_get(n)) {
298 // endstop triggered
299 THEKERNEL->streams->printf("Limit switch %s was hit - reset or M999 required\n", endstop_names[n]);
300 this->status= LIMIT_TRIGGERED;
301 // disables heaters and motors, ignores incoming Gcode and flushes block queue
302 THEKERNEL->call_event(ON_HALT, nullptr);
303 return;
3c947f85
JM
304 }
305 }
306 }
307 }
308}
309
310// if limit switches are enabled, then we must move off of the endstop otherwise we won't be able to move
5bfcd44a
JM
311// checks if triggered and only backs off if triggered
312void Endstops::back_off_home(char axes_to_move)
3c947f85 313{
7c801094 314 std::vector<std::pair<char,float>> params;
3c947f85 315 this->status = BACK_OFF_HOME;
7f3e6350
JM
316
317 // these are handled differently
1b5776bf 318 if(is_delta || is_scara) {
7f3e6350 319 // Move off of the endstop using a regular relative move in Z only
7c801094 320 params.push_back({'Z', this->retract_mm[Z_AXIS]*(this->home_direction[Z_AXIS]?1:-1)});
44127aca
JM
321
322 }else{
7f3e6350 323 // cartesians, concatenate all the moves we need to do into one gcode
44127aca
JM
324 for( int c = X_AXIS; c <= Z_AXIS; c++ ) {
325 if( ((axes_to_move >> c ) & 1) == 0) continue; // only for axes we asked to move
7f3e6350
JM
326
327 // if not triggered no need to move off
28166daf 328 if(this->limit_enable[c] && debounced_get(c + (this->home_direction[c] ? 0 : 3)) ) {
7c801094 329 params.push_back({c+'X', this->retract_mm[c]*(this->home_direction[c]?1:-1)});
44127aca 330 }
3c947f85
JM
331 }
332 }
7f3e6350
JM
333
334 if(!params.empty()) {
335 // Move off of the endstop using a regular relative move
7c801094 336 params.insert(params.begin(), {'G', 0});
7f3e6350 337 // use X slow rate to move, Z should have a max speed set anyway
7c801094
JM
338 params.push_back({'F', this->slow_rates[X_AXIS]*60.0F});
339 char gcode_buf[64];
340 append_parameters(gcode_buf, params, sizeof(gcode_buf));
7f3e6350
JM
341 Gcode gc(gcode_buf, &(StreamOutput::NullStream));
342 bool oldmode= THEKERNEL->robot->absolute_mode;
343 THEKERNEL->robot->absolute_mode= false; // needs to be relative mode
344 THEKERNEL->robot->on_gcode_received(&gc); // send to robot directly
345 THEKERNEL->robot->absolute_mode= oldmode; // restore mode
346 // Wait for above to finish
347 THEKERNEL->conveyor->wait_for_empty_queue();
348 }
349
3c947f85 350 this->status = NOT_HOMING;
a0e0d592
BG
351}
352
2b3cedc7 353// If enabled will move the head to 0,0 after homing, but only if X and Y were set to home
2ddf75fd 354void Endstops::move_to_origin(char axes_to_move)
2b3cedc7
JM
355{
356 if( (axes_to_move&0x03) != 3 ) return; // ignore if X and Y not homing
357
fafb45df
JM
358 // Do we need to check if we are already at 0,0? probably not as the G0 will not do anything if we are
359 // float pos[3]; THEKERNEL->robot->get_axis_position(pos); if(pos[0] == 0 && pos[1] == 0) return;
360
2ddf75fd 361 this->status = MOVE_TO_ORIGIN;
2b3cedc7 362 // Move to center using a regular move, use slower of X and Y fast rate
2955fdbb 363 float rate= std::min(this->fast_rates[0], this->fast_rates[1])*60.0F;
2b3cedc7
JM
364 char buf[32];
365 snprintf(buf, sizeof(buf), "G0 X0 Y0 F%1.4f", rate);
366 Gcode gc(buf, &(StreamOutput::NullStream));
367 THEKERNEL->robot->on_gcode_received(&gc); // send to robot directly
368
369 // Wait for above to finish
370 THEKERNEL->conveyor->wait_for_empty_queue();
371 this->status = NOT_HOMING;
372}
373
798295c1 374bool Endstops::wait_for_homed(char axes_to_move)
33e4cc02 375{
a0e0d592 376 bool running = true;
33e4cc02
JM
377 unsigned int debounce[3] = {0, 0, 0};
378 while (running) {
a0e0d592 379 running = false;
314ab8f7 380 THEKERNEL->call_event(ON_IDLE);
798295c1
JM
381
382 // check if on_halt (eg kill)
73706276 383 if(THEKERNEL->is_halted()) return false;
798295c1 384
56ce2b5a
JM
385 for ( int c = X_AXIS; c <= Z_AXIS; c++ ) {
386 if ( ( axes_to_move >> c ) & 1 ) {
387 if ( this->pins[c + (this->home_direction[c] ? 0 : 3)].get() ) {
388 if ( debounce[c] < debounce_count ) {
389 debounce[c]++;
a0e0d592 390 running = true;
dd0a7cfa
JM
391 } else if ( STEPPER[c]->is_moving() ) {
392 STEPPER[c]->move(0, 0);
e0b58122 393 axes_to_move &= ~(1<<c); // no need to check it again
a0e0d592 394 }
33e4cc02 395 } else {
a0e0d592
BG
396 // The endstop was not hit yet
397 running = true;
56ce2b5a 398 debounce[c] = 0;
323cca60 399 }
a0e0d592
BG
400 }
401 }
402 }
798295c1 403 return true;
750277f8 404}
201bcb94 405
81f02e89 406void Endstops::do_homing_cartesian(char axes_to_move)
33e4cc02 407{
798295c1 408 // check if on_halt (eg kill)
73706276 409 if(THEKERNEL->is_halted()) return;
798295c1 410
80605954 411 // this homing works for cartesian and delta printers
f29b0272 412 // Start moving the axes to the origin
2ddf75fd 413 this->status = MOVING_TO_ENDSTOP_FAST;
56ce2b5a
JM
414 for ( int c = X_AXIS; c <= Z_AXIS; c++ ) {
415 if ( ( axes_to_move >> c) & 1 ) {
416 this->feed_rate[c]= this->fast_rates[c];
6f6677fc 417 STEPPER[c]->move(this->home_direction[c], 10000000, 0);
f29b0272
JM
418 }
419 }
420
421 // Wait for all axes to have homed
798295c1 422 if(!this->wait_for_homed(axes_to_move)) return;
f29b0272
JM
423
424 // Move back a small distance
425 this->status = MOVING_BACK;
426 bool inverted_dir;
56ce2b5a
JM
427 for ( int c = X_AXIS; c <= Z_AXIS; c++ ) {
428 if ( ( axes_to_move >> c ) & 1 ) {
429 inverted_dir = !this->home_direction[c];
430 this->feed_rate[c]= this->slow_rates[c];
6f6677fc 431 STEPPER[c]->move(inverted_dir, this->retract_mm[c]*STEPS_PER_MM(c), 0);
f29b0272
JM
432 }
433 }
434
33e4cc02 435 // Wait for moves to be done
56ce2b5a
JM
436 for ( int c = X_AXIS; c <= Z_AXIS; c++ ) {
437 if ( ( axes_to_move >> c ) & 1 ) {
dd0a7cfa 438 while ( STEPPER[c]->is_moving() ) {
314ab8f7 439 THEKERNEL->call_event(ON_IDLE);
ca287785 440 if(THEKERNEL->is_halted()) return;
f29b0272
JM
441 }
442 }
443 }
444
445 // Start moving the axes to the origin slowly
2ddf75fd 446 this->status = MOVING_TO_ENDSTOP_SLOW;
56ce2b5a
JM
447 for ( int c = X_AXIS; c <= Z_AXIS; c++ ) {
448 if ( ( axes_to_move >> c ) & 1 ) {
449 this->feed_rate[c]= this->slow_rates[c];
6f6677fc 450 STEPPER[c]->move(this->home_direction[c], 10000000, 0);
f29b0272
JM
451 }
452 }
453
454 // Wait for all axes to have homed
798295c1 455 if(!this->wait_for_homed(axes_to_move)) return;
f29b0272
JM
456}
457
798295c1 458bool Endstops::wait_for_homed_corexy(int axis)
33e4cc02 459{
3db88866 460 bool running = true;
33e4cc02
JM
461 unsigned int debounce[3] = {0, 0, 0};
462 while (running) {
3db88866 463 running = false;
314ab8f7 464 THEKERNEL->call_event(ON_IDLE);
798295c1
JM
465
466 // check if on_halt (eg kill)
73706276 467 if(THEKERNEL->is_halted()) return false;
798295c1 468
33e4cc02
JM
469 if ( this->pins[axis + (this->home_direction[axis] ? 0 : 3)].get() ) {
470 if ( debounce[axis] < debounce_count ) {
3db88866
JM
471 debounce[axis] ++;
472 running = true;
473 } else {
474 // turn both off if running
dd0a7cfa
JM
475 if (STEPPER[X_AXIS]->is_moving()) STEPPER[X_AXIS]->move(0, 0);
476 if (STEPPER[Y_AXIS]->is_moving()) STEPPER[Y_AXIS]->move(0, 0);
3db88866 477 }
33e4cc02 478 } else {
3db88866
JM
479 // The endstop was not hit yet
480 running = true;
481 debounce[axis] = 0;
482 }
483 }
798295c1 484 return true;
3db88866
JM
485}
486
1ad23cd3 487void Endstops::corexy_home(int home_axis, bool dirx, bool diry, float fast_rate, float slow_rate, unsigned int retract_steps)
33e4cc02 488{
798295c1 489 // check if on_halt (eg kill)
73706276 490 if(THEKERNEL->is_halted()) return;
798295c1 491
2ddf75fd 492 this->status = MOVING_TO_ENDSTOP_FAST;
64eaf21e 493 this->feed_rate[X_AXIS]= fast_rate;
6f6677fc 494 STEPPER[X_AXIS]->move(dirx, 10000000, 0);
64eaf21e 495 this->feed_rate[Y_AXIS]= fast_rate;
6f6677fc 496 STEPPER[Y_AXIS]->move(diry, 10000000, 0);
f29b0272 497
33e4cc02 498 // wait for primary axis
798295c1 499 if(!this->wait_for_homed_corexy(home_axis)) return;
f29b0272 500
33e4cc02
JM
501 // Move back a small distance
502 this->status = MOVING_BACK;
64eaf21e 503 this->feed_rate[X_AXIS]= slow_rate;
6f6677fc 504 STEPPER[X_AXIS]->move(!dirx, retract_steps, 0);
64eaf21e 505 this->feed_rate[Y_AXIS]= slow_rate;
6f6677fc 506 STEPPER[Y_AXIS]->move(!diry, retract_steps, 0);
33e4cc02
JM
507
508 // wait until done
dd0a7cfa 509 while ( STEPPER[X_AXIS]->is_moving() || STEPPER[Y_AXIS]->is_moving()) {
314ab8f7 510 THEKERNEL->call_event(ON_IDLE);
ca287785 511 if(THEKERNEL->is_halted()) return;
f29b0272
JM
512 }
513
33e4cc02 514 // Start moving the axes to the origin slowly
2ddf75fd 515 this->status = MOVING_TO_ENDSTOP_SLOW;
64eaf21e 516 this->feed_rate[X_AXIS]= slow_rate;
6f6677fc 517 STEPPER[X_AXIS]->move(dirx, 10000000, 0);
64eaf21e 518 this->feed_rate[Y_AXIS]= slow_rate;
6f6677fc 519 STEPPER[Y_AXIS]->move(diry, 10000000, 0);
f29b0272 520
33e4cc02 521 // wait for primary axis
798295c1 522 if(!this->wait_for_homed_corexy(home_axis)) return;
33e4cc02 523}
f29b0272 524
33e4cc02
JM
525// this homing works for HBots/CoreXY
526void Endstops::do_homing_corexy(char axes_to_move)
527{
03dffc07 528 // TODO should really make order configurable, and select whether to allow XY to home at the same time, diagonally
174d9961 529 // To move XY at the same time only one motor needs to turn, determine which motor and which direction based on min or max directions
03dffc07 530 // allow to move until an endstop triggers, then stop that motor. Speed up when moving diagonally to match X or Y speed
174d9961 531 // continue moving in the direction not yet triggered (which means two motors turning) until endstop hit
174d9961
JM
532
533 if((axes_to_move & 0x03) == 0x03) { // both X and Y need Homing
534 // determine which motor to turn and which way
535 bool dirx= this->home_direction[X_AXIS];
536 bool diry= this->home_direction[Y_AXIS];
537 int motor;
538 bool dir;
539 if(dirx && diry) { // min/min
540 motor= X_AXIS;
541 dir= true;
542 }else if(dirx && !diry) { // min/max
543 motor= Y_AXIS;
544 dir= true;
545 }else if(!dirx && diry) { // max/min
546 motor= Y_AXIS;
547 dir= false;
548 }else if(!dirx && !diry) { // max/max
549 motor= X_AXIS;
550 dir= false;
551 }
552
553 // then move both X and Y until one hits the endstop
2ddf75fd 554 this->status = MOVING_TO_ENDSTOP_FAST;
6f6677fc 555 // need to allow for more ground covered when moving diagonally
64eaf21e 556 this->feed_rate[motor]= this->fast_rates[motor]*1.4142;
6f6677fc 557 STEPPER[motor]->move(dir, 10000000, 0);
174d9961
JM
558 // wait until either X or Y hits the endstop
559 bool running= true;
560 while (running) {
314ab8f7 561 THEKERNEL->call_event(ON_IDLE);
ca287785 562 if(THEKERNEL->is_halted()) return;
174d9961
JM
563 for(int m=X_AXIS;m<=Y_AXIS;m++) {
564 if(this->pins[m + (this->home_direction[m] ? 0 : 3)].get()) {
565 // turn off motor
dd0a7cfa 566 if(STEPPER[motor]->is_moving()) STEPPER[motor]->move(0, 0);
174d9961
JM
567 running= false;
568 break;
569 }
570 }
571 }
572 }
33e4cc02 573
174d9961 574 // move individual axis
33e4cc02 575 if (axes_to_move & 0x01) { // Home X, which means both X and Y in same direction
413dd90c 576 bool dir= this->home_direction[X_AXIS];
56ce2b5a 577 corexy_home(X_AXIS, dir, dir, this->fast_rates[X_AXIS], this->slow_rates[X_AXIS], this->retract_mm[X_AXIS]*STEPS_PER_MM(X_AXIS));
f29b0272
JM
578 }
579
65191d91
JM
580 if (axes_to_move & 0x02) { // Home Y, which means both X and Y in different directions
581 bool dir= this->home_direction[Y_AXIS];
56ce2b5a 582 corexy_home(Y_AXIS, dir, !dir, this->fast_rates[Y_AXIS], this->slow_rates[Y_AXIS], this->retract_mm[Y_AXIS]*STEPS_PER_MM(Y_AXIS));
65191d91
JM
583 }
584
33e4cc02 585 if (axes_to_move & 0x04) { // move Z
81f02e89 586 do_homing_cartesian(0x04); // just home normally for Z
f29b0272 587 }
f29b0272
JM
588}
589
81f02e89
JM
590void Endstops::home(char axes_to_move)
591{
72833629
JM
592 // not a block move so disable the last tick setting
593 for ( int c = X_AXIS; c <= Z_AXIS; c++ ) {
594 STEPPER[c]->set_moved_last_block(false);
595 }
596
81f02e89
JM
597 if (is_corexy){
598 // corexy/HBot homing
599 do_homing_corexy(axes_to_move);
600 }else{
601 // cartesian/delta homing
602 do_homing_cartesian(axes_to_move);
603 }
0058d8d4
JM
604
605 // make sure all steppers are off (especially if aborted)
606 for ( int c = X_AXIS; c <= Z_AXIS; c++ ) {
607 STEPPER[c]->move(0, 0);
608 }
ca287785 609 this->status = NOT_HOMING;
81f02e89
JM
610}
611
201bcb94 612// Start homing sequences by response to GCode commands
33e4cc02 613void Endstops::on_gcode_received(void *argument)
c339d634 614{
33e4cc02
JM
615 Gcode *gcode = static_cast<Gcode *>(argument);
616 if ( gcode->has_g) {
617 if ( gcode->g == 28 ) {
cbf7b053 618 if(gcode->subcode == 1) { // G28.1
739e3e6f
JM
619 if(gcode->get_num_args() == 0) {
620 THEKERNEL->robot->reset_axis_position(0, 0, 0);
621 }else{
622 // do a manual homing based on current position, no endstops required
623 if(gcode->has_letter('X')) THEKERNEL->robot->reset_axis_position(gcode->get_value('X'), X_AXIS);
624 if(gcode->has_letter('Y')) THEKERNEL->robot->reset_axis_position(gcode->get_value('Y'), Y_AXIS);
625 if(gcode->has_letter('Z')) THEKERNEL->robot->reset_axis_position(gcode->get_value('Z'), Z_AXIS);
626 }
cbf7b053
JM
627 return;
628 }
6e92ab91 629
df27a6a3 630 // G28 is received, we have homing to do
201bcb94
AW
631
632 // First wait for the queue to be empty
314ab8f7 633 THEKERNEL->conveyor->wait_for_empty_queue();
201bcb94
AW
634
635 // Do we move select axes or all of them
7dee696d 636 char axes_to_move = 0;
3e1f5b74
QH
637 // only enable homing if the endstop is defined, deltas, scaras always home all axis
638 bool home_all = this->is_delta || this->is_scara || !( gcode->has_letter('X') || gcode->has_letter('Y') || gcode->has_letter('Z') );
47bbe224 639
56ce2b5a
JM
640 for ( int c = X_AXIS; c <= Z_AXIS; c++ ) {
641 if ( (home_all || gcode->has_letter(c+'X')) && this->pins[c + (this->home_direction[c] ? 0 : 3)].connected() ) {
642 axes_to_move += ( 1 << c );
33e4cc02 643 }
df27a6a3 644 }
3b948656 645
f6c04440 646 // Enable the motors
314ab8f7 647 THEKERNEL->stepper->turn_enable_pins_on();
f6c04440 648
f29b0272 649 // do the actual homing
80605954
JM
650 if(homing_order != 0){
651 // if an order has been specified do it in the specified order
652 // homing order is 0b00ccbbaa where aa is 0,1,2 to specify the first axis, bb is the second and cc is the third
653 // eg 0b00100001 would be Y X Z, 0b00100100 would be X Y Z
654 for (uint8_t m = homing_order; m != 0; m >>= 2) {
655 int a= (1 << (m & 0x03)); // axis to move
798295c1 656 if((a & axes_to_move) != 0){
81f02e89 657 home(a);
798295c1
JM
658 }
659 // check if on_halt (eg kill)
aa896868 660 if(THEKERNEL->is_halted()) break;
80605954 661 }
798295c1 662
80605954
JM
663 }else {
664 // they all home at the same time
81f02e89 665 home(axes_to_move);
80605954 666 }
3ffe27fb 667
798295c1 668 // check if on_halt (eg kill)
aa896868
JM
669 if(THEKERNEL->is_halted()){
670 THEKERNEL->streams->printf("Homing cycle aborted by kill\n");
671 return;
672 }
798295c1 673
cef9acea 674 if(home_all) {
7552475b
OL
675 // Here's where we would have been if the endstops were perfectly trimmed
676 float ideal_position[3] = {
cef9acea
JM
677 this->homing_position[X_AXIS] + this->home_offset[X_AXIS],
678 this->homing_position[Y_AXIS] + this->home_offset[Y_AXIS],
7552475b
OL
679 this->homing_position[Z_AXIS] + this->home_offset[Z_AXIS]
680 };
681
682 bool has_endstop_trim = this->is_delta || this->is_scara;
683 if (has_endstop_trim) {
807b9b57 684 ActuatorCoordinates ideal_actuator_position;
7552475b
OL
685 THEKERNEL->robot->arm_solution->cartesian_to_actuator(ideal_position, ideal_actuator_position);
686
687 // We are actually not at the ideal position, but a trim away
807b9b57 688 ActuatorCoordinates real_actuator_position = {
7552475b
OL
689 ideal_actuator_position[X_AXIS] - this->trim_mm[X_AXIS],
690 ideal_actuator_position[Y_AXIS] - this->trim_mm[Y_AXIS],
691 ideal_actuator_position[Z_AXIS] - this->trim_mm[Z_AXIS]
692 };
693
694 float real_position[3];
695 THEKERNEL->robot->arm_solution->actuator_to_cartesian(real_actuator_position, real_position);
696 // Reset the actuator positions to correspond our real position
697 THEKERNEL->robot->reset_axis_position(real_position[0], real_position[1], real_position[2]);
698 } else {
699 // without endstop trim, real_position == ideal_position
700 // Reset the actuator positions to correspond our real position
701 THEKERNEL->robot->reset_axis_position(ideal_position[0], ideal_position[1], ideal_position[2]);
702 }
703 } else {
cef9acea
JM
704 // Zero the ax(i/e)s position, add in the home offset
705 for ( int c = X_AXIS; c <= Z_AXIS; c++ ) {
706 if ( (axes_to_move >> c) & 1 ) {
707 THEKERNEL->robot->reset_axis_position(this->homing_position[c] + this->home_offset[c], c);
708 }
3ffe27fb
AV
709 }
710 }
3c947f85 711
1b5776bf 712 // on some systems where 0,0 is bed center it is nice to have home goto 0,0 after homing
2b3cedc7 713 // default is off
1b5776bf
JM
714 if(!is_delta) {
715 if(this->move_to_origin_after_home) move_to_origin(axes_to_move);
716 // if limit switches are enabled we must back off endstop after setting home
717 back_off_home(axes_to_move);
718
719 }else if(this->move_to_origin_after_home || this->limit_enable[X_AXIS]) {
720 // deltas are not left at 0,0 because of the trim settings, so move to 0,0 if requested, but we need to back off endstops first
721 // also need to back off endstops if limits are enabled
722 back_off_home(axes_to_move);
723 if(this->move_to_origin_after_home) move_to_origin(axes_to_move);
724 }
c339d634 725 }
81f02e89 726
33e4cc02
JM
727 } else if (gcode->has_m) {
728 switch (gcode->m) {
729 case 119: {
ef7bd372
JM
730 for (int i = 0; i < 6; ++i) {
731 if(this->pins[i].connected())
732 gcode->stream->printf("%s:%d ", endstop_names[i], this->pins[i].get());
733 }
bd96f4d7 734 gcode->add_nl= true;
6e92ab91 735
33e4cc02
JM
736 }
737 break;
738
739 case 206: // M206 - set homing offset
504f0e3e
JM
740 if (gcode->has_letter('X')) home_offset[0] = gcode->get_value('X');
741 if (gcode->has_letter('Y')) home_offset[1] = gcode->get_value('Y');
742 if (gcode->has_letter('Z')) home_offset[2] = gcode->get_value('Z');
743 gcode->stream->printf("X %5.3f Y %5.3f Z %5.3f\n", home_offset[0], home_offset[1], home_offset[2]);
6e92ab91 744
504f0e3e 745 break;
0e4bf280 746
9ae8c7e4 747 case 306: // Similar to M206 and G92 but sets Homing offsets based on current position, Would be M207 but that is taken
504f0e3e
JM
748 {
749 float cartesian[3];
0e4bf280 750 THEKERNEL->robot->get_axis_position(cartesian); // get actual position from robot
9ae8c7e4
JM
751 if (gcode->has_letter('X')){
752 home_offset[0] -= (cartesian[X_AXIS] - gcode->get_value('X'));
753 THEKERNEL->robot->reset_axis_position(gcode->get_value('X'), X_AXIS);
754 }
755 if (gcode->has_letter('Y')) {
756 home_offset[1] -= (cartesian[Y_AXIS] - gcode->get_value('Y'));
757 THEKERNEL->robot->reset_axis_position(gcode->get_value('Y'), Y_AXIS);
758 }
759 if (gcode->has_letter('Z')) {
760 home_offset[2] -= (cartesian[Z_AXIS] - gcode->get_value('Z'));
761 THEKERNEL->robot->reset_axis_position(gcode->get_value('Z'), Z_AXIS);
762 }
763
764 gcode->stream->printf("Homing Offset: X %5.3f Y %5.3f Z %5.3f\n", home_offset[0], home_offset[1], home_offset[2]);
6e92ab91 765
0e4bf280 766 }
33e4cc02
JM
767 break;
768
769 case 500: // save settings
770 case 503: // print settings
771 gcode->stream->printf(";Home offset (mm):\nM206 X%1.2f Y%1.2f Z%1.2f\n", home_offset[0], home_offset[1], home_offset[2]);
d0280b9d 772 if (this->is_delta || this->is_scara) {
56ce2b5a
JM
773 gcode->stream->printf(";Trim (mm):\nM666 X%1.3f Y%1.3f Z%1.3f\n", trim_mm[0], trim_mm[1], trim_mm[2]);
774 gcode->stream->printf(";Max Z\nM665 Z%1.3f\n", this->homing_position[2]);
7a8fe6e0 775 }
c339d634 776 break;
47bbe224 777
ec4773e5 778 case 665: { // M665 - set max gamma/z height
6e92ab91 779
1ad23cd3 780 float gamma_max = this->homing_position[2];
33e4cc02
JM
781 if (gcode->has_letter('Z')) {
782 this->homing_position[2] = gamma_max = gcode->get_value('Z');
ec4773e5 783 }
33e4cc02
JM
784 gcode->stream->printf("Max Z %8.3f ", gamma_max);
785 gcode->add_nl = true;
786 }
787 break;
ec4773e5 788
47bbe224 789
56ce2b5a 790 case 666:
3e1f5b74 791 if(this->is_delta || this->is_scara) { // M666 - set trim for each axis in mm, NB negative mm trim is down
56ce2b5a
JM
792 if (gcode->has_letter('X')) trim_mm[0] = gcode->get_value('X');
793 if (gcode->has_letter('Y')) trim_mm[1] = gcode->get_value('Y');
794 if (gcode->has_letter('Z')) trim_mm[2] = gcode->get_value('Z');
47bbe224 795
56ce2b5a
JM
796 // print the current trim values in mm
797 gcode->stream->printf("X: %5.3f Y: %5.3f Z: %5.3f\n", trim_mm[0], trim_mm[1], trim_mm[2]);
6e92ab91 798
56ce2b5a 799 }
33e4cc02 800 break;
47bbe224 801
d4ee6ee2 802 // NOTE this is to test accuracy of lead screws etc.
fc320ac5 803 case 1910: { // M1910 - move specific number of raw steps
b023850b
JM
804 if(gcode->subcode == 0) {
805 // Enable the motors
806 THEKERNEL->stepper->turn_enable_pins_on();
807
808 int x= 0, y=0 , z= 0, f= 200*16;
809 if (gcode->has_letter('F')) f = gcode->get_value('F');
810 if (gcode->has_letter('X')) {
811 x = gcode->get_value('X');
812 STEPPER[X_AXIS]->move(x<0, abs(x), f);
813 }
814 if (gcode->has_letter('Y')) {
815 y = gcode->get_value('Y');
816 STEPPER[Y_AXIS]->move(y<0, abs(y), f);
817 }
818 if (gcode->has_letter('Z')) {
819 z = gcode->get_value('Z');
820 STEPPER[Z_AXIS]->move(z<0, abs(z), f);
821 }
822 gcode->stream->printf("Moving X %d Y %d Z %d steps at F %d steps/sec\n", x, y, z, f);
823
824 }else if(gcode->subcode == 1) {
825 // stop any that are moving
826 for (int i = 0; i < 3; ++i) {
827 if(STEPPER[i]->is_moving()) STEPPER[i]->move(0, 0);
828 }
d4ee6ee2 829 }
d4ee6ee2
JM
830 break;
831 }
201bcb94
AW
832 }
833 }
834}
835
64eaf21e 836// Called periodically to change the speed to match acceleration
a157d099 837void Endstops::acceleration_tick(void)
64eaf21e 838{
a157d099 839 if(this->status >= NOT_HOMING) return; // nothing to do, only do this when moving for homing sequence
64eaf21e
JM
840
841 // foreach stepper that is moving
842 for ( int c = X_AXIS; c <= Z_AXIS; c++ ) {
dd0a7cfa 843 if( !STEPPER[c]->is_moving() ) continue;
64eaf21e 844
dd0a7cfa 845 uint32_t current_rate = STEPPER[c]->get_steps_per_second();
c8f4ee77 846 uint32_t target_rate = floorf(this->feed_rate[c]*STEPS_PER_MM(c));
c5fe1787 847 float acc= (c==Z_AXIS) ? THEKERNEL->planner->get_z_acceleration() : THEKERNEL->planner->get_acceleration();
64eaf21e 848 if( current_rate < target_rate ){
a157d099 849 uint32_t rate_increase = floorf((acc/THEKERNEL->acceleration_ticks_per_second)*STEPS_PER_MM(c));
64eaf21e
JM
850 current_rate = min( target_rate, current_rate + rate_increase );
851 }
852 if( current_rate > target_rate ){ current_rate = target_rate; }
853
854 // steps per second
6f6677fc 855 STEPPER[c]->set_speed(current_rate);
64eaf21e
JM
856 }
857
a157d099 858 return;
64eaf21e 859}
9f6f04a5
JM
860
861void Endstops::on_get_public_data(void* argument){
862 PublicDataRequest* pdr = static_cast<PublicDataRequest*>(argument);
863
864 if(!pdr->starts_with(endstops_checksum)) return;
865
866 if(pdr->second_element_is(trim_checksum)) {
86fa0b93 867 pdr->set_data_ptr(&this->trim_mm);
ea5c6d92
JM
868 pdr->set_taken();
869
870 }else if(pdr->second_element_is(home_offset_checksum)) {
86fa0b93 871 pdr->set_data_ptr(&this->home_offset);
9f6f04a5
JM
872 pdr->set_taken();
873 }
874}
7d6fe308
JM
875
876void Endstops::on_set_public_data(void* argument){
877 PublicDataRequest* pdr = static_cast<PublicDataRequest*>(argument);
878
879 if(!pdr->starts_with(endstops_checksum)) return;
880
881 if(pdr->second_element_is(trim_checksum)) {
882 float *t= static_cast<float*>(pdr->get_data_ptr());
883 this->trim_mm[0]= t[0];
884 this->trim_mm[1]= t[1];
885 this->trim_mm[2]= t[2];
886 pdr->set_taken();
ea5c6d92
JM
887
888 }else if(pdr->second_element_is(home_offset_checksum)) {
889 float *t= static_cast<float*>(pdr->get_data_ptr());
890 if(!isnan(t[0])) this->home_offset[0]= t[0];
891 if(!isnan(t[1])) this->home_offset[1]= t[1];
892 if(!isnan(t[2])) this->home_offset[2]= t[2];
7d6fe308
JM
893 }
894}