forked from RF1000/Repetier-Firmware
/
motion.cpp
1821 lines (1569 loc) · 74.7 KB
/
motion.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 the Repetier-Firmware for RF devices from Conrad Electronic SE.
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"
// ================ Sanity checks ================
#ifndef STEP_PACKING_MIN_INTERVAL
#error Please add new parameter STEP_PACKING_MIN_INTERVAL to your configuration.
#else
#if STEP_PACKING_MIN_INTERVAL<MIN_STEP_PACKING_MIN_INTERVAL || STEP_PACKING_MIN_INTERVAL>MAX_STEP_PACKING_MIN_INTERVAL
#error STEP_PACKING_MIN_INTERVAL should be in range of MIN_STEP_PACKING_MIN_INTERVAL .. MAX_STEP_PACKING_MIN_INTERVAL
#endif // STEP_PACKING_MIN_INTERVAL<MIN_STEP_PACKING_MIN_INTERVAL || STEP_PACKING_MIN_INTERVAL>MAX_STEP_PACKING_MIN_INTERVAL
#endif // STEP_PACKING_MIN_INTERVAL
#ifdef EXTRUDER_SPEED
#error EXTRUDER_SPEED is not used any more. Values are now taken from extruder definition.
#endif // EXTRUDER_SPEED
#ifdef ENDSTOPPULLUPS
#error ENDSTOPPULLUPS is now replaced by individual pullup configuration!
#endif // ENDSTOPPULLUPS
#ifdef EXT0_PID_PGAIN
#error The PID system has changed. Please use the new float number options!
#endif // EXT0_PID_PGAIN
// ####################################################################################
// ## No configuration below this line - just some errorchecking
// ####################################################################################
#if X_STEP_PIN<0 || Y_STEP_PIN<0 || Z_STEP_PIN<0
#error One of the following pins is not assigned: X_STEP_PIN,Y_STEP_PIN,Z_STEP_PIN
#endif // X_STEP_PIN<0 || Y_STEP_PIN<0 || Z_STEP_PIN<0
#if EXT0_STEP_PIN<0 && NUM_EXTRUDER>0
#error EXT0_STEP_PIN not set to a pin number.
#endif // EXT0_STEP_PIN<0 && NUM_EXTRUDER>0
#if EXT0_DIR_PIN<0 && NUM_EXTRUDER>0
#error EXT0_DIR_PIN not set to a pin number.
#endif // EXT0_DIR_PIN<0 && NUM_EXTRUDER>0
#if MOVE_CACHE_SIZE<5
#error MOVE_CACHE_SIZE must be at least 5
#endif // MOVE_CACHE_SIZE<5
// Inactivity shutdown variables
millis_t previousMillisCmd = 0;
millis_t maxInactiveTime = MAX_INACTIVE_TIME * 1000L;
millis_t stepperInactiveTime = STEPPER_INACTIVE_TIME * 1000L;
long baudrate = BAUDRATE; // Communication speed rate.
#if USE_ADVANCE
int maxadv2 = 0;
float maxadvspeed = 0;
volatile int waitRelax = 0; // Delay filament relax at the end of print, could be a simple timeout
#endif // USE_ADVANCE
uint8_t pwm_pos[NUM_EXTRUDER + 3]; // 0-NUM_EXTRUDER = Heater 0-NUM_EXTRUDER of extruder, NUM_EXTRUDER = Heated bed, NUM_EXTRUDER+1 Board fan, NUM_EXTRUDER+2 = Fan
uint8_t fanSpeed = 0;
PrintLine PrintLine::lines[MOVE_CACHE_SIZE]; // Cache for print moves.
PrintLine *PrintLine::cur = 0; // Current printing line
PrintLine PrintLine::direct; // direct movement
uint8_t PrintLine::linesWritePos = 0; // Position where we write the next cached line move.
volatile uint8_t PrintLine::linesCount = 0; // Number of lines cached 0 = nothing to do.
uint8_t PrintLine::linesPos = 0; // Position for executing line movement.
/** \brief Put a move to the current destination coordinates into the movement cache.
If the cache is full, the method will wait, until a place gets free. During
wait communication and temperature control is enabled.
@param abortAtEndstops Stop this move at any endstop during move.
Otherwise the endstop causes an ignore of moving that axis but coordinates will move
*/
void PrintLine::prepareQueueMove(uint8_t abortAtEndstops, uint8_t pathOptimize, float feedrate)
{
Printer::unmarkAllSteppersDisabled(); // ??? hier wird nichts enabled. Nur markiert, auch wenn später oder früher "enablestepper" passiert.
//evtl. weil dadurch in jedem fall gleich ein stepper aktiviert werden würde -> darum hier schon als aktiv markieren, weil umumgänglich ist.
// Aber dann müsste man das (timingsicher) auch schon in den Funktionen über prepareDirectMove erledigt haben.
PrintLine::waitForXFreeLines(1);
uint8_t newPath = PrintLine::insertWaitMovesIfNeeded(pathOptimize, 0);
PrintLine *p = PrintLine::getNextWriteLine();
p->task = TASK_NO_TASK;
p->flags = (abortAtEndstops ? FLAG_ABORT_AT_ENDSTOPS : 0);
p->joinFlags = 0;
p->dir = 0;
if (!pathOptimize) p->setEndSpeedFixed(true);
// Constrain Destinations to values we should be able to reach
for (uint8_t axis = 0; axis < E_AXIS; axis++)
{
float direct = Printer::getDirectMM(axis);
float endstop = Printer::maxSoftEndstopSteps[axis] * Printer::axisMMPerSteps[axis];
if (Printer::destinationMM[axis] + direct >= endstop + 0.1) {
Printer::destinationMM[axis] = (endstop + 0.1 - direct);
}
}
float axisDistanceMM[4]; // Axis movement in mm
// Find direction
bool isNoStepsMove = true;
for (uint8_t axis = 0; axis < 4; axis++)
{
//error zwischen soll und ist.
float axisDistanceUnscaledMM = Printer::destinationMM[axis] - Printer::destinationMMLast[axis];
if (axis == E_AXIS)
{
#if FEATURE_DIGIT_FLOW_COMPENSATION
float axisDistanceFactor = Printer::menuExtrusionFactor * Printer::dynamicExtrusionFactor;
#else
float axisDistanceFactor = Printer::menuExtrusionFactor;
#endif // FEATURE_DIGIT_FLOW_COMPENSATION
axisDistanceMM[E_AXIS] = axisDistanceUnscaledMM * axisDistanceFactor;
Printer::extrudeMultiplyErrorSteps += axisDistanceMM[E_AXIS] * Printer::axisStepsPerMM[E_AXIS];
p->delta[E_AXIS] = lroundf(Printer::extrudeMultiplyErrorSteps);
Printer::extrudeMultiplyErrorSteps -= p->delta[E_AXIS];
Printer::filamentPrinted += p->delta[E_AXIS] * Printer::axisMMPerSteps[E_AXIS];
Printer::destinationMMLast[E_AXIS] = Printer::destinationMM[E_AXIS];
}
else {
p->delta[axis] = lroundf(axisDistanceUnscaledMM * Printer::axisStepsPerMM[axis]);
axisDistanceMM[axis] = float(p->delta[axis]) * Printer::axisMMPerSteps[axis];
//Update calculated coordinate by move distance.
Printer::destinationMMLast[axis] += axisDistanceMM[axis];
}
if (axisDistanceMM[axis] >= 0) p->setPositiveDirectionForAxis(axis);
if (axisDistanceMM[axis] != 0) p->setMoveOfAxis(axis);
// remove the sign from all driving length
p->delta[axis] = abs(p->delta[axis]);
axisDistanceMM[axis] = fabs(axisDistanceMM[axis]);
// signal that we at least found some steps to queue in move cache
// The other option is, that we only summed up parts steps for a possible next move which are stored as rounding errors
if (p->delta[axis]) isNoStepsMove = false;
}
// need to delete dummy elements, otherwise commands can get locked.
if (isNoStepsMove)
{
if (newPath) PrintLine::resetPathPlanner();
// No steps included
return;
}
#if FEATURE_HEAT_BED_Z_COMPENSATION
// MAIN RULE:
/* IF there is an extrusion move
after a Z move
to different layer height than before
which is not 0
THEN
accept the z height value as new layer */
// The following two move conditions might not follow each other in one move but in serveral queued moves.
if (p->isZMove())
{
int32_t newZ = Printer::getDestinationSteps(Z_AXIS);
// Z achsen aufstieg/abstieg -> The ternary condition is there to filter out zlifts
Printer::queuePositionZLayerGuessNew = (newZ == Printer::queuePositionZLayerCurrent) ? 0 : newZ;
}
if (p->isEPositiveMove())
{
// We extrude. Do we have a new z layer height too?
if (Printer::queuePositionZLayerGuessNew) {
// It seems we have a new layer height, so shift layers down
// Set current layer as last layer.
Printer::queuePositionZLayerLast = Printer::queuePositionZLayerCurrent;
// Set new layer as current layer
Printer::queuePositionZLayerCurrent = Printer::queuePositionZLayerGuessNew;
// If the new layer ist underneath the old layer (near the bed)
// then this means we can assume the last-layer as 0 after some sort of startline.
// We need this info to possibly have senseoffset running again for sequential multipart prints
if (Printer::queuePositionZLayerLast > Printer::queuePositionZLayerCurrent) {
if (Printer::queuePositionZLayerCurrent < Printer::axisStepsPerMM[Z_AXIS]) { //1mm
Printer::queuePositionZLayerLast = 0;
}
}
// Problemfall Startmade: Wenn die Startmade aus etwas weniger als 16 od. MOVE_CACHE_SIZE Teilstücken besteht,
// was man annehmen kann, dann springt der Pfadplaner über die Startmade einfach drüber und nimmt den ersten Layer als neue Referenz.
// Das hier ist Preprocessing mit Blick in die Zukunft. Kurz steht in g_minZCompensationSteps z.B. 0.35, anschließend aber z.B. korrekte 0.2mm als g_minZCompensationSteps.
// würde das nicht klappen, hätten wir SenseOffset in der Startmade was maximal schlecht sein kann, weil evtl. die Digits zu hoch sind.
//-> Sollte mit dieser Automatik hier nicht vorkommen!
if (!Printer::queuePositionZLayerLast && Printer::queuePositionZLayerCurrent < Printer::axisStepsPerMM[Z_AXIS]) {
// < 1mm
//hiermit hätten wir immer exakt 1 Lage, die der Drucker komplett mit dem Bettprofil abfährt, anschließend ab Layer 2 wird ausgeschlichen +ECMP.
if (abs(Printer::queuePositionZLayerCurrent - Printer::axisStepsPerMM[Z_AXIS] * AUTOADJUST_STARTMADEN_AUSSCHLUSS) > 5 /* 2um um startmadenhöhe herum nichts tun */) {
g_minZCompensationSteps = Printer::queuePositionZLayerCurrent;
g_maxZCompensationSteps = g_minZCompensationSteps + (g_offsetZCompensationSteps - g_ZCompensationMax) * 20; //max zulässige kompensation pro lage: 1/20 = 5%
}
}
}
Printer::queuePositionZLayerGuessNew = 0;
}
#endif // FEATURE_HEAT_BED_Z_COMPENSATION
// Define variables that are needed for the Bresenham algorithm. Please note that Z is not currently included in the Bresenham algorithm.
if (p->delta[Y_AXIS] > p->delta[X_AXIS] && p->delta[Y_AXIS] > p->delta[Z_AXIS] && p->delta[Y_AXIS] > p->delta[E_AXIS])
p->primaryAxis = Y_AXIS;
else if (p->delta[X_AXIS] > p->delta[Z_AXIS] && p->delta[X_AXIS] > p->delta[E_AXIS])
p->primaryAxis = X_AXIS;
else if (p->delta[Z_AXIS] > p->delta[E_AXIS])
p->primaryAxis = Z_AXIS;
else
p->primaryAxis = E_AXIS;
p->stepsRemaining = p->delta[p->primaryAxis];
if (p->isXYZMove())
{
float xydist2 = axisDistanceMM[X_AXIS] * axisDistanceMM[X_AXIS] + axisDistanceMM[Y_AXIS] * axisDistanceMM[Y_AXIS];
if (p->isZMove())
p->distance = RMath::max((float)sqrt(xydist2 + axisDistanceMM[Z_AXIS] * axisDistanceMM[Z_AXIS]), axisDistanceMM[E_AXIS]);
else
p->distance = RMath::max((float)sqrt(xydist2), axisDistanceMM[E_AXIS]);
}
else
{
p->distance = axisDistanceMM[E_AXIS];
}
p->calculateMove(axisDistanceMM, p->primaryAxis, feedrate);
updateTrapezoids();
#if USE_ADVANCE
if (pathOptimize) waitRelax = 70;
#endif // USE_ADVANCE
// Make result permanent
pushLine();
} // prepareQueueMove
void PrintLine::prepareDirectMove(bool stoppable, bool feedrateSource)
{
if (direct.task) {
// Do not overwrite a running directstep process.
// If we return here the steps still might be processed as slow direct-stepping.
// Rework your code if you see this happening.
return;
}
direct.block();
direct.task = DIRECT_PREPARING;
direct.flags = FLAG_ABORT_AT_ENDSTOPS;
direct.joinFlags = 0;
direct.setEndSpeedFixed(true);
direct.dir = 0;
// Find direction
float axisDistanceMM[4]; // Axis movement in mm
for (uint8_t axis = 0; axis < 4; axis++)
{
direct.delta[axis] = Printer::directDestinationSteps[axis] - Printer::directCurrentSteps[axis];
// no special extrusion handling. this direct drive is only for manual move and button feed. no precision needed.
if (direct.delta[axis] >= 0)
direct.setPositiveDirectionForAxis(axis);
else
direct.delta[axis] = -direct.delta[axis];
axisDistanceMM[axis] = fabs(direct.delta[axis] * Printer::axisMMPerSteps[axis]);
if (direct.delta[axis]) direct.setMoveOfAxis(axis);
}
if (direct.isNoMove())
{
direct.stepsRemaining = 0;
direct.unblock();
direct.task = TASK_NO_TASK;
return; // No steps included
}
// Define variables that are needed for the Bresenham algorithm. Please note that Z is not currently included in the Bresenham algorithm.
if (direct.delta[Y_AXIS] > direct.delta[X_AXIS] && direct.delta[Y_AXIS] > direct.delta[Z_AXIS] && direct.delta[Y_AXIS] > direct.delta[E_AXIS])
direct.primaryAxis = Y_AXIS;
else if (direct.delta[X_AXIS] > direct.delta[Z_AXIS] && direct.delta[X_AXIS] > direct.delta[E_AXIS])
direct.primaryAxis = X_AXIS;
else if (direct.delta[Z_AXIS] > direct.delta[E_AXIS])
direct.primaryAxis = Z_AXIS;
else
direct.primaryAxis = E_AXIS;
if (direct.isXYZMove())
{
float xydist2 = axisDistanceMM[X_AXIS] * axisDistanceMM[X_AXIS] + axisDistanceMM[Y_AXIS] * axisDistanceMM[Y_AXIS];
if (direct.isZMove())
direct.distance = RMath::max((float)sqrt(xydist2 + axisDistanceMM[Z_AXIS] * axisDistanceMM[Z_AXIS]), axisDistanceMM[E_AXIS]);
else
direct.distance = RMath::max((float)sqrt(xydist2), axisDistanceMM[E_AXIS]);
}
else
direct.distance = axisDistanceMM[E_AXIS];
direct.stepsRemaining = direct.delta[direct.primaryAxis];
float feedrate = (direct.isXOrYMove() ? STANDARD_POSITION_FEEDRATE_XY : direct.isZMove() ? STANDARD_POSITION_FEEDRATE_Z : STANDARD_POSITION_FEEDRATE_E);
if (feedrateSource == FEEDRATE_GCODE) {
feedrate = Printer::feedrate;
// Menu positioning means only one axis moves at once. Hoever this is not valid for continue moves etc. but they should not have gcode feedrates at all.
if (direct.isZMove() && feedrate > STANDARD_POSITION_FEEDRATE_Z) {
feedrate = STANDARD_POSITION_FEEDRATE_Z;
}
}
direct.calculateMove(axisDistanceMM, direct.primaryAxis, feedrate);
direct.unblock();
direct.task = (stoppable ? DIRECT_PREPARED_STOPPABLE : DIRECT_PREPARED);
} // prepareDirectMove
void PrintLine::stopDirectMove(void) //Funktion ist bereits zur ausführzeit von InterruptProtectedBlock eingeschlossen!
{
if (PrintLine::direct.isXYZMove())
{
// decelerate and stop
if (PrintLine::direct.stepsRemaining > 32) //die genaue anzahl der Decelerate Steps sollte hier eigentlich fast egal sein. Besser evtl. die Microsteps der Hauptachse?
{
PrintLine::direct.stepsRemaining = 32;
}
}
return;
} // stopDirectMove
void PrintLine::calculateMove(float axisDistanceMM[], fast8_t drivingAxis, float feedrate)
{
if (stepsRemaining == 0) { // need at least one step for bresenham
return;
}
float timeForMove = (float)(F_CPU)* distance / feedrate; // time is in ticks
// Small element limiter: This was not present in directmove but is not harmfull.
if (linesCount < MOVE_CACHE_LOW && timeForMove < LOW_TICKS_PER_MOVE) // Limit speed to keep cache full.
{
timeForMove += ((LOW_TICKS_PER_MOVE - timeForMove)) * 3 / (linesCount + 1); // Increase time if queue gets empty. Add more time if queue gets smaller.
}
timeInTicks = timeForMove;
// Compute the solwest allowed interval (ticks/step), so maximum feedrate is not violated
int32_t limitInterval0;
int32_t limitInterval = limitInterval0 = timeForMove / stepsRemaining; // until not violated by other constraints it is your target speed
float toTicks = static_cast<float>(F_CPU) / stepsRemaining;
int32_t axisInterval[4];
if (isXMove())
{
axisInterval[X_AXIS] = axisDistanceMM[X_AXIS] * toTicks / (Printer::maxFeedrate[X_AXIS]); // mm*ticks/s/(mm/s*steps) = ticks/step
limitInterval = RMath::max(axisInterval[X_AXIS], limitInterval);
}
else axisInterval[X_AXIS] = 0;
if (isYMove())
{
axisInterval[Y_AXIS] = axisDistanceMM[Y_AXIS] * toTicks / Printer::maxFeedrate[Y_AXIS];
limitInterval = RMath::max(axisInterval[Y_AXIS], limitInterval);
}
else axisInterval[Y_AXIS] = 0;
if (isZMove()) // normally no move in z direction
{
axisInterval[Z_AXIS] = axisDistanceMM[Z_AXIS] * toTicks / Printer::maxFeedrate[Z_AXIS]; // must prevent overflow!
limitInterval = RMath::max(axisInterval[Z_AXIS], limitInterval);
}
else axisInterval[Z_AXIS] = 0;
if (isEMove())
{
axisInterval[E_AXIS] = axisDistanceMM[E_AXIS] * toTicks / Printer::maxFeedrate[E_AXIS];
limitInterval = RMath::max(axisInterval[E_AXIS], limitInterval);
}
else axisInterval[E_AXIS] = 0;
ticks_t fullIntervalb = limitInterval = (limitInterval > LIMIT_INTERVAL ? limitInterval : LIMIT_INTERVAL); // This is our target speed
if (limitInterval != limitInterval0) {
// new time at full speed = limitInterval*p->stepsRemaining [ticks]
timeForMove = (float)limitInterval * (float)stepsRemaining; // for large z-distance this overflows with long computation
}
float inverseTimeS = static_cast<float>(F_CPU) / timeForMove;
if (isXMove())
{
axisInterval[X_AXIS] = static_cast<int32_t>(timeForMove / (axisDistanceMM[X_AXIS] * Printer::axisStepsPerMM[X_AXIS]));
speedX = axisDistanceMM[X_AXIS] * inverseTimeS;
if (isXNegativeMove()) speedX = -speedX;
}
else speedX = 0;
if (isYMove())
{
axisInterval[Y_AXIS] = static_cast<int32_t>(timeForMove / (axisDistanceMM[Y_AXIS] * Printer::axisStepsPerMM[Y_AXIS]));
speedY = axisDistanceMM[Y_AXIS] * inverseTimeS;
if (isYNegativeMove()) speedY = -speedY;
}
else speedY = 0;
if (isZMove())
{
axisInterval[Z_AXIS] = static_cast<int32_t>(timeForMove / (axisDistanceMM[Z_AXIS] * Printer::axisStepsPerMM[Z_AXIS]));
speedZ = axisDistanceMM[Z_AXIS] * inverseTimeS;
if (isZNegativeMove()) speedZ = -speedZ;
}
else speedZ = 0;
if (isEMove())
{
axisInterval[E_AXIS] = static_cast<int32_t>(timeForMove / (axisDistanceMM[E_AXIS] * Printer::axisStepsPerMM[E_AXIS]));
speedE = axisDistanceMM[E_AXIS] * inverseTimeS;
if (isENegativeMove()) speedE = -speedE;
}
else speedE = 0;
fullSpeed = distance * inverseTimeS;
// long interval = axis_interval[primary_axis]; // time for every step in ticks with full speed
// If acceleration is enabled, do some Bresenham calculations depending on which axis will lead it.
// slowest time to accelerate from v0 to limitInterval determines used acceleration
// t = (v_end-v_start)/a
float slowestAxisPlateauTimeRepro = 1e15; // repro to reduce division Unit: 1/s
uint32_t* accel = (isEPositiveMove() ? Printer::maxPrintAccelerationStepsPerSquareSecond : Printer::maxTravelAccelerationStepsPerSquareSecond);
for (uint8_t axis = 0; axis < 4; axis++)
{
if (isMoveOfAxis(axis))
{
// v = a * t => t = v/a = F_CPU/(c*a) => 1/t = c*a/F_CPU
slowestAxisPlateauTimeRepro = RMath::min(slowestAxisPlateauTimeRepro, (float)axisInterval[axis] * (float)accel[axis]); // steps/s^2 * step/tick Ticks/s^2
}
}
// Errors for delta move are initialized in timer (except extruder)
error[X_AXIS] = error[Y_AXIS] = error[Z_AXIS] = delta[primaryAxis] >> 1;
invFullSpeed = 1.0 / fullSpeed;
accelerationPrim = slowestAxisPlateauTimeRepro / axisInterval[primaryAxis]; // a = v/t = F_CPU/(c*t): Steps/s^2
// Now we can calculate the new primary axis acceleration, so that the slowest axis max acceleration is not violated
// Im Interrupt steht quasi die Formel v = a * t / 2^18, darum hier die 262144
fAcceleration = 262144.0*(float)accelerationPrim / F_CPU; // will overflow without float!
accelerationDistance2 = 2.0 * distance * slowestAxisPlateauTimeRepro * fullSpeed / ((float)F_CPU); // mm^2/s^2
startSpeed = endSpeed = minSpeed = safeSpeed(drivingAxis);
if (startSpeed > feedrate) {
startSpeed = endSpeed = minSpeed = feedrate;
}
// Can accelerate to full speed within the line
if (startSpeed * startSpeed + accelerationDistance2 >= fullSpeed * fullSpeed)
setNominalMove();
vMax = F_CPU / fullIntervalb; // maximum steps per second, we can reach
// if(p->vMax>46000) // gets overflow in N computation
// p->vMax = 46000;
// p->plateauN = (p->vMax*p->vMax/p->accelerationPrim)>>1;
#if USE_ADVANCE
if (!isXYZMove() || !isEPositiveMove()) { // No head move or E move only or sucking filament back
advanceL = 0;
}
else
{
float advlin = fabs(speedE) * Extruder::current->advanceL * 0.001 * Printer::axisStepsPerMM[E_AXIS];
advanceL = ((65536L * advlin) / vMax); //advanceLscaled = (65536*vE*k2)/vMax
if (advlin > maxadv2) {
maxadv2 = advlin;
maxadvspeed = fabs(speedE);
}
}
#endif // USE_ADVANCE
DEBUG_MEMORY;
} // calculateMove
/** \brief
This is the path planner.
It goes from the last entry and tries to increase the end speed of previous moves in a fashion that the maximum jerk
is never exceeded. If a segment with reached maximum speed is met, the planner stops. Everything left from this
is already optimal from previous updates.
The first 2 entries in the queue are not checked. The first is the one that is already in print and the following will likely become active.
The method is called before linesCount is increased!
*/
void PrintLine::updateTrapezoids()
{
uint8_t first = linesWritePos;
PrintLine *firstLine;
PrintLine *act = &lines[linesWritePos];
InterruptProtectedBlock noInts; //BEGIN_INTERRUPT_PROTECTED;
// First we find out how far back we could go with optimization.
uint8_t maxfirst = linesPos; // first non fixed segment
if (maxfirst != linesWritePos)
{
nextPlannerIndex(maxfirst); // don't touch the line printing
}
// Now ignore enough segments to gain enough time for path planning
millis_t timeleft = 0;
// Skip as many stored moves as needed to gain enough time for computation
//millis_t minTime = 4500L * RMath::min(MOVE_CACHE_SIZE,10);
#if MOVE_CACHE_SIZE < 10
#define minTime 4500L * MOVE_CACHE_SIZE
#else
#define minTime 45000L
#endif
while (timeleft < minTime && maxfirst != linesWritePos)
{
timeleft += lines[maxfirst].timeInTicks;
nextPlannerIndex(maxfirst);
}
// Search last fixed element
while (first != maxfirst && !lines[first].isEndSpeedFixed())
previousPlannerIndex(first);
if (first != linesWritePos && lines[first].isEndSpeedFixed())
nextPlannerIndex(first);
// now first points to last segment before the end speed is fixed
// so start speed is also fixed.
if (first == linesWritePos) // Nothing to plan
{
act->block(); // Prevent stepper interrupt from using this
noInts.unprotect(); //ESCAPE_INTERRUPT_PROTECTED
act->setStartSpeedFixed(true);
act->updateStepsParameter();
act->unblock();
return;
}
/** \brief now we have at least one additional move for optimization
that is not a wait move
First is now the new element or the first element with non fixed end speed.
anyhow, the start speed of first is fixed */
firstLine = &lines[first];
firstLine->block(); // don't let printer touch this or following segments during update
noInts.unprotect(); //END_INTERRUPT_PROTECTED;
uint8_t previousIndex = linesWritePos;
previousPlannerIndex(previousIndex);
PrintLine *previous = &lines[previousIndex];
// filters z-move<->not z-move //Nibbels: Test if this is better with our type of Z-Comp because of bad edges? See https://github.com/repetier/Repetier-Firmware/commit/5fbe3748a0ca55386d5315d5b44c4209bec62fc2#diff-593812a66d7348c87b711b15b1ad5195L696
/*
if((previous->primaryAxis == Z_AXIS && act->primaryAxis != Z_AXIS) || (previous->primaryAxis != Z_AXIS && act->primaryAxis == Z_AXIS))
{
previous->setEndSpeedFixed(true);
act->setStartSpeedFixed(true);
act->updateStepsParameter();
firstLine->unblock();
return;
}
*/
//Retract:
if (previous->isEOnlyMove() != act->isEOnlyMove())
{
previous->setEndSpeedFixed(true);
act->setStartSpeedFixed(true);
act->updateStepsParameter();
firstLine->unblock();
return;
}
#if USE_ADVANCE
/**
* If we start/stop extrusion we need to do so with lowest possible end speed
* or advance would leave a drolling extruder and can not adjust fast enough.
*
* https://github.com/repetier/Repetier-Firmware/issues/837
* This exception rule is here for a reason:
* Case I want to catch is fast travel move and then start with a high extrusion speed.
* That means if angle is flat you will start with high extrusion speed and need to build up extruder pressure at an instance.
* So here starting at lower speed makes adding advance steps easy.
*/
if (Printer::isAdvanceActivated() && previous->isEMove() != act->isEMove())
{
previous->setEndSpeedFixed(true);
act->setStartSpeedFixed(true);
act->updateStepsParameter();
firstLine->unblock();
return;
}
#endif // USE_ADVANCE
// Set maximum junction speed if we have a real move before
computeMaxJunctionSpeed(previous, act);
// Increase speed if possible neglecting current speed
backwardPlanner(linesWritePos, first);
// Reduce speed to reachable speeds
forwardPlanner(first);
// Update precomputed data
do
{
lines[first].updateStepsParameter();
//noInts.protect(); //BEGIN_INTERRUPT_PROTECTED;
lines[first].unblock(); // start with first block to release next used segment as early as possible
nextPlannerIndex(first);
lines[first].block();
//noInts.unprotect(); //END_INTERRUPT_PROTECTED;
} while (first != linesWritePos);
act->updateStepsParameter();
act->unblock();
} // updateTrapezoids
/* Computes the maximum junction speed of the newly added segment under
optimal conditions. There is no guarantee that the previous move will be able to reach the
speed at all, but if it could exceed it will never exceed this theoretical limit.
if you define ALTERNATIVE_JERK the new jerk computations are used. These
use the cosine of the angle and the maximum speed
Jerk = (1-cos(alpha))*min(v1,v2)
This sets jerk to 0 on zero angle change.
Old New
0°: 0 0
30°: 51,8 13.4
45°: 76.53 29.3
90°: 141 100
180°: 200 200
Speed from 100 to 200
Old New(min) New(max)
0°: 100 0 0
30°: 123,9 13.4 26.8
45°: 147.3 29.3 58.6
90°: 223 100 200
180°: 300 200 400
*/
inline void PrintLine::computeMaxJunctionSpeed(PrintLine *previous, PrintLine *current)
{
// if we are here we have two identical move types
// either pure extrusion -> pure extrusion or
// move -> move (with or without extrusion)
// First we compute the normalized jerk for speed 1
float factor = 1.0;
float lengthFactor = 1.0;
#if REDUCE_ON_SMALL_SEGMENTS
if (previous->distance < MAX_JERK_DISTANCE)
lengthFactor = static_cast<float>(MAX_JERK_DISTANCE * MAX_JERK_DISTANCE) / (previous->distance * previous->distance);
#endif
float maxJoinSpeed = RMath::min(current->fullSpeed, previous->fullSpeed);
#if ALTERNATIVE_JERK
float calculatedJerk = maxJoinSpeed * lengthFactor * (1.0 - (current->speedX * previous->speedX + current->speedY * previous->speedY + current->speedZ * previous->speedZ) / (current->fullSpeed * previous->fullSpeed));
#else
float dx = current->speedX - previous->speedX;
float dy = current->speedY - previous->speedY;
float calculatedJerk = sqrt(dx * dx + dy * dy) * lengthFactor;
#endif // ALTERNATIVE_JERK
if (calculatedJerk > Printer::maxXYJerk) {
factor = Printer::maxXYJerk / calculatedJerk; // always < 1.0!
if (factor * maxJoinSpeed * 2.0 < Printer::maxXYJerk)
factor = Printer::maxXYJerk / (2.0 * maxJoinSpeed);
}
if ((previous->dir | current->dir) & 64 /* previous zmove oder current zmove */) {
float zJerk = fabs(current->speedZ - previous->speedZ);
if (zJerk > Printer::maxZJerk)
factor = RMath::min(factor, Printer::maxZJerk / zJerk);
}
float eJerk = fabs(current->speedE - previous->speedE);
if (eJerk > Extruder::current->maxEJerk) {
factor = RMath::min(factor, Extruder::current->maxEJerk / eJerk);
}
previous->maxJunctionSpeed = maxJoinSpeed * factor; // set speed limit
} // computeMaxJunctionSpeed
/** \brief Update parameter used by updateTrapezoids
Computes the acceleration/deceleration steps and advanced parameter associated.
*/
void PrintLine::updateStepsParameter()
{
if (areParameterUpToDate() || isWarmUp()) return;
float startFactor = startSpeed * invFullSpeed;
float endFactor = endSpeed * invFullSpeed;
vStart = vMax * startFactor; // starting speed
vEnd = vMax * endFactor;
uint32_t vmax2 = HAL::U16SquaredToU32(vMax);
if (vStart == vMax) {
accelSteps = 0;
}
else {
accelSteps = ((vmax2 - HAL::U16SquaredToU32(vStart)) / (accelerationPrim << 1)) + 1; // Always add 1 for missing precision
}
if (vEnd == vMax) {
decelSteps = 0;
}
else {
decelSteps = ((vmax2 - HAL::U16SquaredToU32(vEnd)) / (accelerationPrim << 1)) + 1;
}
if (static_cast<int32_t>(accelSteps + decelSteps) > stepsRemaining) // can't reach limit speed
{
uint32_t red = (accelSteps + decelSteps - stepsRemaining) >> 1;
accelSteps = accelSteps - RMath::min(static_cast<int32_t>(accelSteps), static_cast<int32_t>(red));
decelSteps = decelSteps - RMath::min(static_cast<int32_t>(decelSteps), static_cast<int32_t>(red));
}
setParameterUpToDate();
} // updateStepsParameter
/** \brief
Compute the maximum speed from the last entered move.
The backwards planner traverses the moves from last to first looking at deceleration. The RHS of the accelerate/decelerate ramp.
start = last line inserted
last = last element until we check
*/
inline void PrintLine::backwardPlanner(uint8_t start, uint8_t last)
{
PrintLine *act = &lines[start], *previous;
float lastJunctionSpeed = act->endSpeed; // Start always with safe speed
while (start != last)
{
previousPlannerIndex(start);
previous = &lines[start];
previous->block();
// Avoid speed calculate once cruising in split delta move
// Avoid speed calculate if we know we can accelerate within the line
lastJunctionSpeed = (act->isNominalMove() ? act->fullSpeed : sqrt(lastJunctionSpeed * lastJunctionSpeed + act->accelerationDistance2)); // acceleration is acceleration*distance*2! What can be reached if we try?
// If that speed is more that the maximum junction speed allowed then ...
if (lastJunctionSpeed >= previous->maxJunctionSpeed) // Limit is reached
{
// If the previous line's end speed has not been updated to maximum speed then do it now
if (previous->endSpeed != previous->maxJunctionSpeed)
{
previous->invalidateParameter(); // Needs recomputation
previous->endSpeed = RMath::max(previous->minSpeed, previous->maxJunctionSpeed); // possibly unneeded???
}
// If actual line start speed has not been updated to maximum speed then do it now
if (act->startSpeed != previous->maxJunctionSpeed)
{
act->startSpeed = RMath::max(act->minSpeed, previous->maxJunctionSpeed); // possibly unneeded???
act->invalidateParameter();
}
lastJunctionSpeed = previous->endSpeed;
}
else
{
// Block prev end and act start as calculated speed and recalculate plateau speeds (which could move the speed higher again)
act->startSpeed = RMath::max(act->minSpeed, lastJunctionSpeed);
lastJunctionSpeed = previous->endSpeed = RMath::max(lastJunctionSpeed, previous->minSpeed);
previous->invalidateParameter();
act->invalidateParameter();
}
act = previous;
} // while loop
} // backwardPlanner
void PrintLine::forwardPlanner(uint8_t first)
{
PrintLine *act;
PrintLine *next = &lines[first];
float vmaxRight;
float leftSpeed = next->startSpeed;
while (first != linesWritePos) // All except last segment, which has fixed end speed
{
act = next;
nextPlannerIndex(first);
next = &lines[first];
// Avoid speed calculate if we know we can accelerate within the line.
vmaxRight = (act->isNominalMove() ? act->fullSpeed : sqrt(leftSpeed * leftSpeed + act->accelerationDistance2));
if (vmaxRight > act->endSpeed) // Could be higher next run?
{
if (leftSpeed < act->minSpeed)
{
leftSpeed = act->minSpeed;
act->endSpeed = sqrt(leftSpeed * leftSpeed + act->accelerationDistance2);
}
act->startSpeed = leftSpeed;
next->startSpeed = leftSpeed = RMath::max(RMath::min(act->endSpeed, act->maxJunctionSpeed), next->minSpeed);
if (act->endSpeed == act->maxJunctionSpeed) // Full speed reached, don't compute again!
{
act->setEndSpeedFixed(true);
next->setStartSpeedFixed(true);
}
act->invalidateParameter();
}
else // We can accelerate full speed without reaching limit, which is as fast as possible. Fix it!
{
act->fixStartAndEndSpeed();
act->invalidateParameter();
if (act->minSpeed > leftSpeed)
{
leftSpeed = act->minSpeed;
vmaxRight = sqrt(leftSpeed * leftSpeed + act->accelerationDistance2);
}
act->startSpeed = leftSpeed;
act->endSpeed = RMath::max(act->minSpeed, vmaxRight);
next->startSpeed = leftSpeed = RMath::max(RMath::min(act->endSpeed, act->maxJunctionSpeed), next->minSpeed);
next->setStartSpeedFixed(true);
}
} // While
next->startSpeed = RMath::max(next->minSpeed, leftSpeed); // This is the new segment, wgich is updated anyway, no extra flag needed.
} // forwardPlanner
inline float PrintLine::safeSpeed(fast8_t drivingAxis)
{
float xyMin = Printer::maxXYJerk * 0.5f;
float mz = 0;
float safe(xyMin);
if (isZMove()) {
mz = Printer::maxZJerk * 0.5f;
if (isXOrYMove()) {
if (fabs(speedZ) > mz)
safe = RMath::min(safe, mz * fullSpeed / fabs(speedZ));
}
else {
safe = mz;
}
}
if (isEMove()) {
if (isXYZMove())
safe = RMath::min(safe, 0.5f * Extruder::current->maxEJerk * fullSpeed / fabs(speedE));
else
safe = 0.5f * Extruder::current->maxEJerk; // This is a retraction move
}
// enforce minimum speed for numerical stability of explicit speed integration
if (drivingAxis == X_AXIS || drivingAxis == Y_AXIS) safe = RMath::max(xyMin, safe);
else if (drivingAxis == Z_AXIS) safe = RMath::max(mz, safe);
return RMath::min(safe, fullSpeed);
} // safeSpeed
/** \brief Check if move is new. If it is insert some dummy moves to allow the path optimizer to work since it does
not act on the first two moves in the queue. The stepper timer will spot these moves and leave some time for
processing.
*/
uint8_t PrintLine::insertWaitMovesIfNeeded(uint8_t pathOptimize, uint8_t waitExtraLines)
{
if (linesCount == 0
#if USE_ADVANCE
&& waitRelax == 0
#endif // USE_ADVANCE
&& pathOptimize) // First line after some time - warmup needed
{
uint8_t w = 4;
while (w--)
{
PrintLine *p = getNextWriteLine();
p->flags = FLAG_WARMUP;
p->joinFlags = FLAG_JOIN_STEPPARAMS_COMPUTED | FLAG_JOIN_END_FIXED | FLAG_JOIN_START_FIXED;
p->dir = 0;
p->setWaitForXLinesFilled(w + waitExtraLines);
p->setWaitTicks(100000); //repetier changed this from 25k to 100k in https://github.com/repetier/Repetier-Firmware/commit/2385051856278c189d7c1f1fd67acc27825c82ac#diff-11347f18746fb080f5bda21c30428558R1080
pushLine();
}
return 1;
}
return 0;
} // insertWaitMovesIfNeeded
void PrintLine::waitForXFreeLines(uint8_t b)
{
while (getLinesCount() + b > MOVE_CACHE_SIZE) // wait for a free entry in movement cache
{
Commands::checkForPeriodicalActions(Processing);
}
} // waitForXFreeLines
#if FEATURE_ARC_SUPPORT
// Arc function taken from grbl
// The arc is approximated by generating a huge number of tiny, linear segments. The length of each
// segment is configured in settings.mm_per_arc_segment.
void PrintLine::arc(float *position, float *target, float *offset, float radius, uint8_t isclockwise) {
// int acceleration_manager_was_enabled = plan_is_acceleration_manager_enabled();
// plan_set_acceleration_manager_enabled(false); // disable acceleration management for the duration of the arc
float center_axis0 = position[X_AXIS] + offset[X_AXIS];
float center_axis1 = position[Y_AXIS] + offset[Y_AXIS];
//float linear_travel = 0; //target[axis_linear] - position[axis_linear];
float extruder_travel = target[E_AXIS] - position[E_AXIS]; //das kann nicht anders sein, als dass man die extrusion im gcode angibt. man muss vorher verindern, dass in der G3 funktion direkt extrudiert wird.
//float extruder_travel = (Printer::destinationSteps[E_AXIS] - Printer::currentPositionSteps[E_AXIS]) * Printer::invAxisStepsPerMM[E_AXIS];
float r_axis0 = -offset[0]; // Radius vector from center to current location
float r_axis1 = -offset[1];
float rt_axis0 = target[0] - center_axis0;
float rt_axis1 = target[1] - center_axis1;
/*long xtarget = Printer::destinationSteps[X_AXIS];
long ytarget = Printer::destinationSteps[Y_AXIS];
long ztarget = Printer::destinationSteps[Z_AXIS];
long etarget = Printer::destinationSteps[E_AXIS];
*/
// CCW angle between position and target from circle center. Only one atan2() trig computation required.
float angular_travel = atan2(r_axis0 * rt_axis1 - r_axis1 * rt_axis0, r_axis0 * rt_axis0 + r_axis1 * rt_axis1);
if ((!isclockwise && angular_travel <= 0.00001) || (isclockwise && angular_travel < -0.000001)) {
angular_travel += 2.0f * M_PI;
}
if (isclockwise) {
angular_travel -= 2.0f * M_PI;
}
float millimeters_of_travel = fabs(angular_travel) * radius; //hypot(angular_travel*radius, fabs(linear_travel));
if (millimeters_of_travel < 0.001f) {
return;// treat as succes because there is nothing to do;
}
//uint16_t segments = (radius>=BIG_ARC_RADIUS ? floor(millimeters_of_travel/MM_PER_ARC_SEGMENT_BIG) : floor(millimeters_of_travel/MM_PER_ARC_SEGMENT));
// Increase segment size if printing faster then computation speed allows
uint16_t segments = (Printer::feedrate > 60.0f ? floor(millimeters_of_travel / RMath::min(static_cast<float>(MM_PER_ARC_SEGMENT_BIG), Printer::feedrate * 0.01666f * static_cast<float>(MM_PER_ARC_SEGMENT))) : floor(millimeters_of_travel / static_cast<float>(MM_PER_ARC_SEGMENT)));
if (segments == 0) segments = 1;
/*
// Multiply inverse feed_rate to compensate for the fact that this movement is approximated
// by a number of discrete segments. The inverse feed_rate should be correct for the sum of
// all segments.
if (invert_feed_rate) { feed_rate *= segments; }
*/
float theta_per_segment = angular_travel / segments;
//float linear_per_segment = linear_travel/segments;
float extruder_per_segment = extruder_travel / segments;
/* Vector rotation by transformation matrix: r is the original vector, r_T is the rotated vector,
and phi is the angle of rotation. Based on the solution approach by Jens Geisler.
r_T = [cos(phi) -sin(phi);
sin(phi) cos(phi] * r ;
For arc generation, the center of the circle is the axis of rotation and the radius vector is
defined from the circle center to the initial position. Each line segment is formed by successive
vector rotations. This requires only two cos() and sin() computations to form the rotation
matrix for the duration of the entire arc. Error may accumulate from numerical round-off, since
all double numbers are single precision on the Arduino. (True double precision will not have
round off issues for CNC applications.) Single precision error can accumulate to be greater than
tool precision in some cases. Therefore, arc path correction is implemented.
Small angle approximation may be used to reduce computation overhead further. This approximation
holds for everything, but very small circles and large mm_per_arc_segment values. In other words,
theta_per_segment would need to be greater than 0.1 rad and N_ARC_CORRECTION would need to be large
to cause an appreciable drift error. N_ARC_CORRECTION~=25 is more than small enough to correct for
numerical drift error. N_ARC_CORRECTION may be on the order a hundred(s) before error becomes an
issue for CNC machines with the single precision Arduino calculations.
This approximation also allows mc_arc to immediately insert a line segment into the planner
without the initial overhead of computing cos() or sin(). By the time the arc needs to be applied
a correction, the planner should have caught up to the lag caused by the initial mc_arc overhead.
This is important when there are successive arc motions.
*/
// Vector rotation matrix values
float cos_T = 1 - 0.5 * theta_per_segment * theta_per_segment; // Small angle approximation
float sin_T = theta_per_segment;
float arc_target[4];
float sin_Ti;
float cos_Ti;
float r_axisi;
uint16_t i;
int8_t count = 0;
// Initialize the linear axis
//arc_target[axis_linear] = position[axis_linear];
// Initialize the extruder axis
arc_target[E_AXIS] = Printer::destinationMM[E_AXIS];
//arc_target[E_AXIS] = Printer::currentPositionSteps[E_AXIS] * Printer::invAxisStepsPerMM[E_AXIS];
for (i = 1; i < segments; i++) {
// Increment (segments-1)