Преглед на файлове

Merge pull request #10614 from thinkyhead/bf2_synced_planner_set_position

[2.0.x] Improve sync of planner / stepper position, asynchronous G92
Scott Lahteine преди 7 години
родител
ревизия
f30241bda5
No account linked to committer's email address

+ 5
- 5
Marlin/src/feature/I2CPositionEncoder.cpp Целия файл

358
 
358
 
359
   stepper.synchronize();
359
   stepper.synchronize();
360
 
360
 
361
-  planner.buffer_line(startCoord[X_AXIS],startCoord[Y_AXIS],startCoord[Z_AXIS],
361
+  planner.buffer_line(startCoord[X_AXIS], startCoord[Y_AXIS], startCoord[Z_AXIS],
362
                       stepper.get_axis_position_mm(E_AXIS), feedrate, 0);
362
                       stepper.get_axis_position_mm(E_AXIS), feedrate, 0);
363
   stepper.synchronize();
363
   stepper.synchronize();
364
 
364
 
415
   startCoord[encoderAxis] = startDistance;
415
   startCoord[encoderAxis] = startDistance;
416
   endCoord[encoderAxis] = endDistance;
416
   endCoord[encoderAxis] = endDistance;
417
 
417
 
418
-  LOOP_L_N(i, iter) {
419
-    stepper.synchronize();
418
+  stepper.synchronize();
420
 
419
 
421
-    planner.buffer_line(startCoord[X_AXIS],startCoord[Y_AXIS],startCoord[Z_AXIS],
420
+  LOOP_L_N(i, iter) {
421
+    planner.buffer_line(startCoord[X_AXIS], startCoord[Y_AXIS], startCoord[Z_AXIS],
422
                         stepper.get_axis_position_mm(E_AXIS), feedrate, 0);
422
                         stepper.get_axis_position_mm(E_AXIS), feedrate, 0);
423
     stepper.synchronize();
423
     stepper.synchronize();
424
 
424
 
427
 
427
 
428
     //do_blocking_move_to(endCoord[X_AXIS],endCoord[Y_AXIS],endCoord[Z_AXIS]);
428
     //do_blocking_move_to(endCoord[X_AXIS],endCoord[Y_AXIS],endCoord[Z_AXIS]);
429
 
429
 
430
-    planner.buffer_line(endCoord[X_AXIS],endCoord[Y_AXIS],endCoord[Z_AXIS],
430
+    planner.buffer_line(endCoord[X_AXIS], endCoord[Y_AXIS], endCoord[Z_AXIS],
431
                         stepper.get_axis_position_mm(E_AXIS), feedrate, 0);
431
                         stepper.get_axis_position_mm(E_AXIS), feedrate, 0);
432
     stepper.synchronize();
432
     stepper.synchronize();
433
 
433
 

+ 21
- 24
Marlin/src/feature/fwretract.cpp Целия файл

108
     // G11 priority to recover the long retract if activated
108
     // G11 priority to recover the long retract if activated
109
     if (!retracting) swapping = retracted_swap[active_extruder];
109
     if (!retracting) swapping = retracted_swap[active_extruder];
110
   #else
110
   #else
111
-    const bool swapping = false;
111
+    constexpr bool swapping = false;
112
   #endif
112
   #endif
113
 
113
 
114
   /* // debugging
114
   /* // debugging
118
     for (uint8_t i = 0; i < EXTRUDERS; ++i) {
118
     for (uint8_t i = 0; i < EXTRUDERS; ++i) {
119
       SERIAL_ECHOPAIR("retracted[", i);
119
       SERIAL_ECHOPAIR("retracted[", i);
120
       SERIAL_ECHOLNPAIR("] ", retracted[i]);
120
       SERIAL_ECHOLNPAIR("] ", retracted[i]);
121
-      SERIAL_ECHOPAIR("retracted_swap[", i);
122
-      SERIAL_ECHOLNPAIR("] ", retracted_swap[i]);
121
+      #if EXTRUDERS > 1
122
+        SERIAL_ECHOPAIR("retracted_swap[", i);
123
+        SERIAL_ECHOLNPAIR("] ", retracted_swap[i]);
124
+      #endif
123
     }
125
     }
124
     SERIAL_ECHOLNPAIR("current_position[z] ", current_position[Z_AXIS]);
126
     SERIAL_ECHOLNPAIR("current_position[z] ", current_position[Z_AXIS]);
125
     SERIAL_ECHOLNPAIR("current_position[e] ", current_position[E_AXIS]);
127
     SERIAL_ECHOLNPAIR("current_position[e] ", current_position[E_AXIS]);
126
     SERIAL_ECHOLNPAIR("hop_amount ", hop_amount);
128
     SERIAL_ECHOLNPAIR("hop_amount ", hop_amount);
127
   //*/
129
   //*/
128
 
130
 
129
-  const float old_feedrate_mm_s = feedrate_mm_s;
131
+  const float old_feedrate_mm_s = feedrate_mm_s,
132
+              renormalize = RECIPROCAL(planner.e_factor[active_extruder]),
133
+              base_retract = swapping ? swap_retract_length : retract_length,
134
+              old_z = current_position[Z_AXIS],
135
+              old_e = current_position[E_AXIS];
130
 
136
 
131
   // The current position will be the destination for E and Z moves
137
   // The current position will be the destination for E and Z moves
132
   set_destination_from_current();
138
   set_destination_from_current();
133
-  stepper.synchronize();  // Wait for buffered moves to complete
134
-
135
-  const float renormalize = 1.0 / planner.e_factor[active_extruder];
136
 
139
 
137
   if (retracting) {
140
   if (retracting) {
138
     // Retract by moving from a faux E position back to the current E position
141
     // Retract by moving from a faux E position back to the current E position
139
     feedrate_mm_s = retract_feedrate_mm_s;
142
     feedrate_mm_s = retract_feedrate_mm_s;
140
-    current_position[E_AXIS] += (swapping ? swap_retract_length : retract_length) * renormalize;
141
-    sync_plan_position_e();
142
-    prepare_move_to_destination();  // set_current_to_destination
143
+    destination[E_AXIS] -= base_retract * renormalize;
144
+    prepare_move_to_destination();                        // set_current_to_destination
143
 
145
 
144
     // Is a Z hop set, and has the hop not yet been done?
146
     // Is a Z hop set, and has the hop not yet been done?
145
-    // No double zlifting
146
-    // Feedrate to the max
147
     if (retract_zlift > 0.01 && !hop_amount) {            // Apply hop only once
147
     if (retract_zlift > 0.01 && !hop_amount) {            // Apply hop only once
148
-      const float old_z = current_position[Z_AXIS];
149
       hop_amount += retract_zlift;                        // Add to the hop total (again, only once)
148
       hop_amount += retract_zlift;                        // Add to the hop total (again, only once)
150
       destination[Z_AXIS] += retract_zlift;               // Raise Z by the zlift (M207 Z) amount
149
       destination[Z_AXIS] += retract_zlift;               // Raise Z by the zlift (M207 Z) amount
151
       feedrate_mm_s = planner.max_feedrate_mm_s[Z_AXIS];  // Maximum Z feedrate
150
       feedrate_mm_s = planner.max_feedrate_mm_s[Z_AXIS];  // Maximum Z feedrate
152
       prepare_move_to_destination();                      // Raise up, set_current_to_destination
151
       prepare_move_to_destination();                      // Raise up, set_current_to_destination
153
-      current_position[Z_AXIS] = old_z;                   // Spoof the Z position in the planner
154
-      SYNC_PLAN_POSITION_KINEMATIC();
155
     }
152
     }
156
   }
153
   }
157
   else {
154
   else {
158
     // If a hop was done and Z hasn't changed, undo the Z hop
155
     // If a hop was done and Z hasn't changed, undo the Z hop
159
     if (hop_amount) {
156
     if (hop_amount) {
160
-      current_position[Z_AXIS] += hop_amount;             // Set actual Z (due to the prior hop)
161
-      SYNC_PLAN_POSITION_KINEMATIC();                     // Spoof the Z position in the planner
157
+      destination[Z_AXIS] -= hop_amount;                  // Move back down by the total hop amount
162
       feedrate_mm_s = planner.max_feedrate_mm_s[Z_AXIS];  // Z feedrate to max
158
       feedrate_mm_s = planner.max_feedrate_mm_s[Z_AXIS];  // Z feedrate to max
163
       prepare_move_to_destination();                      // Lower Z, set_current_to_destination
159
       prepare_move_to_destination();                      // Lower Z, set_current_to_destination
164
       hop_amount = 0.0;                                   // Clear the hop amount
160
       hop_amount = 0.0;                                   // Clear the hop amount
165
     }
161
     }
166
 
162
 
167
-    // A retract multiplier has been added here to get faster swap recovery
163
+    destination[E_AXIS] += (base_retract + (swapping ? swap_retract_recover_length : retract_recover_length)) * renormalize;
168
     feedrate_mm_s = swapping ? swap_retract_recover_feedrate_mm_s : retract_recover_feedrate_mm_s;
164
     feedrate_mm_s = swapping ? swap_retract_recover_feedrate_mm_s : retract_recover_feedrate_mm_s;
169
-
170
-    current_position[E_AXIS] -= (swapping ? swap_retract_length + swap_retract_recover_length
171
-                                          : retract_length + retract_recover_length) * renormalize;
172
-    sync_plan_position_e();
173
     prepare_move_to_destination();                        // Recover E, set_current_to_destination
165
     prepare_move_to_destination();                        // Recover E, set_current_to_destination
174
   }
166
   }
175
 
167
 
176
   feedrate_mm_s = old_feedrate_mm_s;                      // Restore original feedrate
168
   feedrate_mm_s = old_feedrate_mm_s;                      // Restore original feedrate
169
+  current_position[Z_AXIS] = old_z;                       // Restore Z and E positions
170
+  current_position[E_AXIS] = old_e;
171
+  SYNC_PLAN_POSITION_KINEMATIC();                         // As if the move never took place
177
 
172
 
178
   retracted[active_extruder] = retracting;                // Active extruder now retracted / recovered
173
   retracted[active_extruder] = retracting;                // Active extruder now retracted / recovered
179
 
174
 
189
     for (uint8_t i = 0; i < EXTRUDERS; ++i) {
184
     for (uint8_t i = 0; i < EXTRUDERS; ++i) {
190
       SERIAL_ECHOPAIR("retracted[", i);
185
       SERIAL_ECHOPAIR("retracted[", i);
191
       SERIAL_ECHOLNPAIR("] ", retracted[i]);
186
       SERIAL_ECHOLNPAIR("] ", retracted[i]);
192
-      SERIAL_ECHOPAIR("retracted_swap[", i);
193
-      SERIAL_ECHOLNPAIR("] ", retracted_swap[i]);
187
+      #if EXTRUDERS > 1
188
+        SERIAL_ECHOPAIR("retracted_swap[", i);
189
+        SERIAL_ECHOLNPAIR("] ", retracted_swap[i]);
190
+      #endif
194
     }
191
     }
195
     SERIAL_ECHOLNPAIR("current_position[z] ", current_position[Z_AXIS]);
192
     SERIAL_ECHOLNPAIR("current_position[z] ", current_position[Z_AXIS]);
196
     SERIAL_ECHOLNPAIR("current_position[e] ", current_position[E_AXIS]);
193
     SERIAL_ECHOLNPAIR("current_position[e] ", current_position[E_AXIS]);

+ 4
- 4
Marlin/src/feature/pause.cpp Целия файл

121
   set_destination_from_current();
121
   set_destination_from_current();
122
   destination[E_AXIS] += length / planner.e_factor[active_extruder];
122
   destination[E_AXIS] += length / planner.e_factor[active_extruder];
123
   planner.buffer_line_kinematic(destination, fr, active_extruder);
123
   planner.buffer_line_kinematic(destination, fr, active_extruder);
124
-  stepper.synchronize();
125
   set_current_from_destination();
124
   set_current_from_destination();
125
+  stepper.synchronize();
126
 }
126
 }
127
 
127
 
128
 /**
128
 /**
366
   #endif
366
   #endif
367
   print_job_timer.pause();
367
   print_job_timer.pause();
368
 
368
 
369
-  // Wait for synchronize steppers
370
-  stepper.synchronize();
371
-
372
   // Save current position
369
   // Save current position
373
   COPY(resume_position, current_position);
370
   COPY(resume_position, current_position);
374
 
371
 
372
+  // Wait for buffered blocks to complete
373
+  stepper.synchronize();
374
+
375
   // Initial retract before move to filament change position
375
   // Initial retract before move to filament change position
376
   if (retract && thermalManager.hotEnoughToExtrude(active_extruder))
376
   if (retract && thermalManager.hotEnoughToExtrude(active_extruder))
377
     do_pause_e_move(retract, PAUSE_PARK_RETRACT_FEEDRATE);
377
     do_pause_e_move(retract, PAUSE_PARK_RETRACT_FEEDRATE);

+ 1
- 9
Marlin/src/gcode/bedlevel/G26.cpp Целия файл

240
     destination[E_AXIS] = current_position[E_AXIS];
240
     destination[E_AXIS] = current_position[E_AXIS];
241
 
241
 
242
     G26_line_to_destination(feed_value);
242
     G26_line_to_destination(feed_value);
243
-
244
-    stepper.synchronize();
245
     set_destination_from_current();
243
     set_destination_from_current();
246
   }
244
   }
247
 
245
 
256
   destination[E_AXIS] += e_delta;
254
   destination[E_AXIS] += e_delta;
257
 
255
 
258
   G26_line_to_destination(feed_value);
256
   G26_line_to_destination(feed_value);
259
-
260
-  stepper.synchronize();
261
   set_destination_from_current();
257
   set_destination_from_current();
262
 }
258
 }
263
 
259
 
499
           if (Total_Prime >= EXTRUDE_MAXLENGTH) return G26_ERR;
495
           if (Total_Prime >= EXTRUDE_MAXLENGTH) return G26_ERR;
500
         #endif
496
         #endif
501
         G26_line_to_destination(planner.max_feedrate_mm_s[E_AXIS] / 15.0);
497
         G26_line_to_destination(planner.max_feedrate_mm_s[E_AXIS] / 15.0);
502
-
498
+        set_destination_from_current();
503
         stepper.synchronize();    // Without this synchronize, the purge is more consistent,
499
         stepper.synchronize();    // Without this synchronize, the purge is more consistent,
504
                                   // but because the planner has a buffer, we won't be able
500
                                   // but because the planner has a buffer, we won't be able
505
                                   // to stop as quickly. So we put up with the less smooth
501
                                   // to stop as quickly. So we put up with the less smooth
506
                                   // action to give the user a more responsive 'Stop'.
502
                                   // action to give the user a more responsive 'Stop'.
507
-        set_destination_from_current();
508
-        idle();
509
       }
503
       }
510
 
504
 
511
       wait_for_release();
505
       wait_for_release();
526
     set_destination_from_current();
520
     set_destination_from_current();
527
     destination[E_AXIS] += g26_prime_length;
521
     destination[E_AXIS] += g26_prime_length;
528
     G26_line_to_destination(planner.max_feedrate_mm_s[E_AXIS] / 15.0);
522
     G26_line_to_destination(planner.max_feedrate_mm_s[E_AXIS] / 15.0);
529
-    stepper.synchronize();
530
     set_destination_from_current();
523
     set_destination_from_current();
531
     retract_filament(destination);
524
     retract_filament(destination);
532
   }
525
   }
700
 
693
 
701
   if (current_position[Z_AXIS] < Z_CLEARANCE_BETWEEN_PROBES) {
694
   if (current_position[Z_AXIS] < Z_CLEARANCE_BETWEEN_PROBES) {
702
     do_blocking_move_to_z(Z_CLEARANCE_BETWEEN_PROBES);
695
     do_blocking_move_to_z(Z_CLEARANCE_BETWEEN_PROBES);
703
-    stepper.synchronize();
704
     set_current_from_destination();
696
     set_current_from_destination();
705
   }
697
   }
706
 
698
 

+ 1
- 1
Marlin/src/gcode/bedlevel/abl/G29.cpp Целия файл

949
       #if ENABLED(DEBUG_LEVELING_FEATURE)
949
       #if ENABLED(DEBUG_LEVELING_FEATURE)
950
         if (DEBUGGING(LEVELING)) SERIAL_ECHOLNPAIR("Z Probe End Script: ", Z_PROBE_END_SCRIPT);
950
         if (DEBUGGING(LEVELING)) SERIAL_ECHOLNPAIR("Z Probe End Script: ", Z_PROBE_END_SCRIPT);
951
       #endif
951
       #endif
952
-      enqueue_and_echo_commands_P(PSTR(Z_PROBE_END_SCRIPT));
953
       stepper.synchronize();
952
       stepper.synchronize();
953
+      enqueue_and_echo_commands_P(PSTR(Z_PROBE_END_SCRIPT));
954
     #endif
954
     #endif
955
 
955
 
956
     // Auto Bed Leveling is complete! Enable if possible.
956
     // Auto Bed Leveling is complete! Enable if possible.

+ 0
- 1
Marlin/src/gcode/control/M80_M81.cpp Целия файл

108
   safe_delay(1000); // Wait 1 second before switching off
108
   safe_delay(1000); // Wait 1 second before switching off
109
 
109
 
110
   #if HAS_SUICIDE
110
   #if HAS_SUICIDE
111
-    stepper.synchronize();
112
     suicide();
111
     suicide();
113
   #elif HAS_POWER_SWITCH
112
   #elif HAS_POWER_SWITCH
114
     PSU_OFF();
113
     PSU_OFF();

+ 2
- 6
Marlin/src/gcode/geometry/G92.cpp Целия файл

33
  */
33
  */
34
 void GcodeSuite::G92() {
34
 void GcodeSuite::G92() {
35
 
35
 
36
-  stepper.synchronize();
37
-
38
   #if ENABLED(CNC_COORDINATE_SYSTEMS)
36
   #if ENABLED(CNC_COORDINATE_SYSTEMS)
39
     switch (parser.subcode) {
37
     switch (parser.subcode) {
40
       case 1:
38
       case 1:
94
       COPY(coordinate_system[active_coordinate_system], position_shift);
92
       COPY(coordinate_system[active_coordinate_system], position_shift);
95
   #endif
93
   #endif
96
 
94
 
97
-  if (didXYZ)
98
-    SYNC_PLAN_POSITION_KINEMATIC();
99
-  else if (didE)
100
-    sync_plan_position_e();
95
+  if    (didXYZ) SYNC_PLAN_POSITION_KINEMATIC();
96
+  else if (didE) sync_plan_position_e();
101
 
97
 
102
   report_current_position();
98
   report_current_position();
103
 }
99
 }

+ 2
- 2
Marlin/src/gcode/host/M114.cpp Целия файл

43
 
43
 
44
   void report_current_position_detail() {
44
   void report_current_position_detail() {
45
 
45
 
46
-    stepper.synchronize();
47
-
48
     SERIAL_PROTOCOLPGM("\nLogical:");
46
     SERIAL_PROTOCOLPGM("\nLogical:");
49
     const float logical[XYZ] = {
47
     const float logical[XYZ] = {
50
       LOGICAL_X_POSITION(current_position[X_AXIS]),
48
       LOGICAL_X_POSITION(current_position[X_AXIS]),
79
       report_xyz(delta);
77
       report_xyz(delta);
80
     #endif
78
     #endif
81
 
79
 
80
+    stepper.synchronize();
81
+
82
     SERIAL_PROTOCOLPGM("Stepper:");
82
     SERIAL_PROTOCOLPGM("Stepper:");
83
     LOOP_XYZE(i) {
83
     LOOP_XYZE(i) {
84
       SERIAL_CHAR(' ');
84
       SERIAL_CHAR(' ');

+ 2
- 2
Marlin/src/gcode/lcd/M0_M1.cpp Целия файл

58
 
58
 
59
   const bool has_message = !hasP && !hasS && args && *args;
59
   const bool has_message = !hasP && !hasS && args && *args;
60
 
60
 
61
+  stepper.synchronize();
62
+
61
   #if ENABLED(ULTIPANEL)
63
   #if ENABLED(ULTIPANEL)
62
 
64
 
63
     if (has_message)
65
     if (has_message)
81
   KEEPALIVE_STATE(PAUSED_FOR_USER);
83
   KEEPALIVE_STATE(PAUSED_FOR_USER);
82
   wait_for_user = true;
84
   wait_for_user = true;
83
 
85
 
84
-  stepper.synchronize();
85
-
86
   if (ms > 0) {
86
   if (ms > 0) {
87
     ms += millis();  // wait until this time for a click
87
     ms += millis();  // wait until this time for a click
88
     while (PENDING(millis(), ms) && wait_for_user) idle();
88
     while (PENDING(millis(), ms) && wait_for_user) idle();

+ 4
- 4
Marlin/src/module/motion.cpp Целия файл

396
 
396
 
397
   #endif
397
   #endif
398
 
398
 
399
-  stepper.synchronize();
400
-
401
   feedrate_mm_s = old_feedrate_mm_s;
399
   feedrate_mm_s = old_feedrate_mm_s;
402
 
400
 
403
   #if ENABLED(DEBUG_LEVELING_FEATURE)
401
   #if ENABLED(DEBUG_LEVELING_FEATURE)
404
     if (DEBUGGING(LEVELING)) SERIAL_ECHOLNPGM("<<< do_blocking_move_to");
402
     if (DEBUGGING(LEVELING)) SERIAL_ECHOLNPGM("<<< do_blocking_move_to");
405
   #endif
403
   #endif
404
+
405
+  stepper.synchronize();
406
 }
406
 }
407
 void do_blocking_move_to_x(const float &rx, const float &fr_mm_s/*=0.0*/) {
407
 void do_blocking_move_to_x(const float &rx, const float &fr_mm_s/*=0.0*/) {
408
   do_blocking_move_to(rx, current_position[Y_AXIS], current_position[Z_AXIS], fr_mm_s);
408
   do_blocking_move_to(rx, current_position[Y_AXIS], current_position[Z_AXIS], fr_mm_s);
881
               current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS],
881
               current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS],
882
               planner.max_feedrate_mm_s[X_AXIS], 1
882
               planner.max_feedrate_mm_s[X_AXIS], 1
883
             );
883
             );
884
-            SYNC_PLAN_POSITION_KINEMATIC();
885
             stepper.synchronize();
884
             stepper.synchronize();
885
+            SYNC_PLAN_POSITION_KINEMATIC();
886
             extruder_duplication_enabled = true;
886
             extruder_duplication_enabled = true;
887
             active_extruder_parked = false;
887
             active_extruder_parked = false;
888
             #if ENABLED(DEBUG_LEVELING_FEATURE)
888
             #if ENABLED(DEBUG_LEVELING_FEATURE)
1106
     planner.buffer_line(delta[A_AXIS], delta[B_AXIS], delta[C_AXIS], current_position[E_AXIS], fr_mm_s ? fr_mm_s : homing_feedrate(axis), active_extruder);
1106
     planner.buffer_line(delta[A_AXIS], delta[B_AXIS], delta[C_AXIS], current_position[E_AXIS], fr_mm_s ? fr_mm_s : homing_feedrate(axis), active_extruder);
1107
   #else
1107
   #else
1108
     sync_plan_position();
1108
     sync_plan_position();
1109
-    current_position[axis] = distance;
1109
+    current_position[axis] = distance; // Set delta/cartesian axes directly
1110
     planner.buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], fr_mm_s ? fr_mm_s : homing_feedrate(axis), active_extruder);
1110
     planner.buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], fr_mm_s ? fr_mm_s : homing_feedrate(axis), active_extruder);
1111
   #endif
1111
   #endif
1112
 
1112
 

+ 36
- 22
Marlin/src/module/planner.cpp Целия файл

1382
   const float esteps_float = de * e_factor[extruder];
1382
   const float esteps_float = de * e_factor[extruder];
1383
   const int32_t esteps = abs(esteps_float) + 0.5;
1383
   const int32_t esteps = abs(esteps_float) + 0.5;
1384
 
1384
 
1385
-  // Calculate the buffer head after we push this byte
1386
-  const uint8_t next_buffer_head = next_block_index(block_buffer_head);
1387
-
1388
-  // If the buffer is full: good! That means we are well ahead of the robot.
1389
-  // Rest here until there is room in the buffer.
1390
-  while (block_buffer_tail == next_buffer_head) idle();
1391
-
1392
-  // Prepare to set up new block
1393
-  block_t* block = &block_buffer[block_buffer_head];
1385
+  // Wait for the next available block
1386
+  uint8_t next_buffer_head;
1387
+  block_t * const block = get_next_free_block(next_buffer_head);
1394
 
1388
 
1395
   // Clear all flags, including the "busy" bit
1389
   // Clear all flags, including the "busy" bit
1396
   block->flag = 0x00;
1390
   block->flag = 0x00;
2033
 } // _buffer_steps()
2027
 } // _buffer_steps()
2034
 
2028
 
2035
 /**
2029
 /**
2030
+ * Planner::buffer_sync_block
2031
+ * Add a block to the buffer that just updates the position
2032
+ */
2033
+void Planner::buffer_sync_block() {
2034
+  // Wait for the next available block
2035
+  uint8_t next_buffer_head;
2036
+  block_t * const block = get_next_free_block(next_buffer_head);
2037
+
2038
+  block->steps[A_AXIS] = position[A_AXIS];
2039
+  block->steps[B_AXIS] = position[B_AXIS];
2040
+  block->steps[C_AXIS] = position[C_AXIS];
2041
+  block->steps[E_AXIS] = position[E_AXIS];
2042
+
2043
+  block->flag = BLOCK_FLAG_SYNC_POSITION;
2044
+
2045
+  block_buffer_head = next_buffer_head;
2046
+  stepper.wake_up();
2047
+} // buffer_sync_block()
2048
+
2049
+/**
2036
  * Planner::buffer_segment
2050
  * Planner::buffer_segment
2037
  *
2051
  *
2038
  * Add a new linear movement to the buffer in axis units.
2052
  * Add a new linear movement to the buffer in axis units.
2160
   #else
2174
   #else
2161
     #define _EINDEX E_AXIS
2175
     #define _EINDEX E_AXIS
2162
   #endif
2176
   #endif
2163
-  const int32_t na = position[A_AXIS] = LROUND(a * axis_steps_per_mm[A_AXIS]),
2164
-                nb = position[B_AXIS] = LROUND(b * axis_steps_per_mm[B_AXIS]),
2165
-                nc = position[C_AXIS] = LROUND(c * axis_steps_per_mm[C_AXIS]),
2166
-                ne = position[E_AXIS] = LROUND(e * axis_steps_per_mm[_EINDEX]);
2177
+  position[A_AXIS] = LROUND(a * axis_steps_per_mm[A_AXIS]),
2178
+  position[B_AXIS] = LROUND(b * axis_steps_per_mm[B_AXIS]),
2179
+  position[C_AXIS] = LROUND(c * axis_steps_per_mm[C_AXIS]),
2180
+  position[E_AXIS] = LROUND(e * axis_steps_per_mm[_EINDEX]);
2167
   #if HAS_POSITION_FLOAT
2181
   #if HAS_POSITION_FLOAT
2168
-    position_float[X_AXIS] = a;
2169
-    position_float[Y_AXIS] = b;
2170
-    position_float[Z_AXIS] = c;
2182
+    position_float[A_AXIS] = a;
2183
+    position_float[B_AXIS] = b;
2184
+    position_float[C_AXIS] = c;
2171
     position_float[E_AXIS] = e;
2185
     position_float[E_AXIS] = e;
2172
   #endif
2186
   #endif
2173
-  stepper.set_position(na, nb, nc, ne);
2174
   previous_nominal_speed = 0.0; // Resets planner junction speeds. Assumes start from rest.
2187
   previous_nominal_speed = 0.0; // Resets planner junction speeds. Assumes start from rest.
2175
   ZERO(previous_speed);
2188
   ZERO(previous_speed);
2189
+  buffer_sync_block();
2176
 }
2190
 }
2177
 
2191
 
2178
 void Planner::set_position_mm_kinematic(const float (&cart)[XYZE]) {
2192
 void Planner::set_position_mm_kinematic(const float (&cart)[XYZE]) {
2220
   #if HAS_POSITION_FLOAT
2234
   #if HAS_POSITION_FLOAT
2221
     position_float[axis] = v;
2235
     position_float[axis] = v;
2222
   #endif
2236
   #endif
2223
-  stepper.set_position(axis, position[axis]);
2224
   previous_speed[axis] = 0.0;
2237
   previous_speed[axis] = 0.0;
2238
+  buffer_sync_block();
2225
 }
2239
 }
2226
 
2240
 
2227
 // Recalculate the steps/s^2 acceleration rates, based on the mm/s^2
2241
 // Recalculate the steps/s^2 acceleration rates, based on the mm/s^2
2228
 void Planner::reset_acceleration_rates() {
2242
 void Planner::reset_acceleration_rates() {
2229
   #if ENABLED(DISTINCT_E_FACTORS)
2243
   #if ENABLED(DISTINCT_E_FACTORS)
2230
-    #define HIGHEST_CONDITION (i < E_AXIS || i == E_AXIS + active_extruder)
2244
+    #define AXIS_CONDITION (i < E_AXIS || i == E_AXIS + active_extruder)
2231
   #else
2245
   #else
2232
-    #define HIGHEST_CONDITION true
2246
+    #define AXIS_CONDITION true
2233
   #endif
2247
   #endif
2234
   uint32_t highest_rate = 1;
2248
   uint32_t highest_rate = 1;
2235
   LOOP_XYZE_N(i) {
2249
   LOOP_XYZE_N(i) {
2236
     max_acceleration_steps_per_s2[i] = max_acceleration_mm_per_s2[i] * axis_steps_per_mm[i];
2250
     max_acceleration_steps_per_s2[i] = max_acceleration_mm_per_s2[i] * axis_steps_per_mm[i];
2237
-    if (HIGHEST_CONDITION) NOLESS(highest_rate, max_acceleration_steps_per_s2[i]);
2251
+    if (AXIS_CONDITION) NOLESS(highest_rate, max_acceleration_steps_per_s2[i]);
2238
   }
2252
   }
2239
-  cutoff_long = 4294967295UL / highest_rate;
2253
+  cutoff_long = 4294967295UL / highest_rate; // 0xFFFFFFFFUL
2240
 }
2254
 }
2241
 
2255
 
2242
 // Recalculate position, steps_to_mm if axis_steps_per_mm changes!
2256
 // Recalculate position, steps_to_mm if axis_steps_per_mm changes!

+ 28
- 4
Marlin/src/module/planner.h Целия файл

57
   BLOCK_BIT_BUSY,
57
   BLOCK_BIT_BUSY,
58
 
58
 
59
   // The block is segment 2+ of a longer move
59
   // The block is segment 2+ of a longer move
60
-  BLOCK_BIT_CONTINUED
60
+  BLOCK_BIT_CONTINUED,
61
+
62
+  // Sync the stepper counts from the block
63
+  BLOCK_BIT_SYNC_POSITION
61
 };
64
 };
62
 
65
 
63
 enum BlockFlag : char {
66
 enum BlockFlag : char {
64
   BLOCK_FLAG_RECALCULATE          = _BV(BLOCK_BIT_RECALCULATE),
67
   BLOCK_FLAG_RECALCULATE          = _BV(BLOCK_BIT_RECALCULATE),
65
   BLOCK_FLAG_NOMINAL_LENGTH       = _BV(BLOCK_BIT_NOMINAL_LENGTH),
68
   BLOCK_FLAG_NOMINAL_LENGTH       = _BV(BLOCK_BIT_NOMINAL_LENGTH),
66
   BLOCK_FLAG_BUSY                 = _BV(BLOCK_BIT_BUSY),
69
   BLOCK_FLAG_BUSY                 = _BV(BLOCK_BIT_BUSY),
67
-  BLOCK_FLAG_CONTINUED            = _BV(BLOCK_BIT_CONTINUED)
70
+  BLOCK_FLAG_CONTINUED            = _BV(BLOCK_BIT_CONTINUED),
71
+  BLOCK_FLAG_SYNC_POSITION        = _BV(BLOCK_BIT_SYNC_POSITION)
68
 };
72
 };
69
 
73
 
70
 /**
74
 /**
422
 
426
 
423
     #endif
427
     #endif
424
 
428
 
429
+
430
+    /**
431
+     * Planner::get_next_free_block
432
+     *
433
+     * - Get the next head index (passed by reference)
434
+     * - Wait for a space to open up in the planner
435
+     * - Return the head block
436
+     */
437
+    FORCE_INLINE static block_t* get_next_free_block(uint8_t &next_buffer_head) {
438
+      next_buffer_head = next_block_index(block_buffer_head);
439
+      while (block_buffer_tail == next_buffer_head) idle(); // while (is_full)
440
+      return &block_buffer[block_buffer_head];
441
+    }
442
+
425
     /**
443
     /**
426
      * Planner::_buffer_steps
444
      * Planner::_buffer_steps
427
      *
445
      *
440
     );
458
     );
441
 
459
 
442
     /**
460
     /**
461
+     * Planner::buffer_sync_block
462
+     * Add a block to the buffer that just updates the position
463
+     */
464
+    static void buffer_sync_block();
465
+
466
+    /**
443
      * Planner::buffer_segment
467
      * Planner::buffer_segment
444
      *
468
      *
445
      * Add a new linear movement to the buffer in axis units.
469
      * Add a new linear movement to the buffer in axis units.
518
     static void set_position_mm_kinematic(const float (&cart)[XYZE]);
542
     static void set_position_mm_kinematic(const float (&cart)[XYZE]);
519
     static void set_position_mm(const AxisEnum axis, const float &v);
543
     static void set_position_mm(const AxisEnum axis, const float &v);
520
     FORCE_INLINE static void set_z_position_mm(const float &z) { set_position_mm(Z_AXIS, z); }
544
     FORCE_INLINE static void set_z_position_mm(const float &z) { set_position_mm(Z_AXIS, z); }
521
-    FORCE_INLINE static void set_e_position_mm(const float &e) { set_position_mm(AxisEnum(E_AXIS), e); }
545
+    FORCE_INLINE static void set_e_position_mm(const float &e) { set_position_mm(E_AXIS, e); }
522
 
546
 
523
     /**
547
     /**
524
      * Sync from the stepper positions. (e.g., after an interrupted move)
548
      * Sync from the stepper positions. (e.g., after an interrupted move)
528
     /**
552
     /**
529
      * Does the buffer have any blocks queued?
553
      * Does the buffer have any blocks queued?
530
      */
554
      */
531
-    static bool has_blocks_queued() { return (block_buffer_head != block_buffer_tail); }
555
+    FORCE_INLINE static bool has_blocks_queued() { return (block_buffer_head != block_buffer_tail); }
532
 
556
 
533
     /**
557
     /**
534
      * "Discard" the block and "release" the memory.
558
      * "Discard" the block and "release" the memory.

+ 22
- 31
Marlin/src/module/stepper.cpp Целия файл

109
   bool Stepper::locked_z_motor = false, Stepper::locked_z2_motor = false;
109
   bool Stepper::locked_z_motor = false, Stepper::locked_z2_motor = false;
110
 #endif
110
 #endif
111
 
111
 
112
-long Stepper::counter_X = 0,
113
-     Stepper::counter_Y = 0,
114
-     Stepper::counter_Z = 0,
115
-     Stepper::counter_E = 0;
112
+int32_t Stepper::counter_X = 0,
113
+        Stepper::counter_Y = 0,
114
+        Stepper::counter_Z = 0,
115
+        Stepper::counter_E = 0;
116
 
116
 
117
 volatile uint32_t Stepper::step_events_completed = 0; // The number of step events executed in the current block
117
 volatile uint32_t Stepper::step_events_completed = 0; // The number of step events executed in the current block
118
 
118
 
159
 volatile signed char Stepper::count_direction[NUM_AXIS] = { 1, 1, 1, 1 };
159
 volatile signed char Stepper::count_direction[NUM_AXIS] = { 1, 1, 1, 1 };
160
 
160
 
161
 #if ENABLED(MIXING_EXTRUDER)
161
 #if ENABLED(MIXING_EXTRUDER)
162
-  long Stepper::counter_m[MIXING_STEPPERS];
162
+  int32_t Stepper::counter_m[MIXING_STEPPERS];
163
 #endif
163
 #endif
164
 
164
 
165
 uint8_t Stepper::step_loops, Stepper::step_loops_nominal;
165
 uint8_t Stepper::step_loops, Stepper::step_loops_nominal;
169
   hal_timer_t Stepper::acc_step_rate; // needed for deceleration start point
169
   hal_timer_t Stepper::acc_step_rate; // needed for deceleration start point
170
 #endif
170
 #endif
171
 
171
 
172
-volatile long Stepper::endstops_trigsteps[XYZ];
172
+volatile int32_t Stepper::endstops_trigsteps[XYZ];
173
 
173
 
174
 #if ENABLED(X_DUAL_ENDSTOPS) || ENABLED(Y_DUAL_ENDSTOPS) || ENABLED(Z_DUAL_ENDSTOPS)
174
 #if ENABLED(X_DUAL_ENDSTOPS) || ENABLED(Y_DUAL_ENDSTOPS) || ENABLED(Z_DUAL_ENDSTOPS)
175
   #define LOCKED_X_MOTOR  locked_x_motor
175
   #define LOCKED_X_MOTOR  locked_x_motor
1217
     // Anything in the buffer?
1217
     // Anything in the buffer?
1218
     if ((current_block = planner.get_current_block())) {
1218
     if ((current_block = planner.get_current_block())) {
1219
 
1219
 
1220
+      // Sync block? Sync the stepper counts and return
1221
+      while (TEST(current_block->flag, BLOCK_BIT_SYNC_POSITION)) {
1222
+        _set_position(
1223
+          current_block->steps[A_AXIS], current_block->steps[B_AXIS],
1224
+          current_block->steps[C_AXIS], current_block->steps[E_AXIS]
1225
+        );
1226
+        planner.discard_current_block();
1227
+        if (!(current_block = planner.get_current_block())) return;
1228
+      }
1229
+
1220
       // Initialize the trapezoid generator from the current block.
1230
       // Initialize the trapezoid generator from the current block.
1221
       static int8_t last_extruder = -1;
1231
       static int8_t last_extruder = -1;
1222
 
1232
 
1976
  * This allows get_axis_position_mm to correctly
1986
  * This allows get_axis_position_mm to correctly
1977
  * derive the current XYZ position later on.
1987
  * derive the current XYZ position later on.
1978
  */
1988
  */
1979
-void Stepper::set_position(const long &a, const long &b, const long &c, const long &e) {
1980
-
1981
-  synchronize(); // Bad to set stepper counts in the middle of a move
1982
-
1983
-  CRITICAL_SECTION_START;
1984
-
1989
+void Stepper::_set_position(const int32_t &a, const int32_t &b, const int32_t &c, const int32_t &e) {
1985
   #if CORE_IS_XY
1990
   #if CORE_IS_XY
1986
     // corexy positioning
1991
     // corexy positioning
1987
     // these equations follow the form of the dA and dB equations on http://www.corexy.com/theory.html
1992
     // these equations follow the form of the dA and dB equations on http://www.corexy.com/theory.html
2004
     count_position[Y_AXIS] = b;
2009
     count_position[Y_AXIS] = b;
2005
     count_position[Z_AXIS] = c;
2010
     count_position[Z_AXIS] = c;
2006
   #endif
2011
   #endif
2007
-
2008
-  count_position[E_AXIS] = e;
2009
-  CRITICAL_SECTION_END;
2010
-}
2011
-
2012
-void Stepper::set_position(const AxisEnum &axis, const long &v) {
2013
-  CRITICAL_SECTION_START;
2014
-  count_position[axis] = v;
2015
-  CRITICAL_SECTION_END;
2016
-}
2017
-
2018
-void Stepper::set_e_position(const long &e) {
2019
-  CRITICAL_SECTION_START;
2020
   count_position[E_AXIS] = e;
2012
   count_position[E_AXIS] = e;
2021
-  CRITICAL_SECTION_END;
2022
 }
2013
 }
2023
 
2014
 
2024
 /**
2015
 /**
2025
  * Get a stepper's position in steps.
2016
  * Get a stepper's position in steps.
2026
  */
2017
  */
2027
-long Stepper::position(const AxisEnum axis) {
2018
+int32_t Stepper::position(const AxisEnum axis) {
2028
   CRITICAL_SECTION_START;
2019
   CRITICAL_SECTION_START;
2029
-  const long count_pos = count_position[axis];
2020
+  const int32_t count_pos = count_position[axis];
2030
   CRITICAL_SECTION_END;
2021
   CRITICAL_SECTION_END;
2031
   return count_pos;
2022
   return count_pos;
2032
 }
2023
 }
2095
 
2086
 
2096
 void Stepper::report_positions() {
2087
 void Stepper::report_positions() {
2097
   CRITICAL_SECTION_START;
2088
   CRITICAL_SECTION_START;
2098
-  const long xpos = count_position[X_AXIS],
2099
-             ypos = count_position[Y_AXIS],
2100
-             zpos = count_position[Z_AXIS];
2089
+  const int32_t xpos = count_position[X_AXIS],
2090
+                ypos = count_position[Y_AXIS],
2091
+                zpos = count_position[Z_AXIS];
2101
   CRITICAL_SECTION_END;
2092
   CRITICAL_SECTION_END;
2102
 
2093
 
2103
   #if CORE_IS_XY || CORE_IS_XZ || IS_DELTA || IS_SCARA
2094
   #if CORE_IS_XY || CORE_IS_XZ || IS_DELTA || IS_SCARA

+ 31
- 8
Marlin/src/module/stepper.h Целия файл

94
     #endif
94
     #endif
95
 
95
 
96
     // Counter variables for the Bresenham line tracer
96
     // Counter variables for the Bresenham line tracer
97
-    static long counter_X, counter_Y, counter_Z, counter_E;
97
+    static int32_t counter_X, counter_Y, counter_Z, counter_E;
98
     static volatile uint32_t step_events_completed; // The number of step events executed in the current block
98
     static volatile uint32_t step_events_completed; // The number of step events executed in the current block
99
 
99
 
100
     #if ENABLED(BEZIER_JERK_CONTROL)
100
     #if ENABLED(BEZIER_JERK_CONTROL)
137
       static hal_timer_t acc_step_rate; // needed for deceleration start point
137
       static hal_timer_t acc_step_rate; // needed for deceleration start point
138
     #endif
138
     #endif
139
 
139
 
140
-    static volatile long endstops_trigsteps[XYZ];
141
-    static volatile long endstops_stepsTotal, endstops_stepsDone;
140
+    static volatile int32_t endstops_trigsteps[XYZ];
141
+    static volatile int32_t endstops_stepsTotal, endstops_stepsDone;
142
 
142
 
143
     //
143
     //
144
     // Positions of stepper motors, in step units
144
     // Positions of stepper motors, in step units
154
     // Mixing extruder mix counters
154
     // Mixing extruder mix counters
155
     //
155
     //
156
     #if ENABLED(MIXING_EXTRUDER)
156
     #if ENABLED(MIXING_EXTRUDER)
157
-      static long counter_m[MIXING_STEPPERS];
157
+      static int32_t counter_m[MIXING_STEPPERS];
158
       #define MIXING_STEPPERS_LOOP(VAR) \
158
       #define MIXING_STEPPERS_LOOP(VAR) \
159
         for (uint8_t VAR = 0; VAR < MIXING_STEPPERS; VAR++) \
159
         for (uint8_t VAR = 0; VAR < MIXING_STEPPERS; VAR++) \
160
           if (current_block->mix_event_count[VAR])
160
           if (current_block->mix_event_count[VAR])
191
     //
191
     //
192
     // Set the current position in steps
192
     // Set the current position in steps
193
     //
193
     //
194
-    static void set_position(const long &a, const long &b, const long &c, const long &e);
195
-    static void set_position(const AxisEnum &a, const long &v);
196
-    static void set_e_position(const long &e);
194
+    static void _set_position(const int32_t &a, const int32_t &b, const int32_t &c, const int32_t &e);
195
+
196
+    FORCE_INLINE static void _set_position(const AxisEnum a, const int32_t &v) { count_position[a] = v; }
197
+
198
+    FORCE_INLINE static void set_position(const int32_t &a, const int32_t &b, const int32_t &c, const int32_t &e) {
199
+      synchronize();
200
+      CRITICAL_SECTION_START;
201
+      _set_position(a, b, c, e);
202
+      CRITICAL_SECTION_END;
203
+    }
204
+
205
+    static void set_position(const AxisEnum a, const int32_t &v) {
206
+      synchronize();
207
+      CRITICAL_SECTION_START;
208
+      count_position[a] = v;
209
+      CRITICAL_SECTION_END;
210
+    }
211
+
212
+    FORCE_INLINE static void _set_e_position(const int32_t &e) { count_position[E_AXIS] = e; }
213
+
214
+    static void set_e_position(const int32_t &e) {
215
+      synchronize();
216
+      CRITICAL_SECTION_START;
217
+      count_position[E_AXIS] = e;
218
+      CRITICAL_SECTION_END;
219
+    }
197
 
220
 
198
     //
221
     //
199
     // Set direction bits for all steppers
222
     // Set direction bits for all steppers
203
     //
226
     //
204
     // Get the position of a stepper, in steps
227
     // Get the position of a stepper, in steps
205
     //
228
     //
206
-    static long position(const AxisEnum axis);
229
+    static int32_t position(const AxisEnum axis);
207
 
230
 
208
     //
231
     //
209
     // Report the positions of the steppers, in steps
232
     // Report the positions of the steppers, in steps

Loading…
Отказ
Запис