@@ -27,7 +27,6 @@ with Settings; use Settings;
27
27
28
28
package body Gcode.Planner is
29
29
30
- use Float_Functions;
31
30
use type Float_Position;
32
31
use type Step_Position;
33
32
@@ -37,23 +36,22 @@ package body Gcode.Planner is
37
36
type Motion_Block (Kind : Motion_Kind := Motion_Line) is record
38
37
case Kind is
39
38
when Motion_Line =>
40
- Target : Float_Position;
39
+ Target : Float_Position;
41
40
42
- Relative_Steps : Step_Position;
43
- -- Steps for each axis
41
+ Abs_Relative_Steps : Step_Position;
42
+ -- Absolute number of steps for each axis
44
43
45
- Directions : Axis_Directions := (others => Forward);
44
+ Directions : Axis_Directions := (others => Forward);
46
45
-- Step direction for each axis
47
46
48
- Step_Event_Count : Steps := 0 ;
47
+ Step_Event_Count : Steps := 0 ;
49
48
-- Number of steps required to complete this block
50
49
51
- Entry_Speed : Step_Speed := 0.0 ;
52
- Nominal_Speed : Step_Speed := 0.0 ;
53
- Acceleration : Step_Acceleration := Step_Acceleration'Last;
54
- Remaining_Distance : Float_Value := 0.0 ;
50
+ Entry_Speed : Step_Speed := 0.0 ;
51
+ Nominal_Speed : Step_Speed := 0.0 ;
52
+ Acceleration : Step_Acceleration := Step_Acceleration'Last;
55
53
when Motion_Dwell =>
56
- Dwell_Duration : Duration ;
54
+ Dwell_Duration : Float_Value ;
57
55
when Motion_Homing =>
58
56
null ;
59
57
when Motion_Enable_Motors =>
@@ -102,39 +100,48 @@ package body Gcode.Planner is
102
100
pragma Unreferenced (Ctx);
103
101
M_Block : Motion_Block (Kind => Motion_Line);
104
102
Target_Steps : constant Step_Position := Milli_To_Step (Target);
103
+ Relative_Steps : Step_Position := Target_Steps - Planner_Position;
105
104
Delta_MM : Float_Value;
106
105
107
106
Unit_Vect : Float_Position;
108
107
pragma Unreferenced (Unit_Vect);
109
108
-- Unit vector of the block used for junction angle computation
110
109
begin
111
110
112
- M_Block.Relative_Steps := abs (Target_Steps - Planner_Position);
111
+ if Settings.Use_CoreXY_Motion then
112
+ declare
113
+ DX, DY, DA, DB : Steps;
114
+ begin
115
+ DX := Relative_Steps (X_Axis);
116
+ DY := Relative_Steps (Y_Axis);
117
+
118
+ DA := DX + DY;
119
+ DB := DX - DY;
120
+
121
+ Relative_Steps (X_Axis) := DA;
122
+ Relative_Steps (Y_Axis) := DB;
123
+ end ;
124
+ end if ;
125
+
126
+ M_Block.Abs_Relative_Steps := abs Relative_Steps;
113
127
114
128
for Axis in Axis_Name loop
115
129
M_Block.Step_Event_Count :=
116
130
Steps'Max (M_Block.Step_Event_Count,
117
- M_Block.Relative_Steps (Axis));
131
+ M_Block.Abs_Relative_Steps (Axis));
118
132
119
133
-- Distance traveled in milimeters
120
134
Delta_MM :=
121
- Float_Value (Target_Steps (Axis) - Planner_Position (Axis))
135
+ Float_Value (Relative_Steps (Axis))
122
136
/ Settings.Step_Per_Millimeter (Axis);
123
137
124
138
-- Direction of movement for this axis
125
139
M_Block.Directions (Axis) :=
126
140
(if Delta_MM < 0.0 then Backward else Forward);
127
141
128
- -- Add square of each axis to compute distance
129
- M_Block.Remaining_Distance :=
130
- M_Block.Remaining_Distance + Delta_MM**2 ;
131
-
132
142
Unit_Vect (Axis) := Delta_MM;
133
143
end loop ;
134
144
135
- -- Compute distance
136
- M_Block.Remaining_Distance := Sqrt (M_Block.Remaining_Distance);
137
-
138
145
if M_Block.Step_Event_Count = 0 then
139
146
-- zero-length block
140
147
return ;
@@ -156,7 +163,7 @@ package body Gcode.Planner is
156
163
157
164
procedure Planner_Add_Dwell
158
165
(Ctx : in out GContext'Class;
159
- Dwell_Duration : Duration )
166
+ Dwell_Duration : Float_Value )
160
167
is
161
168
pragma Unreferenced (Ctx);
162
169
M_Block : Motion_Block (Kind => Motion_Dwell);
@@ -218,7 +225,7 @@ package body Gcode.Planner is
218
225
Seg : Segment;
219
226
Remaining_Steps : Steps;
220
227
Remaining_Seg : Natural;
221
- Seg_Required_To_Stop : Natural ;
228
+ Seg_Required_To_Stop : Integer ;
222
229
begin
223
230
loop
224
231
@@ -232,13 +239,13 @@ package body Gcode.Planner is
232
239
233
240
-- 100Hz gives us a 10ms precision
234
241
Seg.Frequency :=
235
- Duration 'Max (100.0 , Settings.Idle_Stepper_Frequency);
242
+ Frequency_Value 'Max (100.0 , Settings.Idle_Stepper_Frequency);
236
243
237
244
Seg.Step_Count :=
238
245
Steps (Motion.Dwell_Duration * Seg.Frequency);
239
246
240
247
-- No axis is moving
241
- Seg.Block_Steps := (others => 0 );
248
+ Seg.Abs_Block_Steps := (others => 0 );
242
249
Seg.Block_Event_Count := Steps'Last;
243
250
244
251
-- Blocking call
@@ -254,14 +261,16 @@ package body Gcode.Planner is
254
261
when Motion_Enable_Motors =>
255
262
Segment_Block_Buffer.Insert ((Kind => Enable_Motors_Segment,
256
263
Enable => Motion.Enable));
264
+
265
+
257
266
when Motion_Line =>
258
267
Remaining_Steps := Motion.Step_Event_Count;
259
268
260
269
-- Signal this segment as first of the new block
261
270
Seg.New_Block := True;
262
271
263
272
-- Segment values that will remain for the entire block
264
- Seg.Block_Steps := Motion.Relative_Steps ;
273
+ Seg.Abs_Block_Steps := Motion.Abs_Relative_Steps ;
265
274
Seg.Block_Event_Count := Motion.Step_Event_Count;
266
275
Seg.Directions := Motion.Directions;
267
276
@@ -307,7 +316,6 @@ package body Gcode.Planner is
307
316
308
317
-- Next segements are not first of the block
309
318
Seg.New_Block := False;
310
-
311
319
end loop ;
312
320
end case ;
313
321
end loop ;
0 commit comments