Browse Source

Save some cycle inside the planner

planner.h:
fan speed is used to set integer variables, so no need for long.
Basicaly a byte should be enough for all the fan things, as it's 0-255?

planner.cpp:
Save some float multiplications.
We could squeeze out even more by defining feedrate_percentage,
saved_feedrate_percentage and flow_percentage as float instead of int.
Everytime they are used in the time-critical planner, they are casted to
float and multiplied by 0.01. Not done jet, as they are used in LCD menu
functions I don't know well enough.
Sebastianv650 8 years ago
parent
commit
e3ffb58fbd
2 changed files with 7 additions and 6 deletions
  1. 6
    5
      Marlin/planner.cpp
  2. 1
    1
      Marlin/planner.h

+ 6
- 5
Marlin/planner.cpp View File

@@ -662,7 +662,7 @@ void Planner::_buffer_line(const float &a, const float &b, const float &c, const
662 662
         SERIAL_ECHOLNPGM(MSG_ERR_COLD_EXTRUDE_STOP);
663 663
       }
664 664
       #if ENABLED(PREVENT_LENGTHY_EXTRUDE)
665
-        if (labs(de) > axis_steps_per_mm[E_AXIS] * (EXTRUDE_MAXLENGTH)) {
665
+        if (labs(de) > (int32_t)axis_steps_per_mm[E_AXIS] * (EXTRUDE_MAXLENGTH)) { // It's not important to get max. extrusion length in a precision < 1mm, so save some cycles and cast to int
666 666
           position[E_AXIS] = target[E_AXIS]; // Behave as if the move really took place, but ignore E part
667 667
           de = 0; // no difference
668 668
           SERIAL_ECHO_START;
@@ -699,10 +699,11 @@ void Planner::_buffer_line(const float &a, const float &b, const float &c, const
699 699
   #endif
700 700
   if (de < 0) SBI(dm, E_AXIS);
701 701
 
702
-  int32_t esteps = labs(de) * volumetric_multiplier[extruder] * flow_percentage[extruder] * 0.01 + 0.5;
702
+  float esteps_float = de * volumetric_multiplier[extruder] * flow_percentage[extruder] * 0.01;
703
+  int32_t esteps = abs(esteps_float) + 0.5;
703 704
 
704 705
   // Calculate the buffer head after we push this byte
705
-  int next_buffer_head = next_block_index(block_buffer_head);
706
+  int8_t next_buffer_head = next_block_index(block_buffer_head);
706 707
 
707 708
   // If the buffer is full: good! That means we are well ahead of the robot.
708 709
   // Rest here until there is room in the buffer.
@@ -798,7 +799,7 @@ void Planner::_buffer_line(const float &a, const float &b, const float &c, const
798 799
 
799 800
     #if ENABLED(DISABLE_INACTIVE_EXTRUDER) // Enable only the selected extruder
800 801
 
801
-      for (int i = 0; i < EXTRUDERS; i++)
802
+      for (int8_t i = 0; i < EXTRUDERS; i++)
802 803
         if (g_uc_extruder_last_move[i] > 0) g_uc_extruder_last_move[i]--;
803 804
 
804 805
       switch(extruder) {
@@ -903,7 +904,7 @@ void Planner::_buffer_line(const float &a, const float &b, const float &c, const
903 904
     delta_mm[Y_AXIS] = db * steps_to_mm[Y_AXIS];
904 905
     delta_mm[Z_AXIS] = dc * steps_to_mm[Z_AXIS];
905 906
   #endif
906
-  delta_mm[E_AXIS] = 0.01 * (de * steps_to_mm[E_AXIS]) * volumetric_multiplier[extruder] * flow_percentage[extruder];
907
+  delta_mm[E_AXIS] = esteps_float * steps_to_mm[E_AXIS];
907 908
 
908 909
   if (block->steps[X_AXIS] < MIN_STEPS_PER_SEGMENT && block->steps[Y_AXIS] < MIN_STEPS_PER_SEGMENT && block->steps[Z_AXIS] < MIN_STEPS_PER_SEGMENT) {
909 910
     block->millimeters = fabs(delta_mm[E_AXIS]);

+ 1
- 1
Marlin/planner.h View File

@@ -117,7 +117,7 @@ typedef struct {
117 117
            acceleration_steps_per_s2;       // acceleration steps/sec^2
118 118
 
119 119
   #if FAN_COUNT > 0
120
-    uint32_t fan_speed[FAN_COUNT];
120
+    uint16_t fan_speed[FAN_COUNT];
121 121
   #endif
122 122
 
123 123
   #if ENABLED(BARICUDA)

Loading…
Cancel
Save