Parcourir la source

Fixed AD595 define

Erik van der Zalm il y a 12 ans
Parent
révision
b67dacdc8f
3 fichiers modifiés avec 261 ajouts et 213 suppressions
  1. 258
    208
      Marlin/planner.cpp
  2. 1
    3
      Marlin/stepper.cpp
  3. 2
    2
      Marlin/ultralcd.pde

+ 258
- 208
Marlin/planner.cpp Voir le fichier

@@ -1,56 +1,56 @@
1 1
 /*
2 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 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 54
 #include "Marlin.h"
55 55
 #include "planner.h"
56 56
 #include "stepper.h"
@@ -83,10 +83,10 @@ static float previous_nominal_speed; // Nominal speed of previous path line segm
83 83
 extern volatile int extrudemultiply; // Sets extrude multiply factor (in percent)
84 84
 
85 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 90
 #endif
91 91
 
92 92
 //===========================================================================
@@ -100,27 +100,33 @@ volatile unsigned char block_buffer_tail;           // Index of the block to pro
100 100
 //=============================private variables ============================
101 101
 //===========================================================================
102 102
 #ifdef PREVENT_DANGEROUS_EXTRUDE
103
-  bool allow_cold_extrude=false;
103
+bool allow_cold_extrude=false;
104 104
 #endif
105 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 112
 #endif
111 113
 
112 114
 // Returns the index of the next block in the ring buffer
113 115
 // NOTE: Removed modulo (%) operator, which uses an expensive divide and multiplication.
114 116
 static int8_t next_block_index(int8_t block_index) {
115 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 121
   return(block_index);
118 122
 }
119 123
 
120 124
 
121 125
 // Returns the index of the previous block in the ring buffer
122 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 130
   block_index--;
125 131
   return(block_index);
126 132
 }
@@ -134,8 +140,8 @@ static int8_t prev_block_index(int8_t block_index) {
134 140
 FORCE_INLINE float estimate_acceleration_distance(float initial_rate, float target_rate, float acceleration)
135 141
 {
136 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 146
   else {
141 147
     return 0.0;  // acceleration was 0, set acceleration distance to 0
@@ -149,9 +155,9 @@ FORCE_INLINE float estimate_acceleration_distance(float initial_rate, float targ
149 155
 
150 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 162
   else {
157 163
     return 0.0;  // acceleration was 0, set intersection distance to 0
@@ -165,46 +171,50 @@ void calculate_trapezoid_for_block(block_t *block, float entry_factor, float exi
165 171
   unsigned long final_rate = ceil(block->nominal_rate*exit_factor); // (step/min)
166 172
 
167 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 181
   long acceleration = block->acceleration_st;
172 182
   int32_t accelerate_steps =
173 183
     ceil(estimate_acceleration_distance(block->initial_rate, block->nominal_rate, acceleration));
174 184
   int32_t decelerate_steps =
175 185
     floor(estimate_acceleration_distance(block->nominal_rate, block->final_rate, -acceleration));
176
-    
186
+
177 187
   // Calculate the size of Plateau of Nominal Rate.
178 188
   int32_t plateau_steps = block->step_event_count-accelerate_steps-decelerate_steps;
179
-  
189
+
180 190
   // Is the Plateau of Nominal Rate smaller than nothing? That means no cruising, and we will
181 191
   // have to use intersection_distance() to calculate when to abort acceleration and start braking
182 192
   // in order to reach the final_rate exactly at the end of this block.
183 193
   if (plateau_steps < 0) {
184 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 196
     accelerate_steps = max(accelerate_steps,0); // Check limits due to numerical round-off
187 197
     accelerate_steps = min(accelerate_steps,block->step_event_count);
188 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 208
   CRITICAL_SECTION_START;  // Fill variables used by the stepper in a critical section
199 209
   if(block->busy == false) { // Don't update variables if block is busy.
200 210
     block->accelerate_until = accelerate_steps;
201 211
     block->decelerate_after = accelerate_steps+plateau_steps;
202 212
     block->initial_rate = initial_rate;
203 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 219
   CRITICAL_SECTION_END;
210 220
 }                    
@@ -226,24 +236,27 @@ FORCE_INLINE float max_allowable_speed(float acceleration, float target_velocity
226 236
 
227 237
 // The kernel called by planner_recalculate() when scanning the plan from last to first entry.
228 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 244
     // If entry speed is already at the maximum entry speed, no need to recheck. Block is cruising.
233 245
     // If not, block in state of acceleration or deceleration. Reset entry speed to maximum and
234 246
     // check for maximum allowable speed reductions to ensure maximum possible planned speed.
235 247
     if (current->entry_speed != current->max_entry_speed) {
236
-    
248
+
237 249
       // If nominal length true, max junction speed is guaranteed to be reached. Only compute
238 250
       // for max allowable speed if block is decelerating and nominal length is false.
239 251
       if ((!current->nominal_length_flag) && (current->max_entry_speed > next->entry_speed)) {
240 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 256
         current->entry_speed = current->max_entry_speed;
244 257
       }
245 258
       current->recalculate_flag = true;
246
-    
259
+
247 260
     }
248 261
   } // Skip last block. Already initialized and set for recalculation.
249 262
 }
@@ -252,10 +265,17 @@ void planner_reverse_pass_kernel(block_t *previous, block_t *current, block_t *n
252 265
 // implements the reverse pass.
253 266
 void planner_reverse_pass() {
254 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 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 279
       block_index = prev_block_index(block_index); 
260 280
       block[2]= block[1];
261 281
       block[1]= block[0];
@@ -267,8 +287,10 @@ void planner_reverse_pass() {
267 287
 
268 288
 // The kernel called by planner_recalculate() when scanning the plan from first to last entry.
269 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 294
   // If the previous block is an acceleration block, but it is not long enough to complete the
273 295
   // full speed change within the block, we need to adjust the entry speed accordingly. Entry
274 296
   // speeds have already been reset, maximized, and reverse planned by reverse planner.
@@ -276,7 +298,7 @@ void planner_forward_pass_kernel(block_t *previous, block_t *current, block_t *n
276 298
   if (!previous->nominal_length_flag) {
277 299
     if (previous->entry_speed < current->entry_speed) {
278 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 303
       // Check for junction speed change
282 304
       if (current->entry_speed != entry_speed) {
@@ -291,7 +313,8 @@ void planner_forward_pass_kernel(block_t *previous, block_t *current, block_t *n
291 313
 // implements the forward pass.
292 314
 void planner_forward_pass() {
293 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 319
   while(block_index != block_buffer_head) {
297 320
     block[0] = block[1];
@@ -310,7 +333,7 @@ void planner_recalculate_trapezoids() {
310 333
   int8_t block_index = block_buffer_tail;
311 334
   block_t *current;
312 335
   block_t *next = NULL;
313
-  
336
+
314 337
   while(block_index != block_buffer_head) {
315 338
     current = next;
316 339
     next = &block_buffer[block_index];
@@ -319,7 +342,7 @@ void planner_recalculate_trapezoids() {
319 342
       if (current->recalculate_flag || next->recalculate_flag) {
320 343
         // NOTE: Entry and exit factors always > 0 by all previous logic operations.
321 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 346
         current->recalculate_flag = false; // Reset current only to ensure next trapezoid is computed
324 347
       }
325 348
     }
@@ -328,7 +351,7 @@ void planner_recalculate_trapezoids() {
328 351
   // Last/newest block in buffer. Exit speed is set with MINIMUM_PLANNER_SPEED. Always recalculated.
329 352
   if(next != NULL) {
330 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 355
     next->recalculate_flag = false;
333 356
   }
334 357
 }
@@ -380,14 +403,14 @@ void getHighESpeed()
380 403
   if(degTargetHotend0()+2<autotemp_min) {  //probably temperature set to zero.
381 404
     return; //do nothing
382 405
   }
383
-  
406
+
384 407
   float high=0.0;
385 408
   uint8_t block_index = block_buffer_tail;
386
-  
409
+
387 410
   while(block_index != block_buffer_head) {
388 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 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 415
       //se; mm/sec;
393 416
       if(se>high)
@@ -397,7 +420,7 @@ void getHighESpeed()
397 420
     }
398 421
     block_index = (block_index+1) & (BLOCK_BUFFER_SIZE - 1);
399 422
   }
400
-   
423
+
401 424
   float g=autotemp_min+high*autotemp_factor;
402 425
   float t=g;
403 426
   if(t<autotemp_min)
@@ -436,17 +459,21 @@ void check_axes_activity() {
436 459
     }
437 460
   }
438 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 468
   if((DISABLE_X) && (x_active == 0)) disable_x();
446 469
   if((DISABLE_Y) && (y_active == 0)) disable_y();
447 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 477
   if((FanSpeed == 0) && (fan_speed ==0)) {
451 478
     analogWrite(FAN_PIN, 0);
452 479
   }
@@ -454,10 +481,10 @@ void check_axes_activity() {
454 481
   if (FanSpeed != 0 && tail_fan_speed !=0) { 
455 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,7 +504,7 @@ void plan_buffer_line(const float &x, const float &y, const float &z, const floa
477 504
     manage_inactivity(1); 
478 505
     LCD_STATUS;
479 506
   }
480
-  
507
+
481 508
   // The target position of the tool in absolute steps
482 509
   // Calculate target position in absolute steps
483 510
   //this should be done after the wait, because otherwise a M92 code within the gcode disrupts this calculation somehow
@@ -486,28 +513,28 @@ void plan_buffer_line(const float &x, const float &y, const float &z, const floa
486 513
   target[Y_AXIS] = lround(y*axis_steps_per_unit[Y_AXIS]);
487 514
   target[Z_AXIS] = lround(z*axis_steps_per_unit[Z_AXIS]);     
488 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 519
     if(degHotend(active_extruder)<EXTRUDE_MINTEMP && !allow_cold_extrude)
493 520
     {
494 521
       position[E_AXIS]=target[E_AXIS]; //behave as if the move really took place, but ignore E part
495 522
       SERIAL_ECHO_START;
496 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 535
   // Prepare to set up new block
509 536
   block_t *block = &block_buffer[block_buffer_head];
510
-  
537
+
511 538
   // Mark block as not busy (Not executed by the stepper interrupt)
512 539
   block->busy = false;
513 540
 
@@ -521,36 +548,50 @@ void plan_buffer_line(const float &x, const float &y, const float &z, const floa
521 548
   block->step_event_count = max(block->steps_x, max(block->steps_y, max(block->steps_z, block->steps_e)));
522 549
 
523 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 555
   block->fan_speed = FanSpeed;
527
-  
556
+
528 557
   // Compute direction bits for this block 
529 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 572
   block->active_extruder = extruder;
536
-  
573
+
537 574
   //enable active axes
538 575
   if(block->steps_x != 0) enable_x();
539 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 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 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 591
   else {
551
-    	if(feed_rate<minimumfeedrate) feed_rate=minimumfeedrate;
592
+    if(feed_rate<minimumfeedrate) feed_rate=minimumfeedrate;
552 593
   } 
553
-  
594
+
554 595
   float delta_mm[4];
555 596
   delta_mm[X_AXIS] = (target[X_AXIS]-position[X_AXIS])/axis_steps_per_unit[X_AXIS];
556 597
   delta_mm[Y_AXIS] = (target[Y_AXIS]-position[Y_AXIS])/axis_steps_per_unit[Y_AXIS];
@@ -558,37 +599,38 @@ void plan_buffer_line(const float &x, const float &y, const float &z, const floa
558 599
   delta_mm[E_AXIS] = ((target[E_AXIS]-position[E_AXIS])/axis_steps_per_unit[E_AXIS])*extrudemultiply/100.0;
559 600
   if ( block->steps_x <=dropsegments && block->steps_y <=dropsegments && block->steps_z <=dropsegments ) {
560 601
     block->millimeters = fabs(delta_mm[E_AXIS]);
561
-  } else {
602
+  } 
603
+  else {
562 604
     block->millimeters = sqrt(square(delta_mm[X_AXIS]) + square(delta_mm[Y_AXIS]) + square(delta_mm[Z_AXIS]));
563 605
   }
564 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 609
   float inverse_second = feed_rate * inverse_millimeters;
568
-  
610
+
569 611
   int moves_queued=(block_buffer_head-block_buffer_tail + BLOCK_BUFFER_SIZE) & (BLOCK_BUFFER_SIZE - 1);
570
- 
612
+
571 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 619
   //  segment time im micro seconds
578 620
   unsigned long segment_time = lround(1000000.0/inverse_second);
579 621
   if ((moves_queued > 1) && (moves_queued < (BLOCK_BUFFER_SIZE * 0.5))) {
580 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 627
   //  END OF SLOW DOWN SECTION    
586 628
 
587
-  
629
+
588 630
   block->nominal_speed = block->millimeters * inverse_second; // (mm/sec) Always > 0
589 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 634
   float current_speed[4];
593 635
   float speed_factor = 1.0; //factor <=1 do decrease speed
594 636
   for(int i=0; i < 4; i++) {
@@ -597,7 +639,7 @@ void plan_buffer_line(const float &x, const float &y, const float &z, const floa
597 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 643
 #ifdef XY_FREQUENCY_LIMIT
602 644
 #define MAX_FREQ_TIME (1000000.0/XY_FREQUENCY_LIMIT)
603 645
 
@@ -606,7 +648,7 @@ void plan_buffer_line(const float &x, const float &y, const float &z, const floa
606 648
   old_direction_bits = block->direction_bits;
607 649
 
608 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 653
   else {
612 654
     x_segment_time[2] = x_segment_time[1];
@@ -614,7 +656,7 @@ void plan_buffer_line(const float &x, const float &y, const float &z, const floa
614 656
     x_segment_time[0] = segment_time;
615 657
   }
616 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 661
   else {
620 662
     y_segment_time[2] = y_segment_time[1];
@@ -655,7 +697,7 @@ void plan_buffer_line(const float &x, const float &y, const float &z, const floa
655 697
   }
656 698
   block->acceleration = block->acceleration_st / steps_per_mm;
657 699
   block->acceleration_rate = (long)((float)block->acceleration_st * 8.388608);
658
-  
700
+
659 701
 #if 0  // Use old jerk for now
660 702
   // Compute path unit vector
661 703
   double unit_vec[3];
@@ -663,7 +705,7 @@ void plan_buffer_line(const float &x, const float &y, const float &z, const floa
663 705
   unit_vec[X_AXIS] = delta_mm[X_AXIS]*inverse_millimeters;
664 706
   unit_vec[Y_AXIS] = delta_mm[Y_AXIS]*inverse_millimeters;
665 707
   unit_vec[Z_AXIS] = delta_mm[Z_AXIS]*inverse_millimeters;
666
-  
708
+
667 709
   // Compute maximum allowable entry speed at junction by centripetal acceleration approximation.
668 710
   // Let a circle be tangent to both previous and current path line segments, where the junction
669 711
   // deviation is defined as the distance from the junction to the closest edge of the circle,
@@ -680,9 +722,9 @@ void plan_buffer_line(const float &x, const float &y, const float &z, const floa
680 722
     // Compute cosine of angle between previous and current path. (prev_unit_vec is negative)
681 723
     // NOTE: Max junction velocity is computed without sin() or acos() by trig half angle identity.
682 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 728
     // Skip and use default max junction speed for 0 degree acute junction.
687 729
     if (cos_theta < 0.95) {
688 730
       vmax_junction = min(previous_nominal_speed,block->nominal_speed);
@@ -691,36 +733,39 @@ void plan_buffer_line(const float &x, const float &y, const float &z, const floa
691 733
         // Compute maximum junction velocity based on maximum acceleration and junction deviation
692 734
         double sin_theta_d2 = sqrt(0.5*(1.0-cos_theta)); // Trig half angle identity. Always positive.
693 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 740
 #endif
699 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 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 746
   if(fabs(current_speed[E_AXIS]) > max_e_jerk/2) 
705 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 751
   if ((moves_queued > 1) && (previous_nominal_speed > 0.0001)) {
708 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 756
     if (jerk > max_xy_jerk) {
713
-      vmax_junction *= (max_xy_jerk/jerk);
757
+      vmax_junction_factor = (max_xy_jerk/jerk);
714 758
     } 
715 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 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 767
   block->max_entry_speed = vmax_junction;
723
-    
768
+
724 769
   // Initialize block entry speed. Compute based on deceleration to user-defined MINIMUM_PLANNER_SPEED.
725 770
   double v_allowable = max_allowable_speed(-block->acceleration,MINIMUM_PLANNER_SPEED,block->millimeters);
726 771
   block->entry_speed = min(vmax_junction, v_allowable);
@@ -733,48 +778,52 @@ void plan_buffer_line(const float &x, const float &y, const float &z, const floa
733 778
   // block nominal speed limits both the current and next maximum junction speeds. Hence, in both
734 779
   // the reverse and forward planners, the corresponding block junction speed will always be at the
735 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 787
   block->recalculate_flag = true; // Always calculate trapezoid for new block
739
-  
788
+
740 789
   // Update previous path unit_vector and nominal speed
741 790
   memcpy(previous_speed, current_speed, sizeof(previous_speed)); // previous_speed[] = current_speed[]
742 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 806
       block->advance_rate = 0;
749
-      block->advance = 0;
750
-    }
807
+    } 
751 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 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 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 824
   // Move buffer head
776 825
   block_buffer_head = next_buffer_head;
777
-  
826
+
778 827
   // Update position
779 828
   memcpy(position, target, sizeof(target)); // position[] = target[]
780 829
 
@@ -805,12 +854,13 @@ void plan_set_e_position(const float &e)
805 854
 
806 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 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 Voir le fichier

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

+ 2
- 2
Marlin/ultralcd.pde Voir le fichier

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

Chargement…
Annuler
Enregistrer