-
Notifications
You must be signed in to change notification settings - Fork 583
Expand file tree
/
Copy pathMove.cpp
More file actions
3559 lines (3210 loc) · 123 KB
/
Move.cpp
File metadata and controls
3559 lines (3210 loc) · 123 KB
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
/*
* Move.cpp
*
* Created on: 7 Dec 2014
* Author: David
A note on bed levelling:
As at version 1.21 we support two types of bed compensation:
1. The old 3, 4 and 5-point compensation using a RandomProbePointSet. We will probably discontinue this soon.
2. Mesh bed levelling
There is an interaction between using G30 to home Z or set a precise Z=0 height just before a print, and bed compensation.
Consider the following sequence:
1. Home Z, using either G30 or an endstop.
2. Run G29 to generate a height map. If the Z=0 point has drifted off, the height map may have a Z offset.
3. Use G30 to get an accurate Z=0 point. We want to keep the shape of the height map, but get rid of the offset.
4. Run G29 to generate a height map. This should generate a height map with on offset at the point we just probed.
5. Cancel bed compensation. The height at the point we just probed should be zero.
So as well as maintaining a height map, we maintain a Z offset from it. The procedure is:
1. Whenever bed compensation is not being used, the Z offset should be zero.
2. Whenever we run G29 to probe the bed, we have a choice:
(a) accept that the map may have a height offset; and set the Z offset to zero. This is what we do currently.
(b) normalise the height map to zero, adjust the Z=0 origin, and set the Z offset to zero.
3. When we run G30 to reset the Z=0 height, and we have a height map loaded, we adjust the Z offset to be the negative of the
height map indication of that point.
4. If we now cancel the height map, we also clear the Z offset, and the height at the point we probed remains correct.
5. If we now run G29 to probe again, the height map should have near zero offset at the point we probed, if there has been no drift.
Before we introduced the Z offset, at step 4 we would have a potentially large Z error as if the G30 hadn't been run,
and at step 5 the new height map would have an offset again.
*/
#include "Move.h"
#include "MoveDebugFlags.h"
#include "StepTimer.h"
#include <Platform/Platform.h>
#include <Platform/Event.h>
#include <GCodes/GCodes.h>
#include <GCodes/GCodeBuffer/GCodeBuffer.h>
#include <Tools/Tool.h>
#include <Endstops/ZProbe.h>
#include <Platform/TaskPriorities.h>
#include <AppNotifyIndices.h>
#include "StepperDrivers/SmartDrivers.h"
#if SUPPORT_IOBITS
# include <Platform/PortControl.h>
#endif
#if SUPPORT_CAN_EXPANSION
# include <CAN/CanMotion.h>
# include <CAN/CanInterface.h>
#endif
#ifdef DUET3_MB6XD
# include <pmc/pmc.h>
#endif
#include <limits>
constexpr float MinStepPulseTiming = 0.2; // we assume that we always generate step high and low times at least this wide without special action
Task<Move::MoveTaskStackWords> Move::moveTask;
// Object model table and functions
// Note: if using GCC version 7.3.1 20180622 and lambda functions are used in this table, you must compile this file with option -std=gnu++17.
// Otherwise the table will be allocated in RAM instead of flash, which wastes too much RAM.
// Macro to build a standard lambda function that includes the necessary type conversions
#define OBJECT_MODEL_FUNC(...) OBJECT_MODEL_FUNC_BODY(Move, __VA_ARGS__)
#define OBJECT_MODEL_FUNC_IF(_condition, ...) OBJECT_MODEL_FUNC_IF_BODY(Move, _condition, __VA_ARGS__)
#define OBJECT_MODEL_ARRAY_COUNT(_value) OBJECT_MODEL_ARRAY_COUNT_BODY(Move, _value)
#define OBJECT_MODEL_ARRAY_VALUE(...) OBJECT_MODEL_ARRAY_VALUE_BODY(Move, __VA_ARGS__)
constexpr ObjectModelArrayTableEntry Move::objectModelArrayTable[] =
{
// 0. Axes
{
nullptr, // no lock needed
OBJECT_MODEL_ARRAY_COUNT_NOSELF(reprap.GetGCodes().GetTotalAxes()),
OBJECT_MODEL_ARRAY_VALUE(self, 9)
},
// 1. Extruders
{
nullptr, // no lock needed
OBJECT_MODEL_ARRAY_COUNT_NOSELF(reprap.GetGCodes().GetNumExtruders()),
OBJECT_MODEL_ARRAY_VALUE(self, 10)
},
// 2. Motion system queues
{
nullptr, // no lock needed
OBJECT_MODEL_ARRAY_COUNT_NOSELF(ARRAY_SIZE(rings)),
OBJECT_MODEL_ARRAY_VALUE(&self->rings[context.GetLastIndex()])
},
// 3. Axis drivers
{
nullptr, // no lock needed
OBJECT_MODEL_ARRAY_COUNT(self->axisDrivers[context.GetLastIndex()].numDrivers),
OBJECT_MODEL_ARRAY_VALUE(self->axisDrivers[context.GetIndex(1)].driverNumbers[context.GetLastIndex()])
},
// 4. Workplace coordinate offsets
{
nullptr, // no lock needed
OBJECT_MODEL_ARRAY_COUNT_NOSELF(NumCoordinateSystems),
OBJECT_MODEL_ARRAY_VALUE_NOSELF(reprap.GetGCodes().GetWorkplaceOffset(context.GetIndex(1), context.GetLastIndex()), 3)
},
#if SUPPORT_COORDINATE_ROTATION
// 5. Rotation centre coordinates
{
nullptr, // no lock needed
OBJECT_MODEL_ARRAY_COUNT_NOSELF(2),
OBJECT_MODEL_ARRAY_VALUE_NOSELF(reprap.GetGCodes().GetRotationCentre(reprap.GetGCodes().GetPrimaryMovementState(), context.GetLastIndex()))
},
#elif SUPPORT_KEEPOUT_ZONES
{
nullptr,
OBJECT_MODEL_ARRAY_COUNT_NOSELF(0),
OBJECT_MODEL_ARRAY_VALUE_NOSELF(nullptr)
}
#endif
#if SUPPORT_KEEPOUT_ZONES
// 6. Keepout zone list
{
nullptr, // no lock needed
OBJECT_MODEL_ARRAY_COUNT_NOSELF(reprap.GetGCodes().GetNumKeepoutZones()),
OBJECT_MODEL_ARRAY_VALUE_NOSELF((reprap.GetGCodes().IsKeepoutZoneDefined(context.GetLastIndex())) ? ExpressionValue(reprap.GetGCodes().GetKeepoutZone(context.GetLastIndex())) : ExpressionValue(nullptr))
},
#endif
};
DEFINE_GET_OBJECT_MODEL_ARRAY_TABLE(Move)
size_t Move::GetMaxElementsToReturn(const ObjectModelArrayTableEntry *entry, const ObjectExplorationContext& context) const noexcept
{
// If we are returning the move.axes array, and we are not just returning frequently-changed data, then limit the number of axes returned.
// PanelDue doesn't know that we return a limited number of axes, so if the requester is PanelDue then return an extra axis, which we can do because we omit many fields.
return (entry == &objectModelArrayTable[0] && context.ShouldTruncateArrays())
? ((context.ForPanelDue()) ? MaxReportedAxesForPanelDue : MaxReportedAxes)
: 0;
}
static inline const char *_ecv_array GetFilamentName(size_t extruder) noexcept
{
const Filament *_ecv_null fil = Filament::GetFilamentByExtruder(extruder);
return (fil == nullptr) ? "" : fil->GetName();
}
constexpr ObjectModelTableEntry Move::objectModelTable[] =
{
// Within each group, these entries must be in alphabetical order
// 0. Move members
{ "axes", OBJECT_MODEL_FUNC_ARRAY(0), ObjectModelEntryFlags::live },
{ "backlashFactor", OBJECT_MODEL_FUNC((int32_t)self->GetBacklashCorrectionDistanceFactor()), ObjectModelEntryFlags::none },
{ "calibration", OBJECT_MODEL_FUNC(self, 3), ObjectModelEntryFlags::notPanelDue },
{ "compensation", OBJECT_MODEL_FUNC(self, 6), ObjectModelEntryFlags::none },
{ "currentMove", OBJECT_MODEL_FUNC(self, 2), ObjectModelEntryFlags::live },
{ "extruders", OBJECT_MODEL_FUNC_ARRAY(1), ObjectModelEntryFlags::liveNotPanelDue },
{ "idle", OBJECT_MODEL_FUNC(self, 1), ObjectModelEntryFlags::none },
#if SUPPORT_KEEPOUT_ZONES
{ "keepout", OBJECT_MODEL_FUNC_ARRAY(6), ObjectModelEntryFlags::notPanelDue },
#endif
{ "kinematics", OBJECT_MODEL_FUNC(self->kinematics), ObjectModelEntryFlags::none },
{ "limitAxes", OBJECT_MODEL_FUNC_NOSELF(reprap.GetGCodes().LimitAxes()), ObjectModelEntryFlags::none },
{ "noMovesBeforeHoming", OBJECT_MODEL_FUNC_NOSELF(reprap.GetGCodes().NoMovesBeforeHoming()), ObjectModelEntryFlags::none },
{ "printingAcceleration", OBJECT_MODEL_FUNC_NOSELF(InverseConvertAcceleration(reprap.GetGCodes().GetCurrentMovementState(context).maxPrintingAcceleration), 1), ObjectModelEntryFlags::none },
{ "queue", OBJECT_MODEL_FUNC_ARRAY(2), ObjectModelEntryFlags::none },
#if SUPPORT_COORDINATE_ROTATION
{ "rotation", OBJECT_MODEL_FUNC(self, 15), ObjectModelEntryFlags::notPanelDue },
#endif
{ "shaping", OBJECT_MODEL_FUNC(&self->axisShaper, 0), ObjectModelEntryFlags::none },
{ "speedFactor", OBJECT_MODEL_FUNC_NOSELF(reprap.GetGCodes().GetCurrentMovementState(context).speedFactor, 2), ObjectModelEntryFlags::none },
{ "travelAcceleration", OBJECT_MODEL_FUNC_NOSELF(InverseConvertAcceleration(reprap.GetGCodes().GetCurrentMovementState(context).maxTravelAcceleration), 1), ObjectModelEntryFlags::none },
{ "virtualEPos", OBJECT_MODEL_FUNC_NOSELF(reprap.GetGCodes().GetCurrentMovementState(context).latestVirtualExtruderPosition, 5), ObjectModelEntryFlags::liveNotPanelDue },
{ "workplaceNumber", OBJECT_MODEL_FUNC_NOSELF((int32_t)reprap.GetGCodes().GetCurrentMovementState(context).currentCoordinateSystem), ObjectModelEntryFlags::none },
// 1. Move.Idle members
{ "factor", OBJECT_MODEL_FUNC(self->GetIdleCurrentFactor(), 1), ObjectModelEntryFlags::none },
{ "timeout", OBJECT_MODEL_FUNC(0.001f * (float)self->idleTimeout, 1), ObjectModelEntryFlags::none },
// 2. move.currentMove members
{ "acceleration", OBJECT_MODEL_FUNC(self->GetAccelerationMmPerSecSquared(), 1), ObjectModelEntryFlags::live },
{ "deceleration", OBJECT_MODEL_FUNC(self->GetDecelerationMmPerSecSquared(), 1), ObjectModelEntryFlags::live },
{ "extrusionRate", OBJECT_MODEL_FUNC(self->GetTotalExtrusionRate(), 2), ObjectModelEntryFlags::live },
# if SUPPORT_LASER
{ "laserPwm", OBJECT_MODEL_FUNC_IF_NOSELF(reprap.GetGCodes().GetMachineType() == MachineType::laser,
reprap.GetPlatform().GetLaserPwm(), 2), ObjectModelEntryFlags::live },
# endif
{ "requestedSpeed", OBJECT_MODEL_FUNC(self->GetRequestedSpeedMmPerSec(), 1), ObjectModelEntryFlags::live },
{ "topSpeed", OBJECT_MODEL_FUNC(self->GetTopSpeedMmPerSec(), 1), ObjectModelEntryFlags::live },
// 3. move.calibration members
{ "final", OBJECT_MODEL_FUNC(self, 5), ObjectModelEntryFlags::none },
{ "initial", OBJECT_MODEL_FUNC(self, 4), ObjectModelEntryFlags::none },
{ "numFactors", OBJECT_MODEL_FUNC((int32_t)self->numCalibratedFactors), ObjectModelEntryFlags::none },
// 4. move.calibration.initialDeviation members
{ "deviation", OBJECT_MODEL_FUNC(self->initialCalibrationDeviation.GetDeviationFromMean(), 3), ObjectModelEntryFlags::none },
{ "mean", OBJECT_MODEL_FUNC(self->initialCalibrationDeviation.GetMean(), 3), ObjectModelEntryFlags::none },
// 5. move.calibration.finalDeviation members
{ "deviation", OBJECT_MODEL_FUNC(self->latestCalibrationDeviation.GetDeviationFromMean(), 3), ObjectModelEntryFlags::none },
{ "mean", OBJECT_MODEL_FUNC(self->latestCalibrationDeviation.GetMean(), 3), ObjectModelEntryFlags::none },
// 6. move.compensation members
{ "fadeHeight", OBJECT_MODEL_FUNC((self->useTaper) ? self->taperHeight : std::numeric_limits<float>::quiet_NaN(), 1), ObjectModelEntryFlags::none },
#if HAS_MASS_STORAGE || HAS_SBC_INTERFACE
{ "file", OBJECT_MODEL_FUNC_IF(self->usingMesh, self->heightMap.GetFileName()), ObjectModelEntryFlags::none },
#endif
{ "liveGrid", OBJECT_MODEL_FUNC_IF(self->usingMesh, (const GridDefinition *)&self->GetGrid()), ObjectModelEntryFlags::none },
{ "meshDeviation", OBJECT_MODEL_FUNC_IF(self->usingMesh, self, 7), ObjectModelEntryFlags::none },
{ "probeGrid", OBJECT_MODEL_FUNC_NOSELF((const GridDefinition *)&reprap.GetGCodes().GetDefaultGrid()), ObjectModelEntryFlags::none },
{ "skew", OBJECT_MODEL_FUNC(self, 8), ObjectModelEntryFlags::none },
{ "type", OBJECT_MODEL_FUNC(self->GetCompensationTypeString()), ObjectModelEntryFlags::none },
// 7. move.compensation.meshDeviation members
{ "deviation", OBJECT_MODEL_FUNC(self->latestMeshDeviation.GetDeviationFromMean(), 3), ObjectModelEntryFlags::none },
{ "mean", OBJECT_MODEL_FUNC(self->latestMeshDeviation.GetMean(), 3), ObjectModelEntryFlags::none },
// 8. move.compensation.skew members
{ "compensateXY", OBJECT_MODEL_FUNC(self->compensateXY), ObjectModelEntryFlags::none },
{ "tanXY", OBJECT_MODEL_FUNC(self->tanXY(), 4), ObjectModelEntryFlags::none },
{ "tanXZ", OBJECT_MODEL_FUNC(self->tanXZ(), 4), ObjectModelEntryFlags::none },
{ "tanYZ", OBJECT_MODEL_FUNC(self->tanYZ(), 4), ObjectModelEntryFlags::none },
// 9. move.axes[] members
{ "acceleration", OBJECT_MODEL_FUNC(InverseConvertAcceleration(self->NormalAcceleration(context.GetLastIndex())), 1), ObjectModelEntryFlags::none },
{ "babystep", OBJECT_MODEL_FUNC_NOSELF(reprap.GetGCodes().GetTotalBabyStepOffset(context.GetLastIndex()), 3), ObjectModelEntryFlags::none },
{ "backlash", OBJECT_MODEL_FUNC(self->backlashMm[context.GetLastIndex()], 3), ObjectModelEntryFlags::notPanelDue },
{ "current", OBJECT_MODEL_FUNC((int32_t)(self->GetMotorCurrent(context.GetLastIndex(), 906))), ObjectModelEntryFlags::notPanelDue },
{ "drivers", OBJECT_MODEL_FUNC_ARRAY(3), ObjectModelEntryFlags::notPanelDue },
{ "homed", OBJECT_MODEL_FUNC_NOSELF(reprap.GetGCodes().IsAxisHomed(context.GetLastIndex())), ObjectModelEntryFlags::none },
{ "jerk", OBJECT_MODEL_FUNC(InverseConvertSpeedToMmPerMin(self->GetMaxInstantDv(context.GetLastIndex())), 1), ObjectModelEntryFlags::none },
{ "letter", OBJECT_MODEL_FUNC_NOSELF(reprap.GetGCodes().GetAxisLetters()[context.GetLastIndex()]), ObjectModelEntryFlags::none },
{ "machinePosition", OBJECT_MODEL_FUNC_NOSELF(reprap.GetGCodes().GetCurrentMovementState(context).LiveMachineCoordinate(context.GetLastIndex()), 3), ObjectModelEntryFlags::live },
{ "max", OBJECT_MODEL_FUNC(self->AxisMaximum(context.GetLastIndex()), 2), ObjectModelEntryFlags::none },
{ "maxProbed", OBJECT_MODEL_FUNC(self->axisMaximaProbed.IsBitSet(context.GetLastIndex())), ObjectModelEntryFlags::notPanelDue },
{ "microstepping", OBJECT_MODEL_FUNC(self, 12), ObjectModelEntryFlags::notPanelDue },
{ "min", OBJECT_MODEL_FUNC(self->AxisMinimum(context.GetLastIndex()), 2), ObjectModelEntryFlags::none },
{ "minProbed", OBJECT_MODEL_FUNC(self->axisMinimaProbed.IsBitSet(context.GetLastIndex())), ObjectModelEntryFlags::notPanelDue },
{ "percentCurrent", OBJECT_MODEL_FUNC((int32_t)(self->GetMotorCurrent(context.GetLastIndex(), 913))), ObjectModelEntryFlags::notPanelDue },
#ifndef DUET_NG
{ "percentStstCurrent", OBJECT_MODEL_FUNC((int32_t)(self->GetMotorCurrent(context.GetLastIndex(), 917))), ObjectModelEntryFlags::notPanelDue },
#endif
#if SUPPORT_PHASE_STEPPING
{ "phaseStep", OBJECT_MODEL_FUNC(self->GetStepMode(context.GetLastIndex()) == StepMode::phase), ObjectModelEntryFlags::notPanelDue },
#endif
{ "printingJerk", OBJECT_MODEL_FUNC(InverseConvertSpeedToMmPerMin(self->GetPrintingInstantDv(context.GetLastIndex())), 1), ObjectModelEntryFlags::none },
{ "reducedAcceleration", OBJECT_MODEL_FUNC(InverseConvertAcceleration(self->Acceleration(context.GetLastIndex(), true)), 1), ObjectModelEntryFlags::none },
{ "speed", OBJECT_MODEL_FUNC(InverseConvertSpeedToMmPerMin(self->MaxFeedrate(context.GetLastIndex())), 1), ObjectModelEntryFlags::none },
{ "stepPos", OBJECT_MODEL_FUNC(self->GetLiveMotorPosition(context.GetLastIndex())), ObjectModelEntryFlags::liveNotPanelDue },
{ "stepsPerMm", OBJECT_MODEL_FUNC(self->DriveStepsPerMm(context.GetLastIndex()), 2), ObjectModelEntryFlags::none },
{ "userPosition", OBJECT_MODEL_FUNC_NOSELF(reprap.GetGCodes().GetUserCoordinate(reprap.GetGCodes().GetCurrentMovementState(context), context.GetLastIndex()), 3), ObjectModelEntryFlags::live },
{ "visible", OBJECT_MODEL_FUNC_NOSELF(context.GetLastIndex() < (int32_t)reprap.GetGCodes().GetVisibleAxes()), ObjectModelEntryFlags::none },
{ "workplaceOffsets", OBJECT_MODEL_FUNC_ARRAY(4), ObjectModelEntryFlags::notPanelDue },
// 10. move.extruders[] members
{ "acceleration", OBJECT_MODEL_FUNC(InverseConvertAcceleration(self->NormalAcceleration(ExtruderToLogicalDrive(context.GetLastIndex()))), 1), ObjectModelEntryFlags::none },
{ "current", OBJECT_MODEL_FUNC((int32_t)(self->GetMotorCurrent(ExtruderToLogicalDrive(context.GetLastIndex()), 906))), ObjectModelEntryFlags::notPanelDue },
{ "driver", OBJECT_MODEL_FUNC(self->extruderDrivers[context.GetLastIndex()]), ObjectModelEntryFlags::notPanelDue },
{ "factor", OBJECT_MODEL_FUNC_NOSELF(reprap.GetGCodes().GetExtrusionFactor(context.GetLastIndex()), 3), ObjectModelEntryFlags::none },
{ "filament", OBJECT_MODEL_FUNC_NOSELF(GetFilamentName(context.GetLastIndex())), ObjectModelEntryFlags::none },
{ "filamentDiameter", OBJECT_MODEL_FUNC_NOSELF(reprap.GetGCodes().GetFilamentDiameter(context.GetLastIndex()), 3), ObjectModelEntryFlags::none },
{ "jerk", OBJECT_MODEL_FUNC(InverseConvertSpeedToMmPerMin(self->GetMaxInstantDv(ExtruderToLogicalDrive(context.GetLastIndex()))), 1), ObjectModelEntryFlags::none },
{ "microstepping", OBJECT_MODEL_FUNC(self, 13), ObjectModelEntryFlags::notPanelDue },
{ "nonlinear", OBJECT_MODEL_FUNC(self, 11), ObjectModelEntryFlags::notPanelDue },
{ "percentCurrent", OBJECT_MODEL_FUNC((int32_t)(self->GetMotorCurrent(context.GetLastIndex(), 913))), ObjectModelEntryFlags::notPanelDue },
#ifndef DUET_NG
{ "percentStstCurrent", OBJECT_MODEL_FUNC((int32_t)(self->GetMotorCurrent(context.GetLastIndex(), 917))), ObjectModelEntryFlags::notPanelDue },
#endif
#if SUPPORT_PHASE_STEPPING
{ "phaseStep", OBJECT_MODEL_FUNC(self->GetStepMode(ExtruderToLogicalDrive(context.GetLastIndex())) == StepMode::phase), ObjectModelEntryFlags::notPanelDue },
#endif
{ "position", OBJECT_MODEL_FUNC_NOSELF(ExpressionValue(reprap.GetGCodes().GetCurrentMovementState(context).LiveMachineCoordinate(ExtruderToLogicalDrive(context.GetLastIndex())), 1)), ObjectModelEntryFlags::liveNotPanelDue },
{ "pressureAdvance", OBJECT_MODEL_FUNC(self->GetPressureAdvanceClocksForExtruder(context.GetLastIndex())/StepClockRate, 3), ObjectModelEntryFlags::none },
{ "printingJerk", OBJECT_MODEL_FUNC(InverseConvertSpeedToMmPerMin(self->GetPrintingInstantDv(ExtruderToLogicalDrive(context.GetLastIndex()))), 1), ObjectModelEntryFlags::none },
{ "rawPosition", OBJECT_MODEL_FUNC_NOSELF(reprap.GetGCodes().GetRawExtruderTotalByDrive(context.GetLastIndex()), 1), ObjectModelEntryFlags::liveNotPanelDue },
{ "speed", OBJECT_MODEL_FUNC(InverseConvertSpeedToMmPerMin(self->MaxFeedrate(ExtruderToLogicalDrive(context.GetLastIndex()))), 1), ObjectModelEntryFlags::none },
{ "stepsPerMm", OBJECT_MODEL_FUNC(self->DriveStepsPerMm(ExtruderToLogicalDrive(context.GetLastIndex())), 2), ObjectModelEntryFlags::none },
// 11. move.extruders[].nonlinear members
{ "a", OBJECT_MODEL_FUNC(self->nonlinearExtrusion[context.GetLastIndex()].A, 3), ObjectModelEntryFlags::none },
{ "b", OBJECT_MODEL_FUNC(self->nonlinearExtrusion[context.GetLastIndex()].B, 3), ObjectModelEntryFlags::none },
{ "upperLimit", OBJECT_MODEL_FUNC(self->nonlinearExtrusion[context.GetLastIndex()].limit, 2), ObjectModelEntryFlags::none },
// 12. move.axes[].microstepping members
{ "interpolated", OBJECT_MODEL_FUNC(self->GetMicrostepInterpolation(context.GetLastIndex())), ObjectModelEntryFlags::none },
{ "value", OBJECT_MODEL_FUNC((int32_t)self->GetMicrostepping(context.GetLastIndex())), ObjectModelEntryFlags::none },
// 13. move.extruders[].microstepping members
{ "interpolated", OBJECT_MODEL_FUNC(self->GetMicrostepInterpolation(ExtruderToLogicalDrive(context.GetLastIndex()))), ObjectModelEntryFlags::none },
{ "value", OBJECT_MODEL_FUNC((int32_t)self->GetMicrostepping(ExtruderToLogicalDrive(context.GetLastIndex()))), ObjectModelEntryFlags::none },
// 14. boards[0].drivers[]
{ "status", OBJECT_MODEL_FUNC(self->GetLocalDriverStatus(context.GetLastIndex()).all), ObjectModelEntryFlags::liveNotPanelDue },
#if SUPPORT_COORDINATE_ROTATION
// 15. move.rotation members
{ "angle", OBJECT_MODEL_FUNC_NOSELF(reprap.GetGCodes().GetRotationAngle(reprap.GetGCodes().GetPrimaryMovementState())), ObjectModelEntryFlags::none },
{ "centre", OBJECT_MODEL_FUNC_ARRAY(5), ObjectModelEntryFlags::none },
#endif
};
constexpr uint8_t Move::objectModelTableDescriptor[] =
{
15 + SUPPORT_COORDINATE_ROTATION,
17 + SUPPORT_COORDINATE_ROTATION + SUPPORT_KEEPOUT_ZONES,
2,
5 + SUPPORT_LASER,
3,
2,
2,
6 + (int)(HAS_MASS_STORAGE || HAS_SBC_INTERFACE),
2,
4,
#ifdef DUET_NG // Duet WiFi/Ethernet doesn't have settable standstill current and doesn't support phase stepping
23, // section 9: move.axes[]
16, // section 10: move.extruders[]
#else
24 + SUPPORT_PHASE_STEPPING, // section 9: move.axes[]
17 + SUPPORT_PHASE_STEPPING, // section 10: move.extruders[]
#endif
3, // section 11: move.extruders[].nonlinear
2, // section 12: move.axes[].microstepping
2, // section 13: move.extruders[].microstepping
1, // section 5: boards.drivers
#if SUPPORT_COORDINATE_ROTATION
2,
#endif
};
DEFINE_GET_OBJECT_MODEL_TABLE(Move)
// The Move task starts executing here
[[noreturn]] static void MoveStart(void *param) noexcept
{
static_cast<Move *>(param)->MoveLoop();
}
Move::Move() noexcept
:
#ifdef DUET3_MB6XD
lastStepHighTime(0),
#else
lastStepLowTime(0),
#endif
lastDirChangeTime(0),
#if SUPPORT_ASYNC_MOVES
heightController(nullptr),
#endif
jerkPolicy(0),
numCalibratedFactors(0)
{
#if VARIABLE_NUM_DRIVERS
numActualDirectDrivers = NumDirectDrivers; // assume they are all available until we know otherwise
#endif
// Kinematics must be set up here because GCodes::Init asks the kinematics for the assumed initial position
kinematics = Kinematics::Create(KinematicsType::cartesian); // default to Cartesian
for (DDARing& ring : rings)
{
ring.Init1(InitialDdaRingLength);
}
}
void Move::Init() noexcept
{
// Axes
for (size_t axis = 0; axis < MaxAxes; ++axis)
{
axisMinima[axis] = DefaultAxisMinimum;
axisMaxima[axis] = DefaultAxisMaximum;
maxFeedrates[axis] = ConvertSpeedFromMmPerSec(DefaultAxisMaxFeedrate);
reducedAccelerations[axis] = normalAccelerations[axis] = ConvertAcceleration(DefaultAxisAcceleration);
printingInstantDvs[axis] = maxInstantDvs[axis] = ConvertSpeedFromMmPerSec(DefaultAxisInstantDv);
backlashMm[axis] = 0.0;
backlashSteps[axis] = 0;
targetBacklashSteps[axis] = currentBacklashSteps[axis] = 0;
}
backlashCorrectionDistanceFactor = DefaultBacklashCorrectionDistanceFactor;
// We use different defaults for the Z axis
maxFeedrates[Z_AXIS] = ConvertSpeedFromMmPerSec(DefaultZMaxFeedrate);
reducedAccelerations[Z_AXIS] = normalAccelerations[Z_AXIS] = ConvertAcceleration(DefaultZAcceleration);
printingInstantDvs[Z_AXIS] = maxInstantDvs[Z_AXIS] = ConvertSpeedFromMmPerSec(DefaultZInstantDv);
// Extruders
for (size_t drive = MaxAxes; drive < MaxAxesPlusExtruders; ++drive)
{
maxFeedrates[drive] = ConvertSpeedFromMmPerSec(DefaultEMaxFeedrate);
normalAccelerations[drive] = reducedAccelerations[drive] = ConvertAcceleration(DefaultEAcceleration);
printingInstantDvs[drive] = maxInstantDvs[drive] = ConvertSpeedFromMmPerSec(DefaultEInstantDv);
}
minimumMovementSpeed = ConvertSpeedFromMmPerSec(DefaultMinFeedrate);
axisMaximaProbed.Clear();
axisMinimaProbed.Clear();
idleCurrentFactor = DefaultIdleCurrentFactor;
// Motors
#ifdef DUET3_MB6XD
DriverEnablePins = (reprap.GetPlatform().GetBoardType() == BoardType::Duet3_6XD_v01) ? ENABLE_PINS_v01 : ENABLE_PINS_v100;
unsigned int numErrorHighDrivers = 0;
#endif
for (size_t driver = 0; driver < NumDirectDrivers; ++driver)
{
directions[driver] = true; // drive moves forwards by default
#ifdef DUET3_MB6XD
SetPinMode(DriverEnablePins[driver], INPUT, false); // temporarily set up the enable pin for reading
SetPinMode(DRIVER_ERR_PINS[driver], INPUT, false); // set up the error pin for reading
const bool activeHighEnable = !digitalRead(DriverEnablePins[driver]); // test whether we have a pullup or pulldown on the Enable pin
enableValues[driver] = activeHighEnable;
SetPinMode(DriverEnablePins[driver], (activeHighEnable) ? OUTPUT_LOW : OUTPUT_HIGH); // set driver disabled
if (digitalRead(DRIVER_ERR_PINS[driver]))
{
++numErrorHighDrivers;
}
// Set the default driver step timings
driverTimingMicroseconds[driver][0] = DefaultStepWidthMicroseconds;
driverTimingMicroseconds[driver][1] = DefaultStepIntervalMicroseconds;
driverTimingMicroseconds[driver][2] = DefaultSetupTimeMicroseconds;
driverTimingMicroseconds[driver][3] = DefaultHoldTimeMicroseconds;
#else
enableValues[driver] = 0; // assume active low enable signal
#endif
// Set up the control pins
SetPinMode(STEP_PINS[driver], OUTPUT_LOW);
SetPinMode(DIRECTION_PINS[driver], OUTPUT_LOW);
#if !defined(DUET3) && !defined(DUET3MINI)
SetPinMode(DriverEnablePins[driver], OUTPUT_HIGH); // this is OK for the TMC2660 CS pins too
#endif
brakeOffDelays[driver] = 0;
motorOffDelays[driver] = DefaultDelayAfterBrakeOn;
#if SUPPORT_BRAKE_PWM
currentBrakePwm[driver] = 0.0;
brakeVoltages[driver] = FullyOnBrakeVoltage;
#endif
}
#ifdef DUET3_MB6XD
driverErrPinsActiveLow = (numErrorHighDrivers >= NumDirectDrivers/2); // determine the error signal polarity by assuming most drivers are not in the error state
pmc_enable_periph_clk(STEP_GATE_TC_ID); // need to do this before we set up the step gate TC
UpdateDriverTimings(); // this also initialises the step gate TC
SetPinFunction(StepGatePin, StepGatePinFunction);
#endif
// Initialise the DMs before we make any changes to them
for (size_t drv = 0; drv < MaxAxesPlusExtruders + NumDirectDrivers; ++drv)
{
dms[drv].Init(drv);
if (drv < MaxAxesPlusExtruders)
{
const float stepsPerMm = (drv >= MaxAxes) ? DefaultEDriveStepsPerUnit
: (drv == Z_AXIS) ? DefaultZDriveStepsPerUnit
: DefaultAxisDriveStepsPerUnit;
driveStepsPerMm[drv] = stepsPerMm;
}
}
// Set up the axis+extruder arrays
for (size_t drive = 0; drive < MaxAxesPlusExtruders; drive++)
{
driverState[drive] = DriverStatus::disabled;
motorCurrents[drive] = 0.0;
motorCurrentFraction[drive] = 1.0;
#if HAS_SMART_DRIVERS || SUPPORT_CAN_EXPANSION
standstillCurrentPercent[drive] = (float)DefaultStandstillCurrentPercent;
#endif
SetDriverMicrostepping(drive, 16, true); // x16 with interpolation
}
// Set up the bitmaps for direct driver access
for (size_t driver = 0; driver < NumDirectDrivers; ++driver)
{
dms[driver + MaxAxesPlusExtruders].driversNormallyUsed = StepPins::CalcDriverBitmap(driver);
}
// Set up default axis mapping
for (size_t axis = 0; axis < MinAxes; ++axis)
{
#ifdef PCCB
const size_t driver = (axis + 1) % 3; // on PCCB we map axes X Y Z to drivers 1 2 0
#else
const size_t driver = axis; // on most boards we map axes straight through to drives
#endif
axisDrivers[axis].numDrivers = 1;
axisDrivers[axis].driverNumbers[0].SetLocal(driver);
dms[axis].driversNormallyUsed = StepPins::CalcDriverBitmap(driver); // overwrite the default value set up earlier
}
linearAxes = AxesBitmap::MakeLowestNBits(3); // XYZ axes are linear
for (size_t axis = MinAxes; axis < MaxAxes; ++axis)
{
axisDrivers[axis].numDrivers = 0;
}
// Set up default extruders
for (size_t extr = 0; extr < MaxExtruders; ++extr)
{
extruderDrivers[extr].SetLocal(extr + MinAxes); // set up default extruder drive mapping
dms[ExtruderToLogicalDrive(extr)].driversNormallyUsed = StepPins::CalcDriverBitmap(extr + MinAxes);
#if SUPPORT_NONLINEAR_EXTRUSION
nonlinearExtrusion[extr].A = nonlinearExtrusion[extr].B = 0.0;
nonlinearExtrusion[extr].limit = DefaultNonlinearExtrusionLimit;
#endif
}
#ifndef DUET3_MB6XD
for (uint32_t& entry : slowDriverStepTimingClocks)
{
entry = 0; // reset all to zero as we have no known slow drivers yet
}
slowDriversBitmap = 0; // assume no drivers need extended step pulse timing
#endif
#if HAS_SMART_DRIVERS
// Initialise TMC driver module
# if SUPPORT_TMC51xx
SmartDrivers::Init();
# elif SUPPORT_TMC22xx
# if TMC22xx_VARIABLE_NUM_DRIVERS
SmartDrivers::Init(numSmartDrivers);
# elif SUPPORT_TMC2240 && defined(DUET3MINI)
SmartDrivers::Init(reprap.GetPlatform().HasTmc2240Expansion());
# else
SmartDrivers::Init();
# endif
# else
SmartDrivers::Init(DriverEnablePins, numSmartDrivers);
# endif
temperatureShutdownDrivers.Clear();
temperatureWarningDrivers.Clear();
shortToGroundDrivers.Clear();
#endif
#if HAS_STALL_DETECT
logOnStallDrivers.Clear();
eventOnStallDrivers.Clear();
#endif
// DDA rings
for (DDARing& ring : rings)
{
ring.Init2();
}
#if SUPPORT_ASYNC_MOVES
auxMoveAvailable = false;
auxMoveLocked = false;
#endif
// Clear the transforms
SetIdentityTransform();
compensateXY = true;
tangents[0] = tangents[1] = tangents[2] = 0.0;
usingMesh = useTaper = false;
zShift = 0.0;
idleTimeout = DefaultIdleTimeout;
moveState = MoveState::idle;
const uint32_t now = millis();
whenIdleTimerStarted = now;
for (uint32_t& w : whenLastMoveAdded)
{
w = now;
}
simulationMode = SimulationMode::off;
longestGcodeWaitInterval = 0;
numInterruptHiccups = numPrepareHiccups = 0;
bedLevellingMoveAvailable = false;
activeDMs = nullptr;
for (uint16_t& ms : microstepping)
{
ms = 16 | 0x8000;
}
#if SUPPORT_PHASE_STEPPING
phaseStepDMs = nullptr;
for (float& rm : phaseStepMultiplier)
{
rm = -(1.0/16.0);
}
ResetPhaseStepMonitoringVariables();
#endif
moveTask.Create(MoveStart, "Move", this, TaskPriority::MovePriority);
}
void Move::Exit() noexcept
{
StepTimer::DisableTimerInterrupt();
stepsTimer.CancelCallback();
#if HAS_SMART_DRIVERS
SmartDrivers::Exit();
#endif
for (DDARing& ring : rings)
{
ring.Exit();
}
#if SUPPORT_LASER || SUPPORT_IOBITS
delete laserTask;
laserTask = nullptr;
#endif
moveTask.TerminateAndUnlink();
}
[[noreturn]] void Move::MoveLoop() noexcept
{
stepsTimer.SetCallback(Move::TimerCallback, CallbackParameter(this));
for (;;)
{
if (reprap.IsStopped() || hadStepError)
{
// Emergency stop has been commanded, so terminate this task to prevent new moves being prepared and executed
moveTask.TerminateAndUnlink();
}
#if SUPPORT_REMOTE_COMMANDS
if (CanInterface::InExpansionMode())
{
// In expansion mode we don't need the Move task to do anything, and in particular we must not perform udle detection.
// We could terminate the Move task here but currently we don't because:
// (a) if we do then we must make sure that any attempts to wake it up are benign
// (b) in future we may wish to use the Move task to queue movement commands
// So for now we just delay.
delay(10000);
continue;
}
#endif
bool moveRead = false;
// See if we can add another move to ring 0
const bool canAddRing0Move = rings[0].CanAddMove();
if (canAddRing0Move)
{
// OK to add another move. First check if a special move is available.
if (bedLevellingMoveAvailable)
{
moveRead = true;
if (simulationMode < SimulationMode::partial)
{
if (rings[0].AddSpecialMove(MaxFeedrate(Z_AXIS), specialMoveCoords))
{
const uint32_t now = millis();
const uint32_t timeWaiting = now - whenLastMoveAdded[0];
if (timeWaiting > longestGcodeWaitInterval)
{
longestGcodeWaitInterval = timeWaiting;
}
whenLastMoveAdded[0] = now;
moveState = MoveState::collecting;
}
}
bedLevellingMoveAvailable = false;
}
else
{
// If there's a G Code move available, add it to the DDA ring for processing.
RawMove nextMove;
GCodes& gcodes = reprap.GetGCodes();
if (gcodes.ReadMove(0, nextMove)) // if we have a new move
{
moveRead = true;
if (simulationMode < SimulationMode::partial) // in simulation mode partial, we don't process incoming moves beyond this point
{
if (nextMove.moveType == 0)
{
AxisAndBedTransform(nextMove.coords, nextMove.movementTool,
#if SUPPORT_SCANNING_PROBES
!nextMove.scanningProbeMove
#else
true
#endif
);
}
const MovementError err = rings[0].AddStandardMove(nextMove, !IsRawMotorMove(nextMove.moveType));
if (err == MovementError::ok)
{
const uint32_t now = millis();
const uint32_t timeWaiting = now - whenLastMoveAdded[0];
if (timeWaiting > longestGcodeWaitInterval)
{
longestGcodeWaitInterval = timeWaiting;
}
whenLastMoveAdded[0] = now;
moveState = MoveState::collecting;
}
else if (err != MovementError::noMovement)
{
gcodes.ReportMovementError(err);
}
}
}
}
}
// Let ring 0 process moves
// When there is a gap between moves it can be that we try to prepare the second move while a segment of the first move that has been delayed by input shaping is still executing.
// To avoid this we must ensure that we prepare moves at least half an input shaper period in advance. This avoids the problem because any delayed segment of the first move
// will be half a shaper period long. In order to handle CAN delays etc. we prepare moves [half a shaper period plus MoveTiming::AbsoluteMinimumPreparedTime] in advance,
// with a minimum of MoveTiming::UsualMinimumPreparedTime.
const uint32_t prepareAdvanceTime = axisShaper.GetPrepareAdvanceTime();
uint32_t nextPrepareDelay = rings[0].Spin(prepareAdvanceTime, simulationMode, !canAddRing0Move, millis() - whenLastMoveAdded[0] >= rings[0].GetGracePeriod());
#if SUPPORT_ASYNC_MOVES
const bool canAddRing1Move = rings[1].CanAddMove();
if (canAddRing1Move)
{
if (auxMoveAvailable)
{
moveRead = true;
if (rings[1].AddAsyncMove(auxMove))
{
const uint32_t now = millis();
const uint32_t timeWaiting = now - whenLastMoveAdded[1];
if (timeWaiting > longestGcodeWaitInterval)
{
longestGcodeWaitInterval = timeWaiting;
}
whenLastMoveAdded[1] = now;
moveState = MoveState::collecting;
}
auxMoveAvailable = false;
}
else
{
// If there's a G Code move available, add it to the DDA ring for processing.
RawMove nextMove;
GCodes& gcodes = reprap.GetGCodes();
if (gcodes.ReadMove(1, nextMove)) // if we have a new move
{
moveRead = true;
if (simulationMode < SimulationMode::partial) // in simulation mode partial, we don't process incoming moves beyond this point
{
if (nextMove.moveType == 0)
{
AxisAndBedTransform(nextMove.coords, nextMove.movementTool, true);
}
const MovementError err = rings[1].AddStandardMove(nextMove, !IsRawMotorMove(nextMove.moveType));
if (err == MovementError::ok)
{
const uint32_t now = millis();
const uint32_t timeWaiting = now - whenLastMoveAdded[1];
if (timeWaiting > longestGcodeWaitInterval)
{
longestGcodeWaitInterval = timeWaiting;
}
whenLastMoveAdded[1] = now;
moveState = MoveState::collecting;
}
else if (err != MovementError::noMovement)
{
gcodes.ReportMovementError(err);
}
}
}
}
}
const uint32_t auxPrepareDelay = rings[1].Spin(prepareAdvanceTime, simulationMode, !canAddRing1Move, millis() - whenLastMoveAdded[1] >= rings[1].GetGracePeriod());
if (auxPrepareDelay < nextPrepareDelay)
{
nextPrepareDelay = auxPrepareDelay;
}
#endif
if (simulationMode == SimulationMode::debug && reprap.GetDebugFlags(Module::Move).IsBitSet(MoveDebugFlags::SimulateSteppingDrivers))
{
while (activeDMs != nullptr)
{
SimulateSteppingDrivers(reprap.GetPlatform());
}
}
// Reduce motor current to standby if the rings have been idle for long enough
if ( rings[0].IsIdle()
#if SUPPORT_ASYNC_MOVES
&& rings[1].IsIdle()
#endif
)
{
if ( moveState == MoveState::executing
&& reprap.GetGCodes().GetPauseState() == PauseState::notPaused // for now we don't go into idle hold when we are paused (is this sensible?)
)
{
whenIdleTimerStarted = millis(); // record when we first noticed that the machine was idle
moveState = MoveState::timing;
}
else if (moveState == MoveState::timing && millis() - whenIdleTimerStarted >= idleTimeout)
{
SetDriversIdle(); // put all drives in idle hold
moveState = MoveState::idle;
}
}
else
{
moveState = MoveState::executing;
}
// We need to be woken when one of the following is true:
// 1. If moves are being executed and there are unprepared moves in the queue, when it is time to prepare more moves.
// 2. If the queue was full and all moves in it were prepared, when we have completed one or more moves.
// 3. In order to implement idle timeout, we must wake up regularly anyway, say every half second (MoveTiming::StandardMoveWakeupInterval)
if (!moveRead && nextPrepareDelay != 0)
{
TaskBase::TakeIndexed(NotifyIndices::Move, nextPrepareDelay);
}
}
}
// This is called from GCodes to tell the Move task that a move is available
void Move::MoveAvailable() noexcept
{
if (moveTask.IsRunning())
{
moveTask.Give(NotifyIndices::Move);
}
}
// Tell the lookahead ring we are waiting for it to empty and return true if it is
bool Move::WaitingForAllMovesFinished(MovementSystemNumber msNumber
#if SUPPORT_ASYNC_MOVES
, LogicalDrivesBitmap logicalDrivesOwned
#endif
) noexcept
{
if (!rings[msNumber].SetWaitingToEmpty())
{
return false;
}
// If input shaping is enabled then movement may continue for a little while longer
#if SUPPORT_ASYNC_MOVES
return logicalDrivesOwned.IterateWhile([this](unsigned int axisOrExtruder, unsigned int) noexcept -> bool
{
return !dms[axisOrExtruder].MotionPending();
}
);
#else
for (size_t drive = 0; drive < MaxAxesPlusExtruders; ++drive)
{
if (dms[drive].MotionPending())
{
return false;
}
}
#endif
return true;
}
// Return the number of actually probed probe points
unsigned int Move::GetNumProbedProbePoints() const noexcept
{
return probePoints.NumberOfProbePoints();
}
// Try to push some babystepping through the lookahead queue, returning the amount pushed
// This is called by the Main task, so we need to lock out the Move task while doing this
float Move::PushBabyStepping(MovementSystemNumber msNumber,size_t axis, float amount) noexcept
{
TaskCriticalSectionLocker lock; // lock out the Move task
return rings[msNumber].PushBabyStepping(axis, amount);
}
// Change the kinematics to the specified type if it isn't already
// If it is already correct leave its parameters alone.
// This violates our rule on no dynamic memory allocation after the initialisation phase,
// however this function is normally called only when M665, M667 and M669 commands in config.g are processed.
bool Move::SetKinematics(KinematicsType k) noexcept
{
if (kinematics->GetKinematicsType() != k)
{
Kinematics *_ecv_from _ecv_null const nk = Kinematics::Create(k);
if (nk == nullptr)
{
return false;
}
delete kinematics;
kinematics = _ecv_not_null(nk);
reprap.MoveUpdated();
}
return true;
}
// Return true if this is a raw motor move
bool Move::IsRawMotorMove(uint8_t moveType) const noexcept
{
return moveType == 2 || ((moveType == 1 || moveType == 3) && kinematics->GetHomingMode() != HomingMode::homeCartesianAxes);
}
// Return true if the specified point is accessible to the Z probe
bool Move::IsAccessibleProbePoint(float axesCoords[MaxAxes], AxesBitmap axes) const noexcept
{
return kinematics->IsReachable(axesCoords, axes);
}
// Pause the print as soon as we can, returning true if we are able to skip any moves and updating ms.pauseRestorePoint to the first move we skipped.
bool Move::PausePrint(MovementState& ms) noexcept
{
return rings[ms.GetNumber()].PauseMoves(ms);
}
#if HAS_VOLTAGE_MONITOR || HAS_STALL_DETECT
// Pause the print immediately, returning true if we were able to skip or abort any moves and setting up to the move we aborted
bool Move::LowPowerOrStallPause(MovementState& ms) noexcept
{
return rings[ms.GetNumber()].LowPowerOrStallPause(ms);
}
// Stop generating steps
void Move::CancelStepping() noexcept
{
StepTimer::DisableTimerInterrupt();
}
#endif
#if SUPPORT_PHASE_STEPPING || SUPPORT_CLOSED_LOOP
// Helper function to convert a time period (expressed in StepTimer::Ticks) to a frequency in Hz
static inline uint32_t TickPeriodToFreq(StepTimer::Ticks tickPeriod) noexcept
{
return StepTimer::GetTickRate()/tickPeriod;
}
#endif
void Move::Diagnostics(unsigned int part, const StringRef& reply) noexcept
{
switch (part)
{
case 0:
{
const float totalDelayToReport = (float)StepTimer::GetMovementDelay() * (1000.0/(float)StepTimer::GetTickRate());
#if SUPPORT_CAN_EXPANSION
const float ownDelayToReport = (float)StepTimer::GetOwnMovementDelay() * (1000.0/(float)StepTimer::GetTickRate());
#endif
reply.printf("=== Move ===\nSegments created %u, maxWait %" PRIu32 "ms, bed comp in use: %s, height map offset %.3f, hiccups added %u/%u"
#if SUPPORT_CAN_EXPANSION
" (%.2f/%.2fms)"
#else
" (%.2fms)"
#endif
", max steps late %" PRIi32
#if 1 //debug
", ebfmin %.2f, ebfmax %.2f"
#endif
,
MoveSegment::NumCreated(), longestGcodeWaitInterval, GetCompensationTypeString(), (double)zShift, numPrepareHiccups, numInterruptHiccups,
#if SUPPORT_CAN_EXPANSION
(double)ownDelayToReport, (double)totalDelayToReport,
#else
(double)totalDelayToReport,
#endif
DriveMovement::GetAndClearMaxStepsLate()
#if 1
, (double)minExtrusionPending, (double)maxExtrusionPending
#endif
);
longestGcodeWaitInterval = 0;
numInterruptHiccups = numPrepareHiccups = 0;
#if 1 //debug
minExtrusionPending = maxExtrusionPending = 0.0;
#endif
#if STEPS_DEBUG
# if 0 // DEBUG
reply.lcat("Pos req/act/dcf/state/seg:");
# else
reply.lcat("Pos req/act/dcf:");
# endif
for (size_t drive = 0; drive < reprap.GetGCodes().GetTotalAxes(); ++drive)
{
# if 0 // DEBUG
reply.catf(" %.2f/%" PRIi32 "/%.2f/%u/%u", (double)dms[drive].positionRequested, dms[drive].currentMotorPosition, (double)dms[drive].distanceCarriedForwards, (unsigned int)dms[drive].state, dms[drive].segments != nullptr);
# else
reply.catf(" %.2f/%" PRIi32 "/%.2f", (double)dms[drive].positionRequested, dms[drive].currentMotorPosition, (double)dms[drive].distanceCarriedForwards);