Przeglądaj źródła

Add const to some variables

Scott Lahteine 8 lat temu
rodzic
commit
1929502e15
1 zmienionych plików z 24 dodań i 24 usunięć
  1. 24
    24
      Marlin/planner.cpp

+ 24
- 24
Marlin/planner.cpp Wyświetl plik

@@ -141,8 +141,8 @@ float Planner::previous_speed[NUM_AXIS],
141 141
 #endif
142 142
 
143 143
 #if ENABLED(LIN_ADVANCE)
144
-  float Planner::extruder_advance_k = LIN_ADVANCE_K;
145
-  float Planner::position_float[NUM_AXIS] = { 0 };
144
+  float Planner::extruder_advance_k = LIN_ADVANCE_K,
145
+        Planner::position_float[NUM_AXIS] = { 0 };
146 146
 #endif
147 147
 
148 148
 #if ENABLED(ENSURE_SMOOTH_MOVES)
@@ -654,7 +654,7 @@ void Planner::_buffer_line(const float &a, const float &b, const float &c, const
654 654
   // The target position of the tool in absolute steps
655 655
   // Calculate target position in absolute steps
656 656
   //this should be done after the wait, because otherwise a M92 code within the gcode disrupts this calculation somehow
657
-  long target[XYZE] = {
657
+  const long target[XYZE] = {
658 658
     lround(a * axis_steps_per_mm[X_AXIS]),
659 659
     lround(b * axis_steps_per_mm[Y_AXIS]),
660 660
     lround(c * axis_steps_per_mm[Z_AXIS]),
@@ -670,16 +670,16 @@ void Planner::_buffer_line(const float &a, const float &b, const float &c, const
670 670
   #endif
671 671
 
672 672
   #if ENABLED(LIN_ADVANCE)
673
-    float target_float[XYZE] = {a, b, c, e};
674
-    float de_float = target_float[E_AXIS] - position_float[E_AXIS];
675
-    float mm_D_float = sqrt(sq(target_float[X_AXIS] - position_float[X_AXIS]) + sq(target_float[Y_AXIS] - position_float[Y_AXIS]));
673
+    const float target_float[XYZE] = { a, b, c, e },
674
+                de_float = target_float[E_AXIS] - position_float[E_AXIS],
675
+                mm_D_float = sqrt(sq(target_float[X_AXIS] - position_float[X_AXIS]) + sq(target_float[Y_AXIS] - position_float[Y_AXIS]));
676 676
     
677 677
     memcpy(position_float, target_float, sizeof(position_float));
678 678
   #endif
679 679
 
680
-  long da = target[X_AXIS] - position[X_AXIS],
681
-       db = target[Y_AXIS] - position[Y_AXIS],
682
-       dc = target[Z_AXIS] - position[Z_AXIS];
680
+  const long da = target[X_AXIS] - position[X_AXIS],
681
+             db = target[Y_AXIS] - position[Y_AXIS],
682
+             dc = target[Z_AXIS] - position[Z_AXIS];
683 683
 
684 684
   /*
685 685
   SERIAL_ECHOPAIR("  Planner FR:", fr_mm_s);
@@ -755,11 +755,11 @@ void Planner::_buffer_line(const float &a, const float &b, const float &c, const
755 755
   #endif
756 756
   if (de < 0) SBI(dm, E_AXIS);
757 757
 
758
-  float esteps_float = de * volumetric_multiplier[extruder] * flow_percentage[extruder] * 0.01;
759
-  int32_t esteps = abs(esteps_float) + 0.5;
758
+  const float esteps_float = de * volumetric_multiplier[extruder] * flow_percentage[extruder] * 0.01;
759
+  const int32_t esteps = abs(esteps_float) + 0.5;
760 760
 
761 761
   // Calculate the buffer head after we push this byte
762
-  int8_t next_buffer_head = next_block_index(block_buffer_head);
762
+  const uint8_t next_buffer_head = next_block_index(block_buffer_head);
763 763
 
764 764
   // If the buffer is full: good! That means we are well ahead of the robot.
765 765
   // Rest here until there is room in the buffer.
@@ -852,7 +852,7 @@ void Planner::_buffer_line(const float &a, const float &b, const float &c, const
852 852
 
853 853
     #if ENABLED(DISABLE_INACTIVE_EXTRUDER) // Enable only the selected extruder
854 854
 
855
-      for (int8_t i = 0; i < EXTRUDERS; i++)
855
+      for (uint8_t i = 0; i < EXTRUDERS; i++)
856 856
         if (g_uc_extruder_last_move[i] > 0) g_uc_extruder_last_move[i]--;
857 857
 
858 858
       switch(extruder) {
@@ -980,7 +980,7 @@ void Planner::_buffer_line(const float &a, const float &b, const float &c, const
980 980
   // Calculate moves/second for this move. No divide by zero due to previous checks.
981 981
   float inverse_mm_s = fr_mm_s * inverse_millimeters;
982 982
 
983
-  int moves_queued = movesplanned();
983
+  const uint8_t moves_queued = movesplanned();
984 984
 
985 985
   // Slow down when the buffer starts to empty, rather than wait at the corner for a buffer refill
986 986
   #if ENABLED(SLOWDOWN)
@@ -1037,7 +1037,7 @@ void Planner::_buffer_line(const float &a, const float &b, const float &c, const
1037 1037
         // If the index has changed (must have gone forward)...
1038 1038
         if (filwidth_delay_index[0] != filwidth_delay_index[1]) {
1039 1039
           filwidth_e_count = 0; // Reset the E movement counter
1040
-          int8_t meas_sample = thermalManager.widthFil_to_size_ratio() - 100; // Subtract 100 to reduce magnitude - to store in a signed char
1040
+          const int8_t meas_sample = thermalManager.widthFil_to_size_ratio() - 100; // Subtract 100 to reduce magnitude - to store in a signed char
1041 1041
           do {
1042 1042
             filwidth_delay_index[1] = (filwidth_delay_index[1] + 1) % MMD_CM; // The next unused slot
1043 1043
             measurement_delay[filwidth_delay_index[1]] = meas_sample;         // Store the measurement
@@ -1050,7 +1050,7 @@ void Planner::_buffer_line(const float &a, const float &b, const float &c, const
1050 1050
   // Calculate and limit speed in mm/sec for each axis
1051 1051
   float current_speed[NUM_AXIS], speed_factor = 1.0; // factor <1 decreases speed
1052 1052
   LOOP_XYZE(i) {
1053
-    float cs = fabs(current_speed[i] = delta_mm[i] * inverse_mm_s);
1053
+    const float cs = fabs(current_speed[i] = delta_mm[i] * inverse_mm_s);
1054 1054
     if (cs > max_feedrate_mm_s[i]) NOMORE(speed_factor, max_feedrate_mm_s[i] / cs);
1055 1055
   }
1056 1056
 
@@ -1058,7 +1058,7 @@ void Planner::_buffer_line(const float &a, const float &b, const float &c, const
1058 1058
   #ifdef XY_FREQUENCY_LIMIT
1059 1059
 
1060 1060
     // Check and limit the xy direction change frequency
1061
-    unsigned char direction_change = block->direction_bits ^ old_direction_bits;
1061
+    const unsigned char direction_change = block->direction_bits ^ old_direction_bits;
1062 1062
     old_direction_bits = block->direction_bits;
1063 1063
     segment_time = lround((float)segment_time / speed_factor);
1064 1064
 
@@ -1083,11 +1083,11 @@ void Planner::_buffer_line(const float &a, const float &b, const float &c, const
1083 1083
     }
1084 1084
     ys0 = axis_segment_time[Y_AXIS][0] = ys0 + segment_time;
1085 1085
 
1086
-    long max_x_segment_time = MAX3(xs0, xs1, xs2),
1087
-         max_y_segment_time = MAX3(ys0, ys1, ys2),
1088
-         min_xy_segment_time = min(max_x_segment_time, max_y_segment_time);
1086
+    const long max_x_segment_time = MAX3(xs0, xs1, xs2),
1087
+               max_y_segment_time = MAX3(ys0, ys1, ys2),
1088
+               min_xy_segment_time = min(max_x_segment_time, max_y_segment_time);
1089 1089
     if (min_xy_segment_time < MAX_FREQ_TIME) {
1090
-      float low_sf = speed_factor * min_xy_segment_time / (MAX_FREQ_TIME);
1090
+      const float low_sf = speed_factor * min_xy_segment_time / (MAX_FREQ_TIME);
1091 1091
       NOMORE(speed_factor, low_sf);
1092 1092
     }
1093 1093
   #endif // XY_FREQUENCY_LIMIT
@@ -1100,7 +1100,7 @@ void Planner::_buffer_line(const float &a, const float &b, const float &c, const
1100 1100
   }
1101 1101
 
1102 1102
   // Compute and limit the acceleration rate for the trapezoid generator.
1103
-  float steps_per_mm = block->step_event_count * inverse_millimeters;
1103
+  const float steps_per_mm = block->step_event_count * inverse_millimeters;
1104 1104
   uint32_t accel;
1105 1105
   if (!block->steps[X_AXIS] && !block->steps[Y_AXIS] && !block->steps[Z_AXIS]) {
1106 1106
     // convert to: acceleration steps/sec^2
@@ -1256,7 +1256,7 @@ void Planner::_buffer_line(const float &a, const float &b, const float &c, const
1256 1256
     if (limited) vmax_junction *= v_factor;
1257 1257
     // Now the transition velocity is known, which maximizes the shared exit / entry velocity while
1258 1258
     // respecting the jerk factors, it may be possible, that applying separate safe exit / entry velocities will achieve faster prints.
1259
-    float vmax_junction_threshold = vmax_junction * 0.99f;
1259
+    const float vmax_junction_threshold = vmax_junction * 0.99f;
1260 1260
     if (previous_safe_speed > vmax_junction_threshold && safe_speed > vmax_junction_threshold) {
1261 1261
       // Not coasting. The machine will stop and start the movements anyway,
1262 1262
       // better to start the segment from start.
@@ -1273,7 +1273,7 @@ void Planner::_buffer_line(const float &a, const float &b, const float &c, const
1273 1273
   block->max_entry_speed = vmax_junction;
1274 1274
 
1275 1275
   // Initialize block entry speed. Compute based on deceleration to user-defined MINIMUM_PLANNER_SPEED.
1276
-  float v_allowable = max_allowable_speed(-block->acceleration, MINIMUM_PLANNER_SPEED, block->millimeters);
1276
+  const float v_allowable = max_allowable_speed(-block->acceleration, MINIMUM_PLANNER_SPEED, block->millimeters);
1277 1277
   block->entry_speed = min(vmax_junction, v_allowable);
1278 1278
 
1279 1279
   // Initialize planner efficiency flags

Ładowanie…
Anuluj
Zapisz