-
Notifications
You must be signed in to change notification settings - Fork 734
/
Printer.cpp
3123 lines (3005 loc) · 123 KB
/
Printer.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
This file is part of Repetier-Firmware.
Repetier-Firmware 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.
Repetier-Firmware 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.
You should have received a copy of the GNU General Public License
along with Repetier-Firmware. If not, see <http://www.gnu.org/licenses/>.
*/
#include "Repetier.h"
#if USE_ADVANCE
ufast8_t Printer::maxExtruderSpeed; ///< Timer delay for end extruder speed
volatile int Printer::extruderStepsNeeded; ///< This many extruder steps are still needed, <0 = reverse steps needed.
//uint8_t Printer::extruderAccelerateDelay; ///< delay between 2 speec increases
#endif
uint8_t Printer::unitIsInches = 0; ///< 0 = Units are mm, 1 = units are inches.
//Stepper Movement Variables
float Printer::axisStepsPerMM[E_AXIS_ARRAY] = { XAXIS_STEPS_PER_MM, YAXIS_STEPS_PER_MM, ZAXIS_STEPS_PER_MM, 1 }; ///< Number of steps per mm needed.
float Printer::invAxisStepsPerMM[E_AXIS_ARRAY]; ///< Inverse of axisStepsPerMM for faster conversion
float Printer::maxFeedrate[E_AXIS_ARRAY] = { MAX_FEEDRATE_X, MAX_FEEDRATE_Y, MAX_FEEDRATE_Z }; ///< Maximum allowed feedrate.
float Printer::homingFeedrate[Z_AXIS_ARRAY] = { HOMING_FEEDRATE_X, HOMING_FEEDRATE_Y, HOMING_FEEDRATE_Z };
#if DUAL_X_RESOLUTION
float Printer::axisX1StepsPerMM = XAXIS_STEPS_PER_MM;
float Printer::axisX2StepsPerMM = X2AXIS_STEPS_PER_MM;
#endif
#if DUAL_X_AXIS_MODE > 0 && LAZY_DUAL_X_AXIS == 0
float Printer::x1Length;
float Printer::x1Min;
#endif
#if RAMP_ACCELERATION
// float max_start_speed_units_per_second[E_AXIS_ARRAY] = MAX_START_SPEED_UNITS_PER_SECOND; ///< Speed we can use, without acceleration.
float Printer::maxAccelerationMMPerSquareSecond[E_AXIS_ARRAY] = { MAX_ACCELERATION_UNITS_PER_SQ_SECOND_X, MAX_ACCELERATION_UNITS_PER_SQ_SECOND_Y, MAX_ACCELERATION_UNITS_PER_SQ_SECOND_Z }; ///< X, Y, Z and E max acceleration in mm/s^2 for printing moves or retracts
float Printer::maxTravelAccelerationMMPerSquareSecond[E_AXIS_ARRAY] = { MAX_TRAVEL_ACCELERATION_UNITS_PER_SQ_SECOND_X, MAX_TRAVEL_ACCELERATION_UNITS_PER_SQ_SECOND_Y, MAX_TRAVEL_ACCELERATION_UNITS_PER_SQ_SECOND_Z }; ///< X, Y, Z max acceleration in mm/s^2 for travel moves
/** Acceleration in steps/s^3 in printing mode.*/
unsigned long Printer::maxPrintAccelerationStepsPerSquareSecond[E_AXIS_ARRAY];
/** Acceleration in steps/s^2 in movement mode.*/
unsigned long Printer::maxTravelAccelerationStepsPerSquareSecond[E_AXIS_ARRAY];
// uint32_t Printer::maxInterval;
#endif
#if NONLINEAR_SYSTEM
long Printer::currentNonlinearPositionSteps[E_TOWER_ARRAY];
uint8_t lastMoveID = 0; // Last move ID
#endif
#if DRIVE_SYSTEM != DELTA
int32_t Printer::zCorrectionStepsIncluded = 0;
#endif
#if FEATURE_BABYSTEPPING
int16_t Printer::zBabystepsMissing = 0;
int16_t Printer::zBabysteps = 0;
#endif
uint8_t Printer::relativeCoordinateMode = false; ///< Determines absolute (false) or relative Coordinates (true).
uint8_t Printer::relativeExtruderCoordinateMode = false; ///< Determines Absolute or Relative E Codes while in Absolute Coordinates mode. E is always relative in Relative Coordinates mode.
int32_t Printer::currentPositionSteps[E_AXIS_ARRAY];
float Printer::currentPosition[E_AXIS_ARRAY];
float Printer::destinationPositionTransformed[E_AXIS_ARRAY];
float Printer::currentPositionTransformed[E_AXIS_ARRAY];
float Printer::lastCmdPos[Z_AXIS_ARRAY];
int32_t Printer::destinationSteps[E_AXIS_ARRAY];
float Printer::coordinateOffset[Z_AXIS_ARRAY] = { 0, 0, 0 };
uint8_t Printer::flag0 = 0;
uint8_t Printer::flag1 = 0;
uint8_t Printer::flag2 = 0;
uint8_t Printer::flag3 = 0;
uint8_t Printer::debugLevel = 6; ///< Bitfield defining debug output. 1 = echo, 2 = info, 4 = error, 8 = dry run., 16 = Only communication, 32 = No moves
fast8_t Printer::stepsPerTimerCall = 1;
uint16_t Printer::menuMode = 0;
uint8_t Printer::mode = DEFAULT_PRINTER_MODE;
uint8_t Printer::fanSpeed = 0; // Last fan speed set with M106/M107
float Printer::extrudeMultiplyError = 0;
float Printer::extrusionFactor = 1.0;
uint8_t Printer::interruptEvent = 0;
fast8_t Printer::breakLongCommand = false;
int Printer::currentLayer = 0;
int Printer::maxLayer = -1; // -1 = unknown
char Printer::printName[21] = ""; // max. 20 chars + 0
float Printer::progress = 0;
millis_t Printer::lastTempReport = 0;
#if EEPROM_MODE != 0
float Printer::zBedOffset = HAL::eprGetFloat(EPR_Z_PROBE_Z_OFFSET);
#else
float Printer::zBedOffset = Z_PROBE_Z_OFFSET;
#endif
#if FEATURE_AUTOLEVEL
float Printer::autolevelTransformation[9]; ///< Transformation matrix
#endif
uint32_t Printer::interval = 30000; ///< Last step duration in ticks.
uint32_t Printer::timer; ///< used for acceleration/deceleration timing
uint32_t Printer::stepNumber; ///< Step number in current move.
#if USE_ADVANCE
#if ENABLE_QUADRATIC_ADVANCE
int32_t Printer::advanceExecuted; ///< Executed advance steps
#endif
int Printer::advanceStepsSet;
#endif
#if NONLINEAR_SYSTEM
int32_t Printer::maxDeltaPositionSteps;
floatLong Printer::deltaDiagonalStepsSquaredA;
floatLong Printer::deltaDiagonalStepsSquaredB;
floatLong Printer::deltaDiagonalStepsSquaredC;
float Printer::deltaMaxRadiusSquared;
float Printer::radius0;
int32_t Printer::deltaFloorSafetyMarginSteps = 0;
int32_t Printer::deltaAPosXSteps;
int32_t Printer::deltaAPosYSteps;
int32_t Printer::deltaBPosXSteps;
int32_t Printer::deltaBPosYSteps;
int32_t Printer::deltaCPosXSteps;
int32_t Printer::deltaCPosYSteps;
int32_t Printer::realDeltaPositionSteps[TOWER_ARRAY];
int16_t Printer::travelMovesPerSecond;
int16_t Printer::printMovesPerSecond;
#endif
#if !NONLINEAR_SYSTEM || defined(FAST_COREXYZ)
int32_t Printer::xMinStepsAdj, Printer::yMinStepsAdj, Printer::zMinStepsAdj; // adjusted to cover extruder/probe offsets
int32_t Printer::xMaxStepsAdj, Printer::yMaxStepsAdj, Printer::zMaxStepsAdj;
#endif
#if FEATURE_Z_PROBE || MAX_HARDWARE_ENDSTOP_Z || NONLINEAR_SYSTEM
int32_t Printer::stepsRemainingAtZHit;
#endif
#if DRIVE_SYSTEM == DELTA
int32_t Printer::stepsRemainingAtXHit;
int32_t Printer::stepsRemainingAtYHit;
#endif
#if SOFTWARE_LEVELING
int32_t Printer::levelingP1[3];
int32_t Printer::levelingP2[3];
int32_t Printer::levelingP3[3];
#endif
//float Printer::minimumSpeed; ///< lowest allowed speed to keep integration error small
//float Printer::minimumZSpeed;
int32_t Printer::xMaxSteps; ///< For software endstops, limit of move in positive direction.
int32_t Printer::yMaxSteps; ///< For software endstops, limit of move in positive direction.
int32_t Printer::zMaxSteps; ///< For software endstops, limit of move in positive direction.
int32_t Printer::xMinSteps; ///< For software endstops, limit of move in negative direction.
int32_t Printer::yMinSteps; ///< For software endstops, limit of move in negative direction.
int32_t Printer::zMinSteps; ///< For software endstops, limit of move in negative direction.
float Printer::xLength;
float Printer::xMin;
float Printer::yLength;
float Printer::yMin;
float Printer::zLength;
float Printer::zMin;
float Printer::feedrate; ///< Last requested feedrate.
int Printer::feedrateMultiply; ///< Multiplier for feedrate in percent (factor 1 = 100)
unsigned int Printer::extrudeMultiply; ///< Flow multiplier in percent (factor 1 = 100)
float Printer::maxJerk; ///< Maximum allowed jerk in mm/s
#if DRIVE_SYSTEM != DELTA
float Printer::maxZJerk; ///< Maximum allowed jerk in z direction in mm/s
#endif
float Printer::offsetX; ///< X-offset for different extruder positions.
float Printer::offsetY; ///< Y-offset for different extruder positions.
float Printer::offsetZ; ///< Z-offset for different extruder positions.
float Printer::offsetZ2 = 0; ///< Z-offset without rotation correction.
speed_t Printer::vMaxReached; ///< Maximum reached speed
uint32_t Printer::msecondsPrinting; ///< Milliseconds of printing time (means time with heated extruder)
float Printer::filamentPrinted; ///< mm of filament printed since counting started
#if ENABLE_BACKLASH_COMPENSATION
float Printer::backlashX;
float Printer::backlashY;
float Printer::backlashZ;
uint8_t Printer::backlashDir;
#endif
float Printer::memoryX = IGNORE_COORDINATE;
float Printer::memoryY = IGNORE_COORDINATE;
float Printer::memoryZ = IGNORE_COORDINATE;
float Printer::memoryE = IGNORE_COORDINATE;
float Printer::memoryF = -1;
#if GANTRY && !defined(FAST_COREXYZ)
int8_t Printer::motorX;
int8_t Printer::motorYorZ;
#endif
#if FAN_THERMO_PIN > -1
float Printer::thermoMinTemp = FAN_THERMO_MIN_TEMP;
float Printer::thermoMaxTemp = FAN_THERMO_MAX_TEMP;
#endif
#ifdef DEBUG_SEGMENT_LENGTH
float Printer::maxRealSegmentLength = 0;
#endif
#ifdef DEBUG_REAL_JERK
float Printer::maxRealJerk = 0;
#endif
#if MULTI_XENDSTOP_HOMING
fast8_t Printer::multiXHomeFlags; // 1 = move X0, 2 = move X1
#endif
#if MULTI_YENDSTOP_HOMING
fast8_t Printer::multiYHomeFlags; // 1 = move Y0, 2 = move Y1
#endif
#if MULTI_ZENDSTOP_HOMING
fast8_t Printer::multiZHomeFlags; // 1 = move Z0, 2 = move Z1
#endif
#if CASE_LIGHTS_PIN > -1
fast8_t Printer::lightOn;
#endif
#ifdef DEBUG_PRINT
int debugWaitLoop = 0;
#endif
#if LAZY_DUAL_X_AXIS
bool Printer::sledParked = false;
#endif
fast8_t Printer::wizardStackPos;
wizardVar Printer::wizardStack[WIZARD_STACK_SIZE];
fast8_t Printer::safetyParked = 0; /// True if moved to a safety position to protect print
uint8_t Printer::rescueOn = false;
bool Printer::failedMode = false;
#if defined(DRV_TMC2130)
#if TMC2130_ON_X
TMC2130Stepper* Printer::tmc_driver_x = NULL;
#endif
#if TMC2130_ON_Y
TMC2130Stepper* Printer::tmc_driver_y = NULL;
#endif
#if TMC2130_ON_Z
TMC2130Stepper* Printer::tmc_driver_z = NULL;
#endif
#if TMC2130_ON_EXT0
TMC2130Stepper* Printer::tmc_driver_e0 = NULL;
#endif
#if TMC2130_ON_EXT1
TMC2130Stepper* Printer::tmc_driver_e1 = NULL;
#endif
#if TMC2130_ON_EXT2
TMC2130Stepper* Printer::tmc_driver_e2 = NULL;
#endif
#if TMC2130_ON_EXT3
TMC2130Stepper* Printer::tmc_driver_e3 = NULL;
#endif
#if TMC2130_ON_EXT4
TMC2130Stepper* Printer::tmc_driver_e4 = NULL;
#endif
#endif
#if !NONLINEAR_SYSTEM
void Printer::constrainDestinationCoords() {
if (isNoDestinationCheck() || isHoming())
return;
#if min_software_endstop_x
if (destinationSteps[X_AXIS] < xMinStepsAdj)
destinationSteps[X_AXIS] = xMinStepsAdj;
#endif
#if min_software_endstop_y
if (destinationSteps[Y_AXIS] < yMinStepsAdj)
destinationSteps[Y_AXIS] = yMinStepsAdj;
#endif
#if min_software_endstop_z
if (isAutolevelActive() == false && destinationSteps[Z_AXIS] < zMinStepsAdj && !isZProbingActive())
destinationSteps[Z_AXIS] = zMinStepsAdj;
#endif
#if max_software_endstop_x
if (destinationSteps[X_AXIS] > xMaxStepsAdj)
destinationSteps[X_AXIS] = xMaxStepsAdj;
#endif
#if max_software_endstop_y
if (destinationSteps[Y_AXIS] > yMaxStepsAdj)
destinationSteps[Y_AXIS] = yMaxStepsAdj;
#endif
#if max_software_endstop_z
if (isAutolevelActive() == false && destinationSteps[Z_AXIS] > zMaxStepsAdj && !isZProbingActive())
destinationSteps[Z_AXIS] = zMaxStepsAdj;
#endif
EVENT_CONTRAIN_DESTINATION_COORDINATES
}
#endif
void Printer::setDebugLevel(uint8_t newLevel) {
if (newLevel != debugLevel) {
debugLevel = newLevel;
if (debugDryrun()) {
// Disable all heaters in case they were on
Extruder::disableAllHeater();
}
}
Com::printFLN(PSTR("DebugLevel:"), (int)newLevel);
}
void Printer::toggleEcho() {
setDebugLevel(debugLevel ^ 1);
}
void Printer::toggleInfo() {
setDebugLevel(debugLevel ^ 2);
}
void Printer::toggleErrors() {
setDebugLevel(debugLevel ^ 4);
}
void Printer::toggleDryRun() {
setDebugLevel(debugLevel ^ 8);
}
void Printer::toggleCommunication() {
setDebugLevel(debugLevel ^ 16);
}
void Printer::toggleNoMoves() {
setDebugLevel(debugLevel ^ 32);
}
void Printer::toggleEndStop() {
setDebugLevel(debugLevel ^ 64);
}
bool Printer::isPositionAllowed(float x, float y, float z) {
if (isNoDestinationCheck())
return true;
bool allowed = true;
#if DRIVE_SYSTEM == DELTA
if (!isHoming()) {
allowed = allowed && (z >= 0) && (z <= zLength + 0.05 + ENDSTOP_Z_BACK_ON_HOME);
allowed = allowed && (x * x + y * y <= deltaMaxRadiusSquared);
}
#else // DRIVE_SYSTEM
if (!isHoming()) {
allowed = allowed && x >= xMin - 0.01;
allowed = allowed && x <= xMin + xLength + 0.01;
allowed = allowed && y >= yMin - 0.01;
allowed = allowed && y <= yMin + yLength + 0.01;
allowed = allowed && z >= zMin - 0.01;
allowed = allowed && z <= zMin + zLength + ENDSTOP_Z_BACK_ON_HOME + 0.01;
}
#endif
/*#if DUAL_X_AXIS
// Prevent carriage hit by disallowing moves inside other parking direction.
if(Extruder::current->id == 0) {
if(x > xMin + xLength + 0.01)
allowed = false;
} else {
if(x < xMin - 0.01)
allowed = false;
}
#endif*/
if (!allowed) {
Printer::updateCurrentPosition(true);
Commands::printCurrentPosition();
}
return allowed;
}
void Printer::setFanSpeedDirectly(uint8_t speed) {
uint8_t trimmedSpeed = TRIM_FAN_PWM(speed);
#if FAN_PIN > -1 && FEATURE_FAN_CONTROL
if (pwm_pos[PWM_FAN1] == trimmedSpeed)
return;
#if FAN_KICKSTART_TIME
if (fanKickstart == 0 && speed > pwm_pos[PWM_FAN1] && speed < 85) {
if (pwm_pos[PWM_FAN1])
fanKickstart = FAN_KICKSTART_TIME / 100;
else
fanKickstart = FAN_KICKSTART_TIME / 25;
}
#endif
pwm_pos[PWM_FAN1] = trimmedSpeed;
#endif
}
void Printer::setFan2SpeedDirectly(uint8_t speed) {
uint8_t trimmedSpeed = TRIM_FAN_PWM(speed);
#if FAN2_PIN > -1 && FEATURE_FAN2_CONTROL
if (pwm_pos[PWM_FAN2] == trimmedSpeed)
return;
#if FAN_KICKSTART_TIME
if (fan2Kickstart == 0 && speed > pwm_pos[PWM_FAN2] && speed < 85) {
if (pwm_pos[PWM_FAN2])
fan2Kickstart = FAN_KICKSTART_TIME / 100;
else
fan2Kickstart = FAN_KICKSTART_TIME / 25;
}
#endif
pwm_pos[PWM_FAN2] = trimmedSpeed;
#endif
}
bool Printer::updateDoorOpen() {
#if defined(DOOR_PIN) && DOOR_PIN > -1 // && SUPPORT_LASER should always be respected
bool isOpen = isDoorOpen();
uint8_t b = READ(DOOR_PIN) != DOOR_INVERTING;
if (b && !isOpen) {
UI_STATUS_F(Com::tSpace);
bool all = Com::writeToAll;
Com::writeToAll = true;
Com::printFLN(PSTR("DoorOpened"));
Com::writeToAll = all;
} else if (!b && isOpen) {
bool all = Com::writeToAll;
Com::writeToAll = true;
Com::printFLN(PSTR("DoorClosed"));
Com::writeToAll = all;
UI_STATUS_F(Com::tDoorOpen);
}
flag3 = (b ? flag3 | PRINTER_FLAG3_DOOR_OPEN : flag3 & ~PRINTER_FLAG3_DOOR_OPEN);
return b;
#else
return 0;
#endif
}
void Printer::reportPrinterMode() {
Printer::setMenuMode(MENU_MODE_CNC + MENU_MODE_LASER + MENU_MODE_FDM, false);
switch (Printer::mode) {
case PRINTER_MODE_FFF:
Printer::setMenuMode(MENU_MODE_FDM, true);
Com::printFLN(Com::tPrinterModeFFF);
break;
case PRINTER_MODE_LASER:
Printer::setMenuMode(MENU_MODE_LASER, true);
Com::printFLN(Com::tPrinterModeLaser);
break;
case PRINTER_MODE_CNC:
Printer::setMenuMode(MENU_MODE_CNC, true);
Com::printFLN(Com::tPrinterModeCNC);
break;
}
}
void Printer::updateDerivedParameter() {
#if NONLINEAR_SYSTEM
travelMovesPerSecond = EEPROM::deltaSegmentsPerSecondMove();
printMovesPerSecond = EEPROM::deltaSegmentsPerSecondPrint();
if (travelMovesPerSecond < 15)
travelMovesPerSecond = 15; // lower values make no sense and can cause serious problems
if (printMovesPerSecond < 15)
printMovesPerSecond = 15;
#endif
#if DRIVE_SYSTEM == DELTA
axisStepsPerMM[X_AXIS] = axisStepsPerMM[Y_AXIS] = axisStepsPerMM[Z_AXIS];
maxAccelerationMMPerSquareSecond[X_AXIS] = maxAccelerationMMPerSquareSecond[Y_AXIS] = maxAccelerationMMPerSquareSecond[Z_AXIS];
homingFeedrate[X_AXIS] = homingFeedrate[Y_AXIS] = homingFeedrate[Z_AXIS];
maxFeedrate[X_AXIS] = maxFeedrate[Y_AXIS] = maxFeedrate[Z_AXIS];
maxTravelAccelerationMMPerSquareSecond[X_AXIS] = maxTravelAccelerationMMPerSquareSecond[Y_AXIS] = maxTravelAccelerationMMPerSquareSecond[Z_AXIS];
zMaxSteps = axisStepsPerMM[Z_AXIS] * (zLength);
towerAMinSteps = axisStepsPerMM[A_TOWER] * xMin;
towerBMinSteps = axisStepsPerMM[B_TOWER] * yMin;
towerCMinSteps = axisStepsPerMM[C_TOWER] * zMin;
//radius0 = EEPROM::deltaHorizontalRadius();
float radiusA = radius0 + EEPROM::deltaRadiusCorrectionA();
float radiusB = radius0 + EEPROM::deltaRadiusCorrectionB();
float radiusC = radius0 + EEPROM::deltaRadiusCorrectionC();
deltaAPosXSteps = floor(radiusA * cos(EEPROM::deltaAlphaA() * M_PI / 180.0f) * axisStepsPerMM[Z_AXIS] + 0.5f);
deltaAPosYSteps = floor(radiusA * sin(EEPROM::deltaAlphaA() * M_PI / 180.0f) * axisStepsPerMM[Z_AXIS] + 0.5f);
deltaBPosXSteps = floor(radiusB * cos(EEPROM::deltaAlphaB() * M_PI / 180.0f) * axisStepsPerMM[Z_AXIS] + 0.5f);
deltaBPosYSteps = floor(radiusB * sin(EEPROM::deltaAlphaB() * M_PI / 180.0f) * axisStepsPerMM[Z_AXIS] + 0.5f);
deltaCPosXSteps = floor(radiusC * cos(EEPROM::deltaAlphaC() * M_PI / 180.0f) * axisStepsPerMM[Z_AXIS] + 0.5f);
deltaCPosYSteps = floor(radiusC * sin(EEPROM::deltaAlphaC() * M_PI / 180.0f) * axisStepsPerMM[Z_AXIS] + 0.5f);
deltaDiagonalStepsSquaredA.l = static_cast<uint32_t>((EEPROM::deltaDiagonalCorrectionA() + EEPROM::deltaDiagonalRodLength()) * axisStepsPerMM[Z_AXIS]);
deltaDiagonalStepsSquaredB.l = static_cast<uint32_t>((EEPROM::deltaDiagonalCorrectionB() + EEPROM::deltaDiagonalRodLength()) * axisStepsPerMM[Z_AXIS]);
deltaDiagonalStepsSquaredC.l = static_cast<uint32_t>((EEPROM::deltaDiagonalCorrectionC() + EEPROM::deltaDiagonalRodLength()) * axisStepsPerMM[Z_AXIS]);
if (deltaDiagonalStepsSquaredA.l > 65534 || 2 * radius0 * axisStepsPerMM[Z_AXIS] > 65534) {
setLargeMachine(true);
#ifdef SUPPORT_64_BIT_MATH
deltaDiagonalStepsSquaredA.L = RMath::sqr(static_cast<uint64_t>(deltaDiagonalStepsSquaredA.l));
deltaDiagonalStepsSquaredB.L = RMath::sqr(static_cast<uint64_t>(deltaDiagonalStepsSquaredB.l));
deltaDiagonalStepsSquaredC.L = RMath::sqr(static_cast<uint64_t>(deltaDiagonalStepsSquaredC.l));
#else
deltaDiagonalStepsSquaredA.f = RMath::sqr(static_cast<float>(deltaDiagonalStepsSquaredA.l));
deltaDiagonalStepsSquaredB.f = RMath::sqr(static_cast<float>(deltaDiagonalStepsSquaredB.l));
deltaDiagonalStepsSquaredC.f = RMath::sqr(static_cast<float>(deltaDiagonalStepsSquaredC.l));
#endif
} else {
setLargeMachine(false);
deltaDiagonalStepsSquaredA.l = RMath::sqr(deltaDiagonalStepsSquaredA.l);
deltaDiagonalStepsSquaredB.l = RMath::sqr(deltaDiagonalStepsSquaredB.l);
deltaDiagonalStepsSquaredC.l = RMath::sqr(deltaDiagonalStepsSquaredC.l);
}
deltaMaxRadiusSquared = RMath::sqr(EEPROM::deltaMaxRadius());
long cart[Z_AXIS_ARRAY], delta[TOWER_ARRAY];
cart[X_AXIS] = cart[Y_AXIS] = 0;
cart[Z_AXIS] = zMaxSteps;
transformCartesianStepsToDeltaSteps(cart, delta);
maxDeltaPositionSteps = delta[0];
xMaxSteps = yMaxSteps = zMaxSteps;
xMinSteps = yMinSteps = zMinSteps = 0;
deltaFloorSafetyMarginSteps = DELTA_FLOOR_SAFETY_MARGIN_MM * axisStepsPerMM[Z_AXIS];
#elif DRIVE_SYSTEM == TUGA
deltaDiagonalStepsSquared.l = uint32_t(EEPROM::deltaDiagonalRodLength() * axisStepsPerMM[X_AXIS]);
if (deltaDiagonalStepsSquared.l > 65534) {
setLargeMachine(true);
deltaDiagonalStepsSquared.f = float(deltaDiagonalStepsSquared.l) * float(deltaDiagonalStepsSquared.l);
} else
deltaDiagonalStepsSquared.l = deltaDiagonalStepsSquared.l * deltaDiagonalStepsSquared.l;
deltaBPosXSteps = static_cast<int32_t>(EEPROM::deltaDiagonalRodLength() * axisStepsPerMM[X_AXIS]);
xMaxSteps = static_cast<int32_t>(axisStepsPerMM[X_AXIS] * (xMin + xLength));
yMaxSteps = static_cast<int32_t>(axisStepsPerMM[Y_AXIS] * yLength);
zMaxSteps = static_cast<int32_t>(axisStepsPerMM[Z_AXIS] * (zMin + zLength));
xMinSteps = static_cast<int32_t>(axisStepsPerMM[X_AXIS] * xMin);
yMinSteps = 0;
zMinSteps = static_cast<int32_t>(axisStepsPerMM[Z_AXIS] * zMin);
#else
#if DUAL_X_RESOLUTION
if (Extruder::current->id == 0) // adjust resolution based on active extruder
axisStepsPerMM[X_AXIS] = axisX1StepsPerMM;
else
axisStepsPerMM[X_AXIS] = axisX2StepsPerMM;
invAxisStepsPerMM[X_AXIS] = 1.0 / axisStepsPerMM[X_AXIS];
#endif
xMaxStepsAdj = xMaxSteps = static_cast<int32_t>(axisStepsPerMM[X_AXIS] * (xMin + xLength));
yMaxStepsAdj = yMaxSteps = static_cast<int32_t>(axisStepsPerMM[Y_AXIS] * (yMin + yLength));
zMaxStepsAdj = zMaxSteps = static_cast<int32_t>(axisStepsPerMM[Z_AXIS] * (zMin + zLength));
xMinStepsAdj = xMinSteps = static_cast<int32_t>(axisStepsPerMM[X_AXIS] * xMin);
yMinStepsAdj = yMinSteps = static_cast<int32_t>(axisStepsPerMM[Y_AXIS] * yMin);
zMinStepsAdj = zMinSteps = static_cast<int32_t>(axisStepsPerMM[Z_AXIS] * zMin);
for (fast8_t i = 0; i < NUM_EXTRUDER; i++) {
Extruder& e = extruder[i];
xMaxStepsAdj = RMath::max(xMaxStepsAdj, xMaxSteps - e.xOffset);
xMinStepsAdj = RMath::min(xMinStepsAdj, xMinSteps - e.xOffset);
yMaxStepsAdj = RMath::max(yMaxStepsAdj, yMaxSteps - e.yOffset);
yMinStepsAdj = RMath::min(yMinStepsAdj, yMinSteps - e.yOffset);
zMaxStepsAdj = RMath::max(zMaxStepsAdj, zMaxSteps - e.zOffset);
zMinStepsAdj = RMath::min(zMinStepsAdj, zMinSteps - e.zOffset);
}
#if FEATURE_Z_PROBE
xMaxStepsAdj = RMath::max(xMaxStepsAdj, xMaxSteps - static_cast<int32_t>(EEPROM::zProbeXOffset() * axisStepsPerMM[X_AXIS]));
xMinStepsAdj = RMath::min(xMinStepsAdj, xMinSteps - static_cast<int32_t>(EEPROM::zProbeXOffset() * axisStepsPerMM[X_AXIS]));
yMaxStepsAdj = RMath::max(yMaxStepsAdj, yMaxSteps - static_cast<int32_t>(EEPROM::zProbeYOffset() * axisStepsPerMM[Y_AXIS]));
yMinStepsAdj = RMath::min(yMinStepsAdj, yMinSteps - static_cast<int32_t>(EEPROM::zProbeYOffset() * axisStepsPerMM[Y_AXIS]));
#endif
// For which directions do we need backlash compensation
#if ENABLE_BACKLASH_COMPENSATION
backlashDir &= XYZ_DIRPOS;
if (backlashX != 0)
backlashDir |= 8;
if (backlashY != 0)
backlashDir |= 16;
if (backlashZ != 0)
backlashDir |= 32;
#endif
#endif
for (uint8_t i = 0; i < E_AXIS_ARRAY; i++) {
invAxisStepsPerMM[i] = 1.0f / axisStepsPerMM[i];
#ifdef RAMP_ACCELERATION
/** Acceleration in steps/s^3 in printing mode.*/
maxPrintAccelerationStepsPerSquareSecond[i] = maxAccelerationMMPerSquareSecond[i] * axisStepsPerMM[i];
/** Acceleration in steps/s^2 in movement mode.*/
maxTravelAccelerationStepsPerSquareSecond[i] = maxTravelAccelerationMMPerSquareSecond[i] * axisStepsPerMM[i];
#endif
}
// For numeric stability we need to start accelerations at a minimum speed and hence ensure that the
// jerk is at least 2 * minimum speed.
// For xy moves the minimum speed is multiplied with 1.41 to enforce the condition also for diagonals since the
// driving axis is the problematic speed.
float accel = RMath::max(maxAccelerationMMPerSquareSecond[X_AXIS], maxTravelAccelerationMMPerSquareSecond[X_AXIS]);
float minimumSpeed = 1.41 * accel * sqrt(2.0f / (axisStepsPerMM[X_AXIS] * accel));
accel = RMath::max(maxAccelerationMMPerSquareSecond[Y_AXIS], maxTravelAccelerationMMPerSquareSecond[Y_AXIS]);
float minimumSpeed2 = 1.41 * accel * sqrt(2.0f / (axisStepsPerMM[Y_AXIS] * accel));
if (minimumSpeed2 > minimumSpeed) {
minimumSpeed = minimumSpeed2;
}
if (maxJerk < 2 * minimumSpeed) { // Enforce minimum start speed if target is faster and jerk too low
maxJerk = 2 * minimumSpeed;
Com::printFLN(PSTR("XY jerk was too low, setting to "), maxJerk);
}
accel = RMath::max(maxAccelerationMMPerSquareSecond[Z_AXIS], maxTravelAccelerationMMPerSquareSecond[Z_AXIS]);
#if DRIVE_SYSTEM != DELTA
float minimumZSpeed = 0.5 * accel * sqrt(2.0f / (axisStepsPerMM[Z_AXIS] * accel));
if (maxZJerk < 2 * minimumZSpeed) {
maxZJerk = 2 * minimumZSpeed;
Com::printFLN(PSTR("Z jerk was too low, setting to "), maxZJerk);
}
#endif
/*
maxInterval = F_CPU / (minimumSpeed * axisStepsPerMM[X_AXIS]);
uint32_t tmp = F_CPU / (minimumSpeed * axisStepsPerMM[Y_AXIS]);
if(tmp < maxInterval)
maxInterval = tmp;
#if DRIVE_SYSTEM != DELTA
tmp = F_CPU / (minimumZSpeed * axisStepsPerMM[Z_AXIS]);
if(tmp < maxInterval)
maxInterval = tmp;
#endif
*/
//Com::printFLN(PSTR("Minimum Speed:"),minimumSpeed);
//Com::printFLN(PSTR("Minimum Speed Z:"),minimumZSpeed);
#if DISTORTION_CORRECTION
distortion.updateDerived();
#endif // DISTORTION_CORRECTION
Printer::updateAdvanceFlags();
EVENT_UPDATE_DERIVED;
}
#if AUTOMATIC_POWERUP
void Printer::enablePowerIfNeeded() {
if (Printer::isPowerOn())
return;
SET_OUTPUT(PS_ON_PIN); //GND
Printer::setPowerOn(true);
WRITE(PS_ON_PIN, (POWER_INVERTING ? HIGH : LOW));
HAL::delayMilliseconds(500); // Just to ensure power is up and stable
}
#endif
/**
\brief Stop heater and stepper motors. Disable power,if possible.
*/
void Printer::kill(uint8_t onlySteppers) {
EVENT_KILL(onlySteppers);
if (areAllSteppersDisabled() && onlySteppers)
return;
if (Printer::isAllKilled())
return;
#if defined(NUM_MOTOR_DRIVERS) && NUM_MOTOR_DRIVERS > 0
disableAllMotorDrivers();
#endif // defined
disableXStepper();
disableYStepper();
#if !defined(PREVENT_Z_DISABLE_ON_STEPPER_TIMEOUT)
disableZStepper();
#else
if (!onlySteppers)
disableZStepper();
#endif
Extruder::disableAllExtruderMotors();
setAllSteppersDiabled();
unsetHomedAll();
if (!onlySteppers) {
for (uint8_t i = 0; i < NUM_EXTRUDER; i++)
Extruder::setTemperatureForExtruder(0, i);
Extruder::setHeatedBedTemperature(0);
UI_STATUS_UPD_F(Com::translatedF(UI_TEXT_STANDBY_ID));
#if defined(PS_ON_PIN) && PS_ON_PIN > -1 && !defined(NO_POWER_TIMEOUT)
//pinMode(PS_ON_PIN,INPUT);
SET_OUTPUT(PS_ON_PIN); //GND
WRITE(PS_ON_PIN, (POWER_INVERTING ? LOW : HIGH));
Printer::setPowerOn(false);
#endif
Printer::setAllKilled(true);
} else
UI_STATUS_UPD_F(Com::translatedF(UI_TEXT_STEPPER_DISABLED_ID));
#if FAN_BOARD_PIN > -1
#if HAVE_HEATED_BED
if (heatedBedController.targetTemperatureC < 15) // turn off FAN_BOARD only if bed heater is off
#endif
pwm_pos[PWM_BOARD_FAN] = BOARD_FAN_MIN_SPEED;
#endif // FAN_BOARD_PIN
Commands::printTemperatures(false);
}
void Printer::updateAdvanceFlags() {
Printer::setAdvanceActivated(false);
#if USE_ADVANCE
for (uint8_t i = 0; i < NUM_EXTRUDER; i++) {
if (extruder[i].advanceL != 0) {
Printer::setAdvanceActivated(true);
}
#if ENABLE_QUADRATIC_ADVANCE
if (extruder[i].advanceK != 0)
Printer::setAdvanceActivated(true);
#endif
}
#endif
}
void Printer::moveToParkPosition(bool zOnly) {
if (Printer::isHomedAll()) { // for safety move only when homed!
if (!zOnly) {
moveToReal(EEPROM::parkX(), EEPROM::parkY(), IGNORE_COORDINATE, IGNORE_COORDINATE, Printer::maxFeedrate[X_AXIS], true);
}
moveToReal(IGNORE_COORDINATE, IGNORE_COORDINATE, RMath::min(zMin + zLength, currentPosition[Z_AXIS] + EEPROM::parkZ()), IGNORE_COORDINATE, Printer::maxFeedrate[Z_AXIS], true);
}
}
// This is for untransformed move to coordinates in printers absolute Cartesian space
uint8_t Printer::moveTo(float x, float y, float z, float e, float f) {
Printer::unparkSafety();
if (x != IGNORE_COORDINATE) {
destinationPositionTransformed[X_AXIS] = (x + Printer::offsetX);
destinationSteps[X_AXIS] = destinationPositionTransformed[X_AXIS] * axisStepsPerMM[X_AXIS];
} else {
destinationPositionTransformed[X_AXIS] = currentPositionTransformed[X_AXIS];
destinationSteps[X_AXIS] = currentPositionSteps[X_AXIS];
}
if (y != IGNORE_COORDINATE) {
destinationPositionTransformed[Y_AXIS] = (y + Printer::offsetY);
destinationSteps[Y_AXIS] = destinationPositionTransformed[Y_AXIS] * axisStepsPerMM[Y_AXIS];
} else {
destinationPositionTransformed[Y_AXIS] = currentPositionTransformed[Y_AXIS];
destinationSteps[Y_AXIS] = currentPositionSteps[Y_AXIS];
}
if (z != IGNORE_COORDINATE) {
destinationPositionTransformed[Z_AXIS] = (z + Printer::offsetZ);
destinationSteps[Z_AXIS] = destinationPositionTransformed[Z_AXIS] * axisStepsPerMM[Z_AXIS];
} else {
destinationPositionTransformed[Z_AXIS] = currentPositionTransformed[Z_AXIS];
destinationSteps[Z_AXIS] = currentPositionSteps[Z_AXIS];
}
if (e != IGNORE_COORDINATE) {
destinationPositionTransformed[E_AXIS] = e;
destinationSteps[E_AXIS] = e * axisStepsPerMM[E_AXIS];
} else {
destinationPositionTransformed[E_AXIS] = currentPositionTransformed[E_AXIS];
destinationSteps[E_AXIS] = currentPositionSteps[E_AXIS];
}
if (f != IGNORE_COORDINATE) {
feedrate = f;
}
#if NONLINEAR_SYSTEM
// Disable software end stop or we get wrong distances when length < real length
if (!PrintLine::queueNonlinearMove(ALWAYS_CHECK_ENDSTOPS, true, false)) {
Com::printWarningFLN(PSTR("moveTo / queueDeltaMove returns error"));
return 0;
}
#else
PrintLine::queueCartesianMove(ALWAYS_CHECK_ENDSTOPS, true);
#endif
updateCurrentPosition(false);
return 1;
}
void Printer::moveToCenter() {
#if DRIVE_SYSTEM == DELTA
moveToReal(0, 0, IGNORE_COORDINATE, homingFeedrate[Z_AXIS], false);
#else
moveToReal(xMin + 0.5 * xLength, yMin + 0.5 * yLength, IGNORE_COORDINATE, homingFeedrate[X_AXIS], false);
#endif
}
uint8_t Printer::moveToReal(float x, float y, float z, float e, float f, bool pathOptimize) {
Printer::unparkSafety();
// Com::printFLN(PSTR("MoveToReal X="),x,2);
// Com::printArrayFLN(PSTR("CurPos:"), currentPositionTransformed);
if (x == IGNORE_COORDINATE)
x = currentPosition[X_AXIS];
currentPosition[X_AXIS] = x;
if (y == IGNORE_COORDINATE)
y = currentPosition[Y_AXIS];
currentPosition[Y_AXIS] = y;
if (z == IGNORE_COORDINATE)
z = currentPosition[Z_AXIS];
currentPosition[Z_AXIS] = z;
transformToPrinter(x + Printer::offsetX, y + Printer::offsetY, z + Printer::offsetZ, destinationPositionTransformed[X_AXIS], destinationPositionTransformed[Y_AXIS], destinationPositionTransformed[Z_AXIS]);
destinationPositionTransformed[Z_AXIS] += offsetZ2;
// There was conflicting use of IGNOR_COORDINATE
destinationSteps[X_AXIS] = lroundf(destinationPositionTransformed[X_AXIS] * axisStepsPerMM[X_AXIS]);
destinationSteps[Y_AXIS] = lroundf(destinationPositionTransformed[Y_AXIS] * axisStepsPerMM[Y_AXIS]);
destinationSteps[Z_AXIS] = lroundf(destinationPositionTransformed[Z_AXIS] * axisStepsPerMM[Z_AXIS]);
if (e != IGNORE_COORDINATE && !Printer::debugDryrun()
#if MIN_EXTRUDER_TEMP > 30
&& (Extruder::current->tempControl.currentTemperatureC > MIN_EXTRUDER_TEMP || Printer::isColdExtrusionAllowed() || Extruder::current->tempControl.sensorType == 0)
#endif
) {
destinationPositionTransformed[E_AXIS] = e;
destinationSteps[E_AXIS] = e * axisStepsPerMM[E_AXIS];
} else {
destinationPositionTransformed[E_AXIS] = currentPositionTransformed[E_AXIS];
destinationSteps[E_AXIS] = currentPositionSteps[E_AXIS];
}
if (f != IGNORE_COORDINATE)
feedrate = f;
// Com::printArrayFLN(PSTR("DestPos:"), destinationPositionTransformed);
#if NONLINEAR_SYSTEM
if (!PrintLine::queueNonlinearMove(ALWAYS_CHECK_ENDSTOPS, pathOptimize, true)) {
Com::printWarningFLN(PSTR("moveToReal / queueDeltaMove returns error"));
SHOWM(x);
SHOWM(y);
SHOWM(z);
return 0;
}
#else
PrintLine::queueCartesianMove(ALWAYS_CHECK_ENDSTOPS, pathOptimize);
#endif
return 1;
}
void Printer::setOrigin(float xOff, float yOff, float zOff) {
coordinateOffset[X_AXIS] = xOff; // offset from G92
coordinateOffset[Y_AXIS] = yOff;
coordinateOffset[Z_AXIS] = zOff;
}
/** Computes currentPosition from currentPositionSteps including correction for offset. */
void Printer::updateCurrentPosition(bool copyLastCmd) {
#if DUAL_X_AXIS && LAZY_DUAL_X_AXIS
if (!sledParked)
currentPositionTransformed[X_AXIS] = static_cast<float>(currentPositionSteps[X_AXIS]) * invAxisStepsPerMM[X_AXIS];
#else
currentPositionTransformed[X_AXIS] = static_cast<float>(currentPositionSteps[X_AXIS]) * invAxisStepsPerMM[X_AXIS];
#endif
currentPositionTransformed[Y_AXIS] = static_cast<float>(currentPositionSteps[Y_AXIS]) * invAxisStepsPerMM[Y_AXIS];
#if NONLINEAR_SYSTEM
currentPositionTransformed[Z_AXIS] = static_cast<float>(currentPositionSteps[Z_AXIS]) * invAxisStepsPerMM[Z_AXIS] - offsetZ2;
#else
currentPositionTransformed[Z_AXIS] = static_cast<float>(currentPositionSteps[Z_AXIS] - zCorrectionStepsIncluded) * invAxisStepsPerMM[Z_AXIS] - offsetZ2;
#endif
// currentPositionTransformed[E_AXIS] = currentPositionSteps[E_AXIS] * invAxisStepsPerMM[E_AXIS];
transformFromPrinter(currentPositionTransformed[X_AXIS], currentPositionTransformed[Y_AXIS], currentPositionTransformed[Z_AXIS],
currentPosition[X_AXIS], currentPosition[Y_AXIS], currentPosition[Z_AXIS]);
currentPosition[X_AXIS] -= Printer::offsetX; // Offset from active extruder or z probe
currentPosition[Y_AXIS] -= Printer::offsetY;
currentPosition[Z_AXIS] -= Printer::offsetZ;
if (copyLastCmd) {
lastCmdPos[X_AXIS] = currentPosition[X_AXIS];
lastCmdPos[Y_AXIS] = currentPosition[Y_AXIS];
lastCmdPos[Z_AXIS] = currentPosition[Z_AXIS];
}
}
void Printer::updateCurrentPositionSteps() {
float x_rotc, y_rotc, z_rotc;
transformToPrinter(currentPosition[X_AXIS] + Printer::offsetX, currentPosition[Y_AXIS] + Printer::offsetY, currentPosition[Z_AXIS] + Printer::offsetZ, x_rotc, y_rotc, z_rotc);
z_rotc += offsetZ2;
destinationSteps[X_AXIS] = currentPositionSteps[X_AXIS] = lroundf(x_rotc * axisStepsPerMM[X_AXIS]);
destinationSteps[Y_AXIS] = currentPositionSteps[Y_AXIS] = lroundf(y_rotc * axisStepsPerMM[Y_AXIS]);
destinationSteps[Z_AXIS] = currentPositionSteps[Z_AXIS] = lroundf(z_rotc * axisStepsPerMM[Z_AXIS]);
destinationSteps[E_AXIS] = currentPositionSteps[E_AXIS] = lroundf(currentPositionTransformed[E_AXIS] * axisStepsPerMM[E_AXIS]);
#if NONLINEAR_SYSTEM
transformCartesianStepsToDeltaSteps(Printer::currentPositionSteps, Printer::currentNonlinearPositionSteps);
#endif
#if DRIVE_SYSTEM != DELTA
zCorrectionStepsIncluded = 0;
#endif
}
/** \brief Sets the destination coordinates to values stored in com.
Extracts x,y,z,e,f from g-code considering active units. Converted result is stored in currentPosition and lastCmdPos. Converts
position to destinationSteps including rotation and offsets, excluding distortion correction (which gets added on move queuing).
\param com g-code with new destination position.
\return true if it is a move, false if no move results from coordinates.
*/
uint8_t Printer::setDestinationStepsFromGCode(GCode* com) {
unparkSafety();
register int32_t p;
float x, y, z;
bool posAllowed = true;
#if FEATURE_RETRACTION
if (com->hasNoXYZ() && com->hasE() && isAutoretract()) { // convert into auto retract
if (relativeCoordinateMode || relativeExtruderCoordinateMode) {
Extruder::current->retract(com->E < 0, false);
} else {
p = convertToMM(com->E * axisStepsPerMM[E_AXIS]); // target position
Extruder::current->retract(p < currentPositionSteps[E_AXIS], false);
}
return 0; // Fake no move so nothing gets added
}
#endif
#if DISTORTION_CORRECTION == 0
if (!com->hasNoXYZ()) {
#endif
if (!relativeCoordinateMode) {
if (com->hasX())
currentPosition[X_AXIS] = lastCmdPos[X_AXIS] = convertToMM(com->X) - coordinateOffset[X_AXIS];
if (com->hasY())
currentPosition[Y_AXIS] = lastCmdPos[Y_AXIS] = convertToMM(com->Y) - coordinateOffset[Y_AXIS];
if (com->hasZ())
currentPosition[Z_AXIS] = lastCmdPos[Z_AXIS] = convertToMM(com->Z) - coordinateOffset[Z_AXIS];
} else {
if (com->hasX())
currentPosition[X_AXIS] = (lastCmdPos[X_AXIS] += convertToMM(com->X));
if (com->hasY())
currentPosition[Y_AXIS] = (lastCmdPos[Y_AXIS] += convertToMM(com->Y));
if (com->hasZ())
currentPosition[Z_AXIS] = (lastCmdPos[Z_AXIS] += convertToMM(com->Z));
}
transformToPrinter(lastCmdPos[X_AXIS] + Printer::offsetX, lastCmdPos[Y_AXIS] + Printer::offsetY, lastCmdPos[Z_AXIS] + Printer::offsetZ, destinationPositionTransformed[X_AXIS], destinationPositionTransformed[Y_AXIS], destinationPositionTransformed[Z_AXIS]);
destinationPositionTransformed[Z_AXIS] += offsetZ2;
destinationSteps[X_AXIS] = lroundf(destinationPositionTransformed[X_AXIS] * axisStepsPerMM[X_AXIS]);
destinationSteps[Y_AXIS] = lroundf(destinationPositionTransformed[Y_AXIS] * axisStepsPerMM[Y_AXIS]);
destinationSteps[Z_AXIS] = lroundf(destinationPositionTransformed[Z_AXIS] * axisStepsPerMM[Z_AXIS]);
#if MOVE_X_WHEN_HOMED == 1 || MOVE_Y_WHEN_HOMED == 1 || MOVE_Z_WHEN_HOMED == 1
if (!isNoDestinationCheck()) {
#if MOVE_X_WHEN_HOMED
if (!isXHomed()) {
currentPositionSteps[X_AXIS] = destinationSteps[X_AXIS];
currentPosition[X_AXIS] = destinationPositionTransformed[X_AXIS];
}
#endif
#if MOVE_Y_WHEN_HOMED
if (!isYHomed()) {
currentPositionSteps[Y_AXIS] = destinationSteps[Y_AXIS];
currentPosition[Y_AXIS] = destinationPositionTransformed[Y_AXIS];
}
#endif
#if MOVE_Z_WHEN_HOMED
if (!isZHomed()) {
currentPositionSteps[Z_AXIS] = destinationSteps[Z_AXIS];
currentPosition[Z_AXIS] = destinationPositionTransformed[Z_AXIS];
}
#endif
}
#endif
#if LAZY_DUAL_X_AXIS
sledParked = false;
#endif
posAllowed = com->hasNoXYZ() || Printer::isPositionAllowed(lastCmdPos[X_AXIS], lastCmdPos[Y_AXIS], lastCmdPos[Z_AXIS]);
#if DISTORTION_CORRECTION == 0
}
#endif
#if DUAL_X_AXIS && LAZY_DUAL_X_AXIS
if (sledParked) {
destinationSteps[X_AXIS] = currentPositionSteps[X_AXIS];
destinationSteps[Y_AXIS] = currentPositionSteps[Y_AXIS];
destinationSteps[Z_AXIS] = currentPositionSteps[Z_AXIS];
}
#endif
if (com->hasE() && !Printer::debugDryrun()) {
p = convertToMM(com->E * axisStepsPerMM[E_AXIS]);
if (relativeCoordinateMode || relativeExtruderCoordinateMode) {
if (
#if MIN_EXTRUDER_TEMP > 20
(Extruder::current->tempControl.currentTemperatureC < MIN_EXTRUDER_TEMP && !Printer::isColdExtrusionAllowed() && Extruder::current->tempControl.sensorType != 0) ||
#endif
fabs(com->E) * extrusionFactor > EXTRUDE_MAXLENGTH) {
p = 0;
destinationPositionTransformed[E_AXIS] = currentPositionTransformed[E_AXIS] = 0;
} else {
destinationPositionTransformed[E_AXIS] = 0;
currentPositionTransformed[E_AXIS] = -convertToMM(com->E);
}
destinationSteps[E_AXIS] = 0;
currentPositionSteps[E_AXIS] = -p;
} else {
if (
#if MIN_EXTRUDER_TEMP > 20
(Extruder::current->tempControl.currentTemperatureC < MIN_EXTRUDER_TEMP && !Printer::isColdExtrusionAllowed() && Extruder::current->tempControl.sensorType != 0) ||
#endif
fabs(p - currentPositionSteps[E_AXIS]) * extrusionFactor > EXTRUDE_MAXLENGTH * axisStepsPerMM[E_AXIS]) {
currentPositionSteps[E_AXIS] = p;
destinationPositionTransformed[E_AXIS] = currentPositionTransformed[E_AXIS] = convertToMM(com->E);
} else {
destinationPositionTransformed[E_AXIS] = convertToMM(com->E);
}
destinationSteps[E_AXIS] = p;
}
} else {
destinationPositionTransformed[E_AXIS] = currentPositionTransformed[E_AXIS];
Printer::destinationSteps[E_AXIS] = Printer::currentPositionSteps[E_AXIS];
}
if (com->hasF() && com->F > 0.1) {
if (unitIsInches)
feedrate = com->F * 0.0042333f * (float)feedrateMultiply; // Factor is 25.5/60/100
else
feedrate = com->F * (float)feedrateMultiply * 0.00016666666f;
}
if (!posAllowed) {
currentPositionSteps[E_AXIS] = destinationSteps[E_AXIS];
return false; // ignore move
}
return !com->hasNoXYZ() || (com->hasE() && destinationSteps[E_AXIS] != currentPositionSteps[E_AXIS]); // ignore unproductive moves
}
void Printer::setup() {
HAL::stopWatchdog();
for (uint8_t i = 0; i < NUM_PWM; i++)
pwm_pos[i] = 0;
#if FEATURE_CONTROLLER == CONTROLLER_VIKI
HAL::delayMilliseconds(100);
#endif // FEATURE_CONTROLLER
#if defined(MB_SETUP)
MB_SETUP;
#endif
#if UI_DISPLAY_TYPE != NO_DISPLAY
Com::selectLanguage(0); // just make sure we have a language in case someone uses it early
#endif
//HAL::delayMilliseconds(500); // add a delay at startup to give hardware time for initalization
#if defined(EEPROM_AVAILABLE) && defined(EEPROM_SPI_ALLIGATOR) && EEPROM_AVAILABLE == EEPROM_SPI_ALLIGATOR
HAL::spiBegin();
#endif
HAL::hwSetup();
EVENT_INITIALIZE_EARLY
#ifdef ANALYZER
// Channel->pin assignments
#if ANALYZER_CH0 >= 0
SET_OUTPUT(ANALYZER_CH0);
#endif
#if ANALYZER_CH1 >= 0
SET_OUTPUT(ANALYZER_CH1);
#endif
#if ANALYZER_CH2 >= 0
SET_OUTPUT(ANALYZER_CH2);
#endif
#if ANALYZER_CH3 >= 0
SET_OUTPUT(ANALYZER_CH3);
#endif
#if ANALYZER_CH4 >= 0
SET_OUTPUT(ANALYZER_CH4);
#endif
#if ANALYZER_CH5 >= 0
SET_OUTPUT(ANALYZER_CH5);
#endif
#if ANALYZER_CH6 >= 0
SET_OUTPUT(ANALYZER_CH6);
#endif
#if ANALYZER_CH7 >= 0
SET_OUTPUT(ANALYZER_CH7);
#endif