|
@@ -149,7 +149,7 @@ void Planner::init() {
|
149
|
149
|
* Calculate trapezoid parameters, multiplying the entry- and exit-speeds
|
150
|
150
|
* by the provided factors.
|
151
|
151
|
*/
|
152
|
|
-void Planner::calculate_trapezoid_for_block(block_t* block, float entry_factor, float exit_factor) {
|
|
152
|
+void Planner::calculate_trapezoid_for_block(block_t* const block, const float &entry_factor, const float &exit_factor) {
|
153
|
153
|
uint32_t initial_rate = ceil(block->nominal_rate * entry_factor),
|
154
|
154
|
final_rate = ceil(block->nominal_rate * exit_factor); // (steps per second)
|
155
|
155
|
|
|
@@ -203,29 +203,20 @@ void Planner::calculate_trapezoid_for_block(block_t* block, float entry_factor,
|
203
|
203
|
|
204
|
204
|
|
205
|
205
|
// The kernel called by recalculate() when scanning the plan from last to first entry.
|
206
|
|
-void Planner::reverse_pass_kernel(block_t* current, block_t* next) {
|
207
|
|
- if (!current) return;
|
208
|
|
-
|
209
|
|
- if (next) {
|
210
|
|
- // If entry speed is already at the maximum entry speed, no need to recheck. Block is cruising.
|
211
|
|
- // If not, block in state of acceleration or deceleration. Reset entry speed to maximum and
|
212
|
|
- // check for maximum allowable speed reductions to ensure maximum possible planned speed.
|
213
|
|
- float max_entry_speed = current->max_entry_speed;
|
214
|
|
- if (current->entry_speed != max_entry_speed) {
|
215
|
|
-
|
216
|
|
- // If nominal length true, max junction speed is guaranteed to be reached. Only compute
|
217
|
|
- // for max allowable speed if block is decelerating and nominal length is false.
|
218
|
|
- if (!current->nominal_length_flag && max_entry_speed > next->entry_speed) {
|
219
|
|
- current->entry_speed = min(max_entry_speed,
|
220
|
|
- max_allowable_speed(-current->acceleration, next->entry_speed, current->millimeters));
|
221
|
|
- }
|
222
|
|
- else {
|
223
|
|
- current->entry_speed = max_entry_speed;
|
224
|
|
- }
|
225
|
|
- current->recalculate_flag = true;
|
226
|
|
-
|
227
|
|
- }
|
228
|
|
- } // Skip last block. Already initialized and set for recalculation.
|
|
206
|
+void Planner::reverse_pass_kernel(block_t* const current, const block_t *next) {
|
|
207
|
+ if (!current || !next) return;
|
|
208
|
+ // If entry speed is already at the maximum entry speed, no need to recheck. Block is cruising.
|
|
209
|
+ // If not, block in state of acceleration or deceleration. Reset entry speed to maximum and
|
|
210
|
+ // check for maximum allowable speed reductions to ensure maximum possible planned speed.
|
|
211
|
+ float max_entry_speed = current->max_entry_speed;
|
|
212
|
+ if (current->entry_speed != max_entry_speed) {
|
|
213
|
+ // If nominal length true, max junction speed is guaranteed to be reached. Only compute
|
|
214
|
+ // for max allowable speed if block is decelerating and nominal length is false.
|
|
215
|
+ current->entry_speed = ((current->flag & BLOCK_FLAG_NOMINAL_LENGTH) || max_entry_speed <= next->entry_speed)
|
|
216
|
+ ? max_entry_speed
|
|
217
|
+ : min(max_entry_speed, max_allowable_speed(-current->acceleration, next->entry_speed, current->millimeters));
|
|
218
|
+ current->flag |= BLOCK_FLAG_RECALCULATE;
|
|
219
|
+ }
|
229
|
220
|
}
|
230
|
221
|
|
231
|
222
|
/**
|
|
@@ -255,21 +246,21 @@ void Planner::reverse_pass() {
|
255
|
246
|
}
|
256
|
247
|
|
257
|
248
|
// The kernel called by recalculate() when scanning the plan from first to last entry.
|
258
|
|
-void Planner::forward_pass_kernel(block_t* previous, block_t* current) {
|
|
249
|
+void Planner::forward_pass_kernel(const block_t* previous, block_t* const current) {
|
259
|
250
|
if (!previous) return;
|
260
|
251
|
|
261
|
252
|
// If the previous block is an acceleration block, but it is not long enough to complete the
|
262
|
253
|
// full speed change within the block, we need to adjust the entry speed accordingly. Entry
|
263
|
254
|
// speeds have already been reset, maximized, and reverse planned by reverse planner.
|
264
|
255
|
// If nominal length is true, max junction speed is guaranteed to be reached. No need to recheck.
|
265
|
|
- if (!previous->nominal_length_flag) {
|
|
256
|
+ if (!(previous->flag & BLOCK_FLAG_NOMINAL_LENGTH)) {
|
266
|
257
|
if (previous->entry_speed < current->entry_speed) {
|
267
|
258
|
float entry_speed = min(current->entry_speed,
|
268
|
259
|
max_allowable_speed(-previous->acceleration, previous->entry_speed, previous->millimeters));
|
269
|
260
|
// Check for junction speed change
|
270
|
261
|
if (current->entry_speed != entry_speed) {
|
271
|
262
|
current->entry_speed = entry_speed;
|
272
|
|
- current->recalculate_flag = true;
|
|
263
|
+ current->flag |= BLOCK_FLAG_RECALCULATE;
|
273
|
264
|
}
|
274
|
265
|
}
|
275
|
266
|
}
|
|
@@ -298,19 +289,18 @@ void Planner::forward_pass() {
|
298
|
289
|
*/
|
299
|
290
|
void Planner::recalculate_trapezoids() {
|
300
|
291
|
int8_t block_index = block_buffer_tail;
|
301
|
|
- block_t* current;
|
302
|
|
- block_t* next = NULL;
|
|
292
|
+ block_t *current, *next = NULL;
|
303
|
293
|
|
304
|
294
|
while (block_index != block_buffer_head) {
|
305
|
295
|
current = next;
|
306
|
296
|
next = &block_buffer[block_index];
|
307
|
297
|
if (current) {
|
308
|
298
|
// Recalculate if current block entry or exit junction speed has changed.
|
309
|
|
- if (current->recalculate_flag || next->recalculate_flag) {
|
|
299
|
+ if ((current->flag & BLOCK_FLAG_RECALCULATE) || (next->flag & BLOCK_FLAG_RECALCULATE)) {
|
310
|
300
|
// NOTE: Entry and exit factors always > 0 by all previous logic operations.
|
311
|
301
|
float nom = current->nominal_speed;
|
312
|
302
|
calculate_trapezoid_for_block(current, current->entry_speed / nom, next->entry_speed / nom);
|
313
|
|
- current->recalculate_flag = false; // Reset current only to ensure next trapezoid is computed
|
|
303
|
+ current->flag &= ~BLOCK_FLAG_RECALCULATE; // Reset current only to ensure next trapezoid is computed
|
314
|
304
|
}
|
315
|
305
|
}
|
316
|
306
|
block_index = next_block_index(block_index);
|
|
@@ -319,7 +309,7 @@ void Planner::recalculate_trapezoids() {
|
319
|
309
|
if (next) {
|
320
|
310
|
float nom = next->nominal_speed;
|
321
|
311
|
calculate_trapezoid_for_block(next, next->entry_speed / nom, (MINIMUM_PLANNER_SPEED) / nom);
|
322
|
|
- next->recalculate_flag = false;
|
|
312
|
+ next->flag &= ~BLOCK_FLAG_RECALCULATE;
|
323
|
313
|
}
|
324
|
314
|
}
|
325
|
315
|
|
|
@@ -1119,8 +1109,9 @@ void Planner::_buffer_line(const float &a, const float &b, const float &c, const
|
1119
|
1109
|
// block nominal speed limits both the current and next maximum junction speeds. Hence, in both
|
1120
|
1110
|
// the reverse and forward planners, the corresponding block junction speed will always be at the
|
1121
|
1111
|
// the maximum junction speed and may always be ignored for any speed reduction checks.
|
1122
|
|
- block->nominal_length_flag = (block->nominal_speed <= v_allowable);
|
1123
|
|
- block->recalculate_flag = true; // Always calculate trapezoid for new block
|
|
1112
|
+ block->flag &= ~BLOCK_FLAG_NOMINAL_LENGTH;
|
|
1113
|
+ if (block->nominal_speed <= v_allowable) block->flag |= BLOCK_FLAG_NOMINAL_LENGTH;
|
|
1114
|
+ block->flag |= BLOCK_FLAG_RECALCULATE; // Always calculate trapezoid for new block
|
1124
|
1115
|
|
1125
|
1116
|
// Update previous path unit_vector and nominal speed
|
1126
|
1117
|
memcpy(previous_speed, current_speed, sizeof(previous_speed));
|