Browse Source

Fix some of the crowded code style. And fixed the conditional. #300

daid303 12 years ago
parent
commit
8f20562f49
1 changed files with 78 additions and 44 deletions
  1. 78
    44
      Marlin/planner.cpp

+ 78
- 44
Marlin/planner.cpp View File

435
 }
435
 }
436
 #endif
436
 #endif
437
 
437
 
438
-void check_axes_activity() {
438
+void check_axes_activity()
439
+{
439
   unsigned char x_active = 0;
440
   unsigned char x_active = 0;
440
   unsigned char y_active = 0;  
441
   unsigned char y_active = 0;  
441
   unsigned char z_active = 0;
442
   unsigned char z_active = 0;
444
   unsigned char tail_fan_speed = 0;
445
   unsigned char tail_fan_speed = 0;
445
   block_t *block;
446
   block_t *block;
446
 
447
 
447
-  if(block_buffer_tail != block_buffer_head) {
448
+  if(block_buffer_tail != block_buffer_head)
449
+  {
448
     uint8_t block_index = block_buffer_tail;
450
     uint8_t block_index = block_buffer_tail;
449
     tail_fan_speed = block_buffer[block_index].fan_speed;
451
     tail_fan_speed = block_buffer[block_index].fan_speed;
450
-    while(block_index != block_buffer_head) {
452
+    while(block_index != block_buffer_head)
453
+    {
451
       block = &block_buffer[block_index];
454
       block = &block_buffer[block_index];
452
       if(block->steps_x != 0) x_active++;
455
       if(block->steps_x != 0) x_active++;
453
       if(block->steps_y != 0) y_active++;
456
       if(block->steps_y != 0) y_active++;
457
       block_index = (block_index+1) & (BLOCK_BUFFER_SIZE - 1);
460
       block_index = (block_index+1) & (BLOCK_BUFFER_SIZE - 1);
458
     }
461
     }
459
   }
462
   }
460
-  else {
461
-#if FAN_PIN > -1
463
+  else
464
+  {
465
+    #if FAN_PIN > -1
462
     if (FanSpeed != 0){
466
     if (FanSpeed != 0){
463
       analogWrite(FAN_PIN,FanSpeed); // If buffer is empty use current fan speed
467
       analogWrite(FAN_PIN,FanSpeed); // If buffer is empty use current fan speed
464
     }
468
     }
465
-#endif
469
+    #endif
466
   }
470
   }
467
   if((DISABLE_X) && (x_active == 0)) disable_x();
471
   if((DISABLE_X) && (x_active == 0)) disable_x();
468
   if((DISABLE_Y) && (y_active == 0)) disable_y();
472
   if((DISABLE_Y) && (y_active == 0)) disable_y();
469
   if((DISABLE_Z) && (z_active == 0)) disable_z();
473
   if((DISABLE_Z) && (z_active == 0)) disable_z();
470
-  if((DISABLE_E) && (e_active == 0)) { 
474
+  if((DISABLE_E) && (e_active == 0))
475
+  {
471
     disable_e0();
476
     disable_e0();
472
     disable_e1();
477
     disable_e1();
473
     disable_e2(); 
478
     disable_e2(); 
474
   }
479
   }
475
 #if FAN_PIN > -1
480
 #if FAN_PIN > -1
476
-  if((FanSpeed == 0) && (fan_speed ==0)) {
481
+  if((FanSpeed == 0) && (fan_speed ==0))
482
+  {
477
     analogWrite(FAN_PIN, 0);
483
     analogWrite(FAN_PIN, 0);
478
   }
484
   }
479
 
485
 
480
-  if (FanSpeed != 0 && tail_fan_speed !=0) { 
486
+  if (FanSpeed != 0 && tail_fan_speed !=0)
487
+  {
481
     analogWrite(FAN_PIN,tail_fan_speed);
488
     analogWrite(FAN_PIN,tail_fan_speed);
482
   }
489
   }
483
 #endif
490
 #endif
498
 
505
 
499
   // If the buffer is full: good! That means we are well ahead of the robot. 
506
   // If the buffer is full: good! That means we are well ahead of the robot. 
500
   // Rest here until there is room in the buffer.
507
   // Rest here until there is room in the buffer.
501
-  while(block_buffer_tail == next_buffer_head) { 
508
+  while(block_buffer_tail == next_buffer_head)
509
+  {
502
     manage_heater(); 
510
     manage_heater(); 
503
     manage_inactivity(); 
511
     manage_inactivity(); 
504
     LCD_STATUS;
512
     LCD_STATUS;
513
   target[Z_AXIS] = lround(z*axis_steps_per_unit[Z_AXIS]);     
521
   target[Z_AXIS] = lround(z*axis_steps_per_unit[Z_AXIS]);     
514
   target[E_AXIS] = lround(e*axis_steps_per_unit[E_AXIS]);
522
   target[E_AXIS] = lround(e*axis_steps_per_unit[E_AXIS]);
515
 
523
 
516
-#ifdef PREVENT_DANGEROUS_EXTRUDE
517
-  if(target[E_AXIS]!=position[E_AXIS])
524
+  #ifdef PREVENT_DANGEROUS_EXTRUDE
525
+  if(target[E_AXIS]!=position[E_AXIS])
526
+  {
518
     if(degHotend(active_extruder)<EXTRUDE_MINTEMP && !allow_cold_extrude)
527
     if(degHotend(active_extruder)<EXTRUDE_MINTEMP && !allow_cold_extrude)
519
     {
528
     {
520
       position[E_AXIS]=target[E_AXIS]; //behave as if the move really took place, but ignore E part
529
       position[E_AXIS]=target[E_AXIS]; //behave as if the move really took place, but ignore E part
521
       SERIAL_ECHO_START;
530
       SERIAL_ECHO_START;
522
       SERIAL_ECHOLNPGM(MSG_ERR_COLD_EXTRUDE_STOP);
531
       SERIAL_ECHOLNPGM(MSG_ERR_COLD_EXTRUDE_STOP);
523
     }
532
     }
524
-#ifdef PREVENT_LENGTHY_EXTRUDE
525
-  if(labs(target[E_AXIS]-position[E_AXIS])>axis_steps_per_unit[E_AXIS]*EXTRUDE_MAXLENGTH)
526
-  {
527
-    position[E_AXIS]=target[E_AXIS]; //behave as if the move really took place, but ignore E part
528
-    SERIAL_ECHO_START;
529
-    SERIAL_ECHOLNPGM(MSG_ERR_LONG_EXTRUDE_STOP);
533
+    
534
+    #ifdef PREVENT_LENGTHY_EXTRUDE
535
+    if(labs(target[E_AXIS]-position[E_AXIS])>axis_steps_per_unit[E_AXIS]*EXTRUDE_MAXLENGTH)
536
+    {
537
+      position[E_AXIS]=target[E_AXIS]; //behave as if the move really took place, but ignore E part
538
+      SERIAL_ECHO_START;
539
+      SERIAL_ECHOLNPGM(MSG_ERR_LONG_EXTRUDE_STOP);
540
+    }
541
+    #endif
530
   }
542
   }
531
-#endif
532
-#endif
543
+  #endif
533
 
544
 
534
   // Prepare to set up new block
545
   // Prepare to set up new block
535
   block_t *block = &block_buffer[block_buffer_head];
546
   block_t *block = &block_buffer[block_buffer_head];
547
   block->step_event_count = max(block->steps_x, max(block->steps_y, max(block->steps_z, block->steps_e)));
558
   block->step_event_count = max(block->steps_x, max(block->steps_y, max(block->steps_z, block->steps_e)));
548
 
559
 
549
   // Bail if this is a zero-length block
560
   // Bail if this is a zero-length block
550
-  if (block->step_event_count <= dropsegments) { 
561
+  if (block->step_event_count <= dropsegments)
562
+  { 
551
     return; 
563
     return; 
552
-  };
564
+  }
553
 
565
 
554
   block->fan_speed = FanSpeed;
566
   block->fan_speed = FanSpeed;
555
 
567
 
556
   // Compute direction bits for this block 
568
   // Compute direction bits for this block 
557
   block->direction_bits = 0;
569
   block->direction_bits = 0;
558
-  if (target[X_AXIS] < position[X_AXIS]) { 
570
+  if (target[X_AXIS] < position[X_AXIS])
571
+  {
559
     block->direction_bits |= (1<<X_AXIS); 
572
     block->direction_bits |= (1<<X_AXIS); 
560
   }
573
   }
561
-  if (target[Y_AXIS] < position[Y_AXIS]) { 
574
+  if (target[Y_AXIS] < position[Y_AXIS])
575
+  {
562
     block->direction_bits |= (1<<Y_AXIS); 
576
     block->direction_bits |= (1<<Y_AXIS); 
563
   }
577
   }
564
-  if (target[Z_AXIS] < position[Z_AXIS]) { 
578
+  if (target[Z_AXIS] < position[Z_AXIS])
579
+  {
565
     block->direction_bits |= (1<<Z_AXIS); 
580
     block->direction_bits |= (1<<Z_AXIS); 
566
   }
581
   }
567
-  if (target[E_AXIS] < position[E_AXIS]) { 
582
+  if (target[E_AXIS] < position[E_AXIS])
583
+  {
568
     block->direction_bits |= (1<<E_AXIS); 
584
     block->direction_bits |= (1<<E_AXIS); 
569
   }
585
   }
570
 
586
 
578
 #endif
594
 #endif
579
 
595
 
580
   // Enable all
596
   // Enable all
581
-  if(block->steps_e != 0) { 
597
+  if(block->steps_e != 0)
598
+  {
582
     enable_e0();
599
     enable_e0();
583
     enable_e1();
600
     enable_e1();
584
     enable_e2(); 
601
     enable_e2(); 
585
   }
602
   }
586
 
603
 
587
-  if (block->steps_e == 0) {
604
+  if (block->steps_e == 0)
605
+  {
588
     if(feed_rate<mintravelfeedrate) feed_rate=mintravelfeedrate;
606
     if(feed_rate<mintravelfeedrate) feed_rate=mintravelfeedrate;
589
   }
607
   }
590
-  else {
608
+  else
609
+  {
591
     if(feed_rate<minimumfeedrate) feed_rate=minimumfeedrate;
610
     if(feed_rate<minimumfeedrate) feed_rate=minimumfeedrate;
592
   } 
611
   } 
593
 
612
 
596
   delta_mm[Y_AXIS] = (target[Y_AXIS]-position[Y_AXIS])/axis_steps_per_unit[Y_AXIS];
615
   delta_mm[Y_AXIS] = (target[Y_AXIS]-position[Y_AXIS])/axis_steps_per_unit[Y_AXIS];
597
   delta_mm[Z_AXIS] = (target[Z_AXIS]-position[Z_AXIS])/axis_steps_per_unit[Z_AXIS];
616
   delta_mm[Z_AXIS] = (target[Z_AXIS]-position[Z_AXIS])/axis_steps_per_unit[Z_AXIS];
598
   delta_mm[E_AXIS] = ((target[E_AXIS]-position[E_AXIS])/axis_steps_per_unit[E_AXIS])*extrudemultiply/100.0;
617
   delta_mm[E_AXIS] = ((target[E_AXIS]-position[E_AXIS])/axis_steps_per_unit[E_AXIS])*extrudemultiply/100.0;
599
-  if ( block->steps_x <=dropsegments && block->steps_y <=dropsegments && block->steps_z <=dropsegments ) {
618
+  if ( block->steps_x <=dropsegments && block->steps_y <=dropsegments && block->steps_z <=dropsegments )
619
+  {
600
     block->millimeters = fabs(delta_mm[E_AXIS]);
620
     block->millimeters = fabs(delta_mm[E_AXIS]);
601
   } 
621
   } 
602
-  else {
622
+  else
623
+  {
603
     block->millimeters = sqrt(square(delta_mm[X_AXIS]) + square(delta_mm[Y_AXIS]) + square(delta_mm[Z_AXIS]));
624
     block->millimeters = sqrt(square(delta_mm[X_AXIS]) + square(delta_mm[Y_AXIS]) + square(delta_mm[Z_AXIS]));
604
   }
625
   }
605
   float inverse_millimeters = 1.0/block->millimeters;  // Inverse millimeters to remove multiple divides 
626
   float inverse_millimeters = 1.0/block->millimeters;  // Inverse millimeters to remove multiple divides 
611
 
632
 
612
   // slow down when de buffer starts to empty, rather than wait at the corner for a buffer refill
633
   // slow down when de buffer starts to empty, rather than wait at the corner for a buffer refill
613
 #ifdef OLD_SLOWDOWN
634
 #ifdef OLD_SLOWDOWN
614
-  if(moves_queued < (BLOCK_BUFFER_SIZE * 0.5) && moves_queued > 1) feed_rate = feed_rate*moves_queued / (BLOCK_BUFFER_SIZE * 0.5); 
635
+  if(moves_queued < (BLOCK_BUFFER_SIZE * 0.5) && moves_queued > 1)
636
+    feed_rate = feed_rate*moves_queued / (BLOCK_BUFFER_SIZE * 0.5); 
615
 #endif
637
 #endif
616
 
638
 
617
 #ifdef SLOWDOWN
639
 #ifdef SLOWDOWN
618
   //  segment time im micro seconds
640
   //  segment time im micro seconds
619
   unsigned long segment_time = lround(1000000.0/inverse_second);
641
   unsigned long segment_time = lround(1000000.0/inverse_second);
620
-  if ((moves_queued > 1) && (moves_queued < (BLOCK_BUFFER_SIZE * 0.5))) {
621
-    if (segment_time < minsegmenttime)  { // buffer is draining, add extra time.  The amount of time added increases if the buffer is still emptied more.
642
+  if ((moves_queued > 1) && (moves_queued < (BLOCK_BUFFER_SIZE * 0.5)))
643
+  {
644
+    if (segment_time < minsegmenttime)
645
+    { // buffer is draining, add extra time.  The amount of time added increases if the buffer is still emptied more.
622
       inverse_second=1000000.0/(segment_time+lround(2*(minsegmenttime-segment_time)/moves_queued));
646
       inverse_second=1000000.0/(segment_time+lround(2*(minsegmenttime-segment_time)/moves_queued));
623
     }
647
     }
624
   }
648
   }
632
   // Calculate and limit speed in mm/sec for each axis
656
   // Calculate and limit speed in mm/sec for each axis
633
   float current_speed[4];
657
   float current_speed[4];
634
   float speed_factor = 1.0; //factor <=1 do decrease speed
658
   float speed_factor = 1.0; //factor <=1 do decrease speed
635
-  for(int i=0; i < 4; i++) {
659
+  for(int i=0; i < 4; i++)
660
+  {
636
     current_speed[i] = delta_mm[i] * inverse_second;
661
     current_speed[i] = delta_mm[i] * inverse_second;
637
     if(fabs(current_speed[i]) > max_feedrate[i])
662
     if(fabs(current_speed[i]) > max_feedrate[i])
638
       speed_factor = min(speed_factor, max_feedrate[i] / fabs(current_speed[i]));
663
       speed_factor = min(speed_factor, max_feedrate[i] / fabs(current_speed[i]));
646
   unsigned char direction_change = block->direction_bits ^ old_direction_bits;
671
   unsigned char direction_change = block->direction_bits ^ old_direction_bits;
647
   old_direction_bits = block->direction_bits;
672
   old_direction_bits = block->direction_bits;
648
 
673
 
649
-  if((direction_change & (1<<X_AXIS)) == 0) {
674
+  if((direction_change & (1<<X_AXIS)) == 0)
675
+  {
650
     x_segment_time[0] += segment_time;
676
     x_segment_time[0] += segment_time;
651
   }
677
   }
652
-  else {
678
+  else
679
+  {
653
     x_segment_time[2] = x_segment_time[1];
680
     x_segment_time[2] = x_segment_time[1];
654
     x_segment_time[1] = x_segment_time[0];
681
     x_segment_time[1] = x_segment_time[0];
655
     x_segment_time[0] = segment_time;
682
     x_segment_time[0] = segment_time;
656
   }
683
   }
657
-  if((direction_change & (1<<Y_AXIS)) == 0) {
684
+  if((direction_change & (1<<Y_AXIS)) == 0)
685
+  {
658
     y_segment_time[0] += segment_time;
686
     y_segment_time[0] += segment_time;
659
   }
687
   }
660
-  else {
688
+  else
689
+  {
661
     y_segment_time[2] = y_segment_time[1];
690
     y_segment_time[2] = y_segment_time[1];
662
     y_segment_time[1] = y_segment_time[0];
691
     y_segment_time[1] = y_segment_time[0];
663
     y_segment_time[0] = segment_time;
692
     y_segment_time[0] = segment_time;
665
   long max_x_segment_time = max(x_segment_time[0], max(x_segment_time[1], x_segment_time[2]));
694
   long max_x_segment_time = max(x_segment_time[0], max(x_segment_time[1], x_segment_time[2]));
666
   long max_y_segment_time = max(y_segment_time[0], max(y_segment_time[1], y_segment_time[2]));
695
   long max_y_segment_time = max(y_segment_time[0], max(y_segment_time[1], y_segment_time[2]));
667
   long min_xy_segment_time =min(max_x_segment_time, max_y_segment_time);
696
   long min_xy_segment_time =min(max_x_segment_time, max_y_segment_time);
668
-  if(min_xy_segment_time < MAX_FREQ_TIME) speed_factor = min(speed_factor, speed_factor * (float)min_xy_segment_time / (float)MAX_FREQ_TIME);
697
+  if(min_xy_segment_time < MAX_FREQ_TIME)
698
+    speed_factor = min(speed_factor, speed_factor * (float)min_xy_segment_time / (float)MAX_FREQ_TIME);
669
 #endif
699
 #endif
670
 
700
 
671
   // Correct the speed  
701
   // Correct the speed  
672
-  if( speed_factor < 1.0) {
673
-    for(unsigned char i=0; i < 4; i++) {
702
+  if( speed_factor < 1.0)
703
+  {
704
+    for(unsigned char i=0; i < 4; i++)
705
+    {
674
       current_speed[i] *= speed_factor;
706
       current_speed[i] *= speed_factor;
675
     }
707
     }
676
     block->nominal_speed *= speed_factor;
708
     block->nominal_speed *= speed_factor;
679
 
711
 
680
   // Compute and limit the acceleration rate for the trapezoid generator.  
712
   // Compute and limit the acceleration rate for the trapezoid generator.  
681
   float steps_per_mm = block->step_event_count/block->millimeters;
713
   float steps_per_mm = block->step_event_count/block->millimeters;
682
-  if(block->steps_x == 0 && block->steps_y == 0 && block->steps_z == 0) {
714
+  if(block->steps_x == 0 && block->steps_y == 0 && block->steps_z == 0)
715
+  {
683
     block->acceleration_st = ceil(retract_acceleration * steps_per_mm); // convert to: acceleration steps/sec^2
716
     block->acceleration_st = ceil(retract_acceleration * steps_per_mm); // convert to: acceleration steps/sec^2
684
   }
717
   }
685
-  else {
718
+  else
719
+  {
686
     block->acceleration_st = ceil(acceleration * steps_per_mm); // convert to: acceleration steps/sec^2
720
     block->acceleration_st = ceil(acceleration * steps_per_mm); // convert to: acceleration steps/sec^2
687
     // Limit acceleration per axis
721
     // Limit acceleration per axis
688
     if(((float)block->acceleration_st * (float)block->steps_x / (float)block->step_event_count) > axis_steps_per_sqr_second[X_AXIS])
722
     if(((float)block->acceleration_st * (float)block->steps_x / (float)block->step_event_count) > axis_steps_per_sqr_second[X_AXIS])

Loading…
Cancel
Save