Browse Source

Fixed AD595 define

Erik van der Zalm 12 years ago
parent
commit
b67dacdc8f
3 changed files with 261 additions and 213 deletions
  1. 258
    208
      Marlin/planner.cpp
  2. 1
    3
      Marlin/stepper.cpp
  3. 2
    2
      Marlin/ultralcd.pde

+ 258
- 208
Marlin/planner.cpp View File

1
 /*
1
 /*
2
   planner.c - buffers movement commands and manages the acceleration profile plan
2
   planner.c - buffers movement commands and manages the acceleration profile plan
3
-  Part of Grbl
4
-
5
-  Copyright (c) 2009-2011 Simen Svale Skogsrud
6
-
7
-  Grbl is free software: you can redistribute it and/or modify
8
-  it under the terms of the GNU General Public License as published by
9
-  the Free Software Foundation, either version 3 of the License, or
10
-  (at your option) any later version.
11
-
12
-  Grbl is distributed in the hope that it will be useful,
13
-  but WITHOUT ANY WARRANTY; without even the implied warranty of
14
-  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
-  GNU General Public License for more details.
16
-
17
-  You should have received a copy of the GNU General Public License
18
-  along with Grbl.  If not, see <http://www.gnu.org/licenses/>.
19
-*/
3
+ Part of Grbl
4
+ 
5
+ Copyright (c) 2009-2011 Simen Svale Skogsrud
6
+ 
7
+ Grbl is free software: you can redistribute it and/or modify
8
+ it under the terms of the GNU General Public License as published by
9
+ the Free Software Foundation, either version 3 of the License, or
10
+ (at your option) any later version.
11
+ 
12
+ Grbl is distributed in the hope that it will be useful,
13
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
+ GNU General Public License for more details.
16
+ 
17
+ You should have received a copy of the GNU General Public License
18
+ along with Grbl.  If not, see <http://www.gnu.org/licenses/>.
19
+ */
20
 
20
 
21
 /* The ring buffer implementation gleaned from the wiring_serial library by David A. Mellis. */
21
 /* The ring buffer implementation gleaned from the wiring_serial library by David A. Mellis. */
22
 
22
 
23
 /*  
23
 /*  
24
-  Reasoning behind the mathematics in this module (in the key of 'Mathematica'):
25
-  
26
-  s == speed, a == acceleration, t == time, d == distance
27
-
28
-  Basic definitions:
29
-
30
-    Speed[s_, a_, t_] := s + (a*t) 
31
-    Travel[s_, a_, t_] := Integrate[Speed[s, a, t], t]
32
-
33
-  Distance to reach a specific speed with a constant acceleration:
34
-
35
-    Solve[{Speed[s, a, t] == m, Travel[s, a, t] == d}, d, t]
36
-      d -> (m^2 - s^2)/(2 a) --> estimate_acceleration_distance()
37
-
38
-  Speed after a given distance of travel with constant acceleration:
39
-
40
-    Solve[{Speed[s, a, t] == m, Travel[s, a, t] == d}, m, t]
41
-      m -> Sqrt[2 a d + s^2]    
42
-
43
-    DestinationSpeed[s_, a_, d_] := Sqrt[2 a d + s^2]
44
-
45
-  When to start braking (di) to reach a specified destionation speed (s2) after accelerating
46
-  from initial speed s1 without ever stopping at a plateau:
47
-
48
-    Solve[{DestinationSpeed[s1, a, di] == DestinationSpeed[s2, a, d - di]}, di]
49
-      di -> (2 a d - s1^2 + s2^2)/(4 a) --> intersection_distance()
24
+ Reasoning behind the mathematics in this module (in the key of 'Mathematica'):
25
+ 
26
+ s == speed, a == acceleration, t == time, d == distance
27
+ 
28
+ Basic definitions:
29
+ 
30
+ Speed[s_, a_, t_] := s + (a*t) 
31
+ Travel[s_, a_, t_] := Integrate[Speed[s, a, t], t]
32
+ 
33
+ Distance to reach a specific speed with a constant acceleration:
34
+ 
35
+ Solve[{Speed[s, a, t] == m, Travel[s, a, t] == d}, d, t]
36
+ d -> (m^2 - s^2)/(2 a) --> estimate_acceleration_distance()
37
+ 
38
+ Speed after a given distance of travel with constant acceleration:
39
+ 
40
+ Solve[{Speed[s, a, t] == m, Travel[s, a, t] == d}, m, t]
41
+ m -> Sqrt[2 a d + s^2]    
42
+ 
43
+ DestinationSpeed[s_, a_, d_] := Sqrt[2 a d + s^2]
44
+ 
45
+ When to start braking (di) to reach a specified destionation speed (s2) after accelerating
46
+ from initial speed s1 without ever stopping at a plateau:
47
+ 
48
+ Solve[{DestinationSpeed[s1, a, di] == DestinationSpeed[s2, a, d - di]}, di]
49
+ di -> (2 a d - s1^2 + s2^2)/(4 a) --> intersection_distance()
50
+ 
51
+ IntersectionDistance[s1_, s2_, a_, d_] := (2 a d - s1^2 + s2^2)/(4 a)
52
+ */
50
 
53
 
51
-    IntersectionDistance[s1_, s2_, a_, d_] := (2 a d - s1^2 + s2^2)/(4 a)
52
-*/
53
-                                                                                                            
54
 #include "Marlin.h"
54
 #include "Marlin.h"
55
 #include "planner.h"
55
 #include "planner.h"
56
 #include "stepper.h"
56
 #include "stepper.h"
83
 extern volatile int extrudemultiply; // Sets extrude multiply factor (in percent)
83
 extern volatile int extrudemultiply; // Sets extrude multiply factor (in percent)
84
 
84
 
85
 #ifdef AUTOTEMP
85
 #ifdef AUTOTEMP
86
-    float autotemp_max=250;
87
-    float autotemp_min=210;
88
-    float autotemp_factor=0.1;
89
-    bool autotemp_enabled=false;
86
+float autotemp_max=250;
87
+float autotemp_min=210;
88
+float autotemp_factor=0.1;
89
+bool autotemp_enabled=false;
90
 #endif
90
 #endif
91
 
91
 
92
 //===========================================================================
92
 //===========================================================================
100
 //=============================private variables ============================
100
 //=============================private variables ============================
101
 //===========================================================================
101
 //===========================================================================
102
 #ifdef PREVENT_DANGEROUS_EXTRUDE
102
 #ifdef PREVENT_DANGEROUS_EXTRUDE
103
-  bool allow_cold_extrude=false;
103
+bool allow_cold_extrude=false;
104
 #endif
104
 #endif
105
 #ifdef XY_FREQUENCY_LIMIT
105
 #ifdef XY_FREQUENCY_LIMIT
106
-  // Used for the frequency limit
107
-  static unsigned char old_direction_bits = 0;               // Old direction bits. Used for speed calculations
108
-  static long x_segment_time[3]={0,0,0};                     // Segment times (in us). Used for speed calculations
109
-  static long y_segment_time[3]={0,0,0};
106
+// Used for the frequency limit
107
+static unsigned char old_direction_bits = 0;               // Old direction bits. Used for speed calculations
108
+static long x_segment_time[3]={
109
+  0,0,0};                     // Segment times (in us). Used for speed calculations
110
+static long y_segment_time[3]={
111
+  0,0,0};
110
 #endif
112
 #endif
111
 
113
 
112
 // Returns the index of the next block in the ring buffer
114
 // Returns the index of the next block in the ring buffer
113
 // NOTE: Removed modulo (%) operator, which uses an expensive divide and multiplication.
115
 // NOTE: Removed modulo (%) operator, which uses an expensive divide and multiplication.
114
 static int8_t next_block_index(int8_t block_index) {
116
 static int8_t next_block_index(int8_t block_index) {
115
   block_index++;
117
   block_index++;
116
-  if (block_index == BLOCK_BUFFER_SIZE) { block_index = 0; }
118
+  if (block_index == BLOCK_BUFFER_SIZE) { 
119
+    block_index = 0; 
120
+  }
117
   return(block_index);
121
   return(block_index);
118
 }
122
 }
119
 
123
 
120
 
124
 
121
 // Returns the index of the previous block in the ring buffer
125
 // Returns the index of the previous block in the ring buffer
122
 static int8_t prev_block_index(int8_t block_index) {
126
 static int8_t prev_block_index(int8_t block_index) {
123
-  if (block_index == 0) { block_index = BLOCK_BUFFER_SIZE; }
127
+  if (block_index == 0) { 
128
+    block_index = BLOCK_BUFFER_SIZE; 
129
+  }
124
   block_index--;
130
   block_index--;
125
   return(block_index);
131
   return(block_index);
126
 }
132
 }
134
 FORCE_INLINE float estimate_acceleration_distance(float initial_rate, float target_rate, float acceleration)
140
 FORCE_INLINE float estimate_acceleration_distance(float initial_rate, float target_rate, float acceleration)
135
 {
141
 {
136
   if (acceleration!=0) {
142
   if (acceleration!=0) {
137
-  return((target_rate*target_rate-initial_rate*initial_rate)/
138
-         (2.0*acceleration));
143
+    return((target_rate*target_rate-initial_rate*initial_rate)/
144
+      (2.0*acceleration));
139
   }
145
   }
140
   else {
146
   else {
141
     return 0.0;  // acceleration was 0, set acceleration distance to 0
147
     return 0.0;  // acceleration was 0, set acceleration distance to 0
149
 
155
 
150
 FORCE_INLINE float intersection_distance(float initial_rate, float final_rate, float acceleration, float distance) 
156
 FORCE_INLINE float intersection_distance(float initial_rate, float final_rate, float acceleration, float distance) 
151
 {
157
 {
152
- if (acceleration!=0) {
153
-  return((2.0*acceleration*distance-initial_rate*initial_rate+final_rate*final_rate)/
154
-         (4.0*acceleration) );
158
+  if (acceleration!=0) {
159
+    return((2.0*acceleration*distance-initial_rate*initial_rate+final_rate*final_rate)/
160
+      (4.0*acceleration) );
155
   }
161
   }
156
   else {
162
   else {
157
     return 0.0;  // acceleration was 0, set intersection distance to 0
163
     return 0.0;  // acceleration was 0, set intersection distance to 0
165
   unsigned long final_rate = ceil(block->nominal_rate*exit_factor); // (step/min)
171
   unsigned long final_rate = ceil(block->nominal_rate*exit_factor); // (step/min)
166
 
172
 
167
   // Limit minimal step rate (Otherwise the timer will overflow.)
173
   // Limit minimal step rate (Otherwise the timer will overflow.)
168
-  if(initial_rate <120) {initial_rate=120; }
169
-  if(final_rate < 120) {final_rate=120;  }
170
-  
174
+  if(initial_rate <120) {
175
+    initial_rate=120; 
176
+  }
177
+  if(final_rate < 120) {
178
+    final_rate=120;  
179
+  }
180
+
171
   long acceleration = block->acceleration_st;
181
   long acceleration = block->acceleration_st;
172
   int32_t accelerate_steps =
182
   int32_t accelerate_steps =
173
     ceil(estimate_acceleration_distance(block->initial_rate, block->nominal_rate, acceleration));
183
     ceil(estimate_acceleration_distance(block->initial_rate, block->nominal_rate, acceleration));
174
   int32_t decelerate_steps =
184
   int32_t decelerate_steps =
175
     floor(estimate_acceleration_distance(block->nominal_rate, block->final_rate, -acceleration));
185
     floor(estimate_acceleration_distance(block->nominal_rate, block->final_rate, -acceleration));
176
-    
186
+
177
   // Calculate the size of Plateau of Nominal Rate.
187
   // Calculate the size of Plateau of Nominal Rate.
178
   int32_t plateau_steps = block->step_event_count-accelerate_steps-decelerate_steps;
188
   int32_t plateau_steps = block->step_event_count-accelerate_steps-decelerate_steps;
179
-  
189
+
180
   // Is the Plateau of Nominal Rate smaller than nothing? That means no cruising, and we will
190
   // Is the Plateau of Nominal Rate smaller than nothing? That means no cruising, and we will
181
   // have to use intersection_distance() to calculate when to abort acceleration and start braking
191
   // have to use intersection_distance() to calculate when to abort acceleration and start braking
182
   // in order to reach the final_rate exactly at the end of this block.
192
   // in order to reach the final_rate exactly at the end of this block.
183
   if (plateau_steps < 0) {
193
   if (plateau_steps < 0) {
184
     accelerate_steps = ceil(
194
     accelerate_steps = ceil(
185
-      intersection_distance(block->initial_rate, block->final_rate, acceleration, block->step_event_count));
195
+    intersection_distance(block->initial_rate, block->final_rate, acceleration, block->step_event_count));
186
     accelerate_steps = max(accelerate_steps,0); // Check limits due to numerical round-off
196
     accelerate_steps = max(accelerate_steps,0); // Check limits due to numerical round-off
187
     accelerate_steps = min(accelerate_steps,block->step_event_count);
197
     accelerate_steps = min(accelerate_steps,block->step_event_count);
188
     plateau_steps = 0;
198
     plateau_steps = 0;
189
   }
199
   }
190
 
200
 
191
-  #ifdef ADVANCE
192
-    volatile long initial_advance = block->advance*entry_factor*entry_factor; 
193
-    volatile long final_advance = block->advance*exit_factor*exit_factor;
194
-  #endif // ADVANCE
195
-  
196
- // block->accelerate_until = accelerate_steps;
197
- // block->decelerate_after = accelerate_steps+plateau_steps;
201
+#ifdef ADVANCE
202
+  volatile long initial_advance = block->advance*entry_factor*entry_factor; 
203
+  volatile long final_advance = block->advance*exit_factor*exit_factor;
204
+#endif // ADVANCE
205
+
206
+  // block->accelerate_until = accelerate_steps;
207
+  // block->decelerate_after = accelerate_steps+plateau_steps;
198
   CRITICAL_SECTION_START;  // Fill variables used by the stepper in a critical section
208
   CRITICAL_SECTION_START;  // Fill variables used by the stepper in a critical section
199
   if(block->busy == false) { // Don't update variables if block is busy.
209
   if(block->busy == false) { // Don't update variables if block is busy.
200
     block->accelerate_until = accelerate_steps;
210
     block->accelerate_until = accelerate_steps;
201
     block->decelerate_after = accelerate_steps+plateau_steps;
211
     block->decelerate_after = accelerate_steps+plateau_steps;
202
     block->initial_rate = initial_rate;
212
     block->initial_rate = initial_rate;
203
     block->final_rate = final_rate;
213
     block->final_rate = final_rate;
204
-  #ifdef ADVANCE
205
-      block->initial_advance = initial_advance;
206
-      block->final_advance = final_advance;
207
-  #endif //ADVANCE
214
+#ifdef ADVANCE
215
+    block->initial_advance = initial_advance;
216
+    block->final_advance = final_advance;
217
+#endif //ADVANCE
208
   }
218
   }
209
   CRITICAL_SECTION_END;
219
   CRITICAL_SECTION_END;
210
 }                    
220
 }                    
226
 
236
 
227
 // The kernel called by planner_recalculate() when scanning the plan from last to first entry.
237
 // The kernel called by planner_recalculate() when scanning the plan from last to first entry.
228
 void planner_reverse_pass_kernel(block_t *previous, block_t *current, block_t *next) {
238
 void planner_reverse_pass_kernel(block_t *previous, block_t *current, block_t *next) {
229
-  if(!current) { return; }
230
-  
231
-    if (next) {
239
+  if(!current) { 
240
+    return; 
241
+  }
242
+
243
+  if (next) {
232
     // If entry speed is already at the maximum entry speed, no need to recheck. Block is cruising.
244
     // If entry speed is already at the maximum entry speed, no need to recheck. Block is cruising.
233
     // If not, block in state of acceleration or deceleration. Reset entry speed to maximum and
245
     // If not, block in state of acceleration or deceleration. Reset entry speed to maximum and
234
     // check for maximum allowable speed reductions to ensure maximum possible planned speed.
246
     // check for maximum allowable speed reductions to ensure maximum possible planned speed.
235
     if (current->entry_speed != current->max_entry_speed) {
247
     if (current->entry_speed != current->max_entry_speed) {
236
-    
248
+
237
       // If nominal length true, max junction speed is guaranteed to be reached. Only compute
249
       // If nominal length true, max junction speed is guaranteed to be reached. Only compute
238
       // for max allowable speed if block is decelerating and nominal length is false.
250
       // for max allowable speed if block is decelerating and nominal length is false.
239
       if ((!current->nominal_length_flag) && (current->max_entry_speed > next->entry_speed)) {
251
       if ((!current->nominal_length_flag) && (current->max_entry_speed > next->entry_speed)) {
240
         current->entry_speed = min( current->max_entry_speed,
252
         current->entry_speed = min( current->max_entry_speed,
241
-          max_allowable_speed(-current->acceleration,next->entry_speed,current->millimeters));
242
-      } else {
253
+        max_allowable_speed(-current->acceleration,next->entry_speed,current->millimeters));
254
+      } 
255
+      else {
243
         current->entry_speed = current->max_entry_speed;
256
         current->entry_speed = current->max_entry_speed;
244
       }
257
       }
245
       current->recalculate_flag = true;
258
       current->recalculate_flag = true;
246
-    
259
+
247
     }
260
     }
248
   } // Skip last block. Already initialized and set for recalculation.
261
   } // Skip last block. Already initialized and set for recalculation.
249
 }
262
 }
252
 // implements the reverse pass.
265
 // implements the reverse pass.
253
 void planner_reverse_pass() {
266
 void planner_reverse_pass() {
254
   uint8_t block_index = block_buffer_head;
267
   uint8_t block_index = block_buffer_head;
255
-  if(((block_buffer_head-block_buffer_tail + BLOCK_BUFFER_SIZE) & (BLOCK_BUFFER_SIZE - 1)) > 3) {
268
+  
269
+  //Make a local copy of block_buffer_tail, because the interrupt can alter it
270
+  CRITICAL_SECTION_START;
271
+  unsigned char tail = block_buffer_tail;
272
+  CRITICAL_SECTION_END
273
+  
274
+  if(((block_buffer_head-tail + BLOCK_BUFFER_SIZE) & (BLOCK_BUFFER_SIZE - 1)) > 3) {
256
     block_index = (block_buffer_head - 3) & (BLOCK_BUFFER_SIZE - 1);
275
     block_index = (block_buffer_head - 3) & (BLOCK_BUFFER_SIZE - 1);
257
-    block_t *block[3] = { NULL, NULL, NULL };
258
-    while(block_index != block_buffer_tail) { 
276
+    block_t *block[3] = { 
277
+      NULL, NULL, NULL         };
278
+    while(block_index != tail) { 
259
       block_index = prev_block_index(block_index); 
279
       block_index = prev_block_index(block_index); 
260
       block[2]= block[1];
280
       block[2]= block[1];
261
       block[1]= block[0];
281
       block[1]= block[0];
267
 
287
 
268
 // The kernel called by planner_recalculate() when scanning the plan from first to last entry.
288
 // The kernel called by planner_recalculate() when scanning the plan from first to last entry.
269
 void planner_forward_pass_kernel(block_t *previous, block_t *current, block_t *next) {
289
 void planner_forward_pass_kernel(block_t *previous, block_t *current, block_t *next) {
270
-  if(!previous) { return; }
271
-  
290
+  if(!previous) { 
291
+    return; 
292
+  }
293
+
272
   // If the previous block is an acceleration block, but it is not long enough to complete the
294
   // If the previous block is an acceleration block, but it is not long enough to complete the
273
   // full speed change within the block, we need to adjust the entry speed accordingly. Entry
295
   // full speed change within the block, we need to adjust the entry speed accordingly. Entry
274
   // speeds have already been reset, maximized, and reverse planned by reverse planner.
296
   // speeds have already been reset, maximized, and reverse planned by reverse planner.
276
   if (!previous->nominal_length_flag) {
298
   if (!previous->nominal_length_flag) {
277
     if (previous->entry_speed < current->entry_speed) {
299
     if (previous->entry_speed < current->entry_speed) {
278
       double entry_speed = min( current->entry_speed,
300
       double entry_speed = min( current->entry_speed,
279
-        max_allowable_speed(-previous->acceleration,previous->entry_speed,previous->millimeters) );
301
+      max_allowable_speed(-previous->acceleration,previous->entry_speed,previous->millimeters) );
280
 
302
 
281
       // Check for junction speed change
303
       // Check for junction speed change
282
       if (current->entry_speed != entry_speed) {
304
       if (current->entry_speed != entry_speed) {
291
 // implements the forward pass.
313
 // implements the forward pass.
292
 void planner_forward_pass() {
314
 void planner_forward_pass() {
293
   uint8_t block_index = block_buffer_tail;
315
   uint8_t block_index = block_buffer_tail;
294
-  block_t *block[3] = { NULL, NULL, NULL };
316
+  block_t *block[3] = { 
317
+    NULL, NULL, NULL   };
295
 
318
 
296
   while(block_index != block_buffer_head) {
319
   while(block_index != block_buffer_head) {
297
     block[0] = block[1];
320
     block[0] = block[1];
310
   int8_t block_index = block_buffer_tail;
333
   int8_t block_index = block_buffer_tail;
311
   block_t *current;
334
   block_t *current;
312
   block_t *next = NULL;
335
   block_t *next = NULL;
313
-  
336
+
314
   while(block_index != block_buffer_head) {
337
   while(block_index != block_buffer_head) {
315
     current = next;
338
     current = next;
316
     next = &block_buffer[block_index];
339
     next = &block_buffer[block_index];
319
       if (current->recalculate_flag || next->recalculate_flag) {
342
       if (current->recalculate_flag || next->recalculate_flag) {
320
         // NOTE: Entry and exit factors always > 0 by all previous logic operations.
343
         // NOTE: Entry and exit factors always > 0 by all previous logic operations.
321
         calculate_trapezoid_for_block(current, current->entry_speed/current->nominal_speed,
344
         calculate_trapezoid_for_block(current, current->entry_speed/current->nominal_speed,
322
-          next->entry_speed/current->nominal_speed);
345
+        next->entry_speed/current->nominal_speed);
323
         current->recalculate_flag = false; // Reset current only to ensure next trapezoid is computed
346
         current->recalculate_flag = false; // Reset current only to ensure next trapezoid is computed
324
       }
347
       }
325
     }
348
     }
328
   // Last/newest block in buffer. Exit speed is set with MINIMUM_PLANNER_SPEED. Always recalculated.
351
   // Last/newest block in buffer. Exit speed is set with MINIMUM_PLANNER_SPEED. Always recalculated.
329
   if(next != NULL) {
352
   if(next != NULL) {
330
     calculate_trapezoid_for_block(next, next->entry_speed/next->nominal_speed,
353
     calculate_trapezoid_for_block(next, next->entry_speed/next->nominal_speed,
331
-      MINIMUM_PLANNER_SPEED/next->nominal_speed);
354
+    MINIMUM_PLANNER_SPEED/next->nominal_speed);
332
     next->recalculate_flag = false;
355
     next->recalculate_flag = false;
333
   }
356
   }
334
 }
357
 }
380
   if(degTargetHotend0()+2<autotemp_min) {  //probably temperature set to zero.
403
   if(degTargetHotend0()+2<autotemp_min) {  //probably temperature set to zero.
381
     return; //do nothing
404
     return; //do nothing
382
   }
405
   }
383
-  
406
+
384
   float high=0.0;
407
   float high=0.0;
385
   uint8_t block_index = block_buffer_tail;
408
   uint8_t block_index = block_buffer_tail;
386
-  
409
+
387
   while(block_index != block_buffer_head) {
410
   while(block_index != block_buffer_head) {
388
     if((block_buffer[block_index].steps_x != 0) ||
411
     if((block_buffer[block_index].steps_x != 0) ||
389
-       (block_buffer[block_index].steps_y != 0) ||
390
-       (block_buffer[block_index].steps_z != 0)) {
412
+      (block_buffer[block_index].steps_y != 0) ||
413
+      (block_buffer[block_index].steps_z != 0)) {
391
       float se=(float(block_buffer[block_index].steps_e)/float(block_buffer[block_index].step_event_count))*block_buffer[block_index].nominal_speed;
414
       float se=(float(block_buffer[block_index].steps_e)/float(block_buffer[block_index].step_event_count))*block_buffer[block_index].nominal_speed;
392
       //se; mm/sec;
415
       //se; mm/sec;
393
       if(se>high)
416
       if(se>high)
397
     }
420
     }
398
     block_index = (block_index+1) & (BLOCK_BUFFER_SIZE - 1);
421
     block_index = (block_index+1) & (BLOCK_BUFFER_SIZE - 1);
399
   }
422
   }
400
-   
423
+
401
   float g=autotemp_min+high*autotemp_factor;
424
   float g=autotemp_min+high*autotemp_factor;
402
   float t=g;
425
   float t=g;
403
   if(t<autotemp_min)
426
   if(t<autotemp_min)
436
     }
459
     }
437
   }
460
   }
438
   else {
461
   else {
439
-    #if FAN_PIN > -1
440
-      if (FanSpeed != 0){
441
-        analogWrite(FAN_PIN,FanSpeed); // If buffer is empty use current fan speed
442
-      }
443
-    #endif
462
+#if FAN_PIN > -1
463
+    if (FanSpeed != 0){
464
+      analogWrite(FAN_PIN,FanSpeed); // If buffer is empty use current fan speed
465
+    }
466
+#endif
444
   }
467
   }
445
   if((DISABLE_X) && (x_active == 0)) disable_x();
468
   if((DISABLE_X) && (x_active == 0)) disable_x();
446
   if((DISABLE_Y) && (y_active == 0)) disable_y();
469
   if((DISABLE_Y) && (y_active == 0)) disable_y();
447
   if((DISABLE_Z) && (z_active == 0)) disable_z();
470
   if((DISABLE_Z) && (z_active == 0)) disable_z();
448
-  if((DISABLE_E) && (e_active == 0)) { disable_e0();disable_e1();disable_e2(); }
449
-  #if FAN_PIN > -1
471
+  if((DISABLE_E) && (e_active == 0)) { 
472
+    disable_e0();
473
+    disable_e1();
474
+    disable_e2(); 
475
+  }
476
+#if FAN_PIN > -1
450
   if((FanSpeed == 0) && (fan_speed ==0)) {
477
   if((FanSpeed == 0) && (fan_speed ==0)) {
451
     analogWrite(FAN_PIN, 0);
478
     analogWrite(FAN_PIN, 0);
452
   }
479
   }
454
   if (FanSpeed != 0 && tail_fan_speed !=0) { 
481
   if (FanSpeed != 0 && tail_fan_speed !=0) { 
455
     analogWrite(FAN_PIN,tail_fan_speed);
482
     analogWrite(FAN_PIN,tail_fan_speed);
456
   }
483
   }
457
-  #endif
458
-  #ifdef AUTOTEMP
459
-    getHighESpeed();
460
-  #endif
484
+#endif
485
+#ifdef AUTOTEMP
486
+  getHighESpeed();
487
+#endif
461
 }
488
 }
462
 
489
 
463
 
490
 
477
     manage_inactivity(1); 
504
     manage_inactivity(1); 
478
     LCD_STATUS;
505
     LCD_STATUS;
479
   }
506
   }
480
-  
507
+
481
   // The target position of the tool in absolute steps
508
   // The target position of the tool in absolute steps
482
   // Calculate target position in absolute steps
509
   // Calculate target position in absolute steps
483
   //this should be done after the wait, because otherwise a M92 code within the gcode disrupts this calculation somehow
510
   //this should be done after the wait, because otherwise a M92 code within the gcode disrupts this calculation somehow
486
   target[Y_AXIS] = lround(y*axis_steps_per_unit[Y_AXIS]);
513
   target[Y_AXIS] = lround(y*axis_steps_per_unit[Y_AXIS]);
487
   target[Z_AXIS] = lround(z*axis_steps_per_unit[Z_AXIS]);     
514
   target[Z_AXIS] = lround(z*axis_steps_per_unit[Z_AXIS]);     
488
   target[E_AXIS] = lround(e*axis_steps_per_unit[E_AXIS]);
515
   target[E_AXIS] = lround(e*axis_steps_per_unit[E_AXIS]);
489
-  
490
-  #ifdef PREVENT_DANGEROUS_EXTRUDE
491
-    if(target[E_AXIS]!=position[E_AXIS])
516
+
517
+#ifdef PREVENT_DANGEROUS_EXTRUDE
518
+  if(target[E_AXIS]!=position[E_AXIS])
492
     if(degHotend(active_extruder)<EXTRUDE_MINTEMP && !allow_cold_extrude)
519
     if(degHotend(active_extruder)<EXTRUDE_MINTEMP && !allow_cold_extrude)
493
     {
520
     {
494
       position[E_AXIS]=target[E_AXIS]; //behave as if the move really took place, but ignore E part
521
       position[E_AXIS]=target[E_AXIS]; //behave as if the move really took place, but ignore E part
495
       SERIAL_ECHO_START;
522
       SERIAL_ECHO_START;
496
       SERIAL_ECHOLNPGM(MSG_ERR_COLD_EXTRUDE_STOP);
523
       SERIAL_ECHOLNPGM(MSG_ERR_COLD_EXTRUDE_STOP);
497
     }
524
     }
498
-    #ifdef PREVENT_LENGTHY_EXTRUDE
499
-    if(labs(target[E_AXIS]-position[E_AXIS])>axis_steps_per_unit[E_AXIS]*EXTRUDE_MAXLENGTH)
500
-    {
501
-      position[E_AXIS]=target[E_AXIS]; //behave as if the move really took place, but ignore E part
502
-      SERIAL_ECHO_START;
503
-      SERIAL_ECHOLNPGM(MSG_ERR_LONG_EXTRUDE_STOP);
504
-    }
505
-    #endif
506
-  #endif
507
-  
525
+#ifdef PREVENT_LENGTHY_EXTRUDE
526
+  if(labs(target[E_AXIS]-position[E_AXIS])>axis_steps_per_unit[E_AXIS]*EXTRUDE_MAXLENGTH)
527
+  {
528
+    position[E_AXIS]=target[E_AXIS]; //behave as if the move really took place, but ignore E part
529
+    SERIAL_ECHO_START;
530
+    SERIAL_ECHOLNPGM(MSG_ERR_LONG_EXTRUDE_STOP);
531
+  }
532
+#endif
533
+#endif
534
+
508
   // Prepare to set up new block
535
   // Prepare to set up new block
509
   block_t *block = &block_buffer[block_buffer_head];
536
   block_t *block = &block_buffer[block_buffer_head];
510
-  
537
+
511
   // Mark block as not busy (Not executed by the stepper interrupt)
538
   // Mark block as not busy (Not executed by the stepper interrupt)
512
   block->busy = false;
539
   block->busy = false;
513
 
540
 
521
   block->step_event_count = max(block->steps_x, max(block->steps_y, max(block->steps_z, block->steps_e)));
548
   block->step_event_count = max(block->steps_x, max(block->steps_y, max(block->steps_z, block->steps_e)));
522
 
549
 
523
   // Bail if this is a zero-length block
550
   // Bail if this is a zero-length block
524
-  if (block->step_event_count <= dropsegments) { return; };
551
+  if (block->step_event_count <= dropsegments) { 
552
+    return; 
553
+  };
525
 
554
 
526
   block->fan_speed = FanSpeed;
555
   block->fan_speed = FanSpeed;
527
-  
556
+
528
   // Compute direction bits for this block 
557
   // Compute direction bits for this block 
529
   block->direction_bits = 0;
558
   block->direction_bits = 0;
530
-  if (target[X_AXIS] < position[X_AXIS]) { block->direction_bits |= (1<<X_AXIS); }
531
-  if (target[Y_AXIS] < position[Y_AXIS]) { block->direction_bits |= (1<<Y_AXIS); }
532
-  if (target[Z_AXIS] < position[Z_AXIS]) { block->direction_bits |= (1<<Z_AXIS); }
533
-  if (target[E_AXIS] < position[E_AXIS]) { block->direction_bits |= (1<<E_AXIS); }
534
-  
559
+  if (target[X_AXIS] < position[X_AXIS]) { 
560
+    block->direction_bits |= (1<<X_AXIS); 
561
+  }
562
+  if (target[Y_AXIS] < position[Y_AXIS]) { 
563
+    block->direction_bits |= (1<<Y_AXIS); 
564
+  }
565
+  if (target[Z_AXIS] < position[Z_AXIS]) { 
566
+    block->direction_bits |= (1<<Z_AXIS); 
567
+  }
568
+  if (target[E_AXIS] < position[E_AXIS]) { 
569
+    block->direction_bits |= (1<<E_AXIS); 
570
+  }
571
+
535
   block->active_extruder = extruder;
572
   block->active_extruder = extruder;
536
-  
573
+
537
   //enable active axes
574
   //enable active axes
538
   if(block->steps_x != 0) enable_x();
575
   if(block->steps_x != 0) enable_x();
539
   if(block->steps_y != 0) enable_y();
576
   if(block->steps_y != 0) enable_y();
540
-  #ifndef Z_LATE_ENABLE
541
-    if(block->steps_z != 0) enable_z();
542
-  #endif
577
+#ifndef Z_LATE_ENABLE
578
+  if(block->steps_z != 0) enable_z();
579
+#endif
543
 
580
 
544
   // Enable all
581
   // Enable all
545
-  if(block->steps_e != 0) { enable_e0();enable_e1();enable_e2(); }
582
+  if(block->steps_e != 0) { 
583
+    enable_e0();
584
+    enable_e1();
585
+    enable_e2(); 
586
+  }
546
 
587
 
547
   if (block->steps_e == 0) {
588
   if (block->steps_e == 0) {
548
-        if(feed_rate<mintravelfeedrate) feed_rate=mintravelfeedrate;
589
+    if(feed_rate<mintravelfeedrate) feed_rate=mintravelfeedrate;
549
   }
590
   }
550
   else {
591
   else {
551
-    	if(feed_rate<minimumfeedrate) feed_rate=minimumfeedrate;
592
+    if(feed_rate<minimumfeedrate) feed_rate=minimumfeedrate;
552
   } 
593
   } 
553
-  
594
+
554
   float delta_mm[4];
595
   float delta_mm[4];
555
   delta_mm[X_AXIS] = (target[X_AXIS]-position[X_AXIS])/axis_steps_per_unit[X_AXIS];
596
   delta_mm[X_AXIS] = (target[X_AXIS]-position[X_AXIS])/axis_steps_per_unit[X_AXIS];
556
   delta_mm[Y_AXIS] = (target[Y_AXIS]-position[Y_AXIS])/axis_steps_per_unit[Y_AXIS];
597
   delta_mm[Y_AXIS] = (target[Y_AXIS]-position[Y_AXIS])/axis_steps_per_unit[Y_AXIS];
558
   delta_mm[E_AXIS] = ((target[E_AXIS]-position[E_AXIS])/axis_steps_per_unit[E_AXIS])*extrudemultiply/100.0;
599
   delta_mm[E_AXIS] = ((target[E_AXIS]-position[E_AXIS])/axis_steps_per_unit[E_AXIS])*extrudemultiply/100.0;
559
   if ( block->steps_x <=dropsegments && block->steps_y <=dropsegments && block->steps_z <=dropsegments ) {
600
   if ( block->steps_x <=dropsegments && block->steps_y <=dropsegments && block->steps_z <=dropsegments ) {
560
     block->millimeters = fabs(delta_mm[E_AXIS]);
601
     block->millimeters = fabs(delta_mm[E_AXIS]);
561
-  } else {
602
+  } 
603
+  else {
562
     block->millimeters = sqrt(square(delta_mm[X_AXIS]) + square(delta_mm[Y_AXIS]) + square(delta_mm[Z_AXIS]));
604
     block->millimeters = sqrt(square(delta_mm[X_AXIS]) + square(delta_mm[Y_AXIS]) + square(delta_mm[Z_AXIS]));
563
   }
605
   }
564
   float inverse_millimeters = 1.0/block->millimeters;  // Inverse millimeters to remove multiple divides 
606
   float inverse_millimeters = 1.0/block->millimeters;  // Inverse millimeters to remove multiple divides 
565
-  
566
-  // Calculate speed in mm/second for each axis. No divide by zero due to previous checks.
607
+
608
+    // Calculate speed in mm/second for each axis. No divide by zero due to previous checks.
567
   float inverse_second = feed_rate * inverse_millimeters;
609
   float inverse_second = feed_rate * inverse_millimeters;
568
-  
610
+
569
   int moves_queued=(block_buffer_head-block_buffer_tail + BLOCK_BUFFER_SIZE) & (BLOCK_BUFFER_SIZE - 1);
611
   int moves_queued=(block_buffer_head-block_buffer_tail + BLOCK_BUFFER_SIZE) & (BLOCK_BUFFER_SIZE - 1);
570
- 
612
+
571
   // slow down when de buffer starts to empty, rather than wait at the corner for a buffer refill
613
   // slow down when de buffer starts to empty, rather than wait at the corner for a buffer refill
572
-  #ifdef OLD_SLOWDOWN
573
-    if(moves_queued < (BLOCK_BUFFER_SIZE * 0.5) && moves_queued > 1) feed_rate = feed_rate*moves_queued / (BLOCK_BUFFER_SIZE * 0.5); 
574
-  #endif
614
+#ifdef OLD_SLOWDOWN
615
+  if(moves_queued < (BLOCK_BUFFER_SIZE * 0.5) && moves_queued > 1) feed_rate = feed_rate*moves_queued / (BLOCK_BUFFER_SIZE * 0.5); 
616
+#endif
575
 
617
 
576
-  #ifdef SLOWDOWN
618
+#ifdef SLOWDOWN
577
   //  segment time im micro seconds
619
   //  segment time im micro seconds
578
   unsigned long segment_time = lround(1000000.0/inverse_second);
620
   unsigned long segment_time = lround(1000000.0/inverse_second);
579
   if ((moves_queued > 1) && (moves_queued < (BLOCK_BUFFER_SIZE * 0.5))) {
621
   if ((moves_queued > 1) && (moves_queued < (BLOCK_BUFFER_SIZE * 0.5))) {
580
     if (segment_time < minsegmenttime)  { // buffer is draining, add extra time.  The amount of time added increases if the buffer is still emptied more.
622
     if (segment_time < minsegmenttime)  { // buffer is draining, add extra time.  The amount of time added increases if the buffer is still emptied more.
581
-        inverse_second=1000000.0/(segment_time+lround(2*(minsegmenttime-segment_time)/moves_queued));
623
+      inverse_second=1000000.0/(segment_time+lround(2*(minsegmenttime-segment_time)/moves_queued));
582
     }
624
     }
583
   }
625
   }
584
-  #endif
626
+#endif
585
   //  END OF SLOW DOWN SECTION    
627
   //  END OF SLOW DOWN SECTION    
586
 
628
 
587
-  
629
+
588
   block->nominal_speed = block->millimeters * inverse_second; // (mm/sec) Always > 0
630
   block->nominal_speed = block->millimeters * inverse_second; // (mm/sec) Always > 0
589
   block->nominal_rate = ceil(block->step_event_count * inverse_second); // (step/sec) Always > 0
631
   block->nominal_rate = ceil(block->step_event_count * inverse_second); // (step/sec) Always > 0
590
 
632
 
591
- // Calculate and limit speed in mm/sec for each axis
633
+  // Calculate and limit speed in mm/sec for each axis
592
   float current_speed[4];
634
   float current_speed[4];
593
   float speed_factor = 1.0; //factor <=1 do decrease speed
635
   float speed_factor = 1.0; //factor <=1 do decrease speed
594
   for(int i=0; i < 4; i++) {
636
   for(int i=0; i < 4; i++) {
597
       speed_factor = min(speed_factor, max_feedrate[i] / fabs(current_speed[i]));
639
       speed_factor = min(speed_factor, max_feedrate[i] / fabs(current_speed[i]));
598
   }
640
   }
599
 
641
 
600
-// Max segement time in us.
642
+  // Max segement time in us.
601
 #ifdef XY_FREQUENCY_LIMIT
643
 #ifdef XY_FREQUENCY_LIMIT
602
 #define MAX_FREQ_TIME (1000000.0/XY_FREQUENCY_LIMIT)
644
 #define MAX_FREQ_TIME (1000000.0/XY_FREQUENCY_LIMIT)
603
 
645
 
606
   old_direction_bits = block->direction_bits;
648
   old_direction_bits = block->direction_bits;
607
 
649
 
608
   if((direction_change & (1<<X_AXIS)) == 0) {
650
   if((direction_change & (1<<X_AXIS)) == 0) {
609
-     x_segment_time[0] += segment_time;
651
+    x_segment_time[0] += segment_time;
610
   }
652
   }
611
   else {
653
   else {
612
     x_segment_time[2] = x_segment_time[1];
654
     x_segment_time[2] = x_segment_time[1];
614
     x_segment_time[0] = segment_time;
656
     x_segment_time[0] = segment_time;
615
   }
657
   }
616
   if((direction_change & (1<<Y_AXIS)) == 0) {
658
   if((direction_change & (1<<Y_AXIS)) == 0) {
617
-     y_segment_time[0] += segment_time;
659
+    y_segment_time[0] += segment_time;
618
   }
660
   }
619
   else {
661
   else {
620
     y_segment_time[2] = y_segment_time[1];
662
     y_segment_time[2] = y_segment_time[1];
655
   }
697
   }
656
   block->acceleration = block->acceleration_st / steps_per_mm;
698
   block->acceleration = block->acceleration_st / steps_per_mm;
657
   block->acceleration_rate = (long)((float)block->acceleration_st * 8.388608);
699
   block->acceleration_rate = (long)((float)block->acceleration_st * 8.388608);
658
-  
700
+
659
 #if 0  // Use old jerk for now
701
 #if 0  // Use old jerk for now
660
   // Compute path unit vector
702
   // Compute path unit vector
661
   double unit_vec[3];
703
   double unit_vec[3];
663
   unit_vec[X_AXIS] = delta_mm[X_AXIS]*inverse_millimeters;
705
   unit_vec[X_AXIS] = delta_mm[X_AXIS]*inverse_millimeters;
664
   unit_vec[Y_AXIS] = delta_mm[Y_AXIS]*inverse_millimeters;
706
   unit_vec[Y_AXIS] = delta_mm[Y_AXIS]*inverse_millimeters;
665
   unit_vec[Z_AXIS] = delta_mm[Z_AXIS]*inverse_millimeters;
707
   unit_vec[Z_AXIS] = delta_mm[Z_AXIS]*inverse_millimeters;
666
-  
708
+
667
   // Compute maximum allowable entry speed at junction by centripetal acceleration approximation.
709
   // Compute maximum allowable entry speed at junction by centripetal acceleration approximation.
668
   // Let a circle be tangent to both previous and current path line segments, where the junction
710
   // Let a circle be tangent to both previous and current path line segments, where the junction
669
   // deviation is defined as the distance from the junction to the closest edge of the circle,
711
   // deviation is defined as the distance from the junction to the closest edge of the circle,
680
     // Compute cosine of angle between previous and current path. (prev_unit_vec is negative)
722
     // Compute cosine of angle between previous and current path. (prev_unit_vec is negative)
681
     // NOTE: Max junction velocity is computed without sin() or acos() by trig half angle identity.
723
     // NOTE: Max junction velocity is computed without sin() or acos() by trig half angle identity.
682
     double cos_theta = - previous_unit_vec[X_AXIS] * unit_vec[X_AXIS]
724
     double cos_theta = - previous_unit_vec[X_AXIS] * unit_vec[X_AXIS]
683
-                       - previous_unit_vec[Y_AXIS] * unit_vec[Y_AXIS]
684
-                       - previous_unit_vec[Z_AXIS] * unit_vec[Z_AXIS] ;
685
-                           
725
+      - previous_unit_vec[Y_AXIS] * unit_vec[Y_AXIS]
726
+      - previous_unit_vec[Z_AXIS] * unit_vec[Z_AXIS] ;
727
+
686
     // Skip and use default max junction speed for 0 degree acute junction.
728
     // Skip and use default max junction speed for 0 degree acute junction.
687
     if (cos_theta < 0.95) {
729
     if (cos_theta < 0.95) {
688
       vmax_junction = min(previous_nominal_speed,block->nominal_speed);
730
       vmax_junction = min(previous_nominal_speed,block->nominal_speed);
691
         // Compute maximum junction velocity based on maximum acceleration and junction deviation
733
         // Compute maximum junction velocity based on maximum acceleration and junction deviation
692
         double sin_theta_d2 = sqrt(0.5*(1.0-cos_theta)); // Trig half angle identity. Always positive.
734
         double sin_theta_d2 = sqrt(0.5*(1.0-cos_theta)); // Trig half angle identity. Always positive.
693
         vmax_junction = min(vmax_junction,
735
         vmax_junction = min(vmax_junction,
694
-          sqrt(block->acceleration * junction_deviation * sin_theta_d2/(1.0-sin_theta_d2)) );
736
+        sqrt(block->acceleration * junction_deviation * sin_theta_d2/(1.0-sin_theta_d2)) );
695
       }
737
       }
696
     }
738
     }
697
   }
739
   }
698
 #endif
740
 #endif
699
   // Start with a safe speed
741
   // Start with a safe speed
700
-  float vmax_junction = max_xy_jerk/2;  
742
+  float vmax_junction = max_xy_jerk/2; 
743
+  float vmax_junction_factor = 1.0; 
701
   if(fabs(current_speed[Z_AXIS]) > max_z_jerk/2) 
744
   if(fabs(current_speed[Z_AXIS]) > max_z_jerk/2) 
702
-    vmax_junction = max_z_jerk/2;
703
-  vmax_junction = min(vmax_junction, block->nominal_speed);
745
+    vmax_junction = min(vmax_junction, max_z_jerk/2);
704
   if(fabs(current_speed[E_AXIS]) > max_e_jerk/2) 
746
   if(fabs(current_speed[E_AXIS]) > max_e_jerk/2) 
705
     vmax_junction = min(vmax_junction, max_e_jerk/2);
747
     vmax_junction = min(vmax_junction, max_e_jerk/2);
706
-    
748
+  vmax_junction = min(vmax_junction, block->nominal_speed);
749
+  float safe_speed = vmax_junction;
750
+
707
   if ((moves_queued > 1) && (previous_nominal_speed > 0.0001)) {
751
   if ((moves_queued > 1) && (previous_nominal_speed > 0.0001)) {
708
     float jerk = sqrt(pow((current_speed[X_AXIS]-previous_speed[X_AXIS]), 2)+pow((current_speed[Y_AXIS]-previous_speed[Y_AXIS]), 2));
752
     float jerk = sqrt(pow((current_speed[X_AXIS]-previous_speed[X_AXIS]), 2)+pow((current_speed[Y_AXIS]-previous_speed[Y_AXIS]), 2));
709
-    if((fabs(previous_speed[X_AXIS]) > 0.0001) || (fabs(previous_speed[Y_AXIS]) > 0.0001)) {
710
-      vmax_junction = block->nominal_speed;
711
-    }
753
+    //    if((fabs(previous_speed[X_AXIS]) > 0.0001) || (fabs(previous_speed[Y_AXIS]) > 0.0001)) {
754
+    vmax_junction = block->nominal_speed;
755
+    //    }
712
     if (jerk > max_xy_jerk) {
756
     if (jerk > max_xy_jerk) {
713
-      vmax_junction *= (max_xy_jerk/jerk);
757
+      vmax_junction_factor = (max_xy_jerk/jerk);
714
     } 
758
     } 
715
     if(fabs(current_speed[Z_AXIS] - previous_speed[Z_AXIS]) > max_z_jerk) {
759
     if(fabs(current_speed[Z_AXIS] - previous_speed[Z_AXIS]) > max_z_jerk) {
716
-      vmax_junction *= (max_z_jerk/fabs(current_speed[Z_AXIS] - previous_speed[Z_AXIS]));
760
+      vmax_junction_factor= min(vmax_junction_factor, (max_z_jerk/fabs(current_speed[Z_AXIS] - previous_speed[Z_AXIS])));
717
     } 
761
     } 
718
     if(fabs(current_speed[E_AXIS] - previous_speed[E_AXIS]) > max_e_jerk) {
762
     if(fabs(current_speed[E_AXIS] - previous_speed[E_AXIS]) > max_e_jerk) {
719
-      vmax_junction *= (max_e_jerk/fabs(current_speed[E_AXIS] - previous_speed[E_AXIS]));
763
+      vmax_junction_factor = min(vmax_junction_factor, (max_e_jerk/fabs(current_speed[E_AXIS] - previous_speed[E_AXIS])));
720
     } 
764
     } 
765
+    vmax_junction = min(previous_nominal_speed, vmax_junction * vmax_junction_factor); // Limit speed to max previous speed
721
   }
766
   }
722
   block->max_entry_speed = vmax_junction;
767
   block->max_entry_speed = vmax_junction;
723
-    
768
+
724
   // Initialize block entry speed. Compute based on deceleration to user-defined MINIMUM_PLANNER_SPEED.
769
   // Initialize block entry speed. Compute based on deceleration to user-defined MINIMUM_PLANNER_SPEED.
725
   double v_allowable = max_allowable_speed(-block->acceleration,MINIMUM_PLANNER_SPEED,block->millimeters);
770
   double v_allowable = max_allowable_speed(-block->acceleration,MINIMUM_PLANNER_SPEED,block->millimeters);
726
   block->entry_speed = min(vmax_junction, v_allowable);
771
   block->entry_speed = min(vmax_junction, v_allowable);
733
   // block nominal speed limits both the current and next maximum junction speeds. Hence, in both
778
   // block nominal speed limits both the current and next maximum junction speeds. Hence, in both
734
   // the reverse and forward planners, the corresponding block junction speed will always be at the
779
   // the reverse and forward planners, the corresponding block junction speed will always be at the
735
   // the maximum junction speed and may always be ignored for any speed reduction checks.
780
   // the maximum junction speed and may always be ignored for any speed reduction checks.
736
-  if (block->nominal_speed <= v_allowable) { block->nominal_length_flag = true; }
737
-  else { block->nominal_length_flag = false; }
781
+  if (block->nominal_speed <= v_allowable) { 
782
+    block->nominal_length_flag = true; 
783
+  }
784
+  else { 
785
+    block->nominal_length_flag = false; 
786
+  }
738
   block->recalculate_flag = true; // Always calculate trapezoid for new block
787
   block->recalculate_flag = true; // Always calculate trapezoid for new block
739
-  
788
+
740
   // Update previous path unit_vector and nominal speed
789
   // Update previous path unit_vector and nominal speed
741
   memcpy(previous_speed, current_speed, sizeof(previous_speed)); // previous_speed[] = current_speed[]
790
   memcpy(previous_speed, current_speed, sizeof(previous_speed)); // previous_speed[] = current_speed[]
742
   previous_nominal_speed = block->nominal_speed;
791
   previous_nominal_speed = block->nominal_speed;
743
 
792
 
744
-  
745
-  #ifdef ADVANCE
746
-    // Calculate advance rate
747
-    if((block->steps_e == 0) || (block->steps_x == 0 && block->steps_y == 0 && block->steps_z == 0)) {
793
+
794
+#ifdef ADVANCE
795
+  // Calculate advance rate
796
+  if((block->steps_e == 0) || (block->steps_x == 0 && block->steps_y == 0 && block->steps_z == 0)) {
797
+    block->advance_rate = 0;
798
+    block->advance = 0;
799
+  }
800
+  else {
801
+    long acc_dist = estimate_acceleration_distance(0, block->nominal_rate, block->acceleration_st);
802
+    float advance = (STEPS_PER_CUBIC_MM_E * EXTRUDER_ADVANCE_K) * 
803
+      (current_speed[E_AXIS] * current_speed[E_AXIS] * EXTRUTION_AREA * EXTRUTION_AREA)*256;
804
+    block->advance = advance;
805
+    if(acc_dist == 0) {
748
       block->advance_rate = 0;
806
       block->advance_rate = 0;
749
-      block->advance = 0;
750
-    }
807
+    } 
751
     else {
808
     else {
752
-      long acc_dist = estimate_acceleration_distance(0, block->nominal_rate, block->acceleration_st);
753
-      float advance = (STEPS_PER_CUBIC_MM_E * EXTRUDER_ADVANCE_K) * 
754
-        (current_speed[E_AXIS] * current_speed[E_AXIS] * EXTRUTION_AREA * EXTRUTION_AREA)*256;
755
-      block->advance = advance;
756
-      if(acc_dist == 0) {
757
-        block->advance_rate = 0;
758
-      } 
759
-      else {
760
-        block->advance_rate = advance / (float)acc_dist;
761
-      }
809
+      block->advance_rate = advance / (float)acc_dist;
762
     }
810
     }
763
-    /*
811
+  }
812
+  /*
764
     SERIAL_ECHO_START;
813
     SERIAL_ECHO_START;
765
-    SERIAL_ECHOPGM("advance :");
766
-    SERIAL_ECHO(block->advance/256.0);
767
-    SERIAL_ECHOPGM("advance rate :");
768
-    SERIAL_ECHOLN(block->advance_rate/256.0);
769
-    */
770
-  #endif // ADVANCE
814
+   SERIAL_ECHOPGM("advance :");
815
+   SERIAL_ECHO(block->advance/256.0);
816
+   SERIAL_ECHOPGM("advance rate :");
817
+   SERIAL_ECHOLN(block->advance_rate/256.0);
818
+   */
819
+#endif // ADVANCE
771
 
820
 
772
   calculate_trapezoid_for_block(block, block->entry_speed/block->nominal_speed,
821
   calculate_trapezoid_for_block(block, block->entry_speed/block->nominal_speed,
773
-    MINIMUM_PLANNER_SPEED/block->nominal_speed);
774
-    
822
+  safe_speed/block->nominal_speed);
823
+
775
   // Move buffer head
824
   // Move buffer head
776
   block_buffer_head = next_buffer_head;
825
   block_buffer_head = next_buffer_head;
777
-  
826
+
778
   // Update position
827
   // Update position
779
   memcpy(position, target, sizeof(target)); // position[] = target[]
828
   memcpy(position, target, sizeof(target)); // position[] = target[]
780
 
829
 
805
 
854
 
806
 uint8_t movesplanned()
855
 uint8_t movesplanned()
807
 {
856
 {
808
- return (block_buffer_head-block_buffer_tail + BLOCK_BUFFER_SIZE) & (BLOCK_BUFFER_SIZE - 1);
857
+  return (block_buffer_head-block_buffer_tail + BLOCK_BUFFER_SIZE) & (BLOCK_BUFFER_SIZE - 1);
809
 }
858
 }
810
 
859
 
811
 void allow_cold_extrudes(bool allow)
860
 void allow_cold_extrudes(bool allow)
812
 {
861
 {
813
-  #ifdef PREVENT_DANGEROUS_EXTRUDE
814
-    allow_cold_extrude=allow;
815
-  #endif
862
+#ifdef PREVENT_DANGEROUS_EXTRUDE
863
+  allow_cold_extrude=allow;
864
+#endif
816
 }
865
 }
866
+

+ 1
- 3
Marlin/stepper.cpp View File

261
   #endif
261
   #endif
262
   deceleration_time = 0;
262
   deceleration_time = 0;
263
   // step_rate to timer interval
263
   // step_rate to timer interval
264
+  OCR1A_nominal = calc_timer(current_block->nominal_rate);
264
   acc_step_rate = current_block->initial_rate;
265
   acc_step_rate = current_block->initial_rate;
265
   acceleration_time = calc_timer(acc_step_rate);
266
   acceleration_time = calc_timer(acc_step_rate);
266
   OCR1A = acceleration_time;
267
   OCR1A = acceleration_time;
267
-  OCR1A_nominal = calc_timer(current_block->nominal_rate);
268
-  
269
-
270
   
268
   
271
 //    SERIAL_ECHO_START;
269
 //    SERIAL_ECHO_START;
272
 //    SERIAL_ECHOPGM("advance :");
270
 //    SERIAL_ECHOPGM("advance :");

+ 2
- 2
Marlin/ultralcd.pde View File

957
 #if EXTRUDERS > 2
957
 #if EXTRUDERS > 2
958
   ItemCT_nozzle2,
958
   ItemCT_nozzle2,
959
 #endif
959
 #endif
960
-#if defined BED_USES_THERMISTOR || BED_USES_AD595
960
+#if defined BED_USES_THERMISTOR || defined BED_USES_AD595
961
 ItemCT_bed,
961
 ItemCT_bed,
962
 #endif  
962
 #endif  
963
   ItemCT_fan,
963
   ItemCT_fan,
1212
         
1212
         
1213
       }break;  
1213
       }break;  
1214
     #endif //autotemp
1214
     #endif //autotemp
1215
-    #if defined BED_USES_THERMISTOR || BED_USES_AD595
1215
+    #if defined BED_USES_THERMISTOR || defined BED_USES_AD595
1216
     case ItemCT_bed:
1216
     case ItemCT_bed:
1217
       {
1217
       {
1218
         if(force_lcd_update)
1218
         if(force_lcd_update)

Loading…
Cancel
Save